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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3667432 | Storing sudo password as variable in script - is it safe? | 14 | 2010-09-08 11:55:59 | <p>Is storing my password this way safe?</p>
<pre><code>echo 'Write sudo password (will not be displayed) and hit enter'
read -s password
</code></pre>
<p>I need it to make commands like this:</p>
<pre><code>echo $password | sudo -S apt-get install -y foo bar
</code></pre>
| 11,172 | 190,446 | 2010-09-08 12:17:08 | 3,667,479 | 13 | 2010-09-08 12:00:33 | 143,305 | 2010-09-08 12:00:33 | https://stackoverflow.com/q/3667432 | https://stackoverflow.com/a/3667479 | <p>No because you can see it via <code>/proc/$PID/cmdline</code>.</p>
<p>I suggest not to try to reinvent security tools. The <code>sudo</code> program can cache your password.</p>
| <p>No because you can see it via <code>/proc/$PID/cmdline</code>.</p> <p>I suggest not to try to reinvent security tools. The <code>sudo</code> program can cache your password.</p> | 387, 1674 | bash, sudo | <h1>Storing sudo password as variable in script - is it safe?</h1>
<p>Is storing my password this way safe?</p>
<pre><code>echo 'Write sudo password (will not be displayed) and hit enter'
read -s password
</code></pre>
<p>I need it to make commands like this:</p>
<pre><code>echo $password | sudo -S apt-get install -... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,168 | bash | # Storing sudo password as variable in script - is it safe?
Is storing my password this way safe?
```
echo 'Write sudo password (will not be displayed) and hit enter'
read -s password
```
I need it to make commands like this:
```
echo $password | sudo -S apt-get install -y foo bar
``` | No because you can see it via `/proc/$PID/cmdline`.
I suggest not to try to reinvent security tools. The `sudo` program can cache your password. |
54193643 | Powershell catching exception type | 13 | 2019-01-15 06:20:50 | <p>Is there a convenient way to catch types of exceptions and inner exceptions for try-catch purposes?</p>
<p>Example code:</p>
<pre><code>$a = 5
$b = Read-Host "Enter number"
$c = $a / $b #error if $b -eq 0
$d = get-content C:\I\Do\Not\Exist
</code></pre>
<p>Row #3 will generate a runtime error with an inner excep... | 20,929 | 9,662,732 | 2024-02-20 00:37:36 | 54,195,677 | 13 | 2019-01-15 09:08:05 | 2,060,966 | 2021-08-14 14:18:45 | https://stackoverflow.com/q/54193643 | https://stackoverflow.com/a/54195677 | <p>First of all, you can explicitly catch specific exception types:</p>
<pre><code>$ErrorActionPreference = "Stop"
try {
1 / 0
}
catch [System.DivideByZeroException] {
$_.Exception.GetType().Name
}
try {
Get-Item "c:\does-not-exist"
}
catch [System.Management.Automation.ItemNotFoundExc... | <p>First of all, you can explicitly catch specific exception types:</p> <pre><code>$ErrorActionPreference = "Stop" try { 1 / 0 } catch [System.DivideByZeroException] { $_.Exception.GetType().Name } try { Get-Item "c:\does-not-exist" } catch [System.Management.Automation.ItemNotFoundExc... | 526, 5142 | exception, powershell | <h1>Powershell catching exception type</h1>
<p>Is there a convenient way to catch types of exceptions and inner exceptions for try-catch purposes?</p>
<p>Example code:</p>
<pre><code>$a = 5
$b = Read-Host "Enter number"
$c = $a / $b #error if $b -eq 0
$d = get-content C:\I\Do\Not\Exist
</code></pre>
<p>Row #3 will ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,169 | bash | # Powershell catching exception type
Is there a convenient way to catch types of exceptions and inner exceptions for try-catch purposes?
Example code:
```
$a = 5
$b = Read-Host "Enter number"
$c = $a / $b #error if $b -eq 0
$d = get-content C:\I\Do\Not\Exist
```
Row #3 will generate a runtime error with an inner e... | First of all, you can explicitly catch specific exception types:
```
$ErrorActionPreference = "Stop"
try {
1 / 0
}
catch [System.DivideByZeroException] {
$_.Exception.GetType().Name
}
try {
Get-Item "c:\does-not-exist"
}
catch [System.Management.Automation.ItemNotFoundException] {
$_.Exception.GetTyp... |
51389226 | Docker save images twice the size when using powershell - saving raw byte streams | 13 | 2018-07-17 19:51:38 | <p>Docker version 18.03.1-ce, build 9ee9f40</p>
<p>I'm using powershell to build a big project on windows.</p>
<p>When issuing the command</p>
<pre><code>docker save docker.elastic.co/kibana/kibana > deploy/kibana.docker
</code></pre>
<p>I'm getting an file 1.4Gb.</p>
<p>Same command run in CMD produces 799Mb i... | 1,730 | 1,091,765 | 2018-07-18 03:58:31 | 51,389,456 | 13 | 2018-07-17 20:10:15 | 45,375 | 2018-07-18 03:58:31 | https://stackoverflow.com/q/51389226 | https://stackoverflow.com/a/51389456 | <p><strong>PowerShell doesn't support outputting / passing <em>raw byte streams</em> through</strong> - any output from an external program such as <code>docker</code> is <em>parsed line by line</em>, into <em>strings</em> and the strings are then re-encoded on output to a file (if necessary).<br>
It is the overhead of... | <p><strong>PowerShell doesn't support outputting / passing <em>raw byte streams</em> through</strong> - any output from an external program such as <code>docker</code> is <em>parsed line by line</em>, into <em>strings</em> and the strings are then re-encoded on output to a file (if necessary).<br> It is the overhead of... | 526, 2631, 26698, 90304 | cmd, docker, io-redirection, powershell | <h1>Docker save images twice the size when using powershell - saving raw byte streams</h1>
<p>Docker version 18.03.1-ce, build 9ee9f40</p>
<p>I'm using powershell to build a big project on windows.</p>
<p>When issuing the command</p>
<pre><code>docker save docker.elastic.co/kibana/kibana > deploy/kibana.docker
</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,170 | bash | # Docker save images twice the size when using powershell - saving raw byte streams
Docker version 18.03.1-ce, build 9ee9f40
I'm using powershell to build a big project on windows.
When issuing the command
```
docker save docker.elastic.co/kibana/kibana > deploy/kibana.docker
```
I'm getting an file 1.4Gb.
Same c... | **PowerShell doesn't support outputting / passing *raw byte streams* through** - any output from an external program such as `docker` is *parsed line by line*, into *strings* and the strings are then re-encoded on output to a file (if necessary).
It is the overhead of parsing, decoding and re-encoding that explains t... |
47539292 | Remove language from Windows 10 using PowerShell | 13 | 2017-11-28 19:18:46 | <p>I want to use Powershell to add or remove a language and change the keyboard layout from left to right or from right to left in Windows 10. I wrote code to add a language but I cannot find a guide to remove it again or to change the layout. I also want to ask the user if he wants to add or to remove a language.</p>
... | 14,605 | 5,615,853 | 2025-10-14 12:57:22 | 47,539,681 | 13 | 2017-11-28 19:42:43 | 7,869,690 | 2017-11-28 19:42:43 | https://stackoverflow.com/q/47539292 | https://stackoverflow.com/a/47539681 | <p>I managed to do this by using the index of the English language in the <code>$List</code> array in combination with the <code>Set-WinUserLanguageList</code> cmdlet. I found it odd that I couldn't simply reverse the steps by using the <code>$list.remove("lt-LT")</code> method, as it returns <code>False</code>, so I ... | <p>I managed to do this by using the index of the English language in the <code>$List</code> array in combination with the <code>Set-WinUserLanguageList</code> cmdlet. I found it odd that I couldn't simply reverse the steps by using the <code>$list.remove("lt-LT")</code> method, as it returns <code>False</code>, so I ... | 526, 107329 | powershell, windows-10 | <h1>Remove language from Windows 10 using PowerShell</h1>
<p>I want to use Powershell to add or remove a language and change the keyboard layout from left to right or from right to left in Windows 10. I wrote code to add a language but I cannot find a guide to remove it again or to change the layout. I also want to ask... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,171 | bash | # Remove language from Windows 10 using PowerShell
I want to use Powershell to add or remove a language and change the keyboard layout from left to right or from right to left in Windows 10. I wrote code to add a language but I cannot find a guide to remove it again or to change the layout. I also want to ask the user... | I managed to do this by using the index of the English language in the `$List` array in combination with the `Set-WinUserLanguageList` cmdlet. I found it odd that I couldn't simply reverse the steps by using the `$list.remove("lt-LT")` method, as it returns `False`, so I set about recreating the list another way.
Afte... |
5100788 | bash: comment a long pipeline | 13 | 2011-02-24 05:36:37 | <p>I've found that it's quite powerful to create long pipelines in bash scripts, but the main drawback that I see is that there doesn't seem to be a way to insert comments.</p>
<p>As an example, is there a good way to add comments to this script?</p>
<pre><code>#find all my VNC sessions
ls -t $HOME/.vnc/*.pid ... | 2,540 | 146,821 | 2017-02-14 00:24:19 | 42,215,855 | 13 | 2017-02-14 00:24:19 | 1,019,205 | 2017-02-14 00:24:19 | https://stackoverflow.com/q/5100788 | https://stackoverflow.com/a/42215855 | <p>This works too:</p>
<pre><code># comment here
ls -t $HOME/.vnc/*.pid |
#comment here
xargs -n1 |
#another comment
...
</code></pre>
<p>based on <a href="https://stackoverflow.com/a/5100821/1019205">https://stackoverflow.com/a/5100821/1019205</a>.
it comes down to <code>s/|//;s!\!|!</code>.</p>
| <p>This works too:</p> <pre><code># comment here ls -t $HOME/.vnc/*.pid | #comment here xargs -n1 | #another comment ... </code></pre> <p>based on <a href="https://stackoverflow.com/a/5100821/1019205">https://stackoverflow.com/a/5100821/1019205</a>. it comes down to <code>s/|//;s!\!|!</code>.</p> | 387, 1966, 2844, 10327 | bash, comments, pipeline, sh | <h1>bash: comment a long pipeline</h1>
<p>I've found that it's quite powerful to create long pipelines in bash scripts, but the main drawback that I see is that there doesn't seem to be a way to insert comments.</p>
<p>As an example, is there a good way to add comments to this script?</p>
<pre><code>#find all my VNC ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,172 | bash | # bash: comment a long pipeline
I've found that it's quite powerful to create long pipelines in bash scripts, but the main drawback that I see is that there doesn't seem to be a way to insert comments.
As an example, is there a good way to add comments to this script?
```
#find all my VNC sessions
ls -t $HOME/.vnc/*... | This works too:
```
# comment here
ls -t $HOME/.vnc/*.pid |
#comment here
xargs -n1 |
#another comment
...
```
based on <https://stackoverflow.com/a/5100821/1019205>.
it comes down to `s/|//;s!\!|!`. |
40721662 | How to execute a file without .sh extension in shell | 13 | 2016-11-21 13:43:32 | <p>I want to execute a file in bash without the .sh extension.</p>
<p>Example: I have file "abc.sh" which I can execute directly (as I have added #!/bin/bash as the first line) but I want the filename to be just "abc"</p>
| 30,411 | 7,108,310 | 2023-03-10 14:48:35 | 40,721,743 | 13 | 2016-11-21 13:47:50 | 6,478,480 | 2020-11-27 05:05:38 | https://stackoverflow.com/q/40721662 | https://stackoverflow.com/a/40721743 | <p>In Linux you use <code>./filename</code> too run a script. And you need execute permission:</p>
<p><code>chmod 755 filename</code></p>
<p>But you still need the "Shebang":</p>
<pre><code>#!/bin/bash
</code></pre>
<p>From <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html" rel="noreferre... | <p>In Linux you use <code>./filename</code> too run a script. And you need execute permission:</p> <p><code>chmod 755 filename</code></p> <p>But you still need the "Shebang":</p> <pre><code>#!/bin/bash </code></pre> <p>From <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html" rel="noreferre... | 34, 58, 390, 10327 | linux, sh, shell, unix | <h1>How to execute a file without .sh extension in shell</h1>
<p>I want to execute a file in bash without the .sh extension.</p>
<p>Example: I have file "abc.sh" which I can execute directly (as I have added #!/bin/bash as the first line) but I want the filename to be just "abc"</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,173 | bash | # How to execute a file without .sh extension in shell
I want to execute a file in bash without the .sh extension.
Example: I have file "abc.sh" which I can execute directly (as I have added #!/bin/bash as the first line) but I want the filename to be just "abc" | In Linux you use `./filename` too run a script. And you need execute permission:
`chmod 755 filename`
But you still need the "Shebang":
```
#!/bin/bash
```
From [here](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html) I got this:
> If you did not put the scripts directory in your PATH, and . (the
> cu... |
40317552 | Shell script Bash, Check if string starts and ends with single quotes | 13 | 2016-10-29 09:01:47 | <p>I need to check if a string starts and ends with a single quote, for example
'My name is Mozart'</p>
<p>What I have is this, which doesn't work</p>
<pre><code>if [[ $TEXT == '*' ]] ;
</code></pre>
<p>This does not work either </p>
<pre><code>if [[ $TEXT == /'*/' ]] ;
</code></pre>
<p>But if I change it to</p>
... | 28,039 | 7,044,295 | 2020-01-31 02:28:36 | 40,322,497 | 13 | 2016-10-29 18:50:19 | 1,427,464 | 2018-08-12 15:13:02 | https://stackoverflow.com/q/40317552 | https://stackoverflow.com/a/40322497 | <p>I am writing the complete bash script so you won't have any confusion:</p>
<pre><code>#! /bin/bash
text1="'helo there"
if [[ $text1 =~ ^\'.*\'$ ]]; then
echo "text1 match"
else
echo "text1 not match"
fi
text2="'hello babe'"
if [[ $text2 =~ ^\'.*\'$ ]]; then
echo "text2 match"
else
... | <p>I am writing the complete bash script so you won't have any confusion:</p> <pre><code>#! /bin/bash text1="'helo there" if [[ $text1 =~ ^\'.*\'$ ]]; then echo "text1 match" else echo "text1 not match" fi text2="'hello babe'" if [[ $text2 =~ ^\'.*\'$ ]]; then echo "text2 match" else ... | 387, 390 | bash, shell | <h1>Shell script Bash, Check if string starts and ends with single quotes</h1>
<p>I need to check if a string starts and ends with a single quote, for example
'My name is Mozart'</p>
<p>What I have is this, which doesn't work</p>
<pre><code>if [[ $TEXT == '*' ]] ;
</code></pre>
<p>This does not work either </p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,174 | bash | # Shell script Bash, Check if string starts and ends with single quotes
I need to check if a string starts and ends with a single quote, for example
'My name is Mozart'
What I have is this, which doesn't work
```
if [[ $TEXT == '*' ]] ;
```
This does not work either
```
if [[ $TEXT == /'*/' ]] ;
```
But if I chan... | I am writing the complete bash script so you won't have any confusion:
```
#! /bin/bash
text1="'helo there"
if [[ $text1 =~ ^\'.*\'$ ]]; then
echo "text1 match"
else
echo "text1 not match"
fi
text2="'hello babe'"
if [[ $text2 =~ ^\'.*\'$ ]]; then
echo "text2 match"
else
echo "text2 no... |
39696038 | Why using Bash readonly variable to capture output fails to capture return code $? | 13 | 2016-09-26 06:30:17 | <p>Here's example that tries to execute command and checks if it was executed successfully, while capturing it's output for further processing:</p>
<pre><code>#!/bin/bash
readonly OUTPUT=$(foo)
readonly RES=$?
if [[ ${RES} != 0 ]]
then
echo "failed to execute foo"
exit 1
else
echo "foo success: '${OUTPUT... | 1,572 | 542,452 | 2016-09-26 18:21:08 | 39,696,158 | 13 | 2016-09-26 06:39:01 | 3,030,305 | 2016-09-26 18:21:08 | https://stackoverflow.com/q/39696038 | https://stackoverflow.com/a/39696158 | <p>The problem is that <code>readonly</code> is its own command and the exit code that it returns is its own exit code, not the exit code of the command substitution.</p>
<p>From <code>help readonly</code>:</p>
<blockquote>
<p>Exit Status:<br>
Returns success unless an invalid option is given or NAME is invalid.<... | <p>The problem is that <code>readonly</code> is its own command and the exit code that it returns is its own exit code, not the exit code of the command substitution.</p> <p>From <code>help readonly</code>:</p> <blockquote> <p>Exit Status:<br> Returns success unless an invalid option is given or NAME is invalid.<... | 276, 387 | bash, variables | <h1>Why using Bash readonly variable to capture output fails to capture return code $?</h1>
<p>Here's example that tries to execute command and checks if it was executed successfully, while capturing it's output for further processing:</p>
<pre><code>#!/bin/bash
readonly OUTPUT=$(foo)
readonly RES=$?
if [[ ${RES} !=... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,175 | bash | # Why using Bash readonly variable to capture output fails to capture return code $?
Here's example that tries to execute command and checks if it was executed successfully, while capturing it's output for further processing:
```
#!/bin/bash
readonly OUTPUT=$(foo)
readonly RES=$?
if [[ ${RES} != 0 ]]
then
echo ... | The problem is that `readonly` is its own command and the exit code that it returns is its own exit code, not the exit code of the command substitution.
From `help readonly`:
> Exit Status:
> Returns success unless an invalid option is given or NAME is invalid.
So, you need to use two separate commands:
```
$ out... |
39417793 | How do I populate a bash associative array with command output? | 13 | 2016-09-09 18:34:31 | <p>I'm trying to populate an associative array with the output of a command. I can do it without a command as:</p>
<pre><code>$ declare -A x=( [first]=foo [second]=bar )
$ echo "${x[first]}, ${x[second]}"
foo, bar
</code></pre>
<p>and I can populate a non-associative array with command output as:</p>
<pre><code>$ de... | 5,505 | 1,745,001 | 2020-01-04 15:14:27 | 39,418,782 | 13 | 2016-09-09 19:47:46 | 548,225 | 2016-09-09 20:14:20 | https://stackoverflow.com/q/39417793 | https://stackoverflow.com/a/39418782 | <p>Here is a traditional while loop approach to populate an associative array from a command's output:</p>
<pre><code>while IFS= read -r; do
declare -A z+="( $REPLY )"
done < <(printf '[first]=foo [second]=bar\n[third]=baz\n')
# check output
$> echo "${z[first]}, ${z[second]}, ${z[third]}"
foo, bar, baz
... | <p>Here is a traditional while loop approach to populate an associative array from a command's output:</p> <pre><code>while IFS= read -r; do declare -A z+="( $REPLY )" done < <(printf '[first]=foo [second]=bar\n[third]=baz\n') # check output $> echo "${z[first]}, ${z[second]}, ${z[third]}" foo, bar, baz ... | 387 | bash | <h1>How do I populate a bash associative array with command output?</h1>
<p>I'm trying to populate an associative array with the output of a command. I can do it without a command as:</p>
<pre><code>$ declare -A x=( [first]=foo [second]=bar )
$ echo "${x[first]}, ${x[second]}"
foo, bar
</code></pre>
<p>and I can popu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,176 | bash | # How do I populate a bash associative array with command output?
I'm trying to populate an associative array with the output of a command. I can do it without a command as:
```
$ declare -A x=( [first]=foo [second]=bar )
$ echo "${x[first]}, ${x[second]}"
foo, bar
```
and I can populate a non-associative array with... | Here is a traditional while loop approach to populate an associative array from a command's output:
```
while IFS= read -r; do
declare -A z+="( $REPLY )"
done < <(printf '[first]=foo [second]=bar\n[third]=baz\n')
# check output
$> echo "${z[first]}, ${z[second]}, ${z[third]}"
foo, bar, baz
# or declare -p
$> decl... |
27273440 | Why working directory is changing when executing Invoke-sqlcmd? | 13 | 2014-12-03 13:51:56 | <p>I am trying to search whether particualr machine name is there in database and if so we are replacing with new machine name.</p>
<p>We are using powershell</p>
<pre><code> Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
Add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue
... | 2,604 | 399,145 | 2022-02-17 01:34:54 | 34,083,790 | 13 | 2015-12-04 08:22:11 | 5,324,425 | 2015-12-04 08:22:11 | https://stackoverflow.com/q/27273440 | https://stackoverflow.com/a/34083790 | <p>This issue occurs as part of running the <code>Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue</code> section of your code at the start. I'm not sure why it does this but I know that when I run a similar command (<code>Import-Module 'sqlps' -DisableNameChecking</code>) on computers in our netwo... | <p>This issue occurs as part of running the <code>Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue</code> section of your code at the start. I'm not sure why it does this but I know that when I run a similar command (<code>Import-Module 'sqlps' -DisableNameChecking</code>) on computers in our netwo... | 526, 74269 | powershell, sql-server-2012 | <h1>Why working directory is changing when executing Invoke-sqlcmd?</h1>
<p>I am trying to search whether particualr machine name is there in database and if so we are replacing with new machine name.</p>
<p>We are using powershell</p>
<pre><code> Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,177 | bash | # Why working directory is changing when executing Invoke-sqlcmd?
I am trying to search whether particualr machine name is there in database and if so we are replacing with new machine name.
We are using powershell
```
Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
Add-pssnapin sqlserverc... | This issue occurs as part of running the `Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue` section of your code at the start. I'm not sure why it does this but I know that when I run a similar command (`Import-Module 'sqlps' -DisableNameChecking`) on computers in our network running MS SQL 2012, i... |
33775419 | How to join array in pipe | 13 | 2015-11-18 08:50:20 | <p>I wish to join the result from a pipe.</p>
<p>I tried using <code>-join</code></p>
<pre><code>PS> type .\bleh.log | where { $_ -match "foo"} | select -uniq | $_ -join ','
</code></pre>
<p>But that give me this error :/</p>
<blockquote>
<p>Expressions are only allowed as the first element of a pipeline.</p>
... | 4,187 | 1,220,627 | 2023-03-23 20:22:20 | 33,775,506 | 13 | 2015-11-18 08:56:02 | 3,677,139 | 2015-11-18 08:57:38 | https://stackoverflow.com/q/33775419 | https://stackoverflow.com/a/33775506 | <p>You could try this :</p>
<pre><code>@(type .\bleh.log | where { $_ -match "foo"} | select -uniq) -join ","
</code></pre>
<p>You would need a <code>Foreach-Object</code> (alias <code>%</code>) after the last pipe to have the <code>$_</code> variable available but it wouldn't help since it holds a single cell value ... | <p>You could try this :</p> <pre><code>@(type .\bleh.log | where { $_ -match "foo"} | select -uniq) -join "," </code></pre> <p>You would need a <code>Foreach-Object</code> (alias <code>%</code>) after the last pipe to have the <code>$_</code> variable available but it wouldn't help since it holds a single cell value ... | 526, 3626, 5813 | join, pipe, powershell | <h1>How to join array in pipe</h1>
<p>I wish to join the result from a pipe.</p>
<p>I tried using <code>-join</code></p>
<pre><code>PS> type .\bleh.log | where { $_ -match "foo"} | select -uniq | $_ -join ','
</code></pre>
<p>But that give me this error :/</p>
<blockquote>
<p>Expressions are only allowed as th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,178 | bash | # How to join array in pipe
I wish to join the result from a pipe.
I tried using `-join`
```
PS> type .\bleh.log | where { $_ -match "foo"} | select -uniq | $_ -join ','
```
But that give me this error :/
> Expressions are only allowed as the first element of a pipeline. | You could try this :
```
@(type .\bleh.log | where { $_ -match "foo"} | select -uniq) -join ","
```
You would need a `Foreach-Object` (alias `%`) after the last pipe to have the `$_` variable available but it wouldn't help since it holds a single cell value (for each loop iteration). |
31949586 | How to find if Mongodb is running in auth mode in shell script? | 13 | 2015-08-11 18:42:38 | <p>I am having a mongodb instance running which is running auth mode in my server machine. Currently I am using a shell scipt to get whether there is a mongodb instance running or not. How Can I check whether if the mongodb is running in a auth mode or non auth mode . </p>
| 9,102 | 4,239,226 | 2023-03-10 16:27:23 | 32,042,479 | 13 | 2015-08-17 03:44:44 | 1,388,319 | 2023-03-10 16:27:23 | https://stackoverflow.com/q/31949586 | https://stackoverflow.com/a/32042479 | <p>If you just want to test whether you can connect to a MongoDB server without authentication via <code>bash</code>, you can use a script similar to the following:</p>
<pre><code>#!/bin/bash
# Connect to MongoDB address (host:port/dbname) specified as first parameter
# If no address specified, `mongo` default will be... | <p>If you just want to test whether you can connect to a MongoDB server without authentication via <code>bash</code>, you can use a script similar to the following:</p> <pre><code>#!/bin/bash # Connect to MongoDB address (host:port/dbname) specified as first parameter # If no address specified, `mongo` default will be... | 34, 390, 30073, 79553 | mongodb, mongodb-shell, shell, unix | <h1>How to find if Mongodb is running in auth mode in shell script?</h1>
<p>I am having a mongodb instance running which is running auth mode in my server machine. Currently I am using a shell scipt to get whether there is a mongodb instance running or not. How Can I check whether if the mongodb is running in a auth m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,179 | bash | # How to find if Mongodb is running in auth mode in shell script?
I am having a mongodb instance running which is running auth mode in my server machine. Currently I am using a shell scipt to get whether there is a mongodb instance running or not. How Can I check whether if the mongodb is running in a auth mode or non... | If you just want to test whether you can connect to a MongoDB server without authentication via `bash`, you can use a script similar to the following:
```
#!/bin/bash
# Connect to MongoDB address (host:port/dbname) specified as first parameter
# If no address specified, `mongo` default will be localhost:27017/test
is... |
26526175 | Zsh menu completion causes problems after zle reset-prompt | 13 | 2014-10-23 10:30:32 | <p>I have following code in my .zshrc:</p>
<pre><code>TMOUT=1
TRAPALRM() { zle reset-prompt }
</code></pre>
<p>After triggering menu completion all items from menu, except highlighted one disappear after <code>TRAPALRM</code> triggers and when i keep navigating in menu zsh segvaults after a short time</p>
<p>Is ther... | 3,228 | 3,134,946 | 2023-03-15 13:50:46 | 30,456,173 | 13 | 2015-05-26 10:39:10 | 373,175 | 2015-05-26 17:25:11 | https://stackoverflow.com/q/26526175 | https://stackoverflow.com/a/30456173 | <p>I found this workaround, to basically prevent calling "reset-prompt" when in a menu selection :</p>
<pre><code>TRAPALRM() {
if [ "$WIDGET" != "complete-word" ]; then
zle reset-prompt
fi
}
</code></pre>
<p>Note that <code>complete-word</code> may be different for you; I found it with an <code>echo $... | <p>I found this workaround, to basically prevent calling "reset-prompt" when in a menu selection :</p> <pre><code>TRAPALRM() { if [ "$WIDGET" != "complete-word" ]; then zle reset-prompt fi } </code></pre> <p>Note that <code>complete-word</code> may be different for you; I found it with an <code>echo $... | 58, 390, 3791, 19292 | linux, segmentation-fault, shell, zsh | <h1>Zsh menu completion causes problems after zle reset-prompt</h1>
<p>I have following code in my .zshrc:</p>
<pre><code>TMOUT=1
TRAPALRM() { zle reset-prompt }
</code></pre>
<p>After triggering menu completion all items from menu, except highlighted one disappear after <code>TRAPALRM</code> triggers and when i keep... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,180 | bash | # Zsh menu completion causes problems after zle reset-prompt
I have following code in my .zshrc:
```
TMOUT=1
TRAPALRM() { zle reset-prompt }
```
After triggering menu completion all items from menu, except highlighted one disappear after `TRAPALRM` triggers and when i keep navigating in menu zsh segvaults after a sh... | I found this workaround, to basically prevent calling "reset-prompt" when in a menu selection :
```
TRAPALRM() {
if [ "$WIDGET" != "complete-word" ]; then
zle reset-prompt
fi
}
```
Note that `complete-word` may be different for you; I found it with an `echo $WIDGET` in the `TRAPALRM` call. |
27115880 | ConvertFrom-Json PowerShell Cmdlet not parsing entire JSON object | 13 | 2014-11-24 23:05:59 | <p>I have this JSON in a file called test.txt</p>
<pre><code>{
"local-dev": {
"client": {
"server-url": "http://localhost:3000"
},
"server": {
"renterEndpoint": {
"rejectUnauthorized": false,
"host": "blah.blah.com",
"port": 443,
"path": "/api/renter"
},
... | 18,597 | 1,636,881 | 2014-11-25 00:07:37 | 27,116,544 | 13 | 2014-11-25 00:07:37 | 3,829,407 | 2014-11-25 00:07:37 | https://stackoverflow.com/q/27115880 | https://stackoverflow.com/a/27116544 | <p>The data you want is there. You just need to navigate the "<em>nodes</em>" ( dont know the proper terms )
If you return the data from your file into a variable and use <code>Get-Member</code> you can see what you are looking for.</p>
<pre><code>PS C:\Users\Cameron> $json | Get-Member | Select-Object name
Name ... | <p>The data you want is there. You just need to navigate the "<em>nodes</em>" ( dont know the proper terms ) If you return the data from your file into a variable and use <code>Get-Member</code> you can see what you are looking for.</p> <pre><code>PS C:\Users\Cameron> $json | Get-Member | Select-Object name Name ... | 526, 1508 | json, powershell | <h1>ConvertFrom-Json PowerShell Cmdlet not parsing entire JSON object</h1>
<p>I have this JSON in a file called test.txt</p>
<pre><code>{
"local-dev": {
"client": {
"server-url": "http://localhost:3000"
},
"server": {
"renterEndpoint": {
"rejectUnauthorized": false,
"host": "b... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,181 | bash | # ConvertFrom-Json PowerShell Cmdlet not parsing entire JSON object
I have this JSON in a file called test.txt
```
{
"local-dev": {
"client": {
"server-url": "http://localhost:3000"
},
"server": {
"renterEndpoint": {
"rejectUnauthorized": false,
"host": "blah.blah.com",
... | The data you want is there. You just need to navigate the "*nodes*" ( dont know the proper terms )
If you return the data from your file into a variable and use `Get-Member` you can see what you are looking for.
```
PS C:\Users\Cameron> $json | Get-Member | Select-Object name
Name ... |
25900873 | Write and read from a fifo from two different script | 13 | 2014-09-17 21:46:42 | <p>I have two bash script.
One script write in a fifo. The second one read from the fifo, but AFTER the first one end to write.</p>
<p>But something does not work. I do not understand where the problem is. Here the code.</p>
<p>The first script is (the writer):</p>
<pre><code>#!/bin/bash
fifo_name="myfifo";
# Se ... | 28,684 | 968,759 | 2016-07-14 08:16:31 | 25,901,141 | 13 | 2014-09-17 22:09:21 | 3,030,305 | 2014-09-17 22:09:21 | https://stackoverflow.com/q/25900873 | https://stackoverflow.com/a/25901141 | <p>Replace the second script with:</p>
<pre><code>#!/bin/bash
fifo_name="myfifo"
while true
do
if read line; then
echo $line
fi
done <"$fifo_name"
</code></pre>
<p>This opens the fifo only once and reads every line from it.</p>
| <p>Replace the second script with:</p> <pre><code>#!/bin/bash fifo_name="myfifo" while true do if read line; then echo $line fi done <"$fifo_name" </code></pre> <p>This opens the fifo only once and reads every line from it.</p> | 387, 13018, 30797 | bash, fifo, writer | <h1>Write and read from a fifo from two different script</h1>
<p>I have two bash script.
One script write in a fifo. The second one read from the fifo, but AFTER the first one end to write.</p>
<p>But something does not work. I do not understand where the problem is. Here the code.</p>
<p>The first script is (the wr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,182 | bash | # Write and read from a fifo from two different script
I have two bash script.
One script write in a fifo. The second one read from the fifo, but AFTER the first one end to write.
But something does not work. I do not understand where the problem is. Here the code.
The first script is (the writer):
```
#!/bin/bash
... | Replace the second script with:
```
#!/bin/bash
fifo_name="myfifo"
while true
do
if read line; then
echo $line
fi
done <"$fifo_name"
```
This opens the fifo only once and reads every line from it. |
25410656 | Ansible IP address variable - host part | 13 | 2014-08-20 17:11:24 | <p>I have the following problem:</p>
<p>I'm writing playbook for setting IP address on the command line in Ansible. Lets say 10.10.10.x. I need to get the last part of my public IP lets say x.x.x.15 and assign it to the private: 10.10.10.15. Is there a variable for this? Can i capture some? I've tried to use something... | 46,176 | 3,961,221 | 2016-11-11 06:19:29 | 25,413,400 | 13 | 2014-08-20 19:58:42 | 3,930,609 | 2014-08-20 19:58:42 | https://stackoverflow.com/q/25410656 | https://stackoverflow.com/a/25413400 | <p>Instead of using a system utility you can use ansible <a href="http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts" rel="noreferrer">facts</a> though you will find that interface names will vary from server to server. </p>
<p>You specifically mentioned the <i>last part of my p... | <p>Instead of using a system utility you can use ansible <a href="http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts" rel="noreferrer">facts</a> though you will find that interface names will vary from server to server. </p> <p>You specifically mentioned the <i>last part of my p... | 276, 294, 390, 86394 | ansible, ip, shell, variables | <h1>Ansible IP address variable - host part</h1>
<p>I have the following problem:</p>
<p>I'm writing playbook for setting IP address on the command line in Ansible. Lets say 10.10.10.x. I need to get the last part of my public IP lets say x.x.x.15 and assign it to the private: 10.10.10.15. Is there a variable for this... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,183 | bash | # Ansible IP address variable - host part
I have the following problem:
I'm writing playbook for setting IP address on the command line in Ansible. Lets say 10.10.10.x. I need to get the last part of my public IP lets say x.x.x.15 and assign it to the private: 10.10.10.15. Is there a variable for this? Can i capture ... | Instead of using a system utility you can use ansible [facts](http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts) though you will find that interface names will vary from server to server.
You specifically mentioned the *last part of my public IP*
If you really mean your ***pub... |
20034614 | What are the rules to write robust shell scripts? | 13 | 2013-11-17 18:38:59 | <p>I recently erased part of my home directory with a shell script I wrote. Fortunately, I did hit <kbd>Ctrl</kbd>-<kbd>C</kbd> fast enough to avoid the worst.</p>
<p>My mistake has been to rely too much on relative paths. Since now, I always use absolute paths when changing directory... But, it lead me to an interest... | 2,446 | 717,822 | 2013-12-10 17:16:51 | 20,035,079 | 13 | 2013-11-17 19:26:06 | 641,955 | 2013-11-17 20:56:59 | https://stackoverflow.com/q/20034614 | https://stackoverflow.com/a/20035079 | <p>A couple of ideas:</p>
<ol>
<li><p>Use <code>-e</code> flag in the shebang, for example <code>#!/bin/sh -e</code>. That way the script will stop at the first error. It's a bit like throwing a <code>RuntimeException</code> in Java. This probably did save my ass a couple of times, and I have a feeling it would helped... | <p>A couple of ideas:</p> <ol> <li><p>Use <code>-e</code> flag in the shebang, for example <code>#!/bin/sh -e</code>. That way the script will stop at the first error. It's a bit like throwing a <code>RuntimeException</code> in Java. This probably did save my ass a couple of times, and I have a feeling it would helped... | 390, 12664 | robustness, shell | <h1>What are the rules to write robust shell scripts?</h1>
<p>I recently erased part of my home directory with a shell script I wrote. Fortunately, I did hit <kbd>Ctrl</kbd>-<kbd>C</kbd> fast enough to avoid the worst.</p>
<p>My mistake has been to rely too much on relative paths. Since now, I always use absolute path... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,184 | bash | # What are the rules to write robust shell scripts?
I recently erased part of my home directory with a shell script I wrote. Fortunately, I did hit `Ctrl`-`C` fast enough to avoid the worst.
My mistake has been to rely too much on relative paths. Since now, I always use absolute paths when changing directory... But, ... | A couple of ideas:
1. Use `-e` flag in the shebang, for example `#!/bin/sh -e`. That way the script will stop at the first error. It's a bit like throwing a `RuntimeException` in Java. This probably did save my ass a couple of times, and I have a feeling it would helped you too in this case.
2. Handle the exit codes o... |
17079749 | How do I use pbcopy in a bash function? Can it be scripted? | 13 | 2013-06-13 05:23:12 | <p>I often find myself copying history commands to my clipboard using this:</p>
<p><code>echo !123 | pbcopy</code></p>
<p>This works fine from the Terminal. Assuming <code>!123 = cd ..</code>, it looks something like this:</p>
<pre><code>$ echo !123 | pbcopy
echo cd .. | pbcopy
//result: `cd ..` is in the clipbo... | 17,899 | 1,011,766 | 2013-06-13 13:24:39 | 17,083,020 | 13 | 2013-06-13 08:56:55 | 1,353,267 | 2013-06-13 09:03:56 | https://stackoverflow.com/q/17079749 | https://stackoverflow.com/a/17083020 | <p>Your function is somewhat wrong. It should use <code>$@</code> instead of <code>$1</code></p>
<p>that is </p>
<pre><code>function pb() {
echo "$@" | pbcopy
}
</code></pre>
<p>The result:</p>
<pre><code>samveen@minime:/tmp $ function pb () { echo "$@" | pbcopy ; }
samveen@minime:/tmp $ pb !2030
pb file `which... | <p>Your function is somewhat wrong. It should use <code>$@</code> instead of <code>$1</code></p> <p>that is </p> <pre><code>function pb() { echo "$@" | pbcopy } </code></pre> <p>The result:</p> <pre><code>samveen@minime:/tmp $ function pb () { echo "$@" | pbcopy ; } samveen@minime:/tmp $ pb !2030 pb file `which... | 369, 387, 391, 26252 | bash, macos, pbcopy, terminal | <h1>How do I use pbcopy in a bash function? Can it be scripted?</h1>
<p>I often find myself copying history commands to my clipboard using this:</p>
<p><code>echo !123 | pbcopy</code></p>
<p>This works fine from the Terminal. Assuming <code>!123 = cd ..</code>, it looks something like this:</p>
<pre><code>$ echo !12... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,185 | bash | # How do I use pbcopy in a bash function? Can it be scripted?
I often find myself copying history commands to my clipboard using this:
`echo !123 | pbcopy`
This works fine from the Terminal. Assuming `!123 = cd ..`, it looks something like this:
```
$ echo !123 | pbcopy
echo cd .. | pbcopy
//result: `cd ..` is ... | Your function is somewhat wrong. It should use `$@` instead of `$1`
that is
```
function pb() {
echo "$@" | pbcopy
}
```
The result:
```
samveen@minime:/tmp $ function pb () { echo "$@" | pbcopy ; }
samveen@minime:/tmp $ pb !2030
pb file `which bzcat`
//result: `file /bin/bzcat` is in the clipboard
samveen@... |
14416914 | Bash Shell Current Date Minus Number of Days | 13 | 2013-01-19 17:30:43 | <p>I am new to bash and shell but I am running a debian install and I am trying to make a script which can find a date in the past without having to install any additional packages. From tutorials I have got to this stage:</p>
<pre><code>#!/bin/sh
#
# BACKUP DB TO S3
#
# VARIABLES
TYPE="DATABASE"
DAYS="30"
# GET CUR... | 40,465 | 1,738,522 | 2019-12-12 07:53:55 | 14,416,939 | 13 | 2013-01-19 17:33:52 | 465,183 | 2013-01-19 18:54:35 | https://stackoverflow.com/q/14416914 | https://stackoverflow.com/a/14416939 | <p>Try doing this :</p>
<pre><code>#!/bin/sh
#
# BACKUP DB TO S3
#
# VARIABLES
TYPE="DATABASE"
DAYS="30"
# GET CURRENT DATETIME
CURRENTDATE="$(date +%Y%m%d%H%M%S)"
# GENERATE PAST DATE FROM DAYS CONSTANT
OLDERDATE="$(date "+%Y%m%d%H%M%S" -d "$DAYS days ago")"
# CALL PYTHON SCRIPT WITH OLDERDATE ARGUMENT
python scr... | <p>Try doing this :</p> <pre><code>#!/bin/sh # # BACKUP DB TO S3 # # VARIABLES TYPE="DATABASE" DAYS="30" # GET CURRENT DATETIME CURRENTDATE="$(date +%Y%m%d%H%M%S)" # GENERATE PAST DATE FROM DAYS CONSTANT OLDERDATE="$(date "+%Y%m%d%H%M%S" -d "$DAYS days ago")" # CALL PYTHON SCRIPT WITH OLDERDATE ARGUMENT python scr... | 387, 390, 1012, 1263 | bash, datetime, debian, shell | <h1>Bash Shell Current Date Minus Number of Days</h1>
<p>I am new to bash and shell but I am running a debian install and I am trying to make a script which can find a date in the past without having to install any additional packages. From tutorials I have got to this stage:</p>
<pre><code>#!/bin/sh
#
# BACKUP DB TO ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,186 | bash | # Bash Shell Current Date Minus Number of Days
I am new to bash and shell but I am running a debian install and I am trying to make a script which can find a date in the past without having to install any additional packages. From tutorials I have got to this stage:
```
#!/bin/sh
#
# BACKUP DB TO S3
#
# VARIABLES
TY... | Try doing this :
```
#!/bin/sh
#
# BACKUP DB TO S3
#
# VARIABLES
TYPE="DATABASE"
DAYS="30"
# GET CURRENT DATETIME
CURRENTDATE="$(date +%Y%m%d%H%M%S)"
# GENERATE PAST DATE FROM DAYS CONSTANT
OLDERDATE="$(date "+%Y%m%d%H%M%S" -d "$DAYS days ago")"
# CALL PYTHON SCRIPT WITH OLDERDATE ARGUMENT
python script.py "$OLDER... |
12499195 | Git - How to find all "unpushed" commits for all projects in a directory? | 13 | 2012-09-19 16:44:32 | <p>I'm finally getting used to Git and, after the initial steep learning curve, I must say it's quite good (I just miss the single file externals, but that's another story). I have, however, an issue that I can't solve: I'm currently working on a dozen projects at the same time. They are all interconnected and I must j... | 4,833 | 65,990 | 2024-06-20 16:09:25 | 12,499,489 | 13 | 2012-09-19 17:02:45 | 276,250 | 2013-04-11 14:39:33 | https://stackoverflow.com/q/12499195 | https://stackoverflow.com/a/12499489 | <p>You can find unpushed commits with <code>git cherry</code>, so you should be able to write a bash script like</p>
<pre><code>#!/bin/bash
for file in `find ./ -type d -maxdepth 3` ; do
cd $file
git cherry -v
cd -
done
</code></pre>
<p>which will find 3 layers of subdirectories, but it's probably not very ... | <p>You can find unpushed commits with <code>git cherry</code>, so you should be able to write a bash script like</p> <pre><code>#!/bin/bash for file in `find ./ -type d -maxdepth 3` ; do cd $file git cherry -v cd - done </code></pre> <p>which will find 3 layers of subdirectories, but it's probably not very ... | 119, 387 | bash, git | <h1>Git - How to find all "unpushed" commits for all projects in a directory?</h1>
<p>I'm finally getting used to Git and, after the initial steep learning curve, I must say it's quite good (I just miss the single file externals, but that's another story). I have, however, an issue that I can't solve: I'm currently wor... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,187 | bash | # Git - How to find all "unpushed" commits for all projects in a directory?
I'm finally getting used to Git and, after the initial steep learning curve, I must say it's quite good (I just miss the single file externals, but that's another story). I have, however, an issue that I can't solve: I'm currently working on a... | You can find unpushed commits with `git cherry`, so you should be able to write a bash script like
```
#!/bin/bash
for file in `find ./ -type d -maxdepth 3` ; do
cd $file
git cherry -v
cd -
done
```
which will find 3 layers of subdirectories, but it's probably not very nice to look at.
## EDIT
As Evan s... |
6328980 | Create a custom powershell script for nuget that adds a custom target to the csproj BeforeBuild step | 13 | 2011-06-13 10:00:14 | <p>I want to create a nuget package that adds a BeforeBuild step to my csproj using a custom MSBuild task I have created. Ideally, I want to:</p>
<ol>
<li>Add a new Target into the csproj file (MyCustomBeforeBuildTarget) </li>
<li>Add the BeforeBuild target if it is not already there</li>
<li>Edit the BeforeBuild Depe... | 5,948 | 7,532 | 2012-11-20 16:50:57 | 7,344,508 | 13 | 2011-09-08 07:19:51 | 17,368 | 2012-08-13 06:40:17 | https://stackoverflow.com/q/6328980 | https://stackoverflow.com/a/7344508 | <p>The <a href="http://nuget.org/packages/NuGetPowerTools" rel="noreferrer">NuGetPowerTools</a> is a package that adds some PowerShell functions that makes it easier to work with the project setup of the project you're adding a package to. To use the functions available you only need to make your package depend on the ... | <p>The <a href="http://nuget.org/packages/NuGetPowerTools" rel="noreferrer">NuGetPowerTools</a> is a package that adds some PowerShell functions that makes it easier to work with the project setup of the project you're adding a package to. To use the functions available you only need to make your package depend on the ... | 265, 526, 10101, 62770 | csproj, msbuild, nuget, powershell | <h1>Create a custom powershell script for nuget that adds a custom target to the csproj BeforeBuild step</h1>
<p>I want to create a nuget package that adds a BeforeBuild step to my csproj using a custom MSBuild task I have created. Ideally, I want to:</p>
<ol>
<li>Add a new Target into the csproj file (MyCustomBeforeB... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,188 | bash | # Create a custom powershell script for nuget that adds a custom target to the csproj BeforeBuild step
I want to create a nuget package that adds a BeforeBuild step to my csproj using a custom MSBuild task I have created. Ideally, I want to:
1. Add a new Target into the csproj file (MyCustomBeforeBuildTarget)
2. Add ... | The [NuGetPowerTools](http://nuget.org/packages/NuGetPowerTools) is a package that adds some PowerShell functions that makes it easier to work with the project setup of the project you're adding a package to. To use the functions available you only need to make your package depend on the NuGetPowerTools, using the depe... |
4515274 | Externally disabling signals for a Linux program | 13 | 2010-12-23 01:57:59 | <p>On Linux, is it possible to somehow disable signaling for programs <strong>externally</strong>... that is, without modifying their source code?</p>
<p><strong>Context:</strong></p>
<p>I'm calling a C (<strong>and also a Java</strong>) program from within a bash script on Linux. I don't want any interruptions for m... | 11,396 | 125,540 | 2017-04-11 13:41:46 | 4,515,549 | 13 | 2010-12-23 02:58:31 | 134,633 | 2010-12-23 12:54:54 | https://stackoverflow.com/q/4515274 | https://stackoverflow.com/a/4515549 | <p>The process signal mask is inherited across <code>exec</code>, so you can simply write a small wrapper program that blocks <code>SIGINT</code> and executes the target:</p>
<pre><code>#include <signal.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
sigset_t sig... | <p>The process signal mask is inherited across <code>exec</code>, so you can simply write a small wrapper program that blocks <code>SIGINT</code> and executes the target:</p> <pre><code>#include <signal.h> #include <unistd.h> #include <stdio.h> int main(int argc, char *argv[]) { sigset_t sig... | 58, 387, 2481, 5313, 124485 | bash, bash-trap, external, linux, signals | <h1>Externally disabling signals for a Linux program</h1>
<p>On Linux, is it possible to somehow disable signaling for programs <strong>externally</strong>... that is, without modifying their source code?</p>
<p><strong>Context:</strong></p>
<p>I'm calling a C (<strong>and also a Java</strong>) program from within a ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,189 | bash | # Externally disabling signals for a Linux program
On Linux, is it possible to somehow disable signaling for programs **externally**... that is, without modifying their source code?
**Context:**
I'm calling a C (**and also a Java**) program from within a bash script on Linux. I don't want any interruptions for my ba... | The process signal mask is inherited across `exec`, so you can simply write a small wrapper program that blocks `SIGINT` and executes the target:
```
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
sigset_t sigs;
sigemptyset(&sigs);
sigaddset(&sig... |
969407 | Determining age of a file in shell script | 13 | 2009-06-09 11:08:18 | <p>G'day,</p>
<p>I need to see if a specific file is more than 58 minutes old from a sh shell script. I'm talking straight vanilla Solaris shell with some POSIX extensions it seems.</p>
<p>I've thought of doing a</p>
<pre><code>touch -t YYYYMMDDHHmm.SS /var/tmp/toto
</code></pre>
<p>where the timestamp is 58 minute... | 33,608 | 2,974 | 2016-04-20 12:20:11 | 969,450 | 13 | 2009-06-09 11:17:28 | 19,513 | 2009-06-09 11:17:28 | https://stackoverflow.com/q/969407 | https://stackoverflow.com/a/969450 | <p>You can use different units in the find command, for example:</p>
<pre><code>find . -mtime +0h55m
</code></pre>
<p>Will return any files with modified dates older than 55 minutes ago.</p>
| <p>You can use different units in the find command, for example:</p> <pre><code>find . -mtime +0h55m </code></pre> <p>Will return any files with modified dates older than 55 minutes ago.</p> | 34, 390, 5310 | file, shell, unix | <h1>Determining age of a file in shell script</h1>
<p>G'day,</p>
<p>I need to see if a specific file is more than 58 minutes old from a sh shell script. I'm talking straight vanilla Solaris shell with some POSIX extensions it seems.</p>
<p>I've thought of doing a</p>
<pre><code>touch -t YYYYMMDDHHmm.SS /var/tmp/toto... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,190 | bash | # Determining age of a file in shell script
G'day,
I need to see if a specific file is more than 58 minutes old from a sh shell script. I'm talking straight vanilla Solaris shell with some POSIX extensions it seems.
I've thought of doing a
```
touch -t YYYYMMDDHHmm.SS /var/tmp/toto
```
where the timestamp is 58 mi... | You can use different units in the find command, for example:
```
find . -mtime +0h55m
```
Will return any files with modified dates older than 55 minutes ago. |
386783 | NSTask not picking up $PATH from the user's environment | 13 | 2008-12-22 17:18:24 | <p>I don't know why this method returns a blank string:</p>
<pre><code>- (NSString *)installedGitLocation {
NSString *launchPath = @"/usr/bin/which";
// Set up the task
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:launchPath];
NSArray *args = [NSArray arrayWithObject:@"git"];
[tas... | 10,211 | 41,116 | 2019-11-12 23:48:31 | 387,997 | 13 | 2008-12-23 02:17:05 | 714 | 2008-12-23 02:17:05 | https://stackoverflow.com/q/386783 | https://stackoverflow.com/a/387997 | <p>Running a task via NSTask uses <code>fork()</code> and <code>exec()</code> to actually run the task. The user's interactive shell isn't involved at all. Since <code>$PATH</code> is (by and large) a shell concept, it doesn't apply when you're talking about running processes in some other fashion.</p>
| <p>Running a task via NSTask uses <code>fork()</code> and <code>exec()</code> to actually run the task. The user's interactive shell isn't involved at all. Since <code>$PATH</code> is (by and large) a shell concept, it doesn't apply when you're talking about running processes in some other fashion.</p> | 387, 390, 994, 7003, 20344 | bash, cocoa, nstask, objective-c, shell | <h1>NSTask not picking up $PATH from the user's environment</h1>
<p>I don't know why this method returns a blank string:</p>
<pre><code>- (NSString *)installedGitLocation {
NSString *launchPath = @"/usr/bin/which";
// Set up the task
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:launchPath... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,191 | bash | # NSTask not picking up $PATH from the user's environment
I don't know why this method returns a blank string:
```
- (NSString *)installedGitLocation {
NSString *launchPath = @"/usr/bin/which";
// Set up the task
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:launchPath];
NSArray *args... | Running a task via NSTask uses `fork()` and `exec()` to actually run the task. The user's interactive shell isn't involved at all. Since `$PATH` is (by and large) a shell concept, it doesn't apply when you're talking about running processes in some other fashion. |
64030699 | Where is settings.json for powershell configuration in Windows Terminal? | 12 | 2020-09-23 14:55:13 | <p>I'm new to Windows 10, having spent a lot of time on Mac OS X and some on Ubuntu, and I've read a lot about the types of things that are good to put in the <code>settings.json</code> file for my <a href="https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7" rel="noreferrer">PowerShell</a... | 19,720 | 293,511 | 2020-09-23 15:47:23 | 64,031,588 | 13 | 2020-09-23 15:42:09 | 3,390,419 | 2020-09-23 15:42:09 | https://stackoverflow.com/q/64030699 | https://stackoverflow.com/a/64031588 | <p>You can find the location of the <code>settings.json</code> file with the following Powershell commands:</p>
<pre><code>$settings = (Get-Item "C:\users\$env:UserName\AppData\Local\Packages\Microsoft.WindowsTerminal_*\LocalState\settings.json")
$settings.DirectoryName
</code></pre>
<hr />
<p>To open it from... | <p>You can find the location of the <code>settings.json</code> file with the following Powershell commands:</p> <pre><code>$settings = (Get-Item "C:\users\$env:UserName\AppData\Local\Packages\Microsoft.WindowsTerminal_*\LocalState\settings.json") $settings.DirectoryName </code></pre> <hr /> <p>To open it from... | 526 | powershell | <h1>Where is settings.json for powershell configuration in Windows Terminal?</h1>
<p>I'm new to Windows 10, having spent a lot of time on Mac OS X and some on Ubuntu, and I've read a lot about the types of things that are good to put in the <code>settings.json</code> file for my <a href="https://learn.microsoft.com/en-... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,192 | bash | # Where is settings.json for powershell configuration in Windows Terminal?
I'm new to Windows 10, having spent a lot of time on Mac OS X and some on Ubuntu, and I've read a lot about the types of things that are good to put in the `settings.json` file for my [PowerShell](https://learn.microsoft.com/en-us/powershell/sc... | You can find the location of the `settings.json` file with the following Powershell commands:
```
$settings = (Get-Item "C:\users\$env:UserName\AppData\Local\Packages\Microsoft.WindowsTerminal_*\LocalState\settings.json")
$settings.DirectoryName
```
---
To open it from the Windows Terminal directly:
1. `Ctrl + ,`
2... |
51052475 | How to iterate over the characters of a string in a POSIX shell script? | 12 | 2018-06-26 23:05:06 | <p>A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings:</p>
<pre><code>for x in $(seq 1 5); do
echo $x
done
</code></pre>
<p>But, how do I iterate over each character of a word?</p>
| 4,048 | null | 2022-09-24 04:15:34 | 51,052,644 | 13 | 2018-06-26 23:29:19 | 89,817 | 2018-06-26 23:42:21 | https://stackoverflow.com/q/51052475 | https://stackoverflow.com/a/51052644 | <p>It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in <code>dash</code>, but I don't have busybox handy to test with.</p>
<pre><code>var='ab * cd'
tmp="$var" # The loop will consume the variable, so make a temp copy first
while [ -n "$tmp" ]; do
rest="${tmp#?}" ... | <p>It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in <code>dash</code>, but I don't have busybox handy to test with.</p> <pre><code>var='ab * cd' tmp="$var" # The loop will consume the variable, so make a temp copy first while [ -n "$tmp" ]; do rest="${tmp#?}" ... | 390, 1993, 10327, 137448 | dash-shell, posix, sh, shell | <h1>How to iterate over the characters of a string in a POSIX shell script?</h1>
<p>A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings:</p>
<pre><code>for x in $(seq 1 5); do
echo $x
done
</code></pre>
<p>But, how do I iterate over each character of a word?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,193 | bash | # How to iterate over the characters of a string in a POSIX shell script?
A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings:
```
for x in $(seq 1 5); do
echo $x
done
```
But, how do I iterate over each character of a word? | It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in `dash`, but I don't have busybox handy to test with.
```
var='ab * cd'
tmp="$var" # The loop will consume the variable, so make a temp copy first
while [ -n "$tmp" ]; do
rest="${tmp#?}" # All but the first char... |
48056606 | bash script starting new shell and continuing to run commands | 12 | 2018-01-02 06:41:08 | <p>I'm a complete noob to writing bash scripts. I'm trying to do the following:</p>
<pre><code>#!/bin/bash
mkdir New_Project
cd New_Project
pipenv install ipykernel
pipenv shell
python -m ipykernel install --user --name==new-virtual-env
jupyter notebook
</code></pre>
<p>The problem I'm having is that after it execut... | 6,035 | 2,089,899 | 2018-01-02 07:29:18 | 48,056,896 | 13 | 2018-01-02 07:08:11 | 1,620,779 | 2018-01-02 07:29:18 | https://stackoverflow.com/q/48056606 | https://stackoverflow.com/a/48056896 | <p>As per the <a href="https://pypi.python.org/pypi/pipenv#other-commands" rel="noreferrer">manual</a> :</p>
<blockquote>
<p>shell will spawn a shell with the virtualenv activated.</p>
</blockquote>
<p>which is not what you need. Instead use <code>run</code> :</p>
<blockquote>
<p>run will run a given command fro... | <p>As per the <a href="https://pypi.python.org/pypi/pipenv#other-commands" rel="noreferrer">manual</a> :</p> <blockquote> <p>shell will spawn a shell with the virtualenv activated.</p> </blockquote> <p>which is not what you need. Instead use <code>run</code> :</p> <blockquote> <p>run will run a given command fro... | 387, 390, 116342, 128625 | bash, jupyter-notebook, pipenv, shell | <h1>bash script starting new shell and continuing to run commands</h1>
<p>I'm a complete noob to writing bash scripts. I'm trying to do the following:</p>
<pre><code>#!/bin/bash
mkdir New_Project
cd New_Project
pipenv install ipykernel
pipenv shell
python -m ipykernel install --user --name==new-virtual-env
jupyter no... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,194 | bash | # bash script starting new shell and continuing to run commands
I'm a complete noob to writing bash scripts. I'm trying to do the following:
```
#!/bin/bash
mkdir New_Project
cd New_Project
pipenv install ipykernel
pipenv shell
python -m ipykernel install --user --name==new-virtual-env
jupyter notebook
```
The prob... | As per the [manual](https://pypi.python.org/pypi/pipenv#other-commands) :
> shell will spawn a shell with the virtualenv activated.
which is not what you need. Instead use `run` :
> run will run a given command from the virtualenv, with any arguments
> forwarded (e.g. $ pipenv run python).
In your case, something l... |
47719681 | Calculate Date / Time difference in Bash on macOS | 12 | 2017-12-08 17:48:24 | <p>I realize there are tons of questions and answers involving date calculation, but I haven't found a solution to the issue on OS X/macOS. I would like to calculate the time difference between two dates and times, but I must have the syntax incorrect.</p>
<pre><code>now=$(date +"%b %d %Y %H:%M:%S")
end=$(date +"Dec 2... | 6,692 | 3,257,552 | 2017-12-08 18:41:04 | 47,720,209 | 13 | 2017-12-08 18:28:04 | 5,291,015 | 2017-12-08 18:41:04 | https://stackoverflow.com/q/47719681 | https://stackoverflow.com/a/47720209 | <p>The ideal way is convert the current time into EPOCH and also the date you need also in EPOCH and get the diff (This works on <code>bash</code> on <code>macOS Sierra</code>)</p>
<pre><code>dudeOnMac:~ $ date +%s
1512757414
dudeOnMac:~ $ date -j -f "%b %d %Y %H:%M:%S" "Dec 25 2017 08:00:00" +%s
1514169000
</code></p... | <p>The ideal way is convert the current time into EPOCH and also the date you need also in EPOCH and get the diff (This works on <code>bash</code> on <code>macOS Sierra</code>)</p> <pre><code>dudeOnMac:~ $ date +%s 1512757414 dudeOnMac:~ $ date -j -f "%b %d %Y %H:%M:%S" "Dec 25 2017 08:00:00" +%s 1514169000 </code></p... | 369, 387, 5002 | bash, date, macos | <h1>Calculate Date / Time difference in Bash on macOS</h1>
<p>I realize there are tons of questions and answers involving date calculation, but I haven't found a solution to the issue on OS X/macOS. I would like to calculate the time difference between two dates and times, but I must have the syntax incorrect.</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,195 | bash | # Calculate Date / Time difference in Bash on macOS
I realize there are tons of questions and answers involving date calculation, but I haven't found a solution to the issue on OS X/macOS. I would like to calculate the time difference between two dates and times, but I must have the syntax incorrect.
```
now=$(date +... | The ideal way is convert the current time into EPOCH and also the date you need also in EPOCH and get the diff (This works on `bash` on `macOS Sierra`)
```
dudeOnMac:~ $ date +%s
1512757414
dudeOnMac:~ $ date -j -f "%b %d %Y %H:%M:%S" "Dec 25 2017 08:00:00" +%s
1514169000
```
So now storing in the variables as you wa... |
43799755 | Export Certificate with private key including all certificates in path using powershell | 12 | 2017-05-05 08:10:11 | <p>I am working on power shell script to export certificate with private key which also includes all the certificates in the path. I wrote a script for that, it is not including the certificates in the path or the root certificate. Below is script. Kindly suggest me if there is any changes to make in my script.
Thanks... | 31,388 | 7,967,540 | 2021-03-27 21:17:21 | 43,802,889 | 13 | 2017-05-05 10:41:36 | 1,186,936 | 2020-03-09 16:35:16 | https://stackoverflow.com/q/43799755 | https://stackoverflow.com/a/43802889 | <p>Updated script to <em>export all certificates matching a particular name and issuer (along with the private key)</em>. Make sure you run this with admin privileges:</p>
<pre><code># Script to export certificate from LocalMachine store along with private key
$Password = "@de08nt2128"; #password to access certificate... | <p>Updated script to <em>export all certificates matching a particular name and issuer (along with the private key)</em>. Make sure you run this with admin privileges:</p> <pre><code># Script to export certificate from LocalMachine store along with private key $Password = "@de08nt2128"; #password to access certificate... | 526, 5954, 96533 | certificate, powershell, windows-server-2012-r2 | <h1>Export Certificate with private key including all certificates in path using powershell</h1>
<p>I am working on power shell script to export certificate with private key which also includes all the certificates in the path. I wrote a script for that, it is not including the certificates in the path or the root cert... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,196 | bash | # Export Certificate with private key including all certificates in path using powershell
I am working on power shell script to export certificate with private key which also includes all the certificates in the path. I wrote a script for that, it is not including the certificates in the path or the root certificate. ... | Updated script to *export all certificates matching a particular name and issuer (along with the private key)*. Make sure you run this with admin privileges:
```
# Script to export certificate from LocalMachine store along with private key
$Password = "@de08nt2128"; #password to access certificate after exporting
$Cer... |
40776710 | Redirect only stdout to /dev/null | 12 | 2016-11-24 01:23:43 | <p>I haven't yet mastered the weird shell stdio redirection thing yet.</p>
<p>I want to run npm install but redirect stdout so I don't have to see all of that. (I still want to capture stderr in the terminal, I just don't want to see stdout).</p>
<pre><code>npm install -D suman 1> /dev/null
</code></pre>
<p>This ... | 12,470 | 1,223,975 | 2016-11-24 01:35:13 | 40,776,730 | 13 | 2016-11-24 01:26:54 | 446,357 | 2016-11-24 01:35:13 | https://stackoverflow.com/q/40776710 | https://stackoverflow.com/a/40776730 | <p><code>npm install -D suman > /dev/null</code> should do it. (It is standard for the redirect, only to redirect stdout)</p>
| <p><code>npm install -D suman > /dev/null</code> should do it. (It is standard for the redirect, only to redirect stdout)</p> | 387, 4867, 8213, 46426 | bash, node.js, stdio, stdout | <h1>Redirect only stdout to /dev/null</h1>
<p>I haven't yet mastered the weird shell stdio redirection thing yet.</p>
<p>I want to run npm install but redirect stdout so I don't have to see all of that. (I still want to capture stderr in the terminal, I just don't want to see stdout).</p>
<pre><code>npm install -D su... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,197 | bash | # Redirect only stdout to /dev/null
I haven't yet mastered the weird shell stdio redirection thing yet.
I want to run npm install but redirect stdout so I don't have to see all of that. (I still want to capture stderr in the terminal, I just don't want to see stdout).
```
npm install -D suman 1> /dev/null
```
This ... | `npm install -D suman > /dev/null` should do it. (It is standard for the redirect, only to redirect stdout) |
38579398 | Adding to $PYTHONPATH with bash script | 12 | 2016-07-26 00:35:15 | <p>I wrote a bash script to add to my <code>$PYTHONPATH</code>. My <code>.sh</code> file has the following:</p>
<pre><code>sudo echo export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module >> ~/.bashrc
</code></pre>
<p>What I want to be added to my <code>.bashrc</code> is:</p>
<pre><code>PYTHONPATH=$PYTHONPAT... | 39,384 | 6,637,328 | 2020-01-30 01:48:25 | 38,579,473 | 13 | 2016-07-26 00:44:48 | 3,030,305 | 2016-07-26 01:26:10 | https://stackoverflow.com/q/38579398 | https://stackoverflow.com/a/38579473 | <p>Use single-quotes:</p>
<pre><code>$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module' >> .bashrc
$ cat .bashrc
export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module
</code></pre>
<p>The shell does not perform variable expansion on single-quoted strings.</p>
<p>Note also that, if you are wr... | <p>Use single-quotes:</p> <pre><code>$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module' >> .bashrc $ cat .bashrc export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module </code></pre> <p>The shell does not perform variable expansion on single-quoted strings.</p> <p>Note also that, if you are wr... | 58, 387, 9013 | bash, environment-variables, linux | <h1>Adding to $PYTHONPATH with bash script</h1>
<p>I wrote a bash script to add to my <code>$PYTHONPATH</code>. My <code>.sh</code> file has the following:</p>
<pre><code>sudo echo export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module >> ~/.bashrc
</code></pre>
<p>What I want to be added to my <code>.bashrc<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,198 | bash | # Adding to $PYTHONPATH with bash script
I wrote a bash script to add to my `$PYTHONPATH`. My `.sh` file has the following:
```
sudo echo export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module >> ~/.bashrc
```
What I want to be added to my `.bashrc` is:
```
PYTHONPATH=$PYTHONPATH:/path/to/new/python/module
```
H... | Use single-quotes:
```
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module' >> .bashrc
$ cat .bashrc
export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module
```
The shell does not perform variable expansion on single-quoted strings.
Note also that, if you are writing to `~/.bashrc`, you should not nee... |
28567973 | Powershell tail multiple files command | 12 | 2015-02-17 17:58:28 | <p>I can tail one file via the following command:</p>
<p><code>Get-Content -Path C:\log1.txt -Tail 10 –Wait</code></p>
<p>How do I extend this to multiple files, I have tried the following with no luck:</p>
<p><code>Get-Content -Path C:\log1.txt,C:\log2.txt -Tail 10 –Wait</code></p>
<p>This will only pick up update... | 5,706 | 126,280 | 2023-08-29 17:29:38 | 28,568,384 | 13 | 2015-02-17 18:21:01 | 126,280 | 2015-02-17 18:21:01 | https://stackoverflow.com/q/28567973 | https://stackoverflow.com/a/28568384 | <p>Based on @mjolinor's comment, I have come up with the following that appears to work,</p>
<pre><code>Workflow My-Tail
{
Param([string[]] $Path)
foreach -parallel ($file in $path)
{
Get-Content -Path $file -Tail 1 -Wait
}
}
My-Tail (dir C:\*.log -Include log1.txt,log2.txt)
</code></pre>
<p... | <p>Based on @mjolinor's comment, I have come up with the following that appears to work,</p> <pre><code>Workflow My-Tail { Param([string[]] $Path) foreach -parallel ($file in $path) { Get-Content -Path $file -Tail 1 -Wait } } My-Tail (dir C:\*.log -Include log1.txt,log2.txt) </code></pre> <p... | 526 | powershell | <h1>Powershell tail multiple files command</h1>
<p>I can tail one file via the following command:</p>
<p><code>Get-Content -Path C:\log1.txt -Tail 10 –Wait</code></p>
<p>How do I extend this to multiple files, I have tried the following with no luck:</p>
<p><code>Get-Content -Path C:\log1.txt,C:\log2.txt -Tail 10 –W... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,199 | bash | # Powershell tail multiple files command
I can tail one file via the following command:
`Get-Content -Path C:\log1.txt -Tail 10 –Wait`
How do I extend this to multiple files, I have tried the following with no luck:
`Get-Content -Path C:\log1.txt,C:\log2.txt -Tail 10 –Wait`
This will only pick up updates from the ... | Based on @mjolinor's comment, I have come up with the following that appears to work,
```
Workflow My-Tail
{
Param([string[]] $Path)
foreach -parallel ($file in $path)
{
Get-Content -Path $file -Tail 1 -Wait
}
}
My-Tail (dir C:\*.log -Include log1.txt,log2.txt)
```
However, this has some sor... |
21719999 | Is there a lock statement in PowerShell | 12 | 2014-02-12 06:07:38 | <p>When using threads in PowerShell, are we able to use the <code>lock</code> statement like in C#?</p>
<p>Or do we need to use the code that <code>lock</code> gets pre compiled to, ie. use the <code>Monitor</code> class?</p>
| 8,547 | 2,063,755 | 2021-03-25 08:42:38 | 28,438,762 | 13 | 2015-02-10 18:10:55 | 4,424,236 | 2015-02-17 15:09:02 | https://stackoverflow.com/q/21719999 | https://stackoverflow.com/a/28438762 | <p>There is no native <code>lock</code> statement in PowerShell as such, but you can acquire\release an exclusive lock on a specified object using <a href="https://msdn.microsoft.com/en-us/library/System.Threading.Monitor.aspx" rel="noreferrer">Monitor Class</a>. It can be used to pass data between threads when working... | <p>There is no native <code>lock</code> statement in PowerShell as such, but you can acquire\release an exclusive lock on a specified object using <a href="https://msdn.microsoft.com/en-us/library/System.Threading.Monitor.aspx" rel="noreferrer">Monitor Class</a>. It can be used to pass data between threads when working... | 526, 1381, 3227 | locking, multithreading, powershell | <h1>Is there a lock statement in PowerShell</h1>
<p>When using threads in PowerShell, are we able to use the <code>lock</code> statement like in C#?</p>
<p>Or do we need to use the code that <code>lock</code> gets pre compiled to, ie. use the <code>Monitor</code> class?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,200 | bash | # Is there a lock statement in PowerShell
When using threads in PowerShell, are we able to use the `lock` statement like in C#?
Or do we need to use the code that `lock` gets pre compiled to, ie. use the `Monitor` class? | There is no native `lock` statement in PowerShell as such, but you can acquire\release an exclusive lock on a specified object using [Monitor Class](https://msdn.microsoft.com/en-us/library/System.Threading.Monitor.aspx). It can be used to pass data between threads when working with Runspaces, which is demonstrated in ... |
23120359 | jq sorts KEY and VALUES in different way - how can I enumerate them in the same order? | 12 | 2014-04-16 21:19:35 | <p>I get REST output in JSON format using curl command as below</p>
<p>Getting KEY names alone using:</p>
<pre><code>curl http://test.te:8080/testApp/app/version | jq '.version' | jq '. | keys'
</code></pre>
<p>OUTPUT:</p>
<pre><code>"Archiver-Version",
"Build-Id",
"Build-Jdk",
"Build-Number",
"Build-Tag",
"Built-B... | 15,554 | 2,476,906 | 2017-02-20 23:54:20 | 23,234,757 | 13 | 2014-04-23 04:28:44 | 2,018,649 | 2014-04-23 04:28:44 | https://stackoverflow.com/q/23120359 | https://stackoverflow.com/a/23234757 | <p>jq has an option to sort the keys. See <a href="http://stedolan.github.io/jq/manual/#Invokingjq" rel="noreferrer">http://stedolan.github.io/jq/manual/#Invokingjq</a></p>
<pre><code>--sort-keys / -S:
Output the fields of each object with the keys in sorted order.
</code></pre>
<p>However the current released versi... | <p>jq has an option to sort the keys. See <a href="http://stedolan.github.io/jq/manual/#Invokingjq" rel="noreferrer">http://stedolan.github.io/jq/manual/#Invokingjq</a></p> <pre><code>--sort-keys / -S: Output the fields of each object with the keys in sorted order. </code></pre> <p>However the current released versi... | 34, 390, 1508, 2684, 105170 | enumeration, jq, json, shell, unix | <h1>jq sorts KEY and VALUES in different way - how can I enumerate them in the same order?</h1>
<p>I get REST output in JSON format using curl command as below</p>
<p>Getting KEY names alone using:</p>
<pre><code>curl http://test.te:8080/testApp/app/version | jq '.version' | jq '. | keys'
</code></pre>
<p>OUTPUT:</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,201 | bash | # jq sorts KEY and VALUES in different way - how can I enumerate them in the same order?
I get REST output in JSON format using curl command as below
Getting KEY names alone using:
```
curl http://test.te:8080/testApp/app/version | jq '.version' | jq '. | keys'
```
OUTPUT:
```
"Archiver-Version",
"Build-Id",
"Buil... | jq has an option to sort the keys. See <http://stedolan.github.io/jq/manual/#Invokingjq>
```
--sort-keys / -S:
Output the fields of each object with the keys in sorted order.
```
However the current released version (1.3) of jq doesn't have this enhancement yet, you'll need to compile jq via latest code from it's ma... |
19410644 | Is there a way to make powershell wait for an install to finish? | 12 | 2013-10-16 18:08:07 | <p>I have a list of Windows packages that I'm installing via powershell using the following command:</p>
<p><code>& mypatch.exe /passive /norestart</code></p>
<p><code>mypatch.exe</code> is being passed from a list and it doesn't wait for the prior install to finish - it just keeps going. It builds up a huge win... | 32,991 | 1,492,471 | 2018-11-25 11:30:48 | 19,411,412 | 13 | 2013-10-16 18:50:39 | 499,466 | 2013-10-16 18:50:39 | https://stackoverflow.com/q/19410644 | https://stackoverflow.com/a/19411412 | <pre><code>Start-Process <path to exe> -Wait
</code></pre>
| <pre><code>Start-Process <path to exe> -Wait </code></pre> | 64, 526, 21289 | powershell, wait, windows | <h1>Is there a way to make powershell wait for an install to finish?</h1>
<p>I have a list of Windows packages that I'm installing via powershell using the following command:</p>
<p><code>& mypatch.exe /passive /norestart</code></p>
<p><code>mypatch.exe</code> is being passed from a list and it doesn't wait for t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,202 | bash | # Is there a way to make powershell wait for an install to finish?
I have a list of Windows packages that I'm installing via powershell using the following command:
`& mypatch.exe /passive /norestart`
`mypatch.exe` is being passed from a list and it doesn't wait for the prior install to finish - it just keeps going.... | ```
Start-Process <path to exe> -Wait
``` |
17880902 | Powershell: Issue with & in scriptblock | 12 | 2013-07-26 12:07:13 | <p>I face an issue when I run the following command</p>
<pre><code>$x = "c:\Scripts\Log3.ps1"
$remoteMachineName = "172.16.61.51"
Invoke-Command -ComputerName $remoteMachineName -ScriptBlock {& $x}
The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, s... | 16,294 | 2,622,678 | 2017-06-06 05:37:53 | 17,881,960 | 13 | 2013-07-26 12:59:49 | 2,022,667 | 2013-07-26 12:59:49 | https://stackoverflow.com/q/17880902 | https://stackoverflow.com/a/17881960 | <p>Variables in your PowerShell session are not transferred to sessions created with <code>Invoke-Command</code></p>
<p>You need to use the <code>-ArgumentList</code> parameter to send the variables your command and then use the <code>$args</code> array to access them in the script block so your command will look like... | <p>Variables in your PowerShell session are not transferred to sessions created with <code>Invoke-Command</code></p> <p>You need to use the <code>-ArgumentList</code> parameter to send the variables your command and then use the <code>$args</code> array to access them in the script block so your command will look like... | 526, 63177 | powershell, powershell-remoting | <h1>Powershell: Issue with & in scriptblock</h1>
<p>I face an issue when I run the following command</p>
<pre><code>$x = "c:\Scripts\Log3.ps1"
$remoteMachineName = "172.16.61.51"
Invoke-Command -ComputerName $remoteMachineName -ScriptBlock {& $x}
The expression after '&' in a pipeline element produced an in... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,203 | bash | # Powershell: Issue with & in scriptblock
I face an issue when I run the following command
```
$x = "c:\Scripts\Log3.ps1"
$remoteMachineName = "172.16.61.51"
Invoke-Command -ComputerName $remoteMachineName -ScriptBlock {& $x}
The expression after '&' in a pipeline element produced an invalid object. It must result... | Variables in your PowerShell session are not transferred to sessions created with `Invoke-Command`
You need to use the `-ArgumentList` parameter to send the variables your command and then use the `$args` array to access them in the script block so your command will look like:
```
Invoke-Command -ComputerName $remote... |
14835983 | How to create real objects with behavior (methods) in PowerShell? | 12 | 2013-02-12 15:31:48 | <p>Probably this question has been answered before.... but I have not found a specific answer to my needs.</p>
<p>BTW I'm using PowerShell 3</p>
<p>Well, I'm new in PowerShell but I have a lot of experience as a C# developer, so working with objects is very important to me.</p>
<p>So I'm wondering if there's a <stro... | 10,545 | 1,268,570 | 2020-12-24 17:46:50 | 14,836,102 | 13 | 2013-02-12 15:37:14 | 674,943 | 2013-02-12 15:48:09 | https://stackoverflow.com/q/14835983 | https://stackoverflow.com/a/14836102 | <p>Two options to create object with methods:</p>
<ol>
<li>Add-Member</li>
<li>New-Module -AsCustomObject</li>
</ol>
<p>Code samples:</p>
<pre><code>$person | Add-Member -MemberType ScriptMethod -Value {
'I do stuff!'
}
$person = New-Module -AsCustomObject -ScriptBlock {
$Property = 'value'
[string]$Oth... | <p>Two options to create object with methods:</p> <ol> <li>Add-Member</li> <li>New-Module -AsCustomObject</li> </ol> <p>Code samples:</p> <pre><code>$person | Add-Member -MemberType ScriptMethod -Value { 'I do stuff!' } $person = New-Module -AsCustomObject -ScriptBlock { $Property = 'value' [string]$Oth... | 9, 526, 24067, 73157 | c#, powershell, powershell-2.0, powershell-3.0 | <h1>How to create real objects with behavior (methods) in PowerShell?</h1>
<p>Probably this question has been answered before.... but I have not found a specific answer to my needs.</p>
<p>BTW I'm using PowerShell 3</p>
<p>Well, I'm new in PowerShell but I have a lot of experience as a C# developer, so working with o... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,204 | bash | # How to create real objects with behavior (methods) in PowerShell?
Probably this question has been answered before.... but I have not found a specific answer to my needs.
BTW I'm using PowerShell 3
Well, I'm new in PowerShell but I have a lot of experience as a C# developer, so working with objects is very importan... | Two options to create object with methods:
1. Add-Member
2. New-Module -AsCustomObject
Code samples:
```
$person | Add-Member -MemberType ScriptMethod -Value {
'I do stuff!'
}
$person = New-Module -AsCustomObject -ScriptBlock {
$Property = 'value'
[string]$Other = 'Can be strongly typed'
function M... |
14471692 | Bash decimal to base 62 conversion | 12 | 2013-01-23 02:55:00 | <p>I would like to reverse the operation performed by the following <code>bash</code> command:</p>
<pre><code>$ echo $((62#a39qrT))
9207903953
</code></pre>
<p>i.e. convert <em>decimal 9207903953</em> to <em>base 62</em>, keeping <code>bash</code> standard of <code>{0..9},{a..z},{A..Z}</code>.</p>
<p>I know I can do... | 7,110 | 754,519 | 2017-05-12 20:32:32 | 14,472,352 | 13 | 2013-01-23 04:14:59 | 1,655,939 | 2013-01-23 04:14:59 | https://stackoverflow.com/q/14471692 | https://stackoverflow.com/a/14472352 | <p>I do really appreciate the solution you came up with, and I guess there's no way around it straight with bash. Here's the little point you've missed:</p>
<pre><code>BASE62=($(echo {0..9} {a..z} {A..Z}))
for i in $(bc <<< "obase=62; 9207903953"); do
echo -n ${BASE62[$(( 10#$i ))]}
done && echo
<... | <p>I do really appreciate the solution you came up with, and I guess there's no way around it straight with bash. Here's the little point you've missed:</p> <pre><code>BASE62=($(echo {0..9} {a..z} {A..Z})) for i in $(bc <<< "obase=62; 9207903953"); do echo -n ${BASE62[$(( 10#$i ))]} done && echo <... | 387, 390, 6269, 34696 | base-conversion, bash, bc, shell | <h1>Bash decimal to base 62 conversion</h1>
<p>I would like to reverse the operation performed by the following <code>bash</code> command:</p>
<pre><code>$ echo $((62#a39qrT))
9207903953
</code></pre>
<p>i.e. convert <em>decimal 9207903953</em> to <em>base 62</em>, keeping <code>bash</code> standard of <code>{0..9},{... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,205 | bash | # Bash decimal to base 62 conversion
I would like to reverse the operation performed by the following `bash` command:
```
$ echo $((62#a39qrT))
9207903953
```
i.e. convert *decimal 9207903953* to *base 62*, keeping `bash` standard of `{0..9},{a..z},{A..Z}`.
I know I can do this by using `bc`, but I will have to man... | I do really appreciate the solution you came up with, and I guess there's no way around it straight with bash. Here's the little point you've missed:
```
BASE62=($(echo {0..9} {a..z} {A..Z}))
for i in $(bc <<< "obase=62; 9207903953"); do
echo -n ${BASE62[$(( 10#$i ))]}
done && echo
```
Output:
```
a39qrT
``` |
8254864 | What is the difference between $VARIABLE and ${VARIABLE} | 12 | 2011-11-24 09:38:58 | <p>Can anyone please provide me an explanation as to why some Linux expert suggest that we use ${VARIABLE} in Bash scripts? There doesn't seem to be any difference at all.</p>
| 7,402 | 351,545 | 2013-02-26 18:48:01 | 8,254,900 | 13 | 2011-11-24 09:41:01 | 714,501 | 2011-11-24 09:44:30 | https://stackoverflow.com/q/8254864 | https://stackoverflow.com/a/8254900 | <p>Say you want to print <code>$VARIABLE</code> immediately followed by <code>"string"</code></p>
<pre><code>echo "$VARIABLEstring" # tries to print the variable called VARIABLEstring
echo "${VARIABLE}string" # prints $VARIABLE and then "string"
</code></pre>
<p>Bash also supports <a href="http://tldp.org/LDP/abs... | <p>Say you want to print <code>$VARIABLE</code> immediately followed by <code>"string"</code></p> <pre><code>echo "$VARIABLEstring" # tries to print the variable called VARIABLEstring echo "${VARIABLE}string" # prints $VARIABLE and then "string" </code></pre> <p>Bash also supports <a href="http://tldp.org/LDP/abs... | 58, 276, 387 | bash, linux, variables | <h1>What is the difference between $VARIABLE and ${VARIABLE}</h1>
<p>Can anyone please provide me an explanation as to why some Linux expert suggest that we use ${VARIABLE} in Bash scripts? There doesn't seem to be any difference at all.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,206 | bash | # What is the difference between $VARIABLE and ${VARIABLE}
Can anyone please provide me an explanation as to why some Linux expert suggest that we use ${VARIABLE} in Bash scripts? There doesn't seem to be any difference at all. | Say you want to print `$VARIABLE` immediately followed by `"string"`
```
echo "$VARIABLEstring" # tries to print the variable called VARIABLEstring
echo "${VARIABLE}string" # prints $VARIABLE and then "string"
```
Bash also supports [string manipulation](http://tldp.org/LDP/abs/html/string-manipulation.html) usin... |
8101812 | Using the linux 'file' command to determine type (ie. image, audio, or video) | 12 | 2011-11-12 01:28:11 | <p>The word <code>file</code> here refers to the shell <a href="http://linux.die.net/man/1/file" rel="noreferrer">file</a> command, and not actual files. I want to determine whether a file is a, for example, video file (<code>.mpg</code>, <code>.mkv</code>, <code>.avi</code>). <code>file</code> is pretty good at return... | 29,686 | 654,789 | 2023-07-26 16:29:24 | 8,101,976 | 13 | 2011-11-12 02:00:13 | 331,137 | 2011-11-12 02:00:13 | https://stackoverflow.com/q/8101812 | https://stackoverflow.com/a/8101976 | <p>The results from <code>file</code> are less than perfect, and it has more problems with some types of files than others. File basically just looks for particular pieces of binary data in predictable patterns to figure out filetypes.</p>
<p>Unfortunately, in particular, some of the filetypes often used for video fal... | <p>The results from <code>file</code> are less than perfect, and it has more problems with some types of files than others. File basically just looks for particular pieces of binary data in predictable patterns to figure out filetypes.</p> <p>Unfortunately, in particular, some of the filetypes often used for video fal... | 387, 390, 4280 | bash, file-type, shell | <h1>Using the linux 'file' command to determine type (ie. image, audio, or video)</h1>
<p>The word <code>file</code> here refers to the shell <a href="http://linux.die.net/man/1/file" rel="noreferrer">file</a> command, and not actual files. I want to determine whether a file is a, for example, video file (<code>.mpg</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,207 | bash | # Using the linux 'file' command to determine type (ie. image, audio, or video)
The word `file` here refers to the shell [file](http://linux.die.net/man/1/file) command, and not actual files. I want to determine whether a file is a, for example, video file (`.mpg`, `.mkv`, `.avi`). `file` is pretty good at returning `... | The results from `file` are less than perfect, and it has more problems with some types of files than others. File basically just looks for particular pieces of binary data in predictable patterns to figure out filetypes.
Unfortunately, in particular, some of the filetypes often used for video fall into this "problema... |
7178888 | 'grep -q' not exiting with 'tail -f' | 12 | 2011-08-24 16:21:31 | <p>I am trying to implement a script that wait for a specific message in a log file. Once the message is logged then I want to continue the script.</p>
<p>Here's what I am trying out with <code>tail -f</code> and <code>grep -q</code>:</p>
<pre><code># tail -f logfile | grep -q 'Message to continue'
</code></pre>
<p>... | 8,744 | 594,584 | 2015-02-21 03:22:39 | 7,178,916 | 13 | 2011-08-24 16:23:31 | 112,968 | 2011-08-24 17:07:26 | https://stackoverflow.com/q/7178888 | https://stackoverflow.com/a/7178916 | <p><code>tail -f</code> will read a file and display lines later added, it will not terminate (unless a signal like <code>SIGTERM</code> is sent). <code>grep</code> is not the blocking part here, <code>tail -f</code> is. <code>grep</code> will read from the pipe until it is closed, but it never is because <code>tail -f... | <p><code>tail -f</code> will read a file and display lines later added, it will not terminate (unless a signal like <code>SIGTERM</code> is sent). <code>grep</code> is not the blocking part here, <code>tail -f</code> is. <code>grep</code> will read from the pipe until it is closed, but it never is because <code>tail -f... | 58, 387, 1271 | bash, grep, linux | <h1>'grep -q' not exiting with 'tail -f'</h1>
<p>I am trying to implement a script that wait for a specific message in a log file. Once the message is logged then I want to continue the script.</p>
<p>Here's what I am trying out with <code>tail -f</code> and <code>grep -q</code>:</p>
<pre><code># tail -f logfile | gr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,208 | bash | # 'grep -q' not exiting with 'tail -f'
I am trying to implement a script that wait for a specific message in a log file. Once the message is logged then I want to continue the script.
Here's what I am trying out with `tail -f` and `grep -q`:
```
# tail -f logfile | grep -q 'Message to continue'
```
The `grep` never... | `tail -f` will read a file and display lines later added, it will not terminate (unless a signal like `SIGTERM` is sent). `grep` is not the blocking part here, `tail -f` is. `grep` will read from the pipe until it is closed, but it never is because `tail -f` does not quit and keep the pipe open.
---
A solution to you... |
6072812 | Make java program return value to calling shell script | 12 | 2011-05-20 13:42:50 | <p>Unix gurus!</p>
<p>I have a <strong>Java program</strong> which passes some parameters to a <strong>Servlet</strong>. The Servlet enters the info into a DB and returns back the <em>ID</em> of a row created back to the java program that calls it. The <strong>Java program</strong> is run in a Unix <strong>shell scrip... | 37,392 | 620,275 | 2011-05-20 15:56:31 | 6,072,852 | 13 | 2011-05-20 13:46:47 | 129,570 | 2011-05-20 15:33:40 | https://stackoverflow.com/q/6072812 | https://stackoverflow.com/a/6072852 | <p>I would not recommend using the exit status to carry data, for the reasons you've stated. Catching the exit status depends on what shell you're using, but in Bash, the special <code>$?</code> variable contains the exit status of the last process executed.</p>
<p>Writing data to stdout is far more idiomatic. In Ba... | <p>I would not recommend using the exit status to carry data, for the reasons you've stated. Catching the exit status depends on what shell you're using, but in Bash, the special <code>$?</code> variable contains the exit status of the last process executed.</p> <p>Writing data to stdout is far more idiomatic. In Ba... | 17, 34, 390 | java, shell, unix | <h1>Make java program return value to calling shell script</h1>
<p>Unix gurus!</p>
<p>I have a <strong>Java program</strong> which passes some parameters to a <strong>Servlet</strong>. The Servlet enters the info into a DB and returns back the <em>ID</em> of a row created back to the java program that calls it. The <s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,209 | bash | # Make java program return value to calling shell script
Unix gurus!
I have a **Java program** which passes some parameters to a **Servlet**. The Servlet enters the info into a DB and returns back the *ID* of a row created back to the java program that calls it. The **Java program** is run in a Unix **shell script**,... | I would not recommend using the exit status to carry data, for the reasons you've stated. Catching the exit status depends on what shell you're using, but in Bash, the special `$?` variable contains the exit status of the last process executed.
Writing data to stdout is far more idiomatic. In Bash, you capture it as f... |
5983558 | Reading a config file from a shell script | 12 | 2011-05-12 19:41:42 | <p>I am looking for a shell script analog to something like Pythons's <code>ConfigParser</code> or Perl's <code>Config::INI</code>. I have sourced files in the past to accomplish this, but I'd prefer to read rather than execute my "config file". Does anyone know of anything comparable to the above modules ava... | 32,892 | 363,796 | 2023-08-11 23:10:07 | 5,984,215 | 13 | 2011-05-12 20:42:23 | 632,407 | 2014-07-17 09:27:00 | https://stackoverflow.com/q/5983558 | https://stackoverflow.com/a/5984215 | <p>You don't want source it, so you should:</p>
<p>1.read the config, 2.verify lines 3.eval them</p>
<pre><code>CONFIGFILE="/path/to/config"
echo "=$ADMIN= =$TODO= =$FILE=" #these variables are not defined here
eval $(sed '/:/!d;/^ *#/d;s/:/ /;' < "$CONFIGFILE" | while read -r key val
do
#verify here
#...
... | <p>You don't want source it, so you should:</p> <p>1.read the config, 2.verify lines 3.eval them</p> <pre><code>CONFIGFILE="/path/to/config" echo "=$ADMIN= =$TODO= =$FILE=" #these variables are not defined here eval $(sed '/:/!d;/^ *#/d;s/:/ /;' < "$CONFIGFILE" | while read -r key val do #verify here #... ... | 390, 3574 | config, shell | <h1>Reading a config file from a shell script</h1>
<p>I am looking for a shell script analog to something like Pythons's <code>ConfigParser</code> or Perl's <code>Config::INI</code>. I have sourced files in the past to accomplish this, but I'd prefer to read rather than execute my "config file". Does anyone k... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,210 | bash | # Reading a config file from a shell script
I am looking for a shell script analog to something like Pythons's `ConfigParser` or Perl's `Config::INI`. I have sourced files in the past to accomplish this, but I'd prefer to read rather than execute my "config file". Does anyone know of anything comparable to the above m... | You don't want source it, so you should:
1.read the config, 2.verify lines 3.eval them
```
CONFIGFILE="/path/to/config"
echo "=$ADMIN= =$TODO= =$FILE=" #these variables are not defined here
eval $(sed '/:/!d;/^ *#/d;s/:/ /;' < "$CONFIGFILE" | while read -r key val
do
#verify here
#...
str="$key='$val'"
... |
4753993 | Passing arguments to a command in Bash script with spaces | 12 | 2011-01-20 23:48:02 | <p>I'm trying to pass 2 arguments to a command and each argument contains spaces, I've tried escaping the spaces in the args, I've tried wrapping in single quotes, I've tried escaping \" but nothing will work.</p>
<p>Here's a simple example.</p>
<pre><code>#!/bin/bash -xv
ARG="/tmp/a b/1.txt"
ARG2="/tmp/a b/2.txt"
... | 17,378 | 98,050 | 2011-01-21 00:21:10 | 4,754,015 | 13 | 2011-01-20 23:50:42 | 207,248 | 2011-01-20 23:56:04 | https://stackoverflow.com/q/4753993 | https://stackoverflow.com/a/4754015 | <p>See <a href="http://mywiki.wooledge.org/BashFAQ/050" rel="noreferrer">http://mywiki.wooledge.org/BashFAQ/050</a></p>
<h3>TLDR</h3>
<p>Put your args in an array and call your program as <code>myutil "${arr[@]}"</code></p>
<pre><code>#!/bin/bash -xv
file1="file with spaces 1"
file2="file with spaces 2"
echo "foo" ... | <p>See <a href="http://mywiki.wooledge.org/BashFAQ/050" rel="noreferrer">http://mywiki.wooledge.org/BashFAQ/050</a></p> <h3>TLDR</h3> <p>Put your args in an array and call your program as <code>myutil "${arr[@]}"</code></p> <pre><code>#!/bin/bash -xv file1="file with spaces 1" file2="file with spaces 2" echo "foo" ... | 34, 387, 390, 531, 4804 | bash, escaping, scripting, shell, unix | <h1>Passing arguments to a command in Bash script with spaces</h1>
<p>I'm trying to pass 2 arguments to a command and each argument contains spaces, I've tried escaping the spaces in the args, I've tried wrapping in single quotes, I've tried escaping \" but nothing will work.</p>
<p>Here's a simple example.</p>
<pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,211 | bash | # Passing arguments to a command in Bash script with spaces
I'm trying to pass 2 arguments to a command and each argument contains spaces, I've tried escaping the spaces in the args, I've tried wrapping in single quotes, I've tried escaping \" but nothing will work.
Here's a simple example.
```
#!/bin/bash -xv
ARG=... | See <http://mywiki.wooledge.org/BashFAQ/050>
### TLDR
Put your args in an array and call your program as `myutil "${arr[@]}"`
```
#!/bin/bash -xv
file1="file with spaces 1"
file2="file with spaces 2"
echo "foo" > "$file1"
echo "bar" > "$file2"
arr=("$file1" "$file2")
cat "${arr[@]}"
```
### Output
```
file1="file... |
2290365 | How can I execute a shell command using VBA? | 12 | 2010-02-18 16:45:41 | <p>I want to execute a shell command like the following using Visual Basic for Applications.</p>
<pre><code>C:\Temp\gc.exe 1
</code></pre>
<p>How can I do it?</p>
| 69,040 | 187,730 | 2016-01-15 02:54:15 | 2,290,410 | 13 | 2010-02-18 16:49:46 | 36,737 | 2010-02-18 16:49:46 | https://stackoverflow.com/q/2290365 | https://stackoverflow.com/a/2290410 | <p>Example:</p>
<pre><code> retVal = Shell("C:\Temp\gc.exe 1", vbNormalFocus)
</code></pre>
<p>Link: <a href="http://www.mvps.org/dmcritchie/excel/shell.htm" rel="noreferrer">Shell Invoked from VBA</a></p>
| <p>Example:</p> <pre><code> retVal = Shell("C:\Temp\gc.exe 1", vbNormalFocus) </code></pre> <p>Link: <a href="http://www.mvps.org/dmcritchie/excel/shell.htm" rel="noreferrer">Shell Invoked from VBA</a></p> | 64, 390, 1449 | shell, vba, windows | <h1>How can I execute a shell command using VBA?</h1>
<p>I want to execute a shell command like the following using Visual Basic for Applications.</p>
<pre><code>C:\Temp\gc.exe 1
</code></pre>
<p>How can I do it?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,212 | bash | # How can I execute a shell command using VBA?
I want to execute a shell command like the following using Visual Basic for Applications.
```
C:\Temp\gc.exe 1
```
How can I do it? | Example:
```
retVal = Shell("C:\Temp\gc.exe 1", vbNormalFocus)
```
Link: [Shell Invoked from VBA](http://www.mvps.org/dmcritchie/excel/shell.htm) |
63006323 | Powershell GetEnvironmentVariable vs $Env | 11 | 2020-07-21 02:06:28 | <p>I have run into a couple cases where I am trying to use a command via command line, but the command is not recognized. I have narrowed it down to an issue with environment variables. In each case, the variable is present when I retrieve the variable with the underlying C# method, but not with the shorthand, $env:my... | 15,128 | 2,008,423 | 2020-07-22 04:52:47 | 63,008,393 | 13 | 2020-07-21 06:09:25 | 11,942,268 | 2020-07-22 04:52:47 | https://stackoverflow.com/q/63006323 | https://stackoverflow.com/a/63008393 | <p>When opening a PowerShell session, all permanently stored environment variables<sup>1</sup> will be loaded into the Environment drive (<code>Env:</code>) of this current session (<a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_provider?view=powershell-7#... | <p>When opening a PowerShell session, all permanently stored environment variables<sup>1</sup> will be loaded into the Environment drive (<code>Env:</code>) of this current session (<a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_provider?view=powershell-7#... | 526, 9013 | environment-variables, powershell | <h1>Powershell GetEnvironmentVariable vs $Env</h1>
<p>I have run into a couple cases where I am trying to use a command via command line, but the command is not recognized. I have narrowed it down to an issue with environment variables. In each case, the variable is present when I retrieve the variable with the underl... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,214 | bash | # Powershell GetEnvironmentVariable vs $Env
I have run into a couple cases where I am trying to use a command via command line, but the command is not recognized. I have narrowed it down to an issue with environment variables. In each case, the variable is present when I retrieve the variable with the underlying C# me... | When opening a PowerShell session, all permanently stored environment variables1 will be loaded into the Environment drive (`Env:`) of this current session ([source](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_provider?view=powershell-7#detailed-description)):
... |
52498299 | How can I get the Physical Path property of a site | 11 | 2018-09-25 12:31:07 | <p>When I just list the sites with the default formatting, it shows the physical path.</p>
<pre><code>PS C:\Windows\system32> $sm = Get-IISServerManager
PS C:\Windows\system32> $sm.Sites
Name ID State Physical Path Bindings ... | 12,006 | 1,872,399 | 2023-04-10 15:38:43 | 52,500,746 | 13 | 2018-09-25 14:34:22 | 1,872,399 | 2018-09-25 14:34:22 | https://stackoverflow.com/q/52498299 | https://stackoverflow.com/a/52500746 | <p>After decompiling and debugging this for a few hours, I found the expression powershell uses internally:</p>
<p><code>$_.Applications["/"].VirtualDirectories["/"].PhysicalPath</code></p>
<p>No idea how you are supposed to find that out without a decompiler.</p>
| <p>After decompiling and debugging this for a few hours, I found the expression powershell uses internally:</p> <p><code>$_.Applications["/"].VirtualDirectories["/"].PhysicalPath</code></p> <p>No idea how you are supposed to find that out without a decompiler.</p> | 215, 526 | iis, powershell | <h1>How can I get the Physical Path property of a site</h1>
<p>When I just list the sites with the default formatting, it shows the physical path.</p>
<pre><code>PS C:\Windows\system32> $sm = Get-IISServerManager
PS C:\Windows\system32> $sm.Sites
Name ID State Physical Path ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,215 | bash | # How can I get the Physical Path property of a site
When I just list the sites with the default formatting, it shows the physical path.
```
PS C:\Windows\system32> $sm = Get-IISServerManager
PS C:\Windows\system32> $sm.Sites
Name ID State Physical Path Bindings ... | After decompiling and debugging this for a few hours, I found the expression powershell uses internally:
`$_.Applications["/"].VirtualDirectories["/"].PhysicalPath`
No idea how you are supposed to find that out without a decompiler. |
50849416 | Loop range with steps | 11 | 2018-06-14 04:00:59 | <p>I'm trying to move from BATCH into PowerShell and I am trying to convert my own scripts.</p>
<p>My problem is with ranges in loop: my original BATCH script was like</p>
<pre><code> for /L %%U in (123,2,323) do ECHO %%U
</code></pre>
<p>and will print </p>
<pre><code>123
125
127
...
</code></pre>
<p>with Power... | 30,205 | 9,939,320 | 2023-11-21 21:41:22 | 50,849,553 | 13 | 2018-06-14 04:19:35 | 1,417,694 | 2018-06-14 04:28:44 | https://stackoverflow.com/q/50849416 | https://stackoverflow.com/a/50849553 | <p>Simple Google search should have found you this.</p>
<pre><code>for ($i=123; $i -le 323; $i=$i+2 ) {Write-Host $i;}
</code></pre>
<p>(Initialize; condition to keep the loop running; iteration)</p>
| <p>Simple Google search should have found you this.</p> <pre><code>for ($i=123; $i -le 323; $i=$i+2 ) {Write-Host $i;} </code></pre> <p>(Initialize; condition to keep the loop running; iteration)</p> | 526, 631, 8125 | foreach, powershell, range | <h1>Loop range with steps</h1>
<p>I'm trying to move from BATCH into PowerShell and I am trying to convert my own scripts.</p>
<p>My problem is with ranges in loop: my original BATCH script was like</p>
<pre><code> for /L %%U in (123,2,323) do ECHO %%U
</code></pre>
<p>and will print </p>
<pre><code>123
125
127
.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,216 | bash | # Loop range with steps
I'm trying to move from BATCH into PowerShell and I am trying to convert my own scripts.
My problem is with ranges in loop: my original BATCH script was like
```
for /L %%U in (123,2,323) do ECHO %%U
```
and will print
```
123
125
127
...
```
with Powershell a range would be 123..323, t... | Simple Google search should have found you this.
```
for ($i=123; $i -le 323; $i=$i+2 ) {Write-Host $i;}
```
(Initialize; condition to keep the loop running; iteration) |
44566284 | Cannot commit configuration changes because the file has changed on disk | 11 | 2017-06-15 11:25:23 | <p>I would like to have a powershell script that could create an IIS web site.
but I am getting error </p>
<blockquote>
<p>New-IISSite : Filename:
\?\C:\Windows\system32\inetsrv\config\applicationHost.config Error:
Cannot commit configuration changes because the file has changed on
disk At C:\projects\salonsec... | 16,645 | 307,072 | 2023-09-20 19:41:42 | 45,337,496 | 13 | 2017-07-26 21:10:31 | 3,112,914 | 2017-07-26 21:10:31 | https://stackoverflow.com/q/44566284 | https://stackoverflow.com/a/45337496 | <p>There are many different things that can lock the applicationHost.config file and cause powershell commands like <code>New-IISSite</code> to fail. </p>
<p>In this case, you mentioned you deleted the site manually so perhaps you still have IIS Manager open and it is locking the file. I suggest closing IIS Manager. <... | <p>There are many different things that can lock the applicationHost.config file and cause powershell commands like <code>New-IISSite</code> to fail. </p> <p>In this case, you mentioned you deleted the site manually so perhaps you still have IIS Manager open and it is locking the file. I suggest closing IIS Manager. <... | 96, 215, 526 | asp.net, iis, powershell | <h1>Cannot commit configuration changes because the file has changed on disk</h1>
<p>I would like to have a powershell script that could create an IIS web site.
but I am getting error </p>
<blockquote>
<p>New-IISSite : Filename:
\?\C:\Windows\system32\inetsrv\config\applicationHost.config Error:
Cannot commit co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,217 | bash | # Cannot commit configuration changes because the file has changed on disk
I would like to have a powershell script that could create an IIS web site.
but I am getting error
> New-IISSite : Filename:
> \?\C:\Windows\system32\inetsrv\config\applicationHost.config Error:
> Cannot commit configuration changes because th... | There are many different things that can lock the applicationHost.config file and cause powershell commands like `New-IISSite` to fail.
In this case, you mentioned you deleted the site manually so perhaps you still have IIS Manager open and it is locking the file. I suggest closing IIS Manager.
As described in this [... |
44900568 | How to propagate -Verbose to module functions? | 11 | 2017-07-04 08:17:37 | <p>According to answers <a href="https://stackoverflow.com/questions/4301562/how-to-properly-use-the-verbose-and-debug-parameters-in-custom-cmdlet/20830886#20830886">like this one</a> and my own experience, Powershell can take care of propagating -Verbose (and -Debug) automatically, which is very convenient. However th... | 4,030 | 128,384 | 2025-02-18 19:31:37 | 44,902,512 | 13 | 2017-07-04 09:45:57 | 5,039,142 | 2017-07-04 09:45:57 | https://stackoverflow.com/q/44900568 | https://stackoverflow.com/a/44902512 | <p>The reason this is happening is because the <code>$VerbosePreference</code> is not propagated when the module is called.
I modified your script to explicitly print the value at the same points you are outputting via <code>Write-Verbose</code> and <code>Write-Output</code>.</p>
<p><a href="https://powershell.org/20... | <p>The reason this is happening is because the <code>$VerbosePreference</code> is not propagated when the module is called. I modified your script to explicitly print the value at the same points you are outputting via <code>Write-Verbose</code> and <code>Write-Output</code>.</p> <p><a href="https://powershell.org/20... | 526, 153947 | powershell, powershell-cmdlet | <h1>How to propagate -Verbose to module functions?</h1>
<p>According to answers <a href="https://stackoverflow.com/questions/4301562/how-to-properly-use-the-verbose-and-debug-parameters-in-custom-cmdlet/20830886#20830886">like this one</a> and my own experience, Powershell can take care of propagating -Verbose (and -De... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,218 | bash | # How to propagate -Verbose to module functions?
According to answers [like this one](https://stackoverflow.com/questions/4301562/how-to-properly-use-the-verbose-and-debug-parameters-in-custom-cmdlet/20830886#20830886) and my own experience, Powershell can take care of propagating -Verbose (and -Debug) automatically, ... | The reason this is happening is because the `$VerbosePreference` is not propagated when the module is called.
I modified your script to explicitly print the value at the same points you are outputting via `Write-Verbose` and `Write-Output`.
[This powershell.org post](https://powershell.org/2014/01/13/getting-your-scri... |
42849931 | Why does `cat <(cat)` produce EIO? | 11 | 2017-03-17 05:35:22 | <p>I have a program that reads from two input files simultaneously. I'd like to have this program read from standard input. I thought I'd use something like this:</p>
<pre><code>$program1 <(cat) <($program2)
</code></pre>
<p>but I've just discovered that</p>
<pre><code>cat <(cat)
</code></pre>
<p>produces<... | 1,231 | 3,229,684 | 2019-10-10 12:56:16 | 42,851,792 | 13 | 2017-03-17 07:37:35 | 900,078 | 2018-07-05 10:41:04 | https://stackoverflow.com/q/42849931 | https://stackoverflow.com/a/42851792 | <h3>1. Explain why <code>cat <(cat)</code> produces <code>EIO</code></h3>
<p>( <em>I'm using Debian Linux 8.7, Bash 4.4.12</em> )</p>
<p>Let's replace <code><(cat)</code> with the long running <code><(sleep)</code> to see what's happening.</p>
<p>From <strong>pty #1</strong>:</p>
<pre class="lang-none pret... | <h3>1. Explain why <code>cat <(cat)</code> produces <code>EIO</code></h3> <p>( <em>I'm using Debian Linux 8.7, Bash 4.4.12</em> )</p> <p>Let's replace <code><(cat)</code> with the long running <code><(sleep)</code> to see what's happening.</p> <p>From <strong>pty #1</strong>:</p> <pre class="lang-none pret... | 345, 387, 1701, 57788, 63638 | bash, io, process-substitution, stdin, subshell | <h1>Why does `cat <(cat)` produce EIO?</h1>
<p>I have a program that reads from two input files simultaneously. I'd like to have this program read from standard input. I thought I'd use something like this:</p>
<pre><code>$program1 <(cat) <($program2)
</code></pre>
<p>but I've just discovered that</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 | 10,219 | bash | # Why does `cat <(cat)` produce EIO?
I have a program that reads from two input files simultaneously. I'd like to have this program read from standard input. I thought I'd use something like this:
```
$program1 <(cat) <($program2)
```
but I've just discovered that
```
cat <(cat)
```
produces
```
....
mmap2(NULL, ... | ### 1. Explain why `cat <(cat)` produces `EIO`
( *I'm using Debian Linux 8.7, Bash 4.4.12* )
Let's replace `<(cat)` with the long running `<(sleep)` to see what's happening.
From **pty #1**:
```
$ echo $$
906
$ tty
/dev/pts/14
$ cat <(sleep 12345)
```
Go to another **pty #2**:
```
$ ps t pts/14 j
PPID PID ... |
42822228 | Pass Secret Variable from TFS Build to Powershell script | 11 | 2017-03-15 22:53:12 | <p>I have added secret variable called Password in my build definition as shown in this image:</p>
<p><img src="https://i.sstatic.net/Zxyeb.jpg" alt="TFS Build Variables"></p>
<p>I want to pass the Password to the PowerShell script in one of my build steps as shown in this image:</p>
<p><img src="https://i.sstatic.n... | 4,898 | 1,856,918 | 2017-03-16 22:18:28 | 42,845,547 | 13 | 2017-03-16 21:59:40 | 1,856,918 | 2017-03-16 22:18:28 | https://stackoverflow.com/q/42822228 | https://stackoverflow.com/a/42845547 | <p>Finally I managed to solve it.</p>
<p>I have put double quotes around my Password when sending it via the powershell script arguments. Boom!! it started working. It sends the decrypted password.</p>
<blockquote>
<p>-UserName $(Username) -Password "$(Password)"</p>
</blockquote>
<p>My power shell script stays th... | <p>Finally I managed to solve it.</p> <p>I have put double quotes around my Password when sending it via the powershell script arguments. Boom!! it started working. It sends the decrypted password.</p> <blockquote> <p>-UserName $(Username) -Password "$(Password)"</p> </blockquote> <p>My power shell script stays th... | 526, 16341, 48063 | continuous-deployment, powershell, tfsbuild | <h1>Pass Secret Variable from TFS Build to Powershell script</h1>
<p>I have added secret variable called Password in my build definition as shown in this image:</p>
<p><img src="https://i.sstatic.net/Zxyeb.jpg" alt="TFS Build Variables"></p>
<p>I want to pass the Password to the PowerShell script in one of my build s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,220 | bash | # Pass Secret Variable from TFS Build to Powershell script
I have added secret variable called Password in my build definition as shown in this image:

I want to pass the Password to the PowerShell script in one of my build steps as shown in this image:
, it might be resolved some day though.
For now, here is how we tend to work around that.
First, load this function into memory.
```
function Failure {
$global:helpme = $body
$global:helpmoref = ... |
40292676 | Pipe command with sudo | 11 | 2016-10-27 19:23:10 | <p>I have a script which run this command successfully. I am using this command in another script which gives me error on this line (<code>.md5: Permission denied</code>).</p>
<p>I am running the previous script with sudo.</p>
<pre><code>for i in ${NAME}*
do
sudo md5sum $i | sed -e "s/$i/${NAME}/" > ${NAME}.md... | 15,063 | 6,859,937 | 2024-01-12 20:14:44 | 40,292,825 | 13 | 2016-10-27 19:32:07 | 641,955 | 2024-01-12 20:14:44 | https://stackoverflow.com/q/40292676 | https://stackoverflow.com/a/40292825 | <p>So you want to redirect output as root. It doesn't matter that you executed the command with <code>sudo</code>, because redirection is not part of the execution, so it's not performed by the executing user of the command, but by your current user.</p>
<p>The common trick is to use <code>tee</code>:</p>
<pre><code>fo... | <p>So you want to redirect output as root. It doesn't matter that you executed the command with <code>sudo</code>, because redirection is not part of the execution, so it's not performed by the executing user of the command, but by your current user.</p> <p>The common trick is to use <code>tee</code>:</p> <pre><code>fo... | 58, 387, 390, 531 | bash, linux, scripting, shell | <h1>Pipe command with sudo</h1>
<p>I have a script which run this command successfully. I am using this command in another script which gives me error on this line (<code>.md5: Permission denied</code>).</p>
<p>I am running the previous script with sudo.</p>
<pre><code>for i in ${NAME}*
do
sudo md5sum $i | sed -e... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,222 | bash | # Pipe command with sudo
I have a script which run this command successfully. I am using this command in another script which gives me error on this line (`.md5: Permission denied`).
I am running the previous script with sudo.
```
for i in ${NAME}*
do
sudo md5sum $i | sed -e "s/$i/${NAME}/" > ${NAME}.md5${i/#${N... | So you want to redirect output as root. It doesn't matter that you executed the command with `sudo`, because redirection is not part of the execution, so it's not performed by the executing user of the command, but by your current user.
The common trick is to use `tee`:
```
for i in "${NAME}"*
do
sudo md5sum "$i"... |
34027400 | NPM scripts - config variables and command substitution not working in package.json | 11 | 2015-12-01 18:24:32 | <p><strong>Case 1:</strong> variable name used instead of value</p>
<pre><code>package.json:
{
"name": "example",
"config": {
"url": "localhost/dev"
},
"scripts": {
"watch": "browser-sync start --files \"./**/*, !.node_modules/, !src\" --proxy $npm_package_config_url"
}
}
</code></pre>
<p><code>$np... | 7,651 | 5,590,570 | 2016-09-28 05:26:39 | 39,738,694 | 13 | 2016-09-28 05:26:39 | 1,015,483 | 2016-09-28 05:26:39 | https://stackoverflow.com/q/34027400 | https://stackoverflow.com/a/39738694 | <p>A bit late, but on Windows you need to use <code>%npm_package_config_url%</code></p>
<p>There's a potential package that will "fix" this for you (i.e. give you a work-around) (<a href="https://www.npmjs.com/package/cross-env" rel="noreferrer">https://www.npmjs.com/package/cross-env</a>) that was referenced in one o... | <p>A bit late, but on Windows you need to use <code>%npm_package_config_url%</code></p> <p>There's a potential package that will "fix" this for you (i.e. give you a work-around) (<a href="https://www.npmjs.com/package/cross-env" rel="noreferrer">https://www.npmjs.com/package/cross-env</a>) that was referenced in one o... | 64, 46426, 61387, 61874, 108901 | git-bash, node.js, npm, package.json, windows | <h1>NPM scripts - config variables and command substitution not working in package.json</h1>
<p><strong>Case 1:</strong> variable name used instead of value</p>
<pre><code>package.json:
{
"name": "example",
"config": {
"url": "localhost/dev"
},
"scripts": {
"watch": "browser-sync start --files \"./**/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,223 | bash | # NPM scripts - config variables and command substitution not working in package.json
**Case 1:** variable name used instead of value
```
package.json:
{
"name": "example",
"config": {
"url": "localhost/dev"
},
"scripts": {
"watch": "browser-sync start --files \"./**/*, !.node_modules/, !src\" --prox... | A bit late, but on Windows you need to use `%npm_package_config_url%`
There's a potential package that will "fix" this for you (i.e. give you a work-around) (<https://www.npmjs.com/package/cross-env>) that was referenced in one of the npm issue posts. |
39667296 | How to access a property from an object using a variable name? | 11 | 2016-09-23 18:24:10 | <p>This works:</p>
<pre><code>$psISE.Options.DebugBackgroundColor = '#FFC86400'
</code></pre>
<p>This doesn't:</p>
<pre><code>$attribute = 'DebugBackgroundColor'
($psISE.Options)[$attribute] = '#FFC86400'
</code></pre>
<blockquote>
<p>ERROR: Unable to index into an object of type Microsoft.PowerShell.Host.ISE.IS... | 10,473 | 3,143,122 | 2019-07-23 09:43:33 | 39,667,318 | 13 | 2016-09-23 18:25:19 | 1,163,423 | 2016-09-23 18:25:19 | https://stackoverflow.com/q/39667296 | https://stackoverflow.com/a/39667318 | <p>Just use double quotes after the dot:</p>
<pre><code>$attribute = 'DebugBackgroundColor'
$psISE.Options."$attribute"
</code></pre>
| <p>Just use double quotes after the dot:</p> <pre><code>$attribute = 'DebugBackgroundColor' $psISE.Options."$attribute" </code></pre> | 526, 6981, 108010 | object, powershell, powershell-5.0 | <h1>How to access a property from an object using a variable name?</h1>
<p>This works:</p>
<pre><code>$psISE.Options.DebugBackgroundColor = '#FFC86400'
</code></pre>
<p>This doesn't:</p>
<pre><code>$attribute = 'DebugBackgroundColor'
($psISE.Options)[$attribute] = '#FFC86400'
</code></pre>
<blockquote>
<p>ERROR:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,224 | bash | # How to access a property from an object using a variable name?
This works:
```
$psISE.Options.DebugBackgroundColor = '#FFC86400'
```
This doesn't:
```
$attribute = 'DebugBackgroundColor'
($psISE.Options)[$attribute] = '#FFC86400'
```
> ERROR: Unable to index into an object of type Microsoft.PowerShell.Host.ISE.... | Just use double quotes after the dot:
```
$attribute = 'DebugBackgroundColor'
$psISE.Options."$attribute"
``` |
38489158 | Use Monaco editor in web application | 11 | 2016-07-20 19:23:31 | <p>We have an MVC web application in which Powershell is used as scripting engine. Currently a textarea element is used for script editing which turns out to be very cumbersome. As Microsoft released <a href="https://github.com/Microsoft/monaco-editor" rel="noreferrer">Monaco Editor</a>, we were wondering if we could e... | 13,966 | 3,014,916 | 2021-05-12 06:06:33 | 38,511,327 | 13 | 2016-07-21 18:03:02 | 1,987,838 | 2016-07-21 18:03:02 | https://stackoverflow.com/q/38489158 | https://stackoverflow.com/a/38511327 | <p>This is a workaround to include the <code>Monarc Editor</code>on your website, it still requires files from Microsoft to works, but, it should be work if we download those files locally and modify the <code>baseUrl</code> to point to the right folder:</p>
<blockquote>
<p>Basic HTML Code</p>
</blockquote>
<pre><c... | <p>This is a workaround to include the <code>Monarc Editor</code>on your website, it still requires files from Microsoft to works, but, it should be work if we download those files locally and modify the <code>baseUrl</code> to point to the right folder:</p> <blockquote> <p>Basic HTML Code</p> </blockquote> <pre><c... | 470, 526, 120618 | asp.net-mvc, monaco-editor, powershell | <h1>Use Monaco editor in web application</h1>
<p>We have an MVC web application in which Powershell is used as scripting engine. Currently a textarea element is used for script editing which turns out to be very cumbersome. As Microsoft released <a href="https://github.com/Microsoft/monaco-editor" rel="noreferrer">Mona... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,225 | bash | # Use Monaco editor in web application
We have an MVC web application in which Powershell is used as scripting engine. Currently a textarea element is used for script editing which turns out to be very cumbersome. As Microsoft released [Monaco Editor](https://github.com/Microsoft/monaco-editor), we were wondering if w... | This is a workaround to include the `Monarc Editor`on your website, it still requires files from Microsoft to works, but, it should be work if we download those files locally and modify the `baseUrl` to point to the right folder:
> Basic HTML Code
```
<section class="try">
<div class="container">
<h3>Editor</... |
38341366 | How to specify commandline arguments in pgrep in bash? | 11 | 2016-07-13 01:42:31 | <p>I have few processes running with same name but different commandline arguments. </p>
<pre><code>$ ps -ef | grep process_name
myusername 19276 6408 0 18:12 pts/22 00.00.00 process_name 4010 127.0.0.1
myusername 23242 6369 0 18:32 pts/11 00.00.00 process_name 4010 127.0.0.2
</code></pre>
<p>How can I get the proce... | 7,285 | 1,892,348 | 2016-07-13 02:03:47 | 38,341,515 | 13 | 2016-07-13 02:03:47 | 3,030,305 | 2016-07-13 02:03:47 | https://stackoverflow.com/q/38341366 | https://stackoverflow.com/a/38341515 | <p>Use the <code>-f</code> option to match against full command line:</p>
<pre><code>pgrep -f 'process_name 4010 127.0.0.1'
</code></pre>
<p>This will also match <code>subprocess_name 4010 127.0.0.11</code>. If you want to avoid that, use <code>^</code> to anchor the match at the beginning and <code>$</code> as an a... | <p>Use the <code>-f</code> option to match against full command line:</p> <pre><code>pgrep -f 'process_name 4010 127.0.0.1' </code></pre> <p>This will also match <code>subprocess_name 4010 127.0.0.11</code>. If you want to avoid that, use <code>^</code> to anchor the match at the beginning and <code>$</code> as an a... | 387, 390, 1271, 5910 | bash, grep, process, shell | <h1>How to specify commandline arguments in pgrep in bash?</h1>
<p>I have few processes running with same name but different commandline arguments. </p>
<pre><code>$ ps -ef | grep process_name
myusername 19276 6408 0 18:12 pts/22 00.00.00 process_name 4010 127.0.0.1
myusername 23242 6369 0 18:32 pts/11 00.00.00 proce... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,226 | bash | # How to specify commandline arguments in pgrep in bash?
I have few processes running with same name but different commandline arguments.
```
$ ps -ef | grep process_name
myusername 19276 6408 0 18:12 pts/22 00.00.00 process_name 4010 127.0.0.1
myusername 23242 6369 0 18:32 pts/11 00.00.00 process_name 4010 127.0.0.... | Use the `-f` option to match against full command line:
```
pgrep -f 'process_name 4010 127.0.0.1'
```
This will also match `subprocess_name 4010 127.0.0.11`. If you want to avoid that, use `^` to anchor the match at the beginning and `$` as an anchor at the end:
```
pgrep -f '^process_name 4010 127.0.0.1$'
```
###... |
38054573 | Get current IP addresses associated with an Azure ARM VM's set of NICs via Powershell | 11 | 2016-06-27 12:55:18 | <p>I'm trying to write some Powershell to get a list of Azure ARM vms (Not classic) and the currently associated IP addresses for their NICs.</p>
<p>In classic, this was part of the VM object, but in ARM it's a seperate object, and I'm struggling to get the Powershell to work in the way I want.</p>
<p>I've got the fo... | 19,514 | 2,903,285 | 2020-10-04 19:08:58 | 38,057,839 | 13 | 2016-06-27 15:28:20 | 1,613,873 | 2016-06-27 15:28:20 | https://stackoverflow.com/q/38054573 | https://stackoverflow.com/a/38057839 | <p>I use this code to get all my ARM VMs, their private IP address and allocation method, it works across resource groups.</p>
<pre><code>$vms = get-azurermvm
$nics = get-azurermnetworkinterface | where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
$vm = $vms | where-object -Property Id ... | <p>I use this code to get all my ARM VMs, their private IP address and allocation method, it works across resource groups.</p> <pre><code>$vms = get-azurermvm $nics = get-azurermnetworkinterface | where VirtualMachine -NE $null #skip Nics with no VM foreach($nic in $nics) { $vm = $vms | where-object -Property Id ... | 526, 14158, 108005 | azure, azure-resource-manager, powershell | <h1>Get current IP addresses associated with an Azure ARM VM's set of NICs via Powershell</h1>
<p>I'm trying to write some Powershell to get a list of Azure ARM vms (Not classic) and the currently associated IP addresses for their NICs.</p>
<p>In classic, this was part of the VM object, but in ARM it's a seperate obje... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,227 | bash | # Get current IP addresses associated with an Azure ARM VM's set of NICs via Powershell
I'm trying to write some Powershell to get a list of Azure ARM vms (Not classic) and the currently associated IP addresses for their NICs.
In classic, this was part of the VM object, but in ARM it's a seperate object, and I'm stru... | I use this code to get all my ARM VMs, their private IP address and allocation method, it works across resource groups.
```
$vms = get-azurermvm
$nics = get-azurermnetworkinterface | where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
$vm = $vms | where-object -Property Id -EQ $nic.Virtu... |
37723731 | QSUB: Specify output and error files for each task in Job Array | 11 | 2016-06-09 10:44:45 | <p>Hopefully this is not a dublicate and also not just a problem of our cluster's configuration...</p>
<p>I am submitting a job array to a cluster using <code>qsub</code> with the following command:</p>
<pre><code>qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_$SGE_TASK_ID /path/to/script.sh
</code></pre>
<p>where <... | 6,061 | 6,444,230 | 2016-06-17 02:26:21 | 37,871,484 | 13 | 2016-06-17 00:49:46 | 1,716,866 | 2016-06-17 00:49:46 | https://stackoverflow.com/q/37723731 | https://stackoverflow.com/a/37871484 | <p>I didn't know this either, but it looks like Grid Engine has something called "pseudo environment variables" like <code>$TASK_ID</code> for this purpose. This should work:</p>
<pre><code>qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_\$TASK_ID /path/to/script.sh
</code></pre>
<p>From the <a href="http://gridschedu... | <p>I didn't know this either, but it looks like Grid Engine has something called "pseudo environment variables" like <code>$TASK_ID</code> for this purpose. This should work:</p> <pre><code>qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_\$TASK_ID /path/to/script.sh </code></pre> <p>From the <a href="http://gridschedu... | 387, 9228, 26217, 33581 | bash, cluster-computing, qsub, sungridengine | <h1>QSUB: Specify output and error files for each task in Job Array</h1>
<p>Hopefully this is not a dublicate and also not just a problem of our cluster's configuration...</p>
<p>I am submitting a job array to a cluster using <code>qsub</code> with the following command:</p>
<pre><code>qsub -q QUEUE -N JOBNAME -t 1:1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,228 | bash | # QSUB: Specify output and error files for each task in Job Array
Hopefully this is not a dublicate and also not just a problem of our cluster's configuration...
I am submitting a job array to a cluster using `qsub` with the following command:
```
qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_$SGE_TASK_ID /path/to/... | I didn't know this either, but it looks like Grid Engine has something called "pseudo environment variables" like `$TASK_ID` for this purpose. This should work:
```
qsub -q QUEUE -N JOBNAME -t 1:10 -e ${ERRFILE}_\$TASK_ID /path/to/script.sh
```
From the [man page](http://gridscheduler.sourceforge.net/htmlman/htmlman1... |
36910847 | How can I change the color of string values I type? | 11 | 2016-04-28 09:41:17 | <p>In my job I have recently begun using Powershell quite frequently. To facilitate using it, I am attempting to customize the command prompt colors to my liking, but I have run into a snag when attempting to customize the color of quoted string values. Given how PS is a text based interface, this statement may not m... | 7,586 | 6,265,598 | 2020-04-02 13:09:25 | 36,911,249 | 13 | 2016-04-28 09:59:37 | 712,649 | 2020-04-02 13:09:25 | https://stackoverflow.com/q/36910847 | https://stackoverflow.com/a/36911249 | <p>PowerShell 5.0 ships with <a href="https://technet.microsoft.com/en-us/library/mt560330.aspx" rel="nofollow noreferrer">PSReadLine</a>, a module that enhances the editing experience in the console by adding syntax highlight coloring among other things. </p>
<p>You can change the color of string tokens with <code>Se... | <p>PowerShell 5.0 ships with <a href="https://technet.microsoft.com/en-us/library/mt560330.aspx" rel="nofollow noreferrer">PSReadLine</a>, a module that enhances the editing experience in the console by adding syntax highlight coloring among other things. </p> <p>You can change the color of string tokens with <code>Se... | 526, 964, 9938, 107329, 108010 | command-prompt, customization, powershell, powershell-5.0, windows-10 | <h1>How can I change the color of string values I type?</h1>
<p>In my job I have recently begun using Powershell quite frequently. To facilitate using it, I am attempting to customize the command prompt colors to my liking, but I have run into a snag when attempting to customize the color of quoted string values. Giv... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,229 | bash | # How can I change the color of string values I type?
In my job I have recently begun using Powershell quite frequently. To facilitate using it, I am attempting to customize the command prompt colors to my liking, but I have run into a snag when attempting to customize the color of quoted string values. Given how PS i... | PowerShell 5.0 ships with [PSReadLine](https://technet.microsoft.com/en-us/library/mt560330.aspx), a module that enhances the editing experience in the console by adding syntax highlight coloring among other things.
You can change the color of string tokens with `Set-PSReadLineOption`, for example:
```
Set-PSReadline... |
31721221 | Disable inheritance and manually apply permissions when creating a folder in Powershell | 11 | 2015-07-30 10:24:53 | <p>Im trying to make a new folder in Powershell but I do not want it to inherit any NTFS security permissions and manually add 2 users: The creator and my own admin account.</p>
<p>I have this:</p>
<pre><code> $FolderPath = "\\srv\path"
New-Item -ItemType directory -Path $FolderPath
$acl = Get-Acl "\\srv\path"
$ac... | 46,499 | 1,070,958 | 2016-06-07 17:17:02 | 31,721,570 | 13 | 2015-07-30 10:42:22 | 712,649 | 2015-07-30 15:16:55 | https://stackoverflow.com/q/31721221 | https://stackoverflow.com/a/31721570 | <p>Use the <a href="https://msdn.microsoft.com/en-us/library/0y5xz70d(v=vs.110).aspx" rel="noreferrer"><code>SetAccessRuleProtection()</code></a> method to exclude the ACL from inheriting rules:</p>
<pre><code>$acl.SetAccessRuleProtection($true,$false)
</code></pre>
<p>The second argument (<code>preserveInheritance</... | <p>Use the <a href="https://msdn.microsoft.com/en-us/library/0y5xz70d(v=vs.110).aspx" rel="noreferrer"><code>SetAccessRuleProtection()</code></a> method to exclude the ACL from inheriting rules:</p> <pre><code>$acl.SetAccessRuleProtection($true,$false) </code></pre> <p>The second argument (<code>preserveInheritance</... | 526, 926 | inheritance, powershell | <h1>Disable inheritance and manually apply permissions when creating a folder in Powershell</h1>
<p>Im trying to make a new folder in Powershell but I do not want it to inherit any NTFS security permissions and manually add 2 users: The creator and my own admin account.</p>
<p>I have this:</p>
<pre><code> $FolderP... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,230 | bash | # Disable inheritance and manually apply permissions when creating a folder in Powershell
Im trying to make a new folder in Powershell but I do not want it to inherit any NTFS security permissions and manually add 2 users: The creator and my own admin account.
I have this:
```
$FolderPath = "\\srv\path"
New-Item... | Use the [`SetAccessRuleProtection()`](https://msdn.microsoft.com/en-us/library/0y5xz70d(v=vs.110).aspx) method to exclude the ACL from inheriting rules:
```
$acl.SetAccessRuleProtection($true,$false)
```
The second argument (`preserveInheritance`) also removes existing inherited rules when set to `false`, leaving jus... |
29562598 | Powershell with Robocopy and Arguments Passing | 11 | 2015-04-10 13:22:41 | <p>I'm trying to write a script that uses <code>robocopy</code>. If I were just doing this manually, my command would be:</p>
<pre><code>robocopy c:\hold\test1 c:\hold\test2 test.txt /NJH /NJS
</code></pre>
<p>BUT, when I do this from powershell, like:</p>
<pre><code>$source = "C:\hold\first test"
$destination = "C... | 44,031 | 81,377 | 2020-11-25 04:45:00 | 29,565,317 | 13 | 2015-04-10 15:32:33 | 4,424,236 | 2019-06-10 21:46:00 | https://stackoverflow.com/q/29562598 | https://stackoverflow.com/a/29565317 | <p>Use the arrays, Luke. If you specify an array of values, PowerShell will automatically expand them into separate parameters. In my experience, this is the most reliable method. And it doesn't require you to mess with the <code>Start-Process</code> cmdlet, which is in my opinion is overkill for such tasks.</p>
<p>Th... | <p>Use the arrays, Luke. If you specify an array of values, PowerShell will automatically expand them into separate parameters. In my experience, this is the most reliable method. And it doesn't require you to mess with the <code>Start-Process</code> cmdlet, which is in my opinion is overkill for such tasks.</p> <p>Th... | 526, 11635, 31134 | command-line-arguments, powershell, robocopy | <h1>Powershell with Robocopy and Arguments Passing</h1>
<p>I'm trying to write a script that uses <code>robocopy</code>. If I were just doing this manually, my command would be:</p>
<pre><code>robocopy c:\hold\test1 c:\hold\test2 test.txt /NJH /NJS
</code></pre>
<p>BUT, when I do this from powershell, like:</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,231 | bash | # Powershell with Robocopy and Arguments Passing
I'm trying to write a script that uses `robocopy`. If I were just doing this manually, my command would be:
```
robocopy c:\hold\test1 c:\hold\test2 test.txt /NJH /NJS
```
BUT, when I do this from powershell, like:
```
$source = "C:\hold\first test"
$destination = "C... | Use the arrays, Luke. If you specify an array of values, PowerShell will automatically expand them into separate parameters. In my experience, this is the most reliable method. And it doesn't require you to mess with the `Start-Process` cmdlet, which is in my opinion is overkill for such tasks.
This trick is from the ... |
26404845 | How to use cat in a pipe | 11 | 2014-10-16 12:46:24 | <p>I have the following command:</p>
<pre><code>httpd.conf | grep AuthUserFile | cut -d" " -f4 | sed -e 's|["'\'']||g'
</code></pre>
<p>the output of this is: </p>
<pre><code>/etc/httpd/secure/htpasswd.training
</code></pre>
<p>I did:</p>
<pre><code>httpd.conf | grep AuthUserFile | cut -d" " -f4 | sed -e 's|["'\'... | 26,399 | 3,809,938 | 2021-11-27 20:29:59 | 26,404,898 | 13 | 2014-10-16 12:48:57 | 257,418 | 2014-10-16 12:48:57 | https://stackoverflow.com/q/26404845 | https://stackoverflow.com/a/26404898 | <p>Piping to <code>xargs cat</code> will pass stdin as an argument to <code>cat</code>, printing the file.</p>
<p>Alternatively try: <code>cat $( some command printing a filename )</code>.</p>
| <p>Piping to <code>xargs cat</code> will pass stdin as an argument to <code>cat</code>, printing the file.</p> <p>Alternatively try: <code>cat $( some command printing a filename )</code>.</p> | 34, 387, 4257, 5813, 22820 | bash, cat, cut, pipe, unix | <h1>How to use cat in a pipe</h1>
<p>I have the following command:</p>
<pre><code>httpd.conf | grep AuthUserFile | cut -d" " -f4 | sed -e 's|["'\'']||g'
</code></pre>
<p>the output of this is: </p>
<pre><code>/etc/httpd/secure/htpasswd.training
</code></pre>
<p>I did:</p>
<pre><code>httpd.conf | grep AuthUserFile... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,232 | bash | # How to use cat in a pipe
I have the following command:
```
httpd.conf | grep AuthUserFile | cut -d" " -f4 | sed -e 's|["'\'']||g'
```
the output of this is:
```
/etc/httpd/secure/htpasswd.training
```
I did:
```
httpd.conf | grep AuthUserFile | cut -d" " -f4 | sed -e 's|["'\'']||g'| cat
```
However this just r... | Piping to `xargs cat` will pass stdin as an argument to `cat`, printing the file.
Alternatively try: `cat $( some command printing a filename )`. |
24054147 | PowerShell Hash Tables Double Key Error: "a" and "A" | 11 | 2014-06-05 07:26:09 | <p>from another application I have key-value pairs which I want to use in my script.<br>
But there they have e.g. the keys "a" and "A" - which causes an Error double keys aren't allowed.</p>
<pre><code> $x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" }
</code></pre>
<p>What can I do as I would need both or none... | 3,371 | 664,914 | 2023-01-04 05:45:11 | 24,054,257 | 13 | 2014-06-05 07:32:55 | 90,608 | 2023-01-04 05:45:11 | https://stackoverflow.com/q/24054147 | https://stackoverflow.com/a/24054257 | <p>By default PowerShell Hash tables are case sensitive.
Try this</p>
<pre><code>$h = new-object System.Collections.Hashtable
$h['a'] = "Entry for a"
$h['A'] = "S.th.else for A"
$h[0] = "Entry for 0"
$h[1] = "Entry for 1"
$h
</code></pre>
<p>Output for $h: (it will treat <code>a<... | <p>By default PowerShell Hash tables are case sensitive. Try this</p> <pre><code>$h = new-object System.Collections.Hashtable $h['a'] = "Entry for a" $h['A'] = "S.th.else for A" $h[0] = "Entry for 0" $h[1] = "Entry for 1" $h </code></pre> <p>Output for $h: (it will treat <code>a<... | 526, 5189 | hashtable, powershell | <h1>PowerShell Hash Tables Double Key Error: "a" and "A"</h1>
<p>from another application I have key-value pairs which I want to use in my script.<br>
But there they have e.g. the keys "a" and "A" - which causes an Error double keys aren't allowed.</p>
<pre><code> $x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,233 | bash | # PowerShell Hash Tables Double Key Error: "a" and "A"
from another application I have key-value pairs which I want to use in my script.
But there they have e.g. the keys "a" and "A" - which causes an Error double keys aren't allowed.
```
$x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" }
```
What can I do a... | By default PowerShell Hash tables are case sensitive.
Try this
```
$h = new-object System.Collections.Hashtable
$h['a'] = "Entry for a"
$h['A'] = "S.th.else for A"
$h[0] = "Entry for 0"
$h[1] = "Entry for 1"
$h
```
Output for $h: (it will treat `a` and `A` differently)
```
Name Value
---- ... |
22768021 | Different output between Powershell ToBase64String & Linux base64 | 11 | 2014-03-31 17:17:09 | <p>SGVsbG8sIHdvcmxkIQ== I have to write two scripts, one for Windows Server and another for Ubuntu Server. To illustrate, if my bash script runs:</p>
<pre><code>echo -n 'BASE64' | base64
</code></pre>
<p>the result is <code>QkFTRTY0</code>. If my PowerShell Script runs:</p>
<pre><code>[System.Convert]::ToBase64Strin... | 6,779 | 3,482,014 | 2018-04-18 08:45:42 | 22,768,654 | 13 | 2014-03-31 17:50:41 | 8,446 | 2018-04-18 08:45:42 | https://stackoverflow.com/q/22768021 | https://stackoverflow.com/a/22768654 | <p>You need to use <code>iconv</code> to convert from UTF-8 to UTF-16 without a byte order mark:</p>
<pre><code>$ echo -n 'BASE64' | iconv -f UTF8 -t UTF16LE | base64
QgBBAFMARQA2ADQA
</code></pre>
<p>The <code>UTF16LE</code> causes it to omit the BOM.</p>
<p>See <a href="https://superuser.com/q/381056/4206">https:/... | <p>You need to use <code>iconv</code> to convert from UTF-8 to UTF-16 without a byte order mark:</p> <pre><code>$ echo -n 'BASE64' | iconv -f UTF8 -t UTF16LE | base64 QgBBAFMARQA2ADQA </code></pre> <p>The <code>UTF16LE</code> causes it to omit the BOM.</p> <p>See <a href="https://superuser.com/q/381056/4206">https:/... | 8, 10, 387, 526 | bash, c, c++, powershell | <h1>Different output between Powershell ToBase64String & Linux base64</h1>
<p>SGVsbG8sIHdvcmxkIQ== I have to write two scripts, one for Windows Server and another for Ubuntu Server. To illustrate, if my bash script runs:</p>
<pre><code>echo -n 'BASE64' | base64
</code></pre>
<p>the result is <code>QkFTRTY0</code>. If... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,234 | bash | # Different output between Powershell ToBase64String & Linux base64
SGVsbG8sIHdvcmxkIQ== I have to write two scripts, one for Windows Server and another for Ubuntu Server. To illustrate, if my bash script runs:
```
echo -n 'BASE64' | base64
```
the result is `QkFTRTY0`. If my PowerShell Script runs:
```
[System.Con... | You need to use `iconv` to convert from UTF-8 to UTF-16 without a byte order mark:
```
$ echo -n 'BASE64' | iconv -f UTF8 -t UTF16LE | base64
QgBBAFMARQA2ADQA
```
The `UTF16LE` causes it to omit the BOM.
See <https://superuser.com/q/381056/4206>, where someone asks about forcibly including the BOM, but you want the ... |
22683269 | how to parse a config file (*.conf) in shell script? | 11 | 2014-03-27 09:29:14 | <p>I am new to shell script. I have a file <code>app.conf</code> as :</p>
<pre><code>[MySql]
user = root
password = root123
domain = localhost
database = db_name
port = 3306
[Logs]
level = logging.DEBUG
[Server]
port = 8080
</code></pre>
<p>I want to parse this file in shell script and want to extract mysql credent... | 19,671 | 2,745,266 | 2017-05-20 11:05:52 | 22,683,623 | 13 | 2014-03-27 09:42:52 | 2,836,621 | 2014-03-27 14:08:13 | https://stackoverflow.com/q/22683269 | https://stackoverflow.com/a/22683623 | <p>I'd do this:</p>
<pre><code>pw=$(awk '/^password/{print $3}' app.conf)
user=$(awk '/^user/{print $3}' app.conf)
echo $pw
root123
echo $user
root
</code></pre>
<p>The <code>$()</code> sets the variable <code>pw</code> to the output of the command inside. The command inside looks through your app.conf file for a... | <p>I'd do this:</p> <pre><code>pw=$(awk '/^password/{print $3}' app.conf) user=$(awk '/^user/{print $3}' app.conf) echo $pw root123 echo $user root </code></pre> <p>The <code>$()</code> sets the variable <code>pw</code> to the output of the command inside. The command inside looks through your app.conf file for a... | 390, 3107, 10327, 41898 | app-config, readfile, sh, shell | <h1>how to parse a config file (*.conf) in shell script?</h1>
<p>I am new to shell script. I have a file <code>app.conf</code> as :</p>
<pre><code>[MySql]
user = root
password = root123
domain = localhost
database = db_name
port = 3306
[Logs]
level = logging.DEBUG
[Server]
port = 8080
</code></pre>
<p>I want to par... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,235 | bash | # how to parse a config file (*.conf) in shell script?
I am new to shell script. I have a file `app.conf` as :
```
[MySql]
user = root
password = root123
domain = localhost
database = db_name
port = 3306
[Logs]
level = logging.DEBUG
[Server]
port = 8080
```
I want to parse this file in shell script and want to ext... | I'd do this:
```
pw=$(awk '/^password/{print $3}' app.conf)
user=$(awk '/^user/{print $3}' app.conf)
echo $pw
root123
echo $user
root
```
The `$()` sets the variable `pw` to the output of the command inside. The command inside looks through your app.conf file for a line starting `password` and then prints the 3rd... |
20958388 | Command line escaping single quote for PowerShell | 11 | 2014-01-06 20:10:35 | <p>I have a Windows application and on events, it calls a command like this:</p>
<pre><code>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass "G:\test.ps1 -name '%x' -data '%y'"
</code></pre>
<p>The name parameter sometimes has <code>'</code> in it. Is it possible to escape that someho... | 14,383 | 1,994,803 | 2021-04-28 18:08:51 | 20,960,618 | 13 | 2014-01-06 22:36:28 | 1,248,365 | 2014-01-08 00:46:21 | https://stackoverflow.com/q/20958388 | https://stackoverflow.com/a/20960618 | <p>This is actually a lot trickier than you'd think. Escaping nested quotes in strings passed from cmd to PowerShell is a major headache. What makes this one especially tricky is that you need to make the replacement in a variable expanded by cmd in the quoted argument passed to powershell.exe within a single-quoted ar... | <p>This is actually a lot trickier than you'd think. Escaping nested quotes in strings passed from cmd to PowerShell is a major headache. What makes this one especially tricky is that you need to make the replacement in a variable expanded by cmd in the quoted argument passed to powershell.exe within a single-quoted ar... | 526, 2631, 4804 | cmd, escaping, powershell | <h1>Command line escaping single quote for PowerShell</h1>
<p>I have a Windows application and on events, it calls a command like this:</p>
<pre><code>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass "G:\test.ps1 -name '%x' -data '%y'"
</code></pre>
<p>The name parameter sometimes has... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,236 | bash | # Command line escaping single quote for PowerShell
I have a Windows application and on events, it calls a command like this:
```
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass "G:\test.ps1 -name '%x' -data '%y'"
```
The name parameter sometimes has `'` in it. Is it possible to esc... | This is actually a lot trickier than you'd think. Escaping nested quotes in strings passed from cmd to PowerShell is a major headache. What makes this one especially tricky is that you need to make the replacement in a variable expanded by cmd in the quoted argument passed to powershell.exe within a single-quoted argum... |
19508310 | how to push folders from computer into sdcard using adb shell | 11 | 2013-10-22 03:09:44 | <p>If I have a folder structure in my computer such as A\B and the B subfolder contains 5 files, if I issue the command </p>
<pre><code>adb push c:\programs\A\*.* /sdcard/fooBar
</code></pre>
<p>it copies all the 5 files inside the B subfolder into /sdcard/fooBar<br>
How do I copy the entire subfolder B into the an... | 45,743 | 1,693,203 | 2022-06-22 02:05:46 | 19,508,348 | 13 | 2013-10-22 03:13:53 | 2,563,271 | 2017-07-24 06:25:44 | https://stackoverflow.com/q/19508310 | https://stackoverflow.com/a/19508348 | <p>Don't use <code>\*.*</code> may be ok</p>
<pre><code>adb push c:\programs\A\ /sdcard/fooBar/
</code></pre>
| <p>Don't use <code>\*.*</code> may be ok</p> <pre><code>adb push c:\programs\A\ /sdcard/fooBar/ </code></pre> | 390, 1386, 22975 | adb, android, shell | <h1>how to push folders from computer into sdcard using adb shell</h1>
<p>If I have a folder structure in my computer such as A\B and the B subfolder contains 5 files, if I issue the command </p>
<pre><code>adb push c:\programs\A\*.* /sdcard/fooBar
</code></pre>
<p>it copies all the 5 files inside the B subfolder i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,237 | bash | # how to push folders from computer into sdcard using adb shell
If I have a folder structure in my computer such as A\B and the B subfolder contains 5 files, if I issue the command
```
adb push c:\programs\A\*.* /sdcard/fooBar
```
it copies all the 5 files inside the B subfolder into /sdcard/fooBar
How do I copy t... | Don't use `\*.*` may be ok
```
adb push c:\programs\A\ /sdcard/fooBar/
``` |
17978685 | Is it possible to set multiple environment variables in one CMD line statement? | 11 | 2013-07-31 19:00:32 | <p>I have a PowerShell script set to execute after an MSBuild is finished. It uses environment variables set in the POSTBUILD section of the build process (build directories and the like.) Currently it looks like this: </p>
<pre><code> set MAGE="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools... | 23,628 | 2,370,831 | 2025-05-07 16:00:38 | 17,978,718 | 13 | 2013-07-31 19:02:06 | 1,681,283 | 2013-07-31 19:02:06 | https://stackoverflow.com/q/17978685 | https://stackoverflow.com/a/17978718 | <p>Yes, you can pipe the commands together:</p>
<pre><code>set A="hi" | set B="bye"
</code></pre>
| <p>Yes, you can pipe the commands together:</p> <pre><code>set A="hi" | set B="bye" </code></pre> | 265, 526, 2631, 14456, 40716 | cmd, msbuild, post-build, powershell, visual-studio-2010 | <h1>Is it possible to set multiple environment variables in one CMD line statement?</h1>
<p>I have a PowerShell script set to execute after an MSBuild is finished. It uses environment variables set in the POSTBUILD section of the build process (build directories and the like.) Currently it looks like this: </p>
<pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,238 | bash | # Is it possible to set multiple environment variables in one CMD line statement?
I have a PowerShell script set to execute after an MSBuild is finished. It uses environment variables set in the POSTBUILD section of the build process (build directories and the like.) Currently it looks like this:
```
set MAGE="C:\P... | Yes, you can pipe the commands together:
```
set A="hi" | set B="bye"
``` |
17509757 | Quick search of command options in bash | 11 | 2013-07-07 06:15:19 | <p>I found myself in a situation where I constantly look for parameters of a command in bash. For instance, <code>find -type f -name '*py' -print0</code>. In order to find all of those I need to go through man,info, or --help option which is laborious and time consuming. Is there any way to make this search instant. Id... | 6,352 | 2,069,858 | 2016-06-09 02:44:14 | 17,509,988 | 13 | 2013-07-07 07:03:24 | 2,557,629 | 2016-06-09 02:44:14 | https://stackoverflow.com/q/17509757 | https://stackoverflow.com/a/17509988 | <p>If your man pages open in <code>less</code> you can use <code>/</code> to search over it.</p>
<p><code>man find</code></p>
<p><kbd>/</kbd><code>-type</code></p>
<p><kbd>n</kbd>, for next search</p>
<p><kbd>N</kbd> for previous search</p>
| <p>If your man pages open in <code>less</code> you can use <code>/</code> to search over it.</p> <p><code>man find</code></p> <p><kbd>/</kbd><code>-type</code></p> <p><kbd>n</kbd>, for next search</p> <p><kbd>N</kbd> for previous search</p> | 387, 9524 | bash, manpage | <h1>Quick search of command options in bash</h1>
<p>I found myself in a situation where I constantly look for parameters of a command in bash. For instance, <code>find -type f -name '*py' -print0</code>. In order to find all of those I need to go through man,info, or --help option which is laborious and time consuming.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,239 | bash | # Quick search of command options in bash
I found myself in a situation where I constantly look for parameters of a command in bash. For instance, `find -type f -name '*py' -print0`. In order to find all of those I need to go through man,info, or --help option which is laborious and time consuming. Is there any way to... | If your man pages open in `less` you can use `/` to search over it.
`man find`
`/``-type`
`n`, for next search
`N` for previous search |
15580523 | Powershell Secure password to work on any machine | 11 | 2013-03-22 21:58:40 | <p>I need to write a powershell script that i can run on any machine to connect to a server.
Does the secure-string encrypt using the machine or user i.e will a secure password work on any machine in the domain or can it only be decrypted on the machine it was created on. If it is the latter is there away to encrypt t... | 20,506 | 1,221,996 | 2025-03-14 09:54:46 | 15,581,334 | 13 | 2013-03-22 23:16:14 | 251,123 | 2013-03-22 23:16:14 | https://stackoverflow.com/q/15580523 | https://stackoverflow.com/a/15581334 | <p>To work on other machines you'll need to create a key for use with the ConvertTo-SecureString and ConvertFrom-SecureString cmdlets. </p>
<pre><code>PS C:\> $Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43)
PS C:\>$StandardString = ConvertFrom-SecureString $SecureString -Key $Key
</code>... | <p>To work on other machines you'll need to create a key for use with the ConvertTo-SecureString and ConvertFrom-SecureString cmdlets. </p> <pre><code>PS C:\> $Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43) PS C:\>$StandardString = ConvertFrom-SecureString $SecureString -Key $Key </code>... | 220, 526 | passwords, powershell | <h1>Powershell Secure password to work on any machine</h1>
<p>I need to write a powershell script that i can run on any machine to connect to a server.
Does the secure-string encrypt using the machine or user i.e will a secure password work on any machine in the domain or can it only be decrypted on the machine it was ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,240 | bash | # Powershell Secure password to work on any machine
I need to write a powershell script that i can run on any machine to connect to a server.
Does the secure-string encrypt using the machine or user i.e will a secure password work on any machine in the domain or can it only be decrypted on the machine it was created o... | To work on other machines you'll need to create a key for use with the ConvertTo-SecureString and ConvertFrom-SecureString cmdlets.
```
PS C:\> $Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43)
PS C:\>$StandardString = ConvertFrom-SecureString $SecureString -Key $Key
```
<http://www.leeholmes.c... |
13790763 | Bash RegEx to check floating point numbers from user input | 11 | 2012-12-09 19:11:24 | <p>I'm relatively new to bash programming and i am currently creating a simple calculator.</p>
<p>It needs to use floating point numbers and check they are so.</p>
<p>I have a checkNumbers function:</p>
<pre><code>function checkNumber {
regExp=[0-9]
if [ $testNo =~ $regExp ]
then
echo "That is ... | 13,435 | 1,889,924 | 2021-07-21 03:50:23 | 13,790,836 | 13 | 2012-12-09 19:21:02 | 1,066,031 | 2012-12-09 20:17:42 | https://stackoverflow.com/q/13790763 | https://stackoverflow.com/a/13790836 | <p>This regex <code>^[-+]?[0-9]+\.?[0-9]*$</code> will match only digits with an optional <code>.</code>:</p>
<pre><code>$ echo 30 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match
Match
$ echo 30.10 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match
Match
$ echo 30. | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$... | <p>This regex <code>^[-+]?[0-9]+\.?[0-9]*$</code> will match only digits with an optional <code>.</code>:</p> <pre><code>$ echo 30 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match Match $ echo 30.10 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match Match $ echo 30. | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$... | 18, 387, 2095, 29051 | bash, bash4, expression, regex | <h1>Bash RegEx to check floating point numbers from user input</h1>
<p>I'm relatively new to bash programming and i am currently creating a simple calculator.</p>
<p>It needs to use floating point numbers and check they are so.</p>
<p>I have a checkNumbers function:</p>
<pre><code>function checkNumber {
regExp=... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,241 | bash | # Bash RegEx to check floating point numbers from user input
I'm relatively new to bash programming and i am currently creating a simple calculator.
It needs to use floating point numbers and check they are so.
I have a checkNumbers function:
```
function checkNumber {
regExp=[0-9]
if [ $testNo =~ $regExp... | This regex `^[-+]?[0-9]+\.?[0-9]*$` will match only digits with an optional `.`:
```
$ echo 30 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match
Match
$ echo 30.10 | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match
Match
$ echo 30. | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' && echo Match
Match
$ echo +30 | grep -Eq '^[-+]?... |
12898945 | Using placeholders/variables in a sed command | 11 | 2012-10-15 15:30:14 | <p>I want to store a specific part of a matched result as a variable to be used for replacement later. I would like to keep this in a one liner instead of finding the variable I need before hand.</p>
<p>when configuring apache, and use mod_rewrite, you can specificy specific parts of patterns to be used as variables,l... | 19,456 | 608,725 | 2019-10-07 14:08:59 | 12,899,106 | 13 | 2012-10-15 15:39:20 | 15,168 | 2012-10-15 15:39:20 | https://stackoverflow.com/q/12898945 | https://stackoverflow.com/a/12899106 | <pre><code>sed '/CREATE TABLE \([^ ]*\)/ s//DROP TABLE IF EXISTS \1; &/'
</code></pre>
<p>Find a CREATE TABLE statement and capture the table name. Replace it with 'DROP TABLE IF EXISTS' and the table name, plus a semi-colon to terminate the statement, and a copy of what was matched to preserve the CREATE TABLE s... | <pre><code>sed '/CREATE TABLE \([^ ]*\)/ s//DROP TABLE IF EXISTS \1; &/' </code></pre> <p>Find a CREATE TABLE statement and capture the table name. Replace it with 'DROP TABLE IF EXISTS' and the table name, plus a semi-colon to terminate the statement, and a copy of what was matched to preserve the CREATE TABLE s... | 387, 990, 5282 | awk, bash, sed | <h1>Using placeholders/variables in a sed command</h1>
<p>I want to store a specific part of a matched result as a variable to be used for replacement later. I would like to keep this in a one liner instead of finding the variable I need before hand.</p>
<p>when configuring apache, and use mod_rewrite, you can specifi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,242 | bash | # Using placeholders/variables in a sed command
I want to store a specific part of a matched result as a variable to be used for replacement later. I would like to keep this in a one liner instead of finding the variable I need before hand.
when configuring apache, and use mod_rewrite, you can specificy specific part... | ```
sed '/CREATE TABLE \([^ ]*\)/ s//DROP TABLE IF EXISTS \1; &/'
```
Find a CREATE TABLE statement and capture the table name. Replace it with 'DROP TABLE IF EXISTS' and the table name, plus a semi-colon to terminate the statement, and a copy of what was matched to preserve the CREATE TABLE statement.
This is classi... |
12682715 | Grep Print Only After Match | 11 | 2012-10-01 23:54:55 | <p>I used <code>grep</code> that outputs a list like this</p>
<pre><code>/player/ABc12
/player/ABC321
/player/EGF987
/player/egf751
</code></pre>
<p>However I want to only give the name of the players such <code>ABC321</code>, <code>EFG987</code>, etc...</p>
| 42,417 | 1,709,294 | 2012-10-02 09:59:38 | 12,683,014 | 13 | 2012-10-02 00:31:30 | 836,738 | 2012-10-02 00:31:30 | https://stackoverflow.com/q/12682715 | https://stackoverflow.com/a/12683014 | <p>@sputnick has the right idea with <code>grep</code>, and something like that would actually be my preferred solution. I personally immediately thought of a positive lookbehind:</p>
<pre><code>grep -oP '(?<=/player/)\w+' file
</code></pre>
<p>But the <code>\K</code> works perfectly fine as well.</p>
<p>An alte... | <p>@sputnick has the right idea with <code>grep</code>, and something like that would actually be my preferred solution. I personally immediately thought of a positive lookbehind:</p> <pre><code>grep -oP '(?<=/player/)\w+' file </code></pre> <p>But the <code>\K</code> works perfectly fine as well.</p> <p>An alte... | 387, 1271 | bash, grep | <h1>Grep Print Only After Match</h1>
<p>I used <code>grep</code> that outputs a list like this</p>
<pre><code>/player/ABc12
/player/ABC321
/player/EGF987
/player/egf751
</code></pre>
<p>However I want to only give the name of the players such <code>ABC321</code>, <code>EFG987</code>, etc...</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,243 | bash | # Grep Print Only After Match
I used `grep` that outputs a list like this
```
/player/ABc12
/player/ABC321
/player/EGF987
/player/egf751
```
However I want to only give the name of the players such `ABC321`, `EFG987`, etc... | @sputnick has the right idea with `grep`, and something like that would actually be my preferred solution. I personally immediately thought of a positive lookbehind:
```
grep -oP '(?<=/player/)\w+' file
```
But the `\K` works perfectly fine as well.
An alternative (somewhat shorter) solution is with `sed`:
```
sed ... |
11209509 | Using PHP to execute cmd commands | 11 | 2012-06-26 14:23:22 | <p>How do I properly execute commands in the command line using php? For example I'm using the command below in the command line to convert a docx file into a pdf file:</p>
<pre><code>pdfcreator.exe /PF"D:\Documents\sample.docx
</code></pre>
<p>Now using PHP code I want to be able to execute the same command but noth... | 64,666 | 472,034 | 2025-09-04 03:48:54 | 11,209,592 | 13 | 2012-06-26 14:27:03 | 1,087,407 | 2012-06-26 14:27:03 | https://stackoverflow.com/q/11209509 | https://stackoverflow.com/a/11209592 | <pre><code>system("c:\\path\\to\\pdfcreator.exe /PF\"D:\\Documents\\sample.docx"");
</code></pre>
<p>try this.</p>
| <pre><code>system("c:\\path\\to\\pdfcreator.exe /PF\"D:\\Documents\\sample.docx""); </code></pre> <p>try this.</p> | 5, 2631, 8646 | cmd, php, shell-exec | <h1>Using PHP to execute cmd commands</h1>
<p>How do I properly execute commands in the command line using php? For example I'm using the command below in the command line to convert a docx file into a pdf file:</p>
<pre><code>pdfcreator.exe /PF"D:\Documents\sample.docx
</code></pre>
<p>Now using PHP code I want to b... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,244 | bash | # Using PHP to execute cmd commands
How do I properly execute commands in the command line using php? For example I'm using the command below in the command line to convert a docx file into a pdf file:
```
pdfcreator.exe /PF"D:\Documents\sample.docx
```
Now using PHP code I want to be able to execute the same comman... | ```
system("c:\\path\\to\\pdfcreator.exe /PF\"D:\\Documents\\sample.docx"");
```
try this. |
9510362 | Bash nested quotes and eval | 11 | 2012-03-01 03:49:06 | <p>I'm having difficulty nested quotes within a bash script</p>
<pre><code>argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web"
eval $argv
</code></pre>
<p>The above got me</p>
<pre><code>eval: line 162: unexpected EOF while looking for matching `''
eval: line 163: syntax error: ... | 17,185 | 550,672 | 2018-09-29 05:48:23 | 9,510,560 | 13 | 2012-03-01 04:19:56 | 550,672 | 2012-03-01 04:19:56 | https://stackoverflow.com/q/9510362 | https://stackoverflow.com/a/9510560 | <pre><code>argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web"
</code></pre>
| <pre><code>argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web" </code></pre> | 387, 430, 3610, 4413 | bash, eval, nested, quotes | <h1>Bash nested quotes and eval</h1>
<p>I'm having difficulty nested quotes within a bash script</p>
<pre><code>argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web"
eval $argv
</code></pre>
<p>The above got me</p>
<pre><code>eval: line 162: unexpected EOF while looking for matchi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,245 | bash | # Bash nested quotes and eval
I'm having difficulty nested quotes within a bash script
```
argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web"
eval $argv
```
The above got me
```
eval: line 162: unexpected EOF while looking for matching `''
eval: line 163: syntax error: unexpec... | ```
argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web"
``` |
9429685 | Is it OK to pass a null window handle to ShellExecute? | 11 | 2012-02-24 11:07:15 | <p>I have a Delphi console application that at the end needs to launch one of two applications.</p>
<p>I'm having some problems getting ShellExecute to work without erroring, and I think the problem is associated with not having a handle for the console applicaiton.</p>
<p>The line that is causing me grief is:</p>
<... | 8,121 | 78,334 | 2013-11-06 20:05:12 | 9,429,727 | 13 | 2012-02-24 11:09:46 | 505,088 | 2012-02-24 11:09:46 | https://stackoverflow.com/q/9429685 | https://stackoverflow.com/a/9429727 | <p>Passing 0 for the <code>hwnd</code> parameter is fine. The <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153.aspx" rel="noreferrer">documentation</a> describes the parameter thus:</p>
<blockquote>
<p>A handle to the parent window used for displaying a UI or error messages. This value can b... | <p>Passing 0 for the <code>hwnd</code> parameter is fine. The <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153.aspx" rel="noreferrer">documentation</a> describes the parameter thus:</p> <blockquote> <p>A handle to the parent window used for displaying a UI or error messages. This value can b... | 118, 488, 7839, 35034 | console, delphi, delphi-2010, shellexecute | <h1>Is it OK to pass a null window handle to ShellExecute?</h1>
<p>I have a Delphi console application that at the end needs to launch one of two applications.</p>
<p>I'm having some problems getting ShellExecute to work without erroring, and I think the problem is associated with not having a handle for the console a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,246 | bash | # Is it OK to pass a null window handle to ShellExecute?
I have a Delphi console application that at the end needs to launch one of two applications.
I'm having some problems getting ShellExecute to work without erroring, and I think the problem is associated with not having a handle for the console applicaiton.
The... | Passing 0 for the `hwnd` parameter is fine. The [documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153.aspx) describes the parameter thus:
> A handle to the parent window used for displaying a UI or error messages. This value can be NULL if the operation is not associated with a window.
Your... |
8631990 | How can I delete contents in a folder using a bash script? | 11 | 2011-12-25 22:54:06 | <p>I would like to clear out my /bin folder in my project directory. How can I do this?</p>
<p>I tried <code>rm -rf ~/bin</code> but no luck</p>
| 31,028 | 19,875 | 2024-04-09 13:03:52 | 8,632,015 | 13 | 2011-12-25 23:00:39 | 1,093,528 | 2011-12-25 23:00:39 | https://stackoverflow.com/q/8631990 | https://stackoverflow.com/a/8632015 | <p>You should say "... my bin folder", not "my /bin folder". <code>/bin</code> is an absolute path, <code>bin</code> is a relative path.</p>
<p><code>rm -rf ~/bin</code> removes <code>$HOME/bin</code>, so not what you want either.</p>
<p>Now, it depends on where you are: if you are in your project directory when you... | <p>You should say "... my bin folder", not "my /bin folder". <code>/bin</code> is an absolute path, <code>bin</code> is a relative path.</p> <p><code>rm -rf ~/bin</code> removes <code>$HOME/bin</code>, so not what you want either.</p> <p>Now, it depends on where you are: if you are in your project directory when you... | 34, 387, 390, 391, 531 | bash, scripting, shell, terminal, unix | <h1>How can I delete contents in a folder using a bash script?</h1>
<p>I would like to clear out my /bin folder in my project directory. How can I do this?</p>
<p>I tried <code>rm -rf ~/bin</code> but no luck</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,247 | bash | # How can I delete contents in a folder using a bash script?
I would like to clear out my /bin folder in my project directory. How can I do this?
I tried `rm -rf ~/bin` but no luck | You should say "... my bin folder", not "my /bin folder". `/bin` is an absolute path, `bin` is a relative path.
`rm -rf ~/bin` removes `$HOME/bin`, so not what you want either.
Now, it depends on where you are: if you are in your project directory when you type the command, just type `rm -rf bin`. |
7296288 | PHP shell_exec wait for script to finish? | 11 | 2011-09-03 22:36:56 | <p>I have a PHP script that queries a database for a list of jobs to be done and fires off other PHP scripts based on what it finds in the database (basically a process queue). </p>
<p>Some of the scripts that the queue runner script executes may take 30 seconds or so to finish running (generating PDFs, resizing image... | 21,635 | 604,664 | 2011-09-04 01:19:41 | 7,296,856 | 13 | 2011-09-04 01:19:41 | 905,093 | 2011-09-04 01:19:41 | https://stackoverflow.com/q/7296288 | https://stackoverflow.com/a/7296856 | <p>Try this:</p>
<pre><code>shell_exec("nohup /usr/bin/htmldoc -t pdf --webpage test.html > test.pdf 2>&1 &");
</code></pre>
| <p>Try this:</p> <pre><code>shell_exec("nohup /usr/bin/htmldoc -t pdf --webpage test.html > test.pdf 2>&1 &"); </code></pre> | 5, 342, 8646 | php, queue, shell-exec | <h1>PHP shell_exec wait for script to finish?</h1>
<p>I have a PHP script that queries a database for a list of jobs to be done and fires off other PHP scripts based on what it finds in the database (basically a process queue). </p>
<p>Some of the scripts that the queue runner script executes may take 30 seconds or so... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,248 | bash | # PHP shell_exec wait for script to finish?
I have a PHP script that queries a database for a list of jobs to be done and fires off other PHP scripts based on what it finds in the database (basically a process queue).
Some of the scripts that the queue runner script executes may take 30 seconds or so to finish runnin... | Try this:
```
shell_exec("nohup /usr/bin/htmldoc -t pdf --webpage test.html > test.pdf 2>&1 &");
``` |
6268713 | How can I scp a file and run an ssh command asking for password only once? | 11 | 2011-06-07 16:47:11 | <p>Here's the context of the question:</p>
<p>In order for me to be able to print documents at work, I have to copy the file over to a different computer and then print from that computer. (Don't ask. It's complicated and there is not another viable solution.) Both of the computers are Linux and I work in bash. The... | 9,118 | 558,820 | 2018-08-27 07:16:59 | 6,268,770 | 13 | 2011-06-07 16:51:44 | 358,679 | 2012-11-07 20:59:20 | https://stackoverflow.com/q/6268713 | https://stackoverflow.com/a/6268770 | <pre><code>ssh user@host 'cat - > /tmp/file.ext; do_something_with /tmp/file.ext;rm /tmp/file.ext' < file.ext
</code></pre>
<p>Another option would be to just leave an ssh tunnel open:</p>
<p>In ~/.ssh/config:</p>
<pre><code>Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/ssh-socket-%r-%... | <pre><code>ssh user@host 'cat - > /tmp/file.ext; do_something_with /tmp/file.ext;rm /tmp/file.ext' < file.ext </code></pre> <p>Another option would be to just leave an ssh tunnel open:</p> <p>In ~/.ssh/config:</p> <pre><code>Host * ControlMaster auto ControlPath ~/.ssh/sockets/ssh-socket-%r-%... | 58, 386, 387, 3149 | bash, linux, scp, ssh | <h1>How can I scp a file and run an ssh command asking for password only once?</h1>
<p>Here's the context of the question:</p>
<p>In order for me to be able to print documents at work, I have to copy the file over to a different computer and then print from that computer. (Don't ask. It's complicated and there is not... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,249 | bash | # How can I scp a file and run an ssh command asking for password only once?
Here's the context of the question:
In order for me to be able to print documents at work, I have to copy the file over to a different computer and then print from that computer. (Don't ask. It's complicated and there is not another viable s... | ```
ssh user@host 'cat - > /tmp/file.ext; do_something_with /tmp/file.ext;rm /tmp/file.ext' < file.ext
```
Another option would be to just leave an ssh tunnel open:
In ~/.ssh/config:
```
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/ssh-socket-%r-%h-%p
```
.
```
$ ssh -f -N -l user host
(soc... |
6141088 | Append a text to the top of a file | 11 | 2011-05-26 15:27:52 | <p>I want to add a text on the top of my data.txt file, this code add the text at the end of the file. how I can modify this code to write the text on the top of my data.txt file. thanks in advance for any assistance.</p>
<pre><code>open (MYFILE, '>>data.txt');
print MYFILE "Title\n";
close (MYFILE)
</code></pr... | 17,540 | 654,065 | 2024-07-09 20:06:39 | 6,146,794 | 13 | 2011-05-27 01:10:35 | 579,432 | 2011-05-27 01:10:35 | https://stackoverflow.com/q/6141088 | https://stackoverflow.com/a/6146794 | <pre><code> perl -pi -e 'print "Title\n" if $. == 1' data.text
</code></pre>
| <pre><code> perl -pi -e 'print "Title\n" if $. == 1' data.text </code></pre> | 390, 580 | perl, shell | <h1>Append a text to the top of a file</h1>
<p>I want to add a text on the top of my data.txt file, this code add the text at the end of the file. how I can modify this code to write the text on the top of my data.txt file. thanks in advance for any assistance.</p>
<pre><code>open (MYFILE, '>>data.txt');
print ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,250 | bash | # Append a text to the top of a file
I want to add a text on the top of my data.txt file, this code add the text at the end of the file. how I can modify this code to write the text on the top of my data.txt file. thanks in advance for any assistance.
```
open (MYFILE, '>>data.txt');
print MYFILE "Title\n";
close (MY... | ```
perl -pi -e 'print "Title\n" if $. == 1' data.text
``` |
3335431 | List files with absolute path recursive in linux | 11 | 2010-07-26 13:53:26 | <p>This question is quite similar to <a href="https://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux">How can I list files with their absolute path in linux?</a></p>
<p>I want to get the name of file or folder with absolute path and date modified.</p>
<p>This command almost ... | 29,018 | 402,329 | 2016-02-24 23:24:14 | 3,335,474 | 13 | 2010-07-26 13:58:02 | 131,527 | 2016-02-24 23:24:14 | https://stackoverflow.com/q/3335431 | https://stackoverflow.com/a/3335474 | <p>Check out the <code>find</code> command and its <code>printf</code> option.</p>
<pre><code>find /foo/bar -printf "%p %A@"
</code></pre>
<p>See the man page of <code>find</code> for more information.</p>
| <p>Check out the <code>find</code> command and its <code>printf</code> option.</p> <pre><code>find /foo/bar -printf "%p %A@" </code></pre> <p>See the man page of <code>find</code> for more information.</p> | 58, 387 | bash, linux | <h1>List files with absolute path recursive in linux</h1>
<p>This question is quite similar to <a href="https://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux">How can I list files with their absolute path in linux?</a></p>
<p>I want to get the name of file or folder with abs... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,251 | bash | # List files with absolute path recursive in linux
This question is quite similar to [How can I list files with their absolute path in linux?](https://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux)
I want to get the name of file or folder with absolute path and date modifie... | Check out the `find` command and its `printf` option.
```
find /foo/bar -printf "%p %A@"
```
See the man page of `find` for more information. |
3088556 | testing command line utilities | 11 | 2010-06-21 21:12:09 | <p>I'm looking for a way to run tests on command-line utilities written in bash, or any other language.</p>
<p>I'd like to find a testing framework that would have statements like</p>
<pre><code>setup:
command = 'do_awesome_thing'
filename = 'testfile'
args = ['--with', 'extra_win', '--file', filename]
... | 4,564 | 192,812 | 2015-01-28 15:51:24 | 3,090,460 | 13 | 2010-06-22 05:16:40 | 303,070 | 2010-06-22 05:16:40 | https://stackoverflow.com/q/3088556 | https://stackoverflow.com/a/3090460 | <p>Check out <a href="http://pythonpaste.org/scripttest/" rel="noreferrer">ScriptTest</a> :</p>
<pre><code>from scripttest import TestFileEnvironment
env = TestFileEnvironment('./scratch')
def test_script():
env.reset()
result = env.run('do_awesome_thing testfile --with extra_win --file %s' % filename)
#... | <p>Check out <a href="http://pythonpaste.org/scripttest/" rel="noreferrer">ScriptTest</a> :</p> <pre><code>from scripttest import TestFileEnvironment env = TestFileEnvironment('./scratch') def test_script(): env.reset() result = env.run('do_awesome_thing testfile --with extra_win --file %s' % filename) #... | 16, 33, 186, 387, 1231 | bash, command-line, language-agnostic, python, testing | <h1>testing command line utilities</h1>
<p>I'm looking for a way to run tests on command-line utilities written in bash, or any other language.</p>
<p>I'd like to find a testing framework that would have statements like</p>
<pre><code>setup:
command = 'do_awesome_thing'
filename = 'testfile'
args = ['--wi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,252 | bash | # testing command line utilities
I'm looking for a way to run tests on command-line utilities written in bash, or any other language.
I'd like to find a testing framework that would have statements like
```
setup:
command = 'do_awesome_thing'
filename = 'testfile'
args = ['--with', 'extra_win', '--file',... | Check out [ScriptTest](http://pythonpaste.org/scripttest/) :
```
from scripttest import TestFileEnvironment
env = TestFileEnvironment('./scratch')
def test_script():
env.reset()
result = env.run('do_awesome_thing testfile --with extra_win --file %s' % filename)
# or use a list like ['do_awesome_thing', '... |
2731868 | Powershell: align right for a column value from Select-Object in Format-Table format | 11 | 2010-04-28 17:42:47 | <p>I have the following array value $outData with several columns. I am not sure how I align some columns right?</p>
<pre><code>$outData | Select-Object `
Name `
@{Name="Freespace(byte)"; Expression={"{0:N0}" -f $_.FreeSpace}}, '
.... # other colums `
| Format-Table -AutoSize
</code></pre>
<p>It wo... | 31,496 | 62,776 | 2018-11-15 22:12:12 | 2,731,933 | 13 | 2010-04-28 17:53:05 | 153,982 | 2010-04-28 20:17:12 | https://stackoverflow.com/q/2731868 | https://stackoverflow.com/a/2731933 | <p>The align directive goes in a hashtable that is specified to the Format-Table cmdlet. IOW, align is not a supported hashtable entry for Select-Object. So make sure to do your formatting via hashtables in the hashtable passed to Format-Table e.g.:</p>
<pre><code>gps | select name,pm | format-table @{n='Name';e={$_... | <p>The align directive goes in a hashtable that is specified to the Format-Table cmdlet. IOW, align is not a supported hashtable entry for Select-Object. So make sure to do your formatting via hashtables in the hashtable passed to Format-Table e.g.:</p> <pre><code>gps | select name,pm | format-table @{n='Name';e={$_... | 526 | powershell | <h1>Powershell: align right for a column value from Select-Object in Format-Table format</h1>
<p>I have the following array value $outData with several columns. I am not sure how I align some columns right?</p>
<pre><code>$outData | Select-Object `
Name `
@{Name="Freespace(byte)"; Expression={"{0:N0}" -f $... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,253 | bash | # Powershell: align right for a column value from Select-Object in Format-Table format
I have the following array value $outData with several columns. I am not sure how I align some columns right?
```
$outData | Select-Object `
Name `
@{Name="Freespace(byte)"; Expression={"{0:N0}" -f $_.FreeSpace}}, '
... | The align directive goes in a hashtable that is specified to the Format-Table cmdlet. IOW, align is not a supported hashtable entry for Select-Object. So make sure to do your formatting via hashtables in the hashtable passed to Format-Table e.g.:
```
gps | select name,pm | format-table @{n='Name';e={$_.Name};align='ri... |
2645174 | 'echo' newline suppression | 11 | 2010-04-15 12:30:47 | <p>Why doesn't <code>$echo '-n'</code> write <code>-n</code> on terminal although <code>-n</code> is written within single quotes?</p>
| 31,890 | 317,283 | 2021-11-05 16:48:43 | 2,645,212 | 13 | 2010-04-15 12:36:14 | 101,361 | 2010-04-15 12:36:14 | https://stackoverflow.com/q/2645174 | https://stackoverflow.com/a/2645212 | <p>Because the quotes are processed by the shell and the <code>echo</code> command receives plain <code>-n</code>. If you want to echo <code>-n</code>, you can e.g. <code>printf '%s\n' -n</code></p>
| <p>Because the quotes are processed by the shell and the <code>echo</code> command receives plain <code>-n</code>. If you want to echo <code>-n</code>, you can e.g. <code>printf '%s\n' -n</code></p> | 387, 531, 3705, 13824 | bash, echo, newline, scripting | <h1>'echo' newline suppression</h1>
<p>Why doesn't <code>$echo '-n'</code> write <code>-n</code> on terminal although <code>-n</code> is written within single quotes?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,254 | bash | # 'echo' newline suppression
Why doesn't `$echo '-n'` write `-n` on terminal although `-n` is written within single quotes? | Because the quotes are processed by the shell and the `echo` command receives plain `-n`. If you want to echo `-n`, you can e.g. `printf '%s\n' -n` |
2295361 | Is it possible to do a grep with keywords stored in the array? | 11 | 2010-02-19 09:57:29 | <p>Is it possible to do a grep with keywords stored in the array.</p>
<p>Here is the possible code snippet; how can I correct it?</p>
<pre><code>args=("key1" "key2" "key3")
cat file_name |while read line
echo $line | grep -q -w ${args[c]}
done
</code></pre>
<p>At the moment, I can search... | 21,585 | 276,859 | 2022-08-23 12:07:50 | 2,295,565 | 13 | 2010-02-19 10:28:39 | 131,527 | 2010-02-19 10:38:28 | https://stackoverflow.com/q/2295361 | https://stackoverflow.com/a/2295565 | <pre><code>args=("key1" "key2" "key3")
pat=$(echo ${args[@]}|tr " " "|")
grep -Eow "$pat" file
</code></pre>
<p>Or with the shell</p>
<pre><code>args=("key1" "key2" "key3")
while read -r line
do
for i in ${args[@]}
do
case "$line" in
*"$i"*) echo "found: $line";;
esac
done
done... | <pre><code>args=("key1" "key2" "key3") pat=$(echo ${args[@]}|tr " " "|") grep -Eow "$pat" file </code></pre> <p>Or with the shell</p> <pre><code>args=("key1" "key2" "key3") while read -r line do for i in ${args[@]} do case "$line" in *"$i"*) echo "found: $line";; esac done done... | 387, 390, 1271 | bash, grep, shell | <h1>Is it possible to do a grep with keywords stored in the array?</h1>
<p>Is it possible to do a grep with keywords stored in the array.</p>
<p>Here is the possible code snippet; how can I correct it?</p>
<pre><code>args=("key1" "key2" "key3")
cat file_name |while read line
echo $line |... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,255 | bash | # Is it possible to do a grep with keywords stored in the array?
Is it possible to do a grep with keywords stored in the array.
Here is the possible code snippet; how can I correct it?
```
args=("key1" "key2" "key3")
cat file_name |while read line
echo $line | grep -q -w ${args[c]}
done
```
At the moment, I can s... | ```
args=("key1" "key2" "key3")
pat=$(echo ${args[@]}|tr " " "|")
grep -Eow "$pat" file
```
Or with the shell
```
args=("key1" "key2" "key3")
while read -r line
do
for i in ${args[@]}
do
case "$line" in
*"$i"*) echo "found: $line";;
esac
done
done <"file"
``` |
970308 | Users and Local Groups Report using Powershell? | 11 | 2009-06-09 14:12:22 | <p>Is there a simple way using powershell to show all Local Windows Groups that are active on a machine and the users that are part of those groups? A second part of this question would be if it can be extended to look at more than one machine at a time.</p>
| 26,855 | null | 2016-04-17 23:06:33 | 972,517 | 13 | 2009-06-09 21:07:57 | 9,833 | 2009-06-11 09:08:20 | https://stackoverflow.com/q/970308 | https://stackoverflow.com/a/972517 | <p>In fact you can with the ADSI type shortcut and the WinNT moniker. Here's an example to list groups and members from your own machine:</p>
<pre><code>$server="."
$computer = [ADSI]"WinNT://$server,computer"
$computer.psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach {
write-host $_.na... | <p>In fact you can with the ADSI type shortcut and the WinNT moniker. Here's an example to list groups and members from your own machine:</p> <pre><code>$server="." $computer = [ADSI]"WinNT://$server,computer" $computer.psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach { write-host $_.na... | 64, 136, 526 | powershell, security, windows | <h1>Users and Local Groups Report using Powershell?</h1>
<p>Is there a simple way using powershell to show all Local Windows Groups that are active on a machine and the users that are part of those groups? A second part of this question would be if it can be extended to look at more than one machine at a time.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,256 | bash | # Users and Local Groups Report using Powershell?
Is there a simple way using powershell to show all Local Windows Groups that are active on a machine and the users that are part of those groups? A second part of this question would be if it can be extended to look at more than one machine at a time. | In fact you can with the ADSI type shortcut and the WinNT moniker. Here's an example to list groups and members from your own machine:
```
$server="."
$computer = [ADSI]"WinNT://$server,computer"
$computer.psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach {
write-host $_.name
write-h... |
320313 | echo "-e" doesn't print anything | 11 | 2008-11-26 11:03:22 | <p>I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:</p>
<pre><code>echo "-e"
</code></pre>
<p>doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty strings.</... | 13,420 | 15,647 | 2013-07-08 12:26:45 | 320,328 | 13 | 2008-11-26 11:08:38 | null | 2008-12-25 21:13:06 | https://stackoverflow.com/q/320313 | https://stackoverflow.com/a/320328 | <p>This is a tough one ;)</p>
<p>Usually you would use double dashes to tell the command that it should stop interpreting options, but echo will only output those:</p>
<pre><code>$ echo -- -e
-- -e
</code></pre>
<p>You can use -e itself to get around the problem:</p>
<pre><code>$ echo -e '\055e'
-e
</code></pre>
<... | <p>This is a tough one ;)</p> <p>Usually you would use double dashes to tell the command that it should stop interpreting options, but echo will only output those:</p> <pre><code>$ echo -- -e -- -e </code></pre> <p>You can use -e itself to get around the problem:</p> <pre><code>$ echo -e '\055e' -e </code></pre> <... | 387 | bash | <h1>echo "-e" doesn't print anything</h1>
<p>I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:</p>
<pre><code>echo "-e"
</code></pre>
<p>doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,257 | bash | # echo "-e" doesn't print anything
I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:
```
echo "-e"
```
doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty st... | This is a tough one ;)
Usually you would use double dashes to tell the command that it should stop interpreting options, but echo will only output those:
```
$ echo -- -e
-- -e
```
You can use -e itself to get around the problem:
```
$ echo -e '\055e'
-e
```
Also, as others have pointed out, if you don't insist on... |
296455 | How can I tell if a file is on a remote filesystem with Perl? | 11 | 2008-11-17 18:41:26 | <p>Is there a quick-and-dirty way to tell programmatically, in shell script or in Perl, whether a path is located on a remote filesystem (nfs or the like) or a local one? Or is the only way to do this to parse /etc/fstab and check the filesystem type?</p>
| 3,946 | 12,204 | 2010-08-24 16:49:01 | 296,542 | 13 | 2008-11-17 19:12:22 | 29,759 | 2008-11-17 19:12:22 | https://stackoverflow.com/q/296455 | https://stackoverflow.com/a/296542 | <p><code>stat -f -c %T <filename></code> should do what you want. You might also want <code>-l</code></p>
| <p><code>stat -f -c %T <filename></code> should do what you want. You might also want <code>-l</code></p> | 99, 390, 580, 3014 | filesystems, nfs, perl, shell | <h1>How can I tell if a file is on a remote filesystem with Perl?</h1>
<p>Is there a quick-and-dirty way to tell programmatically, in shell script or in Perl, whether a path is located on a remote filesystem (nfs or the like) or a local one? Or is the only way to do this to parse /etc/fstab and check the filesystem typ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,258 | bash | # How can I tell if a file is on a remote filesystem with Perl?
Is there a quick-and-dirty way to tell programmatically, in shell script or in Perl, whether a path is located on a remote filesystem (nfs or the like) or a local one? Or is the only way to do this to parse /etc/fstab and check the filesystem type? | `stat -f -c %T <filename>` should do what you want. You might also want `-l` |
70923677 | Git - BUG: refs/files-backend.c:465: returning non-zero -1, should have set myerr! On branch main | 10 | 2022-01-31 09:28:56 | <p>I have copy-pasted some files into my directory where I have git, and when I ran a command <code>git status</code> it gave me this error message.</p>
<pre><code>BUG: refs/files-backend.c:465: returning non-zero -1, should have set myerr!
On branch main
</code></pre>
<p>When I restored everything with <code>git resto... | 2,059 | 7,630,984 | 2022-02-01 17:07:38 | 70,944,642 | 13 | 2022-02-01 17:07:38 | 6,309 | 2022-02-01 17:07:38 | https://stackoverflow.com/q/70923677 | https://stackoverflow.com/a/70944642 | <p>The <a href="https://github.com/git-for-windows/git/releases/tag/v2.35.1.windows.2" rel="noreferrer">release 2.35.1(2)</a> seems to fix this issue, through <a href="https://github.com/git-for-windows/git/pull/3678" rel="noreferrer">PR 3678</a></p>
<p>Context: <a href="https://github.com/git-for-windows/git/issues/36... | <p>The <a href="https://github.com/git-for-windows/git/releases/tag/v2.35.1.windows.2" rel="noreferrer">release 2.35.1(2)</a> seems to fix this issue, through <a href="https://github.com/git-for-windows/git/pull/3678" rel="noreferrer">PR 3678</a></p> <p>Context: <a href="https://github.com/git-for-windows/git/issues/36... | 119, 61874 | git, git-bash | <h1>Git - BUG: refs/files-backend.c:465: returning non-zero -1, should have set myerr! On branch main</h1>
<p>I have copy-pasted some files into my directory where I have git, and when I ran a command <code>git status</code> it gave me this error message.</p>
<pre><code>BUG: refs/files-backend.c:465: returning non-zero... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,259 | bash | # Git - BUG: refs/files-backend.c:465: returning non-zero -1, should have set myerr! On branch main
I have copy-pasted some files into my directory where I have git, and when I ran a command `git status` it gave me this error message.
```
BUG: refs/files-backend.c:465: returning non-zero -1, should have set myerr!
On... | The [release 2.35.1(2)](https://github.com/git-for-windows/git/releases/tag/v2.35.1.windows.2) seems to fix this issue, through [PR 3678](https://github.com/git-for-windows/git/pull/3678)
Context: [issue 3655](https://github.com/git-for-windows/git/issues/3655) and [issue 3674](https://github.com/git-for-windows/git/i... |
70746111 | Why does read not have a normal man page? | 10 | 2022-01-17 18:43:33 | <p>I would love to learn more about 'read' so to enhance my shell scripting abilities.</p>
<p>Usually when I have a thirst for knowledge for any program, I simply type:</p>
<pre><code>man [program]
</code></pre>
<p>Then I learn how to work a program. I've been doing it this way for the past 15 years.</p>
<p>But a few d... | 3,737 | 11,623,262 | 2024-11-29 15:25:04 | 70,746,270 | 13 | 2022-01-17 18:59:30 | 68,587 | 2022-01-17 19:05:30 | https://stackoverflow.com/q/70746111 | https://stackoverflow.com/a/70746270 | <p>If your shell is <strong>bash</strong>, its builtin commands don't have individual man pages. Use <code>help</code> to see a list of builtins and <code>help <command></code> to get help on an individual one.</p>
<pre class="lang-none prettyprint-override"><code>$ help
GNU bash, version 5.1.4(1)-release (x86_64... | <p>If your shell is <strong>bash</strong>, its builtin commands don't have individual man pages. Use <code>help</code> to see a list of builtins and <code>help <command></code> to get help on an individual one.</p> <pre class="lang-none prettyprint-override"><code>$ help GNU bash, version 5.1.4(1)-release (x86_64... | 390, 9524 | manpage, shell | <h1>Why does read not have a normal man page?</h1>
<p>I would love to learn more about 'read' so to enhance my shell scripting abilities.</p>
<p>Usually when I have a thirst for knowledge for any program, I simply type:</p>
<pre><code>man [program]
</code></pre>
<p>Then I learn how to work a program. I've been doing it... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,260 | bash | # Why does read not have a normal man page?
I would love to learn more about 'read' so to enhance my shell scripting abilities.
Usually when I have a thirst for knowledge for any program, I simply type:
```
man [program]
```
Then I learn how to work a program. I've been doing it this way for the past 15 years.
But... | If your shell is **bash**, its builtin commands don't have individual man pages. Use `help` to see a list of builtins and `help <command>` to get help on an individual one.
```
$ help
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Ty... |
65640284 | How to change the MySQL JS> prompt to only MySQL>? | 10 | 2021-01-09 07:20:44 | <p>I did a custom installation for MySQL and only included the MySQL shell, the server, and the Python connector in the installation.</p>
<p>But I don't know where the JavaScript prompt <code>MySQL JS ></code> came from.</p>
<p>And because of that I can't connect Python and MySQL.</p>
<p><a href="https://i.sstatic.n... | 20,207 | 12,158,094 | 2024-11-26 06:08:00 | 66,856,556 | 13 | 2021-03-29 14:59:31 | 13,191,503 | 2023-07-27 12:46:11 | https://stackoverflow.com/q/65640284 | https://stackoverflow.com/a/66856556 | <p>Just switch the execution mode to sql in the shell:</p>
<pre><code>\sql
</code></pre>
| <p>Just switch the execution mode to sql in the shell:</p> <pre><code>\sql </code></pre> | 21, 148609 | mysql, mysql-shell | <h1>How to change the MySQL JS> prompt to only MySQL>?</h1>
<p>I did a custom installation for MySQL and only included the MySQL shell, the server, and the Python connector in the installation.</p>
<p>But I don't know where the JavaScript prompt <code>MySQL JS ></code> came from.</p>
<p>And because of that I can't c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,261 | bash | # How to change the MySQL JS> prompt to only MySQL>?
I did a custom installation for MySQL and only included the MySQL shell, the server, and the Python connector in the installation.
But I don't know where the JavaScript prompt `MySQL JS >` came from.
And because of that I can't connect Python and MySQL.
[![Screen... | Just switch the execution mode to sql in the shell:
```
\sql
``` |
65901987 | Get the last echo statement inside a function and put inside variable in bash | 10 | 2021-01-26 13:09:47 | <p>I have the following bash script, inside that statement, it has several commands with few echo commands. Is it possible to get the only last echo statement as return statement and ignore all other echo commands?</p>
<pre><code>#!/bin/bash
function statement(){
echo "This is the first statement"
echo &quo... | 2,450 | 8,713,243 | 2021-01-26 14:35:00 | 65,902,032 | 13 | 2021-01-26 13:12:35 | 1,126,841 | 2021-01-26 13:12:35 | https://stackoverflow.com/q/65901987 | https://stackoverflow.com/a/65902032 | <p>Use <code>tail</code> to extract just the last line.</p>
<pre><code>result=$(statement | tail -n 1)
</code></pre>
| <p>Use <code>tail</code> to extract just the last line.</p> <pre><code>result=$(statement | tail -n 1) </code></pre> | 387 | bash | <h1>Get the last echo statement inside a function and put inside variable in bash</h1>
<p>I have the following bash script, inside that statement, it has several commands with few echo commands. Is it possible to get the only last echo statement as return statement and ignore all other echo commands?</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 | 10,262 | bash | # Get the last echo statement inside a function and put inside variable in bash
I have the following bash script, inside that statement, it has several commands with few echo commands. Is it possible to get the only last echo statement as return statement and ignore all other echo commands?
```
#!/bin/bash
function ... | Use `tail` to extract just the last line.
```
result=$(statement | tail -n 1)
``` |
31974550 | Boolean cli flag using getopts in bash? | 10 | 2015-08-12 20:14:57 | <p>Is it possible to implement a boolean cli option using getopts in bash? Basically I want to do one thing if <code>-x</code> is specified and another if it is not.</p>
| 14,968 | 4,065,689 | 2025-07-02 08:14:51 | 54,302,327 | 13 | 2019-01-22 06:20:23 | 2,068,165 | 2025-07-02 08:14:51 | https://stackoverflow.com/q/31974550 | https://stackoverflow.com/a/54302327 | <p>Of course it is possible. @JonathanLeffler already pretty much gave the answer in the comments to the question, so all I'm going to do here is add an example of the implementation and a few niceties to consider:</p>
<pre class="lang-bash prettyprint-override"><code>#!/usr/bin/env bash
# Initialise option flag with ... | <p>Of course it is possible. @JonathanLeffler already pretty much gave the answer in the comments to the question, so all I'm going to do here is add an example of the implementation and a few niceties to consider:</p> <pre class="lang-bash prettyprint-override"><code>#!/usr/bin/env bash # Initialise option flag with ... | 387, 11225, 19020 | bash, command-line-interface, getopts | <h1>Boolean cli flag using getopts in bash?</h1>
<p>Is it possible to implement a boolean cli option using getopts in bash? Basically I want to do one thing if <code>-x</code> is specified and another if it is not.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,263 | bash | # Boolean cli flag using getopts in bash?
Is it possible to implement a boolean cli option using getopts in bash? Basically I want to do one thing if `-x` is specified and another if it is not. | Of course it is possible. @JonathanLeffler already pretty much gave the answer in the comments to the question, so all I'm going to do here is add an example of the implementation and a few niceties to consider:
```
#!/usr/bin/env bash
# Initialise option flag with a false value
OPT_X='false'
# Process all options s... |
53923226 | Unexpected end-of-input : expected close marker for Object error when trying to send a curl post request in a for loop | 10 | 2018-12-25 14:28:39 | <p>I'm relatively new to bash scripts so forgive me if this is a stupid question. Here is my simple bash script. It is written to send a POST request to a REST API repeatedly. I have set up some alerts to trigger when I have reached a certain threshold of these messages. </p>
<pre><code>for i in {0..600};
do
curl ... | 30,756 | 7,038,723 | 2018-12-25 16:09:16 | 53,923,862 | 13 | 2018-12-25 16:09:16 | 9,818,506 | 2018-12-25 16:09:16 | https://stackoverflow.com/q/53923226 | https://stackoverflow.com/a/53923862 | <p>A closing curly brace is missing in your data:</p>
<pre><code>'{"rsID":
{"action":"RECORDING_REQUESTED",
"ccid":"9999",
"rsId":"1c047ce2-8870-3072-852c-deae92a89105",
"chnnlId":"7438caaf-69bd-d76e-8091-3e5f60e57ad7",
"canonId":"1bb750d2-7b2a-2792-e21b-cdd8e41e6540",
"srsId":"",
"xtId":"SH... | <p>A closing curly brace is missing in your data:</p> <pre><code>'{"rsID": {"action":"RECORDING_REQUESTED", "ccid":"9999", "rsId":"1c047ce2-8870-3072-852c-deae92a89105", "chnnlId":"7438caaf-69bd-d76e-8091-3e5f60e57ad7", "canonId":"1bb750d2-7b2a-2792-e21b-cdd8e41e6540", "srsId":"", "xtId":"SH... | 387, 904, 1554 | bash, curl, post | <h1>Unexpected end-of-input : expected close marker for Object error when trying to send a curl post request in a for loop</h1>
<p>I'm relatively new to bash scripts so forgive me if this is a stupid question. Here is my simple bash script. It is written to send a POST request to a REST API repeatedly. I have set up so... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,264 | bash | # Unexpected end-of-input : expected close marker for Object error when trying to send a curl post request in a for loop
I'm relatively new to bash scripts so forgive me if this is a stupid question. Here is my simple bash script. It is written to send a POST request to a REST API repeatedly. I have set up some alerts... | A closing curly brace is missing in your data:
```
'{"rsID":
{"action":"RECORDING_REQUESTED",
"ccid":"9999",
"rsId":"1c047ce2-8870-3072-852c-deae92a89105",
"chnnlId":"7438caaf-69bd-d76e-8091-3e5f60e57ad7",
"canonId":"1bb750d2-7b2a-2792-e21b-cdd8e41e6540",
"srsId":"",
"xtId":"SH009513260000",... |
52674629 | $lookup with same collection | 10 | 2018-10-06 00:13:04 | <p>I am new to MongoDB so I am not sure if I have phrased my question correctly. </p>
<p>I have a collection in which data looks like this:</p>
<pre><code>{
"_id" : ObjectId("66666"),
"Id" : 994,
"PostType" : 1,
"AnswerId" : 334,
"CreationDate" : ISODate("1994-09-05T09:34:36.177+0000"),
... | 12,715 | 2,291,452 | 2020-04-29 18:03:14 | 52,674,985 | 13 | 2018-10-06 01:38:15 | 7,510,657 | 2018-10-06 01:55:21 | https://stackoverflow.com/q/52674629 | https://stackoverflow.com/a/52674985 | <p>You can try below aggregation in mongodb <strong>3.6</strong> and above</p>
<pre><code>db.collection.aggregate([
{ "$match": { "Id": 2627 }},
{ "$lookup": {
"from": "collection",
"let": { "answerId": "$AnswerId" },
"pipeline": [{ "$match": { "$expr": { "$eq": ["$Id", "$$answerId"] }}}],
"as": "d... | <p>You can try below aggregation in mongodb <strong>3.6</strong> and above</p> <pre><code>db.collection.aggregate([ { "$match": { "Id": 2627 }}, { "$lookup": { "from": "collection", "let": { "answerId": "$AnswerId" }, "pipeline": [{ "$match": { "$expr": { "$eq": ["$Id", "$$answerId"] }}}], "as": "d... | 30073, 69521, 80023, 80031, 82519 | aggregation-framework, mongodb, mongodb-query, mongo-shell, nosql-aggregation | <h1>$lookup with same collection</h1>
<p>I am new to MongoDB so I am not sure if I have phrased my question correctly. </p>
<p>I have a collection in which data looks like this:</p>
<pre><code>{
"_id" : ObjectId("66666"),
"Id" : 994,
"PostType" : 1,
"AnswerId" : 334,
"CreationDate" : ISODate(... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,265 | bash | # $lookup with same collection
I am new to MongoDB so I am not sure if I have phrased my question correctly.
I have a collection in which data looks like this:
```
{
"_id" : ObjectId("66666"),
"Id" : 994,
"PostType" : 1,
"AnswerId" : 334,
"CreationDate" : ISODate("1994-09-05T09:34:36.177+000... | You can try below aggregation in mongodb **3.6** and above
```
db.collection.aggregate([
{ "$match": { "Id": 2627 }},
{ "$lookup": {
"from": "collection",
"let": { "answerId": "$AnswerId" },
"pipeline": [{ "$match": { "$expr": { "$eq": ["$Id", "$$answerId"] }}}],
"as": "dates"
}}
])
```
Or with ... |
51616785 | Working with Powershell invoke-restmethod and json response | 10 | 2018-07-31 15:17:52 | <p>VERY newbie here with Powershell and JSON so may need a little extra help. Not a coder, fyi.</p>
<p>I'm working with Dell's API to retrieve warranty information on machines. I'd like to do it in Powershell if possible.</p>
<p>Here's my code so far -</p>
<pre><code>$headers = New-Object "System.Collections.Gener... | 27,582 | 3,771,461 | 2018-07-31 19:24:58 | 51,616,992 | 13 | 2018-07-31 15:27:39 | 3,905,079 | 2018-07-31 19:24:58 | https://stackoverflow.com/q/51616785 | https://stackoverflow.com/a/51616992 | <p>You're doing great! What you're seeing is PowerShell's system of <em>displaying</em> data on the screen. Since PowerShell tends to deal in complex objects, it's not just formatted string output you are dealing with like you might see from regular shell commands.</p>
<p>In this case, <code>Invoke-RestMethod</code> h... | <p>You're doing great! What you're seeing is PowerShell's system of <em>displaying</em> data on the screen. Since PowerShell tends to deal in complex objects, it's not just formatted string output you are dealing with like you might see from regular shell commands.</p> <p>In this case, <code>Invoke-RestMethod</code> h... | 526, 1508 | json, powershell | <h1>Working with Powershell invoke-restmethod and json response</h1>
<p>VERY newbie here with Powershell and JSON so may need a little extra help. Not a coder, fyi.</p>
<p>I'm working with Dell's API to retrieve warranty information on machines. I'd like to do it in Powershell if possible.</p>
<p>Here's my code so ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,266 | bash | # Working with Powershell invoke-restmethod and json response
VERY newbie here with Powershell and JSON so may need a little extra help. Not a coder, fyi.
I'm working with Dell's API to retrieve warranty information on machines. I'd like to do it in Powershell if possible.
Here's my code so far -
```
$headers = New... | You're doing great! What you're seeing is PowerShell's system of *displaying* data on the screen. Since PowerShell tends to deal in complex objects, it's not just formatted string output you are dealing with like you might see from regular shell commands.
In this case, `Invoke-RestMethod` has automatically done the eq... |
49549782 | Bash - How to count occurences in a column of a .csv file (without awk) | 10 | 2018-03-29 06:54:56 | <p>recently i've started to learn bash scripting and im wondering how i can count occurences in a column of a .csv file, the file is structured like this:</p>
<pre><code> DAYS,SOMEVALUE,SOMEVALUE
sunday,something,something
monday,something,something
wednesday,something,something
sunday,something,som... | 6,038 | 9,568,087 | 2018-03-29 07:54:07 | 49,550,579 | 13 | 2018-03-29 07:44:05 | 3,592,381 | 2018-03-29 07:44:05 | https://stackoverflow.com/q/49549782 | https://stackoverflow.com/a/49550579 | <pre><code>cut -f1 -d, test.csv | tail -n +2 | sort | uniq -c
</code></pre>
<p>This gets you this far:</p>
<pre><code> 2 monday
2 sunday
1 wednesday
</code></pre>
<p>To get your format (<code>Sunday : 1</code>), I think <code>awk</code> would be an easy and clear way (something like <code>awk '{print $2 " : " $... | <pre><code>cut -f1 -d, test.csv | tail -n +2 | sort | uniq -c </code></pre> <p>This gets you this far:</p> <pre><code> 2 monday 2 sunday 1 wednesday </code></pre> <p>To get your format (<code>Sunday : 1</code>), I think <code>awk</code> would be an easy and clear way (something like <code>awk '{print $2 " : " $... | 387 | bash | <h1>Bash - How to count occurences in a column of a .csv file (without awk)</h1>
<p>recently i've started to learn bash scripting and im wondering how i can count occurences in a column of a .csv file, the file is structured like this:</p>
<pre><code> DAYS,SOMEVALUE,SOMEVALUE
sunday,something,something
mond... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,267 | bash | # Bash - How to count occurences in a column of a .csv file (without awk)
recently i've started to learn bash scripting and im wondering how i can count occurences in a column of a .csv file, the file is structured like this:
```
DAYS,SOMEVALUE,SOMEVALUE
sunday,something,something
monday,something,somethi... | ```
cut -f1 -d, test.csv | tail -n +2 | sort | uniq -c
```
This gets you this far:
```
2 monday
2 sunday
1 wednesday
```
To get your format (`Sunday : 1`), I think `awk` would be an easy and clear way (something like `awk '{print $2 " : " $1}'`, but if you really really must, here's a complete non-awk version:... |
47272474 | How to redirect output in multiple columns in bash? | 10 | 2017-11-13 19:55:10 | <p>I am running a test multiple times on terminal and redirecting output to a file. While redirecting I want each run as a separate column. Currently, I am able to get the following:</p>
<pre><code>Run1
1
2
3
4
Run2
1
2
3
4
</code></pre>
<p>How to redirect it as follow:</p>
<pre><code>Run1 Run2
1 1
2 2
3 ... | 5,713 | 1,669,844 | 2023-05-09 06:23:08 | 47,272,800 | 13 | 2017-11-13 20:13:45 | 3,776,858 | 2017-11-13 22:34:27 | https://stackoverflow.com/q/47272474 | https://stackoverflow.com/a/47272800 | <p>With <code>pr</code>:</p>
<pre><code>pr -2 -t -s file
</code></pre>
<p>or from stdin:</p>
<pre><code>cat file | pr -2 -t -s
</code></pre>
<p>Output:</p>
<pre>
Run1 Run2
1 1
2 2
3 3
4 4
</pre>
<p>See: <code>man pr</code></p>
| <p>With <code>pr</code>:</p> <pre><code>pr -2 -t -s file </code></pre> <p>or from stdin:</p> <pre><code>cat file | pr -2 -t -s </code></pre> <p>Output:</p> <pre> Run1 Run2 1 1 2 2 3 3 4 4 </pre> <p>See: <code>man pr</code></p> | 73, 387 | bash, csv | <h1>How to redirect output in multiple columns in bash?</h1>
<p>I am running a test multiple times on terminal and redirecting output to a file. While redirecting I want each run as a separate column. Currently, I am able to get the following:</p>
<pre><code>Run1
1
2
3
4
Run2
1
2
3
4
</code></pre>
<p>How to redirect it... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,268 | bash | # How to redirect output in multiple columns in bash?
I am running a test multiple times on terminal and redirecting output to a file. While redirecting I want each run as a separate column. Currently, I am able to get the following:
```
Run1
1
2
3
4
Run2
1
2
3
4
```
How to redirect it as follow:
```
Run1 Run2
1 ... | With `pr`:
```
pr -2 -t -s file
```
or from stdin:
```
cat file | pr -2 -t -s
```
Output:
```
Run1 Run2
1 1
2 2
3 3
4 4
```
See: `man pr` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.