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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
54567268 | Associative array in bash not storing values inside loop | 8 | 2019-02-07 06:09:07 | <p>This is my <code>$a</code> output:</p>
<pre><code>[root@node1 ~]# echo "${a}"
/dev/vdc1 /gfs1
/dev/vdd1 /elastic
mfsmount /usr/local/flytxt
</code></pre>
<p>I gotta store these in an associative array <code>fsmounts</code> with first column as keys and second col as value.<br>
This is my code for that: </p>
<pre... | 3,275 | 10,989,478 | 2019-02-07 06:20:53 | 54,567,319 | 11 | 2019-02-07 06:13:21 | 5,291,015 | 2019-02-07 06:20:53 | https://stackoverflow.com/q/54567268 | https://stackoverflow.com/a/54567319 | <p>The imminent problem associated with your logic is <a href="http://mywiki.wooledge.org/BashFAQ/024" rel="noreferrer">I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read?
</a></p>
<p>You don't need <code>awk</code> or any third party tool... | <p>The imminent problem associated with your logic is <a href="http://mywiki.wooledge.org/BashFAQ/024" rel="noreferrer">I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read? </a></p> <p>You don't need <code>awk</code> or any third party tool... | 387, 2575, 29051 | associative-array, bash, bash4 | <h1>Associative array in bash not storing values inside loop</h1>
<p>This is my <code>$a</code> output:</p>
<pre><code>[root@node1 ~]# echo "${a}"
/dev/vdc1 /gfs1
/dev/vdd1 /elastic
mfsmount /usr/local/flytxt
</code></pre>
<p>I gotta store these in an associative array <code>fsmounts</code> with first column as keys ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,476 | bash | # Associative array in bash not storing values inside loop
This is my `$a` output:
```
[root@node1 ~]# echo "${a}"
/dev/vdc1 /gfs1
/dev/vdd1 /elastic
mfsmount /usr/local/flytxt
```
I gotta store these in an associative array `fsmounts` with first column as keys and second col as value.
This is my code for that:
`... | The imminent problem associated with your logic is [I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read?](http://mywiki.wooledge.org/BashFAQ/024)
You don't need `awk` or any third party tool at all for this. Just run it over a loop with a `... |
53763542 | nested dictionaries in bash | 8 | 2018-12-13 13:59:00 | <p>I saw it is possible to generate a dict using bash 4 :</p>
<pre><code>declare -A dict=( ["John"]="23" ["Jackie"]="21" )
</code></pre>
<p>My question is can we assign another dictionary as value ?</p>
<p>For example having a structure like :</p>
<pre><code>declare -A dict=( ["John"]=["age"="23" "weight"="150"] ["... | 5,812 | 4,997,158 | 2018-12-14 00:55:39 | 53,772,163 | 11 | 2018-12-14 00:55:39 | 8,572,380 | 2018-12-14 00:55:39 | https://stackoverflow.com/q/53763542 | https://stackoverflow.com/a/53772163 | <p>Althought bash does not support nested arrays as others comment,
if your <code>bash</code> version is 4.3 or newer, <code>declare</code> has an <code>-n</code> option
to define a refence to the variable name which works as something like
a <code>C</code> pointer.<br>
Then you can say: </p>
<pre><code>declare -A Jo... | <p>Althought bash does not support nested arrays as others comment, if your <code>bash</code> version is 4.3 or newer, <code>declare</code> has an <code>-n</code> option to define a refence to the variable name which works as something like a <code>C</code> pointer.<br> Then you can say: </p> <pre><code>declare -A Jo... | 387, 1834 | bash, dictionary | <h1>nested dictionaries in bash</h1>
<p>I saw it is possible to generate a dict using bash 4 :</p>
<pre><code>declare -A dict=( ["John"]="23" ["Jackie"]="21" )
</code></pre>
<p>My question is can we assign another dictionary as value ?</p>
<p>For example having a structure like :</p>
<pre><code>declare -A dict=( ["... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,477 | bash | # nested dictionaries in bash
I saw it is possible to generate a dict using bash 4 :
```
declare -A dict=( ["John"]="23" ["Jackie"]="21" )
```
My question is can we assign another dictionary as value ?
For example having a structure like :
```
declare -A dict=( ["John"]=["age"="23" "weight"="150"] ["Jackie"]=["age... | Althought bash does not support nested arrays as others comment,
if your `bash` version is 4.3 or newer, `declare` has an `-n` option
to define a refence to the variable name which works as something like
a `C` pointer.
Then you can say:
```
declare -A John=( ["age"]="23" ["weight"]="150" )
declare -A Jackie=( ["age... |
51452321 | How does buffer in bash pipe work on linux? | 8 | 2018-07-21 02:34:38 | <p>Think of a simple command as following:</p>
<pre><code>cmd1 | cmd2
</code></pre>
<p>Does <code>cmd2</code> start to execute </p>
<ol>
<li>as soon as <code>cmd1</code> outputs something</li>
<li>or only if <code>cmd1</code> completely finishes and exits?</li>
</ol>
<p>In case 1 when <code>cmd1</code> outputs fast... | 5,978 | 1,467,926 | 2018-07-21 20:19:36 | 51,452,413 | 11 | 2018-07-21 02:55:56 | 226,975 | 2018-07-21 02:55:56 | https://stackoverflow.com/q/51452321 | https://stackoverflow.com/a/51452413 | <p>The <code>cmd2</code> program starts to run immediately, but whenever it tries to read input, it'll "block" (stop and wait) if necessary until some is available. This is done automatically by the kernel. Other than that, the two programs can run concurrently (including at the same time on different CPU cores).</p>... | <p>The <code>cmd2</code> program starts to run immediately, but whenever it tries to read input, it'll "block" (stop and wait) if necessary until some is available. This is done automatically by the kernel. Other than that, the two programs can run concurrently (including at the same time on different CPU cores).</p>... | 58, 387, 5813 | bash, linux, pipe | <h1>How does buffer in bash pipe work on linux?</h1>
<p>Think of a simple command as following:</p>
<pre><code>cmd1 | cmd2
</code></pre>
<p>Does <code>cmd2</code> start to execute </p>
<ol>
<li>as soon as <code>cmd1</code> outputs something</li>
<li>or only if <code>cmd1</code> completely finishes and exits?</li>
</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,478 | bash | # How does buffer in bash pipe work on linux?
Think of a simple command as following:
```
cmd1 | cmd2
```
Does `cmd2` start to execute
1. as soon as `cmd1` outputs something
2. or only if `cmd1` completely finishes and exits?
In case 1 when `cmd1` outputs faster than the speed at which `cmd2` consumes, or simply i... | The `cmd2` program starts to run immediately, but whenever it tries to read input, it'll "block" (stop and wait) if necessary until some is available. This is done automatically by the kernel. Other than that, the two programs can run concurrently (including at the same time on different CPU cores).
The buffer between... |
51272435 | Vim autocommand on write - pass full file path | 8 | 2018-07-10 19:04:46 | <p>I want to execute a bash script whenever I save a file in Vim. The problem is I don't how can I, or if it's possible to pass the full path to the file, rather than just the file name, or relative path that was opened.</p>
<p>This is the code I'm using, it works, however only relative paths, which is useless to me.<... | 1,325 | 4,925,661 | 2018-07-10 19:17:14 | 51,272,599 | 11 | 2018-07-10 19:17:14 | 4,925,661 | 2018-07-10 19:17:14 | https://stackoverflow.com/q/51272435 | https://stackoverflow.com/a/51272599 | <p>I found it:</p>
<pre><code>autocmd BufWritePost * !~/.config/nvim/scripts/on_save.sh %:p
</code></pre>
<p>The <strong>%:p</strong> does it</p>
| <p>I found it:</p> <pre><code>autocmd BufWritePost * !~/.config/nvim/scripts/on_save.sh %:p </code></pre> <p>The <strong>%:p</strong> does it</p> | 370, 387 | bash, vim | <h1>Vim autocommand on write - pass full file path</h1>
<p>I want to execute a bash script whenever I save a file in Vim. The problem is I don't how can I, or if it's possible to pass the full path to the file, rather than just the file name, or relative path that was opened.</p>
<p>This is the code I'm using, it work... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,479 | bash | # Vim autocommand on write - pass full file path
I want to execute a bash script whenever I save a file in Vim. The problem is I don't how can I, or if it's possible to pass the full path to the file, rather than just the file name, or relative path that was opened.
This is the code I'm using, it works, however only ... | I found it:
```
autocmd BufWritePost * !~/.config/nvim/scripts/on_save.sh %:p
```
The **%:p** does it |
50788152 | Can I change Read-Host so it doesn't always end in a colon? | 8 | 2018-06-10 21:21:35 | <p>Whenever I do a <code>Read-Host</code> the prompt always ends in <code>:</code>. Is there any way to change this? is it the -Prompt Flag?</p>
| 5,990 | 9,012,846 | 2024-12-19 16:38:44 | 50,788,696 | 11 | 2018-06-10 22:46:42 | 712,649 | 2018-06-10 22:46:42 | https://stackoverflow.com/q/50788152 | https://stackoverflow.com/a/50788696 | <p>As mentioned in the comments, there's no way to control how the executing host application presents the prompt when passing a <code>Prompt</code> message parameter argument.</p>
<p>What you can do instead, is call <code>$Host.UI.ReadLine()</code> directly from your script and prepend a message yourself:</p>
<pre><... | <p>As mentioned in the comments, there's no way to control how the executing host application presents the prompt when passing a <code>Prompt</code> message parameter argument.</p> <p>What you can do instead, is call <code>$Host.UI.ReadLine()</code> directly from your script and prepend a message yourself:</p> <pre><... | 526 | powershell | <h1>Can I change Read-Host so it doesn't always end in a colon?</h1>
<p>Whenever I do a <code>Read-Host</code> the prompt always ends in <code>:</code>. Is there any way to change this? is it the -Prompt Flag?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,480 | bash | # Can I change Read-Host so it doesn't always end in a colon?
Whenever I do a `Read-Host` the prompt always ends in `:`. Is there any way to change this? is it the -Prompt Flag? | As mentioned in the comments, there's no way to control how the executing host application presents the prompt when passing a `Prompt` message parameter argument.
What you can do instead, is call `$Host.UI.ReadLine()` directly from your script and prepend a message yourself:
```
Write-Host "No colons here>" -NoNewLin... |
50565408 | Should bash scripts called with --help argument return 0 or not-zero exit code? | 8 | 2018-05-28 11:30:16 | <p>Writing a bash script that displays the usage information when called with <code>--help</code> argument, what exit code is it recommended to return/exit the script with?</p>
<pre><code>$ my_script --help; echo $?
Usage ...
0
</code></pre>
<p>or</p>
<pre><code>$ my_script --help; echo $?
Usage ...
1
</code></pre>
... | 1,576 | 454,103 | 2018-05-28 11:59:52 | 50,565,671 | 11 | 2018-05-28 11:45:30 | 1,084,774 | 2018-05-28 11:56:21 | https://stackoverflow.com/q/50565408 | https://stackoverflow.com/a/50565671 | <p>The output should go to <code>stdout</code> and the script should return 0 unless there was an IO error. (The user requested a help screen and you delivered. The operation was a success.)</p>
<p>If you output the same help screen as a response to incorrect use, output it to <code>stderr</code> and fail (=exit with ... | <p>The output should go to <code>stdout</code> and the script should return 0 unless there was an IO error. (The user requested a help screen and you delivered. The operation was a success.)</p> <p>If you output the same help screen as a response to incorrect use, output it to <code>stderr</code> and fail (=exit with ... | 387, 10021 | bash, exit-code | <h1>Should bash scripts called with --help argument return 0 or not-zero exit code?</h1>
<p>Writing a bash script that displays the usage information when called with <code>--help</code> argument, what exit code is it recommended to return/exit the script with?</p>
<pre><code>$ my_script --help; echo $?
Usage ...
0
</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,481 | bash | # Should bash scripts called with --help argument return 0 or not-zero exit code?
Writing a bash script that displays the usage information when called with `--help` argument, what exit code is it recommended to return/exit the script with?
```
$ my_script --help; echo $?
Usage ...
0
```
or
```
$ my_script --help; ... | The output should go to `stdout` and the script should return 0 unless there was an IO error. (The user requested a help screen and you delivered. The operation was a success.)
If you output the same help screen as a response to incorrect use, output it to `stderr` and fail (=exit with a nonzero).
(The user tried to d... |
48380348 | 'ps' without kernel threads | 8 | 2018-01-22 11:17:22 | <p>I'm looking for some solutions to use <code>ps auxf</code> command to show all processes without kernel threads, or maybe anyone know any else program to filter that kernel process?</p>
<p>What I've tried and found:</p>
<pre><code>ps --ppid 2 -p 2 --deselect
</code></pre>
<p>OK, but the processes are not arranged... | 5,446 | 5,255,124 | 2024-08-13 16:50:08 | 48,383,409 | 11 | 2018-01-22 14:06:20 | 171,318 | 2018-01-22 14:54:40 | https://stackoverflow.com/q/48380348 | https://stackoverflow.com/a/48383409 | <p>It's the <code>u</code> in <code>ps aux</code> which defines the output columns. You can use:</p>
<pre><code>ps u --ppid 2 -p 2 --deselect
</code></pre>
| <p>It's the <code>u</code> in <code>ps aux</code> which defines the output columns. You can use:</p> <pre><code>ps u --ppid 2 -p 2 --deselect </code></pre> | 58, 390, 21990 | linux, linux-kernel, shell | <h1>'ps' without kernel threads</h1>
<p>I'm looking for some solutions to use <code>ps auxf</code> command to show all processes without kernel threads, or maybe anyone know any else program to filter that kernel process?</p>
<p>What I've tried and found:</p>
<pre><code>ps --ppid 2 -p 2 --deselect
</code></pre>
<p>O... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,482 | bash | # 'ps' without kernel threads
I'm looking for some solutions to use `ps auxf` command to show all processes without kernel threads, or maybe anyone know any else program to filter that kernel process?
What I've tried and found:
```
ps --ppid 2 -p 2 --deselect
```
OK, but the processes are not arranged like in the u... | It's the `u` in `ps aux` which defines the output columns. You can use:
```
ps u --ppid 2 -p 2 --deselect
``` |
47387451 | java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps | 8 | 2017-11-20 08:04:52 | <p>I want to run bash commands throw Jenkins pipeline, I'm calling a function that has some bash commands but I'm getting this error:</p>
<blockquote>
<pre><code> java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps
</code></pre>
</blockquote>
<p>This is the function:</p>
<blockquote>
<p>def c... | 5,038 | 7,047,604 | 2017-11-20 08:11:54 | 47,387,556 | 11 | 2017-11-20 08:11:54 | 8,644,566 | 2017-11-20 08:11:54 | https://stackoverflow.com/q/47387451 | https://stackoverflow.com/a/47387556 | <p>You want to use <code>sh</code>, not <code>bash</code>. You aren't directly running bash in your code. You need to run the <code>sh</code> pipeline step, which will run the configured shell. </p>
<pre><code>def copy_tools(){
// tools
sh '''#!/bin/bash
mkdir X6//CX6
cp ${x6_tools_path} .
unzip CX6.zi... | <p>You want to use <code>sh</code>, not <code>bash</code>. You aren't directly running bash in your code. You need to run the <code>sh</code> pipeline step, which will run the configured shell. </p> <pre><code>def copy_tools(){ // tools sh '''#!/bin/bash mkdir X6//CX6 cp ${x6_tools_path} . unzip CX6.zi... | 58, 387, 64999, 118285 | bash, jenkins, jenkins-pipeline, linux | <h1>java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps</h1>
<p>I want to run bash commands throw Jenkins pipeline, I'm calling a function that has some bash commands but I'm getting this error:</p>
<blockquote>
<pre><code> java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,483 | bash | # java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps
I want to run bash commands throw Jenkins pipeline, I'm calling a function that has some bash commands but I'm getting this error:
> ```
> java.lang.NoSuchMethodError: No such DSL method 'bash' found among steps
> ```
This is the function:
... | You want to use `sh`, not `bash`. You aren't directly running bash in your code. You need to run the `sh` pipeline step, which will run the configured shell.
```
def copy_tools(){
// tools
sh '''#!/bin/bash
mkdir X6//CX6
cp ${x6_tools_path} .
unzip CX6.zip -d .\\X6
'''
}
``` |
47018863 | Parsing and storing the json output of a curl command in bash | 8 | 2017-10-30 15:25:05 | <p>I have five <code>cURL</code> statements that work fine by themselves and am trying to put them together in a bash script. Each <code>cURL</code> statement relies on a variable generated from a <code>cuRL</code> statement executed before it. I'm trying to figure out the smartest way to go about this. Here is the ... | 14,047 | 1,481,087 | 2021-10-05 15:05:54 | 47,019,058 | 11 | 2017-10-30 15:35:21 | 5,291,015 | 2021-10-05 15:05:54 | https://stackoverflow.com/q/47018863 | https://stackoverflow.com/a/47019058 | <p>Download and install <code>jq</code> which is like <code>sed</code> for <code>JSON</code> data. You can use it to slice and filter and map and transform structured data with the same ease that <code>sed</code>, <code>awk</code>, <code>grep</code> does for unstructured data. Remember to replace <code>'...'</code> wit... | <p>Download and install <code>jq</code> which is like <code>sed</code> for <code>JSON</code> data. You can use it to slice and filter and map and transform structured data with the same ease that <code>sed</code>, <code>awk</code>, <code>grep</code> does for unstructured data. Remember to replace <code>'...'</code> wit... | 387, 1554, 105170 | bash, curl, jq | <h1>Parsing and storing the json output of a curl command in bash</h1>
<p>I have five <code>cURL</code> statements that work fine by themselves and am trying to put them together in a bash script. Each <code>cURL</code> statement relies on a variable generated from a <code>cuRL</code> statement executed before it. I'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,484 | bash | # Parsing and storing the json output of a curl command in bash
I have five `cURL` statements that work fine by themselves and am trying to put them together in a bash script. Each `cURL` statement relies on a variable generated from a `cuRL` statement executed before it. I'm trying to figure out the smartest way to g... | Download and install `jq` which is like `sed` for `JSON` data. You can use it to slice and filter and map and transform structured data with the same ease that `sed`, `awk`, `grep` does for unstructured data. Remember to replace `'...'` with your actual `curl` arguments
```
curl '...' | jq --raw-output '.AssetID'
```
... |
46901452 | How send parameters through a pipe in a python script using argparse? | 8 | 2017-10-24 02:52:42 | <p>I have to create a python script that can be used with Linux pipes</p>
<p>I want to run an script where some parameters can be send with a pipe or in the same line</p>
<p>Some examples of the use of my script with the expected output:</p>
<pre><code>echo "a" > list.txt
echo "b" >> list.txt
./run.py p1 p... | 6,579 | 1,208,222 | 2022-08-15 00:05:53 | 46,907,341 | 11 | 2017-10-24 09:50:58 | 6,245,078 | 2017-10-24 11:31:37 | https://stackoverflow.com/q/46901452 | https://stackoverflow.com/a/46907341 | <p>A solution by using only argparse</p>
<pre><code>import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('args', nargs=argparse.REMAINDER)
parser.add_argument('stdin', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
args = parser.parse_args().args
if not sys.stdin.isatty():
... | <p>A solution by using only argparse</p> <pre><code>import argparse import sys parser = argparse.ArgumentParser() parser.add_argument('args', nargs=argparse.REMAINDER) parser.add_argument('stdin', nargs='?', type=argparse.FileType('r'), default=sys.stdin) args = parser.parse_args().args if not sys.stdin.isatty(): ... | 16, 387, 59189 | argparse, bash, python | <h1>How send parameters through a pipe in a python script using argparse?</h1>
<p>I have to create a python script that can be used with Linux pipes</p>
<p>I want to run an script where some parameters can be send with a pipe or in the same line</p>
<p>Some examples of the use of my script with the expected output:</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,485 | bash | # How send parameters through a pipe in a python script using argparse?
I have to create a python script that can be used with Linux pipes
I want to run an script where some parameters can be send with a pipe or in the same line
Some examples of the use of my script with the expected output:
```
echo "a" > list.txt... | A solution by using only argparse
```
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('args', nargs=argparse.REMAINDER)
parser.add_argument('stdin', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
args = parser.parse_args().args
if not sys.stdin.isatty():
stdin = pars... |
46695859 | Should I use `sh -c \"...\"` or `"!f() {... ; }; f" in git alias scripts? | 8 | 2017-10-11 19:13:04 | <p>I've been getting my feet wet in writing git aliases that take arguments. I've seen some people running shell scripts with</p>
<pre><code>[alias]
shAlias = !sh -c \" ... \"
</code></pre>
<p>and others running functions with</p>
<pre><code>[alias]
fAlias = "!f() { ... ; }; f"
</code></pre>
<p>It seems like (o... | 1,597 | 1,241,736 | 2017-10-11 22:29:36 | 46,698,535 | 11 | 2017-10-11 22:29:36 | 1,899,640 | 2017-10-11 22:29:36 | https://stackoverflow.com/q/46695859 | https://stackoverflow.com/a/46698535 | <p>TL;DR: Use the function approach for the simplest of commands, and switch to an external script once you have any kind of issue with quoting. Just avoid <code>sh -c</code> all together. </p>
<hr>
<p>We can <a href="https://github.com/git/git/blob/217f2767cbcb562872437eed4dec62e00846d90c/run-command.c#L243" rel="no... | <p>TL;DR: Use the function approach for the simplest of commands, and switch to an external script once you have any kind of issue with quoting. Just avoid <code>sh -c</code> all together. </p> <hr> <p>We can <a href="https://github.com/git/git/blob/217f2767cbcb562872437eed4dec62e00846d90c/run-command.c#L243" rel="no... | 119, 387, 390, 79211 | bash, git, git-alias, shell | <h1>Should I use `sh -c \"...\"` or `"!f() {... ; }; f" in git alias scripts?</h1>
<p>I've been getting my feet wet in writing git aliases that take arguments. I've seen some people running shell scripts with</p>
<pre><code>[alias]
shAlias = !sh -c \" ... \"
</code></pre>
<p>and others running functions with</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,486 | bash | # Should I use `sh -c \"...\"` or `"!f() {... ; }; f" in git alias scripts?
I've been getting my feet wet in writing git aliases that take arguments. I've seen some people running shell scripts with
```
[alias]
shAlias = !sh -c \" ... \"
```
and others running functions with
```
[alias]
fAlias = "!f() { ... ; }... | TL;DR: Use the function approach for the simplest of commands, and switch to an external script once you have any kind of issue with quoting. Just avoid `sh -c` all together.
---
We can [have a look at the git source](https://github.com/git/git/blob/217f2767cbcb562872437eed4dec62e00846d90c/run-command.c#L243). It par... |
46473385 | Passing variables to powershell script block in a jenkins pipeline | 8 | 2017-09-28 15:48:06 | <p>Is there a way to use groovy variables inside a powershell script? My sample script is as following.. </p>
<pre><code> node {
stage('Invoke Installation') {
def stdoutpowershell
def serverName = env.fqdn
withEnv(['serverName = $serverName']) {
echo "serverName : $serverName"
stdoutpowershell =... | 14,977 | 5,851,005 | 2023-03-26 10:08:48 | 46,473,737 | 11 | 2017-09-28 16:08:42 | 8,644,566 | 2023-03-26 10:08:48 | https://stackoverflow.com/q/46473385 | https://stackoverflow.com/a/46473737 | <p>You cannot interpolate variables in single quotes or triple-single quotes. Use triple-double-quotes:</p>
<pre><code> stdoutpowershell = powershell returnStdout: true, script: """
write-output "Server is $env:serverName"
"""
</code></pre>
| <p>You cannot interpolate variables in single quotes or triple-single quotes. Use triple-double-quotes:</p> <pre><code> stdoutpowershell = powershell returnStdout: true, script: """ write-output "Server is $env:serverName" """ </code></pre> | 526, 849, 64999, 118285 | groovy, jenkins, jenkins-pipeline, powershell | <h1>Passing variables to powershell script block in a jenkins pipeline</h1>
<p>Is there a way to use groovy variables inside a powershell script? My sample script is as following.. </p>
<pre><code> node {
stage('Invoke Installation') {
def stdoutpowershell
def serverName = env.fqdn
withEnv(['serverName = $se... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,487 | bash | # Passing variables to powershell script block in a jenkins pipeline
Is there a way to use groovy variables inside a powershell script? My sample script is as following..
```
node {
stage('Invoke Installation') {
def stdoutpowershell
def serverName = env.fqdn
withEnv(['serverName = $serverName']) {
e... | You cannot interpolate variables in single quotes or triple-single quotes. Use triple-double-quotes:
```
stdoutpowershell = powershell returnStdout: true, script: """
write-output "Server is $env:serverName"
"""
``` |
44810685 | How to sanitize a string in bash? | 8 | 2017-06-28 19:08:30 | <p>I have a free form string which I need to sanitize in bash in order to produce safe-and-nice filenames.</p>
<p>Example:</p>
<pre><code>STAGE_NAME="Some usafe name 2/2#"
</code></pre>
<p>Expected sanitized result"</p>
<pre><code>"some-unsafe-name-2-2"
</code></pre>
<p>Logic:</p>
<ul>
<li>lowercase chars</li>
<l... | 3,978 | 99,834 | 2023-04-12 14:56:04 | 44,811,468 | 11 | 2017-06-28 19:55:07 | 548,225 | 2023-04-12 14:56:04 | https://stackoverflow.com/q/44810685 | https://stackoverflow.com/a/44811468 | <p>You can use this pure bash function for this sanitization:</p>
<pre><code>sanitize() {
local s="${1?need a string}" # receive input in first argument
s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to -
s="${s//+(-)/-}" # convert multiple - to single... | <p>You can use this pure bash function for this sanitization:</p> <pre><code>sanitize() { local s="${1?need a string}" # receive input in first argument s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to - s="${s//+(-)/-}" # convert multiple - to single... | 387 | bash | <h1>How to sanitize a string in bash?</h1>
<p>I have a free form string which I need to sanitize in bash in order to produce safe-and-nice filenames.</p>
<p>Example:</p>
<pre><code>STAGE_NAME="Some usafe name 2/2#"
</code></pre>
<p>Expected sanitized result"</p>
<pre><code>"some-unsafe-name-2-2"
</code></pre>
<p>L... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,488 | bash | # How to sanitize a string in bash?
I have a free form string which I need to sanitize in bash in order to produce safe-and-nice filenames.
Example:
```
STAGE_NAME="Some usafe name 2/2#"
```
Expected sanitized result"
```
"some-unsafe-name-2-2"
```
Logic:
- lowercase chars
- replace all unsupported or unsafe cha... | You can use this pure bash function for this sanitization:
```
sanitize() {
local s="${1?need a string}" # receive input in first argument
s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to -
s="${s//+(-)/-}" # convert multiple - to single -
s="${s/#-}" # remove... |
43580472 | AWS cli: how to start all machines found by tag | 8 | 2017-04-24 05:35:57 | <p>I can list all machines:<br>
<code>aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].[InstanceId]' --output text</code><br>
And then I wish to start all found machines - is the aws cli expression what allow that?</p>
<p>The workaround can be applying next aw... | 4,713 | 1,266,040 | 2017-04-24 07:37:56 | 43,580,975 | 11 | 2017-04-24 06:16:26 | 174,777 | 2017-04-24 06:16:26 | https://stackoverflow.com/q/43580472 | https://stackoverflow.com/a/43580975 | <p>You can embed one command within another, eg:</p>
<pre><code>aws ec2 start-instances --instance-ids `ANOTHER-COMMAND`
</code></pre>
<p>So, try this:</p>
<pre><code>aws ec2 start-instances --instance-ids `aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].In... | <p>You can embed one command within another, eg:</p> <pre><code>aws ec2 start-instances --instance-ids `ANOTHER-COMMAND` </code></pre> <p>So, try this:</p> <pre><code>aws ec2 start-instances --instance-ids `aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].In... | 387, 33388 | amazon-web-services, bash | <h1>AWS cli: how to start all machines found by tag</h1>
<p>I can list all machines:<br>
<code>aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].[InstanceId]' --output text</code><br>
And then I wish to start all found machines - is the aws cli expression what a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,489 | bash | # AWS cli: how to start all machines found by tag
I can list all machines:
`aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].[InstanceId]' --output text`
And then I wish to start all found machines - is the aws cli expression what allow that?
The workarou... | You can embed one command within another, eg:
```
aws ec2 start-instances --instance-ids `ANOTHER-COMMAND`
```
So, try this:
```
aws ec2 start-instances --instance-ids `aws ec2 describe-instances --filters "Name=tag:Env,Values=my_super_tag" --query 'Reservations[].Instances[].InstanceId' --output text`
``` |
42535773 | Setting variables for batch files in Powershell | 8 | 2017-03-01 15:31:49 | <p>I have a batch file named <code>bar.cmd</code> with a single line: <code>ECHO %Foo%</code>.<br>
How can I set <code>Foo</code> in a Powershell script so that when I call <code>& .\bar.cmd</code>, it will print <code>Bar</code>?</p>
| 8,206 | 1,180,926 | 2022-07-14 15:06:51 | 42,535,959 | 11 | 2017-03-01 15:39:31 | 2,102,693 | 2022-07-14 15:06:51 | https://stackoverflow.com/q/42535773 | https://stackoverflow.com/a/42535959 | <p>To set an environment variable in PowerShell:</p>
<pre><code>Set-Item Env:foo "bar"
</code></pre>
<p>or</p>
<pre><code>$env:foo = "bar"
</code></pre>
<p>If you want to do it the other way around:</p>
<p>When you run <code>cmd.exe</code> to execute a shell script (<code>.bat</code> or <code>.cmd</... | <p>To set an environment variable in PowerShell:</p> <pre><code>Set-Item Env:foo "bar" </code></pre> <p>or</p> <pre><code>$env:foo = "bar" </code></pre> <p>If you want to do it the other way around:</p> <p>When you run <code>cmd.exe</code> to execute a shell script (<code>.bat</code> or <code>.cmd</... | 526, 2631, 7002 | batch-file, cmd, powershell | <h1>Setting variables for batch files in Powershell</h1>
<p>I have a batch file named <code>bar.cmd</code> with a single line: <code>ECHO %Foo%</code>.<br>
How can I set <code>Foo</code> in a Powershell script so that when I call <code>& .\bar.cmd</code>, it will print <code>Bar</code>?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,490 | bash | # Setting variables for batch files in Powershell
I have a batch file named `bar.cmd` with a single line: `ECHO %Foo%`.
How can I set `Foo` in a Powershell script so that when I call `& .\bar.cmd`, it will print `Bar`? | To set an environment variable in PowerShell:
```
Set-Item Env:foo "bar"
```
or
```
$env:foo = "bar"
```
If you want to do it the other way around:
When you run `cmd.exe` to execute a shell script (`.bat` or `.cmd` file) in PowerShell, the variable gets set in that running instance of `cmd.exe` but is lost when th... |
40823769 | How to redirect stderr to a file for the whole pipe? | 8 | 2016-11-26 22:26:43 | <p>I am running a command like this:</p>
<pre><code>mycmd1 | mycmd2 | mycmd3 | lp
</code></pre>
<p>Is there a way to redirect stderr to a file for the whole pipe instead of repeating it for each command?</p>
<p>That is to say, I'd rather avoid doing this:</p>
<pre><code>mycmd1 2>/myfile | mycmd2 2>/myfile | m... | 1,857 | 2,774,883 | 2016-11-28 11:28:37 | 40,824,409 | 11 | 2016-11-26 23:56:40 | 1,084,774 | 2016-11-26 23:56:40 | https://stackoverflow.com/q/40823769 | https://stackoverflow.com/a/40824409 | <p>Either </p>
<pre><code>{ mycmd1 | mycmd2 | mycmd3 | lp; } 2>> logfile
</code></pre>
<p>or </p>
<pre><code>( mycmd1 | mycmd2 | mycmd3 | lp ) 2>> logfile
</code></pre>
<p>will work. (The first version might be have a slightly faster (~1ms) startup time depending on the shell).</p>
| <p>Either </p> <pre><code>{ mycmd1 | mycmd2 | mycmd3 | lp; } 2>> logfile </code></pre> <p>or </p> <pre><code>( mycmd1 | mycmd2 | mycmd3 | lp ) 2>> logfile </code></pre> <p>will work. (The first version might be have a slightly faster (~1ms) startup time depending on the shell).</p> | 387, 5813, 19156 | bash, pipe, stderr | <h1>How to redirect stderr to a file for the whole pipe?</h1>
<p>I am running a command like this:</p>
<pre><code>mycmd1 | mycmd2 | mycmd3 | lp
</code></pre>
<p>Is there a way to redirect stderr to a file for the whole pipe instead of repeating it for each command?</p>
<p>That is to say, I'd rather avoid doing this:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,491 | bash | # How to redirect stderr to a file for the whole pipe?
I am running a command like this:
```
mycmd1 | mycmd2 | mycmd3 | lp
```
Is there a way to redirect stderr to a file for the whole pipe instead of repeating it for each command?
That is to say, I'd rather avoid doing this:
```
mycmd1 2>/myfile | mycmd2 2>/myfil... | Either
```
{ mycmd1 | mycmd2 | mycmd3 | lp; } 2>> logfile
```
or
```
( mycmd1 | mycmd2 | mycmd3 | lp ) 2>> logfile
```
will work. (The first version might be have a slightly faster (~1ms) startup time depending on the shell). |
40666291 | Using OutVariable Creates ArrayList | 8 | 2016-11-17 22:34:51 | <p>I'm sure there is a valid reason why this happens but I don't know what it is. I have the following code</p>
<pre><code>$Deleted = $Items[0].ParentNode.RemoveChild($Items[0])
Write-Output $Deleted
</code></pre>
<p>If I call this code using </p>
<pre><code>Do-Something -OutVariable Test
</code></pre>
<p>I get th... | 5,230 | 3,969,420 | 2023-02-10 21:32:18 | 40,666,568 | 11 | 2016-11-17 22:57:21 | 45,375 | 2023-02-10 21:32:18 | https://stackoverflow.com/q/40666291 | https://stackoverflow.com/a/40666568 |
<p>As of PowerShell (Core) 7.3.2:</p>
<ul>
<li><p><strong>PowerShell unexpectedly does <em>not</em> unwrap a command's <em>single</em>-object output with<br />
<code>-OutVariable</code></strong>: That is, even if a command outputs only <em>one</em> object, that object is unexpectedly stored as an <em>array</em> (array... | <p>As of PowerShell (Core) 7.3.2:</p> <ul> <li><p><strong>PowerShell unexpectedly does <em>not</em> unwrap a command's <em>single</em>-object output with<br /> <code>-OutVariable</code></strong>: That is, even if a command outputs only <em>one</em> object, that object is unexpectedly stored as an <em>array</em> (array... | 526 | powershell | <h1>Using OutVariable Creates ArrayList</h1>
<p>I'm sure there is a valid reason why this happens but I don't know what it is. I have the following code</p>
<pre><code>$Deleted = $Items[0].ParentNode.RemoveChild($Items[0])
Write-Output $Deleted
</code></pre>
<p>If I call this code using </p>
<pre><code>Do-Something... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,492 | bash | # Using OutVariable Creates ArrayList
I'm sure there is a valid reason why this happens but I don't know what it is. I have the following code
```
$Deleted = $Items[0].ParentNode.RemoveChild($Items[0])
Write-Output $Deleted
```
If I call this code using
```
Do-Something -OutVariable Test
```
I get the output on th... | As of PowerShell (Core) 7.3.2:
- **PowerShell unexpectedly does *not* unwrap a command's *single*-object output with
`-OutVariable`**: That is, even if a command outputs only *one* object, that object is unexpectedly stored as an *array* (array list) in the target variable whose name is passed to the common parame... |
40094531 | Bash: How to catch git command failure? | 8 | 2016-10-17 19:50:15 | <p>I have a command:</p>
<pre><code>...
{
git filter-branch -f --env-filter "$ENVFILTER" >/dev/null
echo "Git updated. Run 'git push -f BRANCH_NAME' to push your changes."
} || {
echo "Git failed. Please make sure you run this on a clean working directory." // this doesn't ever get called
}
</code></pre... | 8,705 | 1,555,312 | 2016-10-17 20:06:21 | 40,094,576 | 11 | 2016-10-17 19:53:40 | 6,451,573 | 2016-10-17 19:55:13 | https://stackoverflow.com/q/40094531 | https://stackoverflow.com/a/40094576 | <p>the <code>echo</code> command after your <code>git</code> will be executed no matter what, that's the first problem.
The second problem is that this <code>echo</code> command updates the error code: first error code is overwritten.</p>
<p>I would suggest a "classical" approach (maybe a bit old-fashioned, I was rais... | <p>the <code>echo</code> command after your <code>git</code> will be executed no matter what, that's the first problem. The second problem is that this <code>echo</code> command updates the error code: first error code is overwritten.</p> <p>I would suggest a "classical" approach (maybe a bit old-fashioned, I was rais... | 119, 387 | bash, git | <h1>Bash: How to catch git command failure?</h1>
<p>I have a command:</p>
<pre><code>...
{
git filter-branch -f --env-filter "$ENVFILTER" >/dev/null
echo "Git updated. Run 'git push -f BRANCH_NAME' to push your changes."
} || {
echo "Git failed. Please make sure you run this on a clean working directory... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,493 | bash | # Bash: How to catch git command failure?
I have a command:
```
...
{
git filter-branch -f --env-filter "$ENVFILTER" >/dev/null
echo "Git updated. Run 'git push -f BRANCH_NAME' to push your changes."
} || {
echo "Git failed. Please make sure you run this on a clean working directory." // this doesn't ever... | the `echo` command after your `git` will be executed no matter what, that's the first problem.
The second problem is that this `echo` command updates the error code: first error code is overwritten.
I would suggest a "classical" approach (maybe a bit old-fashioned, I was raised with ksh):
```
git filter-branch -f --e... |
39581150 | Why do I need parenthesis In bash `set -e` and negated return code | 8 | 2016-09-19 20:01:12 | <p>I have a shell script which checks for windows line endings. </p>
<pre><code>set -e
(! git ls-files | xargs grep -I $'\r')
</code></pre>
<p>I am using the <code>!</code> character to negate the return code of the command. Grep will return code <code>0</code> when a file with carriage return is found, and <code>!... | 8,300 | 6,850,466 | 2018-11-26 12:25:31 | 39,582,012 | 11 | 2016-09-19 20:58:53 | 6,394,138 | 2016-09-19 20:58:53 | https://stackoverflow.com/q/39581150 | https://stackoverflow.com/a/39582012 | <p>Your problem has nothing to do with <code>xargs</code>.</p>
<p>The <code>-e</code> option of bash is a little tricky.</p>
<blockquote>
<p><strong>-e</strong> Exit immediately if a <em>pipeline</em> (which may consist of a
single <em>simple command</em>), a <em>list</em>, or a <em>compound comman... | <p>Your problem has nothing to do with <code>xargs</code>.</p> <p>The <code>-e</code> option of bash is a little tricky.</p> <blockquote> <p><strong>-e</strong> Exit immediately if a <em>pipeline</em> (which may consist of a single <em>simple command</em>), a <em>list</em>, or a <em>compound comman... | 58, 387, 390, 10326 | bash, linux, shell, xargs | <h1>Why do I need parenthesis In bash `set -e` and negated return code</h1>
<p>I have a shell script which checks for windows line endings. </p>
<pre><code>set -e
(! git ls-files | xargs grep -I $'\r')
</code></pre>
<p>I am using the <code>!</code> character to negate the return code of the command. Grep will retur... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,494 | bash | # Why do I need parenthesis In bash `set -e` and negated return code
I have a shell script which checks for windows line endings.
```
set -e
(! git ls-files | xargs grep -I $'\r')
```
I am using the `!` character to negate the return code of the command. Grep will return code `0` when a file with carriage return is ... | Your problem has nothing to do with `xargs`.
The `-e` option of bash is a little tricky.
> **-e** Exit immediately if a *pipeline* (which may consist of a
> single *simple command*), a *list*, or a *compound command*
> , exits with a non-zero
> status. **The shell does not exit** if the command that
> fails is part o... |
37126964 | Get exit code when piping into grep -v | 8 | 2016-05-09 23:24:49 | <p>I have a script like this:</p>
<pre><code>#!/bin/sh
echo "hello"
echo "goodbye"
exit 1
</code></pre>
<p>When I run it on its own, I get the failed exit code as I expect.</p>
<pre><code>$ ./fail.sh
hello
goodbye
$ echo $?
1
</code></pre>
<p>However, when I run it through <code>grep -v</code>, the exit status cha... | 7,287 | 1,467,997 | 2025-01-15 14:17:18 | 37,128,767 | 11 | 2016-05-10 03:28:50 | 171,475 | 2025-01-15 14:17:18 | https://stackoverflow.com/q/37126964 | https://stackoverflow.com/a/37128767 | <p>Bash provides an extension <code>set -o pipefail</code>. The following should work:</p>
<pre><code>( set -o pipefail; ./fail.sh | grep -v hello )
</code></pre>
<p>You can then test the value in <code>$?</code>:</p>
<pre><code>( set -o pipefail; ./fail.sh | grep -v hello ); if [[ "$?" -eq "1" ]];... | <p>Bash provides an extension <code>set -o pipefail</code>. The following should work:</p> <pre><code>( set -o pipefail; ./fail.sh | grep -v hello ) </code></pre> <p>You can then test the value in <code>$?</code>:</p> <pre><code>( set -o pipefail; ./fail.sh | grep -v hello ); if [[ "$?" -eq "1" ]];... | 387, 1271, 10021 | bash, exit-code, grep | <h1>Get exit code when piping into grep -v</h1>
<p>I have a script like this:</p>
<pre><code>#!/bin/sh
echo "hello"
echo "goodbye"
exit 1
</code></pre>
<p>When I run it on its own, I get the failed exit code as I expect.</p>
<pre><code>$ ./fail.sh
hello
goodbye
$ echo $?
1
</code></pre>
<p>However, when I run it t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,495 | bash | # Get exit code when piping into grep -v
I have a script like this:
```
#!/bin/sh
echo "hello"
echo "goodbye"
exit 1
```
When I run it on its own, I get the failed exit code as I expect.
```
$ ./fail.sh
hello
goodbye
$ echo $?
1
```
However, when I run it through `grep -v`, the exit status changes to success:
``... | Bash provides an extension `set -o pipefail`. The following should work:
```
( set -o pipefail; ./fail.sh | grep -v hello )
```
You can then test the value in `$?`:
```
( set -o pipefail; ./fail.sh | grep -v hello ); if [[ "$?" -eq "1" ]]; then echo success; else echo bummer; fi
```
It should output:
```
goodbye
s... |
36400268 | Setting up Visual Studio environment variables from PowerShell | 8 | 2016-04-04 10:34:00 | <p>I have Visual Studio 9.0 installed but I want to use it manually from PowerShell. It comes with two setup scripts: <code>vcvars32.bat</code> for the 32-bit compiler and <code>vcvars64.bat</code> for the 64-bit compiler. When I open <code>cmd.exe</code> and run one of the scripts, it sets up everything just fine and ... | 9,342 | 1,197,719 | 2021-12-30 09:34:50 | 36,401,264 | 11 | 2016-04-04 11:23:09 | 82,660 | 2016-04-04 12:42:30 | https://stackoverflow.com/q/36400268 | https://stackoverflow.com/a/36401264 | <p>You should use <a href="https://github.com/majkinetor/posh/blob/master/MM_Admin/Invoke-Environment.ps1" rel="noreferrer">InvokeEnvironment</a> script to do that. Check its man page:</p>
<pre><code>Invoke-Environment <path_to_>vsvars32.bat
</code></pre>
<p>You can furhter generalize this by determining OS bit... | <p>You should use <a href="https://github.com/majkinetor/posh/blob/master/MM_Admin/Invoke-Environment.ps1" rel="noreferrer">InvokeEnvironment</a> script to do that. Check its man page:</p> <pre><code>Invoke-Environment <path_to_>vsvars32.bat </code></pre> <p>You can furhter generalize this by determining OS bit... | 526, 2631, 7002, 80825 | batch-file, cmd, powershell, visual-studio-2012 | <h1>Setting up Visual Studio environment variables from PowerShell</h1>
<p>I have Visual Studio 9.0 installed but I want to use it manually from PowerShell. It comes with two setup scripts: <code>vcvars32.bat</code> for the 32-bit compiler and <code>vcvars64.bat</code> for the 64-bit compiler. When I open <code>cmd.exe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,496 | bash | # Setting up Visual Studio environment variables from PowerShell
I have Visual Studio 9.0 installed but I want to use it manually from PowerShell. It comes with two setup scripts: `vcvars32.bat` for the 32-bit compiler and `vcvars64.bat` for the 64-bit compiler. When I open `cmd.exe` and run one of the scripts, it set... | You should use [InvokeEnvironment](https://github.com/majkinetor/posh/blob/master/MM_Admin/Invoke-Environment.ps1) script to do that. Check its man page:
```
Invoke-Environment <path_to_>vsvars32.bat
```
You can furhter generalize this by determining OS bits and crafting the `vsvars<OsBits>.bat`.
Example:
```
PS C:... |
36273558 | Convert string value "$false" to boolean variable | 8 | 2016-03-29 00:44:30 | <h1>Reason I'm Doing This</h1>
<p>I'm trying to set a token in a file I have. The contents of the token is 1 line in the file, and it's string value is <code>$token=$false</code></p>
<h1>Simplified to test code</h1>
<p>When I try to convert this token into a bool value, I'm having some problems. So I wrote test code an... | 11,714 | 2,150,879 | 2017-10-20 13:56:55 | 36,273,637 | 11 | 2016-03-29 00:55:25 | 3,195,526 | 2017-10-20 13:56:55 | https://stackoverflow.com/q/36273558 | https://stackoverflow.com/a/36273637 | <p>In PowerShell, the usual escape character is the backtick. Normal strings are interpolated: the <code>$</code> symbol is understood and parsed by PowerShell. You need to escape the <code>$</code> to prevent interpolation. This should work for you:</p>
<pre><code>[String]$strValue = "`$false"
</code></pre>
<p>To ... | <p>In PowerShell, the usual escape character is the backtick. Normal strings are interpolated: the <code>$</code> symbol is understood and parsed by PowerShell. You need to escape the <code>$</code> to prevent interpolation. This should work for you:</p> <pre><code>[String]$strValue = "`$false" </code></pre> <p>To ... | 526, 73157 | powershell, powershell-3.0 | <h1>Convert string value "$false" to boolean variable</h1>
<h1>Reason I'm Doing This</h1>
<p>I'm trying to set a token in a file I have. The contents of the token is 1 line in the file, and it's string value is <code>$token=$false</code></p>
<h1>Simplified to test code</h1>
<p>When I try to convert this token into a bo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,497 | bash | # Convert string value "$false" to boolean variable
# Reason I'm Doing This
I'm trying to set a token in a file I have. The contents of the token is 1 line in the file, and it's string value is `$token=$false`
# Simplified to test code
When I try to convert this token into a bool value, I'm having some problems. So... | In PowerShell, the usual escape character is the backtick. Normal strings are interpolated: the `$` symbol is understood and parsed by PowerShell. You need to escape the `$` to prevent interpolation. This should work for you:
```
[String]$strValue = "`$false"
```
To convert "$true" or "$false" to a boolean in a gener... |
35999671 | What's the difference between "sudo -i" and "sudo su -" | 8 | 2016-03-14 22:59:09 | <p>Both commands will log me in as root. I know there is a difference in what environment settings are set. </p>
<p>Which one do you use? Which one is better practice?</p>
| 7,360 | 3,575,896 | 2016-03-14 23:29:18 | 36,000,000 | 11 | 2016-03-14 23:29:18 | 1,126,841 | 2016-03-14 23:29:18 | https://stackoverflow.com/q/35999671 | https://stackoverflow.com/a/36000000 | <p><code>su</code> has only one purpose: to start a shell running as the given user (<code>root</code> by default).</p>
<p><code>sudo</code> is a highly configurable program that lets you run <em>any</em> command as any user, with the configuration allowing the local administrator to place limits on what commands you ... | <p><code>su</code> has only one purpose: to start a shell running as the given user (<code>root</code> by default).</p> <p><code>sudo</code> is a highly configurable program that lets you run <em>any</em> command as any user, with the configuration allowing the local administrator to place limits on what commands you ... | 34, 58, 387 | bash, linux, unix | <h1>What's the difference between "sudo -i" and "sudo su -"</h1>
<p>Both commands will log me in as root. I know there is a difference in what environment settings are set. </p>
<p>Which one do you use? Which one is better practice?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,498 | bash | # What's the difference between "sudo -i" and "sudo su -"
Both commands will log me in as root. I know there is a difference in what environment settings are set.
Which one do you use? Which one is better practice? | `su` has only one purpose: to start a shell running as the given user (`root` by default).
`sudo` is a highly configurable program that lets you run *any* command as any user, with the configuration allowing the local administrator to place limits on what commands you can run using `sudo`, as well as which commands re... |
33664892 | Sort Directory name using Powershell | 8 | 2015-11-12 05:17:28 | <p>I have list of directories. Directories are named as numbers. How to sort the directory name in numeric order by power shell. </p>
<pre><code>Name
-----
1
12
2
</code></pre>
| 12,947 | 5,553,314 | 2015-11-12 07:56:49 | 33,666,651 | 11 | 2015-11-12 07:56:49 | 712,649 | 2015-11-12 07:56:49 | https://stackoverflow.com/q/33664892 | https://stackoverflow.com/a/33666651 | <p>The sort order is based on the <em>type</em> of the property being used for comparison.</p>
<p>Since the <code>Name</code> property of your directories are of type <code>[string]</code>, alphabetical sorting takes place, which ranks <code>10</code> before <code>9</code> (because the first character <code>1</code> p... | <p>The sort order is based on the <em>type</em> of the property being used for comparison.</p> <p>Since the <code>Name</code> property of your directories are of type <code>[string]</code>, alphabetical sorting takes place, which ranks <code>10</code> before <code>9</code> (because the first character <code>1</code> p... | 526 | powershell | <h1>Sort Directory name using Powershell</h1>
<p>I have list of directories. Directories are named as numbers. How to sort the directory name in numeric order by power shell. </p>
<pre><code>Name
-----
1
12
2
</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,499 | bash | # Sort Directory name using Powershell
I have list of directories. Directories are named as numbers. How to sort the directory name in numeric order by power shell.
```
Name
-----
1
12
2
``` | The sort order is based on the *type* of the property being used for comparison.
Since the `Name` property of your directories are of type `[string]`, alphabetical sorting takes place, which ranks `10` before `9` (because the first character `1` precedes the character `9` in alphabetical order).
To sort the numbers b... |
32091717 | Read full stdin until EOF when stdin comes from `cat` bash | 8 | 2015-08-19 09:34:33 | <p>I'm trying to read full stdin into a variable :</p>
<h1>script.sh</h1>
<pre><code>#/bin/bash
input=""
while read line
do
echo "$line"
input="$input""\n""$line"
done < /dev/stdin
echo "$input" > /tmp/test
</code></pre>
<p>When I run <code>ls | ... | 10,661 | 1,993,501 | 2015-08-19 09:45:05 | 32,091,953 | 11 | 2015-08-19 09:45:05 | 3,435,489 | 2015-08-19 09:45:05 | https://stackoverflow.com/q/32091717 | https://stackoverflow.com/a/32091953 | <p>I would stick to the one-liner</p>
<pre><code>input=$(cat)
</code></pre>
<p>Of course, <code>Ctrl-D</code> should be used to signal end-of-file.</p>
| <p>I would stick to the one-liner</p> <pre><code>input=$(cat) </code></pre> <p>Of course, <code>Ctrl-D</code> should be used to signal end-of-file.</p> | 387, 1701, 22820 | bash, cat, stdin | <h1>Read full stdin until EOF when stdin comes from `cat` bash</h1>
<p>I'm trying to read full stdin into a variable :</p>
<h1>script.sh</h1>
<pre><code>#/bin/bash
input=""
while read line
do
echo "$line"
input="$input""\n""$line"
done < /dev/stdin
echo "... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,500 | bash | # Read full stdin until EOF when stdin comes from `cat` bash
I'm trying to read full stdin into a variable :
# script.sh
```
#/bin/bash
input=""
while read line
do
echo "$line"
input="$input""\n""$line"
done < /dev/stdin
echo "$input" > /tmp/test
```
When I run `ls | ./script.sh` or mostly any other command... | I would stick to the one-liner
```
input=$(cat)
```
Of course, `Ctrl-D` should be used to signal end-of-file. |
31506196 | Passing a registry key with an asterisk to Test-Path | 8 | 2015-07-19 21:38:01 | <p>I want to run this registry path by <code>Test-Path</code> in PowerShell but it contains an asterisk, which is valid in the registry but not in Windows paths.</p>
<p>The problem is, when I pass it, <code>Test-Path</code> treats the asterisk as a wild card, so this takes a very, very long time because it checks all ... | 2,235 | 64,519 | 2019-06-12 00:22:37 | 31,506,293 | 11 | 2015-07-19 21:50:27 | 1,630,171 | 2015-07-19 21:52:40 | https://stackoverflow.com/q/31506196 | https://stackoverflow.com/a/31506293 | <p>Use the <a href="https://technet.microsoft.com/en-us/library/hh849776.aspx" rel="noreferrer"><code>-LiteralPath</code></a> parameter to prevent <a href="https://msdn.microsoft.com/en-us/library/aa717088%28v=vs.85%29.aspx" rel="noreferrer">globbing/wildcard matching</a>.</p>
<blockquote>
<p><strong>-LiteralPath<... | <p>Use the <a href="https://technet.microsoft.com/en-us/library/hh849776.aspx" rel="noreferrer"><code>-LiteralPath</code></a> parameter to prevent <a href="https://msdn.microsoft.com/en-us/library/aa717088%28v=vs.85%29.aspx" rel="noreferrer">globbing/wildcard matching</a>.</p> <blockquote> <p><strong>-LiteralPath<... | 526, 4804 | escaping, powershell | <h1>Passing a registry key with an asterisk to Test-Path</h1>
<p>I want to run this registry path by <code>Test-Path</code> in PowerShell but it contains an asterisk, which is valid in the registry but not in Windows paths.</p>
<p>The problem is, when I pass it, <code>Test-Path</code> treats the asterisk as a wild car... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,501 | bash | # Passing a registry key with an asterisk to Test-Path
I want to run this registry path by `Test-Path` in PowerShell but it contains an asterisk, which is valid in the registry but not in Windows paths.
The problem is, when I pass it, `Test-Path` treats the asterisk as a wild card, so this takes a very, very long tim... | Use the [`-LiteralPath`](https://technet.microsoft.com/en-us/library/hh849776.aspx) parameter to prevent [globbing/wildcard matching](https://msdn.microsoft.com/en-us/library/aa717088%28v=vs.85%29.aspx).
> **-LiteralPath<String[]>**
>
> Specifies a path to be tested. Unlike Path, the value of the LiteralPath parameter... |
31443694 | What is the relationship between gwmi and Get-WmiObject | 8 | 2015-07-16 00:54:57 | <p>After reading around, I'm confused about the relationship between these. I don't believe <code>gwmi</code> is a pure alias for <code>Get-WmiObject</code>, as they seem to share similar but not identical syntax in the examples I've seen.</p>
<p>Interestingly enough, when I google "gwmi" on its own, all the... | 6,649 | 1,639,473 | 2020-12-20 16:31:16 | 31,443,747 | 11 | 2015-07-16 01:01:54 | 3,829,407 | 2015-07-16 02:06:39 | https://stackoverflow.com/q/31443694 | https://stackoverflow.com/a/31443747 | <p>There is no fancy voodoo at work here. Aliases in PowerShell are a <em>very</em> simple mechanic that help with short hand coding. Unix aliases, on the other hand, are different and can include entire command calls (Which could possibly be a source of confusion?). </p>
<p>In all cases, there is nothing more that ju... | <p>There is no fancy voodoo at work here. Aliases in PowerShell are a <em>very</em> simple mechanic that help with short hand coding. Unix aliases, on the other hand, are different and can include entire command calls (Which could possibly be a source of confusion?). </p> <p>In all cases, there is nothing more that ju... | 526 | powershell | <h1>What is the relationship between gwmi and Get-WmiObject</h1>
<p>After reading around, I'm confused about the relationship between these. I don't believe <code>gwmi</code> is a pure alias for <code>Get-WmiObject</code>, as they seem to share similar but not identical syntax in the examples I've seen.</p>
<p>Interes... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,502 | bash | # What is the relationship between gwmi and Get-WmiObject
After reading around, I'm confused about the relationship between these. I don't believe `gwmi` is a pure alias for `Get-WmiObject`, as they seem to share similar but not identical syntax in the examples I've seen.
Interestingly enough, when I google "gwmi" on... | There is no fancy voodoo at work here. Aliases in PowerShell are a *very* simple mechanic that help with short hand coding. Unix aliases, on the other hand, are different and can include entire command calls (Which could possibly be a source of confusion?).
In all cases, there is nothing more that just what you see he... |
31124865 | How to round a floating point number upto 3 digits after decimal point in bash | 8 | 2015-06-29 20:22:13 | <p>I am a new <code>bash</code> learner. I want to print the result of an expression given as input having <code>3 digits</code> after decimal point with rounding if needed.
I can use the following code, but it does not round. Say if I give <code>5+50*3/20 + (19*2)/7</code> as input for the following code, the given ou... | 20,767 | 3,555,000 | 2023-10-22 17:10:54 | 31,125,154 | 11 | 2015-06-29 20:39:30 | 1,141,118 | 2015-06-29 20:39:30 | https://stackoverflow.com/q/31124865 | https://stackoverflow.com/a/31125154 | <p>What about</p>
<pre><code>a=`echo "5+50*3/20 + (19*2)/7" | bc -l`
a_rounded=`printf "%.3f" $a`
echo "a = $a"
echo "a_rounded = $a_rounded"
</code></pre>
<p>which outputs</p>
<pre><code>a = 17.92857142857142857142
a_rounded = 17.929
</code></pre>
<p>?</p>
| <p>What about</p> <pre><code>a=`echo "5+50*3/20 + (19*2)/7" | bc -l` a_rounded=`printf "%.3f" $a` echo "a = $a" echo "a_rounded = $a_rounded" </code></pre> <p>which outputs</p> <pre><code>a = 17.92857142857142857142 a_rounded = 17.929 </code></pre> <p>?</p> | 305, 387, 67245, 96150 | bash, floating-point, floating-point-conversion, floating-point-precision | <h1>How to round a floating point number upto 3 digits after decimal point in bash</h1>
<p>I am a new <code>bash</code> learner. I want to print the result of an expression given as input having <code>3 digits</code> after decimal point with rounding if needed.
I can use the following code, but it does not round. Say i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,503 | bash | # How to round a floating point number upto 3 digits after decimal point in bash
I am a new `bash` learner. I want to print the result of an expression given as input having `3 digits` after decimal point with rounding if needed.
I can use the following code, but it does not round. Say if I give `5+50*3/20 + (19*2)/7`... | What about
```
a=`echo "5+50*3/20 + (19*2)/7" | bc -l`
a_rounded=`printf "%.3f" $a`
echo "a = $a"
echo "a_rounded = $a_rounded"
```
which outputs
```
a = 17.92857142857142857142
a_rounded = 17.929
```
? |
26533819 | How can I download a file only if it has changed using powershell | 8 | 2014-10-23 17:26:04 | <p>I am using this simple function to download a file:</p>
<pre><code>function DownloadFile([string]$url, [string]$file)
{
$clnt = new-object System.Net.WebClient
Write-Host "Downloading from $url to $file "
$clnt.DownloadFile($url, $file)
}
</code></pre>
<p>It works fine but the script I am using that c... | 9,149 | 9,976 | 2022-10-18 19:58:52 | 30,129,694 | 11 | 2015-05-08 17:37:42 | 13,532 | 2022-10-18 19:58:52 | https://stackoverflow.com/q/26533819 | https://stackoverflow.com/a/30129694 | <p>I've been beating this up this week, and came up with this</p>
<pre class="lang-bash prettyprint-override"><code># ----------------------------------------------------------------------------------------------
# download a file
# ---------------------------------------------------------------------------------------... | <p>I've been beating this up this week, and came up with this</p> <pre class="lang-bash prettyprint-override"><code># ---------------------------------------------------------------------------------------------- # download a file # ---------------------------------------------------------------------------------------... | 526 | powershell | <h1>How can I download a file only if it has changed using powershell</h1>
<p>I am using this simple function to download a file:</p>
<pre><code>function DownloadFile([string]$url, [string]$file)
{
$clnt = new-object System.Net.WebClient
Write-Host "Downloading from $url to $file "
$clnt.DownloadFile($url... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,504 | bash | # How can I download a file only if it has changed using powershell
I am using this simple function to download a file:
```
function DownloadFile([string]$url, [string]$file)
{
$clnt = new-object System.Net.WebClient
Write-Host "Downloading from $url to $file "
$clnt.DownloadFile($url, $file)
}
```
It w... | I've been beating this up this week, and came up with this
```
# ----------------------------------------------------------------------------------------------
# download a file
# ----------------------------------------------------------------------------------------------
Function Download-File {
Param (
... |
29890426 | create alias for path | 8 | 2015-04-27 08:11:05 | <p>Is it possible in PowerShell to create alias for path?</p>
<p>For example:
I have to write all time </p>
<pre><code>PS PS C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319
</code></pre>
<p>I will happy if I could write</p>
<pre><code>PS PS C:\Users\Jacek>cd dotNet4path
</code></pre>
| 8,483 | 650,148 | 2018-08-22 20:46:13 | 29,890,566 | 11 | 2015-04-27 08:17:43 | 3,142,940 | 2015-04-27 08:17:43 | https://stackoverflow.com/q/29890426 | https://stackoverflow.com/a/29890566 | <p>You could just create a variable in your powershell profile with that path as the value.</p>
<p>Then all you would need to do is something like</p>
<pre><code>cd $dotNet4path
</code></pre>
<p>To add something to your profile profile, type $profile, into a powershell window and it will display the path to your pow... | <p>You could just create a variable in your powershell profile with that path as the value.</p> <p>Then all you would need to do is something like</p> <pre><code>cd $dotNet4path </code></pre> <p>To add something to your profile profile, type $profile, into a powershell window and it will display the path to your pow... | 526, 1448, 69665 | alias, powershell, windows-8 | <h1>create alias for path</h1>
<p>Is it possible in PowerShell to create alias for path?</p>
<p>For example:
I have to write all time </p>
<pre><code>PS PS C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319
</code></pre>
<p>I will happy if I could write</p>
<pre><code>PS PS C:\Users\Jacek>cd dotN... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,505 | bash | # create alias for path
Is it possible in PowerShell to create alias for path?
For example:
I have to write all time
```
PS PS C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319
```
I will happy if I could write
```
PS PS C:\Users\Jacek>cd dotNet4path
``` | You could just create a variable in your powershell profile with that path as the value.
Then all you would need to do is something like
```
cd $dotNet4path
```
To add something to your profile profile, type $profile, into a powershell window and it will display the path to your powershell profile file. Create it if... |
29394208 | Strange "echo" behavior in shell script | 8 | 2015-04-01 14:59:25 | <p>I want to print the content that I have obtained from the split of an array in this way:</p>
<pre><code>string="abc test;ABCtest.it"
IFS=';' read -a array <<< "$string"
name="${array[0]}"
url="${array[1]}"
echo -ne "\n$url,$name" >> "$outputDir/$fileName"
</code></pre>
<p>But the output file doesn... | 3,637 | 2,287,271 | 2024-11-16 02:53:13 | 29,398,829 | 11 | 2015-04-01 19:07:24 | 45,375 | 2024-11-16 02:53:13 | https://stackoverflow.com/q/29394208 | https://stackoverflow.com/a/29398829 | <p>To complement <a href="https://stackoverflow.com/a/29397823/45375">chepner's helpful answer</a>:</p>
<ul>
<li><p>If <strong>output doesn't <em>look</em> what you expect it to look like</strong>, it's always worth examining its contents to <strong>look for hidden control characters</strong> that may change data's app... | <p>To complement <a href="https://stackoverflow.com/a/29397823/45375">chepner's helpful answer</a>:</p> <ul> <li><p>If <strong>output doesn't <em>look</em> what you expect it to look like</strong>, it's always worth examining its contents to <strong>look for hidden control characters</strong> that may change data's app... | 387, 13824 | bash, echo | <h1>Strange "echo" behavior in shell script</h1>
<p>I want to print the content that I have obtained from the split of an array in this way:</p>
<pre><code>string="abc test;ABCtest.it"
IFS=';' read -a array <<< "$string"
name="${array[0]}"
url="${array[1]}"
echo -ne "\n$url,$name" >> "$outputDir/$file... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,506 | bash | # Strange "echo" behavior in shell script
I want to print the content that I have obtained from the split of an array in this way:
```
string="abc test;ABCtest.it"
IFS=';' read -a array <<< "$string"
name="${array[0]}"
url="${array[1]}"
echo -ne "\n$url,$name" >> "$outputDir/$fileName"
```
But the output file does... | To complement [chepner's helpful answer](https://stackoverflow.com/a/29397823/45375):
- If **output doesn't *look* what you expect it to look like**, it's always worth examining its contents to **look for hidden control characters** that may change data's appearance *on output*.
- `\r`, a CR (carriage return; ASCII va... |
29182502 | How to find unique words from file linux | 8 | 2015-03-21 12:05:12 | <p>i have a big file, teh lines look like this
Text numbers etc. [Man-(some numers)] is lot of this Man-somenumbers is repeat in few lines, i want to count only unique Mans -words. I cant use unique file , because text before Man words is always different in each line.
How can i count only unique Man-somenumbers word... | 19,154 | 4,697,125 | 2015-03-21 12:26:52 | 29,182,548 | 11 | 2015-03-21 12:09:33 | 4,301,306 | 2015-03-21 12:15:03 | https://stackoverflow.com/q/29182502 | https://stackoverflow.com/a/29182548 | <p>If I understand what you want to do correctly, then</p>
<pre><code>grep -oE 'Man-[0-9]+' filename | sort | uniq -c
</code></pre>
<p>should do the trick. It works as follows: First</p>
<pre><code>grep -oE 'Man-[0-9]+' filename
</code></pre>
<p>isolates all words from the file that match the <code>Man-[0-9]+</code... | <p>If I understand what you want to do correctly, then</p> <pre><code>grep -oE 'Man-[0-9]+' filename | sort | uniq -c </code></pre> <p>should do the trick. It works as follows: First</p> <pre><code>grep -oE 'Man-[0-9]+' filename </code></pre> <p>isolates all words from the file that match the <code>Man-[0-9]+</code... | 58, 387, 391, 549 | bash, linux, terminal, ubuntu | <h1>How to find unique words from file linux</h1>
<p>i have a big file, teh lines look like this
Text numbers etc. [Man-(some numers)] is lot of this Man-somenumbers is repeat in few lines, i want to count only unique Mans -words. I cant use unique file , because text before Man words is always different in each line.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,507 | bash | # How to find unique words from file linux
i have a big file, teh lines look like this
Text numbers etc. [Man-(some numers)] is lot of this Man-somenumbers is repeat in few lines, i want to count only unique Mans -words. I cant use unique file , because text before Man words is always different in each line.
How can i... | If I understand what you want to do correctly, then
```
grep -oE 'Man-[0-9]+' filename | sort | uniq -c
```
should do the trick. It works as follows: First
```
grep -oE 'Man-[0-9]+' filename
```
isolates all words from the file that match the `Man-[0-9]+` regular expression. That list is then piped through `sort` t... |
29010999 | how to assign echo value to a variable in shell | 8 | 2015-03-12 13:23:30 | <p>Im tring to assign echo value which to a variable but im getting error</p>
<pre><code>Var='(echo $2 | sed -e 's/,/: chararray /g'| sed -e 's/$/: chararray/')'
echo $var
Input : sh load.sh file 1,2,3,4
Error load.sh: line 1: chararray: command not found
</code></pre>
| 30,992 | 2,575,155 | 2015-03-12 15:00:56 | 29,012,804 | 11 | 2015-03-12 14:43:56 | 4,161,438 | 2015-03-12 15:00:56 | https://stackoverflow.com/q/29010999 | https://stackoverflow.com/a/29012804 | <pre><code>Var=$(echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/')
echo "$Var"
</code></pre>
<p>OR</p>
<pre><code>Var=`echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/'`
echo "$Var"
</code></pre>
<p>Use either <code>$(…)</code> or perhaps <code>`…`</code> backtick notation. Howev... | <pre><code>Var=$(echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/') echo "$Var" </code></pre> <p>OR</p> <pre><code>Var=`echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/'` echo "$Var" </code></pre> <p>Use either <code>$(…)</code> or perhaps <code>`…`</code> backtick notation. Howev... | 34, 390 | shell, unix | <h1>how to assign echo value to a variable in shell</h1>
<p>Im tring to assign echo value which to a variable but im getting error</p>
<pre><code>Var='(echo $2 | sed -e 's/,/: chararray /g'| sed -e 's/$/: chararray/')'
echo $var
Input : sh load.sh file 1,2,3,4
Error load.sh: line 1: chararray: command not found
</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,508 | bash | # how to assign echo value to a variable in shell
Im tring to assign echo value which to a variable but im getting error
```
Var='(echo $2 | sed -e 's/,/: chararray /g'| sed -e 's/$/: chararray/')'
echo $var
Input : sh load.sh file 1,2,3,4
Error load.sh: line 1: chararray: command not found
``` | ```
Var=$(echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/')
echo "$Var"
```
OR
```
Var=`echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/'`
echo "$Var"
```
Use either `$(…)` or perhaps `` `…` `` backtick notation. However, the backtick notation is deprecated and should be avoided.... |
27762672 | sed with option -i and flag /d set | 8 | 2015-01-04 05:23:49 | <p>What does this sed command in a shell script do?</p>
<pre><code>sed -i /'abc'/d "/etc/rc.d/rc.local"
</code></pre>
<p>More precisely, what does '-i' do here? And why there is a 'd' flag set at the pattern's end?</p>
| 9,804 | null | 2015-01-04 08:41:42 | 27,762,846 | 11 | 2015-01-04 05:56:17 | 4,326,936 | 2015-01-04 05:56:17 | https://stackoverflow.com/q/27762672 | https://stackoverflow.com/a/27762846 | <p>From sed manual, <code>i</code> option means in-place edit</p>
<pre><code>-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
</code></pre>
<p><code>d</code> means delete action</p>
<pre><code>d Delete pattern space. Start next cycle.
</code></pre>
<p>In you example... | <p>From sed manual, <code>i</code> option means in-place edit</p> <pre><code>-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied) </code></pre> <p><code>d</code> means delete action</p> <pre><code>d Delete pattern space. Start next cycle. </code></pre> <p>In you example... | 390, 4072, 5282 | gnu, sed, shell | <h1>sed with option -i and flag /d set</h1>
<p>What does this sed command in a shell script do?</p>
<pre><code>sed -i /'abc'/d "/etc/rc.d/rc.local"
</code></pre>
<p>More precisely, what does '-i' do here? And why there is a 'd' flag set at the pattern's end?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,509 | bash | # sed with option -i and flag /d set
What does this sed command in a shell script do?
```
sed -i /'abc'/d "/etc/rc.d/rc.local"
```
More precisely, what does '-i' do here? And why there is a 'd' flag set at the pattern's end? | From sed manual, `i` option means in-place edit
```
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
```
`d` means delete action
```
d Delete pattern space. Start next cycle.
```
In you example, this two combination will delete any line contain `abc` in the file `/e... |
24174330 | Bash: Split stdout from multiple concurrent commands into columns | 8 | 2014-06-11 23:41:45 | <p>I am running multiple commands in a bash script using single ampersands like so:</p>
<pre><code>commandA & commandB & commandC
</code></pre>
<p>They each have their own <code>stdout</code> output but they are all mixed together and flood the console in an incoherent mess.</p>
<p>I'm wondering if there is ... | 3,414 | 988,608 | 2014-06-20 22:18:29 | 24,336,467 | 11 | 2014-06-20 22:18:29 | 988,608 | 2014-06-20 22:18:29 | https://stackoverflow.com/q/24174330 | https://stackoverflow.com/a/24336467 | <p>Regrettably answering my own question.</p>
<p>None of the supplied solutions were exactly what I was looking for. So I developed my own command line utility: <strong><a href="https://github.com/arjunmehta/node-multiview" rel="noreferrer">multiview</a></strong>. Maybe others will benefit?</p>
<p>It works by piping ... | <p>Regrettably answering my own question.</p> <p>None of the supplied solutions were exactly what I was looking for. So I developed my own command line utility: <strong><a href="https://github.com/arjunmehta/node-multiview" rel="noreferrer">multiview</a></strong>. Maybe others will benefit?</p> <p>It works by piping ... | 58, 387, 390 | bash, linux, shell | <h1>Bash: Split stdout from multiple concurrent commands into columns</h1>
<p>I am running multiple commands in a bash script using single ampersands like so:</p>
<pre><code>commandA & commandB & commandC
</code></pre>
<p>They each have their own <code>stdout</code> output but they are all mixed together and ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,510 | bash | # Bash: Split stdout from multiple concurrent commands into columns
I am running multiple commands in a bash script using single ampersands like so:
```
commandA & commandB & commandC
```
They each have their own `stdout` output but they are all mixed together and flood the console in an incoherent mess.
I'm wonder... | Regrettably answering my own question.
None of the supplied solutions were exactly what I was looking for. So I developed my own command line utility: **[multiview](https://github.com/arjunmehta/node-multiview)**. Maybe others will benefit?
It works by piping processes' stdout/stderr to a command interface and then b... |
23725992 | How to use quickfix in Vim to debug Bash scripts | 8 | 2014-05-18 19:29:15 | <p>I use Vim every day to write shell scripts. I have been reading about the <em>quickfix</em> window, and I think it could speed up my productivity in the edit-run-fix cycle.</p>
<p>If I understood properly, I have to write my own <code>errorformat</code> function in order to Vim to be able to catch the errors and in... | 2,535 | 3,650,477 | 2014-05-20 16:55:22 | 23,729,626 | 11 | 2014-05-19 04:15:37 | 27,581 | 2014-05-20 16:55:22 | https://stackoverflow.com/q/23725992 | https://stackoverflow.com/a/23729626 | <p>Vim's quickfix window is designed to speed up the <strong>edit-compile-edit</strong> cycle. Since Bash scripts do not get compiled, we have to substitute something else for that step that can point out errors in the current script.</p>
<p>What you want is a <strong>static analysis tool</strong> for Bash scripts. Th... | <p>Vim's quickfix window is designed to speed up the <strong>edit-compile-edit</strong> cycle. Since Bash scripts do not get compiled, we have to substitute something else for that step that can point out errors in the current script.</p> <p>What you want is a <strong>static analysis tool</strong> for Bash scripts. Th... | 370, 387, 7283 | bash, errorformat, vim | <h1>How to use quickfix in Vim to debug Bash scripts</h1>
<p>I use Vim every day to write shell scripts. I have been reading about the <em>quickfix</em> window, and I think it could speed up my productivity in the edit-run-fix cycle.</p>
<p>If I understood properly, I have to write my own <code>errorformat</code> func... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,511 | bash | # How to use quickfix in Vim to debug Bash scripts
I use Vim every day to write shell scripts. I have been reading about the *quickfix* window, and I think it could speed up my productivity in the edit-run-fix cycle.
If I understood properly, I have to write my own `errorformat` function in order to Vim to be able to... | Vim's quickfix window is designed to speed up the **edit-compile-edit** cycle. Since Bash scripts do not get compiled, we have to substitute something else for that step that can point out errors in the current script.
What you want is a **static analysis tool** for Bash scripts. There are two good ones: [shellcheck](... |
23518104 | Mysql dump with timestamp | 8 | 2014-05-07 12:39:33 | <p>I have a project that uses MySQL database. I want to backup the database every day, so I use this:</p>
<pre><code>mysqldump -h host -u user -p password database > 'location.sql'
</code></pre>
<p>I want the files to be named with timestamp, i.e.:</p>
<p>Today the file will be named <code>something-07-05-2014 08... | 24,118 | 1,719,544 | 2014-05-13 10:49:37 | 23,518,253 | 11 | 2014-05-07 12:46:53 | 3,470,953 | 2014-05-07 12:46:53 | https://stackoverflow.com/q/23518104 | https://stackoverflow.com/a/23518253 | <p>you can do</p>
<pre><code>mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql
</code></pre>
| <p>you can do</p> <pre><code>mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql </code></pre> | 21, 387, 526, 2631 | bash, cmd, mysql, powershell | <h1>Mysql dump with timestamp</h1>
<p>I have a project that uses MySQL database. I want to backup the database every day, so I use this:</p>
<pre><code>mysqldump -h host -u user -p password database > 'location.sql'
</code></pre>
<p>I want the files to be named with timestamp, i.e.:</p>
<p>Today the file will be ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,512 | bash | # Mysql dump with timestamp
I have a project that uses MySQL database. I want to backup the database every day, so I use this:
```
mysqldump -h host -u user -p password database > 'location.sql'
```
I want the files to be named with timestamp, i.e.:
Today the file will be named `something-07-05-2014 08-00-00`
Tom... | you can do
```
mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql
``` |
22766678 | How to set the correct local time zone in git bash? | 8 | 2014-03-31 16:11:36 | <p>I am using git-bash on a Windows system.</p>
<p>The Windows clock shows local time, but inside git-bash everything is in GMT time:</p>
<pre><code>$ date
Mon Mar 31 16:08:57 GMT 2014
</code></pre>
<p>Also setting TZ will not change things:</p>
<pre><code>$ TZ="Europe/Berlin" date
Mon Mar 31 16:09:01 GMT 2014
</co... | 5,918 | 1,870,481 | 2015-10-13 13:50:18 | 23,135,729 | 11 | 2014-04-17 14:20:23 | 1,870,481 | 2014-04-17 14:26:08 | https://stackoverflow.com/q/22766678 | https://stackoverflow.com/a/23135729 | <p>On Windows the <code>TZ</code> variable seems to work <a href="http://msdn.microsoft.com/en-us/library/90s5c885%28v=vs.80%29.aspx">differently</a>.</p>
<p>To get the German timezone you have to write:</p>
<pre><code>TZ=GST-1GDT date
</code></pre>
<p>If you set it to some "invalid" value like <code>"Europe/Berlin"... | <p>On Windows the <code>TZ</code> variable seems to work <a href="http://msdn.microsoft.com/en-us/library/90s5c885%28v=vs.80%29.aspx">differently</a>.</p> <p>To get the German timezone you have to write:</p> <pre><code>TZ=GST-1GDT date </code></pre> <p>If you set it to some "invalid" value like <code>"Europe/Berlin"... | 64, 119, 982, 21628, 61874 | git, git-bash, msysgit, timezone, windows | <h1>How to set the correct local time zone in git bash?</h1>
<p>I am using git-bash on a Windows system.</p>
<p>The Windows clock shows local time, but inside git-bash everything is in GMT time:</p>
<pre><code>$ date
Mon Mar 31 16:08:57 GMT 2014
</code></pre>
<p>Also setting TZ will not change things:</p>
<pre><cod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,513 | bash | # How to set the correct local time zone in git bash?
I am using git-bash on a Windows system.
The Windows clock shows local time, but inside git-bash everything is in GMT time:
```
$ date
Mon Mar 31 16:08:57 GMT 2014
```
Also setting TZ will not change things:
```
$ TZ="Europe/Berlin" date
Mon Mar 31 16:09:01 GMT... | On Windows the `TZ` variable seems to work [differently](http://msdn.microsoft.com/en-us/library/90s5c885%28v=vs.80%29.aspx).
To get the German timezone you have to write:
```
TZ=GST-1GDT date
```
If you set it to some "invalid" value like `"Europe/Berlin"` it will default to GMT.
The same seems to happen on my syst... |
22796434 | Have an Rscript read or take input from stdin | 8 | 2014-04-01 20:41:14 | <p>I see how to have an Rscript perform the operations I want when given a filename as an argument, e.g. if my Rscript is called <code>script</code> and contains:</p>
<pre><code>#!/usr/bin/Rscript
path <- commandArgs()[1]
writeLines(readLines(path))
</code></pre>
<p>Then I can run from the bash command line:</p>
... | 10,756 | 258,662 | 2014-04-01 21:15:52 | 22,797,031 | 11 | 2014-04-01 21:15:52 | 429,846 | 2014-04-01 21:15:52 | https://stackoverflow.com/q/22796434 | https://stackoverflow.com/a/22797031 | <p>You need to read text from the connection created by <code>file("stdin")</code> in order to pass anything useful to the <code>text</code> argument of <code>writeLines()</code>. This should work</p>
<pre><code>#!/usr/bin/Rscript
writeLines(readLines(file("stdin")))
</code></pre>
| <p>You need to read text from the connection created by <code>file("stdin")</code> in order to pass anything useful to the <code>text</code> argument of <code>writeLines()</code>. This should work</p> <pre><code>#!/usr/bin/Rscript writeLines(readLines(file("stdin"))) </code></pre> | 387, 1701, 4452 | bash, r, stdin | <h1>Have an Rscript read or take input from stdin</h1>
<p>I see how to have an Rscript perform the operations I want when given a filename as an argument, e.g. if my Rscript is called <code>script</code> and contains:</p>
<pre><code>#!/usr/bin/Rscript
path <- commandArgs()[1]
writeLines(readLines(path))
</code></p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,514 | bash | # Have an Rscript read or take input from stdin
I see how to have an Rscript perform the operations I want when given a filename as an argument, e.g. if my Rscript is called `script` and contains:
```
#!/usr/bin/Rscript
path <- commandArgs()[1]
writeLines(readLines(path))
```
Then I can run from the bash command li... | You need to read text from the connection created by `file("stdin")` in order to pass anything useful to the `text` argument of `writeLines()`. This should work
```
#!/usr/bin/Rscript
writeLines(readLines(file("stdin")))
``` |
22510705 | Get the latest download link programmatically | 8 | 2014-03-19 15:30:48 | <p>I want to be able to download the latest version of a software automatically with my bash script. Unfortunately not ever website has the latest release link just like github.
In my case I need to download the latest <strong>stable</strong> version of Nginx</p>
<p>Currently I use this
<strong><a href="http://nginx.... | 6,041 | 2,650,277 | 2020-09-03 15:03:39 | 22,511,315 | 11 | 2014-03-19 15:52:19 | 45,375 | 2014-03-19 19:21:22 | https://stackoverflow.com/q/22510705 | https://stackoverflow.com/a/22511315 | <p><strong>Update</strong>:<br>
Solution that determines and downloads the latest <strong><em>stable</em> version</strong> via <code>http://nginx.org/en/download.html</code> (<code>http://nginx.org/download/</code>, used in the original solution below, does not distinguish between stable and mainline versions) - works ... | <p><strong>Update</strong>:<br> Solution that determines and downloads the latest <strong><em>stable</em> version</strong> via <code>http://nginx.org/en/download.html</code> (<code>http://nginx.org/download/</code>, used in the original solution below, does not distinguish between stable and mainline versions) - works ... | 387 | bash | <h1>Get the latest download link programmatically</h1>
<p>I want to be able to download the latest version of a software automatically with my bash script. Unfortunately not ever website has the latest release link just like github.
In my case I need to download the latest <strong>stable</strong> version of Nginx</p>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,515 | bash | # Get the latest download link programmatically
I want to be able to download the latest version of a software automatically with my bash script. Unfortunately not ever website has the latest release link just like github.
In my case I need to download the latest **stable** version of Nginx
Currently I use this
**<ht... | **Update**:
Solution that determines and downloads the latest ***stable* version** via `http://nginx.org/en/download.html` (`http://nginx.org/download/`, used in the original solution below, does not distinguish between stable and mainline versions) - works on both Linux and OSX:
```
# Determine the latest stable ve... |
22281436 | How can i make gitbash find the javac command? | 8 | 2014-03-09 11:11:30 | <p>I made my gitrepository and committed it.
Inserted one java-file and wanted to to compile it ,but it gave me this:</p>
<pre><code>Bernard@BERNARD-PC /c/users/bernard/desktop/git2 (master)
$ javac TestGUI.java
sh.exe": javac: command not found
</code></pre>
<p>It used to work in school on their computer,but at hom... | 22,662 | 2,592,761 | 2017-11-29 17:06:53 | 22,281,869 | 11 | 2014-03-09 11:56:32 | 6,309 | 2014-03-09 11:56:32 | https://stackoverflow.com/q/22281436 | https://stackoverflow.com/a/22281869 | <p>You need to add javac parent folder to your PATH.</p>
<pre><code>export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"
</code></pre>
<p>You can <a href="https://stackoverflow.com/a/10690098/6309">check what <code>PATH</code> your git bash shell does see</a> (probably the <a href="https://superuser.com/a/60753... | <p>You need to add javac parent folder to your PATH.</p> <pre><code>export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/" </code></pre> <p>You can <a href="https://stackoverflow.com/a/10690098/6309">check what <code>PATH</code> your git bash shell does see</a> (probably the <a href="https://superuser.com/a/60753... | 7427, 61874 | git-bash, javac | <h1>How can i make gitbash find the javac command?</h1>
<p>I made my gitrepository and committed it.
Inserted one java-file and wanted to to compile it ,but it gave me this:</p>
<pre><code>Bernard@BERNARD-PC /c/users/bernard/desktop/git2 (master)
$ javac TestGUI.java
sh.exe": javac: command not found
</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,516 | bash | # How can i make gitbash find the javac command?
I made my gitrepository and committed it.
Inserted one java-file and wanted to to compile it ,but it gave me this:
```
Bernard@BERNARD-PC /c/users/bernard/desktop/git2 (master)
$ javac TestGUI.java
sh.exe": javac: command not found
```
It used to work in school on the... | You need to add javac parent folder to your PATH.
```
export PATH=$PATH:"/C/Program Files/Java/jdk1.7.0_21/bin/"
```
You can [check what `PATH` your git bash shell does see](https://stackoverflow.com/a/10690098/6309) (probably the [default one](https://superuser.com/a/607534/141)). |
21680561 | bash nohup with two commands | 8 | 2014-02-10 15:02:04 | <p>I have a small function in my <code>bashrc</code> so I can run a script and have the ouput sent to my email when it finishes. The code is the following:</p>
<pre><code>run() {
email=example@gmail.com
last="${!#}"
rest="${@:1:($#-1)}"
(nohup $rest &> $last < /dev/null; mail -s "$rest" "$em... | 6,837 | 495,786 | 2014-02-10 16:19:48 | 21,682,407 | 11 | 2014-02-10 16:19:48 | 1,253,222 | 2014-02-10 16:19:48 | https://stackoverflow.com/q/21680561 | https://stackoverflow.com/a/21682407 | <p>There are multiple ways to resolve this, but I think I would recommend this:</p>
<pre><code>run() {
email=example@gmail.com
rest="${@:1:($#-1)}"
nohup bash -c "$rest < /dev/null 2>&1 | mail -s \"$rest\" \"$email\"" &
}
</code></pre>
<p>The issue is your <code>nohup</code> command ended at the ... | <p>There are multiple ways to resolve this, but I think I would recommend this:</p> <pre><code>run() { email=example@gmail.com rest="${@:1:($#-1)}" nohup bash -c "$rest < /dev/null 2>&1 | mail -s \"$rest\" \"$email\"" & } </code></pre> <p>The issue is your <code>nohup</code> command ended at the ... | 387, 10327, 18966 | bash, nohup, sh | <h1>bash nohup with two commands</h1>
<p>I have a small function in my <code>bashrc</code> so I can run a script and have the ouput sent to my email when it finishes. The code is the following:</p>
<pre><code>run() {
email=example@gmail.com
last="${!#}"
rest="${@:1:($#-1)}"
(nohup $rest &> $las... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,517 | bash | # bash nohup with two commands
I have a small function in my `bashrc` so I can run a script and have the ouput sent to my email when it finishes. The code is the following:
```
run() {
email=example@gmail.com
last="${!#}"
rest="${@:1:($#-1)}"
(nohup $rest &> $last < /dev/null; mail -s "$rest" "$email... | There are multiple ways to resolve this, but I think I would recommend this:
```
run() {
email=example@gmail.com
rest="${@:1:($#-1)}"
nohup bash -c "$rest < /dev/null 2>&1 | mail -s \"$rest\" \"$email\"" &
}
```
The issue is your `nohup` command ended at the semicolon after `/dev/null` and thus didn't apply to... |
20728589 | Find the install location of brew on OS X | 8 | 2013-12-22 10:52:18 | <p>I'm creating a BASH scrip which requires a couple of applications to be installed. <code>ffmpeg</code> and <code>sox</code></p>
<p>To ensure they are in place when my script runs I first check for the installation of Homebrew with :</p>
<pre><code>#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
# Install Hom... | 23,760 | 1,772,521 | 2020-04-12 01:56:45 | 20,733,281 | 11 | 2013-12-22 19:39:54 | 1,772,521 | 2014-11-04 22:36:34 | https://stackoverflow.com/q/20728589 | https://stackoverflow.com/a/20733281 | <p>Answering my own question...</p>
<p>You can test the output of <code>which brew</code> and deal with things accordingly. To gracefully deal with the case where Homebrew is not installed you can use <code>if which brew 2> /dev/null</code> which redirects <code>stderr</code> to <code>/dev/null</code>.</p>
<p><cod... | <p>Answering my own question...</p> <p>You can test the output of <code>which brew</code> and deal with things accordingly. To gracefully deal with the case where Homebrew is not installed you can use <code>if which brew 2> /dev/null</code> which redirects <code>stderr</code> to <code>/dev/null</code>.</p> <p><cod... | 387, 1067 | bash, homebrew | <h1>Find the install location of brew on OS X</h1>
<p>I'm creating a BASH scrip which requires a couple of applications to be installed. <code>ffmpeg</code> and <code>sox</code></p>
<p>To ensure they are in place when my script runs I first check for the installation of Homebrew with :</p>
<pre><code>#!/bin/bash
whic... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,518 | bash | # Find the install location of brew on OS X
I'm creating a BASH scrip which requires a couple of applications to be installed. `ffmpeg` and `sox`
To ensure they are in place when my script runs I first check for the installation of Homebrew with :
```
#!/bin/bash
which -s brew
if [[ $? != 0 ]] ; then
# Install H... | Answering my own question...
You can test the output of `which brew` and deal with things accordingly. To gracefully deal with the case where Homebrew is not installed you can use `if which brew 2> /dev/null` which redirects `stderr` to `/dev/null`.
`brew --prefix` is also useful here as it give the path to where Hom... |
19840580 | Shell - How to deal with find -regex? | 8 | 2013-11-07 15:58:18 | <p>I need to look in a directory for sub-directories that all start by "course" but they have version next. For example</p>
<pre><code>course1.1.0.0
course1.2.0.0
course1.3.0.0
</code></pre>
<p>So how should I modify my command to make it give me the right list of directories?</p>
<pre><code>find test -regex "[cours... | 14,382 | 2,766,382 | 2015-06-12 08:01:20 | 19,840,606 | 11 | 2013-11-07 15:59:35 | 1,983,854 | 2013-11-07 16:27:58 | https://stackoverflow.com/q/19840580 | https://stackoverflow.com/a/19840606 | <p>You can do:</p>
<pre><code>find test -type d -regex '.*/course[0-9.]*'
</code></pre>
<p>it will match files whose name is <code>course</code> plus an amount of numbers and dots.</p>
<p>For example:</p>
<pre><code>$ ls course*
course1.23.0 course1.33.534.1 course1.a course1.a.2
$ find test -type d -regex '.*co... | <p>You can do:</p> <pre><code>find test -type d -regex '.*/course[0-9.]*' </code></pre> <p>it will match files whose name is <code>course</code> plus an amount of numbers and dots.</p> <p>For example:</p> <pre><code>$ ls course* course1.23.0 course1.33.534.1 course1.a course1.a.2 $ find test -type d -regex '.*co... | 18, 390, 10193 | find, regex, shell | <h1>Shell - How to deal with find -regex?</h1>
<p>I need to look in a directory for sub-directories that all start by "course" but they have version next. For example</p>
<pre><code>course1.1.0.0
course1.2.0.0
course1.3.0.0
</code></pre>
<p>So how should I modify my command to make it give me the right list of direct... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,519 | bash | # Shell - How to deal with find -regex?
I need to look in a directory for sub-directories that all start by "course" but they have version next. For example
```
course1.1.0.0
course1.2.0.0
course1.3.0.0
```
So how should I modify my command to make it give me the right list of directories?
```
find test -regex "[co... | You can do:
```
find test -type d -regex '.*/course[0-9.]*'
```
it will match files whose name is `course` plus an amount of numbers and dots.
For example:
```
$ ls course*
course1.23.0 course1.33.534.1 course1.a course1.a.2
$ find test -type d -regex '.*course[0-9.]*'
test/course1.33.534.1
test/course1.23.0
``` |
17243235 | How to read content from two files and merge into a 3rd file in bash shell | 8 | 2013-06-21 19:50:34 | <p>How do you read/process 2 files in sync with each other in bash?</p>
<p>I have 2 text files which have the same number of lines/items in them.
One file is</p>
<pre><code>a
b
c
</code></pre>
<p>The other file is</p>
<pre><code>1
2
3
</code></pre>
<p>How do I loop through these files in sync so that <code>a</code... | 703 | 1,631,414 | 2016-08-08 20:53:10 | 17,243,289 | 11 | 2013-06-21 19:53:51 | 2,339,817 | 2013-06-21 20:26:59 | https://stackoverflow.com/q/17243235 | https://stackoverflow.com/a/17243289 | <p>Use <code>paste</code> (<a href="http://www.gnu.org/software/coreutils/manual/html_node/paste-invocation.html">invocation</a>) to combine the files, then process one line of the combined file at a time:</p>
<pre><code>paste file1 file2 |
while read -r first second
do
echo $first
echo $second
done
</code></pre>
| <p>Use <code>paste</code> (<a href="http://www.gnu.org/software/coreutils/manual/html_node/paste-invocation.html">invocation</a>) to combine the files, then process one line of the combined file at a time:</p> <pre><code>paste file1 file2 | while read -r first second do echo $first echo $second done </code></pre> | 18, 387, 990, 5282, 12282 | awk, bash, pattern-matching, regex, sed | <h1>How to read content from two files and merge into a 3rd file in bash shell</h1>
<p>How do you read/process 2 files in sync with each other in bash?</p>
<p>I have 2 text files which have the same number of lines/items in them.
One file is</p>
<pre><code>a
b
c
</code></pre>
<p>The other file is</p>
<pre><code>1
2... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,520 | bash | # How to read content from two files and merge into a 3rd file in bash shell
How do you read/process 2 files in sync with each other in bash?
I have 2 text files which have the same number of lines/items in them.
One file is
```
a
b
c
```
The other file is
```
1
2
3
```
How do I loop through these files in sync s... | Use `paste` ([invocation](http://www.gnu.org/software/coreutils/manual/html_node/paste-invocation.html)) to combine the files, then process one line of the combined file at a time:
```
paste file1 file2 |
while read -r first second
do
echo $first
echo $second
done
``` |
16700565 | How do I escape single quotes with perl interpreter? | 8 | 2013-05-22 19:59:03 | <p>How do I escape the single qoutes in my bash expression <code>find . | xargs perl -pi -e 's/'conflicts' => '',//g'</code>? I want to replace the string 'conflicts' => '', in my files?</p>
| 16,029 | 340,457 | 2013-05-22 20:20:04 | 16,700,621 | 11 | 2013-05-22 20:02:27 | 1,172,428 | 2013-05-22 20:02:27 | https://stackoverflow.com/q/16700565 | https://stackoverflow.com/a/16700621 | <p>You can't directly escape it within single quotes, so to get a single quote you need to do something like:</p>
<pre><code>$ echo 'i'\''m a string with a single quote'
i'm a string with a single quote
</code></pre>
<p>This ends the quoted part, escapes a single quote as it would appear outside of quotes, and then b... | <p>You can't directly escape it within single quotes, so to get a single quote you need to do something like:</p> <pre><code>$ echo 'i'\''m a string with a single quote' i'm a string with a single quote </code></pre> <p>This ends the quoted part, escapes a single quote as it would appear outside of quotes, and then b... | 387, 580 | bash, perl | <h1>How do I escape single quotes with perl interpreter?</h1>
<p>How do I escape the single qoutes in my bash expression <code>find . | xargs perl -pi -e 's/'conflicts' => '',//g'</code>? I want to replace the string 'conflicts' => '', in my files?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,521 | bash | # How do I escape single quotes with perl interpreter?
How do I escape the single qoutes in my bash expression `find . | xargs perl -pi -e 's/'conflicts' => '',//g'`? I want to replace the string 'conflicts' => '', in my files? | You can't directly escape it within single quotes, so to get a single quote you need to do something like:
```
$ echo 'i'\''m a string with a single quote'
i'm a string with a single quote
```
This ends the quoted part, escapes a single quote as it would appear outside of quotes, and then begins the quoting again. Th... |
16360019 | How do I add multi-threading? | 8 | 2013-05-03 13:24:30 | <p>Is there a way of getting the below to run in parallel (multi-threading)? I have about 200 servers that need to run and was wondering if there is a way of checking say 10 servers at once rather then one at a time...WMI is very slow in checking this one at a time. </p>
<pre><code>clear
Write-Host "Script to Check if... | 13,326 | 461,030 | 2013-05-03 13:40:19 | 16,360,328 | 11 | 2013-05-03 13:40:19 | 1,524,225 | 2013-05-03 13:40:19 | https://stackoverflow.com/q/16360019 | https://stackoverflow.com/a/16360328 | <p>Use powershell jobs:</p>
<pre><code>$scriptblock = {
Param($server)
IF (Test-Connection $server -Quiet){
$wmi = (gwmi win32_computersystem -ComputerName $server).Name
Write-Host "***$server responds: WMI reports the name is: $wmi"
} ELSE { Write-Host "***$server ERROR -Not responding***"... | <p>Use powershell jobs:</p> <pre><code>$scriptblock = { Param($server) IF (Test-Connection $server -Quiet){ $wmi = (gwmi win32_computersystem -ComputerName $server).Name Write-Host "***$server responds: WMI reports the name is: $wmi" } ELSE { Write-Host "***$server ERROR -Not responding***"... | 526, 24067, 73157 | powershell, powershell-2.0, powershell-3.0 | <h1>How do I add multi-threading?</h1>
<p>Is there a way of getting the below to run in parallel (multi-threading)? I have about 200 servers that need to run and was wondering if there is a way of checking say 10 servers at once rather then one at a time...WMI is very slow in checking this one at a time. </p>
<pre><co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,522 | bash | # How do I add multi-threading?
Is there a way of getting the below to run in parallel (multi-threading)? I have about 200 servers that need to run and was wondering if there is a way of checking say 10 servers at once rather then one at a time...WMI is very slow in checking this one at a time.
```
clear
Write-Host "... | Use powershell jobs:
```
$scriptblock = {
Param($server)
IF (Test-Connection $server -Quiet){
$wmi = (gwmi win32_computersystem -ComputerName $server).Name
Write-Host "***$server responds: WMI reports the name is: $wmi"
} ELSE { Write-Host "***$server ERROR -Not responding***" }
}
$servers ... |
15460869 | Nuget - Setting CopyToOutputDirectory on content in subfolders | 8 | 2013-03-17 12:48:47 | <p>I'm new to Nuget and I'm trying to figure out uploading my first package. So far, everything's gone smoothly. However, I'm trying to set CopyToOutputDirectory on some content files that I want to live in a Lib subfolder. My directory looks like this:</p>
<pre><code>│ Readme.txt
│ MyPackage.nupkg
│ MyPackage.n... | 2,410 | 718,940 | 2013-03-17 20:56:48 | 15,466,144 | 11 | 2013-03-17 20:56:48 | 268,874 | 2013-03-17 20:56:48 | https://stackoverflow.com/q/15460869 | https://stackoverflow.com/a/15466144 | <p>Try the following instead:</p>
<pre><code>$project.ProjectItems.Item("Lib").ProjectItems.Item("native1.dll").Properties.Item("CopyToOutputDirectory").Value = 1
</code></pre>
<p>I could be wrong but I do not think that ProjectItems will allow you to locate items that are not direct children of the current item. So ... | <p>Try the following instead:</p> <pre><code>$project.ProjectItems.Item("Lib").ProjectItems.Item("native1.dll").Properties.Item("CopyToOutputDirectory").Value = 1 </code></pre> <p>I could be wrong but I do not think that ProjectItems will allow you to locate items that are not direct children of the current item. So ... | 526, 62770 | nuget, powershell | <h1>Nuget - Setting CopyToOutputDirectory on content in subfolders</h1>
<p>I'm new to Nuget and I'm trying to figure out uploading my first package. So far, everything's gone smoothly. However, I'm trying to set CopyToOutputDirectory on some content files that I want to live in a Lib subfolder. My directory looks like ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,523 | bash | # Nuget - Setting CopyToOutputDirectory on content in subfolders
I'm new to Nuget and I'm trying to figure out uploading my first package. So far, everything's gone smoothly. However, I'm trying to set CopyToOutputDirectory on some content files that I want to live in a Lib subfolder. My directory looks like this:
``... | Try the following instead:
```
$project.ProjectItems.Item("Lib").ProjectItems.Item("native1.dll").Properties.Item("CopyToOutputDirectory").Value = 1
```
I could be wrong but I do not think that ProjectItems will allow you to locate items that are not direct children of the current item. So you need to find the Lib fo... |
15261431 | Powershell - changing the value of an environment variable | 8 | 2013-03-07 01:24:47 | <p>Is there a way to change the value of an environment variable (system) through powershell? I have only been able to change the value manually and see the change after restarting powershell. Context: We are trying to dynamically set the value of an indirect SSIS configuration and the configuration file is different p... | 3,546 | 1,219,322 | 2013-03-08 00:22:39 | 15,284,105 | 11 | 2013-03-07 02:36:55 | 1,324,345 | 2013-03-07 13:31:25 | https://stackoverflow.com/q/15261431 | https://stackoverflow.com/a/15284105 | <p>To set an environment variable at the system level (and make them persistent), you need to use the .Net Framework method <code>[Environment]::SetEnvironmentVariable()</code></p>
<p>In the current session, you can set them via <code>$env:NAME = VALUE</code>.</p>
<p>See <a href="http://technet.microsoft.com/en-us/li... | <p>To set an environment variable at the system level (and make them persistent), you need to use the .Net Framework method <code>[Environment]::SetEnvironmentVariable()</code></p> <p>In the current session, you can set them via <code>$env:NAME = VALUE</code>.</p> <p>See <a href="http://technet.microsoft.com/en-us/li... | 1, 526, 725, 2175 | .net, configuration, powershell, ssis | <h1>Powershell - changing the value of an environment variable</h1>
<p>Is there a way to change the value of an environment variable (system) through powershell? I have only been able to change the value manually and see the change after restarting powershell. Context: We are trying to dynamically set the value of an i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,524 | bash | # Powershell - changing the value of an environment variable
Is there a way to change the value of an environment variable (system) through powershell? I have only been able to change the value manually and see the change after restarting powershell. Context: We are trying to dynamically set the value of an indirect S... | To set an environment variable at the system level (and make them persistent), you need to use the .Net Framework method `[Environment]::SetEnvironmentVariable()`
In the current session, you can set them via `$env:NAME = VALUE`.
See <http://technet.microsoft.com/en-us/library/ff730964.aspx> |
13012265 | Meaning of columns from ps | 8 | 2012-10-22 13:14:28 | <p>In Linux bash, what do the four columns mean from <code>ps</code>?</p>
<p>e.g</p>
<pre><code>PID TTY TIME CMD
15286 pts/498 00:00:00 bash
30887 pts/498 00:00:00 ps
</code></pre>
| 20,442 | 1,247,204 | 2012-10-22 13:17:57 | 13,012,319 | 11 | 2012-10-22 13:17:57 | 478,288 | 2012-10-22 13:17:57 | https://stackoverflow.com/q/13012265 | https://stackoverflow.com/a/13012319 | <p>From the <code>man</code> page:</p>
<blockquote>
<p>It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [dd-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).</p>
</blockquote>
| <p>From the <code>man</code> page:</p> <blockquote> <p>It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [dd-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).</p> </blockquote> | 58, 387, 12645 | bash, linux, ps | <h1>Meaning of columns from ps</h1>
<p>In Linux bash, what do the four columns mean from <code>ps</code>?</p>
<p>e.g</p>
<pre><code>PID TTY TIME CMD
15286 pts/498 00:00:00 bash
30887 pts/498 00:00:00 ps
</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,525 | bash | # Meaning of columns from ps
In Linux bash, what do the four columns mean from `ps`?
e.g
```
PID TTY TIME CMD
15286 pts/498 00:00:00 bash
30887 pts/498 00:00:00 ps
``` | From the `man` page:
> It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [dd-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD). |
12971309 | String manipulation, optional character | 8 | 2012-10-19 09:31:37 | <p>With <code>grep</code>, you can use a question mark <code>?</code> to signify an optional character, that is a character that is to be matches 0 or 1 times.</p>
<pre><code>$ foo=qwerasdf
$ grep -Eo fx? <<< $foo
f
</code></pre>
<p>The question is does Bash String Manipulation have a similar feature? Somet... | 3,126 | 1,002,260 | 2012-10-19 10:04:43 | 12,971,509 | 11 | 2012-10-19 09:42:29 | 1,743,811 | 2012-10-19 10:04:43 | https://stackoverflow.com/q/12971309 | https://stackoverflow.com/a/12971509 | <p>You're probably talking about <a href="http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion">parameter expansion</a>. It uses shell patterns, not regular expression, so <strike>the answer is no</strike>.</p>
<p>Upon further reading, I noticed that if you</p>
<pre><code>shopt -s extglob
</... | <p>You're probably talking about <a href="http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion">parameter expansion</a>. It uses shell patterns, not regular expression, so <strike>the answer is no</strike>.</p> <p>Upon further reading, I noticed that if you</p> <pre><code>shopt -s extglob </... | 387 | bash | <h1>String manipulation, optional character</h1>
<p>With <code>grep</code>, you can use a question mark <code>?</code> to signify an optional character, that is a character that is to be matches 0 or 1 times.</p>
<pre><code>$ foo=qwerasdf
$ grep -Eo fx? <<< $foo
f
</code></pre>
<p>The question is does Bash ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,526 | bash | # String manipulation, optional character
With `grep`, you can use a question mark `?` to signify an optional character, that is a character that is to be matches 0 or 1 times.
```
$ foo=qwerasdf
$ grep -Eo fx? <<< $foo
f
```
The question is does Bash String Manipulation have a similar feature? Something like
```
... | You're probably talking about [parameter expansion](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion). It uses shell patterns, not regular expression, so the answer is no.
Upon further reading, I noticed that if you
```
shopt -s extglob
```
you can use [extended pattern matching](http:/... |
12411643 | How do I find the exact CLI command given to Python? | 8 | 2012-09-13 17:27:08 | <p>I want to find out from inside the script -- the exact command I used to fire it up. I tried the following:</p>
<pre><code>#!/usr/bin/env python
import sys, os
print os.path.basename(sys.argv[0]), sys.argv[1:]
</code></pre>
<p>But it loses info:</p>
<pre><code>$ 1.py -1 dfd 'gf g' "df df"
1.py ['-1', 'dfd', 'gf... | 2,322 | 788,700 | 2023-10-20 09:58:20 | 12,411,695 | 11 | 2012-09-13 17:29:45 | 593,047 | 2012-09-13 18:39:22 | https://stackoverflow.com/q/12411643 | https://stackoverflow.com/a/12411695 | <p>The information you're looking for (command params including quotes) is not available.</p>
<p>The <em>shell</em> (bash), not python, reads and interprets quotes--by the time python or any other spawned program sees the parameters, the quotes are removed. (Except for quoted quotes, of course.)</p>
<h3>More detail</h... | <p>The information you're looking for (command params including quotes) is not available.</p> <p>The <em>shell</em> (bash), not python, reads and interprets quotes--by the time python or any other spawned program sees the parameters, the quotes are removed. (Except for quoted quotes, of course.)</p> <h3>More detail</h... | 16, 34, 390, 31134 | command-line-arguments, python, shell, unix | <h1>How do I find the exact CLI command given to Python?</h1>
<p>I want to find out from inside the script -- the exact command I used to fire it up. I tried the following:</p>
<pre><code>#!/usr/bin/env python
import sys, os
print os.path.basename(sys.argv[0]), sys.argv[1:]
</code></pre>
<p>But it loses info:</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,527 | bash | # How do I find the exact CLI command given to Python?
I want to find out from inside the script -- the exact command I used to fire it up. I tried the following:
```
#!/usr/bin/env python
import sys, os
print os.path.basename(sys.argv[0]), sys.argv[1:]
```
But it loses info:
```
$ 1.py -1 dfd 'gf g' "df df"
1.py... | The information you're looking for (command params including quotes) is not available.
The *shell* (bash), not python, reads and interprets quotes--by the time python or any other spawned program sees the parameters, the quotes are removed. (Except for quoted quotes, of course.)
### More detail
When you type a comma... |
11728223 | Powershell Switch Statement to Set Multiple Variables | 8 | 2012-07-30 19:26:09 | <p>I am in the process of converting some old VB script to Powershell. I am trying to use a Switch statement to set multiple variables. Is this possible in Powershell? In VBS my code would look something like this:</p>
<pre><code>Select Case ENV
Case "DEV"
: SRCDRV = "\\Server1" _
: DESTDRV = "\\S... | 56,115 | 1,558,132 | 2018-01-24 11:42:19 | 11,728,382 | 11 | 2012-07-30 19:38:16 | 532,858 | 2012-07-30 19:38:16 | https://stackoverflow.com/q/11728223 | https://stackoverflow.com/a/11728382 | <p>Are you setting $cENV first?</p>
<p>I'm running that exact script above like this:</p>
<pre><code>$cENV = "DEV"
switch ($cENV) {
DEV {
$SRCDRV = "\\Server1"
$DSTDRV = "\\Server2\Folder1\"
}
TEST {
$SRCDRV = "\\Server1"
$DSTDRV = "\\Server2\Folder2\"
}
PROD {
... | <p>Are you setting $cENV first?</p> <p>I'm running that exact script above like this:</p> <pre><code>$cENV = "DEV" switch ($cENV) { DEV { $SRCDRV = "\\Server1" $DSTDRV = "\\Server2\Folder1\" } TEST { $SRCDRV = "\\Server1" $DSTDRV = "\\Server2\Folder2\" } PROD { ... | 526 | powershell | <h1>Powershell Switch Statement to Set Multiple Variables</h1>
<p>I am in the process of converting some old VB script to Powershell. I am trying to use a Switch statement to set multiple variables. Is this possible in Powershell? In VBS my code would look something like this:</p>
<pre><code>Select Case ENV
Case "... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,528 | bash | # Powershell Switch Statement to Set Multiple Variables
I am in the process of converting some old VB script to Powershell. I am trying to use a Switch statement to set multiple variables. Is this possible in Powershell? In VBS my code would look something like this:
```
Select Case ENV
Case "DEV"
: SRCDR... | Are you setting $cENV first?
I'm running that exact script above like this:
```
$cENV = "DEV"
switch ($cENV) {
DEV {
$SRCDRV = "\\Server1"
$DSTDRV = "\\Server2\Folder1\"
}
TEST {
$SRCDRV = "\\Server1"
$DSTDRV = "\\Server2\Folder2\"
}
PROD {
$SRCDRV = "\\Se... |
10801258 | Read argument with spaces in python script from a shell script | 8 | 2012-05-29 14:33:27 | <p>How do I read an argument with spaces when running a python script?</p>
<p><strong>UPDATE</strong>:</p>
<p>Looks like my problem is that I'm calling the python script through a shell script:</p>
<p>This works:</p>
<pre><code>> python script.py firstParam file\ with\ spaces.txt
# or
> python script.py first... | 14,801 | 259,525 | 2012-06-29 16:26:18 | 10,801,543 | 11 | 2012-05-29 14:50:50 | 100,297 | 2012-05-29 14:50:50 | https://stackoverflow.com/q/10801258 | https://stackoverflow.com/a/10801543 | <p>Use <code>"$@"</code> instead:</p>
<pre class="lang-bash prettyprint-override"><code>#!/bin/sh
python "$@"
</code></pre>
<p>Output:</p>
<pre><code>$ /tmp/test.sh /tmp/test.py firstParam "file with spaces.txt"
['/tmp/test.py', 'firstParam', 'file with spaces.txt']
</code></pre>
<p>with <code>/tmp/test.py</code> d... | <p>Use <code>"$@"</code> instead:</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/sh python "$@" </code></pre> <p>Output:</p> <pre><code>$ /tmp/test.sh /tmp/test.py firstParam "file with spaces.txt" ['/tmp/test.py', 'firstParam', 'file with spaces.txt'] </code></pre> <p>with <code>/tmp/test.py</code> d... | 16, 390 | python, shell | <h1>Read argument with spaces in python script from a shell script</h1>
<p>How do I read an argument with spaces when running a python script?</p>
<p><strong>UPDATE</strong>:</p>
<p>Looks like my problem is that I'm calling the python script through a shell script:</p>
<p>This works:</p>
<pre><code>> python scri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,529 | bash | # Read argument with spaces in python script from a shell script
How do I read an argument with spaces when running a python script?
**UPDATE**:
Looks like my problem is that I'm calling the python script through a shell script:
This works:
```
> python script.py firstParam file\ with\ spaces.txt
# or
> python scr... | Use `"$@"` instead:
```
#!/bin/sh
python "$@"
```
Output:
```
$ /tmp/test.sh /tmp/test.py firstParam "file with spaces.txt"
['/tmp/test.py', 'firstParam', 'file with spaces.txt']
```
with `/tmp/test.py` defined as:
```
import sys
print sys.argv
``` |
10063417 | How do I add an internal command to bash? | 8 | 2012-04-08 14:08:44 | <p>I don't mean an alias or function. I actually want to add an entire new internal command to the <code>bash</code> source code.</p>
<p>That way, when I compile it, it has my new command built in to the shell itself.</p>
<p>What are the steps involved in doing this?</p>
| 2,005 | 14,860 | 2015-07-14 18:26:52 | 10,063,457 | 11 | 2012-04-08 14:15:41 | 14,860 | 2012-04-12 04:27:30 | https://stackoverflow.com/q/10063417 | https://stackoverflow.com/a/10063457 | <p>This actually came up as part of an answer to <a href="https://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2">a more specific question</a> (how to get the evaluated <code>PS1</code> output to a variable) and I thought the process deserved its own question and answer, one more generalised to the p... | <p>This actually came up as part of an answer to <a href="https://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2">a more specific question</a> (how to get the evaluated <code>PS1</code> output to a variable) and I thought the process deserved its own question and answer, one more generalised to the p... | 387, 1796 | bash, command | <h1>How do I add an internal command to bash?</h1>
<p>I don't mean an alias or function. I actually want to add an entire new internal command to the <code>bash</code> source code.</p>
<p>That way, when I compile it, it has my new command built in to the shell itself.</p>
<p>What are the steps involved in doing this?... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,530 | bash | # How do I add an internal command to bash?
I don't mean an alias or function. I actually want to add an entire new internal command to the `bash` source code.
That way, when I compile it, it has my new command built in to the shell itself.
What are the steps involved in doing this? | This actually came up as part of an answer to [a more specific question](https://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2) (how to get the evaluated `PS1` output to a variable) and I thought the process deserved its own question and answer, one more generalised to the process of modifying `bash... |
9351539 | Is it possible to export environment property from ruby script? | 8 | 2012-02-19 17:46:55 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/2660571/exporting-an-environment-variable-in-ruby">Exporting an Environment Variable in Ruby</a> </p>
</blockquote>
<p>I need to set several environment properties from inside of ruby script.</p>
<p>Normally, ... | 4,979 | 486,057 | 2012-02-19 19:03:50 | 9,351,599 | 11 | 2012-02-19 17:52:28 | 978,917 | 2012-02-19 17:52:28 | https://stackoverflow.com/q/9351539 | https://stackoverflow.com/a/9351599 | <p>According to <a href="http://ruby.about.com/od/rubyfeatures/a/envvar.htm" rel="noreferrer">http://ruby.about.com/od/rubyfeatures/a/envvar.htm</a>, you can just write:</p>
<pre><code>ENV['SOME_VAR'] = 'some_value'
</code></pre>
| <p>According to <a href="http://ruby.about.com/od/rubyfeatures/a/envvar.htm" rel="noreferrer">http://ruby.about.com/od/rubyfeatures/a/envvar.htm</a>, you can just write:</p> <pre><code>ENV['SOME_VAR'] = 'some_value' </code></pre> | 12, 387 | bash, ruby | <h1>Is it possible to export environment property from ruby script?</h1>
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/2660571/exporting-an-environment-variable-in-ruby">Exporting an Environment Variable in Ruby</a> </p>
</blockquote>
<p>I need to set seve... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,531 | bash | # Is it possible to export environment property from ruby script?
> **Possible Duplicate:**
> [Exporting an Environment Variable in Ruby](https://stackoverflow.com/questions/2660571/exporting-an-environment-variable-in-ruby)
I need to set several environment properties from inside of ruby script.
Normally, in bash... | According to <http://ruby.about.com/od/rubyfeatures/a/envvar.htm>, you can just write:
```
ENV['SOME_VAR'] = 'some_value'
``` |
8696517 | buffer overflow example from Art of Exploitation book | 8 | 2012-01-02 00:25:18 | <p>I was reading this book Art of Exploitation, which is kinda good book and I run across that example from exploit_notesearch.c file.</p>
<p>Briefly author tries to overflow program from notesearch.c</p>
<pre><code>int main(int argc, char *argv[]) {
int userid, printing=1, fd;
char searchstring[100];
if(... | 5,510 | 1,125,515 | 2012-03-20 17:40:47 | 8,696,593 | 11 | 2012-01-02 00:43:56 | 916,657 | 2012-01-02 00:43:56 | https://stackoverflow.com/q/8696517 | https://stackoverflow.com/a/8696593 | <p>The author simply assumes that the C compiler will place the stacks of those two programs at the same (or very similar) virtual addresses <em>and</em> that the operating system will not perform <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization">address randomization (ASLR)</a>. This means that... | <p>The author simply assumes that the C compiler will place the stacks of those two programs at the same (or very similar) virtual addresses <em>and</em> that the operating system will not perform <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization">address randomization (ASLR)</a>. This means that... | 136, 2172, 10606, 78469 | buffer-overflow, exploit, security, shellcode | <h1>buffer overflow example from Art of Exploitation book</h1>
<p>I was reading this book Art of Exploitation, which is kinda good book and I run across that example from exploit_notesearch.c file.</p>
<p>Briefly author tries to overflow program from notesearch.c</p>
<pre><code>int main(int argc, char *argv[]) {
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,532 | bash | # buffer overflow example from Art of Exploitation book
I was reading this book Art of Exploitation, which is kinda good book and I run across that example from exploit_notesearch.c file.
Briefly author tries to overflow program from notesearch.c
```
int main(int argc, char *argv[]) {
int userid, printing=1, fd;... | The author simply assumes that the C compiler will place the stacks of those two programs at the same (or very similar) virtual addresses *and* that the operating system will not perform [address randomization (ASLR)](http://en.wikipedia.org/wiki/Address_space_layout_randomization). This means that the stack frames of ... |
6396923 | error while using make to compile Glibc-2.11.1 for Linux From Scratch | 8 | 2011-06-18 15:12:42 | <p>I am building LFS and I am in the part where we need to install Glibc-2.11.1</p>
<p><a href="http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc.html" rel="noreferrer">http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc.html</a></p>
<p>I have successfully configured it but I cant run the make com... | 6,126 | 726,872 | 2011-08-18 16:34:44 | 7,110,915 | 11 | 2011-08-18 16:34:44 | 224,671 | 2011-08-18 16:34:44 | https://stackoverflow.com/q/6396923 | https://stackoverflow.com/a/7110915 | <p>You need to install <code>gawk</code>. </p>
<pre><code>sudo apt-get install gawk
</code></pre>
<hr>
<p>The regex on Line 19 was</p>
<pre><code>/\/[^/]+$/
</code></pre>
<p>It is a known issue that <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=127293" rel="noreferrer"><code>mawk</code> does not unders... | <p>You need to install <code>gawk</code>. </p> <pre><code>sudo apt-get install gawk </code></pre> <hr> <p>The regex on Line 19 was</p> <pre><code>/\/[^/]+$/ </code></pre> <p>It is a known issue that <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=127293" rel="noreferrer"><code>mawk</code> does not unders... | 58, 387, 549, 4679, 13516 | bash, glibc, linux, linux-from-scratch, ubuntu | <h1>error while using make to compile Glibc-2.11.1 for Linux From Scratch</h1>
<p>I am building LFS and I am in the part where we need to install Glibc-2.11.1</p>
<p><a href="http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc.html" rel="noreferrer">http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,533 | bash | # error while using make to compile Glibc-2.11.1 for Linux From Scratch
I am building LFS and I am in the part where we need to install Glibc-2.11.1
<http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/glibc.html>
I have successfully configured it but I cant run the make command. Whenever I run the command it run... | You need to install `gawk`.
```
sudo apt-get install gawk
```
---
The regex on Line 19 was
```
/\/[^/]+$/
```
It is a known issue that [`mawk` does not understand unescaped '/' in character classes](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=127293) at least up to version 1.3.3-15 (the one supplied on Ubuntu... |
6665529 | Why can't string literals be used in bash regular expression tests? | 8 | 2011-07-12 14:10:18 | <p>Why does the following bash script only print out <code>variable worked</code>?</p>
<pre><code>#! /bin/bash
foo=baaz
regex='ba{2}z'
if [[ $foo =~ 'ba{2}z' ]]; then
echo "literal worked"
fi
if [[ $foo =~ $regex ]]; then
echo "variable worked"
fi
</code></pre>
<p>Is there something in the bash documentati... | 1,676 | 86,436 | 2015-04-19 16:37:57 | 6,665,860 | 11 | 2011-07-12 14:31:23 | 2,278,151 | 2011-07-12 14:31:23 | https://stackoverflow.com/q/6665529 | https://stackoverflow.com/a/6665860 | <p>You don't need quotes for bash regex anymore:</p>
<pre><code>#! /bin/bash
foo=baaz
regex='ba{2}z'
if [[ $foo =~ ba{2}z ]]; then
echo "literal worked"
fi
if [[ $foo =~ $regex ]]; then
echo "variable worked"
fi
# Should output literal worked, then variable worked
</code></pre>
<p>I can't remember which v... | <p>You don't need quotes for bash regex anymore:</p> <pre><code>#! /bin/bash foo=baaz regex='ba{2}z' if [[ $foo =~ ba{2}z ]]; then echo "literal worked" fi if [[ $foo =~ $regex ]]; then echo "variable worked" fi # Should output literal worked, then variable worked </code></pre> <p>I can't remember which v... | 18, 139, 276, 387, 11609 | bash, literals, regex, string, variables | <h1>Why can't string literals be used in bash regular expression tests?</h1>
<p>Why does the following bash script only print out <code>variable worked</code>?</p>
<pre><code>#! /bin/bash
foo=baaz
regex='ba{2}z'
if [[ $foo =~ 'ba{2}z' ]]; then
echo "literal worked"
fi
if [[ $foo =~ $regex ]]; then
echo "var... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,534 | bash | # Why can't string literals be used in bash regular expression tests?
Why does the following bash script only print out `variable worked`?
```
#! /bin/bash
foo=baaz
regex='ba{2}z'
if [[ $foo =~ 'ba{2}z' ]]; then
echo "literal worked"
fi
if [[ $foo =~ $regex ]]; then
echo "variable worked"
fi
```
Is there ... | You don't need quotes for bash regex anymore:
```
#! /bin/bash
foo=baaz
regex='ba{2}z'
if [[ $foo =~ ba{2}z ]]; then
echo "literal worked"
fi
if [[ $foo =~ $regex ]]; then
echo "variable worked"
fi
# Should output literal worked, then variable worked
```
I can't remember which version changed this though. |
6308438 | comments amongst parameters in BASH | 8 | 2011-06-10 15:19:58 | <p>I want to include command-parameters-inline comments, e.g.:</p>
<pre><code>sed -i.bak -r \
# comment 1
-e 'sed_commands' \
# comment 2
-e 'sed_commands' \
# comment 3
-e 'sed_commands' \
/path/to/file
</code></pre>
<p>The above code doesn't work. Is there a different way for embedding c... | 3,781 | 207,812 | 2017-10-26 23:09:05 | 6,309,461 | 11 | 2011-06-10 16:37:39 | 632,407 | 2011-06-10 17:11:21 | https://stackoverflow.com/q/6308438 | https://stackoverflow.com/a/6309461 | <p>If you really want comment arguments, can try this:</p>
<pre><code>ls $(
echo '-l' #for the long list
echo '-F' #show file types too
echo '-t' #sort by time
)
</code></pre>
<p>This will be equivalent to:</p>
<pre><code>ls -l -F -t
</code></pre>
<p>echo is an shell built-in, so does not execute extern... | <p>If you really want comment arguments, can try this:</p> <pre><code>ls $( echo '-l' #for the long list echo '-F' #show file types too echo '-t' #sort by time ) </code></pre> <p>This will be equivalent to:</p> <pre><code>ls -l -F -t </code></pre> <p>echo is an shell built-in, so does not execute extern... | 387, 1966 | bash, comments | <h1>comments amongst parameters in BASH</h1>
<p>I want to include command-parameters-inline comments, e.g.:</p>
<pre><code>sed -i.bak -r \
# comment 1
-e 'sed_commands' \
# comment 2
-e 'sed_commands' \
# comment 3
-e 'sed_commands' \
/path/to/file
</code></pre>
<p>The above code doesn't w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,535 | bash | # comments amongst parameters in BASH
I want to include command-parameters-inline comments, e.g.:
```
sed -i.bak -r \
# comment 1
-e 'sed_commands' \
# comment 2
-e 'sed_commands' \
# comment 3
-e 'sed_commands' \
/path/to/file
```
The above code doesn't work. Is there a different way for... | If you really want comment arguments, can try this:
```
ls $(
echo '-l' #for the long list
echo '-F' #show file types too
echo '-t' #sort by time
)
```
This will be equivalent to:
```
ls -l -F -t
```
echo is an shell built-in, so does not execute external commands, so it is fast enough. But, it is crazy... |
5648158 | Bash monitor disk usage | 8 | 2011-04-13 11:07:54 | <p>I bought a NAS box which has a cut down version of debian on it.</p>
<p>It ran out of space the other day and I did not realise. I am basically wanting to write a bash script that will alert me whenever the disk gets over 90% full.</p>
<p>Is anyone aware of a script that will do this or give me some advice on wri... | 9,641 | 30,786 | 2022-07-13 10:48:08 | 5,648,249 | 11 | 2011-04-13 11:14:23 | 616,700 | 2011-04-13 11:34:44 | https://stackoverflow.com/q/5648158 | https://stackoverflow.com/a/5648249 | <pre><code>#!/bin/bash
source /etc/profile
# Device to check
devname="/dev/sdb1"
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
if [ $p -ge 90 ]
then
df -h $devname | mail -s "Low on space" my@email.com
fi
</code></pre>
<p>Crontab this to run however often you want an alert</p>
<p>ED... | <pre><code>#!/bin/bash source /etc/profile # Device to check devname="/dev/sdb1" let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'` if [ $p -ge 90 ] then df -h $devname | mail -s "Low on space" my@email.com fi </code></pre> <p>Crontab this to run however often you want an alert</p> <p>ED... | 58, 387, 390, 1012, 6345 | bash, debian, disk, linux, shell | <h1>Bash monitor disk usage</h1>
<p>I bought a NAS box which has a cut down version of debian on it.</p>
<p>It ran out of space the other day and I did not realise. I am basically wanting to write a bash script that will alert me whenever the disk gets over 90% full.</p>
<p>Is anyone aware of a script that will do t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,536 | bash | # Bash monitor disk usage
I bought a NAS box which has a cut down version of debian on it.
It ran out of space the other day and I did not realise. I am basically wanting to write a bash script that will alert me whenever the disk gets over 90% full.
Is anyone aware of a script that will do this or give me some advi... | ```
#!/bin/bash
source /etc/profile
# Device to check
devname="/dev/sdb1"
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
if [ $p -ge 90 ]
then
df -h $devname | mail -s "Low on space" my@email.com
fi
```
Crontab this to run however often you want an alert
EDIT: For multiple disks
```... |
4750154 | Why is the output of my forking program different when I pipe its output? | 8 | 2011-01-20 17:00:58 | <p>I was looking at some simple code on fork, and decided to try it out for myself. I compiled and then ran it from inside Emacs, and got a different output to that output produced from running it in Bash.</p>
<pre><code>#include <unistd.h>
#include <stdio.h>
int main() {
if (fork() != 0) {
printf("... | 346 | 215,924 | 2011-01-20 17:35:00 | 4,750,296 | 11 | 2011-01-20 17:15:18 | 459,640 | 2011-01-20 17:15:18 | https://stackoverflow.com/q/4750154 | https://stackoverflow.com/a/4750296 | <p>The order in which different processes write their output is entirely unpredictable. So the only surprise is that sometimes the "X" print statement sometimes happens twice.</p>
<p>I believe this is because sometimes at the second <code>fork()</code>, an output line including "X" is in an output buffer, needing to ... | <p>The order in which different processes write their output is entirely unpredictable. So the only surprise is that sometimes the "X" print statement sometimes happens twice.</p> <p>I believe this is because sometimes at the second <code>fork()</code>, an output line including "X" is in an output buffer, needing to ... | 8, 58, 387, 2347, 5813 | bash, c, fork, linux, pipe | <h1>Why is the output of my forking program different when I pipe its output?</h1>
<p>I was looking at some simple code on fork, and decided to try it out for myself. I compiled and then ran it from inside Emacs, and got a different output to that output produced from running it in Bash.</p>
<pre><code>#include <un... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,537 | bash | # Why is the output of my forking program different when I pipe its output?
I was looking at some simple code on fork, and decided to try it out for myself. I compiled and then ran it from inside Emacs, and got a different output to that output produced from running it in Bash.
```
#include <unistd.h>
#include <stdio... | The order in which different processes write their output is entirely unpredictable. So the only surprise is that sometimes the "X" print statement sometimes happens twice.
I believe this is because sometimes at the second `fork()`, an output line including "X" is in an output buffer, needing to be flushed. So both pr... |
4741676 | Running Java remotely using PowerShell | 8 | 2011-01-19 22:44:03 | <p>When I run <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="nofollow">PowerShell</a> in a remote session (<code>etsn {servername}</code>), I sometimes can't seem to run Java processes, even the most simple:</p>
<pre><code>[chi-queuing]: PS C:\temp> java -cp .\hello.jar Hello
Error occurred during i... | 7,381 | 200,985 | 2015-12-02 13:57:13 | 4,742,801 | 11 | 2011-01-20 02:01:37 | 574,168 | 2014-10-15 21:21:46 | https://stackoverflow.com/q/4741676 | https://stackoverflow.com/a/4742801 | <p>According to this:
<a href="http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx</a></p>
<p><strong>MaxMemoryPerShellMB</strong>
Specifies the maximum amount of memory allocated per shell, including the shell's child processes. Th... | <p>According to this: <a href="http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx</a></p> <p><strong>MaxMemoryPerShellMB</strong> Specifies the maximum amount of memory allocated per shell, including the shell's child processes. Th... | 17, 526, 5910, 63177 | java, powershell, powershell-remoting, process | <h1>Running Java remotely using PowerShell</h1>
<p>When I run <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="nofollow">PowerShell</a> in a remote session (<code>etsn {servername}</code>), I sometimes can't seem to run Java processes, even the most simple:</p>
<pre><code>[chi-queuing]: PS C:\temp> ja... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,538 | bash | # Running Java remotely using PowerShell
When I run [PowerShell](http://en.wikipedia.org/wiki/Windows_PowerShell) in a remote session (`etsn {servername}`), I sometimes can't seem to run Java processes, even the most simple:
```
[chi-queuing]: PS C:\temp> java -cp .\hello.jar Hello
Error occurred during initializatio... | According to this:
<http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx>
**MaxMemoryPerShellMB**
Specifies the maximum amount of memory allocated per shell, including the shell's child processes. The default is **150 MB**.
### Increase Max Memory Per Shell MB
```
winrm set winrm/config/winrs '@{MaxMemoryPer... |
3464677 | What are the commands for using Git Bash in Windows e.g. when in git diff mode? | 8 | 2010-08-12 04:02:25 | <p>In Windows, in Git Bash, if I do a git diff I get all the differences flushed to the console with some sort of prompt to control the output buffer. What are the commands I can use in this mode of Git Bash? I don't know where to look for a quick reference.</p>
<p>I've worked out that <code><Enter></code> will ... | 3,126 | 78,216 | 2010-08-12 04:17:48 | 3,464,737 | 11 | 2010-08-12 04:17:48 | 390,989 | 2010-08-12 04:17:48 | https://stackoverflow.com/q/3464677 | https://stackoverflow.com/a/3464737 | <p><code>git diff</code> pipes the diff file into the Unix <a href="http://en.wikipedia.org/wiki/Less_%28Unix%29" rel="noreferrer"><code>less</code></a> pager. Press <code>h</code> when the diff view is open to see a bunch of commands. The particularly important ones to know:</p>
<ul>
<li><code>h</code> - Display help... | <p><code>git diff</code> pipes the diff file into the Unix <a href="http://en.wikipedia.org/wiki/Less_%28Unix%29" rel="noreferrer"><code>less</code></a> pager. Press <code>h</code> when the diff view is open to see a bunch of commands. The particularly important ones to know:</p> <ul> <li><code>h</code> - Display help... | 64, 119, 387 | bash, git, windows | <h1>What are the commands for using Git Bash in Windows e.g. when in git diff mode?</h1>
<p>In Windows, in Git Bash, if I do a git diff I get all the differences flushed to the console with some sort of prompt to control the output buffer. What are the commands I can use in this mode of Git Bash? I don't know where to ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,539 | bash | # What are the commands for using Git Bash in Windows e.g. when in git diff mode?
In Windows, in Git Bash, if I do a git diff I get all the differences flushed to the console with some sort of prompt to control the output buffer. What are the commands I can use in this mode of Git Bash? I don't know where to look for ... | `git diff` pipes the diff file into the Unix [`less`](http://en.wikipedia.org/wiki/Less_%28Unix%29) pager. Press `h` when the diff view is open to see a bunch of commands. The particularly important ones to know:
- `h` - Display help/commands
- `q` - Quit/close
- `[Space]` scroll 'k' lines ahead, where k should defaul... |
2970460 | Alternative to scp, transferring files between linux machines by opening parallel connections | 8 | 2010-06-03 23:14:53 | <p>Is there an alternative to scp, to transfer a large file from one machine to another machine by opening parallel connections and also able to pause and resume the download.</p>
<p>Please don't transfer this to severfault.com. I am not a system administrator. I am a developer trying to transfer past database dumps b... | 35,757 | 207,335 | 2011-10-13 00:49:17 | 2,971,118 | 11 | 2010-06-04 02:21:57 | 2,255,990 | 2010-06-04 02:21:57 | https://stackoverflow.com/q/2970460 | https://stackoverflow.com/a/2971118 | <p>You could try using split(1) to break the file apart and then scp the pieces in parallel. The file could then be combined into a single file on the destination machine with 'cat'.</p>
<pre><code># on local host
split -b 1M large.file large.file. # split into 1MiB chunks
for f in large.file.*; do scp $f remote_host... | <p>You could try using split(1) to break the file apart and then scp the pieces in parallel. The file could then be combined into a single file on the destination machine with 'cat'.</p> <pre><code># on local host split -b 1M large.file large.file. # split into 1MiB chunks for f in large.file.*; do scp $f remote_host... | 34, 58, 387, 390, 794 | bash, linux, network-programming, shell, unix | <h1>Alternative to scp, transferring files between linux machines by opening parallel connections</h1>
<p>Is there an alternative to scp, to transfer a large file from one machine to another machine by opening parallel connections and also able to pause and resume the download.</p>
<p>Please don't transfer this to sev... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,540 | bash | # Alternative to scp, transferring files between linux machines by opening parallel connections
Is there an alternative to scp, to transfer a large file from one machine to another machine by opening parallel connections and also able to pause and resume the download.
Please don't transfer this to severfault.com. I a... | You could try using split(1) to break the file apart and then scp the pieces in parallel. The file could then be combined into a single file on the destination machine with 'cat'.
```
# on local host
split -b 1M large.file large.file. # split into 1MiB chunks
for f in large.file.*; do scp $f remote_host: & done
# on ... |
331224 | How do I append onto pipes? | 8 | 2008-12-01 15:48:04 | <p>So my question is if I can somehow send data to my program and then send the same data AND its result to another program without having to create a temporary file (in my case ouputdata.txt).
Preferably using linux pipes/bash.</p>
<p>I currently do the following:</p>
<p>cat inputdata.txt | ./MyProg > outputdata.txt... | 7,549 | 17,500 | 2009-03-30 15:11:23 | 331,246 | 11 | 2008-12-01 15:55:19 | 10,661 | 2008-12-01 15:55:19 | https://stackoverflow.com/q/331224 | https://stackoverflow.com/a/331246 | <p>Choice 1 - fix <code>MyProg</code> to write the merged output from the input and it's own output. Then you can do this.</p>
<pre><code>./MyProg <inputdata.txt | ./MyProg2
</code></pre>
<p>Choice 2 - If you can't fix <code>MyProg</code> to write both input and output, you need to merge.</p>
<pre><code>./MyProg... | <p>Choice 1 - fix <code>MyProg</code> to write the merged output from the input and it's own output. Then you can do this.</p> <pre><code>./MyProg <inputdata.txt | ./MyProg2 </code></pre> <p>Choice 2 - If you can't fix <code>MyProg</code> to write both input and output, you need to merge.</p> <pre><code>./MyProg... | 387, 5813 | bash, pipe | <h1>How do I append onto pipes?</h1>
<p>So my question is if I can somehow send data to my program and then send the same data AND its result to another program without having to create a temporary file (in my case ouputdata.txt).
Preferably using linux pipes/bash.</p>
<p>I currently do the following:</p>
<p>cat inpu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,541 | bash | # How do I append onto pipes?
So my question is if I can somehow send data to my program and then send the same data AND its result to another program without having to create a temporary file (in my case ouputdata.txt).
Preferably using linux pipes/bash.
I currently do the following:
cat inputdata.txt | ./MyProg > ... | Choice 1 - fix `MyProg` to write the merged output from the input and it's own output. Then you can do this.
```
./MyProg <inputdata.txt | ./MyProg2
```
Choice 2 - If you can't fix `MyProg` to write both input and output, you need to merge.
```
./MyProg <inputdata.txt | cat inputdata.txt - | ./MyProg2
``` |
295195 | How do I add a directory with a colon to PYTHONPATH? | 8 | 2008-11-17 09:46:19 | <p>The problem is simple:</p>
<p>Using bash, I want to add a directory to my PYTHONPATH for ease of script execution. Unfortunately, the directory I want to use has a : in it. So I try each of the following</p>
<pre><code>export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com:3344/
export PYTHONPATH=${PYTHONPATH}:... | 17,716 | 10,264 | 2023-07-18 11:08:38 | 295,276 | 11 | 2008-11-17 10:38:26 | 28,258 | 2008-11-17 10:38:26 | https://stackoverflow.com/q/295195 | https://stackoverflow.com/a/295276 | <p>The problem is not with bash. It should be setting your environment variable correctly, complete with the <code>:</code> character.</p>
<p>The problem, instead, is with Python's parsing of the <code>PYTHONPATH</code> variable. Following the example set by the <a href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/p... | <p>The problem is not with bash. It should be setting your environment variable correctly, complete with the <code>:</code> character.</p> <p>The problem, instead, is with Python's parsing of the <code>PYTHONPATH</code> variable. Following the example set by the <a href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/p... | 16, 387, 390 | bash, python, shell | <h1>How do I add a directory with a colon to PYTHONPATH?</h1>
<p>The problem is simple:</p>
<p>Using bash, I want to add a directory to my PYTHONPATH for ease of script execution. Unfortunately, the directory I want to use has a : in it. So I try each of the following</p>
<pre><code>export PYTHONPATH=${PYTHONPATH}:/h... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,542 | bash | # How do I add a directory with a colon to PYTHONPATH?
The problem is simple:
Using bash, I want to add a directory to my PYTHONPATH for ease of script execution. Unfortunately, the directory I want to use has a : in it. So I try each of the following
```
export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com:334... | The problem is not with bash. It should be setting your environment variable correctly, complete with the `:` character.
The problem, instead, is with Python's parsing of the `PYTHONPATH` variable. Following the example set by the [`PATH` variable](http://sourceware.org/cgi-bin/cvsweb.cgi/libc/posix/execvp.c?rev=1.27&... |
210978 | Using os.execvp in Python | 8 | 2008-10-17 03:04:38 | <p>I have a question about using <code>os.execvp</code> in Python. I have the following bit of code that's used to create a list of arguments:</p>
<pre>
args = [ "java"
, classpath
, "-Djava.library.path=" + lib_path()
, ea
, "-Xmx1000m"
, "-server"
, "code_swarm"
, par... | 14,696 | 28,804 | 2008-10-17 12:11:04 | 210,982 | 11 | 2008-10-17 03:07:53 | 28,258 | 2008-10-17 04:15:29 | https://stackoverflow.com/q/210978 | https://stackoverflow.com/a/210982 | <p>If your "classpath" variable contains for instance "-classpath foo.jar", it will not work, since it is thinking the option name is "-classpath foo.jar". Split it in two arguments: [..., "-classpath", classpath, ...].</p>
<p>The other ways (copy and paste and system()) work because the shell splits the command line ... | <p>If your "classpath" variable contains for instance "-classpath foo.jar", it will not work, since it is thinking the option name is "-classpath foo.jar". Split it in two arguments: [..., "-classpath", classpath, ...].</p> <p>The other ways (copy and paste and system()) work because the shell splits the command line ... | 16, 390, 7932 | exec, python, shell | <h1>Using os.execvp in Python</h1>
<p>I have a question about using <code>os.execvp</code> in Python. I have the following bit of code that's used to create a list of arguments:</p>
<pre>
args = [ "java"
, classpath
, "-Djava.library.path=" + lib_path()
, ea
, "-Xmx1000m"
, "-server"... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,543 | bash | # Using os.execvp in Python
I have a question about using `os.execvp` in Python. I have the following bit of code that's used to create a list of arguments:
```
args = [ "java"
, classpath
, "-Djava.library.path=" + lib_path()
, ea
, "-Xmx1000m"
, "-server"
, "code_swarm"
... | If your "classpath" variable contains for instance "-classpath foo.jar", it will not work, since it is thinking the option name is "-classpath foo.jar". Split it in two arguments: [..., "-classpath", classpath, ...].
The other ways (copy and paste and system()) work because the shell splits the command line at the spa... |
74525090 | Bash `set -x` only for the duration of a function | 7 | 2022-11-21 21:30:02 | <p>I have a function that runs several commands and each of them take awhile to finish. I added <code>set -x</code> at the beginning so that I can see exactly which command is executing while it's running. Then at the end I disable it with <code>set +x</code>.</p>
<pre><code>function toolong() {
set -x;
takes_a_lon... | 1,191 | 147,390 | 2025-09-23 05:13:54 | 74,525,211 | 11 | 2022-11-21 21:43:01 | 9,072,753 | 2022-11-21 22:03:26 | https://stackoverflow.com/q/74525090 | https://stackoverflow.com/a/74525211 | <p>If you don't need to affect current execution environment, just run it all in a subshell.</p>
<pre><code>toolong() {
(
set -x;
takes_a_long_time &&
takes_also_a_long_time &&
takes_more time
)
}
</code></pre>
<p>Or shorter you can:</p>
<pre><code>toolong() (
set -x;
takes_a... | <p>If you don't need to affect current execution environment, just run it all in a subshell.</p> <pre><code>toolong() { ( set -x; takes_a_long_time && takes_also_a_long_time && takes_more time ) } </code></pre> <p>Or shorter you can:</p> <pre><code>toolong() ( set -x; takes_a... | 387 | bash | <h1>Bash `set -x` only for the duration of a function</h1>
<p>I have a function that runs several commands and each of them take awhile to finish. I added <code>set -x</code> at the beginning so that I can see exactly which command is executing while it's running. Then at the end I disable it with <code>set +x</code>.<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,544 | bash | # Bash `set -x` only for the duration of a function
I have a function that runs several commands and each of them take awhile to finish. I added `set -x` at the beginning so that I can see exactly which command is executing while it's running. Then at the end I disable it with `set +x`.
```
function toolong() {
set... | If you don't need to affect current execution environment, just run it all in a subshell.
```
toolong() {
(
set -x;
takes_a_long_time &&
takes_also_a_long_time &&
takes_more time
)
}
```
Or shorter you can:
```
toolong() (
set -x;
takes_a_long_time &&
takes_also_a_long_time &&
takes_m... |
69311346 | Get the value of an environment variable whose name is stored in a variable | 7 | 2021-09-24 07:44:53 | <p>I am trying to figure out an easy to read and understandable idiom that evaluates the the value of an environment variable whose name is stored in a variable:</p>
<pre><code>$varName='TEMP'
</code></pre>
<p>I have come up with</p>
<pre><code>$val = invoke-expression "`$env:$varName"
</code></pre>
<p>and am... | 2,995 | 180,275 | 2023-02-16 17:59:59 | 69,313,517 | 11 | 2021-09-24 10:30:01 | 712,649 | 2021-09-24 10:30:01 | https://stackoverflow.com/q/69311346 | https://stackoverflow.com/a/69313517 | <p><code>env:</code> a real PSDrive that supports item retrieval:</p>
<pre><code>$val = (Get-Item -Path env:\$varName).Value
</code></pre>
| <p><code>env:</code> a real PSDrive that supports item retrieval:</p> <pre><code>$val = (Get-Item -Path env:\$varName).Value </code></pre> | 526, 9013, 16357 | environment-variables, indirection, powershell | <h1>Get the value of an environment variable whose name is stored in a variable</h1>
<p>I am trying to figure out an easy to read and understandable idiom that evaluates the the value of an environment variable whose name is stored in a variable:</p>
<pre><code>$varName='TEMP'
</code></pre>
<p>I have come up with</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,545 | bash | # Get the value of an environment variable whose name is stored in a variable
I am trying to figure out an easy to read and understandable idiom that evaluates the the value of an environment variable whose name is stored in a variable:
```
$varName='TEMP'
```
I have come up with
```
$val = invoke-expression "`$env... | `env:` a real PSDrive that supports item retrieval:
```
$val = (Get-Item -Path env:\$varName).Value
``` |
67215169 | Importing multiple versions of Powershell Modules loads them all? | 7 | 2021-04-22 14:23:49 | <p>Importing multiple versions of modules (this is PS7):</p>
<pre><code>Import-Module -Name MyModule -RequiredVersion 1.0.28
Import-Module -Name MyModule -RequiredVersion 1.0.29
</code></pre>
<p>Will load both versions into your session:</p>
<pre><code>Get-Module -Name MyModule
</code></pre>
<p>Outputs:</p>
<pre><code... | 6,691 | 666,254 | 2022-10-24 17:12:14 | 67,215,497 | 11 | 2021-04-22 14:42:54 | 45,375 | 2022-10-24 17:12:14 | https://stackoverflow.com/q/67215169 | https://stackoverflow.com/a/67215497 | <blockquote>
<p>Which version does PS actually use in this scenario?</p>
</blockquote>
<p><strong>The <em>most recently imported</em> version takes precedence</strong>, which the output of <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.core/get-module" rel="nofollow noreferrer"><code>Get-Mo... | <blockquote> <p>Which version does PS actually use in this scenario?</p> </blockquote> <p><strong>The <em>most recently imported</em> version takes precedence</strong>, which the output of <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.core/get-module" rel="nofollow noreferrer"><code>Get-Mo... | 526, 144089 | powershell, powershell-7.0 | <h1>Importing multiple versions of Powershell Modules loads them all?</h1>
<p>Importing multiple versions of modules (this is PS7):</p>
<pre><code>Import-Module -Name MyModule -RequiredVersion 1.0.28
Import-Module -Name MyModule -RequiredVersion 1.0.29
</code></pre>
<p>Will load both versions into your session:</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,546 | bash | # Importing multiple versions of Powershell Modules loads them all?
Importing multiple versions of modules (this is PS7):
```
Import-Module -Name MyModule -RequiredVersion 1.0.28
Import-Module -Name MyModule -RequiredVersion 1.0.29
```
Will load both versions into your session:
```
Get-Module -Name MyModule
```
Ou... | > Which version does PS actually use in this scenario?
**The *most recently imported* version takes precedence**, which the output of [`Get-Module`](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/get-module) indicates in *reverse* order of precedence (as of PowerShell Core 7.2.0-preview.5); th... |
66894559 | How do I run jq on each log line and tail it? | 7 | 2021-03-31 19:59:41 | <p>I have a log file with each line being a json object. I want to view the log lines as pretty json while being able to tail the logs, with maybe <code>tail</code> or <code>less</code>.
I have tried the following and they either return immediately i.e. don't tail the logs, or appear to tail (by not returning) but don'... | 8,771 | 369,243 | 2021-03-31 20:22:12 | 66,894,836 | 11 | 2021-03-31 20:22:12 | 7,552 | 2021-03-31 20:22:12 | https://stackoverflow.com/q/66894559 | https://stackoverflow.com/a/66894836 | <p>"Works for me"™:</p>
<ul>
<li><p>in one terminal window:</p>
<pre class="lang-sh prettyprint-override"><code>while true; do echo "{\"date\":\"$(date)\"}" >> logfile; sleep 1; done
</code></pre>
</li>
<li><p>in another:</p>
<pre class="lang-sh prettyprint-override"><code>... | <p>"Works for me"™:</p> <ul> <li><p>in one terminal window:</p> <pre class="lang-sh prettyprint-override"><code>while true; do echo "{\"date\":\"$(date)\"}" >> logfile; sleep 1; done </code></pre> </li> <li><p>in another:</p> <pre class="lang-sh prettyprint-override"><code>... | 387, 29657, 105170 | bash, jq, less | <h1>How do I run jq on each log line and tail it?</h1>
<p>I have a log file with each line being a json object. I want to view the log lines as pretty json while being able to tail the logs, with maybe <code>tail</code> or <code>less</code>.
I have tried the following and they either return immediately i.e. don't tail ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,547 | bash | # How do I run jq on each log line and tail it?
I have a log file with each line being a json object. I want to view the log lines as pretty json while being able to tail the logs, with maybe `tail` or `less`.
I have tried the following and they either return immediately i.e. don't tail the logs, or appear to tail (by... | "Works for me"™:
- in one terminal window:
```
while true; do echo "{\"date\":\"$(date)\"}" >> logfile; sleep 1; done
```
- in another:
```
tail -f logfile | jq .
``` |
66831836 | How to capture / redirect stdout/stderr from a source command into a variable (in a bash script)? | 7 | 2021-03-27 13:26:37 | <p>Usually I capture the output via a subshell:
<code>result="$(command 2>&1)"</code></p>
<p>If the command is <code>source</code>, the subshell swallows some (all?) changes to the scripts shell's environment.</p>
<p>How can I capture the output of <code>source</code> into a variable?</p>
| 2,601 | 6,919,635 | 2021-03-27 18:25:58 | 66,832,192 | 11 | 2021-03-27 14:05:54 | 14,637 | 2021-03-27 14:05:54 | https://stackoverflow.com/q/66831836 | https://stackoverflow.com/a/66832192 | <p>Surprisingly tricky question!</p>
<p>My first thought was to use a named pipe (<code>mkfifo(1)</code>), but those have a finite buffer size, so if the <code>source</code>d script fills up the buffer the script would hang. And you can't use a background process to drain the buffer because you want the output in a var... | <p>Surprisingly tricky question!</p> <p>My first thought was to use a named pipe (<code>mkfifo(1)</code>), but those have a finite buffer size, so if the <code>source</code>d script fills up the buffer the script would hang. And you can't use a background process to drain the buffer because you want the output in a var... | 387, 4867, 19156, 57788 | bash, stderr, stdout, subshell | <h1>How to capture / redirect stdout/stderr from a source command into a variable (in a bash script)?</h1>
<p>Usually I capture the output via a subshell:
<code>result="$(command 2>&1)"</code></p>
<p>If the command is <code>source</code>, the subshell swallows some (all?) changes to the scripts shell's... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,548 | bash | # How to capture / redirect stdout/stderr from a source command into a variable (in a bash script)?
Usually I capture the output via a subshell:
`result="$(command 2>&1)"`
If the command is `source`, the subshell swallows some (all?) changes to the scripts shell's environment.
How can I capture the output of `source... | Surprisingly tricky question!
My first thought was to use a named pipe (`mkfifo(1)`), but those have a finite buffer size, so if the `source`d script fills up the buffer the script would hang. And you can't use a background process to drain the buffer because you want the output in a variable in the original process e... |
46834093 | find exec and strip extension from filenames | 7 | 2017-10-19 15:58:13 | <p>Any idea why this command is not working? btw, I'm trying to strip out the extensions of all csv files in current directory.</p>
<pre><code>find -type f -iname "*.csv" -exec mv {} $(basename {} ".csv") \;
</code></pre>
<p>Tried many variants including the parameter expansions, xargs ... Even then all went futile.<... | 5,654 | 1,219,052 | 2021-01-21 18:11:11 | 65,833,364 | 11 | 2021-01-21 18:11:11 | 4,773,274 | 2021-01-21 18:11:11 | https://stackoverflow.com/q/46834093 | https://stackoverflow.com/a/65833364 | <p>This should do:</p>
<pre class="lang-sh prettyprint-override"><code> find ./ -type f -iname "*.csv" -exec sh -c 'mv {} $(basename {} .csv)' \;
</code></pre>
<p><code>find</code> is able to substitute <code>{}</code> with its findings since the quotes prevent executing the subshell until <code>find</code> i... | <p>This should do:</p> <pre class="lang-sh prettyprint-override"><code> find ./ -type f -iname "*.csv" -exec sh -c 'mv {} $(basename {} .csv)' \; </code></pre> <p><code>find</code> is able to substitute <code>{}</code> with its findings since the quotes prevent executing the subshell until <code>find</code> i... | 387, 10193 | bash, find | <h1>find exec and strip extension from filenames</h1>
<p>Any idea why this command is not working? btw, I'm trying to strip out the extensions of all csv files in current directory.</p>
<pre><code>find -type f -iname "*.csv" -exec mv {} $(basename {} ".csv") \;
</code></pre>
<p>Tried many variants including the param... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,549 | bash | # find exec and strip extension from filenames
Any idea why this command is not working? btw, I'm trying to strip out the extensions of all csv files in current directory.
```
find -type f -iname "*.csv" -exec mv {} $(basename {} ".csv") \;
```
Tried many variants including the parameter expansions, xargs ... Even t... | This should do:
```
find ./ -type f -iname "*.csv" -exec sh -c 'mv {} $(basename {} .csv)' \;
```
`find` is able to substitute `{}` with its findings since the quotes prevent executing the subshell until `find` is done. Then it executes the `-exec` part.
---
The problem why yours is not working is that `$(basename... |
64891846 | Specify function return type | 7 | 2020-11-18 11:06:39 | <p>How do I specify the return type in a powershell function?</p>
<pre><code>function getSomeString {
return "hello world"
}
$xyz = getSomeString() # <--- IDE does not recognize $xyz as a string
</code></pre>
| 3,218 | 2,583,765 | 2020-11-18 17:37:51 | 64,891,912 | 11 | 2020-11-18 11:10:57 | 712,649 | 2020-11-18 17:37:51 | https://stackoverflow.com/q/64891846 | https://stackoverflow.com/a/64891912 | <p>Before getting to the answer, I should point out that <strong>PowerShell commands do NOT have static return types</strong>!</p>
<p>In terms of I/O, commands in PowerShell are like little black boxes - you send 0 or more input objects in one end, and 0 or more outputs object are emitted at the other end - the <em>typ... | <p>Before getting to the answer, I should point out that <strong>PowerShell commands do NOT have static return types</strong>!</p> <p>In terms of I/O, commands in PowerShell are like little black boxes - you send 0 or more input objects in one end, and 0 or more outputs object are emitted at the other end - the <em>typ... | 526 | powershell | <h1>Specify function return type</h1>
<p>How do I specify the return type in a powershell function?</p>
<pre><code>function getSomeString {
return "hello world"
}
$xyz = getSomeString() # <--- IDE does not recognize $xyz as a string
</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,550 | bash | # Specify function return type
How do I specify the return type in a powershell function?
```
function getSomeString {
return "hello world"
}
$xyz = getSomeString() # <--- IDE does not recognize $xyz as a string
``` | Before getting to the answer, I should point out that **PowerShell commands do NOT have static return types**!
In terms of I/O, commands in PowerShell are like little black boxes - you send 0 or more input objects in one end, and 0 or more outputs object are emitted at the other end - the *type(s) of which may vary*.
... |
64792108 | Getting error "Could not load file or assembly 'System.Windows.Forms" at 'Import-Module "AzureAD" line in PS script | 7 | 2020-11-11 18:28:36 | <p>I am trying to deploy a simple powershell function app that contains the following commands:</p>
<pre><code>Import-Module D:\home\site\wwwroot\HttpTrigger1\AzureAD\AzureAD.psd1
Connect-AzureAD -TenantId $tenantId -Credential $Credential
</code></pre>
<p>AzureAD module files have already been copied from local repos... | 15,517 | 14,620,588 | 2021-02-24 06:55:39 | 64,793,955 | 11 | 2020-11-11 20:53:02 | 6,027,154 | 2020-11-11 20:53:02 | https://stackoverflow.com/q/64792108 | https://stackoverflow.com/a/64793955 | <p>In PowerShell 7, the AzureAD module needs to be explicitly imported with the -UseWindowsPowershell switch, so that it is loaded into a separate Windows PowerShell session:</p>
<pre><code>Import-Module AzureAD -UseWindowsPowerShell
</code></pre>
<p>For more details and caveats, see <a href="https://github.com/Azure/a... | <p>In PowerShell 7, the AzureAD module needs to be explicitly imported with the -UseWindowsPowershell switch, so that it is loaded into a separate Windows PowerShell session:</p> <pre><code>Import-Module AzureAD -UseWindowsPowerShell </code></pre> <p>For more details and caveats, see <a href="https://github.com/Azure/a... | 526, 81879, 118870, 138044 | azure-function-app, azure-functions, azure-powershell, powershell | <h1>Getting error "Could not load file or assembly 'System.Windows.Forms" at 'Import-Module "AzureAD" line in PS script</h1>
<p>I am trying to deploy a simple powershell function app that contains the following commands:</p>
<pre><code>Import-Module D:\home\site\wwwroot\HttpTrigger1\AzureAD\AzureAD.psd1
Connect-AzureA... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,551 | bash | # Getting error "Could not load file or assembly 'System.Windows.Forms" at 'Import-Module "AzureAD" line in PS script
I am trying to deploy a simple powershell function app that contains the following commands:
```
Import-Module D:\home\site\wwwroot\HttpTrigger1\AzureAD\AzureAD.psd1
Connect-AzureAD -TenantId $tenant... | In PowerShell 7, the AzureAD module needs to be explicitly imported with the -UseWindowsPowershell switch, so that it is loaded into a separate Windows PowerShell session:
```
Import-Module AzureAD -UseWindowsPowerShell
```
For more details and caveats, see <https://github.com/Azure/azure-functions-powershell-worker/... |
59717437 | Getting permission denied on k8s initContainer while running sh file | 7 | 2020-01-13 13:17:12 | <p>I have a k8s YAML file with 2 containers. <code>initContainer</code> and the main container. I am using a volume to mount a script file to be run in <code>initContainer</code> but I am getting <code>permission denied</code> error.
Here is the snippet.</p>
<pre><code> volumes:
- name: casacm-script
configMap... | 7,404 | 4,825,076 | 2020-01-13 14:03:10 | 59,718,171 | 11 | 2020-01-13 14:03:10 | 1,839,482 | 2020-01-13 14:03:10 | https://stackoverflow.com/q/59717437 | https://stackoverflow.com/a/59718171 | <p>Change your volumes to below to add permission. </p>
<pre><code>volumes:
- name: casacm-script
configMap:
name: {{ include "oxauth.name" . }}-casacm-script
defaultMode: 0777
</code></pre>
| <p>Change your volumes to below to add permission. </p> <pre><code>volumes: - name: casacm-script configMap: name: {{ include "oxauth.name" . }}-casacm-script defaultMode: 0777 </code></pre> | 387, 106338 | bash, kubernetes | <h1>Getting permission denied on k8s initContainer while running sh file</h1>
<p>I have a k8s YAML file with 2 containers. <code>initContainer</code> and the main container. I am using a volume to mount a script file to be run in <code>initContainer</code> but I am getting <code>permission denied</code> error.
Here is... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,552 | bash | # Getting permission denied on k8s initContainer while running sh file
I have a k8s YAML file with 2 containers. `initContainer` and the main container. I am using a volume to mount a script file to be run in `initContainer` but I am getting `permission denied` error.
Here is the snippet.
```
volumes:
- name: cas... | Change your volumes to below to add permission.
```
volumes:
- name: casacm-script
configMap:
name: {{ include "oxauth.name" . }}-casacm-script
defaultMode: 0777
``` |
59393574 | How to identify the default audio device in Powershell? | 7 | 2019-12-18 13:56:12 | <p>I am looking for a solution to get the default audio device via Powershell.
In best case, it could work via embedded C#-code to directly use IMMDeviceEnumerator::GetDefaultAudioEndpoint (see here <a href="https://learn.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdeviceenumerator-getdefaultaud... | 12,344 | 5,330,333 | 2024-04-03 17:58:56 | 59,398,725 | 11 | 2019-12-18 19:15:48 | 5,330,333 | 2022-09-03 10:57:32 | https://stackoverflow.com/q/59393574 | https://stackoverflow.com/a/59398725 | <p>Finally I figured it out and I am happy to share the working code-snippet:</p>
<pre><code>cls
Add-Type @'
[Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMMDevice {
int a(); int o();
int GetId([MarshalAs(UnmanagedType.LPWStr)] out strin... | <p>Finally I figured it out and I am happy to share the working code-snippet:</p> <pre><code>cls Add-Type @' [Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IMMDevice { int a(); int o(); int GetId([MarshalAs(UnmanagedType.LPWStr)] out strin... | 526, 116115 | audio-device, powershell | <h1>How to identify the default audio device in Powershell?</h1>
<p>I am looking for a solution to get the default audio device via Powershell.
In best case, it could work via embedded C#-code to directly use IMMDeviceEnumerator::GetDefaultAudioEndpoint (see here <a href="https://learn.microsoft.com/en-us/windows/win32... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,553 | bash | # How to identify the default audio device in Powershell?
I am looking for a solution to get the default audio device via Powershell.
In best case, it could work via embedded C#-code to directly use IMMDeviceEnumerator::GetDefaultAudioEndpoint (see here [IMMDeviceEnumertor](https://learn.microsoft.com/en-us/windows/wi... | Finally I figured it out and I am happy to share the working code-snippet:
```
cls
Add-Type @'
[Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMMDevice {
int a(); int o();
int GetId([MarshalAs(UnmanagedType.LPWStr)] out string id);
}
[Guid("A95664D... |
58420393 | Is there a way to keep a cURL command from interpreting a semicolon in macOS Catalina? | 7 | 2019-10-16 19:23:50 | <p>Running a cURL command to upload the contents of a file (by filling a form) like the following <code>curl -L -X POST -F 'edit=filename' http://website.local/example -F 'filecontent=test;2;3'</code> will work on High Sierra but won't on Catalina</p>
<p>Catalina keeps stopping at the semicolon <code>;</code> and igno... | 3,293 | 1,539,854 | 2019-10-16 20:25:21 | 58,420,893 | 11 | 2019-10-16 20:00:58 | 14,122 | 2019-10-16 20:25:21 | https://stackoverflow.com/q/58420393 | https://stackoverflow.com/a/58420893 | <p>Change from <code>--form</code> to <code>--form-string</code> to prevent <code>;key=value</code> (as used for <code>;type=text/x-myapp</code> assignments) from being parsed.</p>
<hr>
<p>Thus, you can change the pertinent line from:</p>
<pre><code>curl "${other_args[@]}" -F "filecontent=$(<file)"
</code></pre>
... | <p>Change from <code>--form</code> to <code>--form-string</code> to prevent <code>;key=value</code> (as used for <code>;type=text/x-myapp</code> assignments) from being parsed.</p> <hr> <p>Thus, you can change the pertinent line from:</p> <pre><code>curl "${other_args[@]}" -F "filecontent=$(<file)" </code></pre> ... | 390, 138656 | macos-catalina, shell | <h1>Is there a way to keep a cURL command from interpreting a semicolon in macOS Catalina?</h1>
<p>Running a cURL command to upload the contents of a file (by filling a form) like the following <code>curl -L -X POST -F 'edit=filename' http://website.local/example -F 'filecontent=test;2;3'</code> will work on High Sierr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,554 | bash | # Is there a way to keep a cURL command from interpreting a semicolon in macOS Catalina?
Running a cURL command to upload the contents of a file (by filling a form) like the following `curl -L -X POST -F 'edit=filename' http://website.local/example -F 'filecontent=test;2;3'` will work on High Sierra but won't on Catal... | Change from `--form` to `--form-string` to prevent `;key=value` (as used for `;type=text/x-myapp` assignments) from being parsed.
---
Thus, you can change the pertinent line from:
```
curl "${other_args[@]}" -F "filecontent=$(<file)"
```
to:
```
curl "${other_args[@]}" --form-string "filecontent=$(<file)"
``` |
58238481 | PowerShell remoting: Controlling what edition is being targeted (PowerShell (Core) 7 or Windows PowerShell); the state of cross-platform remoting | 7 | 2019-10-04 14:36:36 | <p>This self-answered question, which focuses on Windows<sup>[1]</sup>, addresses the following aspects:</p>
<p>Now that there are <strong><em>two</em> PowerShell editions</strong> - the legacy, <strong>Windows-only <em>Windows PowerShell</em></strong> and the <strong>cross-platform <a href="https://github.com/PowerShe... | 3,408 | 45,375 | 2025-02-19 23:57:49 | 58,238,482 | 11 | 2019-10-04 14:36:36 | 45,375 | 2025-02-19 23:57:49 | https://stackoverflow.com/q/58238481 | https://stackoverflow.com/a/58238482 |
<p><strong>Preface</strong>:</p>
<ul>
<li><p>Possibly <em>changing the default</em> remote endpoint for <a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core) 7</em></a> to targeting the <em>same PowerShell edition</em> is being considered: see <a href=... | <p><strong>Preface</strong>:</p> <ul> <li><p>Possibly <em>changing the default</em> remote endpoint for <a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core) 7</em></a> to targeting the <em>same PowerShell edition</em> is being considered: see <a href=... | 526, 63177, 78680, 79396, 130616 | powershell, powershell-core, powershell-remoting, winrm, wsman | <h1>PowerShell remoting: Controlling what edition is being targeted (PowerShell (Core) 7 or Windows PowerShell); the state of cross-platform remoting</h1>
<p>This self-answered question, which focuses on Windows<sup>[1]</sup>, addresses the following aspects:</p>
<p>Now that there are <strong><em>two</em> PowerShell ed... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,555 | bash | # PowerShell remoting: Controlling what edition is being targeted (PowerShell (Core) 7 or Windows PowerShell); the state of cross-platform remoting
This self-answered question, which focuses on Windows[1], addresses the following aspects:
Now that there are ***two* PowerShell editions** - the legacy, **Windows-only *... | **Preface**:
- Possibly *changing the default* remote endpoint for [*PowerShell (Core) 7*](https://github.com/PowerShell/PowerShell/blob/master/README.md) to targeting the *same PowerShell edition* is being considered: see [GitHub issue #11616](https://github.com/PowerShell/PowerShell/issues/11616).
- As of v7.5.x, th... |
57270400 | Creating symlink in Laravel (windows) | 7 | 2019-07-30 11:17:20 | <p>I'm currently having some problems with creating symlink in my Laravel project. I'm currently on <code>Windows 10 OS</code> and I'm using <code>GitBash</code>.</p>
<p>I need to create symlink from <code>storage/app/products_content</code> to <code>public/products_content</code></p>
<p>For that, I'm using the follo... | 12,441 | 10,000,772 | 2021-11-01 15:16:07 | 57,270,908 | 11 | 2019-07-30 11:46:00 | 5,363,197 | 2019-07-30 11:46:00 | https://stackoverflow.com/q/57270400 | https://stackoverflow.com/a/57270908 | <p>Try going into the <code>public</code> folder, then do:</p>
<p><code>ln -s ../storage/app/products_content products_content</code></p>
<p>And if that doesn't work, open Command Prompt (not PowerShell)
And "browse" to the <code>public</code> folder, then do:</p>
<p><code>mklink /D products_content ..\storage\app\p... | <p>Try going into the <code>public</code> folder, then do:</p> <p><code>ln -s ../storage/app/products_content products_content</code></p> <p>And if that doesn't work, open Command Prompt (not PowerShell) And "browse" to the <code>public</code> folder, then do:</p> <p><code>mklink /D products_content ..\storage\app\p... | 1122, 61874, 75151 | git-bash, laravel, symlink | <h1>Creating symlink in Laravel (windows)</h1>
<p>I'm currently having some problems with creating symlink in my Laravel project. I'm currently on <code>Windows 10 OS</code> and I'm using <code>GitBash</code>.</p>
<p>I need to create symlink from <code>storage/app/products_content</code> to <code>public/products_conte... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,556 | bash | # Creating symlink in Laravel (windows)
I'm currently having some problems with creating symlink in my Laravel project. I'm currently on `Windows 10 OS` and I'm using `GitBash`.
I need to create symlink from `storage/app/products_content` to `public/products_content`
For that, I'm using the following command:
```
l... | Try going into the `public` folder, then do:
`ln -s ../storage/app/products_content products_content`
And if that doesn't work, open Command Prompt (not PowerShell)
And "browse" to the `public` folder, then do:
`mklink /D products_content ..\storage\app\products_content`
`mklink` is the same as `ln` except that the... |
57263483 | Bash alias not saving beyond one session? | 7 | 2019-07-30 02:16:03 | <p>I'm trying to make a bash alias for traversing through a few folders, but the alias does not save after I close terminal.</p>
<p>I've already saved the alias in the .bashsrc file and have also have run the command . ~/.bashsrc.</p>
<p>Here's what I've done:</p>
<pre><code>sudo nano .bashsrc
</code></pre>
<p>Insi... | 19,679 | 11,850,020 | 2024-12-01 05:50:28 | 57,265,447 | 11 | 2019-07-30 06:22:00 | 11,498,773 | 2019-07-30 06:50:34 | https://stackoverflow.com/q/57263483 | https://stackoverflow.com/a/57265447 | <p>You should prefer setting your changes in <code>~/.bashrc</code> and <code>~/.bash_profile</code>.</p>
<pre><code>alias x='cd Documents/Photos/Family'
</code></pre>
<p>Also, remember aliases won’t be exported to subshells and while using this alias you always need to be present in the directory where <code>Documen... | <p>You should prefer setting your changes in <code>~/.bashrc</code> and <code>~/.bash_profile</code>.</p> <pre><code>alias x='cd Documents/Photos/Family' </code></pre> <p>Also, remember aliases won’t be exported to subshells and while using this alias you always need to be present in the directory where <code>Documen... | 387 | bash | <h1>Bash alias not saving beyond one session?</h1>
<p>I'm trying to make a bash alias for traversing through a few folders, but the alias does not save after I close terminal.</p>
<p>I've already saved the alias in the .bashsrc file and have also have run the command . ~/.bashsrc.</p>
<p>Here's what I've done:</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,557 | bash | # Bash alias not saving beyond one session?
I'm trying to make a bash alias for traversing through a few folders, but the alias does not save after I close terminal.
I've already saved the alias in the .bashsrc file and have also have run the command . ~/.bashsrc.
Here's what I've done:
```
sudo nano .bashsrc
```
... | You should prefer setting your changes in `~/.bashrc` and `~/.bash_profile`.
```
alias x='cd Documents/Photos/Family'
```
Also, remember aliases won’t be exported to subshells and while using this alias you always need to be present in the directory where `Documents` is present. I guess your `Documents` directory is ... |
54588898 | How to run npm scripts with WinPTY? | 7 | 2019-02-08 09:00:05 | <p>I had the known issue of <a href="https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash">python freezing in Git bash on windows</a>. Many answers on stackoverflow suggested to use <a href="https://github.com/rprichard/winpty/" rel="noreferrer">WinPTY</a>. </p>
<p>Which work... | 4,769 | 4,135,289 | 2019-04-27 10:29:35 | 55,879,587 | 11 | 2019-04-27 10:29:35 | 3,641,004 | 2019-04-27 10:29:35 | https://stackoverflow.com/q/54588898 | https://stackoverflow.com/a/55879587 | <p>I got the same problem.
Actually, in nodejs installation folder, there is npm.cmd
So what you should do to start npm using winpty is </p>
<pre><code>winpty npm.cmd install
</code></pre>
| <p>I got the same problem. Actually, in nodejs installation folder, there is npm.cmd So what you should do to start npm using winpty is </p> <pre><code>winpty npm.cmd install </code></pre> | 64, 61387, 61874 | git-bash, npm, windows | <h1>How to run npm scripts with WinPTY?</h1>
<p>I had the known issue of <a href="https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash">python freezing in Git bash on windows</a>. Many answers on stackoverflow suggested to use <a href="https://github.com/rprichard/winpty/" rel... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,558 | bash | # How to run npm scripts with WinPTY?
I had the known issue of [python freezing in Git bash on windows](https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash). Many answers on stackoverflow suggested to use [WinPTY](https://github.com/rprichard/winpty/).
Which works fine when... | I got the same problem.
Actually, in nodejs installation folder, there is npm.cmd
So what you should do to start npm using winpty is
```
winpty npm.cmd install
``` |
54434601 | PowerShell functions and performance | 7 | 2019-01-30 06:37:42 | <p>I've been wondering about the performance impact of functions in PowerShell.
Let's say we want to generate 100.000 random numbers using System.Random.</p>
<pre><code>$ranGen = New-Object System.Random
</code></pre>
<p>Executing</p>
<pre><code>for ($i = 0; $i -lt 100000; $i++) {
$void = $ranGen.Next()
}
</code... | 1,129 | 10,988,510 | 2019-01-30 10:17:12 | 54,436,133 | 11 | 2019-01-30 08:25:32 | 3,080,908 | 2019-01-30 10:17:12 | https://stackoverflow.com/q/54434601 | https://stackoverflow.com/a/54436133 | <p>a function call is <em>expensive</em>. The way to get around that is to put as much as you can IN the function. take a look at the following ... </p>
<pre><code>$ranGen = New-Object System.Random
$RepeatCount = 1e4
'Basic for loop = {0}' -f (Measure-Command -Expression {
for ($i = 0; $i -lt $RepeatCount; $i+... | <p>a function call is <em>expensive</em>. The way to get around that is to put as much as you can IN the function. take a look at the following ... </p> <pre><code>$ranGen = New-Object System.Random $RepeatCount = 1e4 'Basic for loop = {0}' -f (Measure-Command -Expression { for ($i = 0; $i -lt $RepeatCount; $i+... | 526 | powershell | <h1>PowerShell functions and performance</h1>
<p>I've been wondering about the performance impact of functions in PowerShell.
Let's say we want to generate 100.000 random numbers using System.Random.</p>
<pre><code>$ranGen = New-Object System.Random
</code></pre>
<p>Executing</p>
<pre><code>for ($i = 0; $i -lt 10000... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,559 | bash | # PowerShell functions and performance
I've been wondering about the performance impact of functions in PowerShell.
Let's say we want to generate 100.000 random numbers using System.Random.
```
$ranGen = New-Object System.Random
```
Executing
```
for ($i = 0; $i -lt 100000; $i++) {
$void = $ranGen.Next()
}
```
... | a function call is *expensive*. The way to get around that is to put as much as you can IN the function. take a look at the following ...
```
$ranGen = New-Object System.Random
$RepeatCount = 1e4
'Basic for loop = {0}' -f (Measure-Command -Expression {
for ($i = 0; $i -lt $RepeatCount; $i++) {
$Null = $ra... |
53383257 | Read-Host with multiple colors | 7 | 2018-11-19 22:00:43 | <p>In one of my powershell functions, I want to gather input from the user, but first I need to give some instructions. I'd like to print a line or two in the console with different colors.</p>
<pre><code>function myFunction(){
param(
[string]$directions = $(read-host "Please answer the questions accordin... | 17,728 | 1,038,866 | 2018-11-19 22:20:26 | 53,383,481 | 11 | 2018-11-19 22:20:26 | 5,552,766 | 2018-11-19 22:20:26 | https://stackoverflow.com/q/53383257 | https://stackoverflow.com/a/53383481 | <p>You seem to be struggling a little with the instructions in the comments so here... Unsure why you want a read host for instructions but that's cool.</p>
<pre><code>function myFunction(){
param(
[string]$directions = $(Write-Host "Please answer the questions according to your opinion`nYour answers must ... | <p>You seem to be struggling a little with the instructions in the comments so here... Unsure why you want a read host for instructions but that's cool.</p> <pre><code>function myFunction(){ param( [string]$directions = $(Write-Host "Please answer the questions according to your opinion`nYour answers must ... | 526 | powershell | <h1>Read-Host with multiple colors</h1>
<p>In one of my powershell functions, I want to gather input from the user, but first I need to give some instructions. I'd like to print a line or two in the console with different colors.</p>
<pre><code>function myFunction(){
param(
[string]$directions = $(read-ho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,560 | bash | # Read-Host with multiple colors
In one of my powershell functions, I want to gather input from the user, but first I need to give some instructions. I'd like to print a line or two in the console with different colors.
```
function myFunction(){
param(
[string]$directions = $(read-host "Please answer the... | You seem to be struggling a little with the instructions in the comments so here... Unsure why you want a read host for instructions but that's cool.
```
function myFunction(){
param(
[string]$directions = $(Write-Host "Please answer the questions according to your opinion`nYour answers must be Star Wars-b... |
52169574 | How to suppress output of command in shell script? | 7 | 2018-09-04 15:22:23 | <p>For example:</p>
<pre><code>cat a.txt
1 2
1 6
{ cat $HOME/SANITY/file.txt | grep 1 >> $HOME/SANITY/new.txt } > /dev/null
cut -d' ' -f2
</code></pre>
<p>Now i don't want the results to be shown when running the script with this code.</p>
| 9,975 | null | 2018-09-04 16:25:06 | 52,169,837 | 11 | 2018-09-04 15:36:49 | 3,560,981 | 2018-09-04 15:42:20 | https://stackoverflow.com/q/52169574 | https://stackoverflow.com/a/52169837 | <p>You can redirect the output. if you only use <code>your_command > /dev/null</code> only <code>stdout</code> will be redirected. If you want to remove the output of <code>stderr</code> as well, redirect <code>stderr</code> to <code>stdout</code> and <code>stdout</code> to <code>/dev/null</code> using:</p>
<pre><c... | <p>You can redirect the output. if you only use <code>your_command > /dev/null</code> only <code>stdout</code> will be redirected. If you want to remove the output of <code>stderr</code> as well, redirect <code>stderr</code> to <code>stdout</code> and <code>stdout</code> to <code>/dev/null</code> using:</p> <pre><c... | 34, 387, 390 | bash, shell, unix | <h1>How to suppress output of command in shell script?</h1>
<p>For example:</p>
<pre><code>cat a.txt
1 2
1 6
{ cat $HOME/SANITY/file.txt | grep 1 >> $HOME/SANITY/new.txt } > /dev/null
cut -d' ' -f2
</code></pre>
<p>Now i don't want the results to be shown when running the script with this code.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,561 | bash | # How to suppress output of command in shell script?
For example:
```
cat a.txt
1 2
1 6
{ cat $HOME/SANITY/file.txt | grep 1 >> $HOME/SANITY/new.txt } > /dev/null
cut -d' ' -f2
```
Now i don't want the results to be shown when running the script with this code. | You can redirect the output. if you only use `your_command > /dev/null` only `stdout` will be redirected. If you want to remove the output of `stderr` as well, redirect `stderr` to `stdout` and `stdout` to `/dev/null` using:
```
your_command > /dev/null 2>&1
```
`2>&1` will move `stderr` to the file descriptor of `st... |
51272394 | Why is this Bash script not inheriting all environment variables? | 7 | 2018-07-10 19:02:13 | <p>I'm trying something very straightforward:</p>
<pre><code>PEOPLE=(
"nick"
"bob"
)
export PEOPLE="$(IFS=, ; echo "${PEOPLE[*]}")"
echo "$PEOPLE" # prints 'nick,bob'
./process-people.sh
</code></pre>
<p>For some reason, <code>process-people.sh</code> isn't seeing <code>$PEOPLE</code>. As in, if I <code>echo "$P... | 10,742 | 877,069 | 2018-07-10 20:56:10 | 51,272,395 | 11 | 2018-07-10 19:02:13 | 877,069 | 2018-07-10 20:56:10 | https://stackoverflow.com/q/51272394 | https://stackoverflow.com/a/51272395 | <p>That's a neat solution you have there for <a href="https://stackoverflow.com/a/9429887/877069">joining the elements of a Bash array into a string</a>. Did you know that in Bash you <a href="https://stackoverflow.com/a/5564589/877069">cannot export array variables to the environment</a>? And if a variable is not in t... | <p>That's a neat solution you have there for <a href="https://stackoverflow.com/a/9429887/877069">joining the elements of a Bash array into a string</a>. Did you know that in Bash you <a href="https://stackoverflow.com/a/5564589/877069">cannot export array variables to the environment</a>? And if a variable is not in t... | 387 | bash | <h1>Why is this Bash script not inheriting all environment variables?</h1>
<p>I'm trying something very straightforward:</p>
<pre><code>PEOPLE=(
"nick"
"bob"
)
export PEOPLE="$(IFS=, ; echo "${PEOPLE[*]}")"
echo "$PEOPLE" # prints 'nick,bob'
./process-people.sh
</code></pre>
<p>For some reason, <code>process-peo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,562 | bash | # Why is this Bash script not inheriting all environment variables?
I'm trying something very straightforward:
```
PEOPLE=(
"nick"
"bob"
)
export PEOPLE="$(IFS=, ; echo "${PEOPLE[*]}")"
echo "$PEOPLE" # prints 'nick,bob'
./process-people.sh
```
For some reason, `process-people.sh` isn't seeing `$PEOPLE`. As in,... | That's a neat solution you have there for [joining the elements of a Bash array into a string](https://stackoverflow.com/a/9429887/877069). Did you know that in Bash you [cannot export array variables to the environment](https://stackoverflow.com/a/5564589/877069)? And if a variable is not in the environment, then the ... |
50900810 | Azure Data Factory Disable Triggers On Release | 7 | 2018-06-17 21:59:19 | <p>I've been trying to get Data Factory Deployments working through VSTS and am mostly there, but I'm getting a failure due to the triggers needing to be disabled to be overwritten. Error message below:</p>
<pre><code>Remove-AzureRmDataFactoryV2Trigger : HTTP Status Code: BadRequest
Error Code: TriggerEnabledCannotUpd... | 11,401 | 7,329,979 | 2018-06-19 05:38:08 | 50,901,654 | 11 | 2018-06-18 01:15:26 | 4,419,695 | 2018-06-19 05:38:08 | https://stackoverflow.com/q/50900810 | https://stackoverflow.com/a/50901654 | <p>Call Stop-AzureRmDataFactoryV2Trigger before removing it.</p>
<p>Iterate round all defined triggers and set to variable</p>
<pre><code>$triggersADF = Get-AzureRmDataFactoryV2Trigger -DataFactoryName <DataFactoryName> -ResourceGroupName <ResourceGroupName>
</code></pre>
<p>Disable all triggers</p>
<pr... | <p>Call Stop-AzureRmDataFactoryV2Trigger before removing it.</p> <p>Iterate round all defined triggers and set to variable</p> <pre><code>$triggersADF = Get-AzureRmDataFactoryV2Trigger -DataFactoryName <DataFactoryName> -ResourceGroupName <ResourceGroupName> </code></pre> <p>Disable all triggers</p> <pr... | 526, 81879, 112546, 116537 | azure-data-factory, azure-devops, azure-powershell, powershell | <h1>Azure Data Factory Disable Triggers On Release</h1>
<p>I've been trying to get Data Factory Deployments working through VSTS and am mostly there, but I'm getting a failure due to the triggers needing to be disabled to be overwritten. Error message below:</p>
<pre><code>Remove-AzureRmDataFactoryV2Trigger : HTTP Sta... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,563 | bash | # Azure Data Factory Disable Triggers On Release
I've been trying to get Data Factory Deployments working through VSTS and am mostly there, but I'm getting a failure due to the triggers needing to be disabled to be overwritten. Error message below:
```
Remove-AzureRmDataFactoryV2Trigger : HTTP Status Code: BadRequest... | Call Stop-AzureRmDataFactoryV2Trigger before removing it.
Iterate round all defined triggers and set to variable
```
$triggersADF = Get-AzureRmDataFactoryV2Trigger -DataFactoryName <DataFactoryName> -ResourceGroupName <ResourceGroupName>
```
Disable all triggers
```
$triggersADF | ForEach-Object { Stop-AzureRmDataF... |
45392444 | g++ does not make any file or give any output | 7 | 2017-07-29 18:06:50 | <p>I've just started using g++, downloading the latest version from the site, and I've made a simple HelloWorld program.</p>
<pre><code>#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
</code></pre>
<p>When I try to execute using the powershell wi... | 10,704 | 8,085,945 | 2021-09-26 20:10:47 | 49,237,510 | 11 | 2018-03-12 14:19:27 | 4,338,691 | 2018-03-12 18:51:38 | https://stackoverflow.com/q/45392444 | https://stackoverflow.com/a/49237510 | <p>I've had the same issue and, after running it with the traditional batch console instead of powershell, I noticed a <code>dll</code> was missing. The dll error won't pop up in the powershell command line (god only knows why).</p>
<p>In my case it was <code>libisl-15.dll</code>, but it may be different on your PC.</... | <p>I've had the same issue and, after running it with the traditional batch console instead of powershell, I noticed a <code>dll</code> was missing. The dll error won't pop up in the powershell command line (god only knows why).</p> <p>In my case it was <code>libisl-15.dll</code>, but it may be different on your PC.</... | 10, 526, 4086, 4747, 27017 | c++, g++, mingw, mingw32, powershell | <h1>g++ does not make any file or give any output</h1>
<p>I've just started using g++, downloading the latest version from the site, and I've made a simple HelloWorld program.</p>
<pre><code>#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
</code><... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,564 | bash | # g++ does not make any file or give any output
I've just started using g++, downloading the latest version from the site, and I've made a simple HelloWorld program.
```
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
```
When I try to execute using the powershel... | I've had the same issue and, after running it with the traditional batch console instead of powershell, I noticed a `dll` was missing. The dll error won't pop up in the powershell command line (god only knows why).
In my case it was `libisl-15.dll`, but it may be different on your PC.
Hope this helps someone in the w... |
48403923 | Running sub shell command in Ansible ad-hoc | 7 | 2018-01-23 14:17:58 | <p>I would like to run a sub shell command in an ad-hoc Ansible command.</p>
<p>Here is what I want to do :</p>
<pre><code>sudo ansible myservers -m shell -a "touch /var/tmp/$(uname -n)"
</code></pre>
<p>It creates the remote file but with the name of the local host, it doesn't execute the uname command on remote se... | 22,145 | 3,688,882 | 2019-12-12 15:01:51 | 48,422,209 | 11 | 2018-01-24 12:12:39 | 3,688,882 | 2018-01-24 12:12:39 | https://stackoverflow.com/q/48403923 | https://stackoverflow.com/a/48422209 | <p>I found the solution :</p>
<pre><code>sudo ansible myservers -m shell -a '/bin/bash -c "toto=`uname -n` ; touch /var/tmp/\$toto.json;"'
</code></pre>
<p>Seems that I have to start a shell to execute sub shell commands, but it works.</p>
| <p>I found the solution :</p> <pre><code>sudo ansible myservers -m shell -a '/bin/bash -c "toto=`uname -n` ; touch /var/tmp/\$toto.json;"' </code></pre> <p>Seems that I have to start a shell to execute sub shell commands, but it works.</p> | 387, 86394 | ansible, bash | <h1>Running sub shell command in Ansible ad-hoc</h1>
<p>I would like to run a sub shell command in an ad-hoc Ansible command.</p>
<p>Here is what I want to do :</p>
<pre><code>sudo ansible myservers -m shell -a "touch /var/tmp/$(uname -n)"
</code></pre>
<p>It creates the remote file but with the name of the local ho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,565 | bash | # Running sub shell command in Ansible ad-hoc
I would like to run a sub shell command in an ad-hoc Ansible command.
Here is what I want to do :
```
sudo ansible myservers -m shell -a "touch /var/tmp/$(uname -n)"
```
It creates the remote file but with the name of the local host, it doesn't execute the uname command... | I found the solution :
```
sudo ansible myservers -m shell -a '/bin/bash -c "toto=`uname -n` ; touch /var/tmp/\$toto.json;"'
```
Seems that I have to start a shell to execute sub shell commands, but it works. |
47313425 | Working with epoch time in PowerShell using UniversalTime | 7 | 2017-11-15 17:10:59 | <p>This is probably a super simple question, but I'm a bit frustrated now because I can't find exactly what I'm looking for on the internet.</p>
<p>I am trying to convert a PowerShell DateTime to Epoch time using universal time.</p>
<p>I can do either, but can't seem to find a working command to do both.</p>
<p>Here... | 11,256 | 8,543,505 | 2017-11-15 17:19:48 | 47,313,603 | 11 | 2017-11-15 17:19:48 | 7,869,690 | 2017-11-15 17:19:48 | https://stackoverflow.com/q/47313425 | https://stackoverflow.com/a/47313603 | <p>If you look at <code>Get-Help Get-Date</code> the first parameter is a <code>-Date</code> option. We can use that to our advantage by wrapping our <code>Get-Date</code> in another <code>Get-Date</code> like so:</p>
<pre><code>$epochseconds = Get-Date (Get-Date).ToUniversalTime() -UFormat %s
return $epochseconds
</... | <p>If you look at <code>Get-Help Get-Date</code> the first parameter is a <code>-Date</code> option. We can use that to our advantage by wrapping our <code>Get-Date</code> in another <code>Get-Date</code> like so:</p> <pre><code>$epochseconds = Get-Date (Get-Date).ToUniversalTime() -UFormat %s return $epochseconds </... | 526, 1263, 11716 | datetime, epoch, powershell | <h1>Working with epoch time in PowerShell using UniversalTime</h1>
<p>This is probably a super simple question, but I'm a bit frustrated now because I can't find exactly what I'm looking for on the internet.</p>
<p>I am trying to convert a PowerShell DateTime to Epoch time using universal time.</p>
<p>I can do either... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,566 | bash | # Working with epoch time in PowerShell using UniversalTime
This is probably a super simple question, but I'm a bit frustrated now because I can't find exactly what I'm looking for on the internet.
I am trying to convert a PowerShell DateTime to Epoch time using universal time.
I can do either, but can't seem to fin... | If you look at `Get-Help Get-Date` the first parameter is a `-Date` option. We can use that to our advantage by wrapping our `Get-Date` in another `Get-Date` like so:
```
$epochseconds = Get-Date (Get-Date).ToUniversalTime() -UFormat %s
return $epochseconds
``` |
47214227 | Powershell Invoke RestMethod error 415 Unsupported Media Type | 7 | 2017-11-10 01:11:51 | <p>I'm trying to execute <code>Azure Table Storage API</code> using Powershell <code>Invoke-RestMethod</code> but it returns <strong>415 error</strong>.</p>
<p>Here's Powershell code:</p>
<pre><code>$accessKey = "accesskey"
$account_name = "storage account"
$table_name = "table storage"
$date = "Fri, 10 Nov 2017 00:4... | 21,007 | 8,898,373 | 2017-11-10 08:50:21 | 47,217,328 | 11 | 2017-11-10 07:02:42 | 188,096 | 2017-11-10 07:02:42 | https://stackoverflow.com/q/47214227 | https://stackoverflow.com/a/47217328 | <p>Interesting problem. The reason you're getting this error is because you have not specified the format of response data i.e value for <code>Accept</code> request header. Because you have not specified this value, storage service treats its value as XML which is not supported for the storage service version that you ... | <p>Interesting problem. The reason you're getting this error is because you have not specified the format of response data i.e value for <code>Accept</code> request header. Because you have not specified this value, storage service treats its value as XML which is not supported for the storage service version that you ... | 526, 14158, 43391, 62065 | azure, azure-table-storage, invoke-command, powershell | <h1>Powershell Invoke RestMethod error 415 Unsupported Media Type</h1>
<p>I'm trying to execute <code>Azure Table Storage API</code> using Powershell <code>Invoke-RestMethod</code> but it returns <strong>415 error</strong>.</p>
<p>Here's Powershell code:</p>
<pre><code>$accessKey = "accesskey"
$account_name = "storag... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,567 | bash | # Powershell Invoke RestMethod error 415 Unsupported Media Type
I'm trying to execute `Azure Table Storage API` using Powershell `Invoke-RestMethod` but it returns **415 error**.
Here's Powershell code:
```
$accessKey = "accesskey"
$account_name = "storage account"
$table_name = "table storage"
$date = "Fri, 10 Nov ... | Interesting problem. The reason you're getting this error is because you have not specified the format of response data i.e value for `Accept` request header. Because you have not specified this value, storage service treats its value as XML which is not supported for the storage service version that you have specified... |
47026108 | In Powershell, how can I replace a string that contains a question mark? | 7 | 2017-10-31 00:17:37 | <p>In Powershell, how can I replace a string that contains a question mark? For example:</p>
<p><code>(Get-Content file.txt) -replace "Hello?","Hello."</code></p>
<p>The question mark seems to be interpreted as some kind special character. Is there a way to escape it? I tried using one or two backticks, but no suc... | 9,234 | 8,859,414 | 2017-10-31 00:21:18 | 47,026,133 | 11 | 2017-10-31 00:21:18 | 3,245,749 | 2017-10-31 00:21:18 | https://stackoverflow.com/q/47026108 | https://stackoverflow.com/a/47026133 | <p>The <code>-replace</code> operator uses Regular Expression pattern matching. In RegEx the question mark is a quantifier indicating the previous match should be matched zero or one times. You can escape the question mark by placing a backslash before it as such:</p>
<pre><code>(Get-Content file.txt) -replace "Hello\... | <p>The <code>-replace</code> operator uses Regular Expression pattern matching. In RegEx the question mark is a quantifier indicating the previous match should be matched zero or one times. You can escape the question mark by placing a backslash before it as such:</p> <pre><code>(Get-Content file.txt) -replace "Hello\... | 526, 2498 | powershell, replace | <h1>In Powershell, how can I replace a string that contains a question mark?</h1>
<p>In Powershell, how can I replace a string that contains a question mark? For example:</p>
<p><code>(Get-Content file.txt) -replace "Hello?","Hello."</code></p>
<p>The question mark seems to be interpreted as some kind special charac... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,568 | bash | # In Powershell, how can I replace a string that contains a question mark?
In Powershell, how can I replace a string that contains a question mark? For example:
`(Get-Content file.txt) -replace "Hello?","Hello."`
The question mark seems to be interpreted as some kind special character. Is there a way to escape it? I... | The `-replace` operator uses Regular Expression pattern matching. In RegEx the question mark is a quantifier indicating the previous match should be matched zero or one times. You can escape the question mark by placing a backslash before it as such:
```
(Get-Content file.txt) -replace "Hello\?","Hello."
``` |
45596358 | How to find if Powershell Array Contains Object of Another Array | 7 | 2017-08-09 16:43:03 | <p>I have two arrays in Powershell. Each Array contains an array of objects. These objects have two properties:</p>
<p><strong>Name</strong>: String<br>
<strong>Id</strong>: GUID</p>
<p>The first Array has 4413 objects in it and the second has 4405. The counts are irrelevant, but I only mention them to note that the co... | 20,448 | 430,920 | 2023-09-08 15:27:35 | 45,596,589 | 11 | 2017-08-09 16:57:12 | 7,890,164 | 2017-08-09 16:57:12 | https://stackoverflow.com/q/45596358 | https://stackoverflow.com/a/45596589 | <p>You can use <code>Compare-Object</code> cmdlet :</p>
<pre><code>Compare-Object -ReferenceObject $Array1 -DifferenceObject $Array2 -IncludeEqual
</code></pre>
<p><a href="https://learn.microsoft.com/fr-fr/powershell/module/Microsoft.PowerShell.Utility/Compare-Object?view=powershell-5.0" rel="noreferrer">https://learn... | <p>You can use <code>Compare-Object</code> cmdlet :</p> <pre><code>Compare-Object -ReferenceObject $Array1 -DifferenceObject $Array2 -IncludeEqual </code></pre> <p><a href="https://learn.microsoft.com/fr-fr/powershell/module/Microsoft.PowerShell.Utility/Compare-Object?view=powershell-5.0" rel="noreferrer">https://learn... | 114, 526 | arrays, powershell | <h1>How to find if Powershell Array Contains Object of Another Array</h1>
<p>I have two arrays in Powershell. Each Array contains an array of objects. These objects have two properties:</p>
<p><strong>Name</strong>: String<br>
<strong>Id</strong>: GUID</p>
<p>The first Array has 4413 objects in it and the second has 44... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,569 | bash | # How to find if Powershell Array Contains Object of Another Array
I have two arrays in Powershell. Each Array contains an array of objects. These objects have two properties:
**Name**: String
**Id**: GUID
The first Array has 4413 objects in it and the second has 4405. The counts are irrelevant, but I only mention... | You can use `Compare-Object` cmdlet :
```
Compare-Object -ReferenceObject $Array1 -DifferenceObject $Array2 -IncludeEqual
```
<https://learn.microsoft.com/fr-fr/powershell/module/Microsoft.PowerShell.Utility/Compare-Object?view=powershell-5.0>
<https://technet.microsoft.com/fr-fr/library/ee156812.aspx> |
45280858 | How to diagnose "docker: invalid reference format" when calling "docker run"? | 7 | 2017-07-24 12:37:59 | <p>I'm trying to create a shell script to run a docker container and am struggling. My script is like this:</p>
<pre><code>#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage > run.sh IMAGE NAME"
echo
echo "i.e. ./build.sh cd2:0.0.49"
exit
fi
echo $1
docker run -it --rm \
-e NODE_PATH='./src'\
-e NOD... | 29,788 | 1,775,718 | 2024-10-17 18:39:41 | 45,281,200 | 11 | 2017-07-24 12:54:12 | 7,840,440 | 2023-11-20 22:50:38 | https://stackoverflow.com/q/45280858 | https://stackoverflow.com/a/45281200 | <p>The image name should be immediately after the <code>-it</code> options.
Move the <code>-it</code> options to the end:</p>
<pre><code>docker run \
-e NODE_PATH='./src' \
-e NODE_HOST='0.0.0.0' \
-e NODE_ENV='production' \
-e DOCKER=true \
-e PORT='8080' \
-e STAGING=true \
-e SENDGRID_API_KEY='<redacted>' \
-p... | <p>The image name should be immediately after the <code>-it</code> options. Move the <code>-it</code> options to the end:</p> <pre><code>docker run \ -e NODE_PATH='./src' \ -e NODE_HOST='0.0.0.0' \ -e NODE_ENV='production' \ -e DOCKER=true \ -e PORT='8080' \ -e STAGING=true \ -e SENDGRID_API_KEY='<redacted>' \ -p... | 387, 390, 90304 | bash, docker, shell | <h1>How to diagnose "docker: invalid reference format" when calling "docker run"?</h1>
<p>I'm trying to create a shell script to run a docker container and am struggling. My script is like this:</p>
<pre><code>#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage > run.sh IMAGE NAME"
echo
echo "i.e. ./build.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,570 | bash | # How to diagnose "docker: invalid reference format" when calling "docker run"?
I'm trying to create a shell script to run a docker container and am struggling. My script is like this:
```
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage > run.sh IMAGE NAME"
echo
echo "i.e. ./build.sh cd2:0.0.49"
exit... | The image name should be immediately after the `-it` options.
Move the `-it` options to the end:
```
docker run \
-e NODE_PATH='./src' \
-e NODE_HOST='0.0.0.0' \
-e NODE_ENV='production' \
-e DOCKER=true \
-e PORT='8080' \
-e STAGING=true \
-e SENDGRID_API_KEY='<redacted>' \
-p 8080:8080 --rm -it $1
``` |
43047946 | Invoke-sqlcmd output without "quotes" and headers | 7 | 2017-03-27 13:34:31 | <p><strong>Output example:</strong></p>
<pre><code>#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"
</code></pre>
<p><strong>Requirements:</strong></p>
<p>I want a output without the 2 first lines and without the quote symbols, how can i do that... | 17,209 | 4,698,009 | 2019-03-13 12:49:11 | 43,048,303 | 11 | 2017-03-27 13:50:51 | 1,717,380 | 2017-03-28 10:43:57 | https://stackoverflow.com/q/43047946 | https://stackoverflow.com/a/43048303 | <p>This code should work:</p>
<pre><code>Invoke-Sqlcmd -ServerInstance "" -Database "" -Query "" | ConvertTo-Csv -NoTypeInformation -Delimiter "," | Select-Object -Skip 1 | % {$_ -replace '"', ""} | Out-File ("C:\test.csv") -Force -Encoding ascii
</code></pre>
<p><code>Invoke-Sqlcmd</code> produces:</p>
<pre><code>P... | <p>This code should work:</p> <pre><code>Invoke-Sqlcmd -ServerInstance "" -Database "" -Query "" | ConvertTo-Csv -NoTypeInformation -Delimiter "," | Select-Object -Skip 1 | % {$_ -replace '"', ""} | Out-File ("C:\test.csv") -Force -Encoding ascii </code></pre> <p><code>Invoke-Sqlcmd</code> produces:</p> <pre><code>P... | 526, 115585 | invoke-sqlcmd, powershell | <h1>Invoke-sqlcmd output without "quotes" and headers</h1>
<p><strong>Output example:</strong></p>
<pre><code>#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"
</code></pre>
<p><strong>Requirements:</strong></p>
<p>I want a output without the 2 f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,571 | bash | # Invoke-sqlcmd output without "quotes" and headers
**Output example:**
```
#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"
```
**Requirements:**
I want a output without the 2 first lines and without the quote symbols, how can i do that?
For the he... | This code should work:
```
Invoke-Sqlcmd -ServerInstance "" -Database "" -Query "" | ConvertTo-Csv -NoTypeInformation -Delimiter "," | Select-Object -Skip 1 | % {$_ -replace '"', ""} | Out-File ("C:\test.csv") -Force -Encoding ascii
```
`Invoke-Sqlcmd` produces:
```
PersonalNr
---
00001005
00001001
00... |
41704121 | Escape quotes and pipe in a Bash string | 7 | 2017-01-17 18:10:56 | <p>How can I escape quotes and the pipe?</p>
<pre><code>#!/bin/bash
set -x
MYCMD="VBoxManage showvminfo --machinereadable $1 \| grep \'VMState=\"poweroff\"\'"
echo "`$MYCMD`"
</code></pre>
<p>Executed command:</p>
<pre class="lang-none prettyprint-override"><code>++ VBoxManage showvminfo -... | 11,685 | 625,521 | 2023-11-21 23:26:48 | 41,704,252 | 11 | 2017-01-17 18:18:42 | 1,126,841 | 2017-01-17 18:18:42 | https://stackoverflow.com/q/41704121 | https://stackoverflow.com/a/41704252 | <p>You don't; you would need to use <code>eval</code> to embed an arbitrary pipeline in a regular string parameter.</p>
<pre><code>MYCMD="VBoxManage showvminfo --machinereadable \"$1\" | grep 'VMState=\"poweroff\"'"
eval "$MYCMD"
</code></pre>
<p>However, this is not recommended unless you are <em>certain</em> that t... | <p>You don't; you would need to use <code>eval</code> to embed an arbitrary pipeline in a regular string parameter.</p> <pre><code>MYCMD="VBoxManage showvminfo --machinereadable \"$1\" | grep 'VMState=\"poweroff\"'" eval "$MYCMD" </code></pre> <p>However, this is not recommended unless you are <em>certain</em> that t... | 387 | bash | <h1>Escape quotes and pipe in a Bash string</h1>
<p>How can I escape quotes and the pipe?</p>
<pre><code>#!/bin/bash
set -x
MYCMD="VBoxManage showvminfo --machinereadable $1 \| grep \'VMState=\"poweroff\"\'"
echo "`$MYCMD`"
</code></pre>
<p>Executed command:</p>
<pre class="lang-none prett... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,572 | bash | # Escape quotes and pipe in a Bash string
How can I escape quotes and the pipe?
```
#!/bin/bash
set -x
MYCMD="VBoxManage showvminfo --machinereadable $1 \| grep \'VMState=\"poweroff\"\'"
echo "`$MYCMD`"
```
Executed command:
```
++ VBoxManage showvminfo --machinereadable d667 '|' grep '\'\''VMState="poweroff"\'\'''... | You don't; you would need to use `eval` to embed an arbitrary pipeline in a regular string parameter.
```
MYCMD="VBoxManage showvminfo --machinereadable \"$1\" | grep 'VMState=\"poweroff\"'"
eval "$MYCMD"
```
However, this is not recommended unless you are *certain* that the value of `$1` will not cause problems. (If... |
41426931 | Replace first character in string | 7 | 2017-01-02 12:32:38 | <p>I have a CSV file where I want to replace the first character that is 0 with +46 but I can't make this work as I want to.</p>
<p>I have the following code that works, but it works on all zeroes and not only the first one:</p>
<pre><code>$csv = Import-Csv test.csv
$csv | ForEach-Object {
$_.mobile = $_.mobile.R... | 16,018 | 7,365,221 | 2017-01-03 01:03:01 | 41,427,023 | 11 | 2017-01-02 12:39:10 | 503,046 | 2017-01-02 12:39:10 | https://stackoverflow.com/q/41426931 | https://stackoverflow.com/a/41427023 | <p>This happens as <code>String.Replace()</code> will replace <a href="https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx" rel="noreferrer">all the occurrences</a>.</p>
<p>In order to only replace the first one, use regular expressions. By using the beginning of line anchor, <code>^</code>, the replaceme... | <p>This happens as <code>String.Replace()</code> will replace <a href="https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx" rel="noreferrer">all the occurrences</a>.</p> <p>In order to only replace the first one, use regular expressions. By using the beginning of line anchor, <code>^</code>, the replaceme... | 526 | powershell | <h1>Replace first character in string</h1>
<p>I have a CSV file where I want to replace the first character that is 0 with +46 but I can't make this work as I want to.</p>
<p>I have the following code that works, but it works on all zeroes and not only the first one:</p>
<pre><code>$csv = Import-Csv test.csv
$csv | F... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,573 | bash | # Replace first character in string
I have a CSV file where I want to replace the first character that is 0 with +46 but I can't make this work as I want to.
I have the following code that works, but it works on all zeroes and not only the first one:
```
$csv = Import-Csv test.csv
$csv | ForEach-Object {
$_.mobi... | This happens as `String.Replace()` will replace [all the occurrences](https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx).
In order to only replace the first one, use regular expressions. By using the beginning of line anchor, `^`, the replacement is limited to start of string. Like so,
```
$_.mobile = ... |
41085382 | How do I run a command on all files from git ls-files? | 7 | 2016-12-11 10:55:11 | <p>We have a CI script that does style checking on all Python files in the repository like this:</p>
<pre><code>#!/usr/bin/env bash
find . -name \*.py -exec pep8 --ignore=E402 --max-line-length=120 {} +
if [ $? -ne 0 ]; then
>&2 echo "=== PEP8 errors need to be solved ==="
else
echo "=== PEP8 check ok =... | 3,761 | 2,397,253 | 2023-07-24 00:35:48 | 41,085,442 | 11 | 2016-12-11 11:04:27 | 1,281,385 | 2016-12-11 20:13:04 | https://stackoverflow.com/q/41085382 | https://stackoverflow.com/a/41085442 | <pre><code>#!/usr/bin/env bash
git ls-files -z \*.py | xargs -0 pep8 --ignore=E402 --max-line-length=120
if [ $? -ne 0 ]; then
>&2 echo "=== PEP8 errors need to be solved ==="
else
echo "=== PEP8 check ok ==="
fi
pytest
</code></pre>
<p>Should do you.</p>
<p><code>git ls-files -z</code> and <code>xargs... | <pre><code>#!/usr/bin/env bash git ls-files -z \*.py | xargs -0 pep8 --ignore=E402 --max-line-length=120 if [ $? -ne 0 ]; then >&2 echo "=== PEP8 errors need to be solved ===" else echo "=== PEP8 check ok ===" fi pytest </code></pre> <p>Should do you.</p> <p><code>git ls-files -z</code> and <code>xargs... | 119, 387, 390 | bash, git, shell | <h1>How do I run a command on all files from git ls-files?</h1>
<p>We have a CI script that does style checking on all Python files in the repository like this:</p>
<pre><code>#!/usr/bin/env bash
find . -name \*.py -exec pep8 --ignore=E402 --max-line-length=120 {} +
if [ $? -ne 0 ]; then
>&2 echo "=== PEP8 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,574 | bash | # How do I run a command on all files from git ls-files?
We have a CI script that does style checking on all Python files in the repository like this:
```
#!/usr/bin/env bash
find . -name \*.py -exec pep8 --ignore=E402 --max-line-length=120 {} +
if [ $? -ne 0 ]; then
>&2 echo "=== PEP8 errors need to be solved ==... | ```
#!/usr/bin/env bash
git ls-files -z \*.py | xargs -0 pep8 --ignore=E402 --max-line-length=120
if [ $? -ne 0 ]; then
>&2 echo "=== PEP8 errors need to be solved ==="
else
echo "=== PEP8 check ok ==="
fi
pytest
```
Should do you.
`git ls-files -z` and `xargs -0` allow spaces in file names etc
from the `xar... |
39336725 | How do i print square root of user input in bash? | 7 | 2016-09-05 19:38:38 | <p>I have recently discovered 'bc' in bash, and i have been trying to use it to print out the square root of a user input. The program i wrote below runs successfully, but it only prints out '0' and not the square root of the user input.</p>
<p>Here is the code i wrote:</p>
<pre><code>#!/data/data/com.termux/files/usr/... | 25,631 | 6,797,558 | 2024-07-11 22:07:47 | 39,336,767 | 11 | 2016-09-05 19:42:19 | 3,789,550 | 2016-09-05 19:42:19 | https://stackoverflow.com/q/39336725 | https://stackoverflow.com/a/39336767 | <p>Your <code>bc</code> command and the use of command substitution is correct, the problem is you have provided the <code>echo $a</code> earlier, when it was unset. Do:</p>
<pre><code>a=$(bc <<< "scale=0; sqrt($VAR)")
echo "$a"
</code></pre>
<p>Also while expanding variables, you should use the usual notati... | <p>Your <code>bc</code> command and the use of command substitution is correct, the problem is you have provided the <code>echo $a</code> earlier, when it was unset. Do:</p> <pre><code>a=$(bc <<< "scale=0; sqrt($VAR)") echo "$a" </code></pre> <p>Also while expanding variables, you should use the usual notati... | 387 | bash | <h1>How do i print square root of user input in bash?</h1>
<p>I have recently discovered 'bc' in bash, and i have been trying to use it to print out the square root of a user input. The program i wrote below runs successfully, but it only prints out '0' and not the square root of the user input.</p>
<p>Here is the code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,575 | bash | # How do i print square root of user input in bash?
I have recently discovered 'bc' in bash, and i have been trying to use it to print out the square root of a user input. The program i wrote below runs successfully, but it only prints out '0' and not the square root of the user input.
Here is the code i wrote:
```
... | Your `bc` command and the use of command substitution is correct, the problem is you have provided the `echo $a` earlier, when it was unset. Do:
```
a=$(bc <<< "scale=0; sqrt($VAR)")
echo "$a"
```
Also while expanding variables, you should use the usual notation for variable expansion which is `$var` or `${var}`. I h... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.