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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
18462916 | Does $! mean something in shell scripting | 10 | 2013-08-27 10:25:58 | <p>Does <strong>$!</strong> exists in bash/shell script, if yes, please inform for what it is used for. And why it gives blank when <code>echo $!</code> is run on the command line?</p>
| 11,282 | 2,412,468 | 2013-10-22 04:07:39 | 18,463,014 | 11 | 2013-08-27 10:31:44 | 548,225 | 2013-08-27 10:31:44 | https://stackoverflow.com/q/18462916 | https://stackoverflow.com/a/18463014 | <p>In addition to other answer, this echo</p>
<pre><code>echo $!
</code></pre>
<p>Will print blank if you haven't yet run any <strong>process in background</strong> in current shell. If you now run:</p>
<pre><code>date &
echo $!
</code></pre>
<p>Then it will print something like (i.e. process id of last execute... | <p>In addition to other answer, this echo</p> <pre><code>echo $! </code></pre> <p>Will print blank if you haven't yet run any <strong>process in background</strong> in current shell. If you now run:</p> <pre><code>date & echo $! </code></pre> <p>Then it will print something like (i.e. process id of last execute... | 58, 387, 390, 531 | bash, linux, scripting, shell | <h1>Does $! mean something in shell scripting</h1>
<p>Does <strong>$!</strong> exists in bash/shell script, if yes, please inform for what it is used for. And why it gives blank when <code>echo $!</code> is run on the command line?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,375 | bash | # Does $! mean something in shell scripting
Does **$!** exists in bash/shell script, if yes, please inform for what it is used for. And why it gives blank when `echo $!` is run on the command line? | In addition to other answer, this echo
```
echo $!
```
Will print blank if you haven't yet run any **process in background** in current shell. If you now run:
```
date &
echo $!
```
Then it will print something like (i.e. process id of last executed background process):
```
47833
``` |
17603823 | Save command output to variable without it printing to standard output | 10 | 2013-07-11 21:25:42 | <p>I'm doing a bash script and I'm grabbing the output from this command:</p>
<pre><code>fpings=$(fping -c 1 -t 1 $ips | sort)
</code></pre>
<p>The <code>fpings</code> variable does contain the output from the command, and the actual output of the command is not printed to the shell, but it still writes a line to th... | 9,533 | 596,041 | 2013-07-11 21:37:20 | 17,603,970 | 11 | 2013-07-11 21:37:20 | 1,030,675 | 2013-07-11 21:37:20 | https://stackoverflow.com/q/17603823 | https://stackoverflow.com/a/17603970 | <p>If you do not want to see the standard error, redirect it to <code>/dev/null</code>:</p>
<pre><code>fpings=$(fping -c 1 -t 1 $ips 2>/dev/null | sort)
</code></pre>
| <p>If you do not want to see the standard error, redirect it to <code>/dev/null</code>:</p> <pre><code>fpings=$(fping -c 1 -t 1 $ips 2>/dev/null | sort) </code></pre> | 58, 387 | bash, linux | <h1>Save command output to variable without it printing to standard output</h1>
<p>I'm doing a bash script and I'm grabbing the output from this command:</p>
<pre><code>fpings=$(fping -c 1 -t 1 $ips | sort)
</code></pre>
<p>The <code>fpings</code> variable does contain the output from the command, and the actual out... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,376 | bash | # Save command output to variable without it printing to standard output
I'm doing a bash script and I'm grabbing the output from this command:
```
fpings=$(fping -c 1 -t 1 $ips | sort)
```
The `fpings` variable does contain the output from the command, and the actual output of the command is not printed to the shel... | If you do not want to see the standard error, redirect it to `/dev/null`:
```
fpings=$(fping -c 1 -t 1 $ips 2>/dev/null | sort)
``` |
16028677 | string formatting in bash | 10 | 2013-04-16 04:15:05 | <p>I have the following code that runs in a shell script</p>
<pre><code>foo=`seq 1 1 100`
for i in $foo; do
echo "input$i\_now"
done
</code></pre>
<p>Here's my question: Under some conditions, the output prints <code>input1_now</code> whereas othertimes it prints <code>input1\_now</code>. I'm sure something is di... | 102,411 | 2,150,163 | 2021-12-20 09:17:39 | 16,028,770 | 11 | 2013-04-16 04:23:40 | 77,567 | 2013-04-17 02:54:44 | https://stackoverflow.com/q/16028677 | https://stackoverflow.com/a/16028770 | <p>Is <code>_</code> supposed to be a placeholder that is sometimes a different character?</p>
<p>In <code>bash</code>, <code>"input$i\_now"</code> with an actual <code>_</code> will always produce <code>input1\_now</code>. Inside double-quotes, <code>bash</code> only removes a <code>\</code> when it is followed by a... | <p>Is <code>_</code> supposed to be a placeholder that is sometimes a different character?</p> <p>In <code>bash</code>, <code>"input$i\_now"</code> with an actual <code>_</code> will always produce <code>input1\_now</code>. Inside double-quotes, <code>bash</code> only removes a <code>\</code> when it is followed by a... | 139, 387 | bash, string | <h1>string formatting in bash</h1>
<p>I have the following code that runs in a shell script</p>
<pre><code>foo=`seq 1 1 100`
for i in $foo; do
echo "input$i\_now"
done
</code></pre>
<p>Here's my question: Under some conditions, the output prints <code>input1_now</code> whereas othertimes it prints <code>input1\_no... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,377 | bash | # string formatting in bash
I have the following code that runs in a shell script
```
foo=`seq 1 1 100`
for i in $foo; do
echo "input$i\_now"
done
```
Here's my question: Under some conditions, the output prints `input1_now` whereas othertimes it prints `input1\_now`. I'm sure something is different, but I can't f... | Is `_` supposed to be a placeholder that is sometimes a different character?
In `bash`, `"input$i\_now"` with an actual `_` will always produce `input1\_now`. Inside double-quotes, `bash` only removes a `\` when it is followed by a `$`, a `` ` ``, a `"`, a `\`, or a newline. See [“Double Quotes” in the *Bash Reference... |
14686872 | Sub-shell differences between bash and ksh | 10 | 2013-02-04 12:31:32 | <p>I always believed that a sub-shell was not a child process, but another
shell environment in the same process.</p>
<p>I use a basic set of built-ins:</p>
<pre><code>(echo "Hello";read)
</code></pre>
<p>On another terminal:</p>
<pre><code>ps -t pts/0
PID TTY TIME CMD
20104 pts/0 00:00:00 ksh
</code>... | 7,393 | 736,308 | 2025-11-06 12:46:20 | 15,312,007 | 11 | 2013-03-09 14:50:08 | 495,451 | 2013-03-09 15:22:12 | https://stackoverflow.com/q/14686872 | https://stackoverflow.com/a/15312007 | <p>ksh93 works unusually hard to avoid subshells. Part of the reason is the avoidance of stdio and extensive use of <a href="http://www2.research.att.com/~gsf/download/ref/sfio/sfio.html">sfio</a> which allows builtins to communicate directly. Another reason is ksh can in theory have so many builtins. If built with <co... | <p>ksh93 works unusually hard to avoid subshells. Part of the reason is the avoidance of stdio and extensive use of <a href="http://www2.research.att.com/~gsf/download/ref/sfio/sfio.html">sfio</a> which allows builtins to communicate directly. Another reason is ksh can in theory have so many builtins. If built with <co... | 58, 387, 390, 531, 1964 | bash, ksh, linux, scripting, shell | <h1>Sub-shell differences between bash and ksh</h1>
<p>I always believed that a sub-shell was not a child process, but another
shell environment in the same process.</p>
<p>I use a basic set of built-ins:</p>
<pre><code>(echo "Hello";read)
</code></pre>
<p>On another terminal:</p>
<pre><code>ps -t pts/0
PID TTY ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,378 | bash | # Sub-shell differences between bash and ksh
I always believed that a sub-shell was not a child process, but another
shell environment in the same process.
I use a basic set of built-ins:
```
(echo "Hello";read)
```
On another terminal:
```
ps -t pts/0
PID TTY TIME CMD
20104 pts/0 00:00:00 ksh
```
S... | ksh93 works unusually hard to avoid subshells. Part of the reason is the avoidance of stdio and extensive use of [sfio](http://www2.research.att.com/~gsf/download/ref/sfio/sfio.html) which allows builtins to communicate directly. Another reason is ksh can in theory have so many builtins. If built with `SHOPT_CMDLIB_DIR... |
13109294 | start-process in Powershell closes Window automatically after execution is complete | 10 | 2012-10-28 13:46:27 | <p>I find that if I start a process by <code>start-process</code> in powershell , the new window will be closed automatically after execution complete , is it possible to keep it waiting for my further command to close?</p>
| 17,318 | 1,780,833 | 2020-03-18 12:06:22 | 13,109,885 | 11 | 2012-10-28 14:55:23 | 110,865 | 2013-04-17 16:46:27 | https://stackoverflow.com/q/13109294 | https://stackoverflow.com/a/13109885 | <p>Try passing <code>-noexit</code> as a parameter to <code>powershell.exe</code> when you start it.</p>
| <p>Try passing <code>-noexit</code> as a parameter to <code>powershell.exe</code> when you start it.</p> | 526, 4963, 5910 | powershell, process, window | <h1>start-process in Powershell closes Window automatically after execution is complete</h1>
<p>I find that if I start a process by <code>start-process</code> in powershell , the new window will be closed automatically after execution complete , is it possible to keep it waiting for my further command to close?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,379 | bash | # start-process in Powershell closes Window automatically after execution is complete
I find that if I start a process by `start-process` in powershell , the new window will be closed automatically after execution complete , is it possible to keep it waiting for my further command to close? | Try passing `-noexit` as a parameter to `powershell.exe` when you start it. |
11405225 | What is the meaning of the number in parens after the names of shell commands in the title of a manpage? | 10 | 2012-07-10 00:48:01 | <p>I see these numbers everywhere. For example, on this page: <a href="http://linux.die.net/man/1/tar">http://linux.die.net/man/1/tar</a></p>
<p>What is the meaning of the number - <code>1</code> in <code>tar(1)</code> ? I have seen 2, 5, etc also.</p>
| 259 | 78,351 | 2012-07-10 01:39:26 | 11,405,246 | 11 | 2012-07-10 00:51:30 | 1,488,032 | 2012-07-10 00:58:25 | https://stackoverflow.com/q/11405225 | https://stackoverflow.com/a/11405246 | <p>It tells you what group its manpage is in or, more generally, which group the item itself belongs to. Here's a list of the sections and their contents:</p>
<pre><code> 1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program li... | <p>It tells you what group its manpage is in or, more generally, which group the item itself belongs to. Here's a list of the sections and their contents:</p> <pre><code> 1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program li... | 390, 9524 | manpage, shell | <h1>What is the meaning of the number in parens after the names of shell commands in the title of a manpage?</h1>
<p>I see these numbers everywhere. For example, on this page: <a href="http://linux.die.net/man/1/tar">http://linux.die.net/man/1/tar</a></p>
<p>What is the meaning of the number - <code>1</code> in <code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,380 | bash | # What is the meaning of the number in parens after the names of shell commands in the title of a manpage?
I see these numbers everywhere. For example, on this page: <http://linux.die.net/man/1/tar>
What is the meaning of the number - `1` in `tar(1)` ? I have seen 2, 5, etc also. | It tells you what group its manpage is in or, more generally, which group the item itself belongs to. Here's a list of the sections and their contents:
```
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 ... |
9094679 | Getting Script name in Powershell | 10 | 2012-02-01 11:00:15 | <p>Is there any other way except $MyInvocation.InvocationName in powershell to get the script name?
As i need to turn my script in an exe and in that case it doesnt work on that exe.</p>
| 12,496 | 961,215 | 2016-01-30 17:35:38 | 9,099,339 | 11 | 2012-02-01 16:22:38 | 1,021,945 | 2012-02-01 16:31:27 | https://stackoverflow.com/q/9094679 | https://stackoverflow.com/a/9099339 | <p>I'm assuming since you convert the powershell script to an executable that you are after the location of the executable. You can get it this way:</p>
<pre><code>[Environment]::GetCommandLineArgs()[0]
</code></pre>
| <p>I'm assuming since you convert the powershell script to an executable that you are after the location of the executable. You can get it this way:</p> <pre><code>[Environment]::GetCommandLineArgs()[0] </code></pre> | 526 | powershell | <h1>Getting Script name in Powershell</h1>
<p>Is there any other way except $MyInvocation.InvocationName in powershell to get the script name?
As i need to turn my script in an exe and in that case it doesnt work on that exe.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,381 | bash | # Getting Script name in Powershell
Is there any other way except $MyInvocation.InvocationName in powershell to get the script name?
As i need to turn my script in an exe and in that case it doesnt work on that exe. | I'm assuming since you convert the powershell script to an executable that you are after the location of the executable. You can get it this way:
```
[Environment]::GetCommandLineArgs()[0]
``` |
9028383 | Find the highest user ID in Mac OS X | 10 | 2012-01-27 02:46:20 | <p>I'm writing a script to add new users to an OS X system on the command line. I know I can list all users on a system with their user IDs using:</p>
<pre><code>dscl . -list /Users UniqueID
</code></pre>
<p>which gives something like:</p>
<pre><code>xxxxxxx 937
xxxxxxxx ... | 4,983 | 343,845 | 2014-02-03 01:02:21 | 9,028,465 | 11 | 2012-01-27 03:01:17 | 535,275 | 2012-01-27 03:01:17 | https://stackoverflow.com/q/9028383 | https://stackoverflow.com/a/9028465 | <p>This will give you the line with the highest ID:</p>
<pre><code>dscl . -list /Users UniqueID | sort -nr -k 2 | head -1
</code></pre>
| <p>This will give you the line with the highest ID:</p> <pre><code>dscl . -list /Users UniqueID | sort -nr -k 2 | head -1 </code></pre> | 369, 390 | macos, shell | <h1>Find the highest user ID in Mac OS X</h1>
<p>I'm writing a script to add new users to an OS X system on the command line. I know I can list all users on a system with their user IDs using:</p>
<pre><code>dscl . -list /Users UniqueID
</code></pre>
<p>which gives something like:</p>
<pre><code>xxxxxxx ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,382 | bash | # Find the highest user ID in Mac OS X
I'm writing a script to add new users to an OS X system on the command line. I know I can list all users on a system with their user IDs using:
```
dscl . -list /Users UniqueID
```
which gives something like:
```
xxxxxxx 937
xxxxxxxx ... | This will give you the line with the highest ID:
```
dscl . -list /Users UniqueID | sort -nr -k 2 | head -1
``` |
8395358 | Creating a file in a specific directory using Bash? | 10 | 2011-12-06 04:27:51 | <p>Normally to create a file in a directory I would use:</p>
<pre><code>echo > /home/user/fileName
</code></pre>
<p>but, in this case, my directory path I want to create the file in is stored in a variable in my script so I can't write out the path like that. How do I create a new file inside of it?</p>
| 33,555 | 1,082,822 | 2023-03-29 23:08:44 | 8,395,367 | 11 | 2011-12-06 04:29:46 | 14,860 | 2023-03-29 23:08:44 | https://stackoverflow.com/q/8395358 | https://stackoverflow.com/a/8395367 | <p>If you have a variable <code>myPath</code>, you can use:</p>
<pre class="lang-bash prettyprint-override"><code>echo > "${myPath}/fileName"
</code></pre>
<p>as per the following transcript:</p>
<pre class="lang-bash prettyprint-override"><code>pax:~$ export myPath="/tmp"
pax:~$ ls -al /tmp/xyz... | <p>If you have a variable <code>myPath</code>, you can use:</p> <pre class="lang-bash prettyprint-override"><code>echo > "${myPath}/fileName" </code></pre> <p>as per the following transcript:</p> <pre class="lang-bash prettyprint-override"><code>pax:~$ export myPath="/tmp" pax:~$ ls -al /tmp/xyz... | 218, 387, 5310 | bash, directory, file | <h1>Creating a file in a specific directory using Bash?</h1>
<p>Normally to create a file in a directory I would use:</p>
<pre><code>echo > /home/user/fileName
</code></pre>
<p>but, in this case, my directory path I want to create the file in is stored in a variable in my script so I can't write out the path like ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,383 | bash | # Creating a file in a specific directory using Bash?
Normally to create a file in a directory I would use:
```
echo > /home/user/fileName
```
but, in this case, my directory path I want to create the file in is stored in a variable in my script so I can't write out the path like that. How do I create a new file ins... | If you have a variable `myPath`, you can use:
```
echo > "${myPath}/fileName"
```
as per the following transcript:
```
pax:~$ export myPath="/tmp"
pax:~$ ls -al /tmp/xyzzy
ls: cannot access /tmp/xyzzy: No such file or directory
pax:~$ echo > "${myPath}/xyzzy"
pax:~$ ls -al /tmp/xyzzy
-rw-r--r-- 1 pax pax 1 2011-1... |
7130529 | MissingPropertyException in groovysh | 10 | 2011-08-20 07:51:31 | <p>I run <code>groovysh</code>, and type the following code:</p>
<pre><code>groovy:000> String s = "Hello"
===> Hello
groovy:000> s
ERROR groovy.lang.MissingPropertyException:
No such property: s for class: groovysh_evaluate
at groovysh_evaluate.run (groovysh_evaluate:2)
...
groovy:000>
</c... | 5,351 | 342,235 | 2015-12-21 12:30:15 | 7,135,423 | 11 | 2011-08-20 23:42:34 | 528,428 | 2011-08-20 23:42:34 | https://stackoverflow.com/q/7130529 | https://stackoverflow.com/a/7135423 | <p>The expression <code>s = "Hello"</code> sets a shell variable, the expression <code>String s = "Hello"</code> sets a local variable which does not get saved to the shell's environment. Please see the <a href="http://groovy.codehaus.org/Groovy+Shell#GroovyShell-Variables" rel="noreferrer">Groovy Shell documentation</... | <p>The expression <code>s = "Hello"</code> sets a shell variable, the expression <code>String s = "Hello"</code> sets a local variable which does not get saved to the shell's environment. Please see the <a href="http://groovy.codehaus.org/Groovy+Shell#GroovyShell-Variables" rel="noreferrer">Groovy Shell documentation</... | 849, 3951 | groovy, groovyshell | <h1>MissingPropertyException in groovysh</h1>
<p>I run <code>groovysh</code>, and type the following code:</p>
<pre><code>groovy:000> String s = "Hello"
===> Hello
groovy:000> s
ERROR groovy.lang.MissingPropertyException:
No such property: s for class: groovysh_evaluate
at groovysh_evaluate.run (groov... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,384 | bash | # MissingPropertyException in groovysh
I run `groovysh`, and type the following code:
```
groovy:000> String s = "Hello"
===> Hello
groovy:000> s
ERROR groovy.lang.MissingPropertyException:
No such property: s for class: groovysh_evaluate
at groovysh_evaluate.run (groovysh_evaluate:2)
...
groovy:000>
... | The expression `s = "Hello"` sets a shell variable, the expression `String s = "Hello"` sets a local variable which does not get saved to the shell's environment. Please see the [Groovy Shell documentation](http://groovy.codehaus.org/Groovy+Shell#GroovyShell-Variables) for more information. I am not quite sure what you... |
6549037 | Bash: Brace expansion in scripts not working due to unwanted escaping | 10 | 2011-07-01 14:06:24 | <p>I want to do something like this in a bash script. I'm using <code>bash 4.1.10</code>.</p>
<pre><code># rm -rf /some/path/{folder1,folder2,folder3}
</code></pre>
<p>Works nicely (and as expected) from the shell itself. It deletes the 3 desired folders leaving all others untouched.</p>
<p>When I put it into script... | 7,789 | 609,735 | 2013-02-08 05:42:31 | 6,549,124 | 11 | 2011-07-01 14:13:45 | 557,191 | 2011-07-01 15:01:33 | https://stackoverflow.com/q/6549037 | https://stackoverflow.com/a/6549124 | <p>According to <a href="http://linux.die.net/man/1/bash" rel="noreferrer">the man page</a>:</p>
<blockquote>
<p>The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expa... | <p>According to <a href="http://linux.die.net/man/1/bash" rel="noreferrer">the man page</a>:</p> <blockquote> <p>The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expa... | 387, 4804, 41340 | bash, brace-expansion, escaping | <h1>Bash: Brace expansion in scripts not working due to unwanted escaping</h1>
<p>I want to do something like this in a bash script. I'm using <code>bash 4.1.10</code>.</p>
<pre><code># rm -rf /some/path/{folder1,folder2,folder3}
</code></pre>
<p>Works nicely (and as expected) from the shell itself. It deletes the 3 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,385 | bash | # Bash: Brace expansion in scripts not working due to unwanted escaping
I want to do something like this in a bash script. I'm using `bash 4.1.10`.
```
# rm -rf /some/path/{folder1,folder2,folder3}
```
Works nicely (and as expected) from the shell itself. It deletes the 3 desired folders leaving all others untouched... | According to [the man page](http://linux.die.net/man/1/bash):
> The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expansion.
So to get around this, add another level of exp... |
4935278 | concatenate a string to the end of every output line in bash/csh | 10 | 2011-02-08 15:58:19 | <p>In bash command line, if I run "find . -name 'abc*' ", it prints out a list of filenames like</p>
<pre><code>abc1
abc2
abc3
</code></pre>
<p>How can I pipe it with echo or other command, so that i get this output:</p>
<pre><code>abc1 ok
abc2 ok
abc3 ok
</code></pre>
| 19,265 | 439,888 | 2015-12-08 15:01:30 | 4,935,361 | 11 | 2011-02-08 16:06:09 | 113,195 | 2011-02-08 16:06:09 | https://stackoverflow.com/q/4935278 | https://stackoverflow.com/a/4935361 | <pre><code>find . -name 'abc*' | sed 's/$/\tok/' | column -t
</code></pre>
<p><code>sed</code> appends the string <code><Tab>ok</code> to each line, and <code>column</code> formats the output nicely (you can just skip this, if you don't need it).</p>
| <pre><code>find . -name 'abc*' | sed 's/$/\tok/' | column -t </code></pre> <p><code>sed</code> appends the string <code><Tab>ok</code> to each line, and <code>column</code> formats the output nicely (you can just skip this, if you don't need it).</p> | 387, 7792 | bash, string-concatenation | <h1>concatenate a string to the end of every output line in bash/csh</h1>
<p>In bash command line, if I run "find . -name 'abc*' ", it prints out a list of filenames like</p>
<pre><code>abc1
abc2
abc3
</code></pre>
<p>How can I pipe it with echo or other command, so that i get this output:</p>
<pre><code>abc1 ok
a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,386 | bash | # concatenate a string to the end of every output line in bash/csh
In bash command line, if I run "find . -name 'abc*' ", it prints out a list of filenames like
```
abc1
abc2
abc3
```
How can I pipe it with echo or other command, so that i get this output:
```
abc1 ok
abc2 ok
abc3 ok
``` | ```
find . -name 'abc*' | sed 's/$/\tok/' | column -t
```
`sed` appends the string `<Tab>ok` to each line, and `column` formats the output nicely (you can just skip this, if you don't need it). |
2775526 | XmlSerializer's functionality in PowerShell? | 10 | 2010-05-05 17:48:12 | <p>Is there a way to leverage the functionality of .NET's XmlSerializer class in PowerShell?</p>
<p>More specifically, the ability to easily de/serialize .NET types into Xml e.g.</p>
<pre><code>XmlSerializer s = new XmlSerializer(typeof(MyType));
TextReader r = new StreamReader("sample.xml");
MyType myType = (MyType)... | 11,999 | 118,464 | 2010-05-07 13:38:32 | 2,782,583 | 11 | 2010-05-06 16:09:29 | 48,082 | 2010-05-07 13:38:32 | https://stackoverflow.com/q/2775526 | https://stackoverflow.com/a/2782583 | <p>Sure, you can define a type within Powershell, and use it in serialization.</p>
<p>The first step is defining a new type. In <a href="http://support.microsoft.com/kb/968929" rel="nofollow noreferrer">Powershell 2.0</a>, you can do that by
calling <a href="http://technet.microsoft.com/en-us/library/dd315241.aspx" ... | <p>Sure, you can define a type within Powershell, and use it in serialization.</p> <p>The first step is defining a new type. In <a href="http://support.microsoft.com/kb/968929" rel="nofollow noreferrer">Powershell 2.0</a>, you can do that by calling <a href="http://technet.microsoft.com/en-us/library/dd315241.aspx" ... | 526, 47657 | powershell, xmlserializer | <h1>XmlSerializer's functionality in PowerShell?</h1>
<p>Is there a way to leverage the functionality of .NET's XmlSerializer class in PowerShell?</p>
<p>More specifically, the ability to easily de/serialize .NET types into Xml e.g.</p>
<pre><code>XmlSerializer s = new XmlSerializer(typeof(MyType));
TextReader r = ne... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,387 | bash | # XmlSerializer's functionality in PowerShell?
Is there a way to leverage the functionality of .NET's XmlSerializer class in PowerShell?
More specifically, the ability to easily de/serialize .NET types into Xml e.g.
```
XmlSerializer s = new XmlSerializer(typeof(MyType));
TextReader r = new StreamReader("sample.xml"... | Sure, you can define a type within Powershell, and use it in serialization.
The first step is defining a new type. In [Powershell 2.0](http://support.microsoft.com/kb/968929), you can do that by
calling [Add-Type](http://technet.microsoft.com/en-us/library/dd315241.aspx) . Once you have the dynamically-compiled assemb... |
2704748 | Folder cleanup with PowerShell | 10 | 2010-04-24 14:12:52 | <p>I'd like to clean up some directories after my script runs by deleting certain folders and files from the current directory if they exist. Originally, I structured the script like this:</p>
<pre><code>if (Test-Path Folder1) {
Remove-Item -r Folder1
}
if (Test-Path Folder2) {
Remove-Item -r Folder2
}
if (Test-Pa... | 11,258 | 138,304 | 2010-04-24 15:03:54 | 2,704,898 | 11 | 2010-04-24 15:03:54 | 323,582 | 2010-04-24 15:03:54 | https://stackoverflow.com/q/2704748 | https://stackoverflow.com/a/2704898 | <pre><code># if you want to avoid errors on missed paths
# (because even ignored errors are added to $Error)
# (or you want to -ErrorAction Stop if an item is not removed)
@(
'Directory1'
'Directory2'
'File1'
) |
Where-Object { Test-Path $_ } |
ForEach-Object { Remove-Item $_ -Recurse -Force -ErrorAction St... | <pre><code># if you want to avoid errors on missed paths # (because even ignored errors are added to $Error) # (or you want to -ErrorAction Stop if an item is not removed) @( 'Directory1' 'Directory2' 'File1' ) | Where-Object { Test-Path $_ } | ForEach-Object { Remove-Item $_ -Recurse -Force -ErrorAction St... | 526, 24067 | powershell, powershell-2.0 | <h1>Folder cleanup with PowerShell</h1>
<p>I'd like to clean up some directories after my script runs by deleting certain folders and files from the current directory if they exist. Originally, I structured the script like this:</p>
<pre><code>if (Test-Path Folder1) {
Remove-Item -r Folder1
}
if (Test-Path Folder2) ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,388 | bash | # Folder cleanup with PowerShell
I'd like to clean up some directories after my script runs by deleting certain folders and files from the current directory if they exist. Originally, I structured the script like this:
```
if (Test-Path Folder1) {
Remove-Item -r Folder1
}
if (Test-Path Folder2) {
Remove-Item -r F... | ```
# if you want to avoid errors on missed paths
# (because even ignored errors are added to $Error)
# (or you want to -ErrorAction Stop if an item is not removed)
@(
'Directory1'
'Directory2'
'File1'
) |
Where-Object { Test-Path $_ } |
ForEach-Object { Remove-Item $_ -Recurse -Force -ErrorAction Stop }
``... |
2564761 | how to start growl via the command line | 10 | 2010-04-02 02:41:54 | <p>I have a bash script that uses growlnotify to send notifications. However, growlnotify doesn't work if Growl isn't already running, and it won't auto start Growl if it needs it, either. So I want to be able to check if Growl is running, and then start it if it isn't.<br>
I'm thinking of doing something like:</p>
<p... | 7,206 | 216,687 | 2010-04-02 04:32:46 | 2,565,015 | 11 | 2010-04-02 04:32:46 | 145,403 | 2010-04-02 04:32:46 | https://stackoverflow.com/q/2564761 | https://stackoverflow.com/a/2565015 | <p>Normally the Growl installer will ensure that the user doing the installing gets a login Startup item that launches <code>GrowlHelperApp.app</code>, the notification daemon for Growl. The app is built into the Growl PreferencePane, so you can't guarantee where it will be located; it may be in <code>/Library/Prefere... | <p>Normally the Growl installer will ensure that the user doing the installing gets a login Startup item that launches <code>GrowlHelperApp.app</code>, the notification daemon for Growl. The app is built into the Growl PreferencePane, so you can't guarantee where it will be located; it may be in <code>/Library/Prefere... | 369, 387, 1231, 29026, 45023 | bash, command-line, growl, growlnotify, macos | <h1>how to start growl via the command line</h1>
<p>I have a bash script that uses growlnotify to send notifications. However, growlnotify doesn't work if Growl isn't already running, and it won't auto start Growl if it needs it, either. So I want to be able to check if Growl is running, and then start it if it isn't.<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,389 | bash | # how to start growl via the command line
I have a bash script that uses growlnotify to send notifications. However, growlnotify doesn't work if Growl isn't already running, and it won't auto start Growl if it needs it, either. So I want to be able to check if Growl is running, and then start it if it isn't.
I'm thi... | Normally the Growl installer will ensure that the user doing the installing gets a login Startup item that launches `GrowlHelperApp.app`, the notification daemon for Growl. The app is built into the Growl PreferencePane, so you can't guarantee where it will be located; it may be in `/Library/PreferencePanes` or `~/Libr... |
1478545 | Handling events with PowerShell? | 10 | 2009-09-25 17:16:38 | <p>How can you handle events thrown by .NET object using PowerShell v2? Can someone point me to a simple code sample?</p>
| 5,056 | 3,957 | 2012-09-06 23:20:21 | 1,478,660 | 11 | 2009-09-25 17:39:40 | 153,982 | 2012-09-06 23:20:21 | https://stackoverflow.com/q/1478545 | https://stackoverflow.com/a/1478660 | <p>Look at the docs on the <a href="http://technet.microsoft.com/en-us/library/hh849929.aspx" rel="nofollow noreferrer">Register-ObjectEvent</a> cmdlet. Be sure to use the -full parameter. It has some good examples of usage including this one:</p>
<pre><code>$timer = New-Object Timers.Timer
$timer.Interval = 500
$tim... | <p>Look at the docs on the <a href="http://technet.microsoft.com/en-us/library/hh849929.aspx" rel="nofollow noreferrer">Register-ObjectEvent</a> cmdlet. Be sure to use the -full parameter. It has some good examples of usage including this one:</p> <pre><code>$timer = New-Object Timers.Timer $timer.Interval = 500 $tim... | 1, 526, 11215 | .net, event-handling, powershell | <h1>Handling events with PowerShell?</h1>
<p>How can you handle events thrown by .NET object using PowerShell v2? Can someone point me to a simple code sample?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,390 | bash | # Handling events with PowerShell?
How can you handle events thrown by .NET object using PowerShell v2? Can someone point me to a simple code sample? | Look at the docs on the [Register-ObjectEvent](http://technet.microsoft.com/en-us/library/hh849929.aspx) cmdlet. Be sure to use the -full parameter. It has some good examples of usage including this one:
```
$timer = New-Object Timers.Timer
$timer.Interval = 500
$timer.Start()
$job = Register-ObjectEvent -inputObject ... |
745956 | How can I dispose System.Xml.XmlWriter in PowerShell | 10 | 2009-04-14 00:57:55 | <p>I am trying to dispose XmlWriter object:</p>
<pre><code>try
{
[System.Xml.XmlWriter] $writer = [System.Xml.XmlWriter]::Create('c:\some.xml')
}
finally
{
$writer.Dispose()
}
</code></pre>
<p>Error:</p>
<blockquote>
<p>Method invocation failed because
[System.Xml.XmlWellFormedWriter]
doesn't contain a... | 4,731 | 62,192 | 2009-04-20 10:14:35 | 745,965 | 11 | 2009-04-14 01:02:37 | 67,132 | 2009-04-14 01:02:37 | https://stackoverflow.com/q/745956 | https://stackoverflow.com/a/745965 | <p>Dispose is <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.dispose(loband).aspx" rel="noreferrer">protected</a> on <code>System.Xml.XmlWriter</code>. You should use <code>Close</code> instead.</p>
<pre><code>$writer.Close
</code></pre>
| <p>Dispose is <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.dispose(loband).aspx" rel="noreferrer">protected</a> on <code>System.Xml.XmlWriter</code>. You should use <code>Close</code> instead.</p> <pre><code>$writer.Close </code></pre> | 526, 2128, 3917 | dispose, idisposable, powershell | <h1>How can I dispose System.Xml.XmlWriter in PowerShell</h1>
<p>I am trying to dispose XmlWriter object:</p>
<pre><code>try
{
[System.Xml.XmlWriter] $writer = [System.Xml.XmlWriter]::Create('c:\some.xml')
}
finally
{
$writer.Dispose()
}
</code></pre>
<p>Error:</p>
<blockquote>
<p>Method invocation failed ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,391 | bash | # How can I dispose System.Xml.XmlWriter in PowerShell
I am trying to dispose XmlWriter object:
```
try
{
[System.Xml.XmlWriter] $writer = [System.Xml.XmlWriter]::Create('c:\some.xml')
}
finally
{
$writer.Dispose()
}
```
Error:
> Method invocation failed because
> [System.Xml.XmlWellFormedWriter]
> doesn't ... | Dispose is [protected](http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.dispose(loband).aspx) on `System.Xml.XmlWriter`. You should use `Close` instead.
```
$writer.Close
``` |
443375 | How to escape command line arguments on PowerShell? | 10 | 2009-01-14 15:32:34 | <p>It appears that I can escape command line arguments using single or double quotes:</p>
<pre><code>PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
</code></pre>
<p>But there's still something I can't figure out, which is when you wish to ru... | 17,883 | 34,685 | 2018-09-16 23:14:09 | 443,394 | 11 | 2009-01-14 15:36:41 | 1,358 | 2018-09-16 23:14:09 | https://stackoverflow.com/q/443375 | https://stackoverflow.com/a/443394 | <p>Use this:</p>
<pre><code>. "c:\program files\test.exe"
</code></pre>
<p>Actually an even better solution would be:</p>
<pre><code>Invoke-Item "c:\program files\test.exe"
</code></pre>
<p>or using the alias:</p>
<pre><code>ii "c:\program files\test.exe"
</code></pre>
<p>Using Invoke-Item means that the proper W... | <p>Use this:</p> <pre><code>. "c:\program files\test.exe" </code></pre> <p>Actually an even better solution would be:</p> <pre><code>Invoke-Item "c:\program files\test.exe" </code></pre> <p>or using the alias:</p> <pre><code>ii "c:\program files\test.exe" </code></pre> <p>Using Invoke-Item means that the proper W... | 526 | powershell | <h1>How to escape command line arguments on PowerShell?</h1>
<p>It appears that I can escape command line arguments using single or double quotes:</p>
<pre><code>PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
</code></pre>
<p>But there's sti... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,392 | bash | # How to escape command line arguments on PowerShell?
It appears that I can escape command line arguments using single or double quotes:
```
PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
```
But there's still something I can't figure out, which is ... | Use this:
```
. "c:\program files\test.exe"
```
Actually an even better solution would be:
```
Invoke-Item "c:\program files\test.exe"
```
or using the alias:
```
ii "c:\program files\test.exe"
```
Using Invoke-Item means that the proper Windows file handler would be used. So for an EXE file it would run it. For ... |
69166284 | Powershell, use (space-separated) string as arguments to a program | 9 | 2021-09-13 16:37:37 | <p>I've read <a href="https://stackoverflow.com/questions/61438339/how-to-expand-a-variable-as-several-space-separated-program-arguments">this</a> and it doesn't solve my problem.</p>
<p>I have a space-separated string, let's say <code>$MyString = "arg1 arg2"</code>. Suppose I have a command line program call... | 5,107 | 948,655 | 2022-03-01 13:38:03 | 69,166,398 | 11 | 2021-09-13 16:47:37 | 948,655 | 2021-09-14 01:34:38 | https://stackoverflow.com/q/69166284 | https://stackoverflow.com/a/69166398 | <p>Oh I just found out how LOL. I should have thought of this sooner; basically, just use <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1" rel="noreferrer">splatting</a> The following worked for me:</p>
<pre><code>$MyArray = $($MyString -s... | <p>Oh I just found out how LOL. I should have thought of this sooner; basically, just use <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1" rel="noreferrer">splatting</a> The following worked for me:</p> <pre><code>$MyArray = $($MyString -s... | 139, 526, 10355 | parameter-passing, powershell, string | <h1>Powershell, use (space-separated) string as arguments to a program</h1>
<p>I've read <a href="https://stackoverflow.com/questions/61438339/how-to-expand-a-variable-as-several-space-separated-program-arguments">this</a> and it doesn't solve my problem.</p>
<p>I have a space-separated string, let's say <code>$MyStrin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,393 | bash | # Powershell, use (space-separated) string as arguments to a program
I've read [this](https://stackoverflow.com/questions/61438339/how-to-expand-a-variable-as-several-space-separated-program-arguments) and it doesn't solve my problem.
I have a space-separated string, let's say `$MyString = "arg1 arg2"`. Suppose I hav... | Oh I just found out how LOL. I should have thought of this sooner; basically, just use [splatting](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1) The following worked for me:
```
$MyArray = $($MyString -split " ")
MyProgram @MyArray
```
Explana... |
67907091 | Powershell command to wait some time | 9 | 2021-06-09 15:18:06 | <p>How can I stop a powershell script execution for an x time and that continue after it?<br />
So, for example, I can run a command and wait 3 seconds to display the user a log, then continue with other script execution.</p>
| 25,580 | 14,997,578 | 2021-06-09 15:56:28 | 67,907,275 | 11 | 2021-06-09 15:29:21 | 6,083,222 | 2021-06-09 15:29:21 | https://stackoverflow.com/q/67907091 | https://stackoverflow.com/a/67907275 | <p>Microsoft provides the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-7.1" rel="noreferrer"><code>Start-Sleep</code></a> cmdlet specifically for this purpose. By default, its parameter is the number of seconds to sleep; if you need finer control ... | <p>Microsoft provides the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-7.1" rel="noreferrer"><code>Start-Sleep</code></a> cmdlet specifically for this purpose. By default, its parameter is the number of seconds to sleep; if you need finer control ... | 64, 526, 2221 | powershell, sleep, windows | <h1>Powershell command to wait some time</h1>
<p>How can I stop a powershell script execution for an x time and that continue after it?<br />
So, for example, I can run a command and wait 3 seconds to display the user a log, then continue with other script execution.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,394 | bash | # Powershell command to wait some time
How can I stop a powershell script execution for an x time and that continue after it?
So, for example, I can run a command and wait 3 seconds to display the user a log, then continue with other script execution. | Microsoft provides the [`Start-Sleep`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-7.1) cmdlet specifically for this purpose. By default, its parameter is the number of seconds to sleep; if you need finer control over the idle period, you can specify `-Mi... |
66267355 | Add International English keyboard in windows 10 through the powershell | 9 | 2021-02-18 20:03:09 | <p>It is a known issue that in windows 10 when you decide to add multiple languages you end up with several keyboards that you can not get rid off. A well known solution that I have used in order to have <strong>only</strong> Greek and English keyboards is to create a powershell script that runs on startup with the fol... | 5,583 | 925,040 | 2021-02-18 21:48:20 | 66,268,636 | 11 | 2021-02-18 21:48:20 | 15,238,292 | 2021-02-18 21:48:20 | https://stackoverflow.com/q/66267355 | https://stackoverflow.com/a/66268636 | <p>I don't know the answer to this. I know how you can find the answer to this:</p>
<ol>
<li>Manually set the keyboard language to US International (or any other). Note that this is considered as a "Layout" not as a language like "en-US".</li>
<li>Run in powershell <code>Get-WinUserLanguageList</cod... | <p>I don't know the answer to this. I know how you can find the answer to this:</p> <ol> <li>Manually set the keyboard language to US International (or any other). Note that this is considered as a "Layout" not as a language like "en-US".</li> <li>Run in powershell <code>Get-WinUserLanguageList</cod... | 64, 526, 12565, 107329 | keyboard-layout, powershell, windows, windows-10 | <h1>Add International English keyboard in windows 10 through the powershell</h1>
<p>It is a known issue that in windows 10 when you decide to add multiple languages you end up with several keyboards that you can not get rid off. A well known solution that I have used in order to have <strong>only</strong> Greek and Eng... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,395 | bash | # Add International English keyboard in windows 10 through the powershell
It is a known issue that in windows 10 when you decide to add multiple languages you end up with several keyboards that you can not get rid off. A well known solution that I have used in order to have **only** Greek and English keyboards is to c... | I don't know the answer to this. I know how you can find the answer to this:
1. Manually set the keyboard language to US International (or any other). Note that this is considered as a "Layout" not as a language like "en-US".
2. Run in powershell `Get-WinUserLanguageList`
Example Output:
```
PS C:\> Get-WinUserLangu... |
61235185 | How to get $HOME directory of user in bash script root mode? | 9 | 2020-04-15 17:44:46 | <p>file name <strong>test.sh</strong></p>
<pre><code>echo $HOME
</code></pre>
<p>running in root privilege -> <strong><em>sudo test.sh</em></strong></p>
<p>expected </p>
<pre><code>/home/username/
</code></pre>
<p>but getting </p>
<pre><code>/root
</code></pre>
| 10,962 | 13,033,981 | 2023-06-01 18:59:22 | 61,235,370 | 11 | 2020-04-15 17:54:08 | 7,334,699 | 2020-04-15 17:54:08 | https://stackoverflow.com/q/61235185 | https://stackoverflow.com/a/61235370 | <p><code>sudo</code> runs the script as the root-user
To get the name of the user who initiated sudo you can call <code>echo $SUDO_USER</code></p>
<p>To get its home directory:</p>
<pre><code>getent passwd $SUDO_USER | cut -d: -f6
</code></pre>
| <p><code>sudo</code> runs the script as the root-user To get the name of the user who initiated sudo you can call <code>echo $SUDO_USER</code></p> <p>To get its home directory:</p> <pre><code>getent passwd $SUDO_USER | cut -d: -f6 </code></pre> | 58, 387 | bash, linux | <h1>How to get $HOME directory of user in bash script root mode?</h1>
<p>file name <strong>test.sh</strong></p>
<pre><code>echo $HOME
</code></pre>
<p>running in root privilege -> <strong><em>sudo test.sh</em></strong></p>
<p>expected </p>
<pre><code>/home/username/
</code></pre>
<p>but getting </p>
<pre><code>/r... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,396 | bash | # How to get $HOME directory of user in bash script root mode?
file name **test.sh**
```
echo $HOME
```
running in root privilege -> ***sudo test.sh***
expected
```
/home/username/
```
but getting
```
/root
``` | `sudo` runs the script as the root-user
To get the name of the user who initiated sudo you can call `echo $SUDO_USER`
To get its home directory:
```
getent passwd $SUDO_USER | cut -d: -f6
``` |
58783530 | Powershell script to list all open Explorer windows | 9 | 2019-11-09 21:11:21 | <p><a href="https://stackoverflow.com/questions/31347905/get-report-of-all-open-explorer-windows">This question</a> shows a Powershell script to generate a list of open File Explorer windows and their path.
My goal is to capture the currently open set of explorer windows, and write out a CMD file with commands like: C... | 4,173 | 82,287 | 2021-08-05 17:00:24 | 58,783,790 | 11 | 2019-11-09 21:46:44 | 45,375 | 2021-08-05 17:00:24 | https://stackoverflow.com/q/58783530 | https://stackoverflow.com/a/58783790 | <p>I assume what you're really interested is the <em>local filesystem paths</em> of the open Explorer windows, not necessarily the window titles (which aren't guaranteed to reflect the full paths).</p>
<p>Somewhat obscurely, the window objects returned by the <code>.Windows()</code> method contain the local path repres... | <p>I assume what you're really interested is the <em>local filesystem paths</em> of the open Explorer windows, not necessarily the window titles (which aren't guaranteed to reflect the full paths).</p> <p>Somewhat obscurely, the window objects returned by the <code>.Windows()</code> method contain the local path repres... | 64, 526, 638 | explorer, powershell, windows | <h1>Powershell script to list all open Explorer windows</h1>
<p><a href="https://stackoverflow.com/questions/31347905/get-report-of-all-open-explorer-windows">This question</a> shows a Powershell script to generate a list of open File Explorer windows and their path.
My goal is to capture the currently open set of exp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,397 | bash | # Powershell script to list all open Explorer windows
[This question](https://stackoverflow.com/questions/31347905/get-report-of-all-open-explorer-windows) shows a Powershell script to generate a list of open File Explorer windows and their path.
My goal is to capture the currently open set of explorer windows, and wr... | I assume what you're really interested is the *local filesystem paths* of the open Explorer windows, not necessarily the window titles (which aren't guaranteed to reflect the full paths).
Somewhat obscurely, the window objects returned by the `.Windows()` method contain the local path representation in their `.Documen... |
52484213 | Using nested command substitution in jenkins pipeline sh step | 9 | 2018-09-24 17:06:15 | <p>I'm trying to flatten a results directory prior to archiving using a symbolic link to the relevant inner folder that first traverses a bunch of variable path names determined at runtime. I can't quite seem to get the syntax right with this command substitution approach I picked up from this SO <a href="https://stack... | 7,906 | 1,330,381 | 2018-09-24 17:20:02 | 52,484,384 | 11 | 2018-09-24 17:20:02 | 1,330,381 | 2018-09-24 17:20:02 | https://stackoverflow.com/q/52484213 | https://stackoverflow.com/a/52484384 | <p>Couple of interesting strategies around this problem</p>
<p>Decompose long <code>sh</code> scripts into distinct functional pieces with return values</p>
<p><a href="https://stackoverflow.com/a/47394132/1330381">https://stackoverflow.com/a/47394132/1330381</a></p>
<p>Escape nested shell commands with backslash <c... | <p>Couple of interesting strategies around this problem</p> <p>Decompose long <code>sh</code> scripts into distinct functional pieces with return values</p> <p><a href="https://stackoverflow.com/a/47394132/1330381">https://stackoverflow.com/a/47394132/1330381</a></p> <p>Escape nested shell commands with backslash <c... | 10327, 64999, 118285 | jenkins, jenkins-pipeline, sh | <h1>Using nested command substitution in jenkins pipeline sh step</h1>
<p>I'm trying to flatten a results directory prior to archiving using a symbolic link to the relevant inner folder that first traverses a bunch of variable path names determined at runtime. I can't quite seem to get the syntax right with this comman... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,398 | bash | # Using nested command substitution in jenkins pipeline sh step
I'm trying to flatten a results directory prior to archiving using a symbolic link to the relevant inner folder that first traverses a bunch of variable path names determined at runtime. I can't quite seem to get the syntax right with this command substit... | Couple of interesting strategies around this problem
Decompose long `sh` scripts into distinct functional pieces with return values
<https://stackoverflow.com/a/47394132/1330381>
Escape nested shell commands with backslash `\$`,
```
sh """
\$(echo TEST this subshell \$(ls .))
"""
```
<https://stackoverflow.com... |
48412482 | Binance REST API Timestamp for this request is outside of the recvWindow | 9 | 2018-01-23 23:23:17 | <p>I started testing out the Binance REST API recently but have been unable to get any account info. I consistently receive the same error <em>Code -1021 Timestamp for this request is outside of the recvWindow</em>. Not sure what the issue could be. I have triple checked that my system is synced with NTP and it matches... | 19,495 | null | 2018-01-25 00:01:12 | 48,428,480 | 11 | 2018-01-24 17:33:58 | 9,263,532 | 2018-01-24 17:33:58 | https://stackoverflow.com/q/48412482 | https://stackoverflow.com/a/48428480 | <p>You'll need to multiply date +%s times 1000 so you get miliseconds, because:</p>
<pre><code>man date
%s seconds since 1970-01-01 00:00:00 UTC
</code></pre>
<p>and that's seconds.</p>
<p>So I took liberty to edit your code:</p>
<pre><code>#!/bin/bash
read APIKEY APISECRET <<< $(cat apibinance | cut -... | <p>You'll need to multiply date +%s times 1000 so you get miliseconds, because:</p> <pre><code>man date %s seconds since 1970-01-01 00:00:00 UTC </code></pre> <p>and that's seconds.</p> <p>So I took liberty to edit your code:</p> <pre><code>#!/bin/bash read APIKEY APISECRET <<< $(cat apibinance | cut -... | 364, 387, 10327 | bash, rest, sh | <h1>Binance REST API Timestamp for this request is outside of the recvWindow</h1>
<p>I started testing out the Binance REST API recently but have been unable to get any account info. I consistently receive the same error <em>Code -1021 Timestamp for this request is outside of the recvWindow</em>. Not sure what the issu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,399 | bash | # Binance REST API Timestamp for this request is outside of the recvWindow
I started testing out the Binance REST API recently but have been unable to get any account info. I consistently receive the same error *Code -1021 Timestamp for this request is outside of the recvWindow*. Not sure what the issue could be. I ha... | You'll need to multiply date +%s times 1000 so you get miliseconds, because:
```
man date
%s seconds since 1970-01-01 00:00:00 UTC
```
and that's seconds.
So I took liberty to edit your code:
```
#!/bin/bash
read APIKEY APISECRET <<< $(cat apibinance | cut -f2 -d " ");
RECVWINDOW=50000
RECVWINDOW="recvWindow=$... |
44062627 | zip folder in bash | 9 | 2017-05-19 06:11:50 | <p>I have the files and folder like the below:</p>
<pre><code>/myproject/config/1.xml
/myproject/src/1.py
</code></pre>
<p>I now zip the file like this using bash script:</p>
<pre><code>cd myproject
zip -9 -r -q myfile.zip ./src/*
zip -9 -q myfile.zip ./config/1.xml
</code></pre>
<p>The zip file has 2 folders now, ... | 8,832 | 778,932 | 2017-05-19 06:31:11 | 44,062,764 | 11 | 2017-05-19 06:20:47 | 6,394,138 | 2017-05-19 06:31:11 | https://stackoverflow.com/q/44062627 | https://stackoverflow.com/a/44062764 | <p>In order to build a desired hierarchy inside the zipped archive you must pass to zip relative paths representing such a hierarchy. In your case <code>./src</code> and <code>../config</code> appear as different levels and this is reflected in the resulting archive. In order to make <code>config</code> and <code>src</... | <p>In order to build a desired hierarchy inside the zipped archive you must pass to zip relative paths representing such a hierarchy. In your case <code>./src</code> and <code>../config</code> appear as different levels and this is reflected in the resulting archive. In order to make <code>config</code> and <code>src</... | 387, 881 | bash, zip | <h1>zip folder in bash</h1>
<p>I have the files and folder like the below:</p>
<pre><code>/myproject/config/1.xml
/myproject/src/1.py
</code></pre>
<p>I now zip the file like this using bash script:</p>
<pre><code>cd myproject
zip -9 -r -q myfile.zip ./src/*
zip -9 -q myfile.zip ./config/1.xml
</code></pre>
<p>The ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,400 | bash | # zip folder in bash
I have the files and folder like the below:
```
/myproject/config/1.xml
/myproject/src/1.py
```
I now zip the file like this using bash script:
```
cd myproject
zip -9 -r -q myfile.zip ./src/*
zip -9 -q myfile.zip ./config/1.xml
```
The zip file has 2 folders now, 1 config and 1.xml in it and ... | In order to build a desired hierarchy inside the zipped archive you must pass to zip relative paths representing such a hierarchy. In your case `./src` and `../config` appear as different levels and this is reflected in the resulting archive. In order to make `config` and `src` appear on the same level, you must add an... |
19741957 | Emacs: why shell-command "git log" works, but "git shortlog" doesn't? | 9 | 2013-11-02 12:36:13 | <p>I can't figure this out. Why do these behave differently:</p>
<pre><code>(shell-command "git log")
(shell-command "git shortlog")
</code></pre>
<p>First one works as expected: returns 0 and prints stuff to shell output buffer.
Second one returns 0 but prints nothing. Why is that?</p>
<p>Also</p>
<ol>
<li>both <c... | 1,464 | 1,350,992 | 2017-03-27 09:17:39 | 43,042,420 | 11 | 2017-03-27 09:17:39 | 1,084,174 | 2017-03-27 09:17:39 | https://stackoverflow.com/q/19741957 | https://stackoverflow.com/a/43042420 | <p><code>man git-shortlog</code></p>
<blockquote>
<p>If no revisions are passed on the command line and either standard
input is not a terminal or there is no
current branch, git shortlog will output a summary of the log read from standard input, without reference to
the current repository.</p>
<... | <p><code>man git-shortlog</code></p> <blockquote> <p>If no revisions are passed on the command line and either standard input is not a terminal or there is no current branch, git shortlog will output a summary of the log read from standard input, without reference to the current repository.</p> <... | 119, 371, 390, 3246 | elisp, emacs, git, shell | <h1>Emacs: why shell-command "git log" works, but "git shortlog" doesn't?</h1>
<p>I can't figure this out. Why do these behave differently:</p>
<pre><code>(shell-command "git log")
(shell-command "git shortlog")
</code></pre>
<p>First one works as expected: returns 0 and prints stuff to shell output buffer.
Second on... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,401 | bash | # Emacs: why shell-command "git log" works, but "git shortlog" doesn't?
I can't figure this out. Why do these behave differently:
```
(shell-command "git log")
(shell-command "git shortlog")
```
First one works as expected: returns 0 and prints stuff to shell output buffer.
Second one returns 0 but prints nothing. W... | `man git-shortlog`
> If no revisions are passed on the command line and either standard
> input is not a terminal or there is no
> current branch, git shortlog will output a summary of the log read from standard input, without reference to
> the current repository.
You must explicitly provide reference to work in you... |
42635429 | How to parse a string with multiple characters to split on-Bash Scripting | 9 | 2017-03-06 20:59:30 | <p>I have a text file with the following contents:</p>
<blockquote>
<p>folder4/file2folder4.txt >> folder2/folder2_1/file1folder2.txt</p>
</blockquote>
<p>I have a script that parses each lines as follows</p>
<pre><code>while IFS=" >> " read -r src dest
do
if [ "$src" != "&quo... | 9,801 | 4,805,839 | 2017-03-06 21:18:03 | 42,635,720 | 11 | 2017-03-06 21:16:54 | 1,126,841 | 2017-03-06 21:16:54 | https://stackoverflow.com/q/42635429 | https://stackoverflow.com/a/42635720 | <p><code>IFS</code> is not a single, multicharcter delimiter; instead, it is a collection of single-character delimiters. You can use a regular expression to break apart two fields separated by an arbitrary delimiter.</p>
<pre><code>regex='(.*) >> (.*)'
while IFS= read -r line dest
do
[[ $line =~ $regex ]] ... | <p><code>IFS</code> is not a single, multicharcter delimiter; instead, it is a collection of single-character delimiters. You can use a regular expression to break apart two fields separated by an arbitrary delimiter.</p> <pre><code>regex='(.*) >> (.*)' while IFS= read -r line dest do [[ $line =~ $regex ]] ... | 387 | bash | <h1>How to parse a string with multiple characters to split on-Bash Scripting</h1>
<p>I have a text file with the following contents:</p>
<blockquote>
<p>folder4/file2folder4.txt >> folder2/folder2_1/file1folder2.txt</p>
</blockquote>
<p>I have a script that parses each lines as follows</p>
<pre><code>while IFS=&... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,402 | bash | # How to parse a string with multiple characters to split on-Bash Scripting
I have a text file with the following contents:
> folder4/file2folder4.txt >> folder2/folder2_1/file1folder2.txt
I have a script that parses each lines as follows
```
while IFS=" >> " read -r src dest
do
if [ "$src" != "" ]; then
... | `IFS` is not a single, multicharcter delimiter; instead, it is a collection of single-character delimiters. You can use a regular expression to break apart two fields separated by an arbitrary delimiter.
```
regex='(.*) >> (.*)'
while IFS= read -r line dest
do
[[ $line =~ $regex ]] || continue
src=${BASH_REMA... |
41639739 | Get hibernate status | 9 | 2017-01-13 16:57:56 | <p>Is it possible to get hibernation status using shell ?</p>
<p>I am using <code>powercfg.exe</code> to enable/disable it and there doesn't seem to be any way to get the status, even using /Q (query).</p>
<p>I also tried to base that on existence of <code>%SystemDrive%\hiberfil.sys</code> but that requires admin rig... | 28,308 | 82,660 | 2019-11-19 17:14:56 | 41,639,864 | 11 | 2017-01-13 17:05:56 | 6,788,803 | 2017-01-13 17:05:56 | https://stackoverflow.com/q/41639739 | https://stackoverflow.com/a/41639864 | <p>You could check the registry key:</p>
<pre><code>Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Power -name HibernateEnabled
</code></pre>
<p>Or remotely using .Net and Remote Registry:</p>
<pre><code>$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "ExampleComputer")
$RegKey = $Re... | <p>You could check the registry key:</p> <pre><code>Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Power -name HibernateEnabled </code></pre> <p>Or remotely using .Net and Remote Registry:</p> <pre><code>$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "ExampleComputer") $RegKey = $Re... | 526, 2631 | cmd, powershell | <h1>Get hibernate status</h1>
<p>Is it possible to get hibernation status using shell ?</p>
<p>I am using <code>powercfg.exe</code> to enable/disable it and there doesn't seem to be any way to get the status, even using /Q (query).</p>
<p>I also tried to base that on existence of <code>%SystemDrive%\hiberfil.sys</cod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,403 | bash | # Get hibernate status
Is it possible to get hibernation status using shell ?
I am using `powercfg.exe` to enable/disable it and there doesn't seem to be any way to get the status, even using /Q (query).
I also tried to base that on existence of `%SystemDrive%\hiberfil.sys` but that requires admin rights.
## EDIT
... | You could check the registry key:
```
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Power -name HibernateEnabled
```
Or remotely using .Net and Remote Registry:
```
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "ExampleComputer")
$RegKey = $Reg.OpenSubKey("SYSTEM\\CurrentControlSe... |
41298624 | PHP running multiple scripts concurrently | 9 | 2016-12-23 09:25:49 | <p>I have an array with object server like this:</p>
<pre><code>Array
(
[0](
(
[id] => 1
[version] => 1
[server_addr] => 192.168.5.210
[server_name] => server1
)
)
[1](
... | 6,728 | 6,438,201 | 2016-12-29 04:23:29 | 41,338,163 | 11 | 2016-12-27 02:09:48 | 7,284,356 | 2016-12-28 07:38:35 | https://stackoverflow.com/q/41298624 | https://stackoverflow.com/a/41338163 | <p>You can run your scripts simultaneously with <code>popen()</code> and grab the output later with <code>fread()</code>.</p>
<pre><code>//execute
foreach ($model as $server) {
$server->handles = [
popen('sudo path/to/total_cpu_usage.sh '.$server->server_addr, 'r'),
popen('sudo path/to/total_... | <p>You can run your scripts simultaneously with <code>popen()</code> and grab the output later with <code>fread()</code>.</p> <pre><code>//execute foreach ($model as $server) { $server->handles = [ popen('sudo path/to/total_cpu_usage.sh '.$server->server_addr, 'r'), popen('sudo path/to/total_... | 5, 390, 631, 7932, 8646 | exec, foreach, php, shell, shell-exec | <h1>PHP running multiple scripts concurrently</h1>
<p>I have an array with object server like this:</p>
<pre><code>Array
(
[0](
(
[id] => 1
[version] => 1
[server_addr] => 192.168.5.210
[server_name] => serv... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,404 | bash | # PHP running multiple scripts concurrently
I have an array with object server like this:
```
Array
(
[0](
(
[id] => 1
[version] => 1
[server_addr] => 192.168.5.210
[server_name] => server1
)
)
... | You can run your scripts simultaneously with `popen()` and grab the output later with `fread()`.
```
//execute
foreach ($model as $server) {
$server->handles = [
popen('sudo path/to/total_cpu_usage.sh '.$server->server_addr, 'r'),
popen('sudo path/to/total_memory_usage.sh '.$server->server_addr, 'r... |
40602706 | Batch reduce bitrate and size of mp3 audio files with ffmpeg | 9 | 2016-11-15 05:33:01 | <p>I was looking for a way to batch reduce mp3 bitrate on my sizable collection of mp3 files. It was surprising difficult given that this must be a super common thing to want to do. </p>
<p>In fact, there are dozens, maybe hundreds, of posts from people asking how to do it, and dozens of utilities available for varyin... | 10,539 | 2,386,836 | 2024-03-27 19:05:48 | 40,668,427 | 11 | 2016-11-18 02:29:41 | 2,386,836 | 2024-03-27 19:05:48 | https://stackoverflow.com/q/40602706 | https://stackoverflow.com/a/40668427 | <p>It took a bit of fiddling to get the right ffmpeg and find options, but this should do it.</p>
<pre><code>#!/bin/bash
MUSIC="FULL PATH TO YOUR MUSIC FOLDER"
BITRATE=160k
find "${MUSIC}" -name "*.mp3" \
-execdir echo "{}" \; \
-exec mv "{}" "{}.mp3" \; \... | <p>It took a bit of fiddling to get the right ffmpeg and find options, but this should do it.</p> <pre><code>#!/bin/bash MUSIC="FULL PATH TO YOUR MUSIC FOLDER" BITRATE=160k find "${MUSIC}" -name "*.mp3" \ -execdir echo "{}" \; \ -exec mv "{}" "{}.mp3" \; \... | 387, 1033, 3847, 24342 | bash, bitrate, ffmpeg, mp3 | <h1>Batch reduce bitrate and size of mp3 audio files with ffmpeg</h1>
<p>I was looking for a way to batch reduce mp3 bitrate on my sizable collection of mp3 files. It was surprising difficult given that this must be a super common thing to want to do. </p>
<p>In fact, there are dozens, maybe hundreds, of posts from pe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,405 | bash | # Batch reduce bitrate and size of mp3 audio files with ffmpeg
I was looking for a way to batch reduce mp3 bitrate on my sizable collection of mp3 files. It was surprising difficult given that this must be a super common thing to want to do.
In fact, there are dozens, maybe hundreds, of posts from people asking how t... | It took a bit of fiddling to get the right ffmpeg and find options, but this should do it.
```
#!/bin/bash
MUSIC="FULL PATH TO YOUR MUSIC FOLDER"
BITRATE=160k
find "${MUSIC}" -name "*.mp3" \
-execdir echo "{}" \; \
-exec mv "{}" "{}.mp3" \; \
-exec ffmpeg -y -loglevel "error" -i "{}.mp3" -acodec libmp3lame -ab ... |
38662506 | Bash script size limitation? | 9 | 2016-07-29 15:31:28 | <p>I have a bash script that, when run on RHEL or OS X, gives the following error:</p>
<blockquote>
<p>line 62484: syntax error near unexpected token `newline'</p>
<p>line 62484: ` -o_gz'</p>
</blockquote>
<p>This is an auto-generated script to work around a limitation introduced by the grid engine compute cluster ... | 2,972 | 2,851,999 | 2016-07-29 19:51:46 | 38,662,878 | 11 | 2016-07-29 15:51:12 | 1,566,221 | 2016-07-29 19:51:46 | https://stackoverflow.com/q/38662506 | https://stackoverflow.com/a/38662878 | <p>Yes, this is a limitation with <code>bash</code>.</p>
<p>It's not a script size limit; rather it's a limit to the depth of the parser stack, which has the effect of restricting the complexity of certain constructs. In particular, it will restrict the number of <code>elif</code> clauses in an <code>if</code> stateme... | <p>Yes, this is a limitation with <code>bash</code>.</p> <p>It's not a script size limit; rather it's a limit to the depth of the parser stack, which has the effect of restricting the complexity of certain constructs. In particular, it will restrict the number of <code>elif</code> clauses in an <code>if</code> stateme... | 387, 390, 531, 107339 | bash, rhel6, scripting, shell | <h1>Bash script size limitation?</h1>
<p>I have a bash script that, when run on RHEL or OS X, gives the following error:</p>
<blockquote>
<p>line 62484: syntax error near unexpected token `newline'</p>
<p>line 62484: ` -o_gz'</p>
</blockquote>
<p>This is an auto-generated script to work around a limitation introduc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,406 | bash | # Bash script size limitation?
I have a bash script that, when run on RHEL or OS X, gives the following error:
> line 62484: syntax error near unexpected token `newline'
>
> line 62484: ` -o_gz'
This is an auto-generated script to work around a limitation introduced by the grid engine compute cluster used in my comp... | Yes, this is a limitation with `bash`.
It's not a script size limit; rather it's a limit to the depth of the parser stack, which has the effect of restricting the complexity of certain constructs. In particular, it will restrict the number of `elif` clauses in an `if` statement to about 2500.
There is a longer analys... |
36772569 | Printing with Powershell and files in folders | 9 | 2016-04-21 14:25:06 | <p>I have a script which does some onsite printing. It doesnt work too well at the moment as the below runs for various file types which are sent to a folder to print, but the problem is it will only print 1 document at a time. </p>
<pre><code>Start-Process –FilePath “c:\tests\*.docx” –Verb Print
</code></pre>
<... | 27,081 | 4,691,676 | 2021-05-13 18:30:32 | 36,774,439 | 11 | 2016-04-21 15:40:50 | 6,204,605 | 2021-05-13 18:30:32 | https://stackoverflow.com/q/36772569 | https://stackoverflow.com/a/36774439 | <p>You are very close, <code>start-process</code> needs the full path and name of the file:</p>
<pre><code>Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print}
</code></pre>
<p>Using a foreach loop should help you too:</p>
<pre><code>$files = Get-ChildItem "c:\tests\*.... | <p>You are very close, <code>start-process</code> needs the full path and name of the file:</p> <pre><code>Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print} </code></pre> <p>Using a foreach loop should help you too:</p> <pre><code>$files = Get-ChildItem "c:\tests\*.... | 87, 526 | powershell, printing | <h1>Printing with Powershell and files in folders</h1>
<p>I have a script which does some onsite printing. It doesnt work too well at the moment as the below runs for various file types which are sent to a folder to print, but the problem is it will only print 1 document at a time. </p>
<pre><code>Start-Process –... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,407 | bash | # Printing with Powershell and files in folders
I have a script which does some onsite printing. It doesnt work too well at the moment as the below runs for various file types which are sent to a folder to print, but the problem is it will only print 1 document at a time.
```
Start-Process –FilePath “c:\tests\*.docx”... | You are very close, `start-process` needs the full path and name of the file:
```
Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print}
```
Using a foreach loop should help you too:
```
$files = Get-ChildItem "c:\tests\*.docx"
foreach ($file in $files){
start-process -FilePath... |
36025696 | Break out of inner loop only in nested loop | 9 | 2016-03-16 02:16:12 | <p>I'm trying to implement a break so I don't have to continue to loop when I got the result xxxxx times.</p>
<pre><code>$baseFileCsvContents | ForEach-Object {
# Do stuff
$fileToBeMergedCsvContents | ForEach-Object {
If ($_.SamAccountName -eq $baseSameAccountName) {
# Do something
... | 7,079 | 2,150,879 | 2020-05-26 15:37:31 | 36,025,915 | 11 | 2016-03-16 02:43:33 | 613,928 | 2016-03-16 02:43:33 | https://stackoverflow.com/q/36025696 | https://stackoverflow.com/a/36025915 | <p>You won't be able to use a named loop with ForEach-Object, but can do it using the ForEach keyword instead like so:</p>
<pre><code>$OuterLoop = 1..10
$InnerLoop = 25..50
$OuterLoop | ForEach-Object {
Write-Verbose "[OuterLoop] $($_)" -Verbose
:inner
ForEach ($Item in $InnerLoop) {
Write-Verbose... | <p>You won't be able to use a named loop with ForEach-Object, but can do it using the ForEach keyword instead like so:</p> <pre><code>$OuterLoop = 1..10 $InnerLoop = 25..50 $OuterLoop | ForEach-Object { Write-Verbose "[OuterLoop] $($_)" -Verbose :inner ForEach ($Item in $InnerLoop) { Write-Verbose... | 526, 73157 | powershell, powershell-3.0 | <h1>Break out of inner loop only in nested loop</h1>
<p>I'm trying to implement a break so I don't have to continue to loop when I got the result xxxxx times.</p>
<pre><code>$baseFileCsvContents | ForEach-Object {
# Do stuff
$fileToBeMergedCsvContents | ForEach-Object {
If ($_.SamAccountName -eq $baseS... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,408 | bash | # Break out of inner loop only in nested loop
I'm trying to implement a break so I don't have to continue to loop when I got the result xxxxx times.
```
$baseFileCsvContents | ForEach-Object {
# Do stuff
$fileToBeMergedCsvContents | ForEach-Object {
If ($_.SamAccountName -eq $baseSameAccountName) {
... | You won't be able to use a named loop with ForEach-Object, but can do it using the ForEach keyword instead like so:
```
$OuterLoop = 1..10
$InnerLoop = 25..50
$OuterLoop | ForEach-Object {
Write-Verbose "[OuterLoop] $($_)" -Verbose
:inner
ForEach ($Item in $InnerLoop) {
Write-Verbose "[InnerLoop] ... |
32910416 | Modify PRODUCT_BUNDLE_IDENTIFIER in project.pbxproj of Xcode | 9 | 2015-10-02 15:14:51 | <p>I'm trying to modify the <code>project.pbxproj</code> file of Xcode project using <code>sed</code> shell command on Mac Terminal to replace a string. I want to replace the field -</p>
<p><code>PRODUCT_BUNDLE_IDENTIFIER = com.example.71b9b4f2</code></p>
<p>to</p>
<p><code>PRODUCT_BUNDLE_IDENTIFIER = com.example.14... | 6,718 | 4,143,202 | 2017-12-08 06:24:59 | 32,911,494 | 11 | 2015-10-02 16:15:54 | 3,789,676 | 2015-10-02 16:15:54 | https://stackoverflow.com/q/32910416 | https://stackoverflow.com/a/32911494 | <p>OSX requires the extension to be explicitly specified. The workaround is to set an empty string:</p>
<pre><code>sed -i '' 's/com.example.71b94f2/com.example.14a32d1e/g' project.pbxproj
</code></pre>
| <p>OSX requires the extension to be explicitly specified. The workaround is to set an empty string:</p> <pre><code>sed -i '' 's/com.example.71b94f2/com.example.14a32d1e/g' project.pbxproj </code></pre> | 34, 387, 5282, 14860, 112538 | bash, plist, sed, unix, xcode7 | <h1>Modify PRODUCT_BUNDLE_IDENTIFIER in project.pbxproj of Xcode</h1>
<p>I'm trying to modify the <code>project.pbxproj</code> file of Xcode project using <code>sed</code> shell command on Mac Terminal to replace a string. I want to replace the field -</p>
<p><code>PRODUCT_BUNDLE_IDENTIFIER = com.example.71b9b4f2</cod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,409 | bash | # Modify PRODUCT_BUNDLE_IDENTIFIER in project.pbxproj of Xcode
I'm trying to modify the `project.pbxproj` file of Xcode project using `sed` shell command on Mac Terminal to replace a string. I want to replace the field -
`PRODUCT_BUNDLE_IDENTIFIER = com.example.71b9b4f2`
to
`PRODUCT_BUNDLE_IDENTIFIER = com.example.... | OSX requires the extension to be explicitly specified. The workaround is to set an empty string:
```
sed -i '' 's/com.example.71b94f2/com.example.14a32d1e/g' project.pbxproj
``` |
31861398 | Redirecting printf to file in awk | 9 | 2015-08-06 16:45:58 | <p>I have a simple bash script.</p>
<p>It's purpose is to monitor http access log file (test.log) and output to a file (out.log) the updated hit rate:</p>
<pre><code> stdbuf -o0 tail -f test.log | awk -F'[ "]+' '{
ipcount[$1]++;
print "test" > "out.log"; #Truncate out.log
for (i in ipcount) {
printf... | 22,732 | 3,606,470 | 2015-08-06 20:37:36 | 31,865,237 | 11 | 2015-08-06 20:31:24 | 477,563 | 2015-08-06 20:37:36 | https://stackoverflow.com/q/31861398 | https://stackoverflow.com/a/31865237 | <p>This should work for you:</p>
<pre><code>tail -f test.log | awk -F'[ "]+' -v out_file="out.log" '{
val_count[$1]++
print "" > out_file
for (i in val_count) {
printf "%15s - %d\n", i, val_count[i] >> out_file
printf "%15s - %d\n", i, val_count[i]
}
close(out_file)
}'
</... | <p>This should work for you:</p> <pre><code>tail -f test.log | awk -F'[ "]+' -v out_file="out.log" '{ val_count[$1]++ print "" > out_file for (i in val_count) { printf "%15s - %d\n", i, val_count[i] >> out_file printf "%15s - %d\n", i, val_count[i] } close(out_file) }' </... | 58, 387, 990 | awk, bash, linux | <h1>Redirecting printf to file in awk</h1>
<p>I have a simple bash script.</p>
<p>It's purpose is to monitor http access log file (test.log) and output to a file (out.log) the updated hit rate:</p>
<pre><code> stdbuf -o0 tail -f test.log | awk -F'[ "]+' '{
ipcount[$1]++;
print "test" > "out.log"; #Truncate ou... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,410 | bash | # Redirecting printf to file in awk
I have a simple bash script.
It's purpose is to monitor http access log file (test.log) and output to a file (out.log) the updated hit rate:
```
stdbuf -o0 tail -f test.log | awk -F'[ "]+' '{
ipcount[$1]++;
print "test" > "out.log"; #Truncate out.log
for (i in ipcount) {
... | This should work for you:
```
tail -f test.log | awk -F'[ "]+' -v out_file="out.log" '{
val_count[$1]++
print "" > out_file
for (i in val_count) {
printf "%15s - %d\n", i, val_count[i] >> out_file
printf "%15s - %d\n", i, val_count[i]
}
close(out_file)
}'
```
(Note: I moved the o... |
31489519 | omit passing an empty quoted argument | 9 | 2015-07-18 09:00:17 | <p>I have some variables in a bash script that may contain a file name or be unset. Their content should be passed as an additional argument to a program. But this leaves an empty argument when the variable is unset.</p>
<pre><code>$ afile=/dev/null
$ anotherfile=/dev/null
$ unset empty
$ cat "$afile" "$empty" "$anoth... | 1,840 | 1,018,226 | 2015-07-18 15:04:47 | 31,492,495 | 11 | 2015-07-18 15:04:47 | 89,817 | 2015-07-18 15:04:47 | https://stackoverflow.com/q/31489519 | https://stackoverflow.com/a/31492495 | <p>You can use an <a href="http://wiki.bash-hackers.org/syntax/pe#use_an_alternate_value" rel="noreferrer">alternate value parameter expansion</a> (<code>${var+altvalue}</code>) to include the quoted variable IF it's set:</p>
<pre><code>cat ${afile+"$afile"} ${empty+"$empty"} ${anotherfile+"$anotherfile"}
</code></pre... | <p>You can use an <a href="http://wiki.bash-hackers.org/syntax/pe#use_an_alternate_value" rel="noreferrer">alternate value parameter expansion</a> (<code>${var+altvalue}</code>) to include the quoted variable IF it's set:</p> <pre><code>cat ${afile+"$afile"} ${empty+"$empty"} ${anotherfile+"$anotherfile"} </code></pre... | 387, 2313, 18362, 19749 | argument-passing, arguments, bash, variable-expansion | <h1>omit passing an empty quoted argument</h1>
<p>I have some variables in a bash script that may contain a file name or be unset. Their content should be passed as an additional argument to a program. But this leaves an empty argument when the variable is unset.</p>
<pre><code>$ afile=/dev/null
$ anotherfile=/dev/nul... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,411 | bash | # omit passing an empty quoted argument
I have some variables in a bash script that may contain a file name or be unset. Their content should be passed as an additional argument to a program. But this leaves an empty argument when the variable is unset.
```
$ afile=/dev/null
$ anotherfile=/dev/null
$ unset empty
$ ca... | You can use an [alternate value parameter expansion](http://wiki.bash-hackers.org/syntax/pe#use_an_alternate_value) (`${var+altvalue}`) to include the quoted variable IF it's set:
```
cat ${afile+"$afile"} ${empty+"$empty"} ${anotherfile+"$anotherfile"}
```
Since the double-quotes are in the alternate value string (n... |
30180209 | Sorting lines in one file given the order in another file | 9 | 2015-05-12 01:21:35 | <p>Given a file1:</p>
<pre><code>13 a b c d
5 f a c d
7 d c g a
14 a v s d
</code></pre>
<p>and a file2:</p>
<pre><code>7 x
5 c
14 a
13 i
</code></pre>
<p>I would like to sort file1 considering the same order of the first column in file2, so that the output should be:</p>
<pre><code>7 d c g a
5 f a c d
14 a v s d
... | 3,105 | 1,391,371 | 2019-09-28 13:34:02 | 30,180,282 | 11 | 2015-05-12 01:30:36 | 1,491,895 | 2015-05-12 01:30:36 | https://stackoverflow.com/q/30180209 | https://stackoverflow.com/a/30180282 | <p>Use <code>awk</code> to put the line number from <code>file2</code> as an extra column in front of <code>file1</code>. Sort the result by that column. Then remove that prefix column</p>
<pre><code>awk 'FNR == NR { lineno[$1] = NR; next}
{print lineno[$1], $0;}' file2 file1 | sort -k 1,1n | cut -d' ' -f2-
</cod... | <p>Use <code>awk</code> to put the line number from <code>file2</code> as an extra column in front of <code>file1</code>. Sort the result by that column. Then remove that prefix column</p> <pre><code>awk 'FNR == NR { lineno[$1] = NR; next} {print lineno[$1], $0;}' file2 file1 | sort -k 1,1n | cut -d' ' -f2- </cod... | 134, 387, 5310 | bash, file, sorting | <h1>Sorting lines in one file given the order in another file</h1>
<p>Given a file1:</p>
<pre><code>13 a b c d
5 f a c d
7 d c g a
14 a v s d
</code></pre>
<p>and a file2:</p>
<pre><code>7 x
5 c
14 a
13 i
</code></pre>
<p>I would like to sort file1 considering the same order of the first column in file2, so that th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,412 | bash | # Sorting lines in one file given the order in another file
Given a file1:
```
13 a b c d
5 f a c d
7 d c g a
14 a v s d
```
and a file2:
```
7 x
5 c
14 a
13 i
```
I would like to sort file1 considering the same order of the first column in file2, so that the output should be:
```
7 d c g a
5 f a c d
14 a v s d
1... | Use `awk` to put the line number from `file2` as an extra column in front of `file1`. Sort the result by that column. Then remove that prefix column
```
awk 'FNR == NR { lineno[$1] = NR; next}
{print lineno[$1], $0;}' file2 file1 | sort -k 1,1n | cut -d' ' -f2-
``` |
29621584 | Parsing a curl json response and using response to build another request | 9 | 2015-04-14 07:32:52 | <p>I am trying to build an shell script that will fetch the image url for a random XKCD comic, so that I can display it using Übersicht. Since you can only ask the XKCD API for the latest comic or a specific comic I need to:</p>
<ol>
<li>Send a <code>GET</code> request to <code>http://xkcd.com/info.0.json</code>, fetc... | 34,279 | 407,397 | 2017-03-01 18:46:39 | 29,621,890 | 11 | 2015-04-14 07:51:31 | 1,944,784 | 2017-03-01 18:46:39 | https://stackoverflow.com/q/29621584 | https://stackoverflow.com/a/29621890 | <ol>
<li><p>On OS X you can use the system Perl:</p>
<pre><code> curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe 's/.*"num": ([0-9]+).*/\1/'
</code></pre></li>
<li><p>You can save the output to a variable with command substitution:</p>
<pre><code>num=$(curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe... | <ol> <li><p>On OS X you can use the system Perl:</p> <pre><code> curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe 's/.*"num": ([0-9]+).*/\1/' </code></pre></li> <li><p>You can save the output to a variable with command substitution:</p> <pre><code>num=$(curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe... | 387, 1271, 1554 | bash, curl, grep | <h1>Parsing a curl json response and using response to build another request</h1>
<p>I am trying to build an shell script that will fetch the image url for a random XKCD comic, so that I can display it using Übersicht. Since you can only ask the XKCD API for the latest comic or a specific comic I need to:</p>
<ol>
<li... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,413 | bash | # Parsing a curl json response and using response to build another request
I am trying to build an shell script that will fetch the image url for a random XKCD comic, so that I can display it using Übersicht. Since you can only ask the XKCD API for the latest comic or a specific comic I need to:
1. Send a `GET` reque... | 1. On OS X you can use the system Perl:
```
curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe 's/.*"num": ([0-9]+).*/\1/'
```
2. You can save the output to a variable with command substitution:
```
num=$(curl -sS http://xkcd.com/info.0.json | /usr/bin/perl -pe 's/.*"num": ([0-9]+).*/\1/')
cu... |
26720011 | bash verbose string comparison slashes | 9 | 2014-11-03 17:53:21 | <p>I am comparing two strings in a bash script as follows:</p>
<pre><code>x="hello"
y="hello"
if [[ "$x" != "$y" ]]; then
echo "different"
else
echo "same"
fi
</code></pre>
<p>This comparison works. When I execute the script with <code>-x</code>, the comparison still works, but it shows the output</p>
<pre>... | 2,224 | 121,993 | 2014-11-03 17:59:19 | 26,720,102 | 11 | 2014-11-03 17:58:42 | 258,523 | 2014-11-03 17:58:42 | https://stackoverflow.com/q/26720011 | https://stackoverflow.com/a/26720102 | <p>The simple explanation is for the same reason that the left-hand side doesn't have quotes around it.</p>
<p><code>-x</code> is showing you an equivalent but not exact representation of what it ran. The right-hand side of <code>=</code> and <code>!=</code> in <code>[[ ... ]]</code> is matched as a pattern.</p>
<p>F... | <p>The simple explanation is for the same reason that the left-hand side doesn't have quotes around it.</p> <p><code>-x</code> is showing you an equivalent but not exact representation of what it ran. The right-hand side of <code>=</code> and <code>!=</code> in <code>[[ ... ]]</code> is matched as a pattern.</p> <p>F... | 387, 16493 | bash, string-comparison | <h1>bash verbose string comparison slashes</h1>
<p>I am comparing two strings in a bash script as follows:</p>
<pre><code>x="hello"
y="hello"
if [[ "$x" != "$y" ]]; then
echo "different"
else
echo "same"
fi
</code></pre>
<p>This comparison works. When I execute the script with <code>-x</code>, the comparison... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,414 | bash | # bash verbose string comparison slashes
I am comparing two strings in a bash script as follows:
```
x="hello"
y="hello"
if [[ "$x" != "$y" ]]; then
echo "different"
else
echo "same"
fi
```
This comparison works. When I execute the script with `-x`, the comparison still works, but it shows the output
```
+... | The simple explanation is for the same reason that the left-hand side doesn't have quotes around it.
`-x` is showing you an equivalent but not exact representation of what it ran. The right-hand side of `=` and `!=` in `[[ ... ]]` is matched as a pattern.
From the manual:
> When the == and != operators are used, the... |
26124650 | sed use: expected context address | 9 | 2014-09-30 15:31:48 | <p>I use the <code>sed</code> command on macOS with the following text:</p>
<pre><code>$ cat pets.txt
This is my cat
my cat's name is betty
This is your dog
your dog's name is frank
This is your fish
your fish's name is george
This is my goat
my goat's name is adam
</code></pre>
<p>When I run BSD <code>sed</... | 7,532 | 2,693,045 | 2018-06-19 19:53:02 | 26,125,032 | 11 | 2014-09-30 15:51:48 | 797,049 | 2016-11-30 19:22:15 | https://stackoverflow.com/q/26124650 | https://stackoverflow.com/a/26125032 | <p>It works with GNU sed because you're taking advantage of a feature added to sed by the GNU project, which didn't previously exist in the program (and still doesn't in non-GNU versions). </p>
<p>You can achieve the same results in non-GNU sed with something like this:</p>
<pre><code>sed -E '/dog/{N;N;N;s/(^|\n)/&a... | <p>It works with GNU sed because you're taking advantage of a feature added to sed by the GNU project, which didn't previously exist in the program (and still doesn't in non-GNU versions). </p> <p>You can achieve the same results in non-GNU sed with something like this:</p> <pre><code>sed -E '/dog/{N;N;N;s/(^|\n)/&a... | 387, 1423, 4072, 5282 | bash, bsd, gnu, sed | <h1>sed use: expected context address</h1>
<p>I use the <code>sed</code> command on macOS with the following text:</p>
<pre><code>$ cat pets.txt
This is my cat
my cat's name is betty
This is your dog
your dog's name is frank
This is your fish
your fish's name is george
This is my goat
my goat's name is adam
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,415 | bash | # sed use: expected context address
I use the `sed` command on macOS with the following text:
```
$ cat pets.txt
This is my cat
my cat's name is betty
This is your dog
your dog's name is frank
This is your fish
your fish's name is george
This is my goat
my goat's name is adam
```
When I run BSD `sed` it sho... | It works with GNU sed because you're taking advantage of a feature added to sed by the GNU project, which didn't previously exist in the program (and still doesn't in non-GNU versions).
You can achieve the same results in non-GNU sed with something like this:
```
sed -E '/dog/{N;N;N;s/(^|\n)/&# /g;}' pets.txt
```
Th... |
25729304 | Powershell - Prompt user then expire prompt after xx seconds | 9 | 2014-09-08 16:55:19 | <p>I am trying to display a promp for user action and if no action is taken have the prompt close and teh script continue on. here is my command prompt dialog configuraiton</p>
<hr>
<pre><code>$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = New-Object System.Management.Automa... | 10,060 | 3,990,509 | 2018-08-09 06:39:28 | 25,729,960 | 11 | 2014-09-08 17:37:25 | 3,969,198 | 2014-09-08 17:37:25 | https://stackoverflow.com/q/25729304 | https://stackoverflow.com/a/25729960 | <p>Here you go...dug this out of one of my old scripts</p>
<pre><code>#Value Description
#0 Show OK button.
#1 Show OK and Cancel buttons.
#2 Show Abort, Retry, and Ignore buttons.
#3 Show Yes, No, and Cancel buttons.
#4 Show Yes and No buttons.
#5 Show Retry and Cancel buttons.
#http://msdn.microsoft.com/en... | <p>Here you go...dug this out of one of my old scripts</p> <pre><code>#Value Description #0 Show OK button. #1 Show OK and Cancel buttons. #2 Show Abort, Retry, and Ignore buttons. #3 Show Yes, No, and Cancel buttons. #4 Show Yes and No buttons. #5 Show Retry and Cancel buttons. #http://msdn.microsoft.com/en... | 526, 5003, 5909, 6413 | powershell, prompt, timed, timer | <h1>Powershell - Prompt user then expire prompt after xx seconds</h1>
<p>I am trying to display a promp for user action and if no action is taken have the prompt close and teh script continue on. here is my command prompt dialog configuraiton</p>
<hr>
<pre><code>$yes = New-Object System.Management.Automation.Host.Cho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,416 | bash | # Powershell - Prompt user then expire prompt after xx seconds
I am trying to display a promp for user action and if no action is taken have the prompt close and teh script continue on. here is my command prompt dialog configuraiton
---
```
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes"... | Here you go...dug this out of one of my old scripts
```
#Value Description
#0 Show OK button.
#1 Show OK and Cancel buttons.
#2 Show Abort, Retry, and Ignore buttons.
#3 Show Yes, No, and Cancel buttons.
#4 Show Yes and No buttons.
#5 Show Retry and Cancel buttons.
#http://msdn.microsoft.com/en-us/library/x8... |
24388357 | Returning an object from PowerShell cmdlet | 9 | 2014-06-24 13:48:06 | <p>I'm trying to create my own set of cmdlets for a PowerShell snapin. The problem I'm having is that I've created my own object that I create and populate within the ProcessRecord method but I'm not able to change the return type to allow me to return the object that I created. </p>
<pre><code> protected override voi... | 5,572 | 1,865,044 | 2014-06-24 15:27:02 | 24,390,588 | 11 | 2014-06-24 15:27:02 | 681,785 | 2014-06-24 15:27:02 | https://stackoverflow.com/q/24388357 | https://stackoverflow.com/a/24390588 | <p>You don't ever need to return a value from the <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.cmdlet.processrecord(v=vs.85).aspx" rel="noreferrer"><code>Cmdlet.ProcessRecord</code></a> method. This method has it's specific place and way of use in the <a href="http://msdn.microsoft.com/... | <p>You don't ever need to return a value from the <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.cmdlet.processrecord(v=vs.85).aspx" rel="noreferrer"><code>Cmdlet.ProcessRecord</code></a> method. This method has it's specific place and way of use in the <a href="http://msdn.microsoft.com/... | 9, 526, 8799, 153947 | c#, powershell, powershell-cmdlet, return-type | <h1>Returning an object from PowerShell cmdlet</h1>
<p>I'm trying to create my own set of cmdlets for a PowerShell snapin. The problem I'm having is that I've created my own object that I create and populate within the ProcessRecord method but I'm not able to change the return type to allow me to return the object that... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,417 | bash | # Returning an object from PowerShell cmdlet
I'm trying to create my own set of cmdlets for a PowerShell snapin. The problem I'm having is that I've created my own object that I create and populate within the ProcessRecord method but I'm not able to change the return type to allow me to return the object that I create... | You don't ever need to return a value from the [`Cmdlet.ProcessRecord`](http://msdn.microsoft.com/en-us/library/system.management.automation.cmdlet.processrecord(v=vs.85).aspx) method. This method has it's specific place and way of use in the [PowerShell cmdlet processing lifecycle](http://msdn.microsoft.com/en-us/libr... |
24376421 | Passing arguments from command line into a tcl script | 9 | 2014-06-24 00:01:23 | <p>I have a TCL script that has many parameters defined as arguments. I intend to create a job file where I can execute the .tcl script with different combinations of the parameters without manual intervention.</p>
<p>What I mean is the following:</p>
<p>Job File (run.sh):</p>
<pre><code>./main.tcl arg1 arg2 arg3 ar... | 56,043 | 2,784,743 | 2023-05-31 08:50:10 | 24,376,563 | 11 | 2014-06-24 00:21:48 | 4,196,578 | 2021-06-27 06:37:35 | https://stackoverflow.com/q/24376421 | https://stackoverflow.com/a/24376563 | <p>Per <a href="http://www.fundza.com/tcl/script_shell/arguments/index.html" rel="noreferrer">online document here</a>:</p>
<blockquote>
<p>The method by which numbers can be passed into, and used by a script,
is as follows.</p>
<p>argc argv argv0</p>
<p>All Tcl scripts have access to three predefined variables.
$argc ... | <p>Per <a href="http://www.fundza.com/tcl/script_shell/arguments/index.html" rel="noreferrer">online document here</a>:</p> <blockquote> <p>The method by which numbers can be passed into, and used by a script, is as follows.</p> <p>argc argv argv0</p> <p>All Tcl scripts have access to three predefined variables. $argc ... | 387, 5881 | bash, tcl | <h1>Passing arguments from command line into a tcl script</h1>
<p>I have a TCL script that has many parameters defined as arguments. I intend to create a job file where I can execute the .tcl script with different combinations of the parameters without manual intervention.</p>
<p>What I mean is the following:</p>
<p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,418 | bash | # Passing arguments from command line into a tcl script
I have a TCL script that has many parameters defined as arguments. I intend to create a job file where I can execute the .tcl script with different combinations of the parameters without manual intervention.
What I mean is the following:
Job File (run.sh):
```... | Per [online document here](http://www.fundza.com/tcl/script_shell/arguments/index.html):
> The method by which numbers can be passed into, and used by a script,
> is as follows.
>
> argc argv argv0
>
> All Tcl scripts have access to three predefined variables.
> $argc - number items of arguments passed to a script.
> ... |
23581368 | Bug in parsing args with getopts in bash | 9 | 2014-05-10 13:03:58 | <p>I was trying to modify the <a href="https://github.com/vigneshwaranr/bd" rel="noreferrer">bd</a> script to use <code>getopts</code>. I am a newbie at bash scripting</p>
<p>my script is </p>
<pre><code>while getopts ":hvis:d:" opt
do
...
done
...
echo $somedirpath
cd "$somedirpath"
</code></pre>
<p>this runs... | 3,251 | 1,477,750 | 2022-05-26 00:17:31 | 23,615,586 | 11 | 2014-05-12 17:48:55 | 1,477,750 | 2014-05-12 17:48:55 | https://stackoverflow.com/q/23581368 | https://stackoverflow.com/a/23615586 | <p>Setting <code>OPTIND=1</code> before invoking <code>getopts</code> works fine.</p>
<p>The problem is that <code>getopts</code> relies on <code>OPTIND</code> to loop through the arguments provided, and after sourcing the script, it will be set to some value greater than 1 by <code>getopts</code> according to how man... | <p>Setting <code>OPTIND=1</code> before invoking <code>getopts</code> works fine.</p> <p>The problem is that <code>getopts</code> relies on <code>OPTIND</code> to loop through the arguments provided, and after sourcing the script, it will be set to some value greater than 1 by <code>getopts</code> according to how man... | 387, 19020 | bash, getopts | <h1>Bug in parsing args with getopts in bash</h1>
<p>I was trying to modify the <a href="https://github.com/vigneshwaranr/bd" rel="noreferrer">bd</a> script to use <code>getopts</code>. I am a newbie at bash scripting</p>
<p>my script is </p>
<pre><code>while getopts ":hvis:d:" opt
do
...
done
...
echo $somedirpath... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,419 | bash | # Bug in parsing args with getopts in bash
I was trying to modify the [bd](https://github.com/vigneshwaranr/bd) script to use `getopts`. I am a newbie at bash scripting
my script is
```
while getopts ":hvis:d:" opt
do
...
done
...
echo $somedirpath
cd "$somedirpath"
```
this runs fine when doing
```
$ ./bd -v -i... | Setting `OPTIND=1` before invoking `getopts` works fine.
The problem is that `getopts` relies on `OPTIND` to loop through the arguments provided, and after sourcing the script, it will be set to some value greater than 1 by `getopts` according to how many arguments you pass. This value gets carried over even after the... |
22569726 | Bash script to remove dot end of each line | 9 | 2014-03-21 21:19:02 | <p>Unix command to remove dot at end of each line in file.</p>
<p>Sample rec in file </p>
<pre><code>11234567 0.
23456789 5569.
34567810 1.
10162056 0.
</code></pre>
| 14,204 | 3,347,931 | 2014-03-21 21:33:01 | 22,569,748 | 11 | 2014-03-21 21:20:48 | 970,195 | 2014-03-21 21:20:48 | https://stackoverflow.com/q/22569726 | https://stackoverflow.com/a/22569748 | <p>Just use <code>sed</code>:</p>
<pre><code>sed 's/\.$//' yourfile
</code></pre>
<ul>
<li>Escape the special character <code>.</code> using <code>\</code>. </li>
<li>Put an achor <code>$</code> to only remove it from the end. </li>
<li>To make infile changes use <code>-i</code> option of <code>sed</code>. </li>
</ul... | <p>Just use <code>sed</code>:</p> <pre><code>sed 's/\.$//' yourfile </code></pre> <ul> <li>Escape the special character <code>.</code> using <code>\</code>. </li> <li>Put an achor <code>$</code> to only remove it from the end. </li> <li>To make infile changes use <code>-i</code> option of <code>sed</code>. </li> </ul... | 387 | bash | <h1>Bash script to remove dot end of each line</h1>
<p>Unix command to remove dot at end of each line in file.</p>
<p>Sample rec in file </p>
<pre><code>11234567 0.
23456789 5569.
34567810 1.
10162056 0.
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,420 | bash | # Bash script to remove dot end of each line
Unix command to remove dot at end of each line in file.
Sample rec in file
```
11234567 0.
23456789 5569.
34567810 1.
10162056 0.
``` | Just use `sed`:
```
sed 's/\.$//' yourfile
```
- Escape the special character `.` using `\`.
- Put an achor `$` to only remove it from the end.
- To make infile changes use `-i` option of `sed`. |
21150793 | Why is bash swallowing -e in the front of an array | 9 | 2014-01-15 23:54:16 | <p>Given the following syntax:</p>
<pre><code>x=(-a 2);echo "${x[@]}";x=(-e 2 -e); echo "${x[@]}"
</code></pre>
<p>Output:</p>
<pre><code>-a 2
2 -e
</code></pre>
<p>Desired output </p>
<pre><code>-a 2
-e 2 -e
</code></pre>
<p>Why is this happening? How do I fix?</p>
| 250 | 17,174 | 2015-03-01 14:12:26 | 21,151,208 | 11 | 2014-01-16 00:31:37 | 27,581 | 2014-01-16 00:31:37 | https://stackoverflow.com/q/21150793 | https://stackoverflow.com/a/21151208 | <h2>tl;dr</h2>
<pre><code>printf "%s\n" "${x[*]}"
</code></pre>
<h2>Explanation</h2>
<p><code>echo</code> takes 3 options:</p>
<pre><code>$ help echo
[…]
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash ... | <h2>tl;dr</h2> <pre><code>printf "%s\n" "${x[*]}" </code></pre> <h2>Explanation</h2> <p><code>echo</code> takes 3 options:</p> <pre><code>$ help echo […] Options: -n do not append a newline -e enable interpretation of the following backslash escapes -E explicitly suppress interpretation of backslash ... | 387 | bash | <h1>Why is bash swallowing -e in the front of an array</h1>
<p>Given the following syntax:</p>
<pre><code>x=(-a 2);echo "${x[@]}";x=(-e 2 -e); echo "${x[@]}"
</code></pre>
<p>Output:</p>
<pre><code>-a 2
2 -e
</code></pre>
<p>Desired output </p>
<pre><code>-a 2
-e 2 -e
</code></pre>
<p>Why is this happening? How d... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,421 | bash | # Why is bash swallowing -e in the front of an array
Given the following syntax:
```
x=(-a 2);echo "${x[@]}";x=(-e 2 -e); echo "${x[@]}"
```
Output:
```
-a 2
2 -e
```
Desired output
```
-a 2
-e 2 -e
```
Why is this happening? How do I fix? | ## tl;dr
```
printf "%s\n" "${x[*]}"
```
## Explanation
`echo` takes 3 options:
```
$ help echo
[…]
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash escapes
```
So if you run:
```
$ echo -n
$ echo -n -... |
19823941 | Join lines with the same value in the first column | 9 | 2013-11-06 22:14:38 | <p>I have a tab-delimited file with three columns (excerpt):</p>
<pre><code>AC147602.5_FG004 IPR000146 Fructose-1,6-bisphosphatase class 1/Sedoheputulose-1,7-bisphosphatase
AC147602.5_FG004 IPR023079 Sedoheptulose-1,7-bisphosphatase
AC148152.3_FG001 IPR002110 Ankyrin repeat
AC148152.3_FG001 IPR026961... | 7,390 | 1,040,763 | 2021-07-01 07:32:47 | 19,824,332 | 11 | 2013-11-06 22:37:05 | 164,835 | 2013-11-06 22:37:05 | https://stackoverflow.com/q/19823941 | https://stackoverflow.com/a/19824332 | <p>give this one-liner a try:</p>
<pre><code> awk -F'\t' -v OFS='\t' '{x=$1;$1="";a[x]=a[x]$0}END{for(x in a)print x,a[x]}' file
</code></pre>
| <p>give this one-liner a try:</p> <pre><code> awk -F'\t' -v OFS='\t' '{x=$1;$1="";a[x]=a[x]$0}END{for(x in a)print x,a[x]}' file </code></pre> | 387, 990 | awk, bash | <h1>Join lines with the same value in the first column</h1>
<p>I have a tab-delimited file with three columns (excerpt):</p>
<pre><code>AC147602.5_FG004 IPR000146 Fructose-1,6-bisphosphatase class 1/Sedoheputulose-1,7-bisphosphatase
AC147602.5_FG004 IPR023079 Sedoheptulose-1,7-bisphosphatase
AC148152.3_FG001... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,422 | bash | # Join lines with the same value in the first column
I have a tab-delimited file with three columns (excerpt):
```
AC147602.5_FG004 IPR000146 Fructose-1,6-bisphosphatase class 1/Sedoheputulose-1,7-bisphosphatase
AC147602.5_FG004 IPR023079 Sedoheptulose-1,7-bisphosphatase
AC148152.3_FG001 IPR002110 Anky... | give this one-liner a try:
```
awk -F'\t' -v OFS='\t' '{x=$1;$1="";a[x]=a[x]$0}END{for(x in a)print x,a[x]}' file
``` |
15455324 | Restarting dropbox-daemon if running | 9 | 2013-03-16 22:15:00 | <p>I have a couple of encrypted drives that I mount manually with a script after start. One of those drives hosts my dropbox folder.</p>
<p>I need to check if dropbox is running when mounting the drive so that I can stop dropbox and then start it again so it syncs correctly.</p>
<p>This is what I have so far, but I c... | 11,854 | 2,173,526 | 2016-02-27 05:06:44 | 18,330,263 | 11 | 2013-08-20 08:22:54 | 2,698,019 | 2016-02-27 05:06:44 | https://stackoverflow.com/q/15455324 | https://stackoverflow.com/a/18330263 | <p>Try</p>
<pre><code>killall dropbox
</code></pre>
<p>This is going to stop it for sure! By default SIGTERM is sent, which is a right way to stop a process. If your system supports multiple simultaneous user logins, then this command is going to terminate dropbox for all users, or at least it will attempt to do so. ... | <p>Try</p> <pre><code>killall dropbox </code></pre> <p>This is going to stop it for sure! By default SIGTERM is sent, which is a right way to stop a process. If your system supports multiple simultaneous user logins, then this command is going to terminate dropbox for all users, or at least it will attempt to do so. ... | 58, 387, 17650, 80492 | bash, dropbox, linux, ubuntu-12.04 | <h1>Restarting dropbox-daemon if running</h1>
<p>I have a couple of encrypted drives that I mount manually with a script after start. One of those drives hosts my dropbox folder.</p>
<p>I need to check if dropbox is running when mounting the drive so that I can stop dropbox and then start it again so it syncs correctl... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,423 | bash | # Restarting dropbox-daemon if running
I have a couple of encrypted drives that I mount manually with a script after start. One of those drives hosts my dropbox folder.
I need to check if dropbox is running when mounting the drive so that I can stop dropbox and then start it again so it syncs correctly.
This is what... | Try
```
killall dropbox
```
This is going to stop it for sure! By default SIGTERM is sent, which is a right way to stop a process. If your system supports multiple simultaneous user logins, then this command is going to terminate dropbox for all users, or at least it will attempt to do so. So more elegant way is to u... |
17612004 | Linux Shell Script: How to detect NFS Mount-point (or the Server) is dead? | 9 | 2013-07-12 09:44:12 | <p>Generally on NFS Client, how to detect the <strong>Mounted-Point is no more available or DEAD from Server-end</strong>, by using the Bash Shell Script?</p>
<p>Normally i do:</p>
<pre><code>if ls '/var/data' 2>&1 | grep 'Stale file handle';
then
echo "failing";
else
echo "ok";
fi
</code></pre>
<p>But ... | 27,608 | 775,856 | 2022-09-09 13:01:23 | 17,644,527 | 11 | 2013-07-14 22:43:37 | 134,536 | 2013-07-19 19:03:17 | https://stackoverflow.com/q/17612004 | https://stackoverflow.com/a/17644527 | <p>"stat" command is a somewhat cleaner way:</p>
<pre><code>statresult=`stat /my/mountpoint 2>&1 | grep -i "stale"`
if [ "${statresult}" != "" ]; then
#result not empty: mountpoint is stale; remove it
umount -f /my/mountpoint
fi
</code></pre>
<p>Additionally, you can use rpcinfo to detect whether the remot... | <p>"stat" command is a somewhat cleaner way:</p> <pre><code>statresult=`stat /my/mountpoint 2>&1 | grep -i "stale"` if [ "${statresult}" != "" ]; then #result not empty: mountpoint is stale; remove it umount -f /my/mountpoint fi </code></pre> <p>Additionally, you can use rpcinfo to detect whether the remot... | 58, 387, 390, 1875, 3014 | bash, linux, nfs, nfsclient, shell | <h1>Linux Shell Script: How to detect NFS Mount-point (or the Server) is dead?</h1>
<p>Generally on NFS Client, how to detect the <strong>Mounted-Point is no more available or DEAD from Server-end</strong>, by using the Bash Shell Script?</p>
<p>Normally i do:</p>
<pre><code>if ls '/var/data' 2>&1 | grep 'Stal... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,425 | bash | # Linux Shell Script: How to detect NFS Mount-point (or the Server) is dead?
Generally on NFS Client, how to detect the **Mounted-Point is no more available or DEAD from Server-end**, by using the Bash Shell Script?
Normally i do:
```
if ls '/var/data' 2>&1 | grep 'Stale file handle';
then
echo "failing";
else
... | "stat" command is a somewhat cleaner way:
```
statresult=`stat /my/mountpoint 2>&1 | grep -i "stale"`
if [ "${statresult}" != "" ]; then
#result not empty: mountpoint is stale; remove it
umount -f /my/mountpoint
fi
```
Additionally, you can use rpcinfo to detect whether the remote nfs share is available:
```
rpc... |
16827324 | Modify web.config with powershell | 9 | 2013-05-30 03:09:31 | <p>I need to try to update a web.config file to change the IP address only of the web.config
I have included the section of code Im looking at for powershell to script the change. </p>
<pre><code><connectionStrings>
<add name="connectionString" connectionString="provider=SQLOLEDB;Server=192.168.1.100;data... | 12,787 | 2,434,834 | 2013-05-30 07:10:55 | 16,830,019 | 11 | 2013-05-30 07:10:55 | 952,477 | 2013-05-30 07:10:55 | https://stackoverflow.com/q/16827324 | https://stackoverflow.com/a/16830019 | <p>I'd to the following</p>
<pre><code>$cfg = [xml](gc web.config)
# Replace all references of the IP in all connection string
$cfg.configuration.connectionStrings.add|%{
$_.connectionString = $_.connectionString -replace "192.168.1.100", "1.0.0.1";
}
$cfg.Save("Web.config");
</code></pre>
<p>If you are just looki... | <p>I'd to the following</p> <pre><code>$cfg = [xml](gc web.config) # Replace all references of the IP in all connection string $cfg.configuration.connectionStrings.add|%{ $_.connectionString = $_.connectionString -replace "192.168.1.100", "1.0.0.1"; } $cfg.Save("Web.config"); </code></pre> <p>If you are just looki... | 526, 2537, 4528, 73157 | connection-string, powershell, powershell-3.0, web-config | <h1>Modify web.config with powershell</h1>
<p>I need to try to update a web.config file to change the IP address only of the web.config
I have included the section of code Im looking at for powershell to script the change. </p>
<pre><code><connectionStrings>
<add name="connectionString" connectionString="... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,426 | bash | # Modify web.config with powershell
I need to try to update a web.config file to change the IP address only of the web.config
I have included the section of code Im looking at for powershell to script the change.
```
<connectionStrings>
<add name="connectionString" connectionString="provider=SQLOLEDB;Server=192.1... | I'd to the following
```
$cfg = [xml](gc web.config)
# Replace all references of the IP in all connection string
$cfg.configuration.connectionStrings.add|%{
$_.connectionString = $_.connectionString -replace "192.168.1.100", "1.0.0.1";
}
$cfg.Save("Web.config");
```
If you are just looking to replace a specfic con... |
15460754 | halt and poweroff | 9 | 2013-03-17 12:36:22 | <p>What is the difference between Halt and Poweroff commands? I understand that both of them lead to shutdown of the machine, then why 2 commands? </p>
<p>I want to know this because in my Virtual Machine. Poweroff leads to complete closure of VM. Whrereas halt leads to killing of all processes, and then a stall with ... | 11,950 | 1,190,922 | 2015-01-02 01:39:24 | 15,460,832 | 11 | 2013-03-17 12:44:24 | 2,177,061 | 2013-03-17 12:49:57 | https://stackoverflow.com/q/15460754 | https://stackoverflow.com/a/15460832 | <p>Halt does just what it says: it stops the machine, leaving it in a powered-on state (which usually implies that someone has to reboot or shut it down manually afterwards). Like halt, poweroff also stops the machine, but also shut it down afterwards.</p>
<p>The fact that on your physical machine the halt command als... | <p>Halt does just what it says: it stops the machine, leaving it in a powered-on state (which usually implies that someone has to reboot or shut it down manually afterwards). Like halt, poweroff also stops the machine, but also shut it down afterwards.</p> <p>The fact that on your physical machine the halt command als... | 58, 390, 4921 | linux, shell, shutdown | <h1>halt and poweroff</h1>
<p>What is the difference between Halt and Poweroff commands? I understand that both of them lead to shutdown of the machine, then why 2 commands? </p>
<p>I want to know this because in my Virtual Machine. Poweroff leads to complete closure of VM. Whrereas halt leads to killing of all proces... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,427 | bash | # halt and poweroff
What is the difference between Halt and Poweroff commands? I understand that both of them lead to shutdown of the machine, then why 2 commands?
I want to know this because in my Virtual Machine. Poweroff leads to complete closure of VM. Whrereas halt leads to killing of all processes, and then a s... | Halt does just what it says: it stops the machine, leaving it in a powered-on state (which usually implies that someone has to reboot or shut it down manually afterwards). Like halt, poweroff also stops the machine, but also shut it down afterwards.
The fact that on your physical machine the halt command also shuts th... |
15262426 | Where is Powershell NetSecurity module? | 9 | 2013-03-07 03:13:36 | <p>I can't seem to find the <code>NetSecurity</code> module on my system. I am using an <code>Amazon Windows 2008 Server R2 SP1</code> instance. </p>
<p><code>Get-Module -ListAvailable</code> on my environment returns this:</p>
<pre><code>ActiveDirectory (I installed this)
ADRMS
AppLocker
BestPractices ... | 11,682 | 2,112,710 | 2013-03-07 04:36:37 | 15,263,152 | 11 | 2013-03-07 04:35:24 | 520,612 | 2013-03-07 04:35:24 | https://stackoverflow.com/q/15262426 | https://stackoverflow.com/a/15263152 | <p>The are <a href="http://technet.microsoft.com/en-us/library/hh801904.aspx">new modules in powershell 3.0</a> that are <strong>only included</strong> as part of the roles/features that ship with <strong>Windows Server 2012</strong>, and in some cases they are also <strong>available on Windows 8</strong>. Unfortunatel... | <p>The are <a href="http://technet.microsoft.com/en-us/library/hh801904.aspx">new modules in powershell 3.0</a> that are <strong>only included</strong> as part of the roles/features that ship with <strong>Windows Server 2012</strong>, and in some cases they are also <strong>available on Windows 8</strong>. Unfortunatel... | 526 | powershell | <h1>Where is Powershell NetSecurity module?</h1>
<p>I can't seem to find the <code>NetSecurity</code> module on my system. I am using an <code>Amazon Windows 2008 Server R2 SP1</code> instance. </p>
<p><code>Get-Module -ListAvailable</code> on my environment returns this:</p>
<pre><code>ActiveDirectory (I installed t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,428 | bash | # Where is Powershell NetSecurity module?
I can't seem to find the `NetSecurity` module on my system. I am using an `Amazon Windows 2008 Server R2 SP1` instance.
`Get-Module -ListAvailable` on my environment returns this:
```
ActiveDirectory (I installed this)
ADRMS
AppLocker
BestPractices
BitsTransf... | The are [new modules in powershell 3.0](http://technet.microsoft.com/en-us/library/hh801904.aspx) that are **only included** as part of the roles/features that ship with **Windows Server 2012**, and in some cases they are also **available on Windows 8**. Unfortunately, they cannot be installed on previous versions of W... |
14837894 | Why does bash not stop on error for failures in sequence of short-circuited commands? | 9 | 2013-02-12 17:07:21 | <p>I'm seeing some behavior that doesn't make sense to me when I run a bash script with the <code>-e</code> option that has multiple commands strung together with <code>&&</code>s and one of them fails. I would expect the script to stop on the failed command and return the exit status, but instead it just execu... | 1,517 | 606,784 | 2020-03-23 11:46:58 | 14,837,998 | 11 | 2013-02-12 17:12:40 | 1,664,755 | 2013-02-12 17:12:40 | https://stackoverflow.com/q/14837894 | https://stackoverflow.com/a/14837998 | <p>The logic here is that your use of <code>&&</code> already <em>is</em> error-checking. The same way bash doesn't treat a failure within an <code>if</code> condition as worth aborting, even with <code>set -e</code>.</p>
<p>When you wrap the commands in a parenthesis, you are actually running those commands w... | <p>The logic here is that your use of <code>&&</code> already <em>is</em> error-checking. The same way bash doesn't treat a failure within an <code>if</code> condition as worth aborting, even with <code>set -e</code>.</p> <p>When you wrap the commands in a parenthesis, you are actually running those commands w... | 58, 387, 390, 23102 | bash, linux, shell, short-circuiting | <h1>Why does bash not stop on error for failures in sequence of short-circuited commands?</h1>
<p>I'm seeing some behavior that doesn't make sense to me when I run a bash script with the <code>-e</code> option that has multiple commands strung together with <code>&&</code>s and one of them fails. I would expect... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,429 | bash | # Why does bash not stop on error for failures in sequence of short-circuited commands?
I'm seeing some behavior that doesn't make sense to me when I run a bash script with the `-e` option that has multiple commands strung together with `&&`s and one of them fails. I would expect the script to stop on the failed comma... | The logic here is that your use of `&&` already *is* error-checking. The same way bash doesn't treat a failure within an `if` condition as worth aborting, even with `set -e`.
When you wrap the commands in a parenthesis, you are actually running those commands within a subshell, so the script itself only sees the retur... |
13911881 | Setting Cygwin shell path on Vim for Windows | 9 | 2012-12-17 09:59:26 | <p>I am attempting to set up Vim on Windows, using Git bash (Cygwin) as the shell environment. I'm getting an error about temporary files which I'm 99% sure is related to the fact that the shell can't be loaded (i.e. the "!" commands don't work).</p>
<p>In my <code>_vimrc</code> file I've tried setting the <code>shell... | 5,581 | 1,087,866 | 2015-03-16 17:37:25 | 13,917,410 | 11 | 2012-12-17 15:50:28 | 1,006,963 | 2012-12-17 16:07:22 | https://stackoverflow.com/q/13911881 | https://stackoverflow.com/a/13917410 | <p>You almost got it right. You need to escape each surrounding ". Instead of escaping a space, windows requires you to wrap the string in quotes. But vim interprets the quote as a comment. So you need to escape the double quote. You also need a backslash to escape the space.</p>
<p>See an example in <code>:h 'she... | <p>You almost got it right. You need to escape each surrounding ". Instead of escaping a space, windows requires you to wrap the string in quotes. But vim interprets the quote as a comment. So you need to escape the double quote. You also need a backslash to escape the space.</p> <p>See an example in <code>:h 'she... | 64, 370, 1731, 61874 | cygwin, git-bash, vim, windows | <h1>Setting Cygwin shell path on Vim for Windows</h1>
<p>I am attempting to set up Vim on Windows, using Git bash (Cygwin) as the shell environment. I'm getting an error about temporary files which I'm 99% sure is related to the fact that the shell can't be loaded (i.e. the "!" commands don't work).</p>
<p>In my <code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,430 | bash | # Setting Cygwin shell path on Vim for Windows
I am attempting to set up Vim on Windows, using Git bash (Cygwin) as the shell environment. I'm getting an error about temporary files which I'm 99% sure is related to the fact that the shell can't be loaded (i.e. the "!" commands don't work).
In my `_vimrc` file I've tr... | You almost got it right. You need to escape each surrounding ". Instead of escaping a space, windows requires you to wrap the string in quotes. But vim interprets the quote as a comment. So you need to escape the double quote. You also need a backslash to escape the space.
See an example in `:h 'shell'` (note the sing... |
13011146 | How to stop Xcode build from shell script | 9 | 2012-10-22 12:08:17 | <p>I am currently working on an app in Xcode where I've added a Build Phase that runs a shell script. </p>
<p>The script looks for resources from the Desktop and copies them to the app . If the files/folders don't exist, the script should cancel the build of the app. </p>
<p>I have tried various things to stop the bu... | 3,465 | 1,765,227 | 2014-11-05 23:01:34 | 13,013,170 | 11 | 2012-10-22 14:06:20 | 49,658 | 2012-10-22 14:06:20 | https://stackoverflow.com/q/13011146 | https://stackoverflow.com/a/13013170 | <p>You need to return a non-zero exit code from the script:</p>
<pre><code>exit 1
</code></pre>
| <p>You need to return a non-zero exit code from the script:</p> <pre><code>exit 1 </code></pre> | 387, 390, 908 | bash, shell, xcode | <h1>How to stop Xcode build from shell script</h1>
<p>I am currently working on an app in Xcode where I've added a Build Phase that runs a shell script. </p>
<p>The script looks for resources from the Desktop and copies them to the app . If the files/folders don't exist, the script should cancel the build of the app. ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,431 | bash | # How to stop Xcode build from shell script
I am currently working on an app in Xcode where I've added a Build Phase that runs a shell script.
The script looks for resources from the Desktop and copies them to the app . If the files/folders don't exist, the script should cancel the build of the app.
I have tried var... | You need to return a non-zero exit code from the script:
```
exit 1
``` |
12297284 | In powershell, how can I use Rename-Item to output the old and new file names at the same time? | 9 | 2012-09-06 09:44:33 | <p>I'd like to select a list of files using <code>Get-ChildItem</code> piped to <code>Rename-Item</code> and have the output display text with each line showing something like "Renamed <em>oldfilename</em> to <em>newfilename</em>".</p>
<p>How can I do this?</p>
| 17,153 | 87,427 | 2021-01-22 15:12:44 | 12,303,243 | 11 | 2012-09-06 15:17:44 | 1,652,464 | 2012-09-06 15:39:59 | https://stackoverflow.com/q/12297284 | https://stackoverflow.com/a/12303243 | <pre><code>Get-Childitem C:\Temp |
Foreach-object {
$OldName = $_.name;
$NewName = $_.name -replace 'temp','test';
Rename-Item -Newname $NewName;
Write-Output $("Renamed {0} to {1}" -f $OldName,$NewName)
}
</code></pre>
| <pre><code>Get-Childitem C:\Temp | Foreach-object { $OldName = $_.name; $NewName = $_.name -replace 'temp','test'; Rename-Item -Newname $NewName; Write-Output $("Renamed {0} to {1}" -f $OldName,$NewName) } </code></pre> | 526, 29006, 96017 | get-childitem, powershell, rename-item-cmdlet | <h1>In powershell, how can I use Rename-Item to output the old and new file names at the same time?</h1>
<p>I'd like to select a list of files using <code>Get-ChildItem</code> piped to <code>Rename-Item</code> and have the output display text with each line showing something like "Renamed <em>oldfilename</em> to <em>ne... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,432 | bash | # In powershell, how can I use Rename-Item to output the old and new file names at the same time?
I'd like to select a list of files using `Get-ChildItem` piped to `Rename-Item` and have the output display text with each line showing something like "Renamed *oldfilename* to *newfilename*".
How can I do this? | ```
Get-Childitem C:\Temp |
Foreach-object {
$OldName = $_.name;
$NewName = $_.name -replace 'temp','test';
Rename-Item -Newname $NewName;
Write-Output $("Renamed {0} to {1}" -f $OldName,$NewName)
}
``` |
12088055 | How to change Powershell CLR version when running commands remotely? | 9 | 2012-08-23 08:52:33 | <p>I've got a problem trying to run some of our scripts on a remote server.</p>
<p>We need all Powershell sessions to load v4 of the CLR, as we're loading in our own custom binaries with our scripts.</p>
<p>We've been doing this for some time (we do so using a modified powershell.exe.config similar to here: <a href="... | 7,864 | 1,617,331 | 2012-08-23 11:07:49 | 12,090,217 | 11 | 2012-08-23 11:07:49 | 520,612 | 2012-08-23 11:07:49 | https://stackoverflow.com/q/12088055 | https://stackoverflow.com/a/12090217 | <p>Try creating a <code>c:\windows\System32\wsmprovhost.exe.config</code> file and a <code>c:\windows\SysWOW64\wsmprovhost.exe.config</code> file in 64bit OS like this:</p>
<pre><code><?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedR... | <p>Try creating a <code>c:\windows\System32\wsmprovhost.exe.config</code> file and a <code>c:\windows\SysWOW64\wsmprovhost.exe.config</code> file in 64bit OS like this:</p> <pre><code><?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedR... | 477, 526, 837 | clr, powershell, remoting | <h1>How to change Powershell CLR version when running commands remotely?</h1>
<p>I've got a problem trying to run some of our scripts on a remote server.</p>
<p>We need all Powershell sessions to load v4 of the CLR, as we're loading in our own custom binaries with our scripts.</p>
<p>We've been doing this for some ti... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,433 | bash | # How to change Powershell CLR version when running commands remotely?
I've got a problem trying to run some of our scripts on a remote server.
We need all Powershell sessions to load v4 of the CLR, as we're loading in our own custom binaries with our scripts.
We've been doing this for some time (we do so using a mo... | Try creating a `c:\windows\System32\wsmprovhost.exe.config` file and a `c:\windows\SysWOW64\wsmprovhost.exe.config` file in 64bit OS like this:
```
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supported... |
11500649 | How to create a new terminal session and execute multiple commands | 9 | 2012-07-16 08:32:36 | <p>I'm looking for a way to automate the start-up of my development environment. I have three virtual machines that have to be started, then have to <code>ssh</code> to each of them and open VPN on them.</p>
<p>So far I've gotten them to start and managed to ssh to them:</p>
<pre><code>#!/bin/sh
virsh start virtual_... | 13,071 | 1,214,214 | 2016-07-11 17:12:31 | 11,500,788 | 11 | 2012-07-16 08:43:14 | 912,144 | 2016-07-11 17:12:31 | https://stackoverflow.com/q/11500649 | https://stackoverflow.com/a/11500788 | <p>First of all, if you run</p>
<pre><code>gnome-terminal -x bash -c "cmd1; cmd2"
</code></pre>
<p>you get <code>bash</code> to execute <code>cmd1</code> and <code>cmd2</code>. It doesn't first execute <code>cmd1</code> and then give <code>cmd2</code> to its result. <code>ssh</code> is a program run in the te... | <p>First of all, if you run</p> <pre><code>gnome-terminal -x bash -c "cmd1; cmd2" </code></pre> <p>you get <code>bash</code> to execute <code>cmd1</code> and <code>cmd2</code>. It doesn't first execute <code>cmd1</code> and then give <code>cmd2</code> to its result. <code>ssh</code> is a program run in the te... | 387 | bash | <h1>How to create a new terminal session and execute multiple commands</h1>
<p>I'm looking for a way to automate the start-up of my development environment. I have three virtual machines that have to be started, then have to <code>ssh</code> to each of them and open VPN on them.</p>
<p>So far I've gotten them to start... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,434 | bash | # How to create a new terminal session and execute multiple commands
I'm looking for a way to automate the start-up of my development environment. I have three virtual machines that have to be started, then have to `ssh` to each of them and open VPN on them.
So far I've gotten them to start and managed to ssh to them... | First of all, if you run
```
gnome-terminal -x bash -c "cmd1; cmd2"
```
you get `bash` to execute `cmd1` and `cmd2`. It doesn't first execute `cmd1` and then give `cmd2` to its result. `ssh` is a program run in the terminal and your `cmd2` won't be executed until that is finished.
So you need to run `ssh` and tell *... |
9099233 | Bash: How to apply two string operations in one line? | 9 | 2012-02-01 16:15:42 | <p>I'd like to change the path and extension of a file in a variable at once e.g. do the following</p>
<pre><code>for F in $( find /foo/bar -name "*.ext" ); do
Ftmp=${F%.ext}
cp $F ${Ftmp//bar/b0r}.tmp
done
</code></pre>
<p>without a temporary variable</p>
<p>Can two string operations be applied at once with b... | 3,601 | 887,412 | 2017-07-15 20:38:14 | 11,388,459 | 11 | 2012-07-09 02:30:28 | 1,002,260 | 2013-01-19 08:28:31 | https://stackoverflow.com/q/9099233 | https://stackoverflow.com/a/11388459 | <p>Use the Bash <a href="http://techpaste.com/2012/05/bash-shell-built-in-shell-variables-scripting" rel="noreferrer"><strong>temporary variable</strong></a></p>
<pre class="lang-none prettyprint-override"><code>$_ Temporary variable; initialized to pathname of script or program
being executed. Later, stores ... | <p>Use the Bash <a href="http://techpaste.com/2012/05/bash-shell-built-in-shell-variables-scripting" rel="noreferrer"><strong>temporary variable</strong></a></p> <pre class="lang-none prettyprint-override"><code>$_ Temporary variable; initialized to pathname of script or program being executed. Later, stores ... | 139, 387 | bash, string | <h1>Bash: How to apply two string operations in one line?</h1>
<p>I'd like to change the path and extension of a file in a variable at once e.g. do the following</p>
<pre><code>for F in $( find /foo/bar -name "*.ext" ); do
Ftmp=${F%.ext}
cp $F ${Ftmp//bar/b0r}.tmp
done
</code></pre>
<p>without a temporary varia... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,435 | bash | # Bash: How to apply two string operations in one line?
I'd like to change the path and extension of a file in a variable at once e.g. do the following
```
for F in $( find /foo/bar -name "*.ext" ); do
Ftmp=${F%.ext}
cp $F ${Ftmp//bar/b0r}.tmp
done
```
without a temporary variable
Can two string operations be... | Use the Bash [**temporary variable**](http://techpaste.com/2012/05/bash-shell-built-in-shell-variables-scripting)
```
$_ Temporary variable; initialized to pathname of script or program
being executed. Later, stores the last argument of previous command.
Also stores name of matching MAIL file during mail... |
10866005 | How to prefill command line input | 9 | 2012-06-02 21:15:27 | <p>I'm running a bash script and I'd like to prefill a command line with some command after executing the script. The only condition is that the script mustn't be running at that time.</p>
<p>What I need is to ...</p>
<ol>
<li>run the script</li>
<li>have prefilled text in my command line AFTER the script has been st... | 2,153 | 786,284 | 2016-09-22 16:35:35 | 10,866,105 | 11 | 2012-06-02 21:30:29 | 1,128,465 | 2012-06-02 21:30:29 | https://stackoverflow.com/q/10866005 | https://stackoverflow.com/a/10866105 | <p>You need to use the TIOCSTI ioctl. Here's an example C program that shows how it works:</p>
<pre><code>#include <sys/ioctl.h>
main()
{
char buf[] = "date";
int i;
for (i = 0; i < sizeof buf - 1; i++)
ioctl(0, TIOCSTI, &buf[i]);
return 0;
}
</code></pre>
<p>Compile this and run ... | <p>You need to use the TIOCSTI ioctl. Here's an example C program that shows how it works:</p> <pre><code>#include <sys/ioctl.h> main() { char buf[] = "date"; int i; for (i = 0; i < sizeof buf - 1; i++) ioctl(0, TIOCSTI, &buf[i]); return 0; } </code></pre> <p>Compile this and run ... | 58, 387 | bash, linux | <h1>How to prefill command line input</h1>
<p>I'm running a bash script and I'd like to prefill a command line with some command after executing the script. The only condition is that the script mustn't be running at that time.</p>
<p>What I need is to ...</p>
<ol>
<li>run the script</li>
<li>have prefilled text in m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,436 | bash | # How to prefill command line input
I'm running a bash script and I'd like to prefill a command line with some command after executing the script. The only condition is that the script mustn't be running at that time.
What I need is to ...
1. run the script
2. have prefilled text in my command line AFTER the script ... | You need to use the TIOCSTI ioctl. Here's an example C program that shows how it works:
```
#include <sys/ioctl.h>
main()
{
char buf[] = "date";
int i;
for (i = 0; i < sizeof buf - 1; i++)
ioctl(0, TIOCSTI, &buf[i]);
return 0;
}
```
Compile this and run it and "date" will be buffered as input o... |
10821933 | What are the rules of string manipulation when using backticks (grave accents)? | 9 | 2012-05-30 18:14:08 | <p>In PHP when you write a set a variable equal to a string wrapped in grave accents, it gets executed as it would if it were inside a <code>shell_exec()</code> command. <a href="https://stackoverflow.com/q/6071562/680578">What does the grave accent symbol (`) ( not single quote) represent in PHP?</a></p>
<p>So, in ph... | 6,668 | 680,578 | 2020-07-15 09:27:27 | 10,822,373 | 11 | 2012-05-30 18:46:39 | 451,201 | 2012-05-30 19:15:31 | https://stackoverflow.com/q/10821933 | https://stackoverflow.com/a/10822373 | <p>In the PHP, that character is called a backtick operator.</p>
<p>A literal string wrapped in backticks is a <code>T_ENCAPSED_AND_WHITESPACE</code> token. You can confirm this by running something like this:</p>
<pre><code>print_r(token_get_all('<?php `uname`;'));
</code></pre>
<p>which gives you this:</p>
<pr... | <p>In the PHP, that character is called a backtick operator.</p> <p>A literal string wrapped in backticks is a <code>T_ENCAPSED_AND_WHITESPACE</code> token. You can confirm this by running something like this:</p> <pre><code>print_r(token_get_all('<?php `uname`;')); </code></pre> <p>which gives you this:</p> <pr... | 5, 139, 390, 28438 | backticks, php, shell, string | <h1>What are the rules of string manipulation when using backticks (grave accents)?</h1>
<p>In PHP when you write a set a variable equal to a string wrapped in grave accents, it gets executed as it would if it were inside a <code>shell_exec()</code> command. <a href="https://stackoverflow.com/q/6071562/680578">What doe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,437 | bash | # What are the rules of string manipulation when using backticks (grave accents)?
In PHP when you write a set a variable equal to a string wrapped in grave accents, it gets executed as it would if it were inside a `shell_exec()` command. [What does the grave accent symbol (`) ( not single quote) represent in PHP?](htt... | In the PHP, that character is called a backtick operator.
A literal string wrapped in backticks is a `T_ENCAPSED_AND_WHITESPACE` token. You can confirm this by running something like this:
```
print_r(token_get_all('<?php `uname`;'));
```
which gives you this:
```
Array
(
[0] => Array
(
[0] ... |
10185879 | PowerShell equality operator not a symmetric relation? | 9 | 2012-04-17 05:55:57 | <p>Can someone please explain to me why the equality operator in PowerShell is not a symmetric relation??</p>
<pre><code>PS> "" -eq 0
False
PS> 0 -eq ""
True
</code></pre>
| 833 | 983,442 | 2012-04-17 06:28:16 | 10,186,076 | 11 | 2012-04-17 06:13:36 | 73,070 | 2012-04-17 06:28:16 | https://stackoverflow.com/q/10185879 | https://stackoverflow.com/a/10186076 | <p>Yes, <code>-eq</code> in PowerShell is not an equivalence relation. While theorists may cry out in terror at this point it's mostly to make the language better at conveying ideas and simpler to understand.</p>
<p>For example, PowerShell <em>always</em> tries converting differing types in binary operators to the typ... | <p>Yes, <code>-eq</code> in PowerShell is not an equivalence relation. While theorists may cry out in terror at this point it's mostly to make the language better at conveying ideas and simpler to understand.</p> <p>For example, PowerShell <em>always</em> tries converting differing types in binary operators to the typ... | 526 | powershell | <h1>PowerShell equality operator not a symmetric relation?</h1>
<p>Can someone please explain to me why the equality operator in PowerShell is not a symmetric relation??</p>
<pre><code>PS> "" -eq 0
False
PS> 0 -eq ""
True
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,438 | bash | # PowerShell equality operator not a symmetric relation?
Can someone please explain to me why the equality operator in PowerShell is not a symmetric relation??
```
PS> "" -eq 0
False
PS> 0 -eq ""
True
``` | Yes, `-eq` in PowerShell is not an equivalence relation. While theorists may cry out in terror at this point it's mostly to make the language better at conveying ideas and simpler to understand.
For example, PowerShell *always* tries converting differing types in binary operators to the type of the *left* operand whic... |
9869349 | Shell script call from Android.mk, standard output and missing separator error | 9 | 2012-03-26 09:07:47 | <p>I have a simple Android.mk file:</p>
<pre><code>LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(shell ($(LOCAL_PATH)/echo_test.sh))
LOCAL_MODULE := libecho_test
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
</code></pre>
<p>The interesting thing that it does is to call the 'echo_test.sh' bas... | 18,837 | 324,204 | 2014-12-30 11:44:11 | 9,956,636 | 11 | 2012-03-31 14:17:24 | 4,596 | 2012-04-03 14:11:37 | https://stackoverflow.com/q/9869349 | https://stackoverflow.com/a/9956636 | <p>The Android NDK build system is actually <a href="http://www.gnu.org/software/make/" rel="noreferrer">GNU Make</a>. All of the code in the Android.mk file has to be valid <code>make</code>.</p>
<p>When you run $(shell) and don't store the value in a variable, then it is as if you copied the standard output of the s... | <p>The Android NDK build system is actually <a href="http://www.gnu.org/software/make/" rel="noreferrer">GNU Make</a>. All of the code in the Android.mk file has to be valid <code>make</code>.</p> <p>When you run $(shell) and don't store the value in a variable, then it is as if you copied the standard output of the s... | 387, 390, 4867, 42420 | android-ndk, bash, shell, stdout | <h1>Shell script call from Android.mk, standard output and missing separator error</h1>
<p>I have a simple Android.mk file:</p>
<pre><code>LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(shell ($(LOCAL_PATH)/echo_test.sh))
LOCAL_MODULE := libecho_test
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,439 | bash | # Shell script call from Android.mk, standard output and missing separator error
I have a simple Android.mk file:
```
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(shell ($(LOCAL_PATH)/echo_test.sh))
LOCAL_MODULE := libecho_test
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
```
The interesti... | The Android NDK build system is actually [GNU Make](http://www.gnu.org/software/make/). All of the code in the Android.mk file has to be valid `make`.
When you run $(shell) and don't store the value in a variable, then it is as if you copied the standard output of the script into your Android.mk file. i.e. it is as if... |
9953005 | Should the .bashrc in the home directory load automatically? | 9 | 2012-03-31 04:23:38 | <p>I added scala in my .bashrc file, but when I shut off my mac and turn it back on it does not find it. When i do </p>
<pre><code>source ~/.bashrc
</code></pre>
<p>all is back to normal. I would say the issue is with the whole file in general, but the problem, is I have other things in there that have worked just f... | 16,841 | 1,118,919 | 2012-03-31 08:21:49 | 9,953,085 | 11 | 2012-03-31 04:43:50 | 145,905 | 2012-03-31 04:43:50 | https://stackoverflow.com/q/9953005 | https://stackoverflow.com/a/9953085 | <p>Your shell is probably a login shell, in which case bash will read various profile files in order:</p>
<ol>
<li><code>/etc/profile</code></li>
<li><code>~/.bash_profile</code></li>
<li><code>~/.bash_login</code></li>
<li><code>~/.profile</code></li>
</ol>
<p>It's typical to source <code>~/.bashrc</code> from one o... | <p>Your shell is probably a login shell, in which case bash will read various profile files in order:</p> <ol> <li><code>/etc/profile</code></li> <li><code>~/.bash_profile</code></li> <li><code>~/.bash_login</code></li> <li><code>~/.profile</code></li> </ol> <p>It's typical to source <code>~/.bashrc</code> from one o... | 369, 387 | bash, macos | <h1>Should the .bashrc in the home directory load automatically?</h1>
<p>I added scala in my .bashrc file, but when I shut off my mac and turn it back on it does not find it. When i do </p>
<pre><code>source ~/.bashrc
</code></pre>
<p>all is back to normal. I would say the issue is with the whole file in general, bu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,440 | bash | # Should the .bashrc in the home directory load automatically?
I added scala in my .bashrc file, but when I shut off my mac and turn it back on it does not find it. When i do
```
source ~/.bashrc
```
all is back to normal. I would say the issue is with the whole file in general, but the problem, is I have other thin... | Your shell is probably a login shell, in which case bash will read various profile files in order:
1. `/etc/profile`
2. `~/.bash_profile`
3. `~/.bash_login`
4. `~/.profile`
It's typical to source `~/.bashrc` from one of those files so you get the same config for login shells as well.
This is what my `~/.profile` con... |
9655843 | How to create an AppleScript- or Command-file to launch a Java application on Mac OS? | 9 | 2012-03-11 14:35:39 | <p>I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this <code>launch-win32.bat</code>:</p>
<pre><code>@echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass
</code></pre>
<p>For linux I created a shell s... | 17,516 | 1,260,906 | 2012-03-11 23:49:29 | 9,660,103 | 11 | 2012-03-11 23:49:29 | 1,260,906 | 2012-03-11 23:49:29 | https://stackoverflow.com/q/9655843 | https://stackoverflow.com/a/9660103 | <p>Okay, after some hours of research it seems there are more than just one answer to this issue(s).</p>
<h2>Bash scripts</h2>
<ul>
<li>The <a href="https://stackoverflow.com/a/3155928/1260906">simplest way to create scripts in Mac OS seems to be</a> the <code>.command</code> bash script files. They look quite simila... | <p>Okay, after some hours of research it seems there are more than just one answer to this issue(s).</p> <h2>Bash scripts</h2> <ul> <li>The <a href="https://stackoverflow.com/a/3155928/1260906">simplest way to create scripts in Mac OS seems to be</a> the <code>.command</code> bash script files. They look quite simila... | 17, 369, 390, 1243, 9636 | applescript, java, macos, noclassdeffounderror, shell | <h1>How to create an AppleScript- or Command-file to launch a Java application on Mac OS?</h1>
<p>I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this <code>launch-win32.bat</code>:</p>
<pre><code>@echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp li... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,441 | bash | # How to create an AppleScript- or Command-file to launch a Java application on Mac OS?
I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this `launch-win32.bat`:
```
@echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.pac... | Okay, after some hours of research it seems there are more than just one answer to this issue(s).
## Bash scripts
- The [simplest way to create scripts in Mac OS seems to be](https://stackoverflow.com/a/3155928/1260906) the `.command` bash script files. They look quite similar to linux shell scripts. Make them execut... |
9612609 | How do I set Windows Update to never check for updates with PowerShell? | 9 | 2012-03-08 03:47:53 | <p>I'm looking for help scripting with PowerShell, Windows Server 2008 R2 so Windows Updates is set to "Never check for updates." I found some near answers but I still can't do what I want. Currently, I have to set it by clicking Windows Update > Change Settings > Never Check for Updates. Thanks in advance.</p>
| 10,247 | 1,256,194 | 2014-03-19 16:08:53 | 9,612,904 | 11 | 2012-03-08 04:30:03 | 608,772 | 2014-03-19 16:08:53 | https://stackoverflow.com/q/9612609 | https://stackoverflow.com/a/9612904 | <p>You can use a COM object for that :</p>
<pre><code>$WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
$WUSettings
NotificationLevel : 2
ReadOnly : True
Required : False
ScheduledInstallationDay : 0
ScheduledInstallationTime : 3
IncludeRecommendedUpdates... | <p>You can use a COM object for that :</p> <pre><code>$WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings $WUSettings NotificationLevel : 2 ReadOnly : True Required : False ScheduledInstallationDay : 0 ScheduledInstallationTime : 3 IncludeRecommendedUpdates... | 64, 526 | powershell, windows | <h1>How do I set Windows Update to never check for updates with PowerShell?</h1>
<p>I'm looking for help scripting with PowerShell, Windows Server 2008 R2 so Windows Updates is set to "Never check for updates." I found some near answers but I still can't do what I want. Currently, I have to set it by clicking Windows... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,442 | bash | # How do I set Windows Update to never check for updates with PowerShell?
I'm looking for help scripting with PowerShell, Windows Server 2008 R2 so Windows Updates is set to "Never check for updates." I found some near answers but I still can't do what I want. Currently, I have to set it by clicking Windows Update > C... | You can use a COM object for that :
```
$WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
$WUSettings
NotificationLevel : 2
ReadOnly : True
Required : False
ScheduledInstallationDay : 0
ScheduledInstallationTime : 3
IncludeRecommendedUpdates : True
NonAdm... |
9509817 | diff two files and keep just new or changed lines | 9 | 2012-03-01 02:32:52 | <p>I would like to write a bash script or a few shell commands that solves my problem. I have two files, old.txt, new.txt. I would like to produce a file, diff.txt, that has only the lines that have changed or are new. For instance if I had:</p>
<p>old.txt:</p>
<pre><code>Sierra
Tango
Oscar
Victor
Whiskey
Yankee
<... | 6,524 | 836,450 | 2015-06-12 08:21:26 | 9,510,294 | 11 | 2012-03-01 03:36:51 | 348,785 | 2012-03-01 03:36:51 | https://stackoverflow.com/q/9509817 | https://stackoverflow.com/a/9510294 | <pre><code>$ awk 'FNR==NR{old[$0];next};!($0 in old)' old.txt new.txt
Echo
Osc__ar
Uniform
Yan__kee
</code></pre>
| <pre><code>$ awk 'FNR==NR{old[$0];next};!($0 in old)' old.txt new.txt Echo Osc__ar Uniform Yan__kee </code></pre> | 387, 606, 5310 | bash, diff, file | <h1>diff two files and keep just new or changed lines</h1>
<p>I would like to write a bash script or a few shell commands that solves my problem. I have two files, old.txt, new.txt. I would like to produce a file, diff.txt, that has only the lines that have changed or are new. For instance if I had:</p>
<p>old.txt:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,443 | bash | # diff two files and keep just new or changed lines
I would like to write a bash script or a few shell commands that solves my problem. I have two files, old.txt, new.txt. I would like to produce a file, diff.txt, that has only the lines that have changed or are new. For instance if I had:
old.txt:
```
Sierra
Tango
... | ```
$ awk 'FNR==NR{old[$0];next};!($0 in old)' old.txt new.txt
Echo
Osc__ar
Uniform
Yan__kee
``` |
9220239 | How to append data from one CSV to another using Export-CSV | 9 | 2012-02-09 22:57:39 | <p>I have a script like the following:</p>
<pre><code>$in_file = "C:\Data\Need-Info.csv"
$out_file = "C:\Data\Need-Info_Updated.csv"
$list = Import-Csv $in_file
ForEach ( $user in $list ) {
$zID = $user.zID
ForEach-Object {
Get-QADUser -Service 'domain.local' -SearchRoot 'OU=Users,... | 110,223 | 570,402 | 2021-12-18 00:14:46 | 9,220,445 | 11 | 2012-02-09 23:15:43 | 526,535 | 2021-12-18 00:14:07 | https://stackoverflow.com/q/9220239 | https://stackoverflow.com/a/9220445 | <p>Convert the foreach loop into a foreach-object, and move the export-csv to outside the outer foreach object so that you can pipe all the objects to the export-csv.</p>
<p>Something like this (untested):</p>
<pre><code>$list | ForEach {
$zID = $_.zID
ForEach-Object {
Get-QADUser -Service 'domain.loca... | <p>Convert the foreach loop into a foreach-object, and move the export-csv to outside the outer foreach object so that you can pipe all the objects to the export-csv.</p> <p>Something like this (untested):</p> <pre><code>$list | ForEach { $zID = $_.zID ForEach-Object { Get-QADUser -Service 'domain.loca... | 526, 65062 | export-to-csv, powershell | <h1>How to append data from one CSV to another using Export-CSV</h1>
<p>I have a script like the following:</p>
<pre><code>$in_file = "C:\Data\Need-Info.csv"
$out_file = "C:\Data\Need-Info_Updated.csv"
$list = Import-Csv $in_file
ForEach ( $user in $list ) {
$zID = $user.zID
ForEach-Object ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,444 | bash | # How to append data from one CSV to another using Export-CSV
I have a script like the following:
```
$in_file = "C:\Data\Need-Info.csv"
$out_file = "C:\Data\Need-Info_Updated.csv"
$list = Import-Csv $in_file
ForEach ( $user in $list ) {
$zID = $user.zID
ForEach-Object {
Get-QADUser -Service 'domain... | Convert the foreach loop into a foreach-object, and move the export-csv to outside the outer foreach object so that you can pipe all the objects to the export-csv.
Something like this (untested):
```
$list | ForEach {
$zID = $_.zID
ForEach-Object {
Get-QADUser -Service 'domain.local' -SearchRoot 'OU=... |
9044465 | LIst of dirs without trailing slash "/" | 9 | 2012-01-28 10:12:57 | <p>I'd like a list (one item per line) of a dir. But the last character is a "/"</p>
<pre><code> ls /var/lib/mysql/ | grep -v "\."
</code></pre>
<p>This shows:</p>
<pre><code> wachuwar_funkfow/
wachuwar_prueba/
webdeard_arde/
</code></pre>
<p>And I'd like</p>
<pre><code> wachuwar_funkfow
wachuwar_prueba
webdea... | 17,822 | 736,872 | 2019-07-25 10:00:09 | 9,044,489 | 11 | 2012-01-28 10:16:38 | 841,108 | 2012-01-28 10:16:38 | https://stackoverflow.com/q/9044465 | https://stackoverflow.com/a/9044489 | <p>Probably, your <code>ls</code> is aliased or defined as a function in your <code>.bashrc</code> or <code>/etc/profile</code> or elsewhere.</p>
<p>Try the full path to <code>ls</code> like</p>
<pre><code>/bin/ls /var/lib/mysql/
</code></pre>
| <p>Probably, your <code>ls</code> is aliased or defined as a function in your <code>.bashrc</code> or <code>/etc/profile</code> or elsewhere.</p> <p>Try the full path to <code>ls</code> like</p> <pre><code>/bin/ls /var/lib/mysql/ </code></pre> | 58, 387, 990, 5282 | awk, bash, linux, sed | <h1>LIst of dirs without trailing slash "/"</h1>
<p>I'd like a list (one item per line) of a dir. But the last character is a "/"</p>
<pre><code> ls /var/lib/mysql/ | grep -v "\."
</code></pre>
<p>This shows:</p>
<pre><code> wachuwar_funkfow/
wachuwar_prueba/
webdeard_arde/
</code></pre>
<p>And I'd like</p>
<pre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,445 | bash | # LIst of dirs without trailing slash "/"
I'd like a list (one item per line) of a dir. But the last character is a "/"
```
ls /var/lib/mysql/ | grep -v "\."
```
This shows:
```
wachuwar_funkfow/
wachuwar_prueba/
webdeard_arde/
```
And I'd like
```
wachuwar_funkfow
wachuwar_prueba
webdeard_arde
```
I'd ap... | Probably, your `ls` is aliased or defined as a function in your `.bashrc` or `/etc/profile` or elsewhere.
Try the full path to `ls` like
```
/bin/ls /var/lib/mysql/
``` |
8979332 | How to keyboard type a variable using xdotool? | 9 | 2012-01-23 22:11:08 | <p>I am coding a little script to save some data from Internet every single day.
So I am using xdotool to simulate all my navigation until the point I have the save window of firefox in front of me, I mean, in front of my script. OK, all right until here... But, when I try to use the day of the week(or any data in the ... | 18,769 | 858,991 | 2021-03-16 00:30:06 | 8,979,692 | 11 | 2012-01-23 22:42:21 | 620,097 | 2021-03-16 00:30:06 | https://stackoverflow.com/q/8979332 | https://stackoverflow.com/a/8979692 | <p>I don't know anything about xdotool, but one issue is obvious, correct this and then edit your post if it is not resolved, and include specific text of error messages.</p>
<p>change</p>
<pre><code>i=|date +%A
</code></pre>
<p>to</p>
<pre><code>i=$(date +%A)
</code></pre>
<p>Then when you execute your last line</p>
<... | <p>I don't know anything about xdotool, but one issue is obvious, correct this and then edit your post if it is not resolved, and include specific text of error messages.</p> <p>change</p> <pre><code>i=|date +%A </code></pre> <p>to</p> <pre><code>i=$(date +%A) </code></pre> <p>Then when you execute your last line</p> <... | 387, 1062, 1362 | automation, bash, filenames | <h1>How to keyboard type a variable using xdotool?</h1>
<p>I am coding a little script to save some data from Internet every single day.
So I am using xdotool to simulate all my navigation until the point I have the save window of firefox in front of me, I mean, in front of my script. OK, all right until here... But, w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,446 | bash | # How to keyboard type a variable using xdotool?
I am coding a little script to save some data from Internet every single day.
So I am using xdotool to simulate all my navigation until the point I have the save window of firefox in front of me, I mean, in front of my script. OK, all right until here... But, when I try... | I don't know anything about xdotool, but one issue is obvious, correct this and then edit your post if it is not resolved, and include specific text of error messages.
change
```
i=|date +%A
```
to
```
i=$(date +%A)
```
Then when you execute your last line
```
xdotool type WeekDayIs$i
```
$i will have a value.
... |
8818383 | expect script + how to ignore strings if not appears | 9 | 2012-01-11 11:22:15 | <p>I write the following expect script in order to automate ssh login to remote Linux machine
And run the command "cat /etc/APP_VERSION.txt file"</p>
<p>Sometime I not asked from ssh command about-</p>
<pre><code> "Are you sure you want to continue connecting (yes/no)?"
</code></pre>
<p>So in this case the first... | 19,695 | null | 2017-12-10 07:22:47 | 8,818,879 | 11 | 2012-01-11 12:01:18 | 162,294 | 2012-01-11 12:27:49 | https://stackoverflow.com/q/8818383 | https://stackoverflow.com/a/8818879 | <p>Set a timeout</p>
<blockquote>
<p>set timeout 10</p>
</blockquote>
<p>Will wait for the expected line for 10 seconds, and then move on to the next line in the script if not received within the specified timeout.</p>
<p>Reference
<a href="http://linuxshellaccount.blogspot.com/2008/01/taking-look-at-expect-on-lin... | <p>Set a timeout</p> <blockquote> <p>set timeout 10</p> </blockquote> <p>Will wait for the expected line for 10 seconds, and then move on to the next line in the script if not received within the specified timeout.</p> <p>Reference <a href="http://linuxshellaccount.blogspot.com/2008/01/taking-look-at-expect-on-lin... | 58, 387, 390, 3945, 9048 | bash, expect, linux, shell, tk-toolkit | <h1>expect script + how to ignore strings if not appears</h1>
<p>I write the following expect script in order to automate ssh login to remote Linux machine
And run the command "cat /etc/APP_VERSION.txt file"</p>
<p>Sometime I not asked from ssh command about-</p>
<pre><code> "Are you sure you want to continue con... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,447 | bash | # expect script + how to ignore strings if not appears
I write the following expect script in order to automate ssh login to remote Linux machine
And run the command "cat /etc/APP_VERSION.txt file"
Sometime I not asked from ssh command about-
```
"Are you sure you want to continue connecting (yes/no)?"
```
So i... | Set a timeout
> set timeout 10
Will wait for the expected line for 10 seconds, and then move on to the next line in the script if not received within the specified timeout.
Reference
<http://linuxshellaccount.blogspot.com/2008/01/taking-look-at-expect-on-linux-and-unix.html>
UPDATE:
If a timeout is not an acceptabl... |
8554791 | Different ways to initialize a variable | 9 | 2011-12-18 21:03:15 | <p>As far as I've seen there are two ways to initialize a variable with the output of a process. Is there any difference between these two?</p>
<pre><code>ex1=`echo 'hello world'`
ex2=$(echo 'hello world')
</code></pre>
| 20,341 | 627,005 | 2011-12-19 13:59:30 | 8,554,815 | 11 | 2011-12-18 21:07:31 | 705,676 | 2011-12-19 13:59:30 | https://stackoverflow.com/q/8554791 | https://stackoverflow.com/a/8554815 | <p>You get same effect.</p>
<p>The <code>$()</code> is recommended since it's more readable and makes it easier to nest one <code>$()</code> into another <code>$()</code>.</p>
<p><strong>Update:</strong></p>
<p>The <code>$()</code> syntax is a POSIX 1003.1 standard (2004 edition). However, on some older UNIX systems... | <p>You get same effect.</p> <p>The <code>$()</code> is recommended since it's more readable and makes it easier to nest one <code>$()</code> into another <code>$()</code>.</p> <p><strong>Update:</strong></p> <p>The <code>$()</code> syntax is a POSIX 1003.1 standard (2004 edition). However, on some older UNIX systems... | 276, 367, 387 | bash, syntax, variables | <h1>Different ways to initialize a variable</h1>
<p>As far as I've seen there are two ways to initialize a variable with the output of a process. Is there any difference between these two?</p>
<pre><code>ex1=`echo 'hello world'`
ex2=$(echo 'hello world')
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,448 | bash | # Different ways to initialize a variable
As far as I've seen there are two ways to initialize a variable with the output of a process. Is there any difference between these two?
```
ex1=`echo 'hello world'`
ex2=$(echo 'hello world')
``` | You get same effect.
The `$()` is recommended since it's more readable and makes it easier to nest one `$()` into another `$()`.
**Update:**
The `$()` syntax is a POSIX 1003.1 standard (2004 edition). However, on some older UNIX systems (SunOS, HP-UX, etc.) the `/bin/sh` does not understand it.
You might need to us... |
8182613 | Delphi add menu item in Windows Explorer right click | 9 | 2011-11-18 12:44:21 | <p>How to add a right click context menu in Windows Explorer for all kind of file extension?</p>
<p>From what I read on the internet, I read a way to do this for certain file extension. </p>
<p>My question, how can we do this for all kind of file extension? </p>
<p>I saw some software did this, for example: WinRar, ... | 3,814 | 292,186 | 2011-11-18 15:27:01 | 8,182,781 | 11 | 2011-11-18 12:56:50 | 505,088 | 2011-11-18 12:56:50 | https://stackoverflow.com/q/8182613 | https://stackoverflow.com/a/8182781 | <p>The simplest way to do this is to add a registry entry like this:</p>
<pre><code>HKEY_CLASSES_ROOT
*
shell
YourAppName
Command C:\Full\Path\To\Your\App.exe "%1"
</code></pre>
<p>When the user clicks on this menu item your app will be executed and passed the file name as the first command l... | <p>The simplest way to do this is to add a registry entry like this:</p> <pre><code>HKEY_CLASSES_ROOT * shell YourAppName Command C:\Full\Path\To\Your\App.exe "%1" </code></pre> <p>When the user clicks on this menu item your app will be executed and passed the file name as the first command l... | 118, 390, 4220, 5690 | contextmenu, delphi, shell, windows-explorer | <h1>Delphi add menu item in Windows Explorer right click</h1>
<p>How to add a right click context menu in Windows Explorer for all kind of file extension?</p>
<p>From what I read on the internet, I read a way to do this for certain file extension. </p>
<p>My question, how can we do this for all kind of file extension... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,449 | bash | # Delphi add menu item in Windows Explorer right click
How to add a right click context menu in Windows Explorer for all kind of file extension?
From what I read on the internet, I read a way to do this for certain file extension.
My question, how can we do this for all kind of file extension?
I saw some software d... | The simplest way to do this is to add a registry entry like this:
```
HKEY_CLASSES_ROOT
*
shell
YourAppName
Command C:\Full\Path\To\Your\App.exe "%1"
```
When the user clicks on this menu item your app will be executed and passed the file name as the first command line argument.
Whilst you c... |
7923505 | How to use git hook pre-commit to stop commits to master | 9 | 2011-10-27 23:11:29 | <p>I want to stop myself accidently commiting something to the master branch unless I am sure. So I tried this script to determine which branch I am on but there is a problem. When I create a new branch git name-rev returns master even though I am on the other branch</p>
<pre><code>$ git branch
ignore
master
* set... | 6,278 | 990,524 | 2012-11-13 13:13:09 | 7,923,762 | 11 | 2011-10-27 23:49:13 | 1,864,976 | 2011-12-21 16:24:17 | https://stackoverflow.com/q/7923505 | https://stackoverflow.com/a/7923762 | <p>This command is used to find a friendly name of a commit. What is happening is that HEAD is resolving to the sha1 of the commit first and then a name is determined. I'm guessing it is arbitrarily picking master for the name as it comes up first in what <code>git log --decorate</code> would come across.</p>
<p>I wou... | <p>This command is used to find a friendly name of a commit. What is happening is that HEAD is resolving to the sha1 of the commit first and then a name is determined. I'm guessing it is arbitrarily picking master for the name as it comes up first in what <code>git log --decorate</code> would come across.</p> <p>I wou... | 119, 387, 43087 | bash, git, githooks | <h1>How to use git hook pre-commit to stop commits to master</h1>
<p>I want to stop myself accidently commiting something to the master branch unless I am sure. So I tried this script to determine which branch I am on but there is a problem. When I create a new branch git name-rev returns master even though I am on the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,450 | bash | # How to use git hook pre-commit to stop commits to master
I want to stop myself accidently commiting something to the master branch unless I am sure. So I tried this script to determine which branch I am on but there is a problem. When I create a new branch git name-rev returns master even though I am on the other br... | This command is used to find a friendly name of a commit. What is happening is that HEAD is resolving to the sha1 of the commit first and then a name is determined. I'm guessing it is arbitrarily picking master for the name as it comes up first in what `git log --decorate` would come across.
I would just parse the out... |
6957259 | Using -print0 with -o in find | 9 | 2011-08-05 13:42:17 | <p>I am using -print0 to modify the output of find to use NULL terminators instead of newlines. However I can't get this to work when using find's -o (OR) function.</p>
<p>This works fine, it prints out a newline-separated list of files that are either not owned by user 'pieter' OR not owned by group 'www-data':</p>
... | 2,591 | 350,644 | 2011-08-05 14:03:38 | 6,957,310 | 11 | 2011-08-05 13:45:11 | 115,478 | 2011-08-05 14:03:38 | https://stackoverflow.com/q/6957259 | https://stackoverflow.com/a/6957310 | <p>You're missing parens. Note that you have to escape them so the shell passes them on:</p>
<pre><code>find . \( ! -user pieter -o ! -group www-data \) -print0
</code></pre>
<p>You can find out more about find <a href="http://linux.die.net/man/1/find">on its man page</a>, especially in the Examples section.</p>
<p... | <p>You're missing parens. Note that you have to escape them so the shell passes them on:</p> <pre><code>find . \( ! -user pieter -o ! -group www-data \) -print0 </code></pre> <p>You can find out more about find <a href="http://linux.die.net/man/1/find">on its man page</a>, especially in the Examples section.</p> <p... | 387, 10193 | bash, find | <h1>Using -print0 with -o in find</h1>
<p>I am using -print0 to modify the output of find to use NULL terminators instead of newlines. However I can't get this to work when using find's -o (OR) function.</p>
<p>This works fine, it prints out a newline-separated list of files that are either not owned by user 'pieter' ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,451 | bash | # Using -print0 with -o in find
I am using -print0 to modify the output of find to use NULL terminators instead of newlines. However I can't get this to work when using find's -o (OR) function.
This works fine, it prints out a newline-separated list of files that are either not owned by user 'pieter' OR not owned by ... | You're missing parens. Note that you have to escape them so the shell passes them on:
```
find . \( ! -user pieter -o ! -group www-data \) -print0
```
You can find out more about find [on its man page](http://linux.die.net/man/1/find), especially in the Examples section.
In case you're wondering why that's necessary... |
6204126 | Save well-formed XML from PowerShell | 9 | 2011-06-01 15:58:37 | <p>I create an XmlDocument like this:</p>
<pre><code>$doc = New-Object xml
</code></pre>
<p>Then, after filling it with nodes, I save it:</p>
<pre><code>$doc.Save($fileName)
</code></pre>
<p>The problem is that it does not add the XML declaration to the beginning of the document, resulting in malformed document. In... | 17,463 | 140,367 | 2011-06-01 16:43:39 | 6,204,432 | 11 | 2011-06-01 16:19:17 | 243 | 2011-06-01 16:19:17 | https://stackoverflow.com/q/6204126 | https://stackoverflow.com/a/6204432 | <p>You need to use the <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.aspx">XmlTextWriter</a> class to format the output. Here is a sample, though you may want to evolve it for any specific needs you have beyond adding the header:</p>
<pre><code>$doc = [xml]"<html>Value</html>"
$... | <p>You need to use the <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.aspx">XmlTextWriter</a> class to format the output. Here is a sample, though you may want to evolve it for any specific needs you have beyond adding the header:</p> <pre><code>$doc = [xml]"<html>Value</html>" $... | 19, 526 | powershell, xml | <h1>Save well-formed XML from PowerShell</h1>
<p>I create an XmlDocument like this:</p>
<pre><code>$doc = New-Object xml
</code></pre>
<p>Then, after filling it with nodes, I save it:</p>
<pre><code>$doc.Save($fileName)
</code></pre>
<p>The problem is that it does not add the XML declaration to the beginning of the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,452 | bash | # Save well-formed XML from PowerShell
I create an XmlDocument like this:
```
$doc = New-Object xml
```
Then, after filling it with nodes, I save it:
```
$doc.Save($fileName)
```
The problem is that it does not add the XML declaration to the beginning of the document, resulting in malformed document. In other word... | You need to use the [XmlTextWriter](http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.aspx) class to format the output. Here is a sample, though you may want to evolve it for any specific needs you have beyond adding the header:
```
$doc = [xml]"<html>Value</html>"
$sb = New-Object System.Text.StringBui... |
5504415 | How can I use a Bash array as input to a command? | 9 | 2011-03-31 18:15:57 | <p>Say, for example, I have the following array:</p>
<pre><code>files=( "foo" "bar" "baz fizzle" )
</code></pre>
<p>I want to pipe the contents of this array through a command, say <code>sort</code>, as though each element where a line in a file. Sure, I could write the array to a temporary file, then use the tempora... | 8,702 | 86,436 | 2023-05-08 19:21:37 | 5,504,472 | 11 | 2011-03-31 18:20:57 | 20,862 | 2011-03-31 18:20:57 | https://stackoverflow.com/q/5504415 | https://stackoverflow.com/a/5504472 | <pre><code>sort <(for f in "${files[@]}" ; do echo "$f" ; done)
</code></pre>
| <pre><code>sort <(for f in "${files[@]}" ; do echo "$f" ; done) </code></pre> | 114, 387, 3705, 5813 | arrays, bash, newline, pipe | <h1>How can I use a Bash array as input to a command?</h1>
<p>Say, for example, I have the following array:</p>
<pre><code>files=( "foo" "bar" "baz fizzle" )
</code></pre>
<p>I want to pipe the contents of this array through a command, say <code>sort</code>, as though each element where a line in a file. Sure, I coul... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,453 | bash | # How can I use a Bash array as input to a command?
Say, for example, I have the following array:
```
files=( "foo" "bar" "baz fizzle" )
```
I want to pipe the contents of this array through a command, say `sort`, as though each element where a line in a file. Sure, I could write the array to a temporary file, then ... | ```
sort <(for f in "${files[@]}" ; do echo "$f" ; done)
``` |
4685184 | powershell run java process problem | 9 | 2011-01-13 20:59:43 | <p>I'm trying to run a java process via Powershell in Windows XP. Here's the command:</p>
<pre><code>java.exe -cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install
</code></pre>
<p>So, the classpath is . and .\common.jar (I think java takes the wrong slashes, right?) There are two environment variables, o... | 28,743 | 200,985 | 2020-11-09 22:42:12 | 4,726,368 | 11 | 2011-01-18 16:22:43 | 200,985 | 2020-11-09 22:42:12 | https://stackoverflow.com/q/4685184 | https://stackoverflow.com/a/4726368 | <p>The problem is that PS for some reason parses <code>-Dresourcepath=.</code> differently than cmd. What works is</p>
<pre><code>java -cp '.;.\common.jar' -Dcontext=atest1 "-Dresourcepath=." DW_Install
</code></pre>
<p>It doesn't matter which way the slash goes, and it doesn't matter which quotes one uses (... | <p>The problem is that PS for some reason parses <code>-Dresourcepath=.</code> differently than cmd. What works is</p> <pre><code>java -cp '.;.\common.jar' -Dcontext=atest1 "-Dresourcepath=." DW_Install </code></pre> <p>It doesn't matter which way the slash goes, and it doesn't matter which quotes one uses (... | 17, 526, 1231 | command-line, java, powershell | <h1>powershell run java process problem</h1>
<p>I'm trying to run a java process via Powershell in Windows XP. Here's the command:</p>
<pre><code>java.exe -cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install
</code></pre>
<p>So, the classpath is . and .\common.jar (I think java takes the wrong slashes, ri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,454 | bash | # powershell run java process problem
I'm trying to run a java process via Powershell in Windows XP. Here's the command:
```
java.exe -cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install
```
So, the classpath is . and .\common.jar (I think java takes the wrong slashes, right?) There are two environment va... | The problem is that PS for some reason parses `-Dresourcepath=.` differently than cmd. What works is
```
java -cp '.;.\common.jar' -Dcontext=atest1 "-Dresourcepath=." DW_Install
```
It doesn't matter which way the slash goes, and it doesn't matter which quotes one uses (`'` or `"`). The classpath must be escaped, how... |
4405200 | Can I make Control-U behavior be the same for ZSH as it is for Bash? | 9 | 2010-12-10 02:41:15 | <p>In Bash, <kbd>Ctrl</kbd>+<kbd>u</kbd> will clear from the cursor to the beginning of the line, and put that text into the paste buffer, which can be pasted with <kbd>Ctrl</kbd>+<kbd>y</kbd>.</p>
<p>In Zsh, it will clear the text, but does not put it into the buffer.</p>
<p>Sadness.</p>
| 959 | 168,143 | 2023-11-14 16:06:00 | 4,405,239 | 11 | 2010-12-10 02:52:51 | 54,928 | 2010-12-10 02:52:51 | https://stackoverflow.com/q/4405200 | https://stackoverflow.com/a/4405239 | <p>This can be done really easily with just two <code>bindkey</code> commands:</p>
<pre><code>bindkey '^U' backward-kill-line
bindkey '^Y' yank
</code></pre>
<p>It may be worth noting that at least '^Y' should be bound in the default Emacs keymap.</p>
| <p>This can be done really easily with just two <code>bindkey</code> commands:</p> <pre><code>bindkey '^U' backward-kill-line bindkey '^Y' yank </code></pre> <p>It may be worth noting that at least '^Y' should be bound in the default Emacs keymap.</p> | 387, 3791 | bash, zsh | <h1>Can I make Control-U behavior be the same for ZSH as it is for Bash?</h1>
<p>In Bash, <kbd>Ctrl</kbd>+<kbd>u</kbd> will clear from the cursor to the beginning of the line, and put that text into the paste buffer, which can be pasted with <kbd>Ctrl</kbd>+<kbd>y</kbd>.</p>
<p>In Zsh, it will clear the text, but does ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,455 | bash | # Can I make Control-U behavior be the same for ZSH as it is for Bash?
In Bash, `Ctrl`+`u` will clear from the cursor to the beginning of the line, and put that text into the paste buffer, which can be pasted with `Ctrl`+`y`.
In Zsh, it will clear the text, but does not put it into the buffer.
Sadness. | This can be done really easily with just two `bindkey` commands:
```
bindkey '^U' backward-kill-line
bindkey '^Y' yank
```
It may be worth noting that at least '^Y' should be bound in the default Emacs keymap. |
4111967 | Bash script to scp newest file in a directory on a remote server | 9 | 2010-11-06 04:55:43 | <p>Ok so I kinda know how to do this locally with a find then cp command, but don't know how to do the same remotely with scp.</p>
<p>So know this:</p>
<pre><code>scp -vp me@server:/target/location/ /destination/dir/.
</code></pre>
<p>That target directory is going to be full of database backups, how can I tell it t... | 11,175 | 439,510 | 2015-03-15 14:20:58 | 4,112,014 | 11 | 2010-11-06 05:09:10 | 140,740 | 2010-11-06 05:16:58 | https://stackoverflow.com/q/4111967 | https://stackoverflow.com/a/4112014 | <pre><code>remote_dir=/what/ever
dst=remote-system.host.name.com
scp $dst:`ssh $dst ls -1td $remote_dir/\* | head -1` /tmp/lastmod
</code></pre>
| <pre><code>remote_dir=/what/ever dst=remote-system.host.name.com scp $dst:`ssh $dst ls -1td $remote_dir/\* | head -1` /tmp/lastmod </code></pre> | 387, 493, 601, 3149, 28995 | backup, bash, cron, database-backups, scp | <h1>Bash script to scp newest file in a directory on a remote server</h1>
<p>Ok so I kinda know how to do this locally with a find then cp command, but don't know how to do the same remotely with scp.</p>
<p>So know this:</p>
<pre><code>scp -vp me@server:/target/location/ /destination/dir/.
</code></pre>
<p>That tar... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,456 | bash | # Bash script to scp newest file in a directory on a remote server
Ok so I kinda know how to do this locally with a find then cp command, but don't know how to do the same remotely with scp.
So know this:
```
scp -vp me@server:/target/location/ /destination/dir/.
```
That target directory is going to be full of dat... | ```
remote_dir=/what/ever
dst=remote-system.host.name.com
scp $dst:`ssh $dst ls -1td $remote_dir/\* | head -1` /tmp/lastmod
``` |
3245015 | Get list of USB devices connected currently and their dev file in BASH | 9 | 2010-07-14 09:52:07 | <p>What is the bash command for detecting all currently connected USB devices and getting the /dev/tty... file that corresponds to the USB device. </p>
| 32,612 | 200,477 | 2017-05-31 18:18:46 | 3,245,069 | 11 | 2010-07-14 10:00:59 | 57,095 | 2010-07-14 10:06:41 | https://stackoverflow.com/q/3245015 | https://stackoverflow.com/a/3245069 | <p>Give <code>lsusb</code> a try; for the corresponding file I plug in the device and use <code>dmesg</code>, but there sure is a better way...</p>
| <p>Give <code>lsusb</code> a try; for the corresponding file I plug in the device and use <code>dmesg</code>, but there sure is a better way...</p> | 34, 387, 393 | bash, unix, usb | <h1>Get list of USB devices connected currently and their dev file in BASH</h1>
<p>What is the bash command for detecting all currently connected USB devices and getting the /dev/tty... file that corresponds to the USB device. </p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,457 | bash | # Get list of USB devices connected currently and their dev file in BASH
What is the bash command for detecting all currently connected USB devices and getting the /dev/tty... file that corresponds to the USB device. | Give `lsusb` a try; for the corresponding file I plug in the device and use `dmesg`, but there sure is a better way... |
2659590 | Pipe implementation | 9 | 2010-04-17 18:59:29 | <p>I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing.</p>
<p>I have already read about it and seen some snippets of code, but still haven't been able to sort out a working solution.</p>
<p>What I ... | 13,023 | 161,746 | 2018-03-13 00:48:20 | 2,661,833 | 11 | 2010-04-18 10:01:02 | 134,633 | 2018-03-13 00:48:20 | https://stackoverflow.com/q/2659590 | https://stackoverflow.com/a/2661833 | <p>You need to replace one child's stdout with the writing end of the pipe, and the other child's stdin with the reading end:</p>
<pre><code>if (pid == 0)
{
close(fd[0]); //close read from pipe, in parent
dup2(fd[1], STDOUT_FILENO); // Replace stdout with the write end of the pipe
close(fd[1]); // Don't n... | <p>You need to replace one child's stdout with the writing end of the pipe, and the other child's stdin with the reading end:</p> <pre><code>if (pid == 0) { close(fd[0]); //close read from pipe, in parent dup2(fd[1], STDOUT_FILENO); // Replace stdout with the write end of the pipe close(fd[1]); // Don't n... | 8, 58, 390, 5813, 19486 | c, linux, pipe, piping, shell | <h1>Pipe implementation</h1>
<p>I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing.</p>
<p>I have already read about it and seen some snippets of code, but still haven't been able to sort out a work... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,458 | bash | # Pipe implementation
I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing.
I have already read about it and seen some snippets of code, but still haven't been able to sort out a working solution.
W... | You need to replace one child's stdout with the writing end of the pipe, and the other child's stdin with the reading end:
```
if (pid == 0)
{
close(fd[0]); //close read from pipe, in parent
dup2(fd[1], STDOUT_FILENO); // Replace stdout with the write end of the pipe
close(fd[1]); // Don't need another co... |
805361 | Why do I get this error using {1..9} in zsh? | 9 | 2009-04-30 04:42:02 | <p>I run the following code</p>
<pre><code>zgrep -c compinit /usr/share/man/man{1..9}/zsh*
</code></pre>
<p>I get</p>
<pre><code>zsh: no matches found: /usr/share/man/man2/zsh*
</code></pre>
<p>This is strange, since the following works</p>
<pre><code>echo Masi{1..9}/masi
</code></pre>
<p>This suggests me that th... | 18,258 | 54,964 | 2014-08-09 23:08:53 | 805,367 | 11 | 2009-04-30 04:49:46 | 47,529 | 2009-04-30 04:49:46 | https://stackoverflow.com/q/805361 | https://stackoverflow.com/a/805367 | <p>It's not a bug, and it is working inside words fine. The trouble you're having here is that <code>{1..9}</code> is not a wildcard expression like <code>*</code> is; as your echo example shows, it's an iterative expansion. So your zgrep example is exactly the same as if you had typed each alternate version into the... | <p>It's not a bug, and it is working inside words fine. The trouble you're having here is that <code>{1..9}</code> is not a wildcard expression like <code>*</code> is; as your echo example shows, it's an iterative expansion. So your zgrep example is exactly the same as if you had typed each alternate version into the... | 390, 3791, 19863 | expansion, shell, zsh | <h1>Why do I get this error using {1..9} in zsh?</h1>
<p>I run the following code</p>
<pre><code>zgrep -c compinit /usr/share/man/man{1..9}/zsh*
</code></pre>
<p>I get</p>
<pre><code>zsh: no matches found: /usr/share/man/man2/zsh*
</code></pre>
<p>This is strange, since the following works</p>
<pre><code>echo Masi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,459 | bash | # Why do I get this error using {1..9} in zsh?
I run the following code
```
zgrep -c compinit /usr/share/man/man{1..9}/zsh*
```
I get
```
zsh: no matches found: /usr/share/man/man2/zsh*
```
This is strange, since the following works
```
echo Masi{1..9}/masi
```
This suggests me that the problem may be a bug in Z... | It's not a bug, and it is working inside words fine. The trouble you're having here is that `{1..9}` is not a wildcard expression like `*` is; as your echo example shows, it's an iterative expansion. So your zgrep example is exactly the same as if you had typed each alternate version into the command line, and then sin... |
739477 | How to reverse sed output? | 9 | 2009-04-11 03:52:35 | <p>I'm reading from a line that's about 500 characters. How can I get sed to, instead of replacing that string with something, replace the rest of the line with something?
In short, I want to remove all the text around a specified string. Deleting columns with awk won't work, because there is an indeterminate amount of... | 8,496 | null | 2009-04-11 04:26:39 | 739,491 | 11 | 2009-04-11 04:00:18 | 9,122 | 2009-04-11 04:26:39 | https://stackoverflow.com/q/739477 | https://stackoverflow.com/a/739491 | <p>Try using back references:</p>
<pre><code>sed 's/.*\(searchstring\).*/___\1___/'
</code></pre>
<p>The <code>.*</code>'s around the search string will match everything but the string, and the parentheses tell <code>sed</code> to remember what it matched. You can refer to the first matched string with <code>\1</cod... | <p>Try using back references:</p> <pre><code>sed 's/.*\(searchstring\).*/___\1___/' </code></pre> <p>The <code>.*</code>'s around the search string will match everything but the string, and the parentheses tell <code>sed</code> to remember what it matched. You can refer to the first matched string with <code>\1</cod... | 34, 139, 390, 5282 | sed, shell, string, unix | <h1>How to reverse sed output?</h1>
<p>I'm reading from a line that's about 500 characters. How can I get sed to, instead of replacing that string with something, replace the rest of the line with something?
In short, I want to remove all the text around a specified string. Deleting columns with awk won't work, because... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,460 | bash | # How to reverse sed output?
I'm reading from a line that's about 500 characters. How can I get sed to, instead of replacing that string with something, replace the rest of the line with something?
In short, I want to remove all the text around a specified string. Deleting columns with awk won't work, because there is... | Try using back references:
```
sed 's/.*\(searchstring\).*/___\1___/'
```
The `.*`'s around the search string will match everything but the string, and the parentheses tell `sed` to remember what it matched. You can refer to the first matched string with `\1`.
Here's an example (replacing everything but 'bar baz'):
... |
71629882 | Bash function: Is there a way to check if a variable was defined locally? | 8 | 2022-03-26 16:30:53 | <p>Suppose that you have a function with a lot of options and that you decide to store their value dynamically:</p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/bash
fun() {
local OPTIND __option
while getopts ":$(printf '%s:' {a..z} {A..Z})" __option
do
case $__option in
... | 1,085 | 3,387,716 | 2024-11-30 12:50:17 | 71,630,161 | 11 | 2022-03-26 17:09:59 | 7,939,871 | 2022-03-26 17:09:59 | https://stackoverflow.com/q/71629882 | https://stackoverflow.com/a/71630161 | <p>You can definitely detect a variable is local (if it has been declared with one of Bash's <code>declare</code>, <code>local</code>, <code>typeset</code> statements).</p>
<p>Here is an illustration:</p>
<pre class="lang-sh prettyprint-override"><code>#!/usr/bin/env bash
a=3
b=2
fn() {
declare a=1
b=7
if local... | <p>You can definitely detect a variable is local (if it has been declared with one of Bash's <code>declare</code>, <code>local</code>, <code>typeset</code> statements).</p> <p>Here is an illustration:</p> <pre class="lang-sh prettyprint-override"><code>#!/usr/bin/env bash a=3 b=2 fn() { declare a=1 b=7 if local... | 387 | bash | <h1>Bash function: Is there a way to check if a variable was defined locally?</h1>
<p>Suppose that you have a function with a lot of options and that you decide to store their value dynamically:</p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/bash
fun() {
local OPTIND __option
while getopts ":$... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,461 | bash | # Bash function: Is there a way to check if a variable was defined locally?
Suppose that you have a function with a lot of options and that you decide to store their value dynamically:
```
#!/bin/bash
fun() {
local OPTIND __option
while getopts ":$(printf '%s:' {a..z} {A..Z})" __option
do
case $_... | You can definitely detect a variable is local (if it has been declared with one of Bash's `declare`, `local`, `typeset` statements).
Here is an illustration:
```
#!/usr/bin/env bash
a=3
b=2
fn() {
declare a=1
b=7
if local -p a >/dev/null 2>&1; then
printf 'a is local with value %s\n' "$a"
else
print... |
71459823 | How to change the terminal title to currently running process? | 8 | 2022-03-13 18:50:29 | <p>I know <a href="https://askubuntu.com/questions/22413/how-to-change-gnome-terminal-title">how to change the Terminal Window title</a>. What I am trying to find out is how to make <code>bash</code> not <code>zsh</code> write out the currently running process so if I say do</p>
<pre><code>$ ls -lF
</code></pre>
<p>I ... | 13,228 | 242,042 | 2024-12-17 11:08:24 | 71,460,201 | 11 | 2022-03-13 19:36:32 | 7,366,100 | 2024-08-28 13:56:34 | https://stackoverflow.com/q/71459823 | https://stackoverflow.com/a/71460201 | <p><strong>UPDATE</strong>: my previous answer (at end of this post) displays the <em>previous</em> command in the title bar.</p>
<p>Ignoring everything from my previous answer and starting from scratch:</p>
<pre><code>trap 'echo -ne "\033]0;${PWD}: (${BASH_COMMAND})\007"' DEBUG
</code></pre>
<p>Running the f... | <p><strong>UPDATE</strong>: my previous answer (at end of this post) displays the <em>previous</em> command in the title bar.</p> <p>Ignoring everything from my previous answer and starting from scratch:</p> <pre><code>trap 'echo -ne "\033]0;${PWD}: (${BASH_COMMAND})\007"' DEBUG </code></pre> <p>Running the f... | 387, 138178 | bash, windows-terminal | <h1>How to change the terminal title to currently running process?</h1>
<p>I know <a href="https://askubuntu.com/questions/22413/how-to-change-gnome-terminal-title">how to change the Terminal Window title</a>. What I am trying to find out is how to make <code>bash</code> not <code>zsh</code> write out the currently ru... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,462 | bash | # How to change the terminal title to currently running process?
I know [how to change the Terminal Window title](https://askubuntu.com/questions/22413/how-to-change-gnome-terminal-title). What I am trying to find out is how to make `bash` not `zsh` write out the currently running process so if I say do
```
$ ls -lF
... | **UPDATE**: my previous answer (at end of this post) displays the *previous* command in the title bar.
Ignoring everything from my previous answer and starting from scratch:
```
trap 'echo -ne "\033]0;${PWD}: (${BASH_COMMAND})\007"' DEBUG
```
Running the following at the command prompt:
```
$ sleep 10
```
The wind... |
69759506 | Is it possible to construct a shebang that works for both Python 2 and 3? | 8 | 2021-10-28 18:57:10 | <p>I need to write a Python script that's compatible with both Python 2 and Python 3, can be called directly from a shell (meaning it has a shebang), and can run on systems that have either Python version installed, but possibly not both.</p>
<p>Normally I can write a shebang for Python 2 like so:</p>
<pre><code>#!/usr... | 978 | 1,079,430 | 2023-03-11 12:36:44 | 69,760,814 | 11 | 2021-10-28 20:54:09 | 1,899,640 | 2021-10-28 22:04:55 | https://stackoverflow.com/q/69759506 | https://stackoverflow.com/a/69760814 | <p>Realistically I would just specify <code>python3</code> and make that a prerequisite.</p>
<p>However, it's technically possible to trick a Python file into being its own shell script wrapper:</p>
<pre><code>#!/bin/sh
''':'
for name in python3 python2 python
do
type "$name" > /dev/null 2>&1 &a... | <p>Realistically I would just specify <code>python3</code> and make that a prerequisite.</p> <p>However, it's technically possible to trick a Python file into being its own shell script wrapper:</p> <pre><code>#!/bin/sh ''':' for name in python3 python2 python do type "$name" > /dev/null 2>&1 &a... | 16, 390, 8780, 60010 | python, python-3.x, shebang, shell | <h1>Is it possible to construct a shebang that works for both Python 2 and 3?</h1>
<p>I need to write a Python script that's compatible with both Python 2 and Python 3, can be called directly from a shell (meaning it has a shebang), and can run on systems that have either Python version installed, but possibly not both... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,463 | bash | # Is it possible to construct a shebang that works for both Python 2 and 3?
I need to write a Python script that's compatible with both Python 2 and Python 3, can be called directly from a shell (meaning it has a shebang), and can run on systems that have either Python version installed, but possibly not both.
Normal... | Realistically I would just specify `python3` and make that a prerequisite.
However, it's technically possible to trick a Python file into being its own shell script wrapper:
```
#!/bin/sh
''':'
for name in python3 python2 python
do
type "$name" > /dev/null 2>&1 && exec "$name" "$0" "$@"
done
echo >&2 "Please inst... |
68125700 | Difference between ctrl-z and "&" in linux | 8 | 2021-06-25 05:01:10 | <p>My understanding is that when you are running any command (say <code>sleep 10</code>) within a given shell (say bash), what's happening under the hood is that a fork system call is called, and <code>sleep 10</code> is now running as a child process with the parent being the bash shell I executed the sleep.</p>
<p>No... | 11,889 | 5,041,045 | 2021-06-25 05:15:41 | 68,125,806 | 11 | 2021-06-25 05:15:41 | 9,072,753 | 2021-06-25 05:15:41 | https://stackoverflow.com/q/68125700 | https://stackoverflow.com/a/68125806 | <blockquote>
<p>or run sleep 10 and press ctrl+z so the process is sent to the background</p>
</blockquote>
<p>No, not really. Didn't you see that big message that says "[1]+ <strong>Stopped</strong> sleep 10"? <code>ctrl+z</code> <strong>stops</strong> the process and returns you to the current shell. You ca... | <blockquote> <p>or run sleep 10 and press ctrl+z so the process is sent to the background</p> </blockquote> <p>No, not really. Didn't you see that big message that says "[1]+ <strong>Stopped</strong> sleep 10"? <code>ctrl+z</code> <strong>stops</strong> the process and returns you to the current shell. You ca... | 58, 387, 390, 5910 | bash, linux, process, shell | <h1>Difference between ctrl-z and "&" in linux</h1>
<p>My understanding is that when you are running any command (say <code>sleep 10</code>) within a given shell (say bash), what's happening under the hood is that a fork system call is called, and <code>sleep 10</code> is now running as a child process with the parent ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,464 | bash | # Difference between ctrl-z and "&" in linux
My understanding is that when you are running any command (say `sleep 10`) within a given shell (say bash), what's happening under the hood is that a fork system call is called, and `sleep 10` is now running as a child process with the parent being the bash shell I executed... | > or run sleep 10 and press ctrl+z so the process is sent to the background
No, not really. Didn't you see that big message that says "[1]+ **Stopped** sleep 10"? `ctrl+z` **stops** the process and returns you to the current shell. You can now type `fg` to continue process, or type `bg` to continue the process in the ... |
68018145 | Export/SET environment variables in windows through a shell script | 8 | 2021-06-17 11:10:14 | <p>There is a script.sh file</p>
<pre><code> set FABRIC_CFG_PATH=<some path>
set CORE_PEER_LOCALMSPID=<some id>
</code></pre>
<p>If I'm running this script in windows, the env variables are not getting set.
Whereas if setting the env using the cmd approach,
E.g., on windows cmd
<code>set FABRIC_CFG_PATH=&l... | 28,293 | 12,337,007 | 2024-04-03 03:12:09 | 68,024,909 | 11 | 2021-06-17 18:40:58 | 45,375 | 2024-04-03 03:12:09 | https://stackoverflow.com/q/68018145 | https://stackoverflow.com/a/68024909 |
<p>Since your intent is <strong>to define <em>current-process-only</em> environment variables</strong> (rather than <em>persistently</em> defined ones, which on Windows are stored in the registry) <strong>you need to use a script file / batch file that runs <em>in-process</em></strong> in order for environment variabl... | <p>Since your intent is <strong>to define <em>current-process-only</em> environment variables</strong> (rather than <em>persistently</em> defined ones, which on Windows are stored in the registry) <strong>you need to use a script file / batch file that runs <em>in-process</em></strong> in order for environment variabl... | 526, 2631, 4167, 8470, 9013 | cmd, environment-variables, export, powershell, set | <h1>Export/SET environment variables in windows through a shell script</h1>
<p>There is a script.sh file</p>
<pre><code> set FABRIC_CFG_PATH=<some path>
set CORE_PEER_LOCALMSPID=<some id>
</code></pre>
<p>If I'm running this script in windows, the env variables are not getting set.
Whereas if setting the e... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,465 | bash | # Export/SET environment variables in windows through a shell script
There is a script.sh file
```
set FABRIC_CFG_PATH=<some path>
set CORE_PEER_LOCALMSPID=<some id>
```
If I'm running this script in windows, the env variables are not getting set.
Whereas if setting the env using the cmd approach,
E.g., on windows... | Since your intent is **to define *current-process-only* environment variables** (rather than *persistently* defined ones, which on Windows are stored in the registry) **you need to use a script file / batch file that runs *in-process*** in order for environment variables defined therein to be seen by the script's calle... |
67287029 | How kill a process using powershell without getting errors when the process does not exist | 8 | 2021-04-27 16:27:21 | <p>I want to kill the nodepad process if it exists. If I use this:</p>
<pre><code>PS C:\> get-process -name notepad | Stop-Process -Force
</code></pre>
<p>I will get an error when the process does not exist.</p>
<pre><code>get-process : Cannot find a process with the name "notepad". Verify the process name... | 11,806 | 14,222,243 | 2023-01-10 08:47:03 | 67,287,120 | 11 | 2021-04-27 16:33:49 | 8,475,133 | 2021-04-27 16:33:49 | https://stackoverflow.com/q/67287029 | https://stackoverflow.com/a/67287120 | <p>Just add <code>-ErrorAction SilentlyContinue</code>. This one is simpler and does not prompt any erros if process does not exist.</p>
<pre><code>Get-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process -Force
</code></pre>
| <p>Just add <code>-ErrorAction SilentlyContinue</code>. This one is simpler and does not prompt any erros if process does not exist.</p> <pre><code>Get-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process -Force </code></pre> | 64, 526, 141818 | clamav, powershell, windows | <h1>How kill a process using powershell without getting errors when the process does not exist</h1>
<p>I want to kill the nodepad process if it exists. If I use this:</p>
<pre><code>PS C:\> get-process -name notepad | Stop-Process -Force
</code></pre>
<p>I will get an error when the process does not exist.</p>
<pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,466 | bash | # How kill a process using powershell without getting errors when the process does not exist
I want to kill the nodepad process if it exists. If I use this:
```
PS C:\> get-process -name notepad | Stop-Process -Force
```
I will get an error when the process does not exist.
```
get-process : Cannot find a process wi... | Just add `-ErrorAction SilentlyContinue`. This one is simpler and does not prompt any erros if process does not exist.
```
Get-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process -Force
``` |
64192561 | How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file? | 8 | 2020-10-04 08:27:11 | <p>How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file? as in <a href="https://windows.php.net/download" rel="noreferrer">PHP versions</a> for example.</p>
| 6,919 | 458,204 | 2023-06-25 00:41:18 | 64,192,562 | 11 | 2020-10-04 08:27:11 | 458,204 | 2020-10-05 08:36:34 | https://stackoverflow.com/q/64192561 | https://stackoverflow.com/a/64192562 | <p>The easiest way to validate sha256 hash of a file in Git Bash terminal is like this:</p>
<pre><code># Go to the directory in which the downloaded file exists
cd /path/to/directory/
# Validate sha256 hash of the file
sha256sum name_of_the_file
</code></pre>
<p>This will print, in the terminal, the sha256 hash of the... | <p>The easiest way to validate sha256 hash of a file in Git Bash terminal is like this:</p> <pre><code># Go to the directory in which the downloaded file exists cd /path/to/directory/ # Validate sha256 hash of the file sha256sum name_of_the_file </code></pre> <p>This will print, in the terminal, the sha256 hash of the... | 391, 581, 13892, 61874 | git-bash, hash, sha256, terminal | <h1>How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file?</h1>
<p>How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file? as in <a href="https://windows.php.net/download" rel="noreferrer">PHP versions</a> for example.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,467 | bash | # How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file?
How to use Git Bash terminal on Windows to validate sha256 hash of a downloaded file? as in [PHP versions](https://windows.php.net/download) for example. | The easiest way to validate sha256 hash of a file in Git Bash terminal is like this:
```
# Go to the directory in which the downloaded file exists
cd /path/to/directory/
# Validate sha256 hash of the file
sha256sum name_of_the_file
```
This will print, in the terminal, the sha256 hash of the file and you can then co... |
64048945 | Save slurm job ID as you submit the job with sbatch | 8 | 2020-09-24 14:47:49 | <p>Is there a way to submit a job to slurm with sbatch and record the job id into a variable?</p>
<pre><code>job_id = sbatch --account my_account some_script.sh
echo $job_id
17210254
</code></pre>
| 2,156 | 12,430,026 | 2024-09-10 06:31:11 | 64,048,946 | 11 | 2020-09-24 14:47:49 | 12,430,026 | 2020-09-24 14:47:49 | https://stackoverflow.com/q/64048945 | https://stackoverflow.com/a/64048946 | <p>This can be done with <code>--parsable</code></p>
<pre><code>job_id=$(sbatch --parsable test.sh)
echo $job_id
17211434
</code></pre>
| <p>This can be done with <code>--parsable</code></p> <pre><code>job_id=$(sbatch --parsable test.sh) echo $job_id 17211434 </code></pre> | 390, 97759 | shell, slurm | <h1>Save slurm job ID as you submit the job with sbatch</h1>
<p>Is there a way to submit a job to slurm with sbatch and record the job id into a variable?</p>
<pre><code>job_id = sbatch --account my_account some_script.sh
echo $job_id
17210254
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,468 | bash | # Save slurm job ID as you submit the job with sbatch
Is there a way to submit a job to slurm with sbatch and record the job id into a variable?
```
job_id = sbatch --account my_account some_script.sh
echo $job_id
17210254
``` | This can be done with `--parsable`
```
job_id=$(sbatch --parsable test.sh)
echo $job_id
17211434
``` |
58516065 | What's the right way to emit errors in powershell module functions? | 8 | 2019-10-23 05:33:19 | <p>I've read quite a bit on powershell error handling and now I'm quite confused about what I should be doing on any given situation (error handling). I'm working with powershell 5.1 (not core).
With that said:
Suppose I have a module with a function that would look like this mock:</p>
<pre><code>function Set-Computer... | 3,010 | 450,499 | 2024-11-06 01:54:08 | 58,528,359 | 11 | 2019-10-23 17:44:00 | 45,375 | 2024-11-06 01:54:08 | https://stackoverflow.com/q/58516065 | https://stackoverflow.com/a/58528359 | <ul>
<li><p><strong>If you want to <em>continue</em> processing inputs from the pipeline, you must emit a <em>non-terminating</em> error</strong>:</p>
<ul>
<li><p><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-error" rel="nofollow noreferrer"><code>Write-Error</code></a>... | <ul> <li><p><strong>If you want to <em>continue</em> processing inputs from the pipeline, you must emit a <em>non-terminating</em> error</strong>:</p> <ul> <li><p><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-error" rel="nofollow noreferrer"><code>Write-Error</code></a>... | 526, 108010 | powershell, powershell-5.0 | <h1>What's the right way to emit errors in powershell module functions?</h1>
<p>I've read quite a bit on powershell error handling and now I'm quite confused about what I should be doing on any given situation (error handling). I'm working with powershell 5.1 (not core).
With that said:
Suppose I have a module with a f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,469 | bash | # What's the right way to emit errors in powershell module functions?
I've read quite a bit on powershell error handling and now I'm quite confused about what I should be doing on any given situation (error handling). I'm working with powershell 5.1 (not core).
With that said:
Suppose I have a module with a function t... | - **If you want to *continue* processing inputs from the pipeline, you must emit a *non-terminating* error**:
- [`Write-Error`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-error) writes non-terminating errors; it writes to PowerShell's error stream without generating an exc... |
57728801 | How to convert a huge single line json file to a multi line file without opening it? | 8 | 2019-08-30 14:37:16 | <p>I have a large (around 200Mb) single-line json file and I want to convert this to a more readable multi-line json (or txt) file. </p>
<p>I tried to open the file with text editors like sublime text and it takes forever to open. So, I would like to make the conversion without opening the file.</p>
<p>Therefore, I c... | 10,400 | 8,889,727 | 2019-08-30 15:30:16 | 57,729,080 | 11 | 2019-08-30 14:55:44 | 5,223,223 | 2019-08-30 15:05:46 | https://stackoverflow.com/q/57728801 | https://stackoverflow.com/a/57729080 | <p>The simplest method would be using <code>jq</code> to pretty print the json:</p>
<pre><code>jq . myjsonfile.json > pretty.json
</code></pre>
<p>But from the python output, I suspect the json file may be ill-formed.</p>
| <p>The simplest method would be using <code>jq</code> to pretty print the json:</p> <pre><code>jq . myjsonfile.json > pretty.json </code></pre> <p>But from the python output, I suspect the json file may be ill-formed.</p> | 387, 549, 1508 | bash, json, ubuntu | <h1>How to convert a huge single line json file to a multi line file without opening it?</h1>
<p>I have a large (around 200Mb) single-line json file and I want to convert this to a more readable multi-line json (or txt) file. </p>
<p>I tried to open the file with text editors like sublime text and it takes forever to ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,470 | bash | # How to convert a huge single line json file to a multi line file without opening it?
I have a large (around 200Mb) single-line json file and I want to convert this to a more readable multi-line json (or txt) file.
I tried to open the file with text editors like sublime text and it takes forever to open. So, I would... | The simplest method would be using `jq` to pretty print the json:
```
jq . myjsonfile.json > pretty.json
```
But from the python output, I suspect the json file may be ill-formed. |
57023626 | Why does PowerShell flatten arrays automatically? | 8 | 2019-07-14 00:00:06 | <p>I've written some pwsh code</p>
<pre class="lang-bsh prettyprint-override"><code>"a:b;c:d;e:f".Split(";") | ForEach-Object { $_.Split(":") }
# => @(a, b, c, d, e, f)
</code></pre>
<p>but I want this</p>
<pre class="lang-js prettyprint-override"><code>// in javascript
"a:b;c:d;e:f".split(";").map(str => str.... | 1,075 | 11,781,198 | 2020-06-26 22:41:26 | 57,023,751 | 11 | 2019-07-14 00:31:02 | 45,375 | 2020-06-24 21:59:13 | https://stackoverflow.com/q/57023626 | https://stackoverflow.com/a/57023751 | <p>Use the unary form of <code>,</code>, PowerShell's array-construction operator:</p>
<pre><code>"a:b;c:d;e:f".Split(";") | ForEach-Object { , $_.Split(":") }
</code></pre>
<p>That way, the array returned by <code>$_.Split(":")</code> is effectively output as-is, as an <em>array... | <p>Use the unary form of <code>,</code>, PowerShell's array-construction operator:</p> <pre><code>"a:b;c:d;e:f".Split(";") | ForEach-Object { , $_.Split(":") } </code></pre> <p>That way, the array returned by <code>$_.Split(":")</code> is effectively output as-is, as an <em>array... | 114, 526, 2844, 9291 | arrays, jagged-arrays, pipeline, powershell | <h1>Why does PowerShell flatten arrays automatically?</h1>
<p>I've written some pwsh code</p>
<pre class="lang-bsh prettyprint-override"><code>"a:b;c:d;e:f".Split(";") | ForEach-Object { $_.Split(":") }
# => @(a, b, c, d, e, f)
</code></pre>
<p>but I want this</p>
<pre class="lang-js prettyprint-override"><code>/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,471 | bash | # Why does PowerShell flatten arrays automatically?
I've written some pwsh code
```
"a:b;c:d;e:f".Split(";") | ForEach-Object { $_.Split(":") }
# => @(a, b, c, d, e, f)
```
but I want this
```
// in javascript
"a:b;c:d;e:f".split(";").map(str => str.split(":"))
[ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e', 'f' ] ]
```
a ne... | Use the unary form of `,`, PowerShell's array-construction operator:
```
"a:b;c:d;e:f".Split(";") | ForEach-Object { , $_.Split(":") }
```
That way, the array returned by `$_.Split(":")` is effectively output as-is, as an *array*, instead of having its elements output *one by one*, which happens by default in a Power... |
56618815 | Why use Push/Pop instead of Mov to put a number in a register in shellcode? | 8 | 2019-06-16 12:24:38 | <p>I have some sample code from a shell code payload showing a for loop and using push/pop to set the counter:</p>
<pre><code>push 9
pop ecx
</code></pre>
<p>Why can it not just use mov?</p>
<pre><code>mov ecx, 9
</code></pre>
| 4,683 | 10,972,795 | 2022-05-21 02:10:38 | 56,619,372 | 11 | 2019-06-16 13:40:32 | 224,132 | 2022-05-21 01:08:09 | https://stackoverflow.com/q/56618815 | https://stackoverflow.com/a/56619372 | <p><strong>Yes normally you should always use <code>mov ecx, 9</code> for performance reasons.</strong> It runs more efficiently than <code>push</code>/<code>pop</code>, as a single-uop instruction that can run on any port. (This is true across all existing CPUs that Agner Fog has tested: <a href="https://agner.org/o... | <p><strong>Yes normally you should always use <code>mov ecx, 9</code> for performance reasons.</strong> It runs more efficiently than <code>push</code>/<code>pop</code>, as a single-uop instruction that can run on any port. (This is true across all existing CPUs that Agner Fog has tested: <a href="https://agner.org/o... | 823, 824, 2172, 78469 | assembly, exploit, shellcode, x86 | <h1>Why use Push/Pop instead of Mov to put a number in a register in shellcode?</h1>
<p>I have some sample code from a shell code payload showing a for loop and using push/pop to set the counter:</p>
<pre><code>push 9
pop ecx
</code></pre>
<p>Why can it not just use mov?</p>
<pre><code>mov ecx, 9
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,472 | bash | # Why use Push/Pop instead of Mov to put a number in a register in shellcode?
I have some sample code from a shell code payload showing a for loop and using push/pop to set the counter:
```
push 9
pop ecx
```
Why can it not just use mov?
```
mov ecx, 9
``` | **Yes normally you should always use `mov ecx, 9` for performance reasons.** It runs more efficiently than `push`/`pop`, as a single-uop instruction that can run on any port. (This is true across all existing CPUs that Agner Fog has tested: <https://agner.org/optimize/>)
---
**The normal reason for `push imm8` / `pop... |
56608873 | How do I use youtube-dl's --add-header option? | 8 | 2019-06-15 08:50:22 | <p>I'm trying to add a custom header using youtube-dl, a popular video downloader with command line interface.</p>
<p>I'm using PowerShell (or CMD) on Windows 10.</p>
<p><a href="https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme" rel="noreferrer">The official documentation</a> says like the followin... | 33,150 | 8,491,363 | 2019-12-01 09:05:00 | 56,610,100 | 11 | 2019-06-15 11:49:01 | 8,491,363 | 2019-06-15 11:49:01 | https://stackoverflow.com/q/56608873 | https://stackoverflow.com/a/56610100 | <p>So my problem was not having youtube-dl.exe in my PATH, which prevented me from even starting youtube-dl. So let me answer my own question about --add-header option. </p>
<p>About --add-header option, it should be something like <code>foo:"bar"</code> for each item.</p>
<p>For example, my original command from the... | <p>So my problem was not having youtube-dl.exe in my PATH, which prevented me from even starting youtube-dl. So let me answer my own question about --add-header option. </p> <p>About --add-header option, it should be something like <code>foo:"bar"</code> for each item.</p> <p>For example, my original command from the... | 16, 526, 1231, 2631, 72317 | cmd, command-line, powershell, python, youtube-dl | <h1>How do I use youtube-dl's --add-header option?</h1>
<p>I'm trying to add a custom header using youtube-dl, a popular video downloader with command line interface.</p>
<p>I'm using PowerShell (or CMD) on Windows 10.</p>
<p><a href="https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme" rel="noreferre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,473 | bash | # How do I use youtube-dl's --add-header option?
I'm trying to add a custom header using youtube-dl, a popular video downloader with command line interface.
I'm using PowerShell (or CMD) on Windows 10.
[The official documentation](https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme) says like the fol... | So my problem was not having youtube-dl.exe in my PATH, which prevented me from even starting youtube-dl. So let me answer my own question about --add-header option.
About --add-header option, it should be something like `foo:"bar"` for each item.
For example, my original command from the question should be like:
``... |
56451094 | Powershell Start-Process -NoNewWindow not working with -Credentials | 8 | 2019-06-04 20:44:11 | <p>I am looking to run an exe from powershell using a credential. I want the output to be in the same window. This is how my powershell looks. </p>
<p><code>Start-Process</code> documentation: <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6" ... | 7,272 | 7,369,926 | 2019-06-05 00:33:12 | 56,452,899 | 11 | 2019-06-05 00:33:12 | 2,150,063 | 2019-06-05 00:33:12 | https://stackoverflow.com/q/56451094 | https://stackoverflow.com/a/56452899 | <p>Short answer, you aren't doing anything wrong. You just won't be able to do this.</p>
<p>When you run <code>Start-Process -NoNewWindow</code> without <code>-Credential</code> you say: with the current already authenticated credentials, run the executable, and return the results within the same console window.</p>
... | <p>Short answer, you aren't doing anything wrong. You just won't be able to do this.</p> <p>When you run <code>Start-Process -NoNewWindow</code> without <code>-Credential</code> you say: with the current already authenticated credentials, run the executable, and return the results within the same console window.</p> ... | 526 | powershell | <h1>Powershell Start-Process -NoNewWindow not working with -Credentials</h1>
<p>I am looking to run an exe from powershell using a credential. I want the output to be in the same window. This is how my powershell looks. </p>
<p><code>Start-Process</code> documentation: <a href="https://learn.microsoft.com/en-us/powers... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,474 | bash | # Powershell Start-Process -NoNewWindow not working with -Credentials
I am looking to run an exe from powershell using a credential. I want the output to be in the same window. This is how my powershell looks.
`Start-Process` documentation: <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.man... | Short answer, you aren't doing anything wrong. You just won't be able to do this.
When you run `Start-Process -NoNewWindow` without `-Credential` you say: with the current already authenticated credentials, run the executable, and return the results within the same console window.
When you run `Start-Process` with `-... |
54999200 | Send keys in PowerShell, Alt + N {TAB} {ENTER} | 8 | 2019-03-05 09:14:28 | <p>I am in the process of automating the daily download of a ZIP file from a secure site. The script is ready, which uses <a href="https://en.wikipedia.org/wiki/Internet_Explorer" rel="nofollow noreferrer">Internet Explorer</a> to log in, go to the required location, and then click on the download button. The script wo... | 44,893 | 11,065,321 | 2025-07-05 12:08:04 | 54,999,779 | 11 | 2019-03-05 09:45:38 | 2,722,613 | 2025-07-05 12:03:50 | https://stackoverflow.com/q/54999200 | https://stackoverflow.com/a/54999779 | <p>To emulate send keys, you want to use the <code>System.Windows.Forms.SendKeys</code> class.</p>
<blockquote>
<p>The plus sign (+), caret (^), percent sign (%), tilde (~), and
parentheses () have special meanings to SendKeys. To specify one of
these characters, enclose it within braces ({})</p>
</blockquote>
<p>In yo... | <p>To emulate send keys, you want to use the <code>System.Windows.Forms.SendKeys</code> class.</p> <blockquote> <p>The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({})</p> </blockquote> <p>In yo... | 526 | powershell | <h1>Send keys in PowerShell, Alt + N {TAB} {ENTER}</h1>
<p>I am in the process of automating the daily download of a ZIP file from a secure site. The script is ready, which uses <a href="https://en.wikipedia.org/wiki/Internet_Explorer" rel="nofollow noreferrer">Internet Explorer</a> to log in, go to the required locati... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,475 | bash | # Send keys in PowerShell, Alt + N {TAB} {ENTER}
I am in the process of automating the daily download of a ZIP file from a secure site. The script is ready, which uses [Internet Explorer](https://en.wikipedia.org/wiki/Internet_Explorer) to log in, go to the required location, and then click on the download button. The... | To emulate send keys, you want to use the `System.Windows.Forms.SendKeys` class.
> The plus sign (+), caret (^), percent sign (%), tilde (~), and
> parentheses () have special meanings to SendKeys. To specify one of
> these characters, enclose it within braces ({})
In your case, according to the documentation, a code... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.