QuestionId stringlengths 3 8 | QuestionTitle stringlengths 15 149 | QuestionScore int64 1 27.2k | QuestionCreatedUtc stringdate 2008-08-01 18:33:08 2025-06-16 04:59:48 | QuestionBodyHtml stringlengths 40 28.2k | QuestionViewCount int64 78 16.5M | QuestionOwnerUserId float64 4 25.2M β | QuestionLastActivityUtc stringdate 2008-09-08 19:26:01 2026-01-24 22:40:25 | AcceptedAnswerId int64 266 79.7M | AnswerScore int64 2 30.1k | AnswerCreatedUtc stringdate 2008-08-01 23:40:28 2025-06-16 05:23:39 | AnswerOwnerUserId float64 1 29.5M β | AnswerLastActivityUtc stringdate 2008-08-01 23:40:28 2026-01-23 17:46:09 | QuestionLink stringlengths 31 36 | AnswerLink stringlengths 31 36 | AnswerBodyHtml stringlengths 35 33k | AnswerBodyPreview stringlengths 35 400 | AllTagIdsCsv stringlengths 2 37 | AllTagNamesCsv stringlengths 2 106 | MergedQuestion stringlengths 74 28.4k | quality_filter stringclasses 10
values | unique_id int64 0 29k | tag_major_lang stringclasses 10
values | MergedQuestion_md stringlengths 60 28.1k | AnswerBodyHtml_md stringlengths 14 29.2k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
30980062 | "${0%/*}" and "${0##*/}" in sh | 8 | 2015-06-22 12:30:48 | <p>These are excerpts from a brew command.</p>
<pre><code>BREW_FILE_DIRECTORY=$(chdir "${0%/*}" && pwd -P)
export HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}"
</code></pre>
<p>What do <code>${0%/*}</code> and <code>${0##*/}</code> mean in shell?</p>
| 9,036 | 260,127 | 2021-01-31 00:28:18 | 30,980,170 | 14 | 2015-06-22 12:36:21 | 1,983,854 | 2015-06-23 12:35:13 | https://stackoverflow.com/q/30980062 | https://stackoverflow.com/a/30980170 | <p>These are shell <a href="http://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion" rel="noreferrer">parameter expansions</a>:</p>
<ul>
<li><code>${var%/*}</code> - remove everything after the last occurrence of <code>/</code>.</li>
<li><code>${var##*/}</code> - remove everything up to the last oc... | <p>These are shell <a href="http://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion" rel="noreferrer">parameter expansions</a>:</p> <ul> <li><code>${var%/*}</code> - remove everything after the last occurrence of <code>/</code>.</li> <li><code>${var##*/}</code> - remove everything up to the last oc... | 387, 10327 | bash, sh | <h1>"${0%/*}" and "${0##*/}" in sh</h1>
<p>These are excerpts from a brew command.</p>
<pre><code>BREW_FILE_DIRECTORY=$(chdir "${0%/*}" && pwd -P)
export HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}"
</code></pre>
<p>What do <code>${0%/*}</code> and <code>${0##*/}</code> mean in shell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,868 | bash | # "${0%/*}" and "${0##*/}" in sh
These are excerpts from a brew command.
```
BREW_FILE_DIRECTORY=$(chdir "${0%/*}" && pwd -P)
export HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}"
```
What do `${0%/*}` and `${0##*/}` mean in shell? | These are shell [parameter expansions](http://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion):
- `${var%/*}` - remove everything after the last occurrence of `/`.
- `${var##*/}` - remove everything up to the last occurrence of `/`.
Since you are in a script, `$0` refers to the name of the script... |
30929633 | Nested arrays and ConvertTo-Json | 8 | 2015-06-19 03:52:08 | <p>To use a REST API, I must pass a JSON object that looks like this:</p>
<pre><code>{ "series" :
[{
"metric": "custom.powershell.gauge",
"points":[[1434684739, 1000]]
}
]
}
</code></pre>
<p>Note the nested array here. I cannot get to reproduce this. Here is my code:</p>
<pre><code>[int][doubl... | 18,819 | 2,592,071 | 2016-09-12 16:47:44 | 30,930,382 | 14 | 2015-06-19 05:13:38 | 608,772 | 2015-06-19 06:41:36 | https://stackoverflow.com/q/30929633 | https://stackoverflow.com/a/30930382 | <p>The explanation is that <code>(1,2),(3,4</code>) is an array of array, but Powershell split the first level with the pipe <code>|</code>, and you don't give a name for these arrays so the serializer supplies it. First have a try to this :</p>
<pre><code># First build your array of array
$z = (1,2),(3,4)
# convert i... | <p>The explanation is that <code>(1,2),(3,4</code>) is an array of array, but Powershell split the first level with the pipe <code>|</code>, and you don't give a name for these arrays so the serializer supplies it. First have a try to this :</p> <pre><code># First build your array of array $z = (1,2),(3,4) # convert i... | 526, 1508 | json, powershell | <h1>Nested arrays and ConvertTo-Json</h1>
<p>To use a REST API, I must pass a JSON object that looks like this:</p>
<pre><code>{ "series" :
[{
"metric": "custom.powershell.gauge",
"points":[[1434684739, 1000]]
}
]
}
</code></pre>
<p>Note the nested array here. I cannot get to reproduce this. He... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,869 | bash | # Nested arrays and ConvertTo-Json
To use a REST API, I must pass a JSON object that looks like this:
```
{ "series" :
[{
"metric": "custom.powershell.gauge",
"points":[[1434684739, 1000]]
}
]
}
```
Note the nested array here. I cannot get to reproduce this. Here is my code:
```
[int][double]... | The explanation is that `(1,2),(3,4`) is an array of array, but Powershell split the first level with the pipe `|`, and you don't give a name for these arrays so the serializer supplies it. First have a try to this :
```
# First build your array of array
$z = (1,2),(3,4)
# convert it to JSON using the ,
,$z | ConvertT... |
24320446 | Run shell commands in Scala code on Windows seems to require the full absolute path of the command | 8 | 2014-06-20 05:21:35 | <p>When I try to run shell commands on Mac, it worked as expected like this:</p>
<pre><code>scala> import scala.sys.process._
import scala.sys.process._
scala> """protractor --version"""!
warning: there were 1 feature warning(s); re-run with -feature for details
Version 0.24.0
res12: Int = 0
scala>
</code><... | 2,270 | 290,284 | 2015-04-21 07:42:12 | 29,765,916 | 14 | 2015-04-21 07:42:12 | 2,476,884 | 2015-04-21 07:42:12 | https://stackoverflow.com/q/24320446 | https://stackoverflow.com/a/29765916 | <p>You could try this:</p>
<pre><code>val command = Seq("protractor", "--version")
val os = sys.props("os.name").toLowerCase
val panderToWindows = os match {
case x if x contains "windows" => Seq("cmd", "/C") ++ command
case _ => command
}
panderToWindows.!
</code></pre>
| <p>You could try this:</p> <pre><code>val command = Seq("protractor", "--version") val os = sys.props("os.name").toLowerCase val panderToWindows = os match { case x if x contains "windows" => Seq("cmd", "/C") ++ command case _ => command } panderToWindows.! </code></pre> | 64, 387, 390, 526, 3143 | bash, powershell, scala, shell, windows | <h1>Run shell commands in Scala code on Windows seems to require the full absolute path of the command</h1>
<p>When I try to run shell commands on Mac, it worked as expected like this:</p>
<pre><code>scala> import scala.sys.process._
import scala.sys.process._
scala> """protractor --version"""!
warning: there w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,870 | bash | # Run shell commands in Scala code on Windows seems to require the full absolute path of the command
When I try to run shell commands on Mac, it worked as expected like this:
```
scala> import scala.sys.process._
import scala.sys.process._
scala> """protractor --version"""!
warning: there were 1 feature warning(s); ... | You could try this:
```
val command = Seq("protractor", "--version")
val os = sys.props("os.name").toLowerCase
val panderToWindows = os match {
case x if x contains "windows" => Seq("cmd", "/C") ++ command
case _ => command
}
panderToWindows.!
``` |
29759586 | how do i use find, nm, and grep to find a symbol among many shared libraries? | 8 | 2015-04-20 22:31:16 | <p>I'm struggling with the right command to do the following:</p>
<p>find all shared libraries (*.so) that contain a certain symbol.</p>
<p>This is what I've tried:</p>
<pre><code>find -iname '*.so*' -exec nm {} \; | grep -H _ZN6QDebugD1Ev
</code></pre>
<p>The above gives some output with symbols found, but doesn't... | 6,740 | 1,470,533 | 2015-04-20 22:48:55 | 29,759,790 | 14 | 2015-04-20 22:48:55 | 4,710,467 | 2015-04-20 22:48:55 | https://stackoverflow.com/q/29759586 | https://stackoverflow.com/a/29759790 | <p>Pass the "-A" option to nm which will prefix its output with the filename. Then just grep for the symbol you're interested in, for example:</p>
<pre><code>find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev
</code></pre>
| <p>Pass the "-A" option to nm which will prefix its output with the filename. Then just grep for the symbol you're interested in, for example:</p> <pre><code>find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev </code></pre> | 387, 1271, 10193, 63696 | bash, find, grep, nm | <h1>how do i use find, nm, and grep to find a symbol among many shared libraries?</h1>
<p>I'm struggling with the right command to do the following:</p>
<p>find all shared libraries (*.so) that contain a certain symbol.</p>
<p>This is what I've tried:</p>
<pre><code>find -iname '*.so*' -exec nm {} \; | grep -H _ZN6Q... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,871 | bash | # how do i use find, nm, and grep to find a symbol among many shared libraries?
I'm struggling with the right command to do the following:
find all shared libraries (*.so) that contain a certain symbol.
This is what I've tried:
```
find -iname '*.so*' -exec nm {} \; | grep -H _ZN6QDebugD1Ev
```
The above gives som... | Pass the "-A" option to nm which will prefix its output with the filename. Then just grep for the symbol you're interested in, for example:
```
find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev
``` |
27897669 | PowerShell Remove Files smaller than 500bytes in directory recursively | 8 | 2015-01-12 08:12:16 | <p>I need a script that will remove all files recursively in folders with an extension filter of <code>.stat</code> and all of which is smaller than 500bytes.</p>
<p>It would be nice if the script could first give me all files and the count of files that will be deleted and then with the hit of an enter it will procee... | 11,382 | 1,702,369 | 2020-06-04 22:17:47 | 27,897,921 | 14 | 2015-01-12 08:32:10 | 2,627,148 | 2015-01-12 08:38:20 | https://stackoverflow.com/q/27897669 | https://stackoverflow.com/a/27897921 | <p>It's pretty straight forward with Get-Childitem, helped with Where-Object and ForEach-Object:</p>
<pre><code>$path = 'some path defined here'
Get-ChildItem $path -Filter *.stat -recurse |?{$_.PSIsContainer -eq $false -and $_.length -lt 500}|?{Remove-Item $_.fullname -WhatIf}
</code></pre>
<p>Remove the <code>-what... | <p>It's pretty straight forward with Get-Childitem, helped with Where-Object and ForEach-Object:</p> <pre><code>$path = 'some path defined here' Get-ChildItem $path -Filter *.stat -recurse |?{$_.PSIsContainer -eq $false -and $_.length -lt 500}|?{Remove-Item $_.fullname -WhatIf} </code></pre> <p>Remove the <code>-what... | 526 | powershell | <h1>PowerShell Remove Files smaller than 500bytes in directory recursively</h1>
<p>I need a script that will remove all files recursively in folders with an extension filter of <code>.stat</code> and all of which is smaller than 500bytes.</p>
<p>It would be nice if the script could first give me all files and the coun... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,872 | bash | # PowerShell Remove Files smaller than 500bytes in directory recursively
I need a script that will remove all files recursively in folders with an extension filter of `.stat` and all of which is smaller than 500bytes.
It would be nice if the script could first give me all files and the count of files that will be del... | It's pretty straight forward with Get-Childitem, helped with Where-Object and ForEach-Object:
```
$path = 'some path defined here'
Get-ChildItem $path -Filter *.stat -recurse |?{$_.PSIsContainer -eq $false -and $_.length -lt 500}|?{Remove-Item $_.fullname -WhatIf}
```
Remove the `-whatif` once you have tested to make... |
27734189 | sed- delete line that doesn't contain a pattern | 8 | 2015-01-01 20:04:57 | <p>I'm surprised that I can't find a question similar to this one on SO.</p>
<p>How do I use sed to delete all lines that do not contain a specific pattern.</p>
<p>For example, I have this file:</p>
<pre><code>cat kitty dog
giraffe panda
lion tiger
</code></pre>
<p>I want a sed command that, when called, will delet... | 13,005 | 4,333,347 | 2015-01-04 22:07:01 | 27,734,215 | 14 | 2015-01-01 20:07:43 | 975,114 | 2015-01-02 15:40:41 | https://stackoverflow.com/q/27734189 | https://stackoverflow.com/a/27734215 | <p>This will do:</p>
<pre><code>sed -i '/cat/!d' file1.txt
</code></pre>
<p>To force an exact match:</p>
<pre><code>sed -i '/\<cat\>/!d' file1.txt
</code></pre>
<p>or</p>
<pre><code>sed -i '/\bcat\b/!d' file1.txt
</code></pre>
<p>where <code>\<\></code> & <code>\b\b</code> force an exact match.</p... | <p>This will do:</p> <pre><code>sed -i '/cat/!d' file1.txt </code></pre> <p>To force an exact match:</p> <pre><code>sed -i '/\<cat\>/!d' file1.txt </code></pre> <p>or</p> <pre><code>sed -i '/\bcat\b/!d' file1.txt </code></pre> <p>where <code>\<\></code> & <code>\b\b</code> force an exact match.</p... | 387, 5282 | bash, sed | <h1>sed- delete line that doesn't contain a pattern</h1>
<p>I'm surprised that I can't find a question similar to this one on SO.</p>
<p>How do I use sed to delete all lines that do not contain a specific pattern.</p>
<p>For example, I have this file:</p>
<pre><code>cat kitty dog
giraffe panda
lion tiger
</code></pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,873 | bash | # sed- delete line that doesn't contain a pattern
I'm surprised that I can't find a question similar to this one on SO.
How do I use sed to delete all lines that do not contain a specific pattern.
For example, I have this file:
```
cat kitty dog
giraffe panda
lion tiger
```
I want a sed command that, when called, ... | This will do:
```
sed -i '/cat/!d' file1.txt
```
To force an exact match:
```
sed -i '/\<cat\>/!d' file1.txt
```
or
```
sed -i '/\bcat\b/!d' file1.txt
```
where `\<\>` & `\b\b` force an exact match. |
27437733 | use external python script to open maya and run another script inside maya | 8 | 2014-12-12 05:59:37 | <p>Is it possible to call a script from the command prompt in windows (or bash in linux) to open Maya and then subsequently run a custom script (possibly changing each time its run) inside Maya? I am searching for something a bit more elegant than changing the userSetup file and then running Maya. </p>
<p>The goal her... | 21,811 | 1,520,228 | 2014-12-13 00:56:44 | 27,444,131 | 14 | 2014-12-12 12:55:11 | 2,502,262 | 2014-12-12 12:55:11 | https://stackoverflow.com/q/27437733 | https://stackoverflow.com/a/27444131 | <p>
For something like this you can use Maya standalone instead of the full blown UI mode. It is faster. It is ideal for batch scheduled jobs like these. Maya standalone is just Maya running without the GUI. Once you have initialized your Maya standalone, you can import and call any scripts you want, as part of the ori... | <p> For something like this you can use Maya standalone instead of the full blown UI mode. It is faster. It is ideal for batch scheduled jobs like these. Maya standalone is just Maya running without the GUI. Once you have initialized your Maya standalone, you can import and call any scripts you want, as part of the ori... | 16, 387, 7002, 16618, 84987 | bash, batch-file, maya, pymel, python | <h1>use external python script to open maya and run another script inside maya</h1>
<p>Is it possible to call a script from the command prompt in windows (or bash in linux) to open Maya and then subsequently run a custom script (possibly changing each time its run) inside Maya? I am searching for something a bit more e... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,874 | bash | # use external python script to open maya and run another script inside maya
Is it possible to call a script from the command prompt in windows (or bash in linux) to open Maya and then subsequently run a custom script (possibly changing each time its run) inside Maya? I am searching for something a bit more elegant th... | For something like this you can use Maya standalone instead of the full blown UI mode. It is faster. It is ideal for batch scheduled jobs like these. Maya standalone is just Maya running without the GUI. Once you have initialized your Maya standalone, you can import and call any scripts you want, as part of the origina... |
25515382 | tput: No value for $TERM and no -T specified in Sublime Text 3 | 8 | 2014-08-26 21:24:45 | <p>When I build anything in Sublime Text 3 (regardless of language), I get the following lines at the beginning of any console output:</p>
<pre><code>tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T... | 5,010 | 130,427 | 2014-08-26 22:15:33 | 25,515,953 | 14 | 2014-08-26 22:08:57 | 130,427 | 2014-08-26 22:15:33 | https://stackoverflow.com/q/25515382 | https://stackoverflow.com/a/25515953 | <p>Have to change <code>.bash_profile</code> to check for interactive shell before processing any <code>tput</code> calls:</p>
<pre><code>if [[ $- == *i* ]]
then
# Prompt
NRM=`tput sgr0`
BLD=`tput bold`
ITL=`tput sitm`
UL=`tput smul`
RED=`tput setaf 1`
GRN=`tput setaf 2`
BLU=`tput setaf... | <p>Have to change <code>.bash_profile</code> to check for interactive shell before processing any <code>tput</code> calls:</p> <pre><code>if [[ $- == *i* ]] then # Prompt NRM=`tput sgr0` BLD=`tput bold` ITL=`tput sitm` UL=`tput smul` RED=`tput setaf 1` GRN=`tput setaf 2` BLU=`tput setaf... | 387, 88190 | bash, sublimetext3 | <h1>tput: No value for $TERM and no -T specified in Sublime Text 3</h1>
<p>When I build anything in Sublime Text 3 (regardless of language), I get the following lines at the beginning of any console output:</p>
<pre><code>tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: N... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,875 | bash | # tput: No value for $TERM and no -T specified in Sublime Text 3
When I build anything in Sublime Text 3 (regardless of language), I get the following lines at the beginning of any console output:
```
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM an... | Have to change `.bash_profile` to check for interactive shell before processing any `tput` calls:
```
if [[ $- == *i* ]]
then
# Prompt
NRM=`tput sgr0`
BLD=`tput bold`
ITL=`tput sitm`
UL=`tput smul`
RED=`tput setaf 1`
GRN=`tput setaf 2`
BLU=`tput setaf 4`
PS1='\n\r${BLD}\u${NRM}|${UL... |
24699109 | Bash one liner - Test if a file exists and source if it does other exit with error | 8 | 2014-07-11 13:38:00 | <p>In other words I want to make this into a one-liner:</p>
<pre><code> test -e ${MY_HOME}/setup-env.sh || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; }
. ${MY_HOME}/setup-env.sh
</code></pre>
| 11,492 | 1,076,662 | 2017-12-13 09:51:28 | 24,699,181 | 14 | 2014-07-11 13:41:14 | 548,225 | 2014-07-11 13:41:14 | https://stackoverflow.com/q/24699109 | https://stackoverflow.com/a/24699181 | <p>You can use this one liner:</p>
<pre><code>[[ -e "${MY_HOME}/setup-env.sh" ]] && source "${MY_HOME}/setup-env.sh" || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; }
</code></pre>
| <p>You can use this one liner:</p> <pre><code>[[ -e "${MY_HOME}/setup-env.sh" ]] && source "${MY_HOME}/setup-env.sh" || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; } </code></pre> | 5, 186, 387 | bash, php, testing | <h1>Bash one liner - Test if a file exists and source if it does other exit with error</h1>
<p>In other words I want to make this into a one-liner:</p>
<pre><code> test -e ${MY_HOME}/setup-env.sh || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; }
. ${MY_HOME}/setup-... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,876 | bash | # Bash one liner - Test if a file exists and source if it does other exit with error
In other words I want to make this into a one-liner:
```
test -e ${MY_HOME}/setup-env.sh || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; }
. ${MY_HOME}/setup-env.sh
``` | You can use this one liner:
```
[[ -e "${MY_HOME}/setup-env.sh" ]] && source "${MY_HOME}/setup-env.sh" || { echo "ERROR: MY_HOME not defined or does not contain srtup-env.sh" 1>&2 ; exit 1; }
``` |
24622725 | How to set PATH on Windows through R "shell" command | 8 | 2014-07-08 02:18:07 | <p>I wish to add git to my PATH in Windows 7, through the "shell" command in R.</p>
<pre><code>shell('set PATH=%PATH%;"C:\\Program%20Files%20(x86)\\Git\\bin"', intern = TRUE)
shell("echo %PATH% ", intern= TRUE)
</code></pre>
<p>But I do not see that path added.</p>
<p>If I run the above code in cmd.exe, it does add ... | 9,275 | 256,662 | 2014-07-08 11:53:04 | 24,630,960 | 14 | 2014-07-08 11:43:52 | 134,830 | 2014-07-08 11:53:04 | https://stackoverflow.com/q/24622725 | https://stackoverflow.com/a/24630960 | <p>If you want to permanantly update your path, then you pretty much had the answer:</p>
<pre><code>shell('setx PATH "C:\\Program Files (x86)\\Git\\bin"')
</code></pre>
<p>R only notes a copy of the Windows environment variables when it starts up though, so <code>strsplit(Sys.getenv("PATH"), ";")</code> won't be diff... | <p>If you want to permanantly update your path, then you pretty much had the answer:</p> <pre><code>shell('setx PATH "C:\\Program Files (x86)\\Git\\bin"') </code></pre> <p>R only notes a copy of the Windows environment variables when it starts up though, so <code>strsplit(Sys.getenv("PATH"), ";")</code> won't be diff... | 64, 119, 390, 4452, 6268 | git, path, r, shell, windows | <h1>How to set PATH on Windows through R "shell" command</h1>
<p>I wish to add git to my PATH in Windows 7, through the "shell" command in R.</p>
<pre><code>shell('set PATH=%PATH%;"C:\\Program%20Files%20(x86)\\Git\\bin"', intern = TRUE)
shell("echo %PATH% ", intern= TRUE)
</code></pre>
<p>But I do not see that path a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,877 | bash | # How to set PATH on Windows through R "shell" command
I wish to add git to my PATH in Windows 7, through the "shell" command in R.
```
shell('set PATH=%PATH%;"C:\\Program%20Files%20(x86)\\Git\\bin"', intern = TRUE)
shell("echo %PATH% ", intern= TRUE)
```
But I do not see that path added.
If I run the above code in... | If you want to permanantly update your path, then you pretty much had the answer:
```
shell('setx PATH "C:\\Program Files (x86)\\Git\\bin"')
```
R only notes a copy of the Windows environment variables when it starts up though, so `strsplit(Sys.getenv("PATH"), ";")` won't be different until you restart R.
Also, this... |
24462367 | Parsing string to integer in BeanShell Sampler in JMeter | 8 | 2014-06-28 00:12:39 | <p>I'm trying to parse a string into integer in JMeter but failed due to following error. If I try to print the strings returned by vars.get, they look good.</p>
<pre><code>2014/06/28 00:08:52 WARN - jmeter.assertions.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Source... | 48,552 | 2,182,674 | 2014-06-28 12:09:06 | 24,466,663 | 14 | 2014-06-28 12:09:06 | 2,897,748 | 2014-06-28 12:09:06 | https://stackoverflow.com/q/24462367 | https://stackoverflow.com/a/24466663 | <p>Your code looks good however it can be a problem with <code>currentPMCount</code> and/or <code>pmViolationMaxCount</code> variables. </p>
<p>If they really look good and look like Integers and don't exceed maximum/minimum values of Integer you can try the following:</p>
<ol>
<li><p>Make sure that there are no "spa... | <p>Your code looks good however it can be a problem with <code>currentPMCount</code> and/or <code>pmViolationMaxCount</code> variables. </p> <p>If they really look good and look like Integers and don't exceed maximum/minimum values of Integer you can try the following:</p> <ol> <li><p>Make sure that there are no "spa... | 17, 139, 2054, 8401, 13554 | beanshell, integer, java, jmeter, string | <h1>Parsing string to integer in BeanShell Sampler in JMeter</h1>
<p>I'm trying to parse a string into integer in JMeter but failed due to following error. If I try to print the strings returned by vars.get, they look good.</p>
<pre><code>2014/06/28 00:08:52 WARN - jmeter.assertions.BeanShellAssertion: org.apache.jor... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,878 | bash | # Parsing string to integer in BeanShell Sampler in JMeter
I'm trying to parse a string into integer in JMeter but failed due to following error. If I try to print the strings returned by vars.get, they look good.
```
2014/06/28 00:08:52 WARN - jmeter.assertions.BeanShellAssertion: org.apache.jorphan.util.JMeterExce... | Your code looks good however it can be a problem with `currentPMCount` and/or `pmViolationMaxCount` variables.
If they really look good and look like Integers and don't exceed maximum/minimum values of Integer you can try the following:
1. Make sure that there are no "space" characters around number value as leading ... |
24245858 | Powershell Missing statement block after if | 8 | 2014-06-16 14:20:12 | <p>I have the follow code. But there is a {[( )]} missing somewhere. I can't find it.
I is in the 'if section. But I dont know why it isnt working
If someone can give a tip or something is it will be create. </p>
<p>Thanks for reading. </p>
<pre><code>$date = (get-date).AddDays(-1).ToString("yyyMMdd")
$errora... | 60,782 | 2,355,506 | 2014-06-16 23:26:35 | 24,246,071 | 14 | 2014-06-16 14:32:06 | null | 2014-06-16 23:26:35 | https://stackoverflow.com/q/24245858 | https://stackoverflow.com/a/24246071 | <p>
In PowerShell, all <a href="http://www.computerperformance.co.uk/powershell/powershell_if_statement.htm" rel="noreferrer">if-statements</a> need braces to enclose their bodies. Below is a demonstration:</p>
<pre class="lang-powershell prettyprint-override"><code>PS > if ($true) write 'true'
At line:1 char:10
+... | <p> In PowerShell, all <a href="http://www.computerperformance.co.uk/powershell/powershell_if_statement.htm" rel="noreferrer">if-statements</a> need braces to enclose their bodies. Below is a demonstration:</p> <pre class="lang-powershell prettyprint-override"><code>PS > if ($true) write 'true' At line:1 char:10 +... | 526, 9993 | powershell, syntax-error | <h1>Powershell Missing statement block after if</h1>
<p>I have the follow code. But there is a {[( )]} missing somewhere. I can't find it.
I is in the 'if section. But I dont know why it isnt working
If someone can give a tip or something is it will be create. </p>
<p>Thanks for reading. </p>
<pre><code>$date ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,879 | bash | # Powershell Missing statement block after if
I have the follow code. But there is a {[( )]} missing somewhere. I can't find it.
I is in the 'if section. But I dont know why it isnt working
If someone can give a tip or something is it will be create.
Thanks for reading.
```
$date = (get-date).AddDays(-1).ToSt... | In PowerShell, all [if-statements](http://www.computerperformance.co.uk/powershell/powershell_if_statement.htm) need braces to enclose their bodies. Below is a demonstration:
```
PS > if ($true) write 'true'
At line:1 char:10
+ if ($true) write 'true'
+ ~
Missing statement block after if ( condition ).
+ ... |
24219287 | adb pull file in a specific folder of Pc | 8 | 2014-06-14 11:06:11 | <p>I want to save the screenshot created, in a specific folder on my PC.</p>
<pre><code>cmd = 'adb shell screencap -p /sdcard/screen.png'
subprocess.Popen(cmd.split())
time.sleep(5)
cmd ='adb pull /sdcard/screen.png screen.png'
subprocess.Popen(cmd.split())
</code></pre>
<p>This works if I want the image in my wor... | 35,353 | 3,482,189 | 2020-03-25 01:22:39 | 24,219,661 | 14 | 2014-06-14 11:55:45 | 2,855,059 | 2014-06-14 11:55:45 | https://stackoverflow.com/q/24219287 | https://stackoverflow.com/a/24219661 | <p>Always use double quotes("") for local paths. use it like this:</p>
<pre><code>cmd = "adb pull /sdcard/screen.png \"C:\\Users\\xxx\\Desktop\\prova\\screen.png\"";
</code></pre>
| <p>Always use double quotes("") for local paths. use it like this:</p> <pre><code>cmd = "adb pull /sdcard/screen.png \"C:\\Users\\xxx\\Desktop\\prova\\screen.png\""; </code></pre> | 16, 390, 1386, 4860, 22975 | adb, android, pull, python, shell | <h1>adb pull file in a specific folder of Pc</h1>
<p>I want to save the screenshot created, in a specific folder on my PC.</p>
<pre><code>cmd = 'adb shell screencap -p /sdcard/screen.png'
subprocess.Popen(cmd.split())
time.sleep(5)
cmd ='adb pull /sdcard/screen.png screen.png'
subprocess.Popen(cmd.split())
</code><... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,880 | bash | # adb pull file in a specific folder of Pc
I want to save the screenshot created, in a specific folder on my PC.
```
cmd = 'adb shell screencap -p /sdcard/screen.png'
subprocess.Popen(cmd.split())
time.sleep(5)
cmd ='adb pull /sdcard/screen.png screen.png'
subprocess.Popen(cmd.split())
```
This works if I want the... | Always use double quotes("") for local paths. use it like this:
```
cmd = "adb pull /sdcard/screen.png \"C:\\Users\\xxx\\Desktop\\prova\\screen.png\"";
``` |
23612563 | bash - get directory a script is run from | 8 | 2014-05-12 15:04:40 | <p>So I'm learning some bash and I'm trying to figure out how to get the directory a script is run from. So given that I have my script <code>~/scripts/bash/myscript</code>, if I execute my scipt like:</p>
<pre><code>user@localhost ~/dir/I/need/to/run/the/script/from $ ~/scripts/bash/myscript
</code></pre>
<p>from wi... | 6,018 | 937,271 | 2014-05-12 15:18:55 | 23,612,867 | 14 | 2014-05-12 15:18:55 | 7,552 | 2014-05-12 15:18:55 | https://stackoverflow.com/q/23612563 | https://stackoverflow.com/a/23612867 | <p>The <a href="http://www.gnu.org/software/bash/manual/bashref.html#index-PWD" rel="noreferrer"><code>$PWD</code></a> variable is probably what you need.</p>
<pre><code>$ cat >/tmp/pwd.bash <<'END'
#!/bin/bash
echo "\$0=$0"
echo "\$PWD=$PWD"
END
$ chmod u+x /tmp/pwd.bash
$ pwd
/home/jackman
$ /tmp/pwd.bas... | <p>The <a href="http://www.gnu.org/software/bash/manual/bashref.html#index-PWD" rel="noreferrer"><code>$PWD</code></a> variable is probably what you need.</p> <pre><code>$ cat >/tmp/pwd.bash <<'END' #!/bin/bash echo "\$0=$0" echo "\$PWD=$PWD" END $ chmod u+x /tmp/pwd.bash $ pwd /home/jackman $ /tmp/pwd.bas... | 58, 369, 387, 390 | bash, linux, macos, shell | <h1>bash - get directory a script is run from</h1>
<p>So I'm learning some bash and I'm trying to figure out how to get the directory a script is run from. So given that I have my script <code>~/scripts/bash/myscript</code>, if I execute my scipt like:</p>
<pre><code>user@localhost ~/dir/I/need/to/run/the/script/from ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,881 | bash | # bash - get directory a script is run from
So I'm learning some bash and I'm trying to figure out how to get the directory a script is run from. So given that I have my script `~/scripts/bash/myscript`, if I execute my scipt like:
```
user@localhost ~/dir/I/need/to/run/the/script/from $ ~/scripts/bash/myscript
```
... | The [`$PWD`](http://www.gnu.org/software/bash/manual/bashref.html#index-PWD) variable is probably what you need.
```
$ cat >/tmp/pwd.bash <<'END'
#!/bin/bash
echo "\$0=$0"
echo "\$PWD=$PWD"
END
$ chmod u+x /tmp/pwd.bash
$ pwd
/home/jackman
$ /tmp/pwd.bash
$0=/tmp/pwd.bash
$PWD=/home/jackman
``` |
23560215 | replace xml value with sed | 8 | 2014-05-09 08:43:29 | <p>I would like to replace value in XML file. Sample XML</p>
<pre><code><Console>
<!-- REQUIRED PARAMETERS -->
<!-- Enter the node that you are running the installation program from. This value must be a fully qualified name, which includes a host name and domain name. For... | 35,588 | 3,606,551 | 2024-04-20 23:33:33 | 23,561,009 | 14 | 2014-05-09 09:24:28 | 2,885,763 | 2024-04-20 23:33:33 | https://stackoverflow.com/q/23560215 | https://stackoverflow.com/a/23561009 | <pre class="lang-bash prettyprint-override"><code>sed -i -e '/<Console>/,/<\/Console>/ s|<node>[0-9a-z.]\{1,\}</node>|<node>newvalue</node>|g' YourFile
</code></pre>
<p>i assume value is between your tag and and only contain small letter, dot and digit (based on your sample and try... | <pre class="lang-bash prettyprint-override"><code>sed -i -e '/<Console>/,/<\/Console>/ s|<node>[0-9a-z.]\{1,\}</node>|<node>newvalue</node>|g' YourFile </code></pre> <p>i assume value is between your tag and and only contain small letter, dot and digit (based on your sample and try... | 19, 387, 5282 | bash, sed, xml | <h1>replace xml value with sed</h1>
<p>I would like to replace value in XML file. Sample XML</p>
<pre><code><Console>
<!-- REQUIRED PARAMETERS -->
<!-- Enter the node that you are running the installation program from. This value must be a fully qualified name, which inclu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,882 | bash | # replace xml value with sed
I would like to replace value in XML file. Sample XML
```
<Console>
<!-- REQUIRED PARAMETERS -->
<!-- Enter the node that you are running the installation program from. This value must be a fully qualified name, which includes a host name and domain name. F... | ```
sed -i -e '/<Console>/,/<\/Console>/ s|<node>[0-9a-z.]\{1,\}</node>|<node>newvalue</node>|g' YourFile
```
i assume value is between your tag and and only contain small letter, dot and digit (based on your sample and try). If extended, just add character missing in the class like `[0-9a-z._-A-Z:]` and maybe sub-cla... |
22892284 | How to check if the directory is symlink in chef | 8 | 2014-04-06 09:40:44 | <p>I just want to do delete directory if it is not symlnik. </p>
<pre><code>directory "/var/www/html/" do
action :delete
only_if ???
end
</code></pre>
| 6,020 | 1,245,142 | 2015-03-18 17:04:23 | 22,898,010 | 14 | 2014-04-06 18:18:53 | 365,738 | 2015-03-18 17:04:23 | https://stackoverflow.com/q/22892284 | https://stackoverflow.com/a/22898010 | <p>The selected answer will not work on Windows or systems where Bash is the default interpreter. You should use a Ruby solution to be cross-platform (and faster, since there's no process spawning):</p>
<pre class="lang-rb prettyprint-override"><code>directory '/var/www/html' do
action :delete
not_if { File.symlin... | <p>The selected answer will not work on Windows or systems where Bash is the default interpreter. You should use a Ruby solution to be cross-platform (and faster, since there's no process spawning):</p> <pre class="lang-rb prettyprint-override"><code>directory '/var/www/html' do action :delete not_if { File.symlin... | 390, 46913 | chef-infra, shell | <h1>How to check if the directory is symlink in chef</h1>
<p>I just want to do delete directory if it is not symlnik. </p>
<pre><code>directory "/var/www/html/" do
action :delete
only_if ???
end
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,883 | bash | # How to check if the directory is symlink in chef
I just want to do delete directory if it is not symlnik.
```
directory "/var/www/html/" do
action :delete
only_if ???
end
``` | The selected answer will not work on Windows or systems where Bash is the default interpreter. You should use a Ruby solution to be cross-platform (and faster, since there's no process spawning):
```
directory '/var/www/html' do
action :delete
not_if { File.symlink?('/var/www/html') }
end
``` |
22798333 | Unary operator expected in Bash | 8 | 2014-04-01 22:43:12 | <p>I've seen questions regarding the same issue, but all of them are about strings. How about integers? Why am I getting the "unary operator expected" error?</p>
<pre><code> if [ $(date +%k%M) -ge ${!BLOCK1FRAN} ] ; then whatever ; fi
</code></pre>
| 22,922 | 2,589,223 | 2021-10-05 16:54:52 | 22,799,695 | 14 | 2014-04-02 01:03:20 | 3,088,572 | 2021-10-05 16:54:52 | https://stackoverflow.com/q/22798333 | https://stackoverflow.com/a/22799695 | <p>You are using indirection. If the variable <code>${BLOCK1FRAN}</code> points to an empty variable, you'll get the error message. Make sure that the variable pointed by <code>${BLOCK1FRAN}</code> contains a valid numeric value.</p>
<p>If you want an empty string and nonnumeric values to be evaluated as zero (<code>0<... | <p>You are using indirection. If the variable <code>${BLOCK1FRAN}</code> points to an empty variable, you'll get the error message. Make sure that the variable pointed by <code>${BLOCK1FRAN}</code> contains a valid numeric value.</p> <p>If you want an empty string and nonnumeric values to be evaluated as zero (<code>0<... | 387, 2054, 53836 | bash, integer, operator-keyword | <h1>Unary operator expected in Bash</h1>
<p>I've seen questions regarding the same issue, but all of them are about strings. How about integers? Why am I getting the "unary operator expected" error?</p>
<pre><code> if [ $(date +%k%M) -ge ${!BLOCK1FRAN} ] ; then whatever ; fi
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,884 | bash | # Unary operator expected in Bash
I've seen questions regarding the same issue, but all of them are about strings. How about integers? Why am I getting the "unary operator expected" error?
```
if [ $(date +%k%M) -ge ${!BLOCK1FRAN} ] ; then whatever ; fi
``` | You are using indirection. If the variable `${BLOCK1FRAN}` points to an empty variable, you'll get the error message. Make sure that the variable pointed by `${BLOCK1FRAN}` contains a valid numeric value.
If you want an empty string and nonnumeric values to be evaluated as zero (`0`), use the following syntax.
```
if... |
22117937 | How can the arguments to bash script be copied for separate processing? | 8 | 2014-03-01 17:44:14 | <p>There is an existing bash script I need to modify, but I want to encapsulate the changes required to it in a function without affect how it manipulates the '$@' variable.</p>
<p>My idea is to copy the argument string to a new variable and extract the arguments required separately, but it seems that applying the 'sh... | 3,733 | 172,406 | 2014-03-01 18:11:46 | 22,117,981 | 14 | 2014-03-01 17:48:22 | 548,225 | 2014-03-01 18:11:46 | https://stackoverflow.com/q/22117937 | https://stackoverflow.com/a/22117981 | <p>You can preserve the <code>$@</code> into a BASH array:</p>
<pre><code>args=("$@")
</code></pre>
<p>And construct/retrieve/process original arguments anytime from BASH array <code>"${args[@]}"</code></p>
| <p>You can preserve the <code>$@</code> into a BASH array:</p> <pre><code>args=("$@") </code></pre> <p>And construct/retrieve/process original arguments anytime from BASH array <code>"${args[@]}"</code></p> | 387, 426, 31134 | bash, command-line-arguments, processing | <h1>How can the arguments to bash script be copied for separate processing?</h1>
<p>There is an existing bash script I need to modify, but I want to encapsulate the changes required to it in a function without affect how it manipulates the '$@' variable.</p>
<p>My idea is to copy the argument string to a new variable ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,885 | bash | # How can the arguments to bash script be copied for separate processing?
There is an existing bash script I need to modify, but I want to encapsulate the changes required to it in a function without affect how it manipulates the '$@' variable.
My idea is to copy the argument string to a new variable and extract the ... | You can preserve the `$@` into a BASH array:
```
args=("$@")
```
And construct/retrieve/process original arguments anytime from BASH array `"${args[@]}"` |
21140815 | How do I modify cygwin's PS1 for git bash completion? | 8 | 2014-01-15 15:00:12 | <p>Here is my current PS1:</p>
<pre><code>$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
</code></pre>
<p>I have installed git bash completion and it isn't showing the current branch in my command prompt. I think this needs to be edited but I've got no idea what to change to make it show the cur... | 7,014 | 157,971 | 2021-09-03 12:15:29 | 21,141,058 | 14 | 2014-01-15 15:11:11 | 354,577 | 2014-01-15 15:24:43 | https://stackoverflow.com/q/21140815 | https://stackoverflow.com/a/21141058 | <p>Modify the prompt string and add <code>$(__git_ps1 " (%s)")</code> somewhere.</p>
<p>For example, try typing this into Bash:</p>
<pre><code>export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]$(__git_ps1 ' (%s)')\n\$"
</code></pre>
<p>Once you find something you like, add that line to one of Bash's st... | <p>Modify the prompt string and add <code>$(__git_ps1 " (%s)")</code> somewhere.</p> <p>For example, try typing this into Bash:</p> <pre><code>export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]$(__git_ps1 ' (%s)')\n\$" </code></pre> <p>Once you find something you like, add that line to one of Bash's st... | 119, 387, 1731, 61874 | bash, cygwin, git, git-bash | <h1>How do I modify cygwin's PS1 for git bash completion?</h1>
<p>Here is my current PS1:</p>
<pre><code>$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
</code></pre>
<p>I have installed git bash completion and it isn't showing the current branch in my command prompt. I think this needs to be edi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,886 | bash | # How do I modify cygwin's PS1 for git bash completion?
Here is my current PS1:
```
$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
```
I have installed git bash completion and it isn't showing the current branch in my command prompt. I think this needs to be edited but I've got no idea what to ... | Modify the prompt string and add `$(__git_ps1 " (%s)")` somewhere.
For example, try typing this into Bash:
```
export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]$(__git_ps1 ' (%s)')\n\$"
```
Once you find something you like, add that line to one of Bash's startup files, e.g. `$HOME/.bashrc`.
The [sour... |
20892626 | Python β time.time() vs. bash time | 8 | 2014-01-02 21:52:44 | <p>I've been working on some Project Euler problems in Python 3 [osx 10.9], and I like to know how long they take to run.</p>
<p>I've been using the following two approaches to time my programs:</p>
<p>1)</p>
<pre><code>import time
start = time.time()
[program]
print(time.time() - start)
</code></pre>
<p>2) On th... | 4,505 | 1,631,673 | 2014-01-03 03:14:45 | 20,892,693 | 14 | 2014-01-02 21:58:20 | 100,297 | 2014-01-02 21:58:20 | https://stackoverflow.com/q/20892626 | https://stackoverflow.com/a/20892693 | <p>The interpreter imports <code>site.py</code> and can touch upon various other files on start-up. This all takes time before your <code>import time</code> line is ever executed:</p>
<pre><code>$ touch empty.py
$ time python3 empty.py
real 0m0.158s
user 0m0.033s
sys 0m0.021s
</code></pre>
<p>When timing ... | <p>The interpreter imports <code>site.py</code> and can touch upon various other files on start-up. This all takes time before your <code>import time</code> line is ever executed:</p> <pre><code>$ touch empty.py $ time python3 empty.py real 0m0.158s user 0m0.033s sys 0m0.021s </code></pre> <p>When timing ... | 16, 369, 387, 603 | bash, macos, python, time | <h1>Python β time.time() vs. bash time</h1>
<p>I've been working on some Project Euler problems in Python 3 [osx 10.9], and I like to know how long they take to run.</p>
<p>I've been using the following two approaches to time my programs:</p>
<p>1)</p>
<pre><code>import time
start = time.time()
[program]
print(tim... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,887 | bash | # Python β time.time() vs. bash time
I've been working on some Project Euler problems in Python 3 [osx 10.9], and I like to know how long they take to run.
I've been using the following two approaches to time my programs:
1)
```
import time
start = time.time()
[program]
print(time.time() - start)
```
2) On the b... | The interpreter imports `site.py` and can touch upon various other files on start-up. This all takes time before your `import time` line is ever executed:
```
$ touch empty.py
$ time python3 empty.py
real 0m0.158s
user 0m0.033s
sys 0m0.021s
```
When timing code, take into account that other processes, dis... |
20555605 | How can I install the grunt-cli without getting errors? | 8 | 2013-12-12 22:29:43 | <p>Inspired by Chris Coyier's <a href="http://24ways.org/2013/grunt-is-not-weird-and-hard/">post</a>, I decided I'd give grunt a go. But I'm having big problems getting set up. </p>
<p>First, I installed Node. </p>
<p>Then I added a package.json file to my project root, including this:</p>
<pre><code>{
"name": "ex... | 20,849 | 2,472,219 | 2016-07-26 20:01:23 | 20,558,396 | 14 | 2013-12-13 03:06:59 | 2,472,219 | 2014-06-03 18:46:19 | https://stackoverflow.com/q/20555605 | https://stackoverflow.com/a/20558396 | <p>All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.</p>
<pre><code>sudo npm install -g grunt-cli
</code></pre>
<p>Hope this helps someone!</p>
| <p>All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.</p> <pre><code>sudo npm install -g grunt-cli </code></pre> <p>Hope this helps someone!</p> | 387, 46426, 80988 | bash, gruntjs, node.js | <h1>How can I install the grunt-cli without getting errors?</h1>
<p>Inspired by Chris Coyier's <a href="http://24ways.org/2013/grunt-is-not-weird-and-hard/">post</a>, I decided I'd give grunt a go. But I'm having big problems getting set up. </p>
<p>First, I installed Node. </p>
<p>Then I added a package.json file to... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,888 | bash | # How can I install the grunt-cli without getting errors?
Inspired by Chris Coyier's [post](http://24ways.org/2013/grunt-is-not-weird-and-hard/), I decided I'd give grunt a go. But I'm having big problems getting set up.
First, I installed Node.
Then I added a package.json file to my project root, including this:
`... | All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.
```
sudo npm install -g grunt-cli
```
Hope this helps someone! |
18669756 | BASH - How to extract data from a column in CSV file and put it in an array? | 8 | 2013-09-07 04:38:09 | <p>I am learning to script in Bash.</p>
<p>I have a CSV file with 5 columns and 22 rows. I am interested in taking the data from the second column and put it into an array. </p>
<p>What I want is that the first name be in <code>array[0]</code>, the second in <code>array[1]</code> and so on.</p>
<p>Bash script:</p>
... | 60,364 | 2,756,247 | 2021-02-09 03:13:40 | 18,669,878 | 14 | 2013-09-07 04:56:29 | 2,704,585 | 2021-02-09 03:13:40 | https://stackoverflow.com/q/18669756 | https://stackoverflow.com/a/18669878 | <p>Remove the <code>IFS=","</code> assignment thereby letting the default IFS value of space, tab, newline apply</p>
<pre><code>#!/bin/bash
eCollection=( $(cut -d ',' -f2 MyAssignment.csv ) )
printf "%s\n" "${eCollection[0]}"
</code></pre>
<p>Explained: The <code>eCollection</code> variab... | <p>Remove the <code>IFS=","</code> assignment thereby letting the default IFS value of space, tab, newline apply</p> <pre><code>#!/bin/bash eCollection=( $(cut -d ',' -f2 MyAssignment.csv ) ) printf "%s\n" "${eCollection[0]}" </code></pre> <p>Explained: The <code>eCollection</code> variab... | 73, 114, 387 | arrays, bash, csv | <h1>BASH - How to extract data from a column in CSV file and put it in an array?</h1>
<p>I am learning to script in Bash.</p>
<p>I have a CSV file with 5 columns and 22 rows. I am interested in taking the data from the second column and put it into an array. </p>
<p>What I want is that the first name be in <code>arra... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,889 | bash | # BASH - How to extract data from a column in CSV file and put it in an array?
I am learning to script in Bash.
I have a CSV file with 5 columns and 22 rows. I am interested in taking the data from the second column and put it into an array.
What I want is that the first name be in `array[0]`, the second in `array[1... | Remove the `IFS=","` assignment thereby letting the default IFS value of space, tab, newline apply
```
#!/bin/bash
eCollection=( $(cut -d ',' -f2 MyAssignment.csv ) )
printf "%s\n" "${eCollection[0]}"
```
Explained: The `eCollection` variable is an array due to the outer parenthesis. It is initialized with each elem... |
18662202 | Unix, split file into chunks of max N bytes, keeping complete lines | 8 | 2013-09-06 16:17:15 | <p>I'd like to split a file into chunks of maximum N bytes, while keeping complete lines.</p>
<p>Something like the following breaks up first and last lines of each chunk on exact byte boundries.</p>
<pre><code>split -b 100m -d data.tsv data.tsv.
</code></pre>
| 3,579 | 2,748,263 | 2013-09-06 16:50:51 | 18,662,536 | 14 | 2013-09-06 16:38:02 | 1,207,958 | 2013-09-06 16:50:51 | https://stackoverflow.com/q/18662202 | https://stackoverflow.com/a/18662536 | <p>Sounds like a job for <code>split -C</code>:</p>
<pre><code>split -C 100m -d data.tsv data.tsv.
</code></pre>
| <p>Sounds like a job for <code>split -C</code>:</p> <pre><code>split -C 100m -d data.tsv data.tsv. </code></pre> | 34, 387, 2193 | bash, split, unix | <h1>Unix, split file into chunks of max N bytes, keeping complete lines</h1>
<p>I'd like to split a file into chunks of maximum N bytes, while keeping complete lines.</p>
<p>Something like the following breaks up first and last lines of each chunk on exact byte boundries.</p>
<pre><code>split -b 100m -d data.tsv data... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,890 | bash | # Unix, split file into chunks of max N bytes, keeping complete lines
I'd like to split a file into chunks of maximum N bytes, while keeping complete lines.
Something like the following breaks up first and last lines of each chunk on exact byte boundries.
```
split -b 100m -d data.tsv data.tsv.
``` | Sounds like a job for `split -C`:
```
split -C 100m -d data.tsv data.tsv.
``` |
18492443 | Pass all parameters of one shell script to another | 8 | 2013-08-28 15:41:32 | <p>I have a shell script to which i am passing few parameters.
<code>Test1.sh -a 1 -b 2 -c "One Two Three"</code></p>
<p>Inside Test1.sh i am calling another shell script in the below fashion.
<code>Test2.sh $*</code></p>
<p>I want to pass all the parameters to Test2, that were passed to Test1 and also in the same fo... | 10,608 | 2,726,057 | 2013-08-28 15:51:52 | 18,492,575 | 14 | 2013-08-28 15:46:48 | 2,235,132 | 2013-08-28 15:51:52 | https://stackoverflow.com/q/18492443 | https://stackoverflow.com/a/18492575 | <p>You need to say:</p>
<pre><code>Test2.sh "$@"
</code></pre>
<p>Refer to <a href="http://www.gnu.org/software/bash/manual/bash.html#Special-Parameters">Special Parameters</a>:</p>
<blockquote>
<p><code>@</code> </p>
<p>Expands to the positional parameters, starting from one. When the
expansion occurs wi... | <p>You need to say:</p> <pre><code>Test2.sh "$@" </code></pre> <p>Refer to <a href="http://www.gnu.org/software/bash/manual/bash.html#Special-Parameters">Special Parameters</a>:</p> <blockquote> <p><code>@</code> </p> <p>Expands to the positional parameters, starting from one. When the expansion occurs wi... | 34, 390 | shell, unix | <h1>Pass all parameters of one shell script to another</h1>
<p>I have a shell script to which i am passing few parameters.
<code>Test1.sh -a 1 -b 2 -c "One Two Three"</code></p>
<p>Inside Test1.sh i am calling another shell script in the below fashion.
<code>Test2.sh $*</code></p>
<p>I want to pass all the parameters... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,891 | bash | # Pass all parameters of one shell script to another
I have a shell script to which i am passing few parameters.
`Test1.sh -a 1 -b 2 -c "One Two Three"`
Inside Test1.sh i am calling another shell script in the below fashion.
`Test2.sh $*`
I want to pass all the parameters to Test2, that were passed to Test1 and also... | You need to say:
```
Test2.sh "$@"
```
Refer to [Special Parameters](http://www.gnu.org/software/bash/manual/bash.html#Special-Parameters):
> `@`
>
> Expands to the positional parameters, starting from one. When the
> expansion occurs within double quotes, each parameter expands to a
> separate word. That is, `"$@"`... |
18251070 | remove only the last extension from file name | 8 | 2013-08-15 10:43:21 | <p>I have file names that look something similar to this </p>
<pre><code>name_1.23.ps.png
</code></pre>
<p>or</p>
<pre><code>name_1.23.ps.best
</code></pre>
<p>or </p>
<pre><code>name_1.23.ps
</code></pre>
<p>I want to take off the random file extensions on the end and be left with just </p>
<pre><code>name_1.23... | 26,736 | 1,958,508 | 2016-11-15 23:30:45 | 18,251,430 | 14 | 2013-08-15 11:06:04 | 164,835 | 2013-08-15 11:29:06 | https://stackoverflow.com/q/18251070 | https://stackoverflow.com/a/18251430 | <p>check this if it works for your requirement:</p>
<p><strong>sed</strong></p>
<pre><code>sed 's/\.[^.]*$//'
</code></pre>
<p><strong>grep</strong></p>
<pre><code>grep -Po '.*(?=\.)'
</code></pre>
<p>test:</p>
<pre><code>kent$ cat f
name_1.23.ps.png
name_1.23.ps.best
name_1.23.ps
name_1.23.ps
#sed:
kent$ sed ... | <p>check this if it works for your requirement:</p> <p><strong>sed</strong></p> <pre><code>sed 's/\.[^.]*$//' </code></pre> <p><strong>grep</strong></p> <pre><code>grep -Po '.*(?=\.)' </code></pre> <p>test:</p> <pre><code>kent$ cat f name_1.23.ps.png name_1.23.ps.best name_1.23.ps name_1.23.ps #sed: kent$ sed ... | 387, 5310, 5826, 8599 | bash, edit, file, tcsh | <h1>remove only the last extension from file name</h1>
<p>I have file names that look something similar to this </p>
<pre><code>name_1.23.ps.png
</code></pre>
<p>or</p>
<pre><code>name_1.23.ps.best
</code></pre>
<p>or </p>
<pre><code>name_1.23.ps
</code></pre>
<p>I want to take off the random file extensions on t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,892 | bash | # remove only the last extension from file name
I have file names that look something similar to this
```
name_1.23.ps.png
```
or
```
name_1.23.ps.best
```
or
```
name_1.23.ps
```
I want to take off the random file extensions on the end and be left with just
```
name_1.23.ps
```
Other questions similar to this... | check this if it works for your requirement:
**sed**
```
sed 's/\.[^.]*$//'
```
**grep**
```
grep -Po '.*(?=\.)'
```
test:
```
kent$ cat f
name_1.23.ps.png
name_1.23.ps.best
name_1.23.ps
name_1.23.ps
#sed:
kent$ sed 's/\.[^.]*$//' f
name_1.23.ps
name_1.23.ps
name_1.23
name_1.23
#grep
kent$ grep -Po '.*(?=\.)... |
16961084 | LINUX Shell commands cat and grep | 8 | 2013-06-06 11:34:52 | <p>I am a windows user having basic idea about LINUX and i encountered this command:</p>
<pre><code>cat countryInfo.txt | grep -v "^#" >countryInfo-n.txt
</code></pre>
<p>After some research i found that cat is for concatenation and grep is for regular exp search (don't know if i am right) but what will the above ... | 64,424 | 988,268 | 2013-06-06 11:41:17 | 16,961,185 | 14 | 2013-06-06 11:39:28 | 400,056 | 2013-06-06 11:39:28 | https://stackoverflow.com/q/16961084 | https://stackoverflow.com/a/16961185 | <p>Short answer: it removes all lines starting with a <code>#</code> and stores the result in <code>countryInfo-n.txt</code>.</p>
<p>Long explanation:</p>
<p><code>cat countryInfo.txt</code> reads the file <code>countryInfo.txt</code> and streams its content to standard output.</p>
<p><code>|</code> connects the out... | <p>Short answer: it removes all lines starting with a <code>#</code> and stores the result in <code>countryInfo-n.txt</code>.</p> <p>Long explanation:</p> <p><code>cat countryInfo.txt</code> reads the file <code>countryInfo.txt</code> and streams its content to standard output.</p> <p><code>|</code> connects the out... | 58, 390 | linux, shell | <h1>LINUX Shell commands cat and grep</h1>
<p>I am a windows user having basic idea about LINUX and i encountered this command:</p>
<pre><code>cat countryInfo.txt | grep -v "^#" >countryInfo-n.txt
</code></pre>
<p>After some research i found that cat is for concatenation and grep is for regular exp search (don't k... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,893 | bash | # LINUX Shell commands cat and grep
I am a windows user having basic idea about LINUX and i encountered this command:
```
cat countryInfo.txt | grep -v "^#" >countryInfo-n.txt
```
After some research i found that cat is for concatenation and grep is for regular exp search (don't know if i am right) but what will the... | Short answer: it removes all lines starting with a `#` and stores the result in `countryInfo-n.txt`.
Long explanation:
`cat countryInfo.txt` reads the file `countryInfo.txt` and streams its content to standard output.
`|` connects the output of the left command with the input of the right command (so the right comma... |
16838837 | How to get the name of an object property in powershell? | 8 | 2013-05-30 14:27:43 | <p>I know I can use get-member to get all the properties of an object but I'm going through a list of objects and I'm interested in the very last property whose name keeps changing. To automate my script, I'm trying to get the name of that last property but I'm not sure how.</p>
<p>Let's say I have:</p>
<pre><code>$r... | 47,471 | 780,392 | 2013-05-30 14:35:57 | 16,838,974 | 14 | 2013-05-30 14:34:06 | 520,612 | 2013-05-30 14:34:06 | https://stackoverflow.com/q/16838837 | https://stackoverflow.com/a/16838974 | <p>try:</p>
<pre><code>( $result | get-member)[-1]
</code></pre>
| <p>try:</p> <pre><code>( $result | get-member)[-1] </code></pre> | 526, 4898, 6981 | object, powershell, properties | <h1>How to get the name of an object property in powershell?</h1>
<p>I know I can use get-member to get all the properties of an object but I'm going through a list of objects and I'm interested in the very last property whose name keeps changing. To automate my script, I'm trying to get the name of that last property ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,894 | bash | # How to get the name of an object property in powershell?
I know I can use get-member to get all the properties of an object but I'm going through a list of objects and I'm interested in the very last property whose name keeps changing. To automate my script, I'm trying to get the name of that last property but I'm n... | try:
```
( $result | get-member)[-1]
``` |
16734918 | Executing KornShell script | 8 | 2013-05-24 12:24:17 | <p>I can't execute my KornShell (ksh) script without the <code>ksh</code> command. I included <code>#!/bin/ksh</code> in the first line of the script but when I try to execute it by name only, it says no such file or directory. Can someone help me?</p>
| 100,102 | 2,350,150 | 2014-01-02 20:51:25 | 16,734,980 | 14 | 2013-05-24 12:28:16 | 1,120,221 | 2013-05-24 12:38:29 | https://stackoverflow.com/q/16734918 | https://stackoverflow.com/a/16734980 | <ul>
<li><p>make sure that <code>ksh</code> is correctly installed in <code>/bin/ksh</code> </p>
<p>try <code>which ksh</code> from the command-line.</p>
<p>consider <code>#! /usr/bin/env ksh</code> for more portability.</p></li>
<li><p>for executing a <code>script</code> run from the command-line <code>./script</cod... | <ul> <li><p>make sure that <code>ksh</code> is correctly installed in <code>/bin/ksh</code> </p> <p>try <code>which ksh</code> from the command-line.</p> <p>consider <code>#! /usr/bin/env ksh</code> for more portability.</p></li> <li><p>for executing a <code>script</code> run from the command-line <code>./script</cod... | 34, 390, 1964 | ksh, shell, unix | <h1>Executing KornShell script</h1>
<p>I can't execute my KornShell (ksh) script without the <code>ksh</code> command. I included <code>#!/bin/ksh</code> in the first line of the script but when I try to execute it by name only, it says no such file or directory. Can someone help me?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,895 | bash | # Executing KornShell script
I can't execute my KornShell (ksh) script without the `ksh` command. I included `#!/bin/ksh` in the first line of the script but when I try to execute it by name only, it says no such file or directory. Can someone help me? | - make sure that `ksh` is correctly installed in `/bin/ksh`
try `which ksh` from the command-line.
consider `#! /usr/bin/env ksh` for more portability.
- for executing a `script` run from the command-line `./script` in the directory where `script` exist.
- If you want to execut the `script` from any directory wit... |
15662577 | Select multiple columns in powershell | 8 | 2013-03-27 15:22:26 | <p>This is probably a very noob powershell question, but here goes.</p>
<p>I want to select only a few properties for display when using a particular cmdlet, but when I club them using the select statement, only the first one in the select statement is shown.</p>
<p>E.g., the cmdlet I'm interested in is Get-VM</p>
<... | 44,414 | 819,415 | 2013-03-27 21:08:32 | 15,669,534 | 14 | 2013-03-27 21:08:32 | 674,943 | 2013-03-27 21:08:32 | https://stackoverflow.com/q/15662577 | https://stackoverflow.com/a/15669534 | <p>I would suspect issue with size of buffer/ window. If buffer is wider than buffer than some columns may become "invisible". State, as an <code>[enum]</code> (read: <code>[int]</code> in disguise) will be always right-aligned by default. Name (<code>[string]</code>) will be aligned left. Suspect you would see everyth... | <p>I would suspect issue with size of buffer/ window. If buffer is wider than buffer than some columns may become "invisible". State, as an <code>[enum]</code> (read: <code>[int]</code> in disguise) will be always right-aligned by default. Name (<code>[string]</code>) will be aligned left. Suspect you would see everyth... | 73157 | powershell-3.0 | <h1>Select multiple columns in powershell</h1>
<p>This is probably a very noob powershell question, but here goes.</p>
<p>I want to select only a few properties for display when using a particular cmdlet, but when I club them using the select statement, only the first one in the select statement is shown.</p>
<p>E.g.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,896 | bash | # Select multiple columns in powershell
This is probably a very noob powershell question, but here goes.
I want to select only a few properties for display when using a particular cmdlet, but when I club them using the select statement, only the first one in the select statement is shown.
E.g., the cmdlet I'm intere... | I would suspect issue with size of buffer/ window. If buffer is wider than buffer than some columns may become "invisible". State, as an `[enum]` (read: `[int]` in disguise) will be always right-aligned by default. Name (`[string]`) will be aligned left. Suspect you would see everything by simply changing order.
Take ... |
15343447 | Bash style process substitution with Python's Popen | 8 | 2013-03-11 16:17:51 | <p>In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this:</p>
<pre><code>$ mydaemon --config-file <(echo "autostart: True \n daemonize: True")
</code></pre>
<p>or like this:</p>
<pre><code>$ wc -l <(ls)
15 /dev/fd/63
</code>... | 4,853 | 1,647,611 | 2013-03-11 19:16:31 | 15,343,686 | 14 | 2013-03-11 16:30:56 | 4,279 | 2013-03-11 19:16:31 | https://stackoverflow.com/q/15343447 | https://stackoverflow.com/a/15343686 | <p>If <code>pram_axdnull</code> understands <code>"-"</code> convention to mean: "read from stdin" then you could:</p>
<pre class="lang-py prettyprint-override"><code>p = Popen(["pram_axdnull", str(kmer), input_filename, "-"],
stdin=PIPE, stdout=PIPE)
output = p.communicate(generate_kmers(3))[0]
</code></p... | <p>If <code>pram_axdnull</code> understands <code>"-"</code> convention to mean: "read from stdin" then you could:</p> <pre class="lang-py prettyprint-override"><code>p = Popen(["pram_axdnull", str(kmer), input_filename, "-"], stdin=PIPE, stdout=PIPE) output = p.communicate(generate_kmers(3))[0] </code></p... | 16, 387, 2348, 9696 | bash, popen, python, subprocess | <h1>Bash style process substitution with Python's Popen</h1>
<p>In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this:</p>
<pre><code>$ mydaemon --config-file <(echo "autostart: True \n daemonize: True")
</code></pre>
<p>or like... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,897 | bash | # Bash style process substitution with Python's Popen
In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this:
```
$ mydaemon --config-file <(echo "autostart: True \n daemonize: True")
```
or like this:
```
$ wc -l <(ls)
15 /dev/fd... | If `pram_axdnull` understands `"-"` convention to mean: "read from stdin" then you could:
```
p = Popen(["pram_axdnull", str(kmer), input_filename, "-"],
stdin=PIPE, stdout=PIPE)
output = p.communicate(generate_kmers(3))[0]
```
If the input is generated by external process:
```
kmer_proc = Popen(["generate... |
13075361 | How to preserve newlines when using variables in here-strings | 8 | 2012-10-25 18:57:59 | <p>When running the following code:</p>
<pre><code> $txt = Get-Content file1.txt
$a = @"
-- file start --
$txt
-- file end --
"@
$a
</code></pre>
<p>All new lines are removed from the file's contents, but just running</p>
<pre><code>$txt
</code></pre>
<p>prints out the file without stri... | 9,040 | 1,509,282 | 2012-10-27 09:45:16 | 13,075,546 | 14 | 2012-10-25 19:10:25 | 9,833 | 2012-10-25 19:10:25 | https://stackoverflow.com/q/13075361 | https://stackoverflow.com/a/13075546 | <p>Pipe $txt to Out-String inside a sub-expression.</p>
<pre><code>$a = @"
-- file start --
$($txt | Out-String)
-- file end --
"@
</code></pre>
| <p>Pipe $txt to Out-String inside a sub-expression.</p> <pre><code>$a = @" -- file start -- $($txt | Out-String) -- file end -- "@ </code></pre> | 526 | powershell | <h1>How to preserve newlines when using variables in here-strings</h1>
<p>When running the following code:</p>
<pre><code> $txt = Get-Content file1.txt
$a = @"
-- file start --
$txt
-- file end --
"@
$a
</code></pre>
<p>All new lines are removed from the file's contents, but just running<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,898 | bash | # How to preserve newlines when using variables in here-strings
When running the following code:
```
$txt = Get-Content file1.txt
$a = @"
-- file start --
$txt
-- file end --
"@
$a
```
All new lines are removed from the file's contents, but just running
```
$txt
```
prints out the fil... | Pipe $txt to Out-String inside a sub-expression.
```
$a = @"
-- file start --
$($txt | Out-String)
-- file end --
"@
``` |
12273724 | How to iterate over a folder with a large number of files in PowerShell? | 8 | 2012-09-05 02:26:07 | <p>I'm trying to write a script that would go through 1.6 million files in a folder and move them to the correct folder based on the file name.</p>
<p>The reason is that NTFS can't handle a large number of files within a single folder without a degrade in performance. </p>
<p>The script call "Get-ChildItem" to get al... | 13,486 | 1,046,234 | 2016-02-25 14:13:45 | 12,274,440 | 14 | 2012-09-05 04:20:12 | 526,535 | 2014-07-09 14:51:22 | https://stackoverflow.com/q/12273724 | https://stackoverflow.com/a/12274440 | <p>If you do </p>
<pre><code>$files = Get-ChildItem $dirWithMillionsOfFiles
#Now, process with $files
</code></pre>
<p>you WILL face memory issues.</p>
<p>Use PowerShell piping to process the files:</p>
<pre><code>Get-ChildItem $dirWithMillionsOfFiles | %{
#process here
}
</code></pre>
<p>The second way will ... | <p>If you do </p> <pre><code>$files = Get-ChildItem $dirWithMillionsOfFiles #Now, process with $files </code></pre> <p>you WILL face memory issues.</p> <p>Use PowerShell piping to process the files:</p> <pre><code>Get-ChildItem $dirWithMillionsOfFiles | %{ #process here } </code></pre> <p>The second way will ... | 526 | powershell | <h1>How to iterate over a folder with a large number of files in PowerShell?</h1>
<p>I'm trying to write a script that would go through 1.6 million files in a folder and move them to the correct folder based on the file name.</p>
<p>The reason is that NTFS can't handle a large number of files within a single folder wi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,899 | bash | # How to iterate over a folder with a large number of files in PowerShell?
I'm trying to write a script that would go through 1.6 million files in a folder and move them to the correct folder based on the file name.
The reason is that NTFS can't handle a large number of files within a single folder without a degrade ... | If you do
```
$files = Get-ChildItem $dirWithMillionsOfFiles
#Now, process with $files
```
you WILL face memory issues.
Use PowerShell piping to process the files:
```
Get-ChildItem $dirWithMillionsOfFiles | %{
#process here
}
```
The second way will consume less memory and should ideally not grow beyond a ce... |
11868811 | Capturing the output of bash time in script variable | 8 | 2012-08-08 16:17:34 | <p>I'm trying this:</p>
<pre><code>TIMEFORMAT=%R;
foo=$(time wget http://www.mysite.com)
echo $foo
</code></pre>
<p>and when I execute I see the number I want in the output but not in variable foo (echo $foo print nothing). </p>
<p>Why is that?</p>
| 3,264 | 967,722 | 2024-03-15 17:45:35 | 11,868,986 | 14 | 2012-08-08 16:29:09 | 341,459 | 2015-02-09 04:09:40 | https://stackoverflow.com/q/11868811 | https://stackoverflow.com/a/11868986 | <p>You are not capturing anything in <code>foo</code> because <code>time</code> sends its output on <code>stderr</code>. The trouble is that the <code>wget</code> command also sends most of its output on <code>stderr</code>. To split the two streams (and throw away the output from <code>wget</code>) you will need to us... | <p>You are not capturing anything in <code>foo</code> because <code>time</code> sends its output on <code>stderr</code>. The trouble is that the <code>wget</code> command also sends most of its output on <code>stderr</code>. To split the two streams (and throw away the output from <code>wget</code>) you will need to us... | 387, 390, 603, 5583 | bash, shell, time, wget | <h1>Capturing the output of bash time in script variable</h1>
<p>I'm trying this:</p>
<pre><code>TIMEFORMAT=%R;
foo=$(time wget http://www.mysite.com)
echo $foo
</code></pre>
<p>and when I execute I see the number I want in the output but not in variable foo (echo $foo print nothing). </p>
<p>Why is that?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,900 | bash | # Capturing the output of bash time in script variable
I'm trying this:
```
TIMEFORMAT=%R;
foo=$(time wget http://www.mysite.com)
echo $foo
```
and when I execute I see the number I want in the output but not in variable foo (echo $foo print nothing).
Why is that? | You are not capturing anything in `foo` because `time` sends its output on `stderr`. The trouble is that the `wget` command also sends most of its output on `stderr`. To split the two streams (and throw away the output from `wget`) you will need to use a [subshell](http://tldp.org/LDP/abs/html/subshells.html):
```
TIM... |
11860452 | Why does "uniq" count identical words as different? | 8 | 2012-08-08 08:20:40 | <p>I want to calculate the frequency of the words from a file, where the words are one by line. The file is really big, so this might be the problem (it counts 300k lines in this example).</p>
<p>I do this command:</p>
<pre><code>cat .temp_occ | uniq -c | sort -k1,1nr -k2 > distribution.txt
</code></pre>
<p>and t... | 5,342 | 1,582,517 | 2019-09-12 22:42:20 | 11,860,524 | 14 | 2012-08-08 08:24:34 | 1,356,883 | 2012-08-08 08:24:34 | https://stackoverflow.com/q/11860452 | https://stackoverflow.com/a/11860524 | <p>Try to sort first:</p>
<pre><code>cat .temp_occ | sort| uniq -c | sort -k1,1nr -k2 > distribution.txt
</code></pre>
| <p>Try to sort first:</p> <pre><code>cat .temp_occ | sort| uniq -c | sort -k1,1nr -k2 > distribution.txt </code></pre> | 58, 387, 390, 35617 | bash, linux, shell, uniq | <h1>Why does "uniq" count identical words as different?</h1>
<p>I want to calculate the frequency of the words from a file, where the words are one by line. The file is really big, so this might be the problem (it counts 300k lines in this example).</p>
<p>I do this command:</p>
<pre><code>cat .temp_occ | uniq -c | s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,901 | bash | # Why does "uniq" count identical words as different?
I want to calculate the frequency of the words from a file, where the words are one by line. The file is really big, so this might be the problem (it counts 300k lines in this example).
I do this command:
```
cat .temp_occ | uniq -c | sort -k1,1nr -k2 > distribut... | Try to sort first:
```
cat .temp_occ | sort| uniq -c | sort -k1,1nr -k2 > distribution.txt
``` |
11762432 | Timing bash functions | 8 | 2012-08-01 15:22:49 | <p>I'd like to see how long it takes for a bash function to run. After doing a little research, I've come up with this approach which uses a sub-shell:</p>
<pre><code>function test-function() {
time (
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-... | 9,907 | 102,401 | 2012-08-01 18:28:44 | 11,762,949 | 14 | 2012-08-01 15:48:52 | 1,032,785 | 2012-08-01 18:28:44 | https://stackoverflow.com/q/11762432 | https://stackoverflow.com/a/11762949 | <p>You can use command grouping rather than a subshell:</p>
<pre><code>time { command1; command2; }
</code></pre>
<p>Update - more specific example:</p>
<pre><code>test-function() {
time {
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end-2/
# ... | <p>You can use command grouping rather than a subshell:</p> <pre><code>time { command1; command2; } </code></pre> <p>Update - more specific example:</p> <pre><code>test-function() { time { rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/ rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end-2/ # ... | 387, 603, 69858 | bash, bash-function, time | <h1>Timing bash functions</h1>
<p>I'd like to see how long it takes for a bash function to run. After doing a little research, I've come up with this approach which uses a sub-shell:</p>
<pre><code>function test-function() {
time (
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/
rsync -av ~/t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,902 | bash | # Timing bash functions
I'd like to see how long it takes for a bash function to run. After doing a little research, I've come up with this approach which uses a sub-shell:
```
function test-function() {
time (
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/
rsync -av ~/tmp/test-dir-start/ ... | You can use command grouping rather than a subshell:
```
time { command1; command2; }
```
Update - more specific example:
```
test-function() {
time {
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end/
rsync -av ~/tmp/test-dir-start/ ~/tmp/test-dir-end-2/
# etc...
}
}
``` |
11198023 | Why does an error still show when I specify -ErrorAction SilentlyContinue? | 8 | 2012-06-25 22:02:25 | <pre><code>PS C:\Users\ad_ctjares> Stop-Transcript -ErrorAction silentlycontinue
Transcription has not been started. Use the start-transcript command to start transcription.
Stop-Transcript : An error occurred stopping transcription: The console host is not currently transcribing.
At line:1 char:16
+ Stop-Transcript... | 11,012 | 264,675 | 2015-01-30 09:26:42 | 11,198,583 | 14 | 2012-06-25 22:58:11 | 153,982 | 2012-06-25 22:58:11 | https://stackoverflow.com/q/11198023 | https://stackoverflow.com/a/11198583 | <p>The <code>ErrorAction</code> ubiquitous parameter can be used to silence non-terminating errors using the parameter value <code>SilentlyContinue</code> and it can be used to convert non-terminating errors to terminating errors using the parameter value <code>Stop</code>. However it can't help you ignore terminating... | <p>The <code>ErrorAction</code> ubiquitous parameter can be used to silence non-terminating errors using the parameter value <code>SilentlyContinue</code> and it can be used to convert non-terminating errors to terminating errors using the parameter value <code>Stop</code>. However it can't help you ignore terminating... | 526 | powershell | <h1>Why does an error still show when I specify -ErrorAction SilentlyContinue?</h1>
<pre><code>PS C:\Users\ad_ctjares> Stop-Transcript -ErrorAction silentlycontinue
Transcription has not been started. Use the start-transcript command to start transcription.
Stop-Transcript : An error occurred stopping transcription:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,903 | bash | # Why does an error still show when I specify -ErrorAction SilentlyContinue?
```
PS C:\Users\ad_ctjares> Stop-Transcript -ErrorAction silentlycontinue
Transcription has not been started. Use the start-transcript command to start transcription.
Stop-Transcript : An error occurred stopping transcription: The console hos... | The `ErrorAction` ubiquitous parameter can be used to silence non-terminating errors using the parameter value `SilentlyContinue` and it can be used to convert non-terminating errors to terminating errors using the parameter value `Stop`. However it can't help you ignore terminating errors and in this case Stop-Transcr... |
10616831 | How to use string.format with string array in powershell | 8 | 2012-05-16 10:39:11 | <p>I want to output a formated string to console. I have one string variable and one string array variable.</p>
<p>When I do this:</p>
<pre><code>$arr = "aaa","bbb"
"test {0} + {1}" -f "first",$arr
</code></pre>
<p>The output is this:</p>
<pre><code>test first + System.Object[]
</code></pre>
<p>But I need output t... | 10,636 | 411,691 | 2012-05-16 10:49:58 | 10,616,951 | 14 | 2012-05-16 10:47:29 | 73,070 | 2012-05-16 10:47:29 | https://stackoverflow.com/q/10616831 | https://stackoverflow.com/a/10616951 | <p>Several options:</p>
<ol>
<li><p>Join the array first, so you don't rely on the default <code>ToString()</code> implementation (which just prints the class name):</p>
<pre><code>PS> 'test {0} + {1}' -f 'first',($arr -join ',')
test first + aaa,bbb
</code></pre></li>
<li><p>Use string interpolation:</p>
<pre><c... | <p>Several options:</p> <ol> <li><p>Join the array first, so you don't rely on the default <code>ToString()</code> implementation (which just prints the class name):</p> <pre><code>PS> 'test {0} + {1}' -f 'first',($arr -join ',') test first + aaa,bbb </code></pre></li> <li><p>Use string interpolation:</p> <pre><c... | 114, 526, 10232 | arrays, powershell, string-formatting | <h1>How to use string.format with string array in powershell</h1>
<p>I want to output a formated string to console. I have one string variable and one string array variable.</p>
<p>When I do this:</p>
<pre><code>$arr = "aaa","bbb"
"test {0} + {1}" -f "first",$arr
</code></pre>
<p>The output is this:</p>
<pre><code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,904 | bash | # How to use string.format with string array in powershell
I want to output a formated string to console. I have one string variable and one string array variable.
When I do this:
```
$arr = "aaa","bbb"
"test {0} + {1}" -f "first",$arr
```
The output is this:
```
test first + System.Object[]
```
But I need output... | Several options:
1. Join the array first, so you don't rely on the default `ToString()` implementation (which just prints the class name):
```
PS> 'test {0} + {1}' -f 'first',($arr -join ',')
test first + aaa,bbb
```
2. Use string interpolation:
```
PS> $first = 'first'
PS> "test $first + $arr"
... |
9540192 | How do I return a custom object in Powershell that's formatted as a table? | 8 | 2012-03-02 20:52:29 | <p>I'm pretty new to powershell, so I won't be surprised at all if I'm going about this all wrong. I'm trying to create a function that, when executed, prints results formatted as a table. Maybe it would even be possible to pipe those results to another function for further analysis.</p>
<p>Here's what I have so far. ... | 21,653 | 166,258 | 2012-03-04 04:01:58 | 9,540,677 | 14 | 2012-03-02 21:34:00 | 36,429 | 2012-03-04 04:01:58 | https://stackoverflow.com/q/9540192 | https://stackoverflow.com/a/9540677 | <p>How 'bout using </p>
<pre><code>return new-object psobject -Property $dirs
</code></pre>
<p>That would return an object whose properties match the items in the hashtable. Then you can use the built-in powershell formatting cmdlets to make it look like you want. since you only have 2 properties, it will be format... | <p>How 'bout using </p> <pre><code>return new-object psobject -Property $dirs </code></pre> <p>That would return an object whose properties match the items in the hashtable. Then you can use the built-in powershell formatting cmdlets to make it look like you want. since you only have 2 properties, it will be format... | 526 | powershell | <h1>How do I return a custom object in Powershell that's formatted as a table?</h1>
<p>I'm pretty new to powershell, so I won't be surprised at all if I'm going about this all wrong. I'm trying to create a function that, when executed, prints results formatted as a table. Maybe it would even be possible to pipe those r... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,905 | bash | # How do I return a custom object in Powershell that's formatted as a table?
I'm pretty new to powershell, so I won't be surprised at all if I'm going about this all wrong. I'm trying to create a function that, when executed, prints results formatted as a table. Maybe it would even be possible to pipe those results to... | How 'bout using
```
return new-object psobject -Property $dirs
```
That would return an object whose properties match the items in the hashtable. Then you can use the built-in powershell formatting cmdlets to make it look like you want. since you only have 2 properties, it will be formatted as a table by default.
ED... |
9398776 | Is there a bash command for converting an entire directory to HAML from HTML? | 8 | 2012-02-22 16:25:18 | <p>I'm looking to convert an entire directory of HTML to HAML so that the files have the same name but with a new extension.</p>
<pre><code>html2haml file.html.erb file.haml
</code></pre>
<p>Can I run a loop so that I can convert all these files all at once so that the name is the same just the extension is changed?<... | 2,572 | 93,311 | 2016-03-20 13:35:11 | 9,398,812 | 14 | 2012-02-22 16:27:43 | 221,213 | 2012-03-09 17:09:01 | https://stackoverflow.com/q/9398776 | https://stackoverflow.com/a/9398812 | <p>It's not sexy but it's working:</p>
<pre><code>for file in $(find . -type f -name \*.html.erb); do
html2haml -e ${file} "$(dirname ${file})/$(basename ${file} .erb).haml";
done
</code></pre>
<p>(Pay attention to the <code>-e</code> flag of <code>html2haml</code> it parses the ERb tags.)</p>
| <p>It's not sexy but it's working:</p> <pre><code>for file in $(find . -type f -name \*.html.erb); do html2haml -e ${file} "$(dirname ${file})/$(basename ${file} .erb).haml"; done </code></pre> <p>(Pay attention to the <code>-e</code> flag of <code>html2haml</code> it parses the ERb tags.)</p> | 387, 968, 4984, 77646 | bash, haml, html2haml, ruby-on-rails | <h1>Is there a bash command for converting an entire directory to HAML from HTML?</h1>
<p>I'm looking to convert an entire directory of HTML to HAML so that the files have the same name but with a new extension.</p>
<pre><code>html2haml file.html.erb file.haml
</code></pre>
<p>Can I run a loop so that I can convert a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,906 | bash | # Is there a bash command for converting an entire directory to HAML from HTML?
I'm looking to convert an entire directory of HTML to HAML so that the files have the same name but with a new extension.
```
html2haml file.html.erb file.haml
```
Can I run a loop so that I can convert all these files all at once so tha... | It's not sexy but it's working:
```
for file in $(find . -type f -name \*.html.erb); do
html2haml -e ${file} "$(dirname ${file})/$(basename ${file} .erb).haml";
done
```
(Pay attention to the `-e` flag of `html2haml` it parses the ERb tags.) |
8892813 | Emacs shell script mode hook | 8 | 2012-01-17 10:11:26 | <p>For some reason my shell script mode hooks do not get executed. Example in my .emacs:</p>
<p><code>(add-hook 'shell-script-mode-hook (lambda ()
(rainbow-delimiters-mode 1)))</code></p>
<p>causes the variables to be set, but the mode is not loaded for the opened script files. What is t... | 7,211 | 673,592 | 2016-04-26 13:04:40 | 8,894,933 | 14 | 2012-01-17 12:53:15 | 324,105 | 2016-04-26 13:03:59 | https://stackoverflow.com/q/8892813 | https://stackoverflow.com/a/8894933 | <p><code>shell-script-mode</code> is an alias for <code>sh-mode</code>. I haven't checked, but I would suspect that only the hook variable for the 'real' function name is evaluated, so I think <code>sh-mode-hook</code> would be the one to use.</p>
<p>Anyhow, there's nothing broken about your syntax, so there may be so... | <p><code>shell-script-mode</code> is an alias for <code>sh-mode</code>. I haven't checked, but I would suspect that only the hook variable for the 'real' function name is evaluated, so I think <code>sh-mode-hook</code> would be the one to use.</p> <p>Anyhow, there's nothing broken about your syntax, so there may be so... | 371, 387, 390 | bash, emacs, shell | <h1>Emacs shell script mode hook</h1>
<p>For some reason my shell script mode hooks do not get executed. Example in my .emacs:</p>
<p><code>(add-hook 'shell-script-mode-hook (lambda ()
(rainbow-delimiters-mode 1)))</code></p>
<p>causes the variables to be set, but the mode is not loaded ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,907 | bash | # Emacs shell script mode hook
For some reason my shell script mode hooks do not get executed. Example in my .emacs:
`(add-hook 'shell-script-mode-hook (lambda ()
(rainbow-delimiters-mode 1)))`
causes the variables to be set, but the mode is not loaded for the opened script files. What is the proper way to hook here... | `shell-script-mode` is an alias for `sh-mode`. I haven't checked, but I would suspect that only the hook variable for the 'real' function name is evaluated, so I think `sh-mode-hook` would be the one to use.
Anyhow, there's nothing broken about your syntax, so there may be something amiss with the use of `(rainbow-del... |
8413975 | 10 second delay between login and shell prompt. | 8 | 2011-12-07 10:39:43 | <p>I've got a strange problem. After I enter my password on a debian 6.0 system, I get the motd but then there is a 5-10 second pause until I get a shell prompt. If I press ctrl-c during that pause the prompt comes up instantly. What could be happening here? Am I killing the login process? Why might it be taking so lon... | 15,771 | null | 2024-09-14 00:46:47 | 8,414,667 | 14 | 2011-12-07 11:37:07 | null | 2011-12-07 11:37:07 | https://stackoverflow.com/q/8413975 | https://stackoverflow.com/a/8414667 | <p>You can debug bash shell scripts using <code>set -x</code> and <code>set +x</code>. The <code>set -x</code> command enables debug mode and the <code>set +x</code> command disables it. </p>
<p>Putting <code>set -x</code> at the top of your $HOME/.bash_profile should cause debug information to be printed for your per... | <p>You can debug bash shell scripts using <code>set -x</code> and <code>set +x</code>. The <code>set -x</code> command enables debug mode and the <code>set +x</code> command disables it. </p> <p>Putting <code>set -x</code> at the top of your $HOME/.bash_profile should cause debug information to be printed for your per... | 58, 183, 387 | authentication, bash, linux | <h1>10 second delay between login and shell prompt.</h1>
<p>I've got a strange problem. After I enter my password on a debian 6.0 system, I get the motd but then there is a 5-10 second pause until I get a shell prompt. If I press ctrl-c during that pause the prompt comes up instantly. What could be happening here? Am I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,908 | bash | # 10 second delay between login and shell prompt.
I've got a strange problem. After I enter my password on a debian 6.0 system, I get the motd but then there is a 5-10 second pause until I get a shell prompt. If I press ctrl-c during that pause the prompt comes up instantly. What could be happening here? Am I killing ... | You can debug bash shell scripts using `set -x` and `set +x`. The `set -x` command enables debug mode and the `set +x` command disables it.
Putting `set -x` at the top of your $HOME/.bash_profile should cause debug information to be printed for your personal shell initialisation files. If as you say you get a 10 secon... |
8122780 | exiting shell script with background processes | 8 | 2011-11-14 14:08:53 | <p>I need somehow to exit my script.sh (with return code - would be the best) which runs some other commands and other scripts in the background.</p>
<p>I've tried to run commands via</p>
<pre><code>nohup myInScript.sh &
</code></pre>
<p>also I've tried to use at the end of script.sh</p>
<pre><code>disown -a[r]... | 16,403 | 540,885 | 2015-07-30 10:44:20 | 8,123,399 | 14 | 2011-11-14 14:55:34 | 694,014 | 2013-11-13 13:42:12 | https://stackoverflow.com/q/8122780 | https://stackoverflow.com/a/8123399 | <p>From memory a login shell will be kept around even when it finishes if any of its still running children have standard (terminal) file handles open. Normal (sub process) shells do not seem to suffer from this. So see if changing your nohup line to the following makes any difference.</p>
<pre><code>nohup myInScript.... | <p>From memory a login shell will be kept around even when it finishes if any of its still running children have standard (terminal) file handles open. Normal (sub process) shells do not seem to suffer from this. So see if changing your nohup line to the following makes any difference.</p> <pre><code>nohup myInScript.... | 387, 390, 15292 | background-process, bash, shell | <h1>exiting shell script with background processes</h1>
<p>I need somehow to exit my script.sh (with return code - would be the best) which runs some other commands and other scripts in the background.</p>
<p>I've tried to run commands via</p>
<pre><code>nohup myInScript.sh &
</code></pre>
<p>also I've tried to ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,909 | bash | # exiting shell script with background processes
I need somehow to exit my script.sh (with return code - would be the best) which runs some other commands and other scripts in the background.
I've tried to run commands via
```
nohup myInScript.sh &
```
also I've tried to use at the end of script.sh
```
disown -a[r... | From memory a login shell will be kept around even when it finishes if any of its still running children have standard (terminal) file handles open. Normal (sub process) shells do not seem to suffer from this. So see if changing your nohup line to the following makes any difference.
```
nohup myInScript.sh >some.log 2... |
7533318 | Get rid of newline from shell commands in Ruby | 8 | 2011-09-23 18:29:10 | <p>I am trying to run simple shell commands in my script, but am unable to get rid of new lines even using chomp or chop. </p>
<p>Is there something I am missing ?</p>
<pre><code> u=`echo '#{l}' | cut -d: -f4`.chop()
p2=`echo '#{l}' | cut -d: -f3`.chop()
p1=`echo '#{l}' | cut -d: -f2`.chop()
h... | 5,043 | 250,304 | 2011-09-23 21:09:52 | 7,533,491 | 14 | 2011-09-23 18:46:41 | 405,017 | 2011-09-23 20:37:38 | https://stackoverflow.com/q/7533318 | https://stackoverflow.com/a/7533491 | <p>Use either <a href="http://ruby-doc.org/core/classes/String.html#M001189" rel="noreferrer"><code>String#strip</code></a> to remove all wrapping whitespace, or <a href="http://ruby-doc.org/core/classes/String.html#M001188" rel="noreferrer"><code>String#chomp</code></a> (note the 'm') to remove a single trailing newli... | <p>Use either <a href="http://ruby-doc.org/core/classes/String.html#M001189" rel="noreferrer"><code>String#strip</code></a> to remove all wrapping whitespace, or <a href="http://ruby-doc.org/core/classes/String.html#M001188" rel="noreferrer"><code>String#chomp</code></a> (note the 'm') to remove a single trailing newli... | 12, 390, 2847 | ruby, rubygems, shell | <h1>Get rid of newline from shell commands in Ruby</h1>
<p>I am trying to run simple shell commands in my script, but am unable to get rid of new lines even using chomp or chop. </p>
<p>Is there something I am missing ?</p>
<pre><code> u=`echo '#{l}' | cut -d: -f4`.chop()
p2=`echo '#{l}' | cut -d: -f3`.ch... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,910 | bash | # Get rid of newline from shell commands in Ruby
I am trying to run simple shell commands in my script, but am unable to get rid of new lines even using chomp or chop.
Is there something I am missing ?
```
u=`echo '#{l}' | cut -d: -f4`.chop()
p2=`echo '#{l}' | cut -d: -f3`.chop()
p1=`echo '#{l}' |... | Use either [`String#strip`](http://ruby-doc.org/core/classes/String.html#M001189) to remove all wrapping whitespace, or [`String#chomp`](http://ruby-doc.org/core/classes/String.html#M001188) (note the 'm') to remove a single trailing newline only.
[`String#chop`](http://ruby-doc.org/core/classes/String.html#M001187) r... |
7301026 | Extract numbers from filename | 8 | 2011-09-04 17:45:29 | <p>In BASH I thought to use <code>sed</code>, but can't figure how to extract pattern instead usual replace.</p>
<p>For example:</p>
<p>FILENAME = 'blah_blah_#######_blah.ext'</p>
<p>number of ciphers (in above example written with "#" substitute) could be either 7 or 10</p>
<p>I want to extract only the number</p>... | 32,883 | 901,704 | 2017-08-28 08:34:16 | 7,301,106 | 14 | 2011-09-04 17:58:00 | 371,793 | 2011-09-04 17:58:00 | https://stackoverflow.com/q/7301026 | https://stackoverflow.com/a/7301106 | <p>If all you need is to remove anything but digits, you could use</p>
<pre><code>ls | sed -e s/[^0-9]//g
</code></pre>
<p>to get all digits grouped per filename (123test456.ext will become 123456), or</p>
<pre><code>ls | egrep -o [0-9]+
</code></pre>
<p>for all groups of numbers (123test456.ext will turn up 123 an... | <p>If all you need is to remove anything but digits, you could use</p> <pre><code>ls | sed -e s/[^0-9]//g </code></pre> <p>to get all digits grouped per filename (123test456.ext will become 123456), or</p> <pre><code>ls | egrep -o [0-9]+ </code></pre> <p>for all groups of numbers (123test456.ext will turn up 123 an... | 387, 5282 | bash, sed | <h1>Extract numbers from filename</h1>
<p>In BASH I thought to use <code>sed</code>, but can't figure how to extract pattern instead usual replace.</p>
<p>For example:</p>
<p>FILENAME = 'blah_blah_#######_blah.ext'</p>
<p>number of ciphers (in above example written with "#" substitute) could be either 7 or 10</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,911 | bash | # Extract numbers from filename
In BASH I thought to use `sed`, but can't figure how to extract pattern instead usual replace.
For example:
FILENAME = 'blah_blah_#######_blah.ext'
number of ciphers (in above example written with "#" substitute) could be either 7 or 10
I want to extract only the number | If all you need is to remove anything but digits, you could use
```
ls | sed -e s/[^0-9]//g
```
to get all digits grouped per filename (123test456.ext will become 123456), or
```
ls | egrep -o [0-9]+
```
for all groups of numbers (123test456.ext will turn up 123 and 456) |
7031687 | Merge 2 txt files in a single tab delimited file in batch | 8 | 2011-08-11 19:28:26 | <p>I'm stuck with this :
I need to merge two text files in a single tab delimited text file, on a batch script.
ex :</p>
<p>file1:</p>
<pre><code>qwer
tyui
asdf
</code></pre>
<p>file2:</p>
<pre><code>1345
6876
8796
</code></pre>
<p>file3: </p>
<pre><code>qwer 1345
tyui 6876
asdf 8796
</code></pre>
<p>A... | 7,279 | 767,990 | 2017-06-07 16:39:02 | 7,037,534 | 14 | 2011-08-12 08:34:06 | 540,014 | 2011-08-12 08:34:06 | https://stackoverflow.com/q/7031687 | https://stackoverflow.com/a/7037534 | <pre><code> @echo off
set f1=1.txt
set f2=2.txt
set "sep= " % tab %
(
for /f "delims=" %%a in (%f1%) do (
setlocal enabledelayedexpansion
set /p line=
echo(%%a!sep!!line!
endlocal
)
)<%f2%
pause
goto :eof
</code></pre>
| <pre><code> @echo off set f1=1.txt set f2=2.txt set "sep= " % tab % ( for /f "delims=" %%a in (%f1%) do ( setlocal enabledelayedexpansion set /p line= echo(%%a!sep!!line! endlocal ) )<%f2% pause goto :eof </code></pre> | 64, 387, 7002 | bash, batch-file, windows | <h1>Merge 2 txt files in a single tab delimited file in batch</h1>
<p>I'm stuck with this :
I need to merge two text files in a single tab delimited text file, on a batch script.
ex :</p>
<p>file1:</p>
<pre><code>qwer
tyui
asdf
</code></pre>
<p>file2:</p>
<pre><code>1345
6876
8796
</code></pre>
<p>file3: </p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,912 | bash | # Merge 2 txt files in a single tab delimited file in batch
I'm stuck with this :
I need to merge two text files in a single tab delimited text file, on a batch script.
ex :
file1:
```
qwer
tyui
asdf
```
file2:
```
1345
6876
8796
```
file3:
```
qwer 1345
tyui 6876
asdf 8796
```
All I need in fact, is a... | ```
@echo off
set f1=1.txt
set f2=2.txt
set "sep= " % tab %
(
for /f "delims=" %%a in (%f1%) do (
setlocal enabledelayedexpansion
set /p line=
echo(%%a!sep!!line!
endlocal
)
)<%f2%
pause
goto :eof
``` |
6829179 | how to source a shell script [environment variables] in perl script without forking a subshell? | 8 | 2011-07-26 11:16:02 | <p>I want to call "env.sh " from "my_perl.pl" without forking a subshell. I tried with backtics and system like this --> <code>system (. env.sh)</code> [dot space env.sh] , however wont work. </p>
| 13,124 | 673,018 | 2018-11-08 05:22:01 | 6,829,502 | 14 | 2011-07-26 11:46:08 | 78,259 | 2011-07-26 12:15:07 | https://stackoverflow.com/q/6829179 | https://stackoverflow.com/a/6829502 | <p>Child environments cannot change parent environments. Your best bet is to parse <code>env.sh</code> from inside the Perl code and set the variables in <code>%ENV</code>:</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
sub source {
my $name = shift;
open my $fh, "<", $name
or die "cou... | <p>Child environments cannot change parent environments. Your best bet is to parse <code>env.sh</code> from inside the Perl code and set the variables in <code>%ENV</code>:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; sub source { my $name = shift; open my $fh, "<", $name or die "cou... | 390, 580 | perl, shell | <h1>how to source a shell script [environment variables] in perl script without forking a subshell?</h1>
<p>I want to call "env.sh " from "my_perl.pl" without forking a subshell. I tried with backtics and system like this --> <code>system (. env.sh)</code> [dot space env.sh] , however wont work. </p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,913 | bash | # how to source a shell script [environment variables] in perl script without forking a subshell?
I want to call "env.sh " from "my_perl.pl" without forking a subshell. I tried with backtics and system like this --> `system (. env.sh)` [dot space env.sh] , however wont work. | Child environments cannot change parent environments. Your best bet is to parse `env.sh` from inside the Perl code and set the variables in `%ENV`:
```
#!/usr/bin/perl
use strict;
use warnings;
sub source {
my $name = shift;
open my $fh, "<", $name
or die "could not open $name: $!";
while (<$fh... |
6357914 | How do I install a DMG file from the command line? | 8 | 2011-06-15 12:51:37 | <p>I am looking for small bash or python script that will install a <code>.dmg</code> file.</p>
<p>We'll assume that the dmg contains one or more <code>.app</code> directories that have to be copied to <code>/Applications</code>, overriding any already existing directories.</p>
<p>Files or directories not matching th... | 16,908 | 99,834 | 2011-06-15 16:26:04 | 6,358,679 | 14 | 2011-06-15 13:45:40 | 23,388 | 2011-06-15 16:26:04 | https://stackoverflow.com/q/6357914 | https://stackoverflow.com/a/6358679 | <p>You can mount the disk image using</p>
<pre><code>hdiutil attach -mountpoint <path-to-desired-mountpoint> <filename.dmg>
</code></pre>
<p>The disk image will be mounted at the selected path (the argument following <code>-mountpoint</code>). Then, search for an <code>.app</code> file and copy the file t... | <p>You can mount the disk image using</p> <pre><code>hdiutil attach -mountpoint <path-to-desired-mountpoint> <filename.dmg> </code></pre> <p>The disk image will be mounted at the selected path (the argument following <code>-mountpoint</code>). Then, search for an <code>.app</code> file and copy the file t... | 16, 369, 387 | bash, macos, python | <h1>How do I install a DMG file from the command line?</h1>
<p>I am looking for small bash or python script that will install a <code>.dmg</code> file.</p>
<p>We'll assume that the dmg contains one or more <code>.app</code> directories that have to be copied to <code>/Applications</code>, overriding any already existi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,914 | bash | # How do I install a DMG file from the command line?
I am looking for small bash or python script that will install a `.dmg` file.
We'll assume that the dmg contains one or more `.app` directories that have to be copied to `/Applications`, overriding any already existing directories.
Files or directories not matchin... | You can mount the disk image using
```
hdiutil attach -mountpoint <path-to-desired-mountpoint> <filename.dmg>
```
The disk image will be mounted at the selected path (the argument following `-mountpoint`). Then, search for an `.app` file and copy the file to `/Applications`.
Once you have finished installation unmou... |
5995895 | Shell commands from vim | 8 | 2011-05-13 17:58:06 | <p>What is the best approach of using shell commands from vim? I know about the possibility of <code>!shell_command</code>. But this doesn't know all commands e.g.
<code>export OSTYPE; make install</code> So I have to run it outside vim. Is there better approach?</p>
| 15,584 | 653,379 | 2019-08-29 13:19:52 | 5,996,052 | 14 | 2011-05-13 18:13:09 | 244,297 | 2019-08-29 13:19:52 | https://stackoverflow.com/q/5995895 | https://stackoverflow.com/a/5996052 | <p>You can start a shell from Vim using the <a href="https://vimhelp.org/various.txt.html" rel="noreferrer"><code>:sh</code></a> command. When the shell exits
(after the <code>exit</code> command or <kbd>Ctrl</kbd>+<kbd>D</kbd>) you return to Vim. The name for the shell command comes from the <a href="https://vimhelp.o... | <p>You can start a shell from Vim using the <a href="https://vimhelp.org/various.txt.html" rel="noreferrer"><code>:sh</code></a> command. When the shell exits (after the <code>exit</code> command or <kbd>Ctrl</kbd>+<kbd>D</kbd>) you return to Vim. The name for the shell command comes from the <a href="https://vimhelp.o... | 370, 390 | shell, vim | <h1>Shell commands from vim</h1>
<p>What is the best approach of using shell commands from vim? I know about the possibility of <code>!shell_command</code>. But this doesn't know all commands e.g.
<code>export OSTYPE; make install</code> So I have to run it outside vim. Is there better approach?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,915 | bash | # Shell commands from vim
What is the best approach of using shell commands from vim? I know about the possibility of `!shell_command`. But this doesn't know all commands e.g.
`export OSTYPE; make install` So I have to run it outside vim. Is there better approach? | You can start a shell from Vim using the [`:sh`](https://vimhelp.org/various.txt.html) command. When the shell exits
(after the `exit` command or `Ctrl`+`D`) you return to Vim. The name for the shell command comes from the [`shell`](https://vimhelp.org/options.txt.html#%27shell%27) option.
For terminal Vim (on unix-li... |
5802370 | Is it possible to use teamcity message from shell scripts? | 8 | 2011-04-27 10:03:48 | <p>I have several build steps that use command line with custom scripts. And i want to use teamcity messages. Like this ones:</p>
<pre><code>##teamcity[message 'value']
##teamcity[buildNumber '<new build number>']
##teamcity[buildStatus status='<status value>' text='<text>']
</code></pre>
<p>But it ... | 3,848 | 274,517 | 2021-04-30 11:15:52 | 5,802,705 | 14 | 2011-04-27 10:35:31 | 65,612 | 2021-04-30 11:15:52 | https://stackoverflow.com/q/5802370 | https://stackoverflow.com/a/5802705 | <p>In a shell script, use</p>
<pre class="lang-sh prettyprint-override"><code>echo "##teamcity[buildStatus status='<status value>' text='<text>']"
</code></pre>
<p>Here is the <a href="https://www.jetbrains.com/help/teamcity/service-messages.html" rel="nofollow noreferrer">detailed docs</a> for Te... | <p>In a shell script, use</p> <pre class="lang-sh prettyprint-override"><code>echo "##teamcity[buildStatus status='<status value>' text='<text>']" </code></pre> <p>Here is the <a href="https://www.jetbrains.com/help/teamcity/service-messages.html" rel="nofollow noreferrer">detailed docs</a> for Te... | 390, 604, 1783 | build-process, shell, teamcity | <h1>Is it possible to use teamcity message from shell scripts?</h1>
<p>I have several build steps that use command line with custom scripts. And i want to use teamcity messages. Like this ones:</p>
<pre><code>##teamcity[message 'value']
##teamcity[buildNumber '<new build number>']
##teamcity[buildStatus status='... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,916 | bash | # Is it possible to use teamcity message from shell scripts?
I have several build steps that use command line with custom scripts. And i want to use teamcity messages. Like this ones:
```
##teamcity[message 'value']
##teamcity[buildNumber '<new build number>']
##teamcity[buildStatus status='<status value>' text='<tex... | In a shell script, use
```
echo "##teamcity[buildStatus status='<status value>' text='<text>']"
```
Here is the [detailed docs](https://www.jetbrains.com/help/teamcity/service-messages.html) for TeamCity 2020.2. |
5150835 | Prepend text in file | 8 | 2011-03-01 05:26:16 | <p>I have used an awk command to find a particular line in a file and would like to prepend this in a second file. Can someone help me in this respect?</p>
| 8,305 | 459,184 | 2022-11-22 08:06:42 | 5,150,973 | 14 | 2011-03-01 05:48:16 | 350,351 | 2011-03-01 06:03:55 | https://stackoverflow.com/q/5150835 | https://stackoverflow.com/a/5150973 | <p>The short answer is that you can't. You'll need a temp file.</p>
<pre><code>echo "Prepended Line" > tmpfile && cat origfile >> tmpfile && mv tmpfile origfile
</code></pre>
<p>Edit:</p>
<pre><code>sed -i 's/\(line you want\)/Prefix \1/g' origfile
</code></pre>
| <p>The short answer is that you can't. You'll need a temp file.</p> <pre><code>echo "Prepended Line" > tmpfile && cat origfile >> tmpfile && mv tmpfile origfile </code></pre> <p>Edit:</p> <pre><code>sed -i 's/\(line you want\)/Prefix \1/g' origfile </code></pre> | 58, 390 | linux, shell | <h1>Prepend text in file</h1>
<p>I have used an awk command to find a particular line in a file and would like to prepend this in a second file. Can someone help me in this respect?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,917 | bash | # Prepend text in file
I have used an awk command to find a particular line in a file and would like to prepend this in a second file. Can someone help me in this respect? | The short answer is that you can't. You'll need a temp file.
```
echo "Prepended Line" > tmpfile && cat origfile >> tmpfile && mv tmpfile origfile
```
Edit:
```
sed -i 's/\(line you want\)/Prefix \1/g' origfile
``` |
5037128 | cmd.exe powershell HashTable | 8 | 2011-02-18 02:39:24 | <p>Is there a way in PowerShell to pass a HashTable as an argument when being invoked with cmd.exe?</p>
<p>I want to invoke a script like this:</p>
<pre><code>powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"
</code></pre>
<p>Where arg4 is a HashTable. Is this possible? </p>
| 3,960 | 2,764 | 2011-02-19 02:33:15 | 5,037,960 | 14 | 2011-02-18 05:30:04 | 153,982 | 2011-02-19 02:33:15 | https://stackoverflow.com/q/5037128 | https://stackoverflow.com/a/5037960 | <p>Given a script (foo.ps1) like this:</p>
<pre><code>param($a1, $a2, $a3, [hashtable]$a4)
"a1 is $a1"
"a2 is $a2"
"a3 is $a3"
"a4 is "
$a4
</code></pre>
<p>You can invoke it from cmd.exe like so specifying a hashtable as the fourth parameter:</p>
<pre><code>C:\> powershell -command "& {c:\foo.ps1 1 2 three ... | <p>Given a script (foo.ps1) like this:</p> <pre><code>param($a1, $a2, $a3, [hashtable]$a4) "a1 is $a1" "a2 is $a2" "a3 is $a3" "a4 is " $a4 </code></pre> <p>You can invoke it from cmd.exe like so specifying a hashtable as the fourth parameter:</p> <pre><code>C:\> powershell -command "& {c:\foo.ps1 1 2 three ... | 526, 2631 | cmd, powershell | <h1>cmd.exe powershell HashTable</h1>
<p>Is there a way in PowerShell to pass a HashTable as an argument when being invoked with cmd.exe?</p>
<p>I want to invoke a script like this:</p>
<pre><code>powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"
</code></pre>
<p>Where arg4 is a HashTable. Is this possibl... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,918 | bash | # cmd.exe powershell HashTable
Is there a way in PowerShell to pass a HashTable as an argument when being invoked with cmd.exe?
I want to invoke a script like this:
```
powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"
```
Where arg4 is a HashTable. Is this possible? | Given a script (foo.ps1) like this:
```
param($a1, $a2, $a3, [hashtable]$a4)
"a1 is $a1"
"a2 is $a2"
"a3 is $a3"
"a4 is "
$a4
```
You can invoke it from cmd.exe like so specifying a hashtable as the fourth parameter:
```
C:\> powershell -command "& {c:\foo.ps1 1 2 three @{name='John';age=45}}"
a1 is 1
a2 is 2
a3 is... |
4935764 | Creating empty file in all subfolders | 8 | 2011-02-08 16:45:03 | <p>I need to extract an archive and create a empty file in each of the folders contained within the archive.</p>
<p>I tried this:</p>
<pre><code>for folder in `ls -d1 */` ; do touch "${folder}/COMPLETE"; done;
</code></pre>
<p>works just perfect till someone creates a folder with a space in its name.</p>
<p>How can... | 6,328 | 335,523 | 2011-02-08 16:59:59 | 4,935,799 | 14 | 2011-02-08 16:47:39 | 7,412 | 2011-02-08 16:47:39 | https://stackoverflow.com/q/4935764 | https://stackoverflow.com/a/4935799 | <p>You can use find instead:</p>
<pre><code>find . -type d -exec touch {}/COMPLETE \;
</code></pre>
| <p>You can use find instead:</p> <pre><code>find . -type d -exec touch {}/COMPLETE \; </code></pre> | 387 | bash | <h1>Creating empty file in all subfolders</h1>
<p>I need to extract an archive and create a empty file in each of the folders contained within the archive.</p>
<p>I tried this:</p>
<pre><code>for folder in `ls -d1 */` ; do touch "${folder}/COMPLETE"; done;
</code></pre>
<p>works just perfect till someone creates a f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,919 | bash | # Creating empty file in all subfolders
I need to extract an archive and create a empty file in each of the folders contained within the archive.
I tried this:
```
for folder in `ls -d1 */` ; do touch "${folder}/COMPLETE"; done;
```
works just perfect till someone creates a folder with a space in its name.
How can... | You can use find instead:
```
find . -type d -exec touch {}/COMPLETE \;
``` |
4880486 | Curl to download and upload same file simultaneously | 8 | 2011-02-02 22:09:20 | <p>Not sure if it's possible but I've been trying to use curl to essentially download a file from a HTTP location and output it onto an FTP server. I would really like some help if this is in fact possible.</p>
| 4,731 | 600,715 | 2011-02-02 22:29:13 | 4,880,663 | 14 | 2011-02-02 22:29:13 | 224,346 | 2011-02-02 22:29:13 | https://stackoverflow.com/q/4880486 | https://stackoverflow.com/a/4880663 | <pre><code>curl http://example.com/down | curl -T - ftp://mysite.org/up
</code></pre>
<p>By default curl spits its output to stdout - we then pipe that into another instance of curl.</p>
<p>On the second instance, <code>-T</code> tells curl to upload a file, and the <code>-</code> tells it to take the file data from ... | <pre><code>curl http://example.com/down | curl -T - ftp://mysite.org/up </code></pre> <p>By default curl spits its output to stdout - we then pipe that into another instance of curl.</p> <p>On the second instance, <code>-T</code> tells curl to upload a file, and the <code>-</code> tells it to take the file data from ... | 58, 261, 387, 1554, 5210 | bash, curl, ftp, http, linux | <h1>Curl to download and upload same file simultaneously</h1>
<p>Not sure if it's possible but I've been trying to use curl to essentially download a file from a HTTP location and output it onto an FTP server. I would really like some help if this is in fact possible.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,920 | bash | # Curl to download and upload same file simultaneously
Not sure if it's possible but I've been trying to use curl to essentially download a file from a HTTP location and output it onto an FTP server. I would really like some help if this is in fact possible. | ```
curl http://example.com/down | curl -T - ftp://mysite.org/up
```
By default curl spits its output to stdout - we then pipe that into another instance of curl.
On the second instance, `-T` tells curl to upload a file, and the `-` tells it to take the file data from stdin (rather than from a file on disk). |
2516343 | Add at the end of the line with sed | 8 | 2010-03-25 14:33:18 | <p>given a plain text document with several lines like:</p>
<pre><code>c48 7.587 7.39
c49 7.508 7.345983
c50 5.8 7.543
c51 8.37454546 7.34
</code></pre>
<p>I need to add some info 2 spaces after the end of the line, so for each line I would get:</p>
<pre><code>c48 7.587 7.39 def
c49 7.508 7.345983 def
c50 5.8 7.54... | 26,795 | 171,546 | 2010-03-25 14:48:22 | 2,516,416 | 14 | 2010-03-25 14:42:44 | 131,527 | 2010-03-25 14:48:22 | https://stackoverflow.com/q/2516343 | https://stackoverflow.com/a/2516416 | <p>if all your files are in one directory</p>
<pre><code>sed -i.bak 's/$/ def/' *.txt
</code></pre>
<p>to do it recursive (GNU find)</p>
<pre><code>find /path -type f -iname '*.txt' -exec sed -i.bak 's/$/ def/' "{}" +;
</code></pre>
<p>you can see <a href="http://www.grymoire.com/Unix/Sed.html" rel="noreferrer">h... | <p>if all your files are in one directory</p> <pre><code>sed -i.bak 's/$/ def/' *.txt </code></pre> <p>to do it recursive (GNU find)</p> <pre><code>find /path -type f -iname '*.txt' -exec sed -i.bak 's/$/ def/' "{}" +; </code></pre> <p>you can see <a href="http://www.grymoire.com/Unix/Sed.html" rel="noreferrer">h... | 387, 5282 | bash, sed | <h1>Add at the end of the line with sed</h1>
<p>given a plain text document with several lines like:</p>
<pre><code>c48 7.587 7.39
c49 7.508 7.345983
c50 5.8 7.543
c51 8.37454546 7.34
</code></pre>
<p>I need to add some info 2 spaces after the end of the line, so for each line I would get:</p>
<pre><code>c48 7.587 7... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,921 | bash | # Add at the end of the line with sed
given a plain text document with several lines like:
```
c48 7.587 7.39
c49 7.508 7.345983
c50 5.8 7.543
c51 8.37454546 7.34
```
I need to add some info 2 spaces after the end of the line, so for each line I would get:
```
c48 7.587 7.39 def
c49 7.508 7.345983 def
c50 5.8 7.5... | if all your files are in one directory
```
sed -i.bak 's/$/ def/' *.txt
```
to do it recursive (GNU find)
```
find /path -type f -iname '*.txt' -exec sed -i.bak 's/$/ def/' "{}" +;
```
you can see [here](http://www.grymoire.com/Unix/Sed.html) for introduction to sed
Other ways you can use,
awk
```
for file in ... |
2310021 | Checking the return value of a C program in a bash script? | 8 | 2010-02-22 09:50:29 | <p>I have a bash script in which i check the exit code of a last run command by using $? variable but now I am executing a C program (from that script) which returns 0 if the program gets executed successfully. Is there any way I can catch this return value of the C program from with in my bash script?</p>
<p>I believ... | 10,906 | 184,759 | 2010-02-22 21:13:02 | 2,310,037 | 14 | 2010-02-22 09:53:40 | null | 2010-02-22 09:53:40 | https://stackoverflow.com/q/2310021 | https://stackoverflow.com/a/2310037 | <p>There's no need to do anything - if your C program returns 0, that's what will be stored in the <code>$?</code> variable of the shell that executed it.</p>
| <p>There's no need to do anything - if your C program returns 0, that's what will be stored in the <code>$?</code> variable of the shell that executed it.</p> | 8, 58, 387 | bash, c, linux | <h1>Checking the return value of a C program in a bash script?</h1>
<p>I have a bash script in which i check the exit code of a last run command by using $? variable but now I am executing a C program (from that script) which returns 0 if the program gets executed successfully. Is there any way I can catch this return ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,922 | bash | # Checking the return value of a C program in a bash script?
I have a bash script in which i check the exit code of a last run command by using $? variable but now I am executing a C program (from that script) which returns 0 if the program gets executed successfully. Is there any way I can catch this return value of ... | There's no need to do anything - if your C program returns 0, that's what will be stored in the `$?` variable of the shell that executed it. |
2162681 | MongoDB external script file | 8 | 2010-01-29 14:52:55 | <p>I am using mongoDB and am curious to whether you can import scripts like you can in MySQL:</p>
<pre><code>mysql -uuser -ppassword database < script.sql
</code></pre>
<p>Can you do this with mongoDB?</p>
<p>Cheers</p>
<p>Eef</p>
| 8,706 | 30,786 | 2010-01-29 16:08:09 | 2,163,207 | 14 | 2010-01-29 16:08:09 | 111,332 | 2010-01-29 16:08:09 | https://stackoverflow.com/q/2162681 | https://stackoverflow.com/a/2163207 | <p>You can pass a list of JS files to the <strong>mongo</strong> JavaScript shell and those will get executed:</p>
<pre><code>$ echo "print('hello');" > test.js
$ ./mongo test.js
MongoDB shell version: 1.3.2-
url: test
connecting to: test
hello
</code></pre>
<p>You can use the normal <strong>mongo</strong> command... | <p>You can pass a list of JS files to the <strong>mongo</strong> JavaScript shell and those will get executed:</p> <pre><code>$ echo "print('hello');" > test.js $ ./mongo test.js MongoDB shell version: 1.3.2- url: test connecting to: test hello </code></pre> <p>You can use the normal <strong>mongo</strong> command... | 58, 387, 30073 | bash, linux, mongodb | <h1>MongoDB external script file</h1>
<p>I am using mongoDB and am curious to whether you can import scripts like you can in MySQL:</p>
<pre><code>mysql -uuser -ppassword database < script.sql
</code></pre>
<p>Can you do this with mongoDB?</p>
<p>Cheers</p>
<p>Eef</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,923 | bash | # MongoDB external script file
I am using mongoDB and am curious to whether you can import scripts like you can in MySQL:
```
mysql -uuser -ppassword database < script.sql
```
Can you do this with mongoDB?
Cheers
Eef | You can pass a list of JS files to the **mongo** JavaScript shell and those will get executed:
```
$ echo "print('hello');" > test.js
$ ./mongo test.js
MongoDB shell version: 1.3.2-
url: test
connecting to: test
hello
```
You can use the normal **mongo** command line arguments if you need to specify a specific db, us... |
1126116 | Python: Persistent shell variables in subprocess | 8 | 2009-07-14 15:19:21 | <p>I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.</p>
<p>Is there any way to go about this? I could create ... | 3,482 | 138,138 | 2009-08-27 09:22:32 | 1,126,137 | 14 | 2009-07-14 15:22:45 | 95,810 | 2009-07-14 15:22:45 | https://stackoverflow.com/q/1126116 | https://stackoverflow.com/a/1126137 | <p><code>subprocess.Popen</code> takes an optional named argument <code>env</code> that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of <code>os.environ</code> and alter that as you need) and pass it to all ... | <p><code>subprocess.Popen</code> takes an optional named argument <code>env</code> that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of <code>os.environ</code> and alter that as you need) and pass it to all ... | 16, 276, 390, 2348, 14905 | persistent, python, shell, subprocess, variables | <h1>Python: Persistent shell variables in subprocess</h1>
<p>I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,924 | bash | # Python: Persistent shell variables in subprocess
I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.
Is there... | `subprocess.Popen` takes an optional named argument `env` that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of `os.environ` and alter that as you need) and pass it to all the `subprocess.Popen` calls you per... |
453627 | Shell Script Tilde Expansion | 8 | 2009-01-17 17:15:16 | <p>Here is my script:</p>
<pre><code>#!/bin/bash
echo "Digite o local em que deseja instalar o IGRAFU(pressione enter para
instalar em
${HOME}/IGRAFO):"
read caminho
if test -z $caminho
then
caminho="${HOME}/IGRAFO"
fi
echo "O IGRAFU serΓ‘ instalado no diretΓ³rio: $caminho"
mkdir -pv $caminho
mv -v ./* $caminho
echo... | 4,919 | 2,605 | 2011-09-29 12:42:08 | 453,635 | 14 | 2009-01-17 17:23:09 | 46,991 | 2009-01-17 17:28:46 | https://stackoverflow.com/q/453627 | https://stackoverflow.com/a/453635 | <p>You will probably need to eval the variable to have it substituted correctly. One example would be to simply do</p>
<pre><code>caminho=`eval "echo $caminho"`
</code></pre>
<p>Keep in mind that this will break if <code>caminho</code> contains semicolons or quotes, it will also treat backslashes as escaping, and if ... | <p>You will probably need to eval the variable to have it substituted correctly. One example would be to simply do</p> <pre><code>caminho=`eval "echo $caminho"` </code></pre> <p>Keep in mind that this will break if <code>caminho</code> contains semicolons or quotes, it will also treat backslashes as escaping, and if ... | 58, 390 | linux, shell | <h1>Shell Script Tilde Expansion</h1>
<p>Here is my script:</p>
<pre><code>#!/bin/bash
echo "Digite o local em que deseja instalar o IGRAFU(pressione enter para
instalar em
${HOME}/IGRAFO):"
read caminho
if test -z $caminho
then
caminho="${HOME}/IGRAFO"
fi
echo "O IGRAFU serΓ‘ instalado no diretΓ³rio: $caminho"
mkdir... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,925 | bash | # Shell Script Tilde Expansion
Here is my script:
```
#!/bin/bash
echo "Digite o local em que deseja instalar o IGRAFU(pressione enter para
instalar em
${HOME}/IGRAFO):"
read caminho
if test -z $caminho
then
caminho="${HOME}/IGRAFO"
fi
echo "O IGRAFU serΓ‘ instalado no diretΓ³rio: $caminho"
mkdir -pv $caminho
mv -v... | You will probably need to eval the variable to have it substituted correctly. One example would be to simply do
```
caminho=`eval "echo $caminho"`
```
Keep in mind that this will break if `caminho` contains semicolons or quotes, it will also treat backslashes as escaping, and if the data is untrusted, you need to tak... |
70841814 | Powershell 7: using ampersand (&) in string literals | 7 | 2022-01-24 23:42:16 | <p>I'm trying to execute the following command in PowerShell, but I have no idea how to escape the ampersand character which is part of the URL</p>
<pre><code> az rest `
--method GET `
--uri ("https://graph.microsoft.com/v1.0/groups?`$count=true&`$filter=startsWith(displayName,'some+filter+text')&... | 5,074 | 1,077,228 | 2026-01-23 17:46:09 | 70,842,846 | 14 | 2022-01-25 02:42:19 | 45,375 | 2026-01-23 17:46:09 | https://stackoverflow.com/q/70841814 | https://stackoverflow.com/a/70842846 |
<p><a href="https://stackoverflow.com/a/70842056/45375">Olaf's answer</a> provides an effective solution; let me add an explanation:</p>
<p><strong>The source of the problem</strong> is a confluence of two behaviors:</p>
<ul>
<li><p>When calling <em>external programs</em>, <strong>PowerShell</strong> performs <em>on-d... | <p><a href="https://stackoverflow.com/a/70842056/45375">Olaf's answer</a> provides an effective solution; let me add an explanation:</p> <p><strong>The source of the problem</strong> is a confluence of two behaviors:</p> <ul> <li><p>When calling <em>external programs</em>, <strong>PowerShell</strong> performs <em>on-d... | 526 | powershell | <h1>Powershell 7: using ampersand (&) in string literals</h1>
<p>I'm trying to execute the following command in PowerShell, but I have no idea how to escape the ampersand character which is part of the URL</p>
<pre><code> az rest `
--method GET `
--uri ("https://graph.microsoft.com/v1.0/groups?`$count=tru... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,926 | bash | # Powershell 7: using ampersand (&) in string literals
I'm trying to execute the following command in PowerShell, but I have no idea how to escape the ampersand character which is part of the URL
```
az rest `
--method GET `
--uri ("https://graph.microsoft.com/v1.0/groups?`$count=true&`$filter=startsWith(di... | [Olaf's answer](https://stackoverflow.com/a/70842056/45375) provides an effective solution; let me add an explanation:
**The source of the problem** is a confluence of two behaviors:
- When calling *external programs*, **PowerShell** performs *on-demand* double-quoting of each argument solely based on whether a given... |
70769217 | Do bash scripts execute in new shells or subshells? | 7 | 2022-01-19 10:46:37 | <p>I am running a bash script from my bash interactive shell as:</p>
<pre><code>./shell.sh
</code></pre>
<p>The confusion I am having is, will this script run inside a new shell instance or a subshell of my current bash instance?
I assume that all shell scripts invoked from a shell run inside a new shell therefore they... | 3,151 | 12,964,497 | 2022-01-19 11:29:23 | 70,769,810 | 14 | 2022-01-19 11:29:23 | 89,817 | 2022-01-19 11:29:23 | https://stackoverflow.com/q/70769217 | https://stackoverflow.com/a/70769810 | <p>You're correct; when you run a script with <code>./shell.sh</code>, it runs in a new shell, not a subshell of the current shell.</p>
<p>It does run in a sub<em>process</em>, which is a shell, so it's a tempting and common mistake to say "subprocess+shell=subshell, so it must be a subshell!" But that's inco... | <p>You're correct; when you run a script with <code>./shell.sh</code>, it runs in a new shell, not a subshell of the current shell.</p> <p>It does run in a sub<em>process</em>, which is a shell, so it's a tempting and common mistake to say "subprocess+shell=subshell, so it must be a subshell!" But that's inco... | 387, 390, 2182 | bash, scope, shell | <h1>Do bash scripts execute in new shells or subshells?</h1>
<p>I am running a bash script from my bash interactive shell as:</p>
<pre><code>./shell.sh
</code></pre>
<p>The confusion I am having is, will this script run inside a new shell instance or a subshell of my current bash instance?
I assume that all shell scrip... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,927 | bash | # Do bash scripts execute in new shells or subshells?
I am running a bash script from my bash interactive shell as:
```
./shell.sh
```
The confusion I am having is, will this script run inside a new shell instance or a subshell of my current bash instance?
I assume that all shell scripts invoked from a shell run ins... | You're correct; when you run a script with `./shell.sh`, it runs in a new shell, not a subshell of the current shell.
It does run in a sub*process*, which is a shell, so it's a tempting and common mistake to say "subprocess+shell=subshell, so it must be a subshell!" But that's incorrect. The shell running the script w... |
69519695 | Adding cookies to InvokeRest-Method Powershell | 7 | 2021-10-10 23:32:39 | <p>I need to make a POST call to a webserver which is validating usertype from cookies, I couldn't figure out how to add this cookies to my request.</p>
<pre><code>$eth_config = Invoke-RestMethod -Method 'Post' -Uri $network_settings_url -Body $request_body
</code></pre>
| 13,091 | 13,413,150 | 2021-10-11 08:36:39 | 69,523,191 | 14 | 2021-10-11 08:31:19 | 712,649 | 2021-10-11 08:36:39 | https://stackoverflow.com/q/69519695 | https://stackoverflow.com/a/69523191 | <p>Create a new <code>WebRequestSession</code> object:</p>
<pre><code>$session = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
</code></pre>
<p>Add cookies to session object:</p>
<pre><code>$cookie = [System.Net.Cookie]::new('cookieName', 'value')
$session.Cookies.Add('https://domain.tld/', $cookie)
</code><... | <p>Create a new <code>WebRequestSession</code> object:</p> <pre><code>$session = [Microsoft.PowerShell.Commands.WebRequestSession]::new() </code></pre> <p>Add cookies to session object:</p> <pre><code>$cookie = [System.Net.Cookie]::new('cookieName', 'value') $session.Cookies.Add('https://domain.tld/', $cookie) </code><... | 292, 526, 145532 | cookies, invoke-restmethod, powershell | <h1>Adding cookies to InvokeRest-Method Powershell</h1>
<p>I need to make a POST call to a webserver which is validating usertype from cookies, I couldn't figure out how to add this cookies to my request.</p>
<pre><code>$eth_config = Invoke-RestMethod -Method 'Post' -Uri $network_settings_url -Body $request_body
</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,928 | bash | # Adding cookies to InvokeRest-Method Powershell
I need to make a POST call to a webserver which is validating usertype from cookies, I couldn't figure out how to add this cookies to my request.
```
$eth_config = Invoke-RestMethod -Method 'Post' -Uri $network_settings_url -Body $request_body
``` | Create a new `WebRequestSession` object:
```
$session = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
```
Add cookies to session object:
```
$cookie = [System.Net.Cookie]::new('cookieName', 'value')
$session.Cookies.Add('https://domain.tld/', $cookie)
```
And then pass the session object to the `-WebSess... |
69208770 | Taking output of terraform to bash script as input variable | 7 | 2021-09-16 12:50:15 | <p>I am writing a script that takes care of running a terraform file and create infra. I have requirement where I need to take output from the terraform into the same script to create schema for DB. I need to take Endpoint, username, Password and DB name and take it as an input into the script to login to the db and cr... | 11,283 | 15,753,345 | 2021-09-20 19:45:16 | 69,260,021 | 14 | 2021-09-20 19:45:16 | 281,848 | 2021-09-20 19:45:16 | https://stackoverflow.com/q/69208770 | https://stackoverflow.com/a/69260021 | <p>The usual way to export particular values from a Terraform configuration is to declare <a href="https://www.terraform.io/docs/language/values/outputs.html" rel="noreferrer">Output Values</a>.</p>
<p>In your case it seems like you want to export several of the result attributes from <a href="https://registry.terrafor... | <p>The usual way to export particular values from a Terraform configuration is to declare <a href="https://www.terraform.io/docs/language/values/outputs.html" rel="noreferrer">Output Values</a>.</p> <p>In your case it seems like you want to export several of the result attributes from <a href="https://registry.terrafor... | 387, 390, 110634, 131331 | bash, shell, terraform, terraform-provider-aws | <h1>Taking output of terraform to bash script as input variable</h1>
<p>I am writing a script that takes care of running a terraform file and create infra. I have requirement where I need to take output from the terraform into the same script to create schema for DB. I need to take Endpoint, username, Password and DB n... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,929 | bash | # Taking output of terraform to bash script as input variable
I am writing a script that takes care of running a terraform file and create infra. I have requirement where I need to take output from the terraform into the same script to create schema for DB. I need to take Endpoint, username, Password and DB name and t... | The usual way to export particular values from a Terraform configuration is to declare [Output Values](https://www.terraform.io/docs/language/values/outputs.html).
In your case it seems like you want to export several of the result attributes from [`aws_db_instance`](https://registry.terraform.io/providers/hashicorp/a... |
66912915 | find exec rm: No such file or directory | 7 | 2021-04-01 23:58:54 | <p>Why "No such file or directory" in example below?
There are workarounds to not get this error, the question is why in this exact example the error is produced.</p>
<pre><code>cd /tmp
mkdir -p TOP1/AB/AC/AD/AE/AF
mkdir -p TOP2/AB/AC/AD/AE/AF
find . -iname 'A*' -exec rm -rvf {} \;
removed directory: `./TOP1... | 8,293 | 1,341,921 | 2021-04-02 01:34:53 | 66,913,451 | 14 | 2021-04-02 01:34:53 | 13,067,200 | 2021-04-02 01:34:53 | https://stackoverflow.com/q/66912915 | https://stackoverflow.com/a/66913451 | <p>I think the answer is in the man page itself: <a href="https://linux.die.net/man/1/find" rel="noreferrer">https://linux.die.net/man/1/find</a></p>
<p>Also see <code>\;</code> vs <code>+</code>: <a href="https://stackoverflow.com/questions/6085156/using-semicolon-vs-plus-with-exec-in-find">Using semicolon (;) vs plus... | <p>I think the answer is in the man page itself: <a href="https://linux.die.net/man/1/find" rel="noreferrer">https://linux.die.net/man/1/find</a></p> <p>Also see <code>\;</code> vs <code>+</code>: <a href="https://stackoverflow.com/questions/6085156/using-semicolon-vs-plus-with-exec-in-find">Using semicolon (;) vs plus... | 58, 390 | linux, shell | <h1>find exec rm: No such file or directory</h1>
<p>Why "No such file or directory" in example below?
There are workarounds to not get this error, the question is why in this exact example the error is produced.</p>
<pre><code>cd /tmp
mkdir -p TOP1/AB/AC/AD/AE/AF
mkdir -p TOP2/AB/AC/AD/AE/AF
find . -iname 'A... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,930 | bash | # find exec rm: No such file or directory
Why "No such file or directory" in example below?
There are workarounds to not get this error, the question is why in this exact example the error is produced.
```
cd /tmp
mkdir -p TOP1/AB/AC/AD/AE/AF
mkdir -p TOP2/AB/AC/AD/AE/AF
find . -iname 'A*' -exec rm -rvf {} \;
remove... | I think the answer is in the man page itself: <https://linux.die.net/man/1/find>
Also see `\;` vs `+`: [Using semicolon (;) vs plus (+) with exec in find](https://stackoverflow.com/questions/6085156/using-semicolon-vs-plus-with-exec-in-find)
To understand the whole process better, you can print the files instead of d... |
60404847 | Are you able to use PtrToStringAuto to decrypt a secure string in Powershell 7 on macOS? | 7 | 2020-02-25 23:52:09 | <p>I have had no success in getting the following code snippet to output "Hello World!" in PS7</p>
<pre><code>$string = $("Hello World!" | ConvertTo-SecureString -AsPlainText -Force)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($string))
</code... | 4,119 | 4,257,163 | 2020-06-18 17:45:12 | 60,406,968 | 14 | 2020-02-26 04:48:12 | 45,375 | 2020-02-26 18:19:54 | https://stackoverflow.com/q/60404847 | https://stackoverflow.com/a/60406968 | <p>Note that <strong><a href="https://learn.microsoft.com/en-US/dotnet/api/System.Security.SecureString" rel="noreferrer"><code>[securestring]</code></a> is <a href="https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md" rel="noreferrer">not recommended for new code</a> anymore</strong>.</p>
<p>While <s... | <p>Note that <strong><a href="https://learn.microsoft.com/en-US/dotnet/api/System.Security.SecureString" rel="noreferrer"><code>[securestring]</code></a> is <a href="https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md" rel="noreferrer">not recommended for new code</a> anymore</strong>.</p> <p>While <s... | 526, 108163 | .net-core, powershell | <h1>Are you able to use PtrToStringAuto to decrypt a secure string in Powershell 7 on macOS?</h1>
<p>I have had no success in getting the following code snippet to output "Hello World!" in PS7</p>
<pre><code>$string = $("Hello World!" | ConvertTo-SecureString -AsPlainText -Force)
[System.Runtime.InteropServices.Marsha... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,931 | bash | # Are you able to use PtrToStringAuto to decrypt a secure string in Powershell 7 on macOS?
I have had no success in getting the following code snippet to output "Hello World!" in PS7
```
$string = $("Hello World!" | ConvertTo-SecureString -AsPlainText -Force)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto(... | Note that **[`[securestring]`](https://learn.microsoft.com/en-US/dotnet/api/System.Security.SecureString) is [not recommended for new code](https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md) anymore**.
While **on Windows secure strings offer *limited* protection** - by storing the string *encrypted*... |
59860674 | How to correctly concatenate string in Powershell inline script in Azure DevOps? | 7 | 2020-01-22 13:19:06 | <p>I try to concatenate string to construct a path:</p>
<pre><code>$SourceDirectoryPath = $(System.DefaultWorkingDirectory) + "/solution/project/bin/Debug"
$TargetFilePath = $(System.DefaultWorkingDirectory) + "/solution/project/bin/Debug/" + $(Release.ReleaseName) +$(Release.EnvironmentName)
</code></pre>
<p>but ins... | 28,322 | 1,123,020 | 2021-11-18 16:26:28 | 59,861,171 | 14 | 2020-01-22 13:47:09 | 45,375 | 2021-11-18 16:26:28 | https://stackoverflow.com/q/59860674 | https://stackoverflow.com/a/59861171 | <p><strong>tl;dr</strong></p>
<p>It is <em>Azure</em> that expands <code>$(System.DefaultWorkingDirectory)</code> <em>before</em> PowerShell sees the resulting commands; if the expanded <code>$(...)</code> value is to be seen as a <em>string</em> by PowerShell, it must be enclosed in <em>quotes</em> (<code>'$(...)'</co... | <p><strong>tl;dr</strong></p> <p>It is <em>Azure</em> that expands <code>$(System.DefaultWorkingDirectory)</code> <em>before</em> PowerShell sees the resulting commands; if the expanded <code>$(...)</code> value is to be seen as a <em>string</em> by PowerShell, it must be enclosed in <em>quotes</em> (<code>'$(...)'</co... | 526, 116537, 119596 | azure-devops, azure-pipelines, powershell | <h1>How to correctly concatenate string in Powershell inline script in Azure DevOps?</h1>
<p>I try to concatenate string to construct a path:</p>
<pre><code>$SourceDirectoryPath = $(System.DefaultWorkingDirectory) + "/solution/project/bin/Debug"
$TargetFilePath = $(System.DefaultWorkingDirectory) + "/solution/project/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,932 | bash | # How to correctly concatenate string in Powershell inline script in Azure DevOps?
I try to concatenate string to construct a path:
```
$SourceDirectoryPath = $(System.DefaultWorkingDirectory) + "/solution/project/bin/Debug"
$TargetFilePath = $(System.DefaultWorkingDirectory) + "/solution/project/bin/Debug/" + $(Rele... | **tl;dr**
It is *Azure* that expands `$(System.DefaultWorkingDirectory)` *before* PowerShell sees the resulting commands; if the expanded `$(...)` value is to be seen as a *string* by PowerShell, it must be enclosed in *quotes* (`'$(...)'`):
- Using **`$(...)` (Azure macro syntax)** **embeds the Azure variable's *ver... |
47580240 | Bcrypt for BASH Shell? | 7 | 2017-11-30 18:26:05 | <p>I'm searching for a way to hash a password using BCRYPT in a BASH script. I've searched high and low, and googled all the things ... the closest I've come is maybe an implementation using openssl, but the method is still unclear.</p>
<p>I am in a closed system with no external access, and python is not installed.</... | 18,763 | 2,183,303 | 2019-12-12 01:49:53 | 59,296,540 | 14 | 2019-12-12 01:43:43 | 4,599,129 | 2019-12-12 01:49:53 | https://stackoverflow.com/q/47580240 | https://stackoverflow.com/a/59296540 | <p>This is what I use</p>
<pre><code>leo@xxx:~$ htpasswd -nbBC 10 USER topsecret
USER:$2y$10$vDtCxgJ4DIZ1itAAq6NDkedmaDFHlPdlpLY.EiEa3QBXHnH0oLatW
</code></pre>
<p>Please note the salt prefix (i.e. <em>$2a</em> or <em>$2y</em>) could be different in different system/platform.</p>
<p>My computer</p>
<pre><code>leo@... | <p>This is what I use</p> <pre><code>leo@xxx:~$ htpasswd -nbBC 10 USER topsecret USER:$2y$10$vDtCxgJ4DIZ1itAAq6NDkedmaDFHlPdlpLY.EiEa3QBXHnH0oLatW </code></pre> <p>Please note the salt prefix (i.e. <em>$2a</em> or <em>$2y</em>) could be different in different system/platform.</p> <p>My computer</p> <pre><code>leo@... | 58, 219, 387, 390, 15822 | bash, bcrypt, encryption, linux, shell | <h1>Bcrypt for BASH Shell?</h1>
<p>I'm searching for a way to hash a password using BCRYPT in a BASH script. I've searched high and low, and googled all the things ... the closest I've come is maybe an implementation using openssl, but the method is still unclear.</p>
<p>I am in a closed system with no external access... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,933 | bash | # Bcrypt for BASH Shell?
I'm searching for a way to hash a password using BCRYPT in a BASH script. I've searched high and low, and googled all the things ... the closest I've come is maybe an implementation using openssl, but the method is still unclear.
I am in a closed system with no external access, and python is ... | This is what I use
```
leo@xxx:~$ htpasswd -nbBC 10 USER topsecret
USER:$2y$10$vDtCxgJ4DIZ1itAAq6NDkedmaDFHlPdlpLY.EiEa3QBXHnH0oLatW
```
Please note the salt prefix (i.e. *$2a* or *$2y*) could be different in different system/platform.
My computer
```
leo@xxx:~$ uname -a
Linux xxx 5.0.0-37-generic #40~18.04.1-Ubunt... |
54041174 | How can I find all the folders that contain certain file extensions in Bash? | 7 | 2019-01-04 14:46:35 | <p>I need to write a Bash script (preferably a one-liner) to find all the <strong>subdirectories</strong> under the current directory which contain any files with a certain file extension, namely <code>.tf</code>. The tricky part is that there may be more than one <code>.tf</code> file in a folder, and <em>I need the f... | 5,132 | 5,454 | 2019-01-04 16:36:11 | 54,041,286 | 14 | 2019-01-04 14:53:09 | 147,356 | 2019-01-04 14:53:09 | https://stackoverflow.com/q/54041174 | https://stackoverflow.com/a/54041286 | <p>You can use find's <code>-printf</code> action to print out just the directory name, and then remove duplicates:</p>
<pre><code>find . -name '*.tf' -not -path '*.terraform*' -printf '%h\n' | sort -u
</code></pre>
<p>The <code>-printf '%h\n'</code> prints out the name of the directory containing matched files, whil... | <p>You can use find's <code>-printf</code> action to print out just the directory name, and then remove duplicates:</p> <pre><code>find . -name '*.tf' -not -path '*.terraform*' -printf '%h\n' | sort -u </code></pre> <p>The <code>-printf '%h\n'</code> prints out the name of the directory containing matched files, whil... | 387 | bash | <h1>How can I find all the folders that contain certain file extensions in Bash?</h1>
<p>I need to write a Bash script (preferably a one-liner) to find all the <strong>subdirectories</strong> under the current directory which contain any files with a certain file extension, namely <code>.tf</code>. The tricky part is t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,934 | bash | # How can I find all the folders that contain certain file extensions in Bash?
I need to write a Bash script (preferably a one-liner) to find all the **subdirectories** under the current directory which contain any files with a certain file extension, namely `.tf`. The tricky part is that there may be more than one `.... | You can use find's `-printf` action to print out just the directory name, and then remove duplicates:
```
find . -name '*.tf' -not -path '*.terraform*' -printf '%h\n' | sort -u
```
The `-printf '%h\n'` prints out the name of the directory containing matched files, while the `sort -u` at the end removes duplicates. |
50965417 | awk command fails in snakemake --use-singularity | 7 | 2018-06-21 09:44:59 | <p>I am trying to combine Snakemake with Singularity, and I noticed that a simple <code>awk</code> command no longer works when using singularity. The <code>$1</code> in the last line gets replaced by bash instead of being used as the first field by <code>awk</code>.</p>
<p>Here is a minimal working example (<em>Snake... | 6,158 | 8,118,305 | 2018-11-20 00:58:03 | 53,384,755 | 14 | 2018-11-20 00:58:03 | 3,997,411 | 2018-11-20 00:58:03 | https://stackoverflow.com/q/50965417 | https://stackoverflow.com/a/53384755 | <p>I had a similar issue and after lots of trial and error finally solved it. Currently (November 2018, for Snakemake 5.3), this is somewhat undocumented, so I thought it is good to put it here for future reference to help others... </p>
<p><strong>All examples above incorrectly use the double quotation mark with bash... | <p>I had a similar issue and after lots of trial and error finally solved it. Currently (November 2018, for Snakemake 5.3), this is somewhat undocumented, so I thought it is good to put it here for future reference to help others... </p> <p><strong>All examples above incorrectly use the double quotation mark with bash... | 387, 119019, 131962 | bash, singularity-container, snakemake | <h1>awk command fails in snakemake --use-singularity</h1>
<p>I am trying to combine Snakemake with Singularity, and I noticed that a simple <code>awk</code> command no longer works when using singularity. The <code>$1</code> in the last line gets replaced by bash instead of being used as the first field by <code>awk</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,935 | bash | # awk command fails in snakemake --use-singularity
I am trying to combine Snakemake with Singularity, and I noticed that a simple `awk` command no longer works when using singularity. The `$1` in the last line gets replaced by bash instead of being used as the first field by `awk`.
Here is a minimal working example (... | I had a similar issue and after lots of trial and error finally solved it. Currently (November 2018, for Snakemake 5.3), this is somewhat undocumented, so I thought it is good to put it here for future reference to help others...
**All examples above incorrectly use the double quotation mark with bash -c, which is NOT... |
52456616 | Why does the "yes | sleep 10" pipe not fail | 7 | 2018-09-22 12:22:00 | <p>In thinking about how to implement a certain feature in one of my own programs I've been wondering how bash handles pipes of the following nature internally:</p>
<pre><code>yes | sleep 10
</code></pre>
<p>This obviously does nothing but I don't understand how this does not result in an error. I would have thought ... | 1,158 | 4,858,640 | 2018-10-08 05:23:22 | 52,456,906 | 14 | 2018-09-22 13:01:37 | 387,076 | 2018-09-22 13:01:37 | https://stackoverflow.com/q/52456616 | https://stackoverflow.com/a/52456906 | <p>Here's what actually happens when you run the shell command <code>yes | sleep 10</code>.</p>
<p>First the shell creates an <a href="https://en.wikipedia.org/wiki/Anonymous_pipe" rel="noreferrer">anonymous pipe</a> using the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html" rel="noreferre... | <p>Here's what actually happens when you run the shell command <code>yes | sleep 10</code>.</p> <p>First the shell creates an <a href="https://en.wikipedia.org/wiki/Anonymous_pipe" rel="noreferrer">anonymous pipe</a> using the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html" rel="noreferre... | 387, 5813 | bash, pipe | <h1>Why does the "yes | sleep 10" pipe not fail</h1>
<p>In thinking about how to implement a certain feature in one of my own programs I've been wondering how bash handles pipes of the following nature internally:</p>
<pre><code>yes | sleep 10
</code></pre>
<p>This obviously does nothing but I don't understand how th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,936 | bash | # Why does the "yes | sleep 10" pipe not fail
In thinking about how to implement a certain feature in one of my own programs I've been wondering how bash handles pipes of the following nature internally:
```
yes | sleep 10
```
This obviously does nothing but I don't understand how this does not result in an error. I... | Here's what actually happens when you run the shell command `yes | sleep 10`.
First the shell creates an [anonymous pipe](https://en.wikipedia.org/wiki/Anonymous_pipe) using the [`pipe` system call](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html). The `pipe` system call opens two file descriptors ... |
52393850 | How to Install GNU Parallel on Windows 10 using git-bash | 7 | 2018-09-18 20:03:30 | <p>Has anyone been able to successfully use GNU Parallel on Windows 10 with git-bash? <strong>Is it possible?</strong> - If so, how?</p>
<hr>
<p><strong>Background:</strong>
I'm having trouble installing GNU Parallel and using it, and it got me thinking - <em>maybe git-bash is holding me back?</em> I'm sure if I ins... | 10,904 | 484,732 | 2021-07-08 19:04:25 | 52,451,011 | 14 | 2018-09-21 20:59:47 | 363,028 | 2021-07-08 19:04:25 | https://stackoverflow.com/q/52393850 | https://stackoverflow.com/a/52451011 | <p>I just installed <code>git-bash</code> on a Microsoft Windows 10 machine and had no problems installing GNU Parallel.</p>
<p>It is by no means well tested on git-bash, but basic functionality clearly works.</p>
<blockquote>
<p>I'm having trouble installing GNU Parallel</p>
</blockquote>
<p>Maybe you can post the err... | <p>I just installed <code>git-bash</code> on a Microsoft Windows 10 machine and had no problems installing GNU Parallel.</p> <p>It is by no means well tested on git-bash, but basic functionality clearly works.</p> <blockquote> <p>I'm having trouble installing GNU Parallel</p> </blockquote> <p>Maybe you can post the err... | 34, 64, 387, 61874, 82247 | bash, git-bash, gnu-parallel, unix, windows | <h1>How to Install GNU Parallel on Windows 10 using git-bash</h1>
<p>Has anyone been able to successfully use GNU Parallel on Windows 10 with git-bash? <strong>Is it possible?</strong> - If so, how?</p>
<hr>
<p><strong>Background:</strong>
I'm having trouble installing GNU Parallel and using it, and it got me thinki... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,937 | bash | # How to Install GNU Parallel on Windows 10 using git-bash
Has anyone been able to successfully use GNU Parallel on Windows 10 with git-bash? **Is it possible?** - If so, how?
---
**Background:**
I'm having trouble installing GNU Parallel and using it, and it got me thinking - *maybe git-bash is holding me back?* I'... | I just installed `git-bash` on a Microsoft Windows 10 machine and had no problems installing GNU Parallel.
It is by no means well tested on git-bash, but basic functionality clearly works.
> I'm having trouble installing GNU Parallel
Maybe you can post the error you get when running:
```
$ (wget -O - pi.dk/3 || lyn... |
49351437 | Combine a shell script and a zip file into a single executable for deployment | 7 | 2018-03-18 18:27:50 | <p>I have two files for deployment,</p>
<p>1) <code>deploymentpackage.zip</code> -> It contains the database package with few shell scripts.</p>
<p>2) <code>deployment.sh</code> -> It is the primary shell script which first unzips the deploymentpackage.zip and then execute the list of shell files inside it.</p>
<p>I... | 3,440 | 1,602,853 | 2019-12-02 22:55:07 | 49,351,570 | 14 | 2018-03-18 18:41:18 | 641,955 | 2018-03-18 18:49:19 | https://stackoverflow.com/q/49351437 | https://stackoverflow.com/a/49351570 | <p>If it's ok to assume that the user who will run the script has the <code>unzip</code> utility, then you can create a script like this:</p>
<pre><code>#!/usr/bin/env bash
# commands that you need to do ...
# ...
unzip <(tail -n +$((LINENO + 2)) "$0")
exit
</code></pre>
<p>Make sure the script has a newline <co... | <p>If it's ok to assume that the user who will run the script has the <code>unzip</code> utility, then you can create a script like this:</p> <pre><code>#!/usr/bin/env bash # commands that you need to do ... # ... unzip <(tail -n +$((LINENO + 2)) "$0") exit </code></pre> <p>Make sure the script has a newline <co... | 58, 190, 387, 390 | bash, deployment, linux, shell | <h1>Combine a shell script and a zip file into a single executable for deployment</h1>
<p>I have two files for deployment,</p>
<p>1) <code>deploymentpackage.zip</code> -> It contains the database package with few shell scripts.</p>
<p>2) <code>deployment.sh</code> -> It is the primary shell script which first unzips ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,938 | bash | # Combine a shell script and a zip file into a single executable for deployment
I have two files for deployment,
1) `deploymentpackage.zip` -> It contains the database package with few shell scripts.
2) `deployment.sh` -> It is the primary shell script which first unzips the deploymentpackage.zip and then execute th... | If it's ok to assume that the user who will run the script has the `unzip` utility, then you can create a script like this:
```
#!/usr/bin/env bash
# commands that you need to do ...
# ...
unzip <(tail -n +$((LINENO + 2)) "$0")
exit
```
Make sure the script has a newline `\n` character at the end of the line of `ex... |
49322682 | Powershell: conditional flag based on a local variable | 7 | 2018-03-16 14:07:15 | <p>There is a variable in my PowerShell script called <code>$IncludeSubfolders</code> (either <code>0</code> or <code>1</code>)</p>
<p>Depending on its value, I would like to call <code>Get-ChildItem</code> method either with or without the <code>-Recurse</code> option.</p>
<p>Currently, my code looks like this:</p>
... | 4,428 | 2,610,701 | 2018-03-16 14:18:13 | 49,322,900 | 14 | 2018-03-16 14:17:10 | 3,905,079 | 2018-03-16 14:17:10 | https://stackoverflow.com/q/49322682 | https://stackoverflow.com/a/49322900 | <p><code>$IncludeSubfolders</code> should ideally be a boolean value, not an integer, but it can be converted easily.</p>
<p>Even if you must keep it an integer, the code is the same.</p>
<pre><code>$Files = Get-ChildItem $RootPath -Name $FileMask -Recurse:$IncludeSubfolders
</code></pre>
<h2>Why?</h2>
<p>Because <... | <p><code>$IncludeSubfolders</code> should ideally be a boolean value, not an integer, but it can be converted easily.</p> <p>Even if you must keep it an integer, the code is the same.</p> <pre><code>$Files = Get-ChildItem $RootPath -Name $FileMask -Recurse:$IncludeSubfolders </code></pre> <h2>Why?</h2> <p>Because <... | 526, 1079, 39271, 108010 | conditional-statements, flags, powershell, powershell-5.0 | <h1>Powershell: conditional flag based on a local variable</h1>
<p>There is a variable in my PowerShell script called <code>$IncludeSubfolders</code> (either <code>0</code> or <code>1</code>)</p>
<p>Depending on its value, I would like to call <code>Get-ChildItem</code> method either with or without the <code>-Recurse... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,939 | bash | # Powershell: conditional flag based on a local variable
There is a variable in my PowerShell script called `$IncludeSubfolders` (either `0` or `1`)
Depending on its value, I would like to call `Get-ChildItem` method either with or without the `-Recurse` option.
Currently, my code looks like this:
```
if($IncludeSu... | `$IncludeSubfolders` should ideally be a boolean value, not an integer, but it can be converted easily.
Even if you must keep it an integer, the code is the same.
```
$Files = Get-ChildItem $RootPath -Name $FileMask -Recurse:$IncludeSubfolders
```
## Why?
Because `-Recurse` is a Switch parameter, which is a special... |
47960344 | Automatically detect when HDMI is plugged in | 7 | 2017-12-24 11:52:02 | <p>Sometimes I connect my laptop to my TV over HDMI to have a bigger screen. Unfortunately, it doesn't automatically switch the audio output, so I have to do that myself every single time I plug or unplug it, with either of those two, to have the sound come from where I want it to come from.</p>
<ul>
<li><code>pacmd s... | 23,995 | 8,163,419 | 2017-12-25 00:05:59 | 47,964,800 | 14 | 2017-12-25 00:05:59 | 3,988,526 | 2017-12-25 00:05:59 | https://stackoverflow.com/q/47960344 | https://stackoverflow.com/a/47964800 | <p>I am using two different ways to determine if HDMI is plugged in:</p>
<p>a) Using xrandr<br>
A simple xrandr will report your hdmi monitor as connected
To use this in a script you can do something like:</p>
<pre><code>hdmi_active=$(xrandr |grep ' connected' |grep 'HDMI' |awk '{print $1}')
</code></pre>
<p>Above w... | <p>I am using two different ways to determine if HDMI is plugged in:</p> <p>a) Using xrandr<br> A simple xrandr will report your hdmi monitor as connected To use this in a script you can do something like:</p> <pre><code>hdmi_active=$(xrandr |grep ' connected' |grep 'HDMI' |awk '{print $1}') </code></pre> <p>Above w... | 58, 348, 387, 73137 | audio, bash, hdmi, linux | <h1>Automatically detect when HDMI is plugged in</h1>
<p>Sometimes I connect my laptop to my TV over HDMI to have a bigger screen. Unfortunately, it doesn't automatically switch the audio output, so I have to do that myself every single time I plug or unplug it, with either of those two, to have the sound come from whe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,940 | bash | # Automatically detect when HDMI is plugged in
Sometimes I connect my laptop to my TV over HDMI to have a bigger screen. Unfortunately, it doesn't automatically switch the audio output, so I have to do that myself every single time I plug or unplug it, with either of those two, to have the sound come from where I want... | I am using two different ways to determine if HDMI is plugged in:
a) Using xrandr
A simple xrandr will report your hdmi monitor as connected
To use this in a script you can do something like:
```
hdmi_active=$(xrandr |grep ' connected' |grep 'HDMI' |awk '{print $1}')
```
Above will return the connected hdmi port (... |
47022407 | PowerShell run two processes in parallel and display combined stdout in the terminal | 7 | 2017-10-30 18:57:17 | <p>I'd like to get some help putting together a PowerShell script that starts two processes (in my case two servers that monitor file changes and report, writing stuff to stdout continuously) and mixes their respective outputs into one terminal window?</p>
<p>I am not interested in writing into files. I want to monito... | 7,124 | 2,715,716 | 2017-10-30 20:55:16 | 47,023,880 | 14 | 2017-10-30 20:46:10 | 4,003,407 | 2017-10-30 20:46:10 | https://stackoverflow.com/q/47022407 | https://stackoverflow.com/a/47023880 | <p>You can use <code>Start-Process</code> cmdlet with <code>-NoNewWindow</code> switch to start new independent console application attached to the same console window:</p>
<pre><code>Start-Process -NoNewWindow process1 arguments1
Start-Process -NoNewWindow process2 arguments2
</code></pre>
<p>If you want to start Po... | <p>You can use <code>Start-Process</code> cmdlet with <code>-NoNewWindow</code> switch to start new independent console application attached to the same console window:</p> <pre><code>Start-Process -NoNewWindow process1 arguments1 Start-Process -NoNewWindow process2 arguments2 </code></pre> <p>If you want to start Po... | 526 | powershell | <h1>PowerShell run two processes in parallel and display combined stdout in the terminal</h1>
<p>I'd like to get some help putting together a PowerShell script that starts two processes (in my case two servers that monitor file changes and report, writing stuff to stdout continuously) and mixes their respective outputs... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,941 | bash | # PowerShell run two processes in parallel and display combined stdout in the terminal
I'd like to get some help putting together a PowerShell script that starts two processes (in my case two servers that monitor file changes and report, writing stuff to stdout continuously) and mixes their respective outputs into one... | You can use `Start-Process` cmdlet with `-NoNewWindow` switch to start new independent console application attached to the same console window:
```
Start-Process -NoNewWindow process1 arguments1
Start-Process -NoNewWindow process2 arguments2
```
If you want to start PowerShell script this way, then you need to start ... |
46411970 | Add X days to a particular date in BASH | 7 | 2017-09-25 18:33:51 | <p>Totally new to BASH. Apologies in advance.</p>
<hr>
<p><strong>Problem</strong></p>
<p>I'd like to add X days to a specific date. </p>
<hr>
<p><strong>Code</strong></p>
<p>I figured out that <code>date</code> in BASH retrieves the current date. </p>
<p>I also figured out that I can add X days to the current d... | 10,910 | 7,326,714 | 2025-09-11 06:51:24 | 46,412,019 | 14 | 2017-09-25 18:36:35 | 548,225 | 2017-09-25 18:50:41 | https://stackoverflow.com/q/46411970 | https://stackoverflow.com/a/46412019 | <p>You can do this way:</p>
<pre><code>dt='2017-09-20'
date -d "$dt +1 day"
Thu Sep 21 00:00:00 EDT 2017
date -d "$dt +2 day"
Fri Sep 22 00:00:00 EDT 2017
</code></pre>
<hr>
<p>It seems OP is using OSX. You can use date addition this way:</p>
<pre><code>s='20/09/2017'
date -j -v +1d -f "%d/%m/%Y" "$s"
Thu Sep 21... | <p>You can do this way:</p> <pre><code>dt='2017-09-20' date -d "$dt +1 day" Thu Sep 21 00:00:00 EDT 2017 date -d "$dt +2 day" Fri Sep 22 00:00:00 EDT 2017 </code></pre> <hr> <p>It seems OP is using OSX. You can use date addition this way:</p> <pre><code>s='20/09/2017' date -j -v +1d -f "%d/%m/%Y" "$s" Thu Sep 21... | 369, 387, 5002 | bash, date, macos | <h1>Add X days to a particular date in BASH</h1>
<p>Totally new to BASH. Apologies in advance.</p>
<hr>
<p><strong>Problem</strong></p>
<p>I'd like to add X days to a specific date. </p>
<hr>
<p><strong>Code</strong></p>
<p>I figured out that <code>date</code> in BASH retrieves the current date. </p>
<p>I also f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,942 | bash | # Add X days to a particular date in BASH
Totally new to BASH. Apologies in advance.
---
**Problem**
I'd like to add X days to a specific date.
---
**Code**
I figured out that `date` in BASH retrieves the current date.
I also figured out that I can add X days to the current date in the following way,
```
expir... | You can do this way:
```
dt='2017-09-20'
date -d "$dt +1 day"
Thu Sep 21 00:00:00 EDT 2017
date -d "$dt +2 day"
Fri Sep 22 00:00:00 EDT 2017
```
---
It seems OP is using OSX. You can use date addition this way:
```
s='20/09/2017'
date -j -v +1d -f "%d/%m/%Y" "$s"
Thu Sep 21 14:49:51 EDT 2017
``` |
46351722 | How to combine getopts and positional parameters in bash? | 7 | 2017-09-21 19:23:11 | <p>I want to use both <code>getopts</code> and positional parameters, but if I pass in a positional parameter to the program the <code>getopts</code> get lost.</p>
<pre><code>directory=$1
while getopts l: flag; do
case "$flag" in
l) level=$OPTARG;;
esac
done
if [ -n "$level" ]; then
echo "Level exist!"
els... | 4,391 | 1,473,423 | 2020-11-19 02:09:04 | 46,352,129 | 14 | 2017-09-21 19:49:03 | 7,552 | 2020-11-19 02:09:04 | https://stackoverflow.com/q/46351722 | https://stackoverflow.com/a/46352129 | <p>Most tools are written in the form: <code>tool [options] arg ...</code></p>
<p>So you would do this:</p>
<pre><code># first, parse the options:
while getopts l: flag; do
case "$flag" in
l) level=$OPTARG;;
\?) exit 42;;
esac
done
# and shift them away
shift $((OPTIND - 1))
# validation
if [ -n... | <p>Most tools are written in the form: <code>tool [options] arg ...</code></p> <p>So you would do this:</p> <pre><code># first, parse the options: while getopts l: flag; do case "$flag" in l) level=$OPTARG;; \?) exit 42;; esac done # and shift them away shift $((OPTIND - 1)) # validation if [ -n... | 360, 387, 390, 19020 | bash, getopts, parameters, shell | <h1>How to combine getopts and positional parameters in bash?</h1>
<p>I want to use both <code>getopts</code> and positional parameters, but if I pass in a positional parameter to the program the <code>getopts</code> get lost.</p>
<pre><code>directory=$1
while getopts l: flag; do
case "$flag" in
l) level=$OPTAR... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,943 | bash | # How to combine getopts and positional parameters in bash?
I want to use both `getopts` and positional parameters, but if I pass in a positional parameter to the program the `getopts` get lost.
```
directory=$1
while getopts l: flag; do
case "$flag" in
l) level=$OPTARG;;
esac
done
if [ -n "$level" ]; then
... | Most tools are written in the form: `tool [options] arg ...`
So you would do this:
```
# first, parse the options:
while getopts l: flag; do
case "$flag" in
l) level=$OPTARG;;
\?) exit 42;;
esac
done
# and shift them away
shift $((OPTIND - 1))
# validation
if [ -n "$level" ]; then
echo "Level exist!"
... |
46119832 | CMake get HOSTNAME environment variable | 7 | 2017-09-08 15:25:46 | <p>I have both HOSTNAME and USER defined as environment variables (Linux Ubuntu)</p>
<pre><code>echo $USER
pvicente
echo $HOSTNAME
glace
</code></pre>
<p>I get the variables in CMakeLists.txt using</p>
<pre><code>message("-- USER environment variable is set to: " $ENV{USER})
message("-- HOSTNAME environment variable... | 5,796 | 4,739,800 | 2017-09-16 12:49:12 | 46,122,556 | 14 | 2017-09-08 18:27:23 | 4,763,489 | 2017-09-08 18:27:23 | https://stackoverflow.com/q/46119832 | https://stackoverflow.com/a/46122556 | <p>You could check which environment variables CMake does see with</p>
<pre><code>$ cmake -E environment
</code></pre>
<p>It gives my hostname in an environment variable named <code>NAME</code>. So try:</p>
<pre><code>message("-- USER environment variable is set to: " $ENV{USER})
message("-- HOSTNAME environment var... | <p>You could check which environment variables CMake does see with</p> <pre><code>$ cmake -E environment </code></pre> <p>It gives my hostname in an environment variable named <code>NAME</code>. So try:</p> <pre><code>message("-- USER environment variable is set to: " $ENV{USER}) message("-- HOSTNAME environment var... | 58, 387, 549, 8822, 9013 | bash, cmake, environment-variables, linux, ubuntu | <h1>CMake get HOSTNAME environment variable</h1>
<p>I have both HOSTNAME and USER defined as environment variables (Linux Ubuntu)</p>
<pre><code>echo $USER
pvicente
echo $HOSTNAME
glace
</code></pre>
<p>I get the variables in CMakeLists.txt using</p>
<pre><code>message("-- USER environment variable is set to: " $ENV... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,944 | bash | # CMake get HOSTNAME environment variable
I have both HOSTNAME and USER defined as environment variables (Linux Ubuntu)
```
echo $USER
pvicente
echo $HOSTNAME
glace
```
I get the variables in CMakeLists.txt using
```
message("-- USER environment variable is set to: " $ENV{USER})
message("-- HOSTNAME environment var... | You could check which environment variables CMake does see with
```
$ cmake -E environment
```
It gives my hostname in an environment variable named `NAME`. So try:
```
message("-- USER environment variable is set to: " $ENV{USER})
message("-- HOSTNAME environment variable is set to: " $ENV{NAME})
```
But the offic... |
45192835 | need to change values of json file using sed | 7 | 2017-07-19 13:58:51 | <p>I need to change values of JSON file using sed,</p>
<p>I saw a lot of people suggesting using jq, python, or Perl.</p>
<p>But I'm working inside a container and I want it to be as simple as possible so only sed is the needed solution for me.</p>
<p>the JSON file is:</p>
<pre><code>{
"useCaseName" : "rca",
"a... | 25,365 | 1,783,632 | 2024-02-07 22:36:13 | 45,193,610 | 14 | 2017-07-19 14:28:12 | 1,815,837 | 2017-07-19 14:28:12 | https://stackoverflow.com/q/45192835 | https://stackoverflow.com/a/45193610 | <p>For sed use the following</p>
<pre><code>sed -i '/spark.driver.memory/c\ \"spark.driver.memory\" : \"1gb\",' file.txt
sed -i '/spark.executor.memory/c\ \"spark.executor.memory\" : \"1gb\",' file.txt
sed -i '/spark.cores.max/c\ \"spark.cores.max\" : \"1\",' file.txt
sed -i '/period/c\ \"period\" : \"15\",' f... | <p>For sed use the following</p> <pre><code>sed -i '/spark.driver.memory/c\ \"spark.driver.memory\" : \"1gb\",' file.txt sed -i '/spark.executor.memory/c\ \"spark.executor.memory\" : \"1gb\",' file.txt sed -i '/spark.cores.max/c\ \"spark.cores.max\" : \"1\",' file.txt sed -i '/period/c\ \"period\" : \"15\",' f... | 387, 5282 | bash, sed | <h1>need to change values of json file using sed</h1>
<p>I need to change values of JSON file using sed,</p>
<p>I saw a lot of people suggesting using jq, python, or Perl.</p>
<p>But I'm working inside a container and I want it to be as simple as possible so only sed is the needed solution for me.</p>
<p>the JSON fi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,945 | bash | # need to change values of json file using sed
I need to change values of JSON file using sed,
I saw a lot of people suggesting using jq, python, or Perl.
But I'm working inside a container and I want it to be as simple as possible so only sed is the needed solution for me.
the JSON file is:
```
{
"useCaseName" ... | For sed use the following
```
sed -i '/spark.driver.memory/c\ \"spark.driver.memory\" : \"1gb\",' file.txt
sed -i '/spark.executor.memory/c\ \"spark.executor.memory\" : \"1gb\",' file.txt
sed -i '/spark.cores.max/c\ \"spark.cores.max\" : \"1\",' file.txt
sed -i '/period/c\ \"period\" : \"15\",' file.txt
``` |
45058955 | Batch - minimize window while running a loop command (not start minimized) | 7 | 2017-07-12 13:24:29 | <p>I'm wondering if there is a way to minimize a batch window after it runs a certain command. I already know start /min and tricks to START the window minimized but what about while it's running a loop or timeout?</p>
<p>Let's say:</p>
<pre><code>echo Hello!
timeout /t 100
:COMMAND TO MINIMIZE WINDOW WHILE TIMEOUT I... | 17,205 | 7,228,003 | 2020-08-07 14:38:35 | 45,061,676 | 14 | 2017-07-12 15:17:02 | 1,683,264 | 2017-07-12 15:17:02 | https://stackoverflow.com/q/45058955 | https://stackoverflow.com/a/45061676 | <p>Use PowerShell's invocation options, executing no command or script.</p>
<pre class="lang-js prettyprint-override"><code>@echo off & setlocal
echo Hello!
powershell -window minimized -command ""
timeout /t 100
powershell -window normal -command ""
</code></pre>
<p>FWIW, <code>-window hidden</code> is also a... | <p>Use PowerShell's invocation options, executing no command or script.</p> <pre class="lang-js prettyprint-override"><code>@echo off & setlocal echo Hello! powershell -window minimized -command "" timeout /t 100 powershell -window normal -command "" </code></pre> <p>FWIW, <code>-window hidden</code> is also a... | 494, 526, 4963, 7002, 10264 | batch-file, minimize, powershell, vbscript, window | <h1>Batch - minimize window while running a loop command (not start minimized)</h1>
<p>I'm wondering if there is a way to minimize a batch window after it runs a certain command. I already know start /min and tricks to START the window minimized but what about while it's running a loop or timeout?</p>
<p>Let's say:</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,946 | bash | # Batch - minimize window while running a loop command (not start minimized)
I'm wondering if there is a way to minimize a batch window after it runs a certain command. I already know start /min and tricks to START the window minimized but what about while it's running a loop or timeout?
Let's say:
```
echo Hello!
t... | Use PowerShell's invocation options, executing no command or script.
```
@echo off & setlocal
echo Hello!
powershell -window minimized -command ""
timeout /t 100
powershell -window normal -command ""
```
FWIW, `-window hidden` is also available if you wish. |
45059358 | How can I split a string into an array on every newline? | 7 | 2017-07-12 13:40:32 | <p>In my situation, I will have a string that looks like this.</p>
<pre><code>$emailList = "example@mail.com
example2@mail.com
example3@mail.com"
</code></pre>
<p>How can I port this into an array with no white-space so it would look like</p>
<pre><code>$emailList = @("example@mail.com","... | 18,114 | 5,969,629 | 2021-03-18 12:53:55 | 45,060,282 | 14 | 2017-07-12 14:18:48 | 2,796,058 | 2017-07-12 14:18:48 | https://stackoverflow.com/q/45059358 | https://stackoverflow.com/a/45060282 | <p>Per the comments, if you do this:</p>
<pre><code>($emailList -split '\r?\n').Trim()
</code></pre>
<p>It uses <code>-split</code> to separate the list in to an array based on the new line/return charaters and then <code>.Trim()</code> to remove any whitespace either side of each string. </p>
<p>Following this the ... | <p>Per the comments, if you do this:</p> <pre><code>($emailList -split '\r?\n').Trim() </code></pre> <p>It uses <code>-split</code> to separate the list in to an array based on the new line/return charaters and then <code>.Trim()</code> to remove any whitespace either side of each string. </p> <p>Following this the ... | 526 | powershell | <h1>How can I split a string into an array on every newline?</h1>
<p>In my situation, I will have a string that looks like this.</p>
<pre><code>$emailList = "example@mail.com
example2@mail.com
example3@mail.com"
</code></pre>
<p>How can I port this into an array with no white-space so it w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,947 | bash | # How can I split a string into an array on every newline?
In my situation, I will have a string that looks like this.
```
$emailList = "example@mail.com
example2@mail.com
example3@mail.com"
```
How can I port this into an array with no white-space so it would look like
```
$emailList = ... | Per the comments, if you do this:
```
($emailList -split '\r?\n').Trim()
```
It uses `-split` to separate the list in to an array based on the new line/return charaters and then `.Trim()` to remove any whitespace either side of each string.
Following this the result is now already an array. However if you explicitly... |
43421755 | PowerShell regex -match only matching once | 7 | 2017-04-15 03:05:05 | <p>I'm trying to run through files named using alphabetical dates, and set file date-times accordingly. My code works fine, and I was ready to consider it complete, when I noticed this issue. My code should detect two dates and generate an error, but it doesn't. I've extracted the relevant code, and recreated the issue... | 7,148 | 3,199,491 | 2026-01-15 19:50:11 | 43,421,819 | 14 | 2017-04-15 03:16:32 | 45,375 | 2026-01-15 19:50:11 | https://stackoverflow.com/q/43421755 | https://stackoverflow.com/a/43421819 |
<p><strong>PowerShell's <code>-match</code> operator only ever looks for the <em>first</em> match (if any) per input string</strong>, because its purpose is to <em>test</em> for <em>a</em> (any) match, irrespective of whether there is more than one.</p>
<p><sup>Note that a single <code>-match</code> expression can hav... | <p><strong>PowerShell's <code>-match</code> operator only ever looks for the <em>first</em> match (if any) per input string</strong>, because its purpose is to <em>test</em> for <em>a</em> (any) match, irrespective of whether there is more than one.</p> <p><sup>Note that a single <code>-match</code> expression can hav... | 18, 526 | powershell, regex | <h1>PowerShell regex -match only matching once</h1>
<p>I'm trying to run through files named using alphabetical dates, and set file date-times accordingly. My code works fine, and I was ready to consider it complete, when I noticed this issue. My code should detect two dates and generate an error, but it doesn't. I've ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,948 | bash | # PowerShell regex -match only matching once
I'm trying to run through files named using alphabetical dates, and set file date-times accordingly. My code works fine, and I was ready to consider it complete, when I noticed this issue. My code should detect two dates and generate an error, but it doesn't. I've extracted... | **PowerShell's `-match` operator only ever looks for the *first* match (if any) per input string**, because its purpose is to *test* for *a* (any) match, irrespective of whether there is more than one.
Note that a single `-match` expression can have *multiple* input strings, if the LHS is an *array*, in which case an ... |
42564740 | MongoDB type update from NumberLong to String | 7 | 2017-03-02 19:55:20 | <p>I've imported CSV file to my mongodb. CSV have separators as needed to mongo and was received from MySQL database with this query:<br>
<code>SELECT * FROM csgo_users INTO OUTFILE 'b1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';</code> <br>
Also I've tried to receive CSV from Sequel Pro wit... | 11,539 | 6,066,986 | 2021-03-07 06:59:32 | 42,565,631 | 14 | 2017-03-02 20:47:48 | 6,299,938 | 2017-07-07 15:15:55 | https://stackoverflow.com/q/42564740 | https://stackoverflow.com/a/42565631 | <p>You can use valueOf() to get the value of a NumberLong as a javascript number value.</p>
<p><strong>Casting NumberLong to Number :</strong></p>
<pre><code>NumberLong('5').valueOf() // 5
</code></pre>
<p>Then, you can then use easilly <code>toString()</code> on your number to get the String value.</p>
<p><strong>... | <p>You can use valueOf() to get the value of a NumberLong as a javascript number value.</p> <p><strong>Casting NumberLong to Number :</strong></p> <pre><code>NumberLong('5').valueOf() // 5 </code></pre> <p>Then, you can then use easilly <code>toString()</code> on your number to get the String value.</p> <p><strong>... | 21, 73, 30073, 69521 | csv, mongodb, mongo-shell, mysql | <h1>MongoDB type update from NumberLong to String</h1>
<p>I've imported CSV file to my mongodb. CSV have separators as needed to mongo and was received from MySQL database with this query:<br>
<code>SELECT * FROM csgo_users INTO OUTFILE 'b1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';</code> ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,949 | bash | # MongoDB type update from NumberLong to String
I've imported CSV file to my mongodb. CSV have separators as needed to mongo and was received from MySQL database with this query:
`SELECT * FROM csgo_users INTO OUTFILE 'b1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';`
Also I've tried to ... | You can use valueOf() to get the value of a NumberLong as a javascript number value.
**Casting NumberLong to Number :**
```
NumberLong('5').valueOf() // 5
```
Then, you can then use easilly `toString()` on your number to get the String value.
**Casting NumberLong to String :**
```
NumberLong('5').valueOf().toStrin... |
41770139 | Variable assignment in nested function call unexpectedly changes local variable in the caller's scope | 7 | 2017-01-20 18:26:12 | <p><sup>
<strong>Editor's note</strong>:<br>
Perhaps the following, taken from the OP's own answer, better illustrates the surprising behavior:<br>
<code>f() { local b=1; g; echo $b; }; g() { b=2; }; f # -> '2'</code><br>
I.e., <code>g()</code> was able to modify <code>f()</code>'s <em>local</em> <code>$b</code> var... | 2,568 | 2,553,437 | 2020-03-22 03:01:26 | 41,771,664 | 14 | 2017-01-20 20:14:55 | 7,422,249 | 2020-03-22 03:01:26 | https://stackoverflow.com/q/41770139 | https://stackoverflow.com/a/41771664 | <p>Using <code>local</code> creates a variable that is not inherited from the parent scope.</p>
<p>There are useful things to add.</p>
<p>A local variable will be inherited (and can be modified) if the function that declares it calls another function. Therefore, <code>local</code> protects changes to a variable of t... | <p>Using <code>local</code> creates a variable that is not inherited from the parent scope.</p> <p>There are useful things to add.</p> <p>A local variable will be inherited (and can be modified) if the function that declares it calls another function. Therefore, <code>local</code> protects changes to a variable of t... | 387, 2182, 3791, 5569 | bash, function, scope, zsh | <h1>Variable assignment in nested function call unexpectedly changes local variable in the caller's scope</h1>
<p><sup>
<strong>Editor's note</strong>:<br>
Perhaps the following, taken from the OP's own answer, better illustrates the surprising behavior:<br>
<code>f() { local b=1; g; echo $b; }; g() { b=2; }; f # ->... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,950 | bash | # Variable assignment in nested function call unexpectedly changes local variable in the caller's scope
**Editor's note**:
Perhaps the following, taken from the OP's own answer, better illustrates the surprising behavior:
`f() { local b=1; g; echo $b; }; g() { b=2; }; f # -> '2'`
I.e., `g()` was able to modify `... | Using `local` creates a variable that is not inherited from the parent scope.
There are useful things to add.
A local variable will be inherited (and can be modified) if the function that declares it calls another function. Therefore, `local` protects changes to a variable of the same name inherited from higher in th... |
41477518 | Azure Resource Manager IP Security Restrictions using Powershell | 7 | 2017-01-05 04:53:59 | <p>I'm trying to use Powershell to set IP Security Restrictions. My syntax is not returning any errors, but settings are not changing. The "ipSecurityRestrictions" property is a hashtable.</p>
<pre><code>$r = Get-AzureRmResource -ResourceGroupName *resource-group-name* -ResourceType Microsoft.Web/sites/config -Resourc... | 4,194 | 7,377,310 | 2018-11-27 08:39:18 | 41,502,686 | 14 | 2017-01-06 09:32:34 | 7,005,159 | 2017-01-07 05:04:32 | https://stackoverflow.com/q/41477518 | https://stackoverflow.com/a/41502686 | <p><code>ipSecurityRestrictions</code> should be object array. Please have a try to change code as following. It works correctly for me.</p>
<pre><code>$r = Get-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01
$p =... | <p><code>ipSecurityRestrictions</code> should be object array. Please have a try to change code as following. It works correctly for me.</p> <pre><code>$r = Get-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01 $p =... | 526, 14158, 108005 | azure, azure-resource-manager, powershell | <h1>Azure Resource Manager IP Security Restrictions using Powershell</h1>
<p>I'm trying to use Powershell to set IP Security Restrictions. My syntax is not returning any errors, but settings are not changing. The "ipSecurityRestrictions" property is a hashtable.</p>
<pre><code>$r = Get-AzureRmResource -ResourceGroupNa... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,951 | bash | # Azure Resource Manager IP Security Restrictions using Powershell
I'm trying to use Powershell to set IP Security Restrictions. My syntax is not returning any errors, but settings are not changing. The "ipSecurityRestrictions" property is a hashtable.
```
$r = Get-AzureRmResource -ResourceGroupName *resource-group-n... | `ipSecurityRestrictions` should be object array. Please have a try to change code as following. It works correctly for me.
```
$r = Get-AzureRmResource -ResourceGroupName "Resoucegroup name" -ResourceType Microsoft.Web/sites/config -ResourceName resourcename/web -ApiVersion 2016-08-01
$p = $r.Properties
$p.ipSecurity... |
40967449 | Get List Of Functions From Script | 7 | 2016-12-05 05:07:46 | <p>If I have a .ps1 file with the following functions</p>
<pre><code>function SomeFunction {}
function AnotherFunction {}
</code></pre>
<p>How can I get a list of all those functions and invoke them?</p>
<p>I'd like to do something like this:</p>
<pre><code>$functionsFromFile = Get-ListOfFunctions -Path 'C:\someSc... | 14,505 | 2,063,755 | 2024-01-23 15:48:58 | 40,969,712 | 14 | 2016-12-05 08:07:38 | 1,163,423 | 2023-05-28 15:41:20 | https://stackoverflow.com/q/40967449 | https://stackoverflow.com/a/40969712 | <p>You could use the <code>Get-ChildItem</code> to retrieve all functions and store them into a variable. Then load the script into to runspace and retrieve all functions again and use the <code>Where-Object</code> cmdlet to filter all new functions by excluding all previously retrieved functions. Finally iterate over ... | <p>You could use the <code>Get-ChildItem</code> to retrieve all functions and store them into a variable. Then load the script into to runspace and retrieve all functions again and use the <code>Where-Object</code> cmdlet to filter all new functions by excluding all previously retrieved functions. Finally iterate over ... | 526 | powershell | <h1>Get List Of Functions From Script</h1>
<p>If I have a .ps1 file with the following functions</p>
<pre><code>function SomeFunction {}
function AnotherFunction {}
</code></pre>
<p>How can I get a list of all those functions and invoke them?</p>
<p>I'd like to do something like this:</p>
<pre><code>$functionsFrom... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,952 | bash | # Get List Of Functions From Script
If I have a .ps1 file with the following functions
```
function SomeFunction {}
function AnotherFunction {}
```
How can I get a list of all those functions and invoke them?
I'd like to do something like this:
```
$functionsFromFile = Get-ListOfFunctions -Path 'C:\someScript.ps1... | You could use the `Get-ChildItem` to retrieve all functions and store them into a variable. Then load the script into to runspace and retrieve all functions again and use the `Where-Object` cmdlet to filter all new functions by excluding all previously retrieved functions. Finally iterate over all new functions and inv... |
40244228 | Get formatted universal date / time | 7 | 2016-10-25 15:41:41 | <p>In PowerShell you can format a date to return the current hour like this:</p>
<pre><code>Get-Date -UFormat %H
</code></pre>
<p>And you can get a date string in UTC like this:</p>
<pre><code>$dateNow = Get-Date
$dateNow.ToUniversalTime()
</code></pre>
<p>But how can you can get the current hour in universal time?... | 7,910 | 3,252,835 | 2020-12-08 17:59:35 | 40,244,594 | 14 | 2016-10-25 16:00:05 | 45,375 | 2020-12-08 17:59:35 | https://stackoverflow.com/q/40244228 | https://stackoverflow.com/a/40244594 | <pre><code>Get-Date ([datetime]::UtcNow) -UFormat %H
</code></pre>
<p><strong>Up to PowerShell 7.0</strong>, <strong><code>Get-Date</code> doesn't directly support formatting the current time based on its UTC value</strong>: the formatting options apply to the <em>local</em> representation of the current time.</p>
<ul>... | <pre><code>Get-Date ([datetime]::UtcNow) -UFormat %H </code></pre> <p><strong>Up to PowerShell 7.0</strong>, <strong><code>Get-Date</code> doesn't directly support formatting the current time based on its UTC value</strong>: the formatting options apply to the <em>local</em> representation of the current time.</p> <ul>... | 526, 1263, 5998 | datetime, powershell, utc | <h1>Get formatted universal date / time</h1>
<p>In PowerShell you can format a date to return the current hour like this:</p>
<pre><code>Get-Date -UFormat %H
</code></pre>
<p>And you can get a date string in UTC like this:</p>
<pre><code>$dateNow = Get-Date
$dateNow.ToUniversalTime()
</code></pre>
<p>But how can yo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,953 | bash | # Get formatted universal date / time
In PowerShell you can format a date to return the current hour like this:
```
Get-Date -UFormat %H
```
And you can get a date string in UTC like this:
```
$dateNow = Get-Date
$dateNow.ToUniversalTime()
```
But how can you can get the current hour in universal time? | ```
Get-Date ([datetime]::UtcNow) -UFormat %H
```
**Up to PowerShell 7.0**, **`Get-Date` doesn't directly support formatting the current time based on its UTC value**: the formatting options apply to the *local* representation of the current time.
- In **PowerShell v7.1+** you can use the **`-AsUTC`** switch, which e... |
40049546 | Fix Mismatch Between Data And Local In Awk Command | 7 | 2016-10-14 18:09:57 | <p>I am receiving the following error:</p>
<p><code>awk: cmd. line:1: (FILENAME=- FNR=798) warning: Invalid multibyte data detected. There may be a mismatch between your data and your locale.</code></p>
<p>The command I'm running is the following:</p>
<p><code>cat file.txt | awk 'length($0)<10000' > output-fil... | 10,479 | 3,119,675 | 2019-06-26 16:36:00 | 40,052,815 | 14 | 2016-10-14 22:22:28 | 3,789,550 | 2016-10-14 22:22:28 | https://stackoverflow.com/q/40049546 | https://stackoverflow.com/a/40052815 | <p>Make the locale as <code>C</code> to use only ASCII character set with single byte encoding, pass <code>LC_ALL=C</code> to <code>awk</code>'s environment:</p>
<pre><code>LC_ALL=C awk 'length($0)<10000' file.txt >output-file.txt
</code></pre>
<p>Also you don't need to use <code>cat</code> as <code>awk</code> ... | <p>Make the locale as <code>C</code> to use only ASCII character set with single byte encoding, pass <code>LC_ALL=C</code> to <code>awk</code>'s environment:</p> <pre><code>LC_ALL=C awk 'length($0)<10000' file.txt >output-file.txt </code></pre> <p>Also you don't need to use <code>cat</code> as <code>awk</code> ... | 34, 58, 387, 990, 1921 | awk, bash, linux, locale, unix | <h1>Fix Mismatch Between Data And Local In Awk Command</h1>
<p>I am receiving the following error:</p>
<p><code>awk: cmd. line:1: (FILENAME=- FNR=798) warning: Invalid multibyte data detected. There may be a mismatch between your data and your locale.</code></p>
<p>The command I'm running is the following:</p>
<p><c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,954 | bash | # Fix Mismatch Between Data And Local In Awk Command
I am receiving the following error:
`awk: cmd. line:1: (FILENAME=- FNR=798) warning: Invalid multibyte data detected. There may be a mismatch between your data and your locale.`
The command I'm running is the following:
`cat file.txt | awk 'length($0)<10000' > ou... | Make the locale as `C` to use only ASCII character set with single byte encoding, pass `LC_ALL=C` to `awk`'s environment:
```
LC_ALL=C awk 'length($0)<10000' file.txt >output-file.txt
```
Also you don't need to use `cat` as `awk` takes filename(s) as argument(s). |
39781994 | How to get column index of field in unix shell | 7 | 2016-09-30 00:37:43 | <p>I have a csv file with headers:</p>
<pre><code>a,b,c,d,e,f,g,h
</code></pre>
<p>I would like to do something</p>
<pre><code>cat abc.csv | sed "something to split them" | grep "e"
#position of "e"
</code></pre>
<p>Can someone guide me how do I get the column idx of which header 'e' is... | 13,488 | 1,939,166 | 2020-09-25 12:27:17 | 39,782,016 | 14 | 2016-09-30 00:41:17 | 797,049 | 2018-04-29 20:35:48 | https://stackoverflow.com/q/39781994 | https://stackoverflow.com/a/39782016 | <p>Assuming your goal is to say "which column is this value in", you have a number of options, but this works:</p>
<pre><code>sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e'
#output: 5:e
</code></pre>
<p>If you want to get just the number out of that:</p>
<pre><code>sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e' | cut ... | <p>Assuming your goal is to say "which column is this value in", you have a number of options, but this works:</p> <pre><code>sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e' #output: 5:e </code></pre> <p>If you want to get just the number out of that:</p> <pre><code>sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e' | cut ... | 34, 73, 390, 5282 | csv, sed, shell, unix | <h1>How to get column index of field in unix shell</h1>
<p>I have a csv file with headers:</p>
<pre><code>a,b,c,d,e,f,g,h
</code></pre>
<p>I would like to do something</p>
<pre><code>cat abc.csv | sed "something to split them" | grep "e"
#position of "e"
</code></pre>
<p>Can someone gui... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,955 | bash | # How to get column index of field in unix shell
I have a csv file with headers:
```
a,b,c,d,e,f,g,h
```
I would like to do something
```
cat abc.csv | sed "something to split them" | grep "e"
#position of "e"
```
Can someone guide me how do I get the column idx of which header 'e' is at? | Assuming your goal is to say "which column is this value in", you have a number of options, but this works:
```
sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e'
#output: 5:e
```
If you want to get just the number out of that:
```
sed -n $'1s/,/\\\n/gp' abc.csv | grep -nx 'e' | cut -d: -f1
#output: 5
```
Explanation:
... |
38742842 | find command with 'regex' match not working | 7 | 2016-08-03 11:52:28 | <p>Am trying to do a simple file-name match with this below regex which I tested to be working from this <a href="https://regex101.com/" rel="noreferrer"><code>page</code></a> for a sample file-name <code>ABC_YYYYMMDDHHMMSS.sha1</code></p>
<pre><code>ABC_20[0-9]{2}(0[1-9]|1[0-2])([0-2][0-9]|3[0-1])([0-2][0-3])([0-5][0... | 8,274 | 5,291,015 | 2024-06-14 03:10:49 | 38,743,056 | 14 | 2016-08-03 12:00:54 | 2,660,911 | 2016-08-03 12:00:54 | https://stackoverflow.com/q/38742842 | https://stackoverflow.com/a/38743056 | <p>add <code>.*</code> at the start of your regex because you will always get something like <code>./</code> at start of path </p>
<pre><code>find . -type f -regextype posix-extended -regex '.*ABC_20[0-9]{2}(0[1-9]|1[0-2])([0-2][0-9]|3[0-1])([0-2][0-3])([0-5][0-9])([0-5][0-9])\.sha1'
</code></pre>
| <p>add <code>.*</code> at the start of your regex because you will always get something like <code>./</code> at start of path </p> <pre><code>find . -type f -regextype posix-extended -regex '.*ABC_20[0-9]{2}(0[1-9]|1[0-2])([0-2][0-9]|3[0-1])([0-2][0-3])([0-5][0-9])([0-5][0-9])\.sha1' </code></pre> | 18, 34, 387, 10193 | bash, find, regex, unix | <h1>find command with 'regex' match not working</h1>
<p>Am trying to do a simple file-name match with this below regex which I tested to be working from this <a href="https://regex101.com/" rel="noreferrer"><code>page</code></a> for a sample file-name <code>ABC_YYYYMMDDHHMMSS.sha1</code></p>
<pre><code>ABC_20[0-9]{2}(... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,956 | bash | # find command with 'regex' match not working
Am trying to do a simple file-name match with this below regex which I tested to be working from this [`page`](https://regex101.com/) for a sample file-name `ABC_YYYYMMDDHHMMSS.sha1`
```
ABC_20[0-9]{2}(0[1-9]|1[0-2])([0-2][0-9]|3[0-1])([0-2][0-3])([0-5][0-9])([0-5][0-9])\... | add `.*` at the start of your regex because you will always get something like `./` at start of path
```
find . -type f -regextype posix-extended -regex '.*ABC_20[0-9]{2}(0[1-9]|1[0-2])([0-2][0-9]|3[0-1])([0-2][0-3])([0-5][0-9])([0-5][0-9])\.sha1'
``` |
38697164 | Is it possible to print variable names? | 7 | 2016-08-01 11:01:56 | <p>Is it possible to print variable names in PowerShell?</p>
<pre><code>$myVariable = "My Value"
Write-Host "The variable name is ?????"
</code></pre>
<p>Expected output: </p>
<blockquote>
<p>The variable name is myVariable</p>
</blockquote>
<p>Question 2 (more tricky):
Is it possible to print variable name passe... | 19,061 | 782,534 | 2021-05-08 09:36:29 | 38,701,875 | 14 | 2016-08-01 14:48:33 | 712,649 | 2016-08-04 10:45:27 | https://stackoverflow.com/q/38697164 | https://stackoverflow.com/a/38701875 | <h1>No!</h1>
<p><em>(at least not in a reliable fashion)</em></p>
<p>The simple reason being that contextual information about a variable being referenced as a parameter argument will have been stripped away by the time you can actually inspect the parameter value inside the function.</p>
<p>Long before the function... | <h1>No!</h1> <p><em>(at least not in a reliable fashion)</em></p> <p>The simple reason being that contextual information about a variable being referenced as a parameter argument will have been stripped away by the time you can actually inspect the parameter value inside the function.</p> <p>Long before the function... | 526 | powershell | <h1>Is it possible to print variable names?</h1>
<p>Is it possible to print variable names in PowerShell?</p>
<pre><code>$myVariable = "My Value"
Write-Host "The variable name is ?????"
</code></pre>
<p>Expected output: </p>
<blockquote>
<p>The variable name is myVariable</p>
</blockquote>
<p>Question 2 (more tri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,957 | bash | # Is it possible to print variable names?
Is it possible to print variable names in PowerShell?
```
$myVariable = "My Value"
Write-Host "The variable name is ?????"
```
Expected output:
> The variable name is myVariable
Question 2 (more tricky):
Is it possible to print variable name passed to a function in PowerSh... | # No!
*(at least not in a reliable fashion)*
The simple reason being that contextual information about a variable being referenced as a parameter argument will have been stripped away by the time you can actually inspect the parameter value inside the function.
Long before the function is actually called, the parser... |
36407166 | Synchronize windows folders | 7 | 2016-04-04 15:44:20 | <p>I have set up remote sync in my eclipse to copy jsp and js files at different locations. I am observing that sometimes because of this sync (I need to keep build auto option enabled) eclipse is hanging and I need to kill the process.In windows do we have any option to sync two local folders. I searched but options I... | 11,159 | 4,130,820 | 2017-12-02 20:15:25 | 36,407,584 | 14 | 2016-04-04 16:05:32 | 6,111,454 | 2016-04-04 16:05:32 | https://stackoverflow.com/q/36407166 | https://stackoverflow.com/a/36407584 | <p>Fortunately, there is a useful little program in Windows called <code>robocopy</code> that ships with Win7 and above.</p>
<p><a href="https://technet.microsoft.com/en-us/library/cc733145.aspx" rel="noreferrer">https://technet.microsoft.com/en-us/library/cc733145.aspx</a></p>
<pre><code>robocopy <source> <... | <p>Fortunately, there is a useful little program in Windows called <code>robocopy</code> that ships with Win7 and above.</p> <p><a href="https://technet.microsoft.com/en-us/library/cc733145.aspx" rel="noreferrer">https://technet.microsoft.com/en-us/library/cc733145.aspx</a></p> <pre><code>robocopy <source> <... | 64, 526, 3885 | eclipse-plugin, powershell, windows | <h1>Synchronize windows folders</h1>
<p>I have set up remote sync in my eclipse to copy jsp and js files at different locations. I am observing that sometimes because of this sync (I need to keep build auto option enabled) eclipse is hanging and I need to kill the process.In windows do we have any option to sync two lo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,958 | bash | # Synchronize windows folders
I have set up remote sync in my eclipse to copy jsp and js files at different locations. I am observing that sometimes because of this sync (I need to keep build auto option enabled) eclipse is hanging and I need to kill the process.In windows do we have any option to sync two local folde... | Fortunately, there is a useful little program in Windows called `robocopy` that ships with Win7 and above.
<https://technet.microsoft.com/en-us/library/cc733145.aspx>
```
robocopy <source> <destination> /mir /copyall
```
This is what you can use to copy a source directory to a target directory including all subdirec... |
35881004 | exporting PATH not working in a bash shell on linux | 7 | 2016-03-09 00:56:01 | <p>For example, I type to the following command:</p>
<pre><code> # PATH=$PATH:/var/test
# echo $PATH
........./var/test // working
# export PATH
</code></pre>
<p>Next, I open another bash shell session to test if the export works by typing the following command:</p>
<pre><c... | 23,140 | 2,489,602 | 2016-03-09 01:09:25 | 35,881,047 | 14 | 2016-03-09 01:00:29 | 1,091,784 | 2016-03-09 01:09:25 | https://stackoverflow.com/q/35881004 | https://stackoverflow.com/a/35881047 | <p>you have set the <code>PATH</code> environment variable only for your current <code>bash</code> session. You need to add the line <code>PATH=$PATH:/var/test</code> into <code>~/.bashrc</code> so that it works for any <code>bash</code> shell. </p>
<p>Just run the following command to put it into your <code>rc</code... | <p>you have set the <code>PATH</code> environment variable only for your current <code>bash</code> session. You need to add the line <code>PATH=$PATH:/var/test</code> into <code>~/.bashrc</code> so that it works for any <code>bash</code> shell. </p> <p>Just run the following command to put it into your <code>rc</code... | 58, 387, 390 | bash, linux, shell | <h1>exporting PATH not working in a bash shell on linux</h1>
<p>For example, I type to the following command:</p>
<pre><code> # PATH=$PATH:/var/test
# echo $PATH
........./var/test // working
# export PATH
</code></pre>
<p>Next, I open another bash shell session to test if t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,959 | bash | # exporting PATH not working in a bash shell on linux
For example, I type to the following command:
```
# PATH=$PATH:/var/test
# echo $PATH
........./var/test // working
# export PATH
```
Next, I open another bash shell session to test if the export works by typing the fol... | you have set the `PATH` environment variable only for your current `bash` session. You need to add the line `PATH=$PATH:/var/test` into `~/.bashrc` so that it works for any `bash` shell.
Just run the following command to put it into your `rc`(run commands) file (rc files contain startup information for a command(initi... |
35078239 | Show DU outcome in purely megabytes | 7 | 2016-01-29 06:30:21 | <p>I am using <code>DU</code> function to output the directory size to a file and then move it to an excel file to add the total. Is it possible to output the size of a directory only in MB (even if the size is in KB or GB):</p>
<p>e.g. if the file size is 50kb the output would show 0.048MB</p>
<p>I'm aware of <code>... | 12,297 | 2,612,009 | 2018-02-21 07:17:13 | 35,078,450 | 14 | 2016-01-29 06:45:20 | 897,295 | 2016-01-29 08:09:49 | https://stackoverflow.com/q/35078239 | https://stackoverflow.com/a/35078450 | <p>It's the <code>-m</code> option. So, for example:</p>
<pre><code>$ du -s -m <my_directory_here>
</code></pre>
<p><strong>UPDATE</strong></p>
<p>Oh... you want an "M" printed after the number of megabytes. Here you are:</p>
<pre><code>$ du -s -m /usr/local | sed 's/^\([0-9]*\)\(.*\)$/\1M \2/'
</code></pre>
... | <p>It's the <code>-m</code> option. So, for example:</p> <pre><code>$ du -s -m <my_directory_here> </code></pre> <p><strong>UPDATE</strong></p> <p>Oh... you want an "M" printed after the number of megabytes. Here you are:</p> <pre><code>$ du -s -m /usr/local | sed 's/^\([0-9]*\)\(.*\)$/\1M \2/' </code></pre> ... | 58, 387, 2205, 26163 | bash, du, linux, redhat | <h1>Show DU outcome in purely megabytes</h1>
<p>I am using <code>DU</code> function to output the directory size to a file and then move it to an excel file to add the total. Is it possible to output the size of a directory only in MB (even if the size is in KB or GB):</p>
<p>e.g. if the file size is 50kb the output w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,960 | bash | # Show DU outcome in purely megabytes
I am using `DU` function to output the directory size to a file and then move it to an excel file to add the total. Is it possible to output the size of a directory only in MB (even if the size is in KB or GB):
e.g. if the file size is 50kb the output would show 0.048MB
I'm awar... | It's the `-m` option. So, for example:
```
$ du -s -m <my_directory_here>
```
**UPDATE**
Oh... you want an "M" printed after the number of megabytes. Here you are:
```
$ du -s -m /usr/local | sed 's/^\([0-9]*\)\(.*\)$/\1M \2/'
```
or...
```
$ du -s -m /usr/local | sed 's/^\([0-9]*\)\(.*\)$/\1MiB \2/'
```
or...
... |
33787200 | Get Directories Names Only | 7 | 2015-11-18 18:07:23 | <p>I have a directoy X that has say 500 subdirectories. What I need is a quick way to just get <em>only</em> my directory and the names of these 500 subdirectories in my X directory (so, no Mode, no LastWriteTime or anything else, just the name) and pipe it to a file.</p>
<p>So, for example, I have this:</p>
<pre><c... | 40,726 | 3,453,898 | 2015-11-19 14:13:04 | 33,806,279 | 14 | 2015-11-19 14:13:04 | 5,418,922 | 2015-11-19 14:13:04 | https://stackoverflow.com/q/33787200 | https://stackoverflow.com/a/33806279 | <p><code>Get-ChildItem</code> will do the same thing as <code>dir</code> in command-line: it gets whatever is in your directory. You're looking only for directories. PS v3 and up has this built-in by using the flag of <code>-directory</code>. In older PowerShell versions, you can pipe your <code>Get-ChildItem</code... | <p><code>Get-ChildItem</code> will do the same thing as <code>dir</code> in command-line: it gets whatever is in your directory. You're looking only for directories. PS v3 and up has this built-in by using the flag of <code>-directory</code>. In older PowerShell versions, you can pipe your <code>Get-ChildItem</code... | 526, 1231 | command-line, powershell | <h1>Get Directories Names Only</h1>
<p>I have a directoy X that has say 500 subdirectories. What I need is a quick way to just get <em>only</em> my directory and the names of these 500 subdirectories in my X directory (so, no Mode, no LastWriteTime or anything else, just the name) and pipe it to a file.</p>
<p>So, fo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,961 | bash | # Get Directories Names Only
I have a directoy X that has say 500 subdirectories. What I need is a quick way to just get *only* my directory and the names of these 500 subdirectories in my X directory (so, no Mode, no LastWriteTime or anything else, just the name) and pipe it to a file.
So, for example, I have this:
... | `Get-ChildItem` will do the same thing as `dir` in command-line: it gets whatever is in your directory. You're looking only for directories. PS v3 and up has this built-in by using the flag of `-directory`. In older PowerShell versions, you can pipe your `Get-ChildItem` to a `Where{$_.PSIsContainer` to get directories ... |
32622761 | Cookiecutter created directory giving me issues running development server and python shell | 7 | 2015-09-17 04:46:47 | <p>I created a django project using cookiecutter as reccomended by Two scoops of Django 1.8. It's called icecreamratings_project
I use the git cmd prompt and use </p>
<p>'cd icecreamratings_project'.</p>
<p>When i want to use the built-in python interpreter by using
python manage.py shell it gives me the following er... | 4,907 | 5,344,951 | 2015-09-17 05:55:20 | 32,623,416 | 14 | 2015-09-17 05:55:20 | 2,744,166 | 2015-09-17 05:55:20 | https://stackoverflow.com/q/32622761 | https://stackoverflow.com/a/32623416 | <p>The <code>environ</code> module can be found in <a href="https://django-environ.readthedocs.org/en/latest/">django-environ</a>. </p>
<p><code>django-environ</code> is a requirement of <a href="https://github.com/pydanny/cookiecutter-django">cookiecutter-django's</a> <a href="https://github.com/pydanny/cookiecutter-... | <p>The <code>environ</code> module can be found in <a href="https://django-environ.readthedocs.org/en/latest/">django-environ</a>. </p> <p><code>django-environ</code> is a requirement of <a href="https://github.com/pydanny/cookiecutter-django">cookiecutter-django's</a> <a href="https://github.com/pydanny/cookiecutter-... | 16, 119, 243, 390, 113036 | cookiecutter, django, git, python, shell | <h1>Cookiecutter created directory giving me issues running development server and python shell</h1>
<p>I created a django project using cookiecutter as reccomended by Two scoops of Django 1.8. It's called icecreamratings_project
I use the git cmd prompt and use </p>
<p>'cd icecreamratings_project'.</p>
<p>When i wan... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,962 | bash | # Cookiecutter created directory giving me issues running development server and python shell
I created a django project using cookiecutter as reccomended by Two scoops of Django 1.8. It's called icecreamratings_project
I use the git cmd prompt and use
'cd icecreamratings_project'.
When i want to use the built-in py... | The `environ` module can be found in [django-environ](https://django-environ.readthedocs.org/en/latest/).
`django-environ` is a requirement of [cookiecutter-django's](https://github.com/pydanny/cookiecutter-django) [`requirements/base.txt`](https://github.com/pydanny/cookiecutter-django/blob/ec12e84407ebbf762a8020f83e... |
31965874 | How to delete all files except directories? | 7 | 2015-08-12 12:55:02 | <p>I was searching unsuccessfully for a solution to delete all the files inside a working directory except for the subdirectories inside.</p>
<p>I found a way to delete all the files inside all the directories, but I'm looking for a way to delete only the files on the same "level" I'm on.</p>
| 19,348 | 3,253,953 | 2019-08-05 13:45:51 | 31,966,018 | 14 | 2015-08-12 13:00:54 | 1,552,737 | 2015-08-12 13:22:38 | https://stackoverflow.com/q/31965874 | https://stackoverflow.com/a/31966018 | <pre><code>find . -maxdepth 1 -type f -print0 | xargs -0 rm
</code></pre>
<p>The <code>find</code> command recursively searches a directory for files and folders that match the specified expressions.</p>
<ul>
<li><code>-maxdepth 1</code> will only search the current level (when used with <code>.</code> or the top lev... | <pre><code>find . -maxdepth 1 -type f -print0 | xargs -0 rm </code></pre> <p>The <code>find</code> command recursively searches a directory for files and folders that match the specified expressions.</p> <ul> <li><code>-maxdepth 1</code> will only search the current level (when used with <code>.</code> or the top lev... | 218, 387, 34708, 37510 | bash, delete-file, directory, subdirectory | <h1>How to delete all files except directories?</h1>
<p>I was searching unsuccessfully for a solution to delete all the files inside a working directory except for the subdirectories inside.</p>
<p>I found a way to delete all the files inside all the directories, but I'm looking for a way to delete only the files on t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,963 | bash | # How to delete all files except directories?
I was searching unsuccessfully for a solution to delete all the files inside a working directory except for the subdirectories inside.
I found a way to delete all the files inside all the directories, but I'm looking for a way to delete only the files on the same "level" ... | ```
find . -maxdepth 1 -type f -print0 | xargs -0 rm
```
The `find` command recursively searches a directory for files and folders that match the specified expressions.
- `-maxdepth 1` will only search the current level (when used with `.` or the top level when a directory is used instead), effectively turning of the... |
31611103 | Setting permissions on a windows fileshare | 7 | 2015-07-24 12:55:23 | <p>I have the following code which is supposed to go through the folders in the fileshare and turn whatever permissions there are into read permissions. However, there is a problem: it doesn't replace the permissions already there it merely adds to them. Secondly, if the folder has not got inherited permissions it give... | 13,956 | 4,911,608 | 2015-07-25 17:18:45 | 31,629,122 | 14 | 2015-07-25 17:18:45 | 3,874,447 | 2015-07-25 17:18:45 | https://stackoverflow.com/q/31611103 | https://stackoverflow.com/a/31629122 | <p>The biggest problem isn't with your code, but with the <a href="https://connect.microsoft.com/PowerShell/feedback/details/789418/unable-to-set-acl-using-set-acl-when-not-admin-on-acl-protected-folder" rel="noreferrer">Set-Acl Cmdlet/FileSystem provider combination</a>. When Set-Acl is being called, an attempt to wri... | <p>The biggest problem isn't with your code, but with the <a href="https://connect.microsoft.com/PowerShell/feedback/details/789418/unable-to-set-acl-using-set-acl-when-not-admin-on-acl-protected-folder" rel="noreferrer">Set-Acl Cmdlet/FileSystem provider combination</a>. When Set-Acl is being called, an attempt to wri... | 526 | powershell | <h1>Setting permissions on a windows fileshare</h1>
<p>I have the following code which is supposed to go through the folders in the fileshare and turn whatever permissions there are into read permissions. However, there is a problem: it doesn't replace the permissions already there it merely adds to them. Secondly, if ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,964 | bash | # Setting permissions on a windows fileshare
I have the following code which is supposed to go through the folders in the fileshare and turn whatever permissions there are into read permissions. However, there is a problem: it doesn't replace the permissions already there it merely adds to them. Secondly, if the folde... | The biggest problem isn't with your code, but with the [Set-Acl Cmdlet/FileSystem provider combination](https://connect.microsoft.com/PowerShell/feedback/details/789418/unable-to-set-acl-using-set-acl-when-not-admin-on-acl-protected-folder). When Set-Acl is being called, an attempt to write the entire security descript... |
31335600 | Fish keeps trying to use fish_vi_key_bindings although it is not in config.fish anymore | 7 | 2015-07-10 08:07:11 | <p>I am playing with fish and oh-my-fish on the cygwin terminal. It was working fine until I tried to turn on VI key bindings by setting the <code>fish_vi_key_bindings</code> in my <code>config.fish</code>.</p>
<p>It did not work. Apparently this only works from the version <code>2.2.x</code> on, and on cygwin I'm run... | 1,172 | 1,394,590 | 2015-07-10 16:00:17 | 31,345,324 | 14 | 2015-07-10 16:00:17 | 1,441,328 | 2015-07-10 16:00:17 | https://stackoverflow.com/q/31335600 | https://stackoverflow.com/a/31345324 | <p>You probably have the universal variable <code>$fish_key_bindings</code> set to something you don't want. Try running this (just once):</p>
<pre><code>set -U fish_key_bindings fish_default_key_bindings
</code></pre>
| <p>You probably have the universal variable <code>$fish_key_bindings</code> set to something you don't want. Try running this (just once):</p> <pre><code>set -U fish_key_bindings fish_default_key_bindings </code></pre> | 390, 55824 | fish, shell | <h1>Fish keeps trying to use fish_vi_key_bindings although it is not in config.fish anymore</h1>
<p>I am playing with fish and oh-my-fish on the cygwin terminal. It was working fine until I tried to turn on VI key bindings by setting the <code>fish_vi_key_bindings</code> in my <code>config.fish</code>.</p>
<p>It did n... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,965 | bash | # Fish keeps trying to use fish_vi_key_bindings although it is not in config.fish anymore
I am playing with fish and oh-my-fish on the cygwin terminal. It was working fine until I tried to turn on VI key bindings by setting the `fish_vi_key_bindings` in my `config.fish`.
It did not work. Apparently this only works fr... | You probably have the universal variable `$fish_key_bindings` set to something you don't want. Try running this (just once):
```
set -U fish_key_bindings fish_default_key_bindings
``` |
29360925 | What's the difference between `\;` and `+` at the end of a find command? | 7 | 2015-03-31 05:02:05 | <p>These are bash commands that are used to convert tabs to spaces.
Here's the <a href="https://stackoverflow.com/a/18469894/2925306">link</a> to the original stackoverflow post.</p>
<p>This one uses <code>\;</code> at the end of the command</p>
<pre><code>find /path/to/directory -type f -iname '*.js' -exec sed -ie '... | 2,462 | 2,925,306 | 2015-03-31 05:21:27 | 29,361,115 | 14 | 2015-03-31 05:21:27 | 827,263 | 2015-03-31 05:21:27 | https://stackoverflow.com/q/29360925 | https://stackoverflow.com/a/29361115 | <p>The <code>\;</code> or <code>+</code> is not related to bash. It's an argument to the <code>find</code> command, specifically to <code>find</code>'s <code>-exec</code> option.</p>
<p><code>find -exec</code> uses <code>{}</code> to pass the current file name to the specified command, and <code>\;</code> to mark the ... | <p>The <code>\;</code> or <code>+</code> is not related to bash. It's an argument to the <code>find</code> command, specifically to <code>find</code>'s <code>-exec</code> option.</p> <p><code>find -exec</code> uses <code>{}</code> to pass the current file name to the specified command, and <code>\;</code> to mark the ... | 387, 10193, 11225 | bash, command-line-interface, find | <h1>What's the difference between `\;` and `+` at the end of a find command?</h1>
<p>These are bash commands that are used to convert tabs to spaces.
Here's the <a href="https://stackoverflow.com/a/18469894/2925306">link</a> to the original stackoverflow post.</p>
<p>This one uses <code>\;</code> at the end of the com... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,966 | bash | # What's the difference between `\;` and `+` at the end of a find command?
These are bash commands that are used to convert tabs to spaces.
Here's the [link](https://stackoverflow.com/a/18469894/2925306) to the original stackoverflow post.
This one uses `\;` at the end of the command
```
find /path/to/directory -typ... | The `\;` or `+` is not related to bash. It's an argument to the `find` command, specifically to `find`'s `-exec` option.
`find -exec` uses `{}` to pass the current file name to the specified command, and `\;` to mark the end of the the command's arguments. The `\` is needed because `;` by itself *is* special to bash; ... |
28051969 | TCL/Expect equivalent of Bash $@ or how to pass arguments to spawned process in TCL/Expect | 7 | 2015-01-20 17:51:26 | <p>If somebody wants to call external program (which was passed as a Bash argument) from Bash and also pass it command line options (which were also passed as a Bash arguments) the solution is fairy simple:</p>
<pre><code>TCL_SCRIPT="$1"
shift
TCL_SCRIPT_ARGUMENTS="$@"
expect -f "$TCL_SCRIPT" "$TCL_SCRIPT_ARGUMENTS" 2... | 6,107 | 1,616,488 | 2021-03-26 14:53:31 | 28,052,786 | 14 | 2015-01-20 18:39:31 | 7,552 | 2015-01-20 18:57:09 | https://stackoverflow.com/q/28051969 | https://stackoverflow.com/a/28052786 | <p>To literally translate your example</p>
<pre><code>set program [lindex $argv 0]
set arguments [lrange $argv 1 end]
spawn $program {*}$arguments
</code></pre>
<p><code>{*}</code> is Tcl's "list expansion" syntax (rule 5 of <a href="http://tcl.tk/man/tcl8.6/TclCmd/Tcl.htm">Tcl's 12 rules of syntax</a>). It splits a ... | <p>To literally translate your example</p> <pre><code>set program [lindex $argv 0] set arguments [lrange $argv 1 end] spawn $program {*}$arguments </code></pre> <p><code>{*}</code> is Tcl's "list expansion" syntax (rule 5 of <a href="http://tcl.tk/man/tcl8.6/TclCmd/Tcl.htm">Tcl's 12 rules of syntax</a>). It splits a ... | 387, 2313, 9048, 18362, 31134 | argument-passing, arguments, bash, command-line-arguments, expect | <h1>TCL/Expect equivalent of Bash $@ or how to pass arguments to spawned process in TCL/Expect</h1>
<p>If somebody wants to call external program (which was passed as a Bash argument) from Bash and also pass it command line options (which were also passed as a Bash arguments) the solution is fairy simple:</p>
<pre><co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,967 | bash | # TCL/Expect equivalent of Bash $@ or how to pass arguments to spawned process in TCL/Expect
If somebody wants to call external program (which was passed as a Bash argument) from Bash and also pass it command line options (which were also passed as a Bash arguments) the solution is fairy simple:
```
TCL_SCRIPT="$1"
s... | To literally translate your example
```
set program [lindex $argv 0]
set arguments [lrange $argv 1 end]
spawn $program {*}$arguments
```
`{*}` is Tcl's "list expansion" syntax (rule 5 of [Tcl's 12 rules of syntax](http://tcl.tk/man/tcl8.6/TclCmd/Tcl.htm)). It splits a list into its element in the current command.
If... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.