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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
36851632 | Issues with newline character while using ansi-term in emacs | 6 | 2016-04-25 21:45:05 | <p>I am trying to use ansi-term in emacs (configured to tcsh shell). I see some issues with newline characters being displayed. If I try the following from the terminal (ansi-term), I get the correct output: </p>
<pre><code>myterm > echo "Line1"; echo "Line2"; echo "Line3";
Line1
Line2
Line3
myterm >
</code>... | 1,423 | 990,772 | 2016-05-09 14:11:50 | 37,038,271 | 15 | 2016-05-04 21:23:02 | 6,170,930 | 2016-05-09 14:11:50 | https://stackoverflow.com/q/36851632 | https://stackoverflow.com/a/37038271 | <p>If you set <code>stty onlcr</code> in your script, you will get the behaviour you require.<br>Translating the command into english one might say:<br> <strong>s</strong>et the <strong>tty</strong> to <strong>o</strong>utput <strong>n</strong>ew<strong>l</strong>ine as <strong>c</strong>arriage-<strong>r</strong>eturn... | <p>If you set <code>stty onlcr</code> in your script, you will get the behaviour you require.<br>Translating the command into english one might say:<br> <strong>s</strong>et the <strong>tty</strong> to <strong>o</strong>utput <strong>n</strong>ew<strong>l</strong>ine as <strong>c</strong>arriage-<strong>r</strong>eturn... | 371, 390, 391, 8599, 84237 | ansi-term, emacs, shell, tcsh, terminal | <h1>Issues with newline character while using ansi-term in emacs</h1>
<p>I am trying to use ansi-term in emacs (configured to tcsh shell). I see some issues with newline characters being displayed. If I try the following from the terminal (ansi-term), I get the correct output: </p>
<pre><code>myterm > echo "Line1";... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,466 | bash | # Issues with newline character while using ansi-term in emacs
I am trying to use ansi-term in emacs (configured to tcsh shell). I see some issues with newline characters being displayed. If I try the following from the terminal (ansi-term), I get the correct output:
```
myterm > echo "Line1"; echo "Line2"; echo "Lin... | If you set `stty onlcr` in your script, you will get the behaviour you require.
Translating the command into english one might say:
**s**et the **tty** to **o**utput **n**ew**l**ine as **c**arriage-**r**eturn and newline.
This is a workaround of course, because this option should be set by default. I can see from... |
35405266 | Combine 2 PowerShell arrays | 6 | 2016-02-15 09:10:05 | <p>I'm trying to figure out how to combine 2 arrays as explained <a href="https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/27/powertip-add-two-powershell-arrays-together/" rel="nofollow">here</a> by Microsoft.</p>
<pre><code>$Source = 'S:\Test\Out_Test\Departments'
$Array = Get-ChildItem $Source -Recurse
$... | 6,594 | 2,304,170 | 2023-02-24 14:47:00 | 35,405,406 | 15 | 2016-02-15 09:17:14 | 712,649 | 2016-02-15 09:17:14 | https://stackoverflow.com/q/35405266 | https://stackoverflow.com/a/35405406 | <p>In PowerShell, the <em>left-hand side</em> operand determines the operator overload used, and the <em>right-hand side</em> gets converted to a type that satisfies the operation.</p>
<p>That's why you can observe that </p>
<p><code>[string] + [array of strings]</code> results in a <code>[string]</code> (Count = 1)<... | <p>In PowerShell, the <em>left-hand side</em> operand determines the operator overload used, and the <em>right-hand side</em> gets converted to a type that satisfies the operation.</p> <p>That's why you can observe that </p> <p><code>[string] + [array of strings]</code> results in a <code>[string]</code> (Count = 1)<... | 114, 526 | arrays, powershell | <h1>Combine 2 PowerShell arrays</h1>
<p>I'm trying to figure out how to combine 2 arrays as explained <a href="https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/27/powertip-add-two-powershell-arrays-together/" rel="nofollow">here</a> by Microsoft.</p>
<pre><code>$Source = 'S:\Test\Out_Test\Departments'
$Arra... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,467 | bash | # Combine 2 PowerShell arrays
I'm trying to figure out how to combine 2 arrays as explained [here](https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/27/powertip-add-two-powershell-arrays-together/) by Microsoft.
```
$Source = 'S:\Test\Out_Test\Departments'
$Array = Get-ChildItem $Source -Recurse
$Array.Ful... | In PowerShell, the *left-hand side* operand determines the operator overload used, and the *right-hand side* gets converted to a type that satisfies the operation.
That's why you can observe that
`[string] + [array of strings]` results in a `[string]` (Count = 1)
`[array of strings] + [string]` results in an `[arra... |
33349124 | restrict pidof to own processes | 6 | 2015-10-26 15:09:19 | <p>In bash,</p>
<pre><code>pidof unison
</code></pre>
<p>will list me unison processes of all users. However I am only interested in instances started under my uid.</p>
<p>How can I achieve this?</p>
<p>What I want to do:
I'm periodically syncing several accounts on several machines using unison. However, I want th... | 2,665 | 1,285,585 | 2015-10-26 15:18:25 | 33,349,253 | 15 | 2015-10-26 15:15:11 | 4,687,135 | 2015-10-26 15:15:11 | https://stackoverflow.com/q/33349124 | https://stackoverflow.com/a/33349253 | <p>You could use <code>pgrep</code> instead, like</p>
<pre><code>pgrep -u <userid> unison
</code></pre>
<p>which will return a list of pids of unison processes that have the euid of the given user.</p>
| <p>You could use <code>pgrep</code> instead, like</p> <pre><code>pgrep -u <userid> unison </code></pre> <p>which will return a list of pids of unison processes that have the euid of the given user.</p> | 387, 3300, 5910 | bash, pid, process | <h1>restrict pidof to own processes</h1>
<p>In bash,</p>
<pre><code>pidof unison
</code></pre>
<p>will list me unison processes of all users. However I am only interested in instances started under my uid.</p>
<p>How can I achieve this?</p>
<p>What I want to do:
I'm periodically syncing several accounts on several ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,468 | bash | # restrict pidof to own processes
In bash,
```
pidof unison
```
will list me unison processes of all users. However I am only interested in instances started under my uid.
How can I achieve this?
What I want to do:
I'm periodically syncing several accounts on several machines using unison. However, I want the sync... | You could use `pgrep` instead, like
```
pgrep -u <userid> unison
```
which will return a list of pids of unison processes that have the euid of the given user. |
32205052 | bash cat all files that contains a certain string in file name | 6 | 2015-08-25 13:15:34 | <p>In <code>bash</code>, how would you <code>cat</code> all files in a directory that contains a certain string in its filename. For example I have files named:</p>
<pre><code>test001.csv
test002.csv
test003.csv
result001.csv
result002.csv
</code></pre>
<p>I want to <code>cat</code> all <code>.csv</code> that contain... | 14,297 | 4,291,805 | 2015-08-25 15:58:34 | 32,205,274 | 15 | 2015-08-25 13:25:37 | 2,768,341 | 2015-08-25 13:25:37 | https://stackoverflow.com/q/32205052 | https://stackoverflow.com/a/32205274 | <p>Just:</p>
<pre><code>cat *test*.csv
cat *result*.csv
</code></pre>
<p>For all files with <code>test</code> (or in case of the second one <code>result</code>) in their name.</p>
| <p>Just:</p> <pre><code>cat *test*.csv cat *result*.csv </code></pre> <p>For all files with <code>test</code> (or in case of the second one <code>result</code>) in their name.</p> | 387, 390, 1231, 22820 | bash, cat, command-line, shell | <h1>bash cat all files that contains a certain string in file name</h1>
<p>In <code>bash</code>, how would you <code>cat</code> all files in a directory that contains a certain string in its filename. For example I have files named:</p>
<pre><code>test001.csv
test002.csv
test003.csv
result001.csv
result002.csv
</code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,469 | bash | # bash cat all files that contains a certain string in file name
In `bash`, how would you `cat` all files in a directory that contains a certain string in its filename. For example I have files named:
```
test001.csv
test002.csv
test003.csv
result001.csv
result002.csv
```
I want to `cat` all `.csv` that contains the... | Just:
```
cat *test*.csv
cat *result*.csv
```
For all files with `test` (or in case of the second one `result`) in their name. |
30614156 | unix awk column equal to a variable | 6 | 2015-06-03 08:00:00 | <p>I want to print the lines that with two columns equal to a variable, for example, input:</p>
<pre><code>2607s1 NC_000067.6 95.92 49 1 1 3 50 1e-14 84.2
2607s1 NC_000067.6 97.73 44 1 0 7 50 4e-14 84.2
2607s1 NC_000067.6 97.67 43 1 0 8 50 1e-13 75.0
</code></pre>
<p>and variabl... | 18,650 | 4,290,753 | 2015-06-04 05:03:54 | 30,614,299 | 15 | 2015-06-03 08:07:18 | 3,150,943 | 2015-06-04 05:03:54 | https://stackoverflow.com/q/30614156 | https://stackoverflow.com/a/30614299 | <p>You are passing the shell variables to the awk command using a wrong method. It should be like</p>
<pre><code>awk -v a="$a" -v b="$b" '$1==a && $10 == b'
</code></pre>
<p><strong>What it does</strong></p>
<ul>
<li><p><code>-v a="$a"</code> creates an awk variable <code>a</code> and assigns the value of s... | <p>You are passing the shell variables to the awk command using a wrong method. It should be like</p> <pre><code>awk -v a="$a" -v b="$b" '$1==a && $10 == b' </code></pre> <p><strong>What it does</strong></p> <ul> <li><p><code>-v a="$a"</code> creates an awk variable <code>a</code> and assigns the value of s... | 34, 276, 387, 990, 17310 | awk, bash, unix, variables, while-loop | <h1>unix awk column equal to a variable</h1>
<p>I want to print the lines that with two columns equal to a variable, for example, input:</p>
<pre><code>2607s1 NC_000067.6 95.92 49 1 1 3 50 1e-14 84.2
2607s1 NC_000067.6 97.73 44 1 0 7 50 4e-14 84.2
2607s1 NC_000067.6 97.67 43 1 0 8 5... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,470 | bash | # unix awk column equal to a variable
I want to print the lines that with two columns equal to a variable, for example, input:
```
2607s1 NC_000067.6 95.92 49 1 1 3 50 1e-14 84.2
2607s1 NC_000067.6 97.73 44 1 0 7 50 4e-14 84.2
2607s1 NC_000067.6 97.67 43 1 0 8 50 1e-13 75.0
```
... | You are passing the shell variables to the awk command using a wrong method. It should be like
```
awk -v a="$a" -v b="$b" '$1==a && $10 == b'
```
**What it does**
- `-v a="$a"` creates an awk variable `a` and assigns the value of shell variable `$a` to it.
- `-v b="$b"` Creates awk variable `b`.
**OR**
```
awk '$... |
29813239 | "Name or service not knownname" using SSH from script | 6 | 2015-04-23 03:39:56 | <p>Cannot connect to host by SSH.</p>
<p>I am using following shell script to use <code>ssh</code>.</p>
<pre><code>host_list="c15-0330-14.ad.mtu.edu"
ssh "$host_list"
</code></pre>
<p>But It always says <code>: Name or service not knownname c15-0330-14.ad.mtu.edu</code>.</p>
<p>I tried <code>ssh c15-0330-14.ad.mtu.... | 6,340 | 4,789,316 | 2018-01-05 18:44:17 | 29,813,398 | 15 | 2015-04-23 03:59:47 | 1,126,841 | 2015-04-23 04:09:05 | https://stackoverflow.com/q/29813239 | https://stackoverflow.com/a/29813398 | <p>The error message <em>should</em> be</p>
<pre><code>ssh: Could not resolve hostname c15-0330-14.ad.mtu.edu: Name or service not known
</code></pre>
<p>except the DOS line endings in your script cause an extra carriage return to be stored at the end of the value of <code>host_list</code>. This carriage return, when... | <p>The error message <em>should</em> be</p> <pre><code>ssh: Could not resolve hostname c15-0330-14.ad.mtu.edu: Name or service not known </code></pre> <p>except the DOS line endings in your script cause an extra carriage return to be stored at the end of the value of <code>host_list</code>. This carriage return, when... | 58, 386, 390 | linux, shell, ssh | <h1>"Name or service not knownname" using SSH from script</h1>
<p>Cannot connect to host by SSH.</p>
<p>I am using following shell script to use <code>ssh</code>.</p>
<pre><code>host_list="c15-0330-14.ad.mtu.edu"
ssh "$host_list"
</code></pre>
<p>But It always says <code>: Name or service not knownname c15-0330-14.a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,471 | bash | # "Name or service not knownname" using SSH from script
Cannot connect to host by SSH.
I am using following shell script to use `ssh`.
```
host_list="c15-0330-14.ad.mtu.edu"
ssh "$host_list"
```
But It always says `: Name or service not knownname c15-0330-14.ad.mtu.edu`.
I tried `ssh c15-0330-14.ad.mtu.edu`. It wo... | The error message *should* be
```
ssh: Could not resolve hostname c15-0330-14.ad.mtu.edu: Name or service not known
```
except the DOS line endings in your script cause an extra carriage return to be stored at the end of the value of `host_list`. This carriage return, when printed as part of the error message, causes... |
26941644 | PowerShell function parameters syntax | 6 | 2014-11-15 01:50:48 | <p>Why do the <a href="http://technet.microsoft.com/en-us/library/hh849877.aspx" rel="nofollow noreferrer">Write-Host</a> outside of the function work different than inside of the function?</p>
<p>It seems like somehow the parameters variables are changing from what I declared it to be...</p>
<pre class="lang-sh pretty... | 10,251 | 1,810,969 | 2022-01-15 21:28:40 | 26,941,685 | 15 | 2014-11-15 01:57:43 | 3,905,079 | 2019-03-22 21:23:26 | https://stackoverflow.com/q/26941644 | https://stackoverflow.com/a/26941685 | <p>Don't call functions or cmdlets in PowerShell with parentheses and commas (only do this in method calls)!</p>
<p>When you call <code>a($svr, $usr)</code> you're passing an array with the two values as the single value of the first parameter. It's equivalent to calling it like <code>a -svr $svr,$usr</code> which mea... | <p>Don't call functions or cmdlets in PowerShell with parentheses and commas (only do this in method calls)!</p> <p>When you call <code>a($svr, $usr)</code> you're passing an array with the two values as the single value of the first parameter. It's equivalent to calling it like <code>a -svr $svr,$usr</code> which mea... | 526, 73157 | powershell, powershell-3.0 | <h1>PowerShell function parameters syntax</h1>
<p>Why do the <a href="http://technet.microsoft.com/en-us/library/hh849877.aspx" rel="nofollow noreferrer">Write-Host</a> outside of the function work different than inside of the function?</p>
<p>It seems like somehow the parameters variables are changing from what I decl... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,472 | bash | # PowerShell function parameters syntax
Why do the [Write-Host](http://technet.microsoft.com/en-us/library/hh849877.aspx) outside of the function work different than inside of the function?
It seems like somehow the parameters variables are changing from what I declared it to be...
```
function a([string]$svr, [stri... | Don't call functions or cmdlets in PowerShell with parentheses and commas (only do this in method calls)!
When you call `a($svr, $usr)` you're passing an array with the two values as the single value of the first parameter. It's equivalent to calling it like `a -svr $svr,$usr` which means the `$usr` parameter is not s... |
26545686 | Why does '$true -eq "string"' returns $true? | 6 | 2014-10-24 09:57:11 | <p>In powerShell you compare a boolean with a string with the "-eq" operator it will always return the same boolean as I used to compare.</p>
<p>E.g. </p>
<pre><code>$shouldBeFalse = $true -eq "hello"
$shouldBeTrue = $false -eq "hello"
</code></pre>
<p>The variable $shouldBeFalse is $true.
The variable $shouldBe... | 18,986 | 2,964,949 | 2019-05-23 06:31:09 | 26,546,992 | 15 | 2014-10-24 11:27:38 | 3,829,407 | 2014-10-24 11:27:38 | https://stackoverflow.com/q/26545686 | https://stackoverflow.com/a/26546992 | <p>PowerShell will always evaluate using the type of the left-side argument. Since you have a boolean on the left PowerShell will try and cast "Hello" as a boolean for the purpose of evaluating with <code>-eq</code>.</p>
<p>So in your case <code>"hello"</code> is converted to a boolean value <code>[bool]"hello"</code>... | <p>PowerShell will always evaluate using the type of the left-side argument. Since you have a boolean on the left PowerShell will try and cast "Hello" as a boolean for the purpose of evaluating with <code>-eq</code>.</p> <p>So in your case <code>"hello"</code> is converted to a boolean value <code>[bool]"hello"</code>... | 139, 526, 2848, 2936, 5678 | boolean, compare, equals, powershell, string | <h1>Why does '$true -eq "string"' returns $true?</h1>
<p>In powerShell you compare a boolean with a string with the "-eq" operator it will always return the same boolean as I used to compare.</p>
<p>E.g. </p>
<pre><code>$shouldBeFalse = $true -eq "hello"
$shouldBeTrue = $false -eq "hello"
</code></pre>
<p>The va... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,473 | bash | # Why does '$true -eq "string"' returns $true?
In powerShell you compare a boolean with a string with the "-eq" operator it will always return the same boolean as I used to compare.
E.g.
```
$shouldBeFalse = $true -eq "hello"
$shouldBeTrue = $false -eq "hello"
```
The variable $shouldBeFalse is $true.
The variable ... | PowerShell will always evaluate using the type of the left-side argument. Since you have a boolean on the left PowerShell will try and cast "Hello" as a boolean for the purpose of evaluating with `-eq`.
So in your case `"hello"` is converted to a boolean value `[bool]"hello"` which would evaluate to True since it is n... |
24058921 | How to recursively delete multiple files with different extensions? | 6 | 2014-06-05 11:23:46 | <p>I am trying to write a command to remove recursively several files with different extensions (*.extension1, *.extension2 etc) from the current directory and all its related sub-directories.</p>
<p>So far I got this command from <a href="https://askubuntu.com/questions/377438/how-can-i-recursively-delete-all-files-o... | 11,086 | 3,565,491 | 2021-08-15 13:20:34 | 24,059,207 | 15 | 2014-06-05 11:38:01 | 3,150,853 | 2014-06-05 11:47:35 | https://stackoverflow.com/q/24058921 | https://stackoverflow.com/a/24059207 | <pre><code>find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete
</code></pre>
<p>find Documents ( -name "<em>.py" -o -name "</em>.html" ) -exec file {} \;</p>
<p>OR</p>
<pre><code>find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete
</code></pre>
| <pre><code>find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete </code></pre> <p>find Documents ( -name "<em>.py" -o -name "</em>.html" ) -exec file {} \;</p> <p>OR</p> <pre><code>find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete </code></pre> | 58, 387, 10193, 37510 | bash, delete-file, find, linux | <h1>How to recursively delete multiple files with different extensions?</h1>
<p>I am trying to write a command to remove recursively several files with different extensions (*.extension1, *.extension2 etc) from the current directory and all its related sub-directories.</p>
<p>So far I got this command from <a href="ht... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,474 | bash | # How to recursively delete multiple files with different extensions?
I am trying to write a command to remove recursively several files with different extensions (*.extension1, *.extension2 etc) from the current directory and all its related sub-directories.
So far I got this command from [another post](https://asku... | ```
find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete
```
find Documents ( -name "*.py" -o -name "*.html" ) -exec file {} \;
OR
```
find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete
``` |
23681705 | Apply XOR operation to an array of bytes? | 6 | 2014-05-15 14:48:41 | <p>I have an array of bytes :</p>
<pre><code>$bytes = [System.IO.File]::ReadAllBytes($myFile)
</code></pre>
<p>I would like to perform a XOR operation on each byte inside this array, like this (in python)</p>
<pre><code>bytes[i] ^= 0x6A // python-style
</code></pre>
<p>I tried</p>
<pre><code>for($i=0; $i -lt $byt... | 16,323 | 2,997,563 | 2014-05-15 15:08:43 | 23,682,176 | 15 | 2014-05-15 15:08:43 | 153,982 | 2014-05-15 15:08:43 | https://stackoverflow.com/q/23681705 | https://stackoverflow.com/a/23682176 | <p><code>-xor</code> is a logical operator returning True or False. Perhaps you want to use bitwise exclusive OR'ing via <code>-bxor</code>?</p>
<pre><code>for($i=0; $i -lt $bytes.count ; $i++)
{
$bytes[$i] = $bytes[$i] -bxor 0x6A
}
</code></pre>
| <p><code>-xor</code> is a logical operator returning True or False. Perhaps you want to use bitwise exclusive OR'ing via <code>-bxor</code>?</p> <pre><code>for($i=0; $i -lt $bytes.count ; $i++) { $bytes[$i] = $bytes[$i] -bxor 0x6A } </code></pre> | 526 | powershell | <h1>Apply XOR operation to an array of bytes?</h1>
<p>I have an array of bytes :</p>
<pre><code>$bytes = [System.IO.File]::ReadAllBytes($myFile)
</code></pre>
<p>I would like to perform a XOR operation on each byte inside this array, like this (in python)</p>
<pre><code>bytes[i] ^= 0x6A // python-style
</code></pre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,475 | bash | # Apply XOR operation to an array of bytes?
I have an array of bytes :
```
$bytes = [System.IO.File]::ReadAllBytes($myFile)
```
I would like to perform a XOR operation on each byte inside this array, like this (in python)
```
bytes[i] ^= 0x6A // python-style
```
I tried
```
for($i=0; $i -lt $bytes.count ; $i++)
... | `-xor` is a logical operator returning True or False. Perhaps you want to use bitwise exclusive OR'ing via `-bxor`?
```
for($i=0; $i -lt $bytes.count ; $i++)
{
$bytes[$i] = $bytes[$i] -bxor 0x6A
}
``` |
23332942 | incrementing an environmental variable | 6 | 2014-04-28 05:13:42 | <p>I need to increment an environmental variable by these steps:</p>
<pre><code>envar=1
export envar
sh script_incrementation
echo $envar
</code></pre>
<p>where script_incrementation contains something like this:</p>
<pre><code>#! /bin/sh
envar=$[envar+1] #I've tried also other methods of incrementation
export envar... | 6,732 | null | 2020-01-09 18:47:13 | 23,333,059 | 15 | 2014-04-28 05:24:40 | 391,161 | 2020-01-09 18:47:13 | https://stackoverflow.com/q/23332942 | https://stackoverflow.com/a/23333059 | <p>A shell script executes in its own shell, so you cannot affect the outer shell unless you source it. See <a href="https://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell">this question</a> for details of that discussion.</p>
<p>Consider the following script, whic... | <p>A shell script executes in its own shell, so you cannot affect the outer shell unless you source it. See <a href="https://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell">this question</a> for details of that discussion.</p> <p>Consider the following script, whic... | 58, 387, 390, 10327 | bash, linux, sh, shell | <h1>incrementing an environmental variable</h1>
<p>I need to increment an environmental variable by these steps:</p>
<pre><code>envar=1
export envar
sh script_incrementation
echo $envar
</code></pre>
<p>where script_incrementation contains something like this:</p>
<pre><code>#! /bin/sh
envar=$[envar+1] #I've tried a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,476 | bash | # incrementing an environmental variable
I need to increment an environmental variable by these steps:
```
envar=1
export envar
sh script_incrementation
echo $envar
```
where script_incrementation contains something like this:
```
#! /bin/sh
envar=$[envar+1] #I've tried also other methods of incrementation
export e... | A shell script executes in its own shell, so you cannot affect the outer shell unless you source it. See [this question](https://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell) for details of that discussion.
Consider the following script, which I will call `Foo.sh... |
21600700 | How to count the number of words in a string in Bash | 6 | 2014-02-06 10:49:03 | <p>I have the following string which contains words separated by spaces</p>
<pre><code>str="word1 word2 word3"
</code></pre>
<p>How to count the number of words?</p>
<p>I do not want to use a for loop with counter. I want to do it in one command.</p>
| 6,738 | 1,003,575 | 2014-03-11 04:08:32 | 21,600,790 | 15 | 2014-02-06 10:52:21 | 1,983,854 | 2014-02-06 10:52:21 | https://stackoverflow.com/q/21600700 | https://stackoverflow.com/a/21600790 | <p>You can use <code>wc</code>:</p>
<pre><code>$ wc -w <<< "$str"
3
</code></pre>
| <p>You can use <code>wc</code>:</p> <pre><code>$ wc -w <<< "$str" 3 </code></pre> | 58, 387, 390 | bash, linux, shell | <h1>How to count the number of words in a string in Bash</h1>
<p>I have the following string which contains words separated by spaces</p>
<pre><code>str="word1 word2 word3"
</code></pre>
<p>How to count the number of words?</p>
<p>I do not want to use a for loop with counter. I want to do it in one command.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,477 | bash | # How to count the number of words in a string in Bash
I have the following string which contains words separated by spaces
```
str="word1 word2 word3"
```
How to count the number of words?
I do not want to use a for loop with counter. I want to do it in one command. | You can use `wc`:
```
$ wc -w <<< "$str"
3
``` |
20635125 | Return new line by grep if not match found | 6 | 2013-12-17 13:12:30 | <p>I would like to modify this code to return an empty line if no match is found by grep:</p>
<pre><code>while read vl ; do grep "^$vl" Table_S4.tab ; done < 1
</code></pre>
| 4,654 | 2,604,088 | 2013-12-17 15:12:06 | 20,635,169 | 15 | 2013-12-17 13:14:48 | 1,126,841 | 2013-12-17 13:14:48 | https://stackoverflow.com/q/20635125 | https://stackoverflow.com/a/20635169 | <pre><code>while read vl; do
grep "^$vl" Table_S4.tab || printf "\n"
done < 1
</code></pre>
<p>If <code>grep</code> doesn't find a match, the <code>printf</code> command will be run and output an empty line.</p>
| <pre><code>while read vl; do grep "^$vl" Table_S4.tab || printf "\n" done < 1 </code></pre> <p>If <code>grep</code> doesn't find a match, the <code>printf</code> command will be run and output an empty line.</p> | 387, 390, 1271 | bash, grep, shell | <h1>Return new line by grep if not match found</h1>
<p>I would like to modify this code to return an empty line if no match is found by grep:</p>
<pre><code>while read vl ; do grep "^$vl" Table_S4.tab ; done < 1
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,478 | bash | # Return new line by grep if not match found
I would like to modify this code to return an empty line if no match is found by grep:
```
while read vl ; do grep "^$vl" Table_S4.tab ; done < 1
``` | ```
while read vl; do
grep "^$vl" Table_S4.tab || printf "\n"
done < 1
```
If `grep` doesn't find a match, the `printf` command will be run and output an empty line. |
20577191 | Format all XML files in a directory and save them in a subdirectory | 6 | 2013-12-13 22:35:56 | <p>I'm trying to write a script that will look through a directory, find all the XML files, run them through <code>xmllint</code>, and save the formatted results to a file of the same name in a subdirectory called <code>formatted</code>. Here's the script I have so far:</p>
<pre><code>find . -maxdepth 1 -type f -iname... | 6,678 | 791,664 | 2013-12-13 23:02:10 | 20,577,314 | 15 | 2013-12-13 22:47:42 | 1,258,041 | 2013-12-13 23:00:09 | https://stackoverflow.com/q/20577191 | https://stackoverflow.com/a/20577314 | <p>The file named <code>{}</code> that you see should probably contain <em>all</em> of the formatted files together. The reason for this is that the redirection that you are using is not actually a part of the command that <code>xargs</code> sees. The redirection is interpreted by the shell, so what it does is run</p>
... | <p>The file named <code>{}</code> that you see should probably contain <em>all</em> of the formatted files together. The reason for this is that the redirection that you are using is not actually a part of the command that <code>xargs</code> sees. The redirection is interpreted by the shell, so what it does is run</p> ... | 387, 10193, 10326, 70156 | bash, find, xargs, xmllint | <h1>Format all XML files in a directory and save them in a subdirectory</h1>
<p>I'm trying to write a script that will look through a directory, find all the XML files, run them through <code>xmllint</code>, and save the formatted results to a file of the same name in a subdirectory called <code>formatted</code>. Here'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,479 | bash | # Format all XML files in a directory and save them in a subdirectory
I'm trying to write a script that will look through a directory, find all the XML files, run them through `xmllint`, and save the formatted results to a file of the same name in a subdirectory called `formatted`. Here's the script I have so far:
``... | The file named `{}` that you see should probably contain *all* of the formatted files together. The reason for this is that the redirection that you are using is not actually a part of the command that `xargs` sees. The redirection is interpreted by the shell, so what it does is run
```
find . -maxdepth 1 -type f -ina... |
20478516 | How to detect when networking initialized in /etc/init.d script? | 6 | 2013-12-09 19:00:03 | <p>I have an /etc/init.d/ script that starts on boot and requires networking to be in place. I have the rc start set to 99, so it's the last thing that loads, but the networking doesn't load immediately and I'm currently having to rely on a 30 second sleep command to wait for network loading.</p>
<p>The OS is Ubuntu ... | 18,706 | 1,571,994 | 2013-12-18 14:44:22 | 20,532,666 | 15 | 2013-12-12 00:19:53 | 171,318 | 2013-12-12 00:47:24 | https://stackoverflow.com/q/20478516 | https://stackoverflow.com/a/20532666 | <p><strong>The basic Debian way</strong>:</p>
<p>Basically <code>/etc/network/if-up.d</code> is the place for such scripts. These scripts are called when an interface get's up on a Debian system or derivate - like Ubuntu. Here you can find a list of environment variables passed to these scripts. Using these variables ... | <p><strong>The basic Debian way</strong>:</p> <p>Basically <code>/etc/network/if-up.d</code> is the place for such scripts. These scripts are called when an interface get's up on a Debian system or derivate - like Ubuntu. Here you can find a list of environment variables passed to these scripts. Using these variables ... | 387, 390, 549, 9079, 10789 | bash, init.d, rc, shell, ubuntu | <h1>How to detect when networking initialized in /etc/init.d script?</h1>
<p>I have an /etc/init.d/ script that starts on boot and requires networking to be in place. I have the rc start set to 99, so it's the last thing that loads, but the networking doesn't load immediately and I'm currently having to rely on a 30 s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,480 | bash | # How to detect when networking initialized in /etc/init.d script?
I have an /etc/init.d/ script that starts on boot and requires networking to be in place. I have the rc start set to 99, so it's the last thing that loads, but the networking doesn't load immediately and I'm currently having to rely on a 30 second slee... | **The basic Debian way**:
Basically `/etc/network/if-up.d` is the place for such scripts. These scripts are called when an interface get's up on a Debian system or derivate - like Ubuntu. Here you can find a list of environment variables passed to these scripts. Using these variables you can decide which interface get... |
20235365 | how to zip particular folders in linux using shell | 6 | 2013-11-27 06:24:00 | <p>Let say we have a directory structure like: </p>
<pre><code>A
|---B
| |---C
| | |--f1.txt
| |
| |---D
| | |--f2.txt
|
|---E
| |---f3.txt
| |
|
|---F
| |---f4.txt
</code></pre>
<p>Now how to zip a file BE.zip excluding F directory, i.e when I unzip BE.zip the result should be:</p>
<pre><code>|-... | 5,859 | 2,410,148 | 2014-09-29 08:36:04 | 20,235,464 | 15 | 2013-11-27 06:30:17 | 2,410,148 | 2013-11-27 06:30:17 | https://stackoverflow.com/q/20235365 | https://stackoverflow.com/a/20235464 | <p>ok got it..</p>
<pre><code>zip -r BE.zip B/ E/
</code></pre>
| <p>ok got it..</p> <pre><code>zip -r BE.zip B/ E/ </code></pre> | 58, 390, 881, 10327 | linux, sh, shell, zip | <h1>how to zip particular folders in linux using shell</h1>
<p>Let say we have a directory structure like: </p>
<pre><code>A
|---B
| |---C
| | |--f1.txt
| |
| |---D
| | |--f2.txt
|
|---E
| |---f3.txt
| |
|
|---F
| |---f4.txt
</code></pre>
<p>Now how to zip a file BE.zip excluding F directory, i.e ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,481 | bash | # how to zip particular folders in linux using shell
Let say we have a directory structure like:
```
A
|---B
| |---C
| | |--f1.txt
| |
| |---D
| | |--f2.txt
|
|---E
| |---f3.txt
| |
|
|---F
| |---f4.txt
```
Now how to zip a file BE.zip excluding F directory, i.e when I unzip BE.zip the result sho... | ok got it..
```
zip -r BE.zip B/ E/
``` |
19528455 | Running multiple shell commands with wildcards | 6 | 2013-10-22 21:11:48 | <p>Is there an <em>easy</em> way to do the following in Scala (or Java). I want to run command line commands from a Scala process, for example:</p>
<pre><code> cd test && javac *.java
</code></pre>
<p>as a dynamically generated shell script. The <code>javac *.java</code> should
happen in the directory <code>t... | 2,920 | 667,786 | 2017-10-16 00:46:10 | 19,529,480 | 15 | 2013-10-22 22:24:49 | 247,533 | 2013-10-22 22:24:49 | https://stackoverflow.com/q/19528455 | https://stackoverflow.com/a/19529480 | <p>For what you want, you should enter the string as a command-line argument to <code>bash</code>. (That is, <code>Process(Seq("bash","-c","cd test && javac *.java")).!</code>) The reason is that there is no virtual shell into which you're entering commands that will change state like <code>cd</code>. You ha... | <p>For what you want, you should enter the string as a command-line argument to <code>bash</code>. (That is, <code>Process(Seq("bash","-c","cd test && javac *.java")).!</code>) The reason is that there is no virtual shell into which you're entering commands that will change state like <code>cd</code>. You ha... | 390, 3143 | scala, shell | <h1>Running multiple shell commands with wildcards</h1>
<p>Is there an <em>easy</em> way to do the following in Scala (or Java). I want to run command line commands from a Scala process, for example:</p>
<pre><code> cd test && javac *.java
</code></pre>
<p>as a dynamically generated shell script. The <code>ja... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,482 | bash | # Running multiple shell commands with wildcards
Is there an *easy* way to do the following in Scala (or Java). I want to run command line commands from a Scala process, for example:
```
cd test && javac *.java
```
as a dynamically generated shell script. The `javac *.java` should
happen in the directory `test`. Th... | For what you want, you should enter the string as a command-line argument to `bash`. (That is, `Process(Seq("bash","-c","cd test && javac *.java")).!`) The reason is that there is no virtual shell into which you're entering commands that will change state like `cd`. You have to create one explicitly.
The `process` too... |
16916281 | Accessing shell script arguments by index | 6 | 2013-06-04 11:08:45 | <p>I'm sure this is a no-brainer when you're into shell programming.
Unfortunately I'm not and I'm having a pretty hard time ...</p>
<p>I need to verify arguments passed to a shell script.
I also want to store all parameters passed in an array as I need further separation later.</p>
<p>I have an argument "-o" which m... | 13,065 | 884,891 | 2013-06-04 12:56:21 | 16,918,471 | 15 | 2013-06-04 12:56:21 | 1,126,841 | 2013-06-04 12:56:21 | https://stackoverflow.com/q/16916281 | https://stackoverflow.com/a/16918471 | <p>In <code>bash</code>, you can use indirect parameter expansion to access an arbitrary positional parameter.</p>
<pre><code>$ set a b c
$ paramIndex=2
$ echo $2
b
$ echo ${!paramIndex}
b
</code></pre>
| <p>In <code>bash</code>, you can use indirect parameter expansion to access an arbitrary positional parameter.</p> <pre><code>$ set a b c $ paramIndex=2 $ echo $2 b $ echo ${!paramIndex} b </code></pre> | 360, 387, 390, 531 | bash, parameters, scripting, shell | <h1>Accessing shell script arguments by index</h1>
<p>I'm sure this is a no-brainer when you're into shell programming.
Unfortunately I'm not and I'm having a pretty hard time ...</p>
<p>I need to verify arguments passed to a shell script.
I also want to store all parameters passed in an array as I need further separa... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,483 | bash | # Accessing shell script arguments by index
I'm sure this is a no-brainer when you're into shell programming.
Unfortunately I'm not and I'm having a pretty hard time ...
I need to verify arguments passed to a shell script.
I also want to store all parameters passed in an array as I need further separation later.
I h... | In `bash`, you can use indirect parameter expansion to access an arbitrary positional parameter.
```
$ set a b c
$ paramIndex=2
$ echo $2
b
$ echo ${!paramIndex}
b
``` |
16497501 | How to generate for loop number sequence by using variable names in bash? | 6 | 2013-05-11 13:15:56 | <p>Could anybody explain how can I use variable names in bash for loop to generate a sequence of numbers? </p>
<pre><code>for year in {1990..1997}
do
echo ${year}
done
</code></pre>
<p>Results:</p>
<p>1990
1991
1992
1993
1994
1995
1996
1997</p>
<p>However</p>
<pre><code>year_start=1990
year_end=1997
for year in ... | 17,245 | 758,677 | 2013-05-11 14:02:13 | 16,497,754 | 15 | 2013-05-11 13:46:56 | 436,084 | 2013-05-11 14:02:13 | https://stackoverflow.com/q/16497501 | https://stackoverflow.com/a/16497754 | <p>You can use something like this</p>
<pre><code>for (( year = ${year_start}; year <=${year_end}; year++ ))
do
echo ${year}
done
</code></pre>
<p><code>seq</code> command is outdated and best avoided.</p>
<p><a href="http://www.cyberciti.biz/faq/bash-for-loop/">http://www.cyberciti.biz/faq/bash-for-loop/</a></... | <p>You can use something like this</p> <pre><code>for (( year = ${year_start}; year <=${year_end}; year++ )) do echo ${year} done </code></pre> <p><code>seq</code> command is outdated and best avoided.</p> <p><a href="http://www.cyberciti.biz/faq/bash-for-loop/">http://www.cyberciti.biz/faq/bash-for-loop/</a></... | 387, 2531, 3926 | bash, for-loop, sequences | <h1>How to generate for loop number sequence by using variable names in bash?</h1>
<p>Could anybody explain how can I use variable names in bash for loop to generate a sequence of numbers? </p>
<pre><code>for year in {1990..1997}
do
echo ${year}
done
</code></pre>
<p>Results:</p>
<p>1990
1991
1992
1993
1994
1995
1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,484 | bash | # How to generate for loop number sequence by using variable names in bash?
Could anybody explain how can I use variable names in bash for loop to generate a sequence of numbers?
```
for year in {1990..1997}
do
echo ${year}
done
```
Results:
1990
1991
1992
1993
1994
1995
1996
1997
However
```
year_start=1990
ye... | You can use something like this
```
for (( year = ${year_start}; year <=${year_end}; year++ ))
do
echo ${year}
done
```
`seq` command is outdated and best avoided.
<http://www.cyberciti.biz/faq/bash-for-loop/>
And if you want real bad to use the following syntax,
```
for year in {${year_start}..${year_end}}
```
... |
14736017 | Batch rename in hadoop | 6 | 2013-02-06 18:17:46 | <p>How can I rename all files in a hdfs directory to have a <code>.lzo</code> extension? <code>.lzo.index</code> files should not be renamed. </p>
<p>For example, this directory listing:</p>
<blockquote>
<pre><code>file0.lzo file0.lzo.index file0.lzo_copy_1
</code></pre>
</blockquote>
<p>could be renamed to:</p>
<... | 13,098 | 867,671 | 2016-08-04 13:00:34 | 14,736,250 | 15 | 2013-02-06 18:32:52 | 772,013 | 2014-11-13 14:04:30 | https://stackoverflow.com/q/14736017 | https://stackoverflow.com/a/14736250 | <p>If you don't want to write Java Code for this - I think using the command line HDFS API is your best bet: </p>
<p><a href="http://hadoop.apache.org/docs/r0.20.0/hdfs_shell.html#mv" rel="noreferrer"><code>mv</code> in Hadoop</a></p>
<p><code>hadoop fs -mv URI [URI …] <dest></code> </p>
<p>You can get the pat... | <p>If you don't want to write Java Code for this - I think using the command line HDFS API is your best bet: </p> <p><a href="http://hadoop.apache.org/docs/r0.20.0/hdfs_shell.html#mv" rel="noreferrer"><code>mv</code> in Hadoop</a></p> <p><code>hadoop fs -mv URI [URI …] <dest></code> </p> <p>You can get the pat... | 387, 1995, 12895 | bash, file-rename, hadoop | <h1>Batch rename in hadoop</h1>
<p>How can I rename all files in a hdfs directory to have a <code>.lzo</code> extension? <code>.lzo.index</code> files should not be renamed. </p>
<p>For example, this directory listing:</p>
<blockquote>
<pre><code>file0.lzo file0.lzo.index file0.lzo_copy_1
</code></pre>
</blockquote>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,485 | bash | # Batch rename in hadoop
How can I rename all files in a hdfs directory to have a `.lzo` extension? `.lzo.index` files should not be renamed.
For example, this directory listing:
> ```
> file0.lzo file0.lzo.index file0.lzo_copy_1
> ```
could be renamed to:
> ```
> file0.lzo file0.lzo.index file0.lzo_copy_1.lzo
> `... | If you don't want to write Java Code for this - I think using the command line HDFS API is your best bet:
[`mv` in Hadoop](http://hadoop.apache.org/docs/r0.20.0/hdfs_shell.html#mv)
`hadoop fs -mv URI [URI …] <dest>`
You can get the paths using a small one liner:
```
% hadoop fs -ls /user/foo/bar | awk '!/^d/ {prin... |
12712852 | How can I use PowerShell to move a user in AD? | 6 | 2012-10-03 16:32:04 | <p>I'm in need of a little help. I've got little to no PowerShell experience but I'm working with a Pocket Guide by my side and my GoogleFu. </p>
<p>Currently, my plan is to prompt for a username and store it, use Get-ADUser with the stored username to get and store the DistinguishedName, use Move-ADObject to move the... | 90,082 | 1,639,447 | 2024-02-13 13:50:43 | 12,713,273 | 15 | 2012-10-03 16:59:46 | 520,612 | 2012-10-03 16:59:46 | https://stackoverflow.com/q/12712852 | https://stackoverflow.com/a/12713273 | <p>Try this:</p>
<p><code>Get-ADUser $name| Move-ADObject -TargetPath 'OU=nonactive,OU=compny,DC=domain,Dc=net'</code></p>
| <p>Try this:</p> <p><code>Get-ADUser $name| Move-ADObject -TargetPath 'OU=nonactive,OU=compny,DC=domain,Dc=net'</code></p> | 526, 10401 | active-directory, powershell | <h1>How can I use PowerShell to move a user in AD?</h1>
<p>I'm in need of a little help. I've got little to no PowerShell experience but I'm working with a Pocket Guide by my side and my GoogleFu. </p>
<p>Currently, my plan is to prompt for a username and store it, use Get-ADUser with the stored username to get and st... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,486 | bash | # How can I use PowerShell to move a user in AD?
I'm in need of a little help. I've got little to no PowerShell experience but I'm working with a Pocket Guide by my side and my GoogleFu.
Currently, my plan is to prompt for a username and store it, use Get-ADUser with the stored username to get and store the Distingui... | Try this:
`Get-ADUser $name| Move-ADObject -TargetPath 'OU=nonactive,OU=compny,DC=domain,Dc=net'` |
11527899 | Assigning output of a command to a variable(BASH) | 6 | 2012-07-17 17:40:55 | <p>I need to assign the output of a command to a variable. The command I tried is:</p>
<pre><code>grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}'
</code></pre>
<p>I try this code to assign a variable:</p>
<pre><code>UUID=$(grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}')... | 13,900 | 1,454,756 | 2015-06-01 18:02:46 | 11,527,976 | 15 | 2012-07-17 17:46:14 | 135,549 | 2013-01-08 13:32:39 | https://stackoverflow.com/q/11527899 | https://stackoverflow.com/a/11527976 | <p>well, using the '$()' subshell operator is a common way to get the output of a bash command. As it spans a subshell it is not that efficient.</p>
<p>I tried :</p>
<pre><code>UUID=$(grep UUID /etc/fstab|awk '/ext4/ {print $1}'|awk '{print substr($0,6)}')
echo $UUID # writes e577b87e-2fec-893b-c237-6a14aeb5b390
</co... | <p>well, using the '$()' subshell operator is a common way to get the output of a bash command. As it spans a subshell it is not that efficient.</p> <p>I tried :</p> <pre><code>UUID=$(grep UUID /etc/fstab|awk '/ext4/ {print $1}'|awk '{print substr($0,6)}') echo $UUID # writes e577b87e-2fec-893b-c237-6a14aeb5b390 </co... | 58, 387, 390, 1796 | bash, command, linux, shell | <h1>Assigning output of a command to a variable(BASH)</h1>
<p>I need to assign the output of a command to a variable. The command I tried is:</p>
<pre><code>grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}'
</code></pre>
<p>I try this code to assign a variable:</p>
<pre><code>UUID=$(grep UUID fs... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,487 | bash | # Assigning output of a command to a variable(BASH)
I need to assign the output of a command to a variable. The command I tried is:
```
grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}'
```
I try this code to assign a variable:
```
UUID=$(grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print ... | well, using the '$()' subshell operator is a common way to get the output of a bash command. As it spans a subshell it is not that efficient.
I tried :
```
UUID=$(grep UUID /etc/fstab|awk '/ext4/ {print $1}'|awk '{print substr($0,6)}')
echo $UUID # writes e577b87e-2fec-893b-c237-6a14aeb5b390
```
it works perfectly :... |
11124572 | what is the windows equivalent of the command "date+%s" | 6 | 2012-06-20 17:04:39 | <p>I'm writing a batch script and I need the unix time. It's easy under linux, but I can't figure out how to do this in windows.</p>
| 10,020 | 664,720 | 2013-03-16 01:28:23 | 11,128,674 | 15 | 2012-06-20 21:48:14 | 1,012,053 | 2012-06-21 05:12:03 | https://stackoverflow.com/q/11124572 | https://stackoverflow.com/a/11128674 | <p>Here is a native batch solution that should work in any locale. It uses WMIC to get the current local time in a locale independent manner. Everything else is a "simple" matter of string parsing and basic math.</p>
<pre><code>:UnixTime [ReturnVar] [TimeStamp]
::
:: Computes the Unix time from the current local tim... | <p>Here is a native batch solution that should work in any locale. It uses WMIC to get the current local time in a locale independent manner. Everything else is a "simple" matter of string parsing and basic math.</p> <pre><code>:UnixTime [ReturnVar] [TimeStamp] :: :: Computes the Unix time from the current local tim... | 64, 387, 1231, 7002, 32842 | bash, batch-file, command-line, unix-timestamp, windows | <h1>what is the windows equivalent of the command "date+%s"</h1>
<p>I'm writing a batch script and I need the unix time. It's easy under linux, but I can't figure out how to do this in windows.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,488 | bash | # what is the windows equivalent of the command "date+%s"
I'm writing a batch script and I need the unix time. It's easy under linux, but I can't figure out how to do this in windows. | Here is a native batch solution that should work in any locale. It uses WMIC to get the current local time in a locale independent manner. Everything else is a "simple" matter of string parsing and basic math.
```
:UnixTime [ReturnVar] [TimeStamp]
::
:: Computes the Unix time from the current local time as reported ... |
10945370 | how to: make -j x // where x is automatically determined | 6 | 2012-06-08 08:24:52 | <p>After reading answer to this question:
<a href="https://stackoverflow.com/questions/2151605/make-make-default-to-make-j-8">Make "make" default to "make -j 8"</a></p>
<p>I am wondering if there is way to make the -j option automatically use the correct number of compile threads?</p>
<p>So I say ... | 2,219 | 35,065 | 2016-05-11 17:20:20 | 10,945,430 | 15 | 2012-06-08 08:28:48 | 946,850 | 2016-05-11 17:18:34 | https://stackoverflow.com/q/10945370 | https://stackoverflow.com/a/10945430 | <p><code>make</code> does not look up the number of cores by itself if you just use <code>make -j</code> -- instead, it parallelizes to the max. However, you should be able to determine the number of cores by</p>
<pre><code>grep -c "^processor" /proc/cpuinfo
</code></pre>
<p>or (as per Azor-Ahai's comment, if availab... | <p><code>make</code> does not look up the number of cores by itself if you just use <code>make -j</code> -- instead, it parallelizes to the max. However, you should be able to determine the number of cores by</p> <pre><code>grep -c "^processor" /proc/cpuinfo </code></pre> <p>or (as per Azor-Ahai's comment, if availab... | 387, 1448, 4301 | alias, bash, makefile | <h1>how to: make -j x // where x is automatically determined</h1>
<p>After reading answer to this question:
<a href="https://stackoverflow.com/questions/2151605/make-make-default-to-make-j-8">Make "make" default to "make -j 8"</a></p>
<p>I am wondering if there is way to make the -j option automati... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,489 | bash | # how to: make -j x // where x is automatically determined
After reading answer to this question:
[Make "make" default to "make -j 8"](https://stackoverflow.com/questions/2151605/make-make-default-to-make-j-8)
I am wondering if there is way to make the -j option automatically use the correct number of compile threads... | `make` does not look up the number of cores by itself if you just use `make -j` -- instead, it parallelizes to the max. However, you should be able to determine the number of cores by
```
grep -c "^processor" /proc/cpuinfo
```
or (as per Azor-Ahai's comment, if available on your system)
```
nproc
```
Hence:
```
ma... |
9944885 | Powershell XML importnode from different file | 6 | 2012-03-30 14:25:46 | <p>Content of profile.xml:</p>
<pre><code><files>
<file folder="CaptureServer" filename="CSConfig" object="CSConfig">
<Profile name="BBH1200Kofax">
<OutputCache>\</OutputCache>
<EncryptedConnectionString>564rgr=</EncryptedConnectionString>
<ConvertDo... | 15,299 | 1,298,774 | 2022-09-22 22:14:57 | 9,945,766 | 15 | 2012-03-30 15:15:43 | 153,982 | 2012-03-30 15:15:43 | https://stackoverflow.com/q/9944885 | https://stackoverflow.com/a/9945766 | <p>You're really close but ImportNode only makes a copy and doesn't actually insert the copied nodes into the document. Try this:</p>
<pre><code>$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true)
$newxml.DocumentElement.AppendChild($newNode)
$xml.Save("$pwd\profile.xml")
</code></pre>
| <p>You're really close but ImportNode only makes a copy and doesn't actually insert the copied nodes into the document. Try this:</p> <pre><code>$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true) $newxml.DocumentElement.AppendChild($newNode) $xml.Save("$pwd\profile.xml") </code></pre> | 19, 526 | powershell, xml | <h1>Powershell XML importnode from different file</h1>
<p>Content of profile.xml:</p>
<pre><code><files>
<file folder="CaptureServer" filename="CSConfig" object="CSConfig">
<Profile name="BBH1200Kofax">
<OutputCache>\</OutputCache>
<EncryptedConnectionString>564rgr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,490 | bash | # Powershell XML importnode from different file
Content of profile.xml:
```
<files>
<file folder="CaptureServer" filename="CSConfig" object="CSConfig">
<Profile name="BBH1200Kofax">
<OutputCache>\</OutputCache>
<EncryptedConnectionString>564rgr=</EncryptedConnectionString>
<ConvertDocsBeforeRe... | You're really close but ImportNode only makes a copy and doesn't actually insert the copied nodes into the document. Try this:
```
$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true)
$newxml.DocumentElement.AppendChild($newNode)
$xml.Save("$pwd\profile.xml")
``` |
9437084 | Can't execute any basic command in linux console | 6 | 2012-02-24 19:49:04 | <p>I know how the problem was created, but really have no idea how to restore the server command execution.</p>
<p>The thing is, I was configuring the environment variables of Glassfish in my Ubuntu server, and I modified the <code>.bashrc</code> file from root and added an <code>export</code> clause (with <code>GLASS... | 31,719 | 866,390 | 2012-02-24 20:02:26 | 9,437,161 | 15 | 2012-02-24 19:55:02 | 371,653 | 2012-02-24 19:55:02 | https://stackoverflow.com/q/9437084 | https://stackoverflow.com/a/9437161 | <p>Do an export of the binary paths:</p>
<pre><code>export PATH=$PATH:/bin:/usr/bin
</code></pre>
<p>right after that you're able again to operate and to reverse your changes.</p>
<p>Otherwise just do an edit with your favorite editor while given the full path to your editors binary:</p>
<pre><code>/usr/bin/emacs -... | <p>Do an export of the binary paths:</p> <pre><code>export PATH=$PATH:/bin:/usr/bin </code></pre> <p>right after that you're able again to operate and to reverse your changes.</p> <p>Otherwise just do an edit with your favorite editor while given the full path to your editors binary:</p> <pre><code>/usr/bin/emacs -... | 58, 387 | bash, linux | <h1>Can't execute any basic command in linux console</h1>
<p>I know how the problem was created, but really have no idea how to restore the server command execution.</p>
<p>The thing is, I was configuring the environment variables of Glassfish in my Ubuntu server, and I modified the <code>.bashrc</code> file from root... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,491 | bash | # Can't execute any basic command in linux console
I know how the problem was created, but really have no idea how to restore the server command execution.
The thing is, I was configuring the environment variables of Glassfish in my Ubuntu server, and I modified the `.bashrc` file from root and added an `export` clau... | Do an export of the binary paths:
```
export PATH=$PATH:/bin:/usr/bin
```
right after that you're able again to operate and to reverse your changes.
Otherwise just do an edit with your favorite editor while given the full path to your editors binary:
```
/usr/bin/emacs -nw /root/.bashrc
``` |
5736643 | while loops within expect | 6 | 2011-04-20 21:06:09 | <p>I am using expect within bash. I want my script to telnet into a box, expect a prompt, send a command. If there is a different prompt now, it has to proceed or else it has to send that command again.
My script goes like this: </p>
<pre><code>\#!bin/bash
//I am filling up IP and PORT1 here
expect -c "
set t... | 32,819 | 1,251,211 | 2017-03-10 06:51:41 | 5,737,864 | 15 | 2011-04-20 23:39:45 | 7,552 | 2011-04-20 23:39:45 | https://stackoverflow.com/q/5736643 | https://stackoverflow.com/a/5737864 | <p>This is how I'd implement this:</p>
<pre><code>expect -c '
set timeout -1
spawn telnet [lindex $argv 0] [lindex $argv 1]
send "\r"
send "\r"
expect {
Prompt1 {
send "command"
exp_continue
}
Prompt2 {
send "Yes\r"
}
}
}
' $IP $PORT1
</code></pre>
<ul>... | <p>This is how I'd implement this:</p> <pre><code>expect -c ' set timeout -1 spawn telnet [lindex $argv 0] [lindex $argv 1] send "\r" send "\r" expect { Prompt1 { send "command" exp_continue } Prompt2 { send "Yes\r" } } } ' $IP $PORT1 </code></pre> <ul>... | 387, 9048, 17310 | bash, expect, while-loop | <h1>while loops within expect</h1>
<p>I am using expect within bash. I want my script to telnet into a box, expect a prompt, send a command. If there is a different prompt now, it has to proceed or else it has to send that command again.
My script goes like this: </p>
<pre><code>\#!bin/bash
//I am filling up IP and... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,492 | bash | # while loops within expect
I am using expect within bash. I want my script to telnet into a box, expect a prompt, send a command. If there is a different prompt now, it has to proceed or else it has to send that command again.
My script goes like this:
```
\#!bin/bash
//I am filling up IP and PORT1 here
expect -... | This is how I'd implement this:
```
expect -c '
set timeout -1
spawn telnet [lindex $argv 0] [lindex $argv 1]
send "\r"
send "\r"
expect {
Prompt1 {
send "command"
exp_continue
}
Prompt2 {
send "Yes\r"
}
}
}
' $IP $PORT1
```
- use single quotes around t... |
3062305 | Executing shell commands from Java | 6 | 2010-06-17 14:04:09 | <p>I'm trying to execute a shell command from a java application, on the GNU/Linux platform. The problem is that the script, that calls another java application, never ends, although it runs successfully from bash. I tried to debug it:</p>
<pre>
(gdb) bt
#0 0xb773d422 in __kernel_vsyscall ()
#1 0xb7709b5d in pthread... | 22,577 | 2,203,413 | 2014-12-18 17:52:59 | 3,062,874 | 15 | 2010-06-17 15:04:13 | 352,088 | 2014-12-18 17:52:59 | https://stackoverflow.com/q/3062305 | https://stackoverflow.com/a/3062874 | <p>Are you processing the standard input and standard output? From the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html" rel="nofollow noreferrer">javadocs</a>:</p>
<blockquote>
<p>Because some native platforms only provide limited buffer size for standard input and output streams, failure to... | <p>Are you processing the standard input and standard output? From the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html" rel="nofollow noreferrer">javadocs</a>:</p> <blockquote> <p>Because some native platforms only provide limited buffer size for standard input and output streams, failure to... | 17, 390, 1231 | command-line, java, shell | <h1>Executing shell commands from Java</h1>
<p>I'm trying to execute a shell command from a java application, on the GNU/Linux platform. The problem is that the script, that calls another java application, never ends, although it runs successfully from bash. I tried to debug it:</p>
<pre>
(gdb) bt
#0 0xb773d422 in __... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,493 | bash | # Executing shell commands from Java
I'm trying to execute a shell command from a java application, on the GNU/Linux platform. The problem is that the script, that calls another java application, never ends, although it runs successfully from bash. I tried to debug it:
```
(gdb) bt
#0 0xb773d422 in __kernel_vsyscall... | Are you processing the standard input and standard output? From the [javadocs](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html):
> Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of... |
1938185 | How to reenter Vim after :! bash? | 6 | 2009-12-21 04:29:51 | <p>I'm slowing getting to know Vim and Bash shell scripting and am running into this issue:</p>
<p>When I'm running MacVim, I sometimes want to use the command line to compile whatever it is I'm working on (in this case a small Java program). So I type <code>:! bash</code> and compile whatever it is that I need and te... | 3,546 | 164,468 | 2012-06-05 00:23:31 | 1,938,195 | 15 | 2009-12-21 04:33:17 | 29,157 | 2009-12-21 04:33:17 | https://stackoverflow.com/q/1938185 | https://stackoverflow.com/a/1938195 | <p>Two suggestions:</p>
<ol>
<li>Use <code>exit</code> to quit the bash shell and return to vim.</li>
<li>Within vim, use <code>:set makeprg=name_of_your_make_program</code> to automatically compile from within vim with the <code>:make</code> command. As a bonus, if it's a toolset that vim recognizes, vim will parse ... | <p>Two suggestions:</p> <ol> <li>Use <code>exit</code> to quit the bash shell and return to vim.</li> <li>Within vim, use <code>:set makeprg=name_of_your_make_program</code> to automatically compile from within vim with the <code>:make</code> command. As a bonus, if it's a toolset that vim recognizes, vim will parse ... | 370, 387, 1231 | bash, command-line, vim | <h1>How to reenter Vim after :! bash?</h1>
<p>I'm slowing getting to know Vim and Bash shell scripting and am running into this issue:</p>
<p>When I'm running MacVim, I sometimes want to use the command line to compile whatever it is I'm working on (in this case a small Java program). So I type <code>:! bash</code> an... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,494 | bash | # How to reenter Vim after :! bash?
I'm slowing getting to know Vim and Bash shell scripting and am running into this issue:
When I'm running MacVim, I sometimes want to use the command line to compile whatever it is I'm working on (in this case a small Java program). So I type `:! bash` and compile whatever it is th... | Two suggestions:
1. Use `exit` to quit the bash shell and return to vim.
2. Within vim, use `:set makeprg=name_of_your_make_program` to automatically compile from within vim with the `:make` command. As a bonus, if it's a toolset that vim recognizes, vim will parse the compiler's output, show you the errors, and allow... |
519395 | Bash Scripting - shell command output redirection | 6 | 2009-02-06 07:11:41 | <p>Can someone help explain the following:</p>
<p>If I type:</p>
<pre><code>a=`ls -l`
</code></pre>
<p>Then the output of the ls command is saved in the variable <code>a</code></p>
<p>but if I try:</p>
<pre><code>a=`sh ./somefile`
</code></pre>
<p>The result is outputed to the shell (<code>stdout</code>) rather t... | 29,577 | 14,587 | 2009-02-06 08:31:26 | 519,418 | 15 | 2009-02-06 07:25:02 | 14,860 | 2009-02-06 08:31:26 | https://stackoverflow.com/q/519395 | https://stackoverflow.com/a/519418 | <p>I think because the shell probably attaches itself to /dev/tty but I may be wrong. Why wouldn't you just set execute permissions on the script and use:</p>
<pre><code>a=`./somefile`
</code></pre>
<p>If you want to capture stderr <strong>and</strong> stdout to a, just use:</p>
<pre><code>a=`./somefile 2>&1`... | <p>I think because the shell probably attaches itself to /dev/tty but I may be wrong. Why wouldn't you just set execute permissions on the script and use:</p> <pre><code>a=`./somefile` </code></pre> <p>If you want to capture stderr <strong>and</strong> stdout to a, just use:</p> <pre><code>a=`./somefile 2>&1`... | 387, 390, 531 | bash, scripting, shell | <h1>Bash Scripting - shell command output redirection</h1>
<p>Can someone help explain the following:</p>
<p>If I type:</p>
<pre><code>a=`ls -l`
</code></pre>
<p>Then the output of the ls command is saved in the variable <code>a</code></p>
<p>but if I try:</p>
<pre><code>a=`sh ./somefile`
</code></pre>
<p>The res... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,495 | bash | # Bash Scripting - shell command output redirection
Can someone help explain the following:
If I type:
```
a=`ls -l`
```
Then the output of the ls command is saved in the variable `a`
but if I try:
```
a=`sh ./somefile`
```
The result is outputed to the shell (`stdout`) rather than the variable `a`
What I expec... | I think because the shell probably attaches itself to /dev/tty but I may be wrong. Why wouldn't you just set execute permissions on the script and use:
```
a=`./somefile`
```
If you want to capture stderr **and** stdout to a, just use:
```
a=`./somefile 2>&1`
```
To check file is executable first:
```
if [[ -x ./s... |
209145 | Unix: Getting Export PATH to "Stick" | 6 | 2008-10-16 15:50:49 | <p>When setting the export path in Unix, example:</p>
<pre><code>export PATH=$PATH: $EC2_HOME/bin
</code></pre>
<p>If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick" so my system... | 9,656 | 2,293 | 2012-04-27 10:04:20 | 209,166 | 15 | 2008-10-16 15:54:03 | 8,078 | 2012-04-27 10:04:20 | https://stackoverflow.com/q/209145 | https://stackoverflow.com/a/209166 | <p>Open <code>~/.bashrc.</code> This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like <code>~/.shrc</code>.</p>
<p>Add the line you need to the bottom of the file:</p>
<pre><code>export PATH=$P... | <p>Open <code>~/.bashrc.</code> This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like <code>~/.shrc</code>.</p> <p>Add the line you need to the bottom of the file:</p> <pre><code>export PATH=$P... | 34, 390, 391, 4167, 6268 | export, path, shell, terminal, unix | <h1>Unix: Getting Export PATH to "Stick"</h1>
<p>When setting the export path in Unix, example:</p>
<pre><code>export PATH=$PATH: $EC2_HOME/bin
</code></pre>
<p>If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,496 | bash | # Unix: Getting Export PATH to "Stick"
When setting the export path in Unix, example:
```
export PATH=$PATH: $EC2_HOME/bin
```
If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick"... | Open `~/.bashrc.` This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like `~/.shrc`.
Add the line you need to the bottom of the file:
```
export PATH=$PATH:$EC2_HOME/bi
```
Other info rolled up ... |
10053678 | Escaping characters in bash (for JSON) | 114 | 2012-04-07 10:28:18 | <p>I'm using git, then posting the commit message and other bits as a JSON payload to a server.</p>
<p>Currently I have:</p>
<pre><code>MSG=`git log -n 1 --format=oneline | grep -o ' .\+'`
</code></pre>
<p>which sets MSG to something like:</p>
<pre><code>Calendar can't go back past today
</code></pre>
<p>then</p>
... | 128,472 | 16,511 | 2024-03-25 04:52:48 | 10,053,951 | 14 | 2012-04-07 11:10:20 | 16,511 | 2012-04-07 11:22:15 | https://stackoverflow.com/q/10053678 | https://stackoverflow.com/a/10053951 | <p>OK, found out what to do. Bash supports this natively as expected, though as always, the syntax isn't really very guessable!</p>
<p>Essentially <code>${string//substring/replacement}</code> returns what you'd image, so you can use</p>
<pre><code>MSG=${MSG//\'/\\\'}
</code></pre>
<p>To do this. The next problem is... | <p>OK, found out what to do. Bash supports this natively as expected, though as always, the syntax isn't really very guessable!</p> <p>Essentially <code>${string//substring/replacement}</code> returns what you'd image, so you can use</p> <pre><code>MSG=${MSG//\'/\\\'} </code></pre> <p>To do this. The next problem is... | 387, 1508, 4804 | bash, escaping, json | <h1>Escaping characters in bash (for JSON)</h1>
<p>I'm using git, then posting the commit message and other bits as a JSON payload to a server.</p>
<p>Currently I have:</p>
<pre><code>MSG=`git log -n 1 --format=oneline | grep -o ' .\+'`
</code></pre>
<p>which sets MSG to something like:</p>
<pre><code>Calendar can'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,497 | bash | # Escaping characters in bash (for JSON)
I'm using git, then posting the commit message and other bits as a JSON payload to a server.
Currently I have:
```
MSG=`git log -n 1 --format=oneline | grep -o ' .\+'`
```
which sets MSG to something like:
```
Calendar can't go back past today
```
then
```
curl -i -X POST... | OK, found out what to do. Bash supports this natively as expected, though as always, the syntax isn't really very guessable!
Essentially `${string//substring/replacement}` returns what you'd image, so you can use
```
MSG=${MSG//\'/\\\'}
```
To do this. The next problem is that the first regex doesn't work anymore, b... |
30431353 | How to use sed to replace regex capture group? | 72 | 2015-05-25 04:42:04 | <p>I have a large file with many scattered file paths that look like</p>
<pre><code>lolsed_bulsh.png
</code></pre>
<p>I want to prepend these file names with an extended path like:</p>
<pre><code>/full/path/lolsed_bullsh.png
</code></pre>
<p>I'm having a hard time matching and capturing these. currently i'm trying ... | 142,635 | 93,212 | 2022-06-27 16:34:36 | 30,431,408 | 14 | 2015-05-25 04:48:39 | 1,400,768 | 2022-01-07 11:11:26 | https://stackoverflow.com/q/30431353 | https://stackoverflow.com/a/30431408 | <p><code>sed</code> uses POSIX BRE, and <a href="http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html#tag_09_03_03" rel="noreferrer">BRE doesn't support one or more quantifier <code>+</code></a>. The quantifier <code>+</code> is only <a href="http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xb... | <p><code>sed</code> uses POSIX BRE, and <a href="http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html#tag_09_03_03" rel="noreferrer">BRE doesn't support one or more quantifier <code>+</code></a>. The quantifier <code>+</code> is only <a href="http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xb... | 18, 387, 5282 | bash, regex, sed | <h1>How to use sed to replace regex capture group?</h1>
<p>I have a large file with many scattered file paths that look like</p>
<pre><code>lolsed_bulsh.png
</code></pre>
<p>I want to prepend these file names with an extended path like:</p>
<pre><code>/full/path/lolsed_bullsh.png
</code></pre>
<p>I'm having a hard ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,498 | bash | # How to use sed to replace regex capture group?
I have a large file with many scattered file paths that look like
```
lolsed_bulsh.png
```
I want to prepend these file names with an extended path like:
```
/full/path/lolsed_bullsh.png
```
I'm having a hard time matching and capturing these. currently i'm trying v... | `sed` uses POSIX BRE, and [BRE doesn't support one or more quantifier `+`](http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html#tag_09_03_03). The quantifier `+` is only [supported in POSIX ERE](http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html#tag_09_04_03). However, [POSIX sed... |
3222810 | Sorting on the last field of a line | 58 | 2010-07-11 11:05:39 | <p>What is the simplest way to sort a list of lines, sorting on the last field of each line? Each line may have a variable number of fields.</p>
<p>Something like</p>
<pre><code>sort -k -1
</code></pre>
<p>is what I want, but sort(1) does not take negative numbers to select fields from the end instead of the start.<... | 43,825 | 23,744 | 2025-04-25 17:42:56 | 3,225,496 | 14 | 2010-07-12 02:24:31 | 310,574 | 2012-06-07 11:08:13 | https://stackoverflow.com/q/3222810 | https://stackoverflow.com/a/3225496 | <p>Here's a Perl command line (note that your shell may require you to escape the <code>$</code>s):</p>
<pre><code>perl -e "print sort {(split '/', $a)[-1] <=> (split '/', $b)[-1]} <>"
</code></pre>
<p>Just pipe the list into it or, if the list is in a file, put the filename at the end of the command line... | <p>Here's a Perl command line (note that your shell may require you to escape the <code>$</code>s):</p> <pre><code>perl -e "print sort {(split '/', $a)[-1] <=> (split '/', $b)[-1]} <>" </code></pre> <p>Just pipe the list into it or, if the list is in a file, put the filename at the end of the command line... | 58, 134, 390 | linux, shell, sorting | <h1>Sorting on the last field of a line</h1>
<p>What is the simplest way to sort a list of lines, sorting on the last field of each line? Each line may have a variable number of fields.</p>
<p>Something like</p>
<pre><code>sort -k -1
</code></pre>
<p>is what I want, but sort(1) does not take negative numbers to sele... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,499 | bash | # Sorting on the last field of a line
What is the simplest way to sort a list of lines, sorting on the last field of each line? Each line may have a variable number of fields.
Something like
```
sort -k -1
```
is what I want, but sort(1) does not take negative numbers to select fields from the end instead of the st... | Here's a Perl command line (note that your shell may require you to escape the `$`s):
```
perl -e "print sort {(split '/', $a)[-1] <=> (split '/', $b)[-1]} <>"
```
Just pipe the list into it or, if the list is in a file, put the filename at the end of the command line.
Note that this script does not actually change ... |
29556437 | How to return one and only one value from a PowerShell function? | 57 | 2015-04-10 08:11:41 | <p>I've learned from <a href="https://stackoverflow.com/questions/10286164/powershell-function-return-value">this Stack Overflow question</a>, that PowerShell return semantics are different, let's say, from C#'s return semantics. Quote from the aforementioned question:</p>
<blockquote>
<p>PowerShell has really wacky... | 48,805 | 1,611,590 | 2024-10-23 11:33:19 | 29,597,354 | 14 | 2015-04-13 03:17:41 | 115,690 | 2015-04-13 03:17:41 | https://stackoverflow.com/q/29556437 | https://stackoverflow.com/a/29597354 | <p>Several answers already given do not fully answer your question because they do not account for <em>other</em> cmdlets you might call--as you point out--that might "pollute" your output. The answer from @Laezylion is essentially correct but I believe bears further elaboration.</p>
<p>It is clear that you appreciate... | <p>Several answers already given do not fully answer your question because they do not account for <em>other</em> cmdlets you might call--as you point out--that might "pollute" your output. The answer from @Laezylion is essentially correct but I believe bears further elaboration.</p> <p>It is clear that you appreciate... | 526 | powershell | <h1>How to return one and only one value from a PowerShell function?</h1>
<p>I've learned from <a href="https://stackoverflow.com/questions/10286164/powershell-function-return-value">this Stack Overflow question</a>, that PowerShell return semantics are different, let's say, from C#'s return semantics. Quote from the a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,500 | bash | # How to return one and only one value from a PowerShell function?
I've learned from [this Stack Overflow question](https://stackoverflow.com/questions/10286164/powershell-function-return-value), that PowerShell return semantics are different, let's say, from C#'s return semantics. Quote from the aforementioned questi... | Several answers already given do not fully answer your question because they do not account for *other* cmdlets you might call--as you point out--that might "pollute" your output. The answer from @Laezylion is essentially correct but I believe bears further elaboration.
It is clear that you appreciate that your curren... |
9651898 | Is there a 'git sed' or equivalent? | 56 | 2012-03-11 02:27:57 | <p>Let's say I want to rename a method in source code contained in a git repository. I could do this by hand, but the method name might be in multiple places (e.g., unit test, documentation, actual method). To check where the method is used, I use 'git grep'. I get 'git grep' to show only lines that I want to change, a... | 18,774 | 822,162 | 2024-08-28 11:01:50 | 9,651,941 | 14 | 2012-03-11 02:35:59 | 229,602 | 2012-03-11 04:33:33 | https://stackoverflow.com/q/9651898 | https://stackoverflow.com/a/9651941 | <p>You could do a </p>
<pre><code>for i in $(git grep --full-name -l old_method_name)
do
perl -p -i -e 's/old_method_name/new_method_name/g' $i
done
</code></pre>
<p>stick that in a file somewhere and then alias it as <code>git sed</code> in your config. </p>
<p><strong>Update:</strong> The comment by tchrist below... | <p>You could do a </p> <pre><code>for i in $(git grep --full-name -l old_method_name) do perl -p -i -e 's/old_method_name/new_method_name/g' $i done </code></pre> <p>stick that in a file somewhere and then alias it as <code>git sed</code> in your config. </p> <p><strong>Update:</strong> The comment by tchrist below... | 58, 119, 387, 5282 | bash, git, linux, sed | <h1>Is there a 'git sed' or equivalent?</h1>
<p>Let's say I want to rename a method in source code contained in a git repository. I could do this by hand, but the method name might be in multiple places (e.g., unit test, documentation, actual method). To check where the method is used, I use 'git grep'. I get 'git grep... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,501 | bash | # Is there a 'git sed' or equivalent?
Let's say I want to rename a method in source code contained in a git repository. I could do this by hand, but the method name might be in multiple places (e.g., unit test, documentation, actual method). To check where the method is used, I use 'git grep'. I get 'git grep' to show... | You could do a
```
for i in $(git grep --full-name -l old_method_name)
do
perl -p -i -e 's/old_method_name/new_method_name/g' $i
done
```
stick that in a file somewhere and then alias it as `git sed` in your config.
**Update:** The comment by tchrist below is a much better solution since it prevents perl from spawn... |
71855882 | How to add directory recursively on git safe.directory? | 52 | 2022-04-13 10:23:02 | <p>According to this <a href="https://stackoverflow.com/questions/71849415/cannot-add-parent-directory-to-safe-directory-on-git">QA</a>, we may use <code>safe.directory</code> argument to add directory to be marked as whitelist, due to <a href="https://github.blog/2022-04-12-git-security-vulnerability-announced/" rel="... | 59,177 | 6,819,038 | 2024-08-19 11:49:13 | 71,859,097 | 14 | 2022-04-13 14:19:39 | 7,936,768 | 2022-04-13 14:19:39 | https://stackoverflow.com/q/71855882 | https://stackoverflow.com/a/71859097 | <p>What I did for now, but may not be the perfect solution, is to find all <code>.git</code> folders and add them through a <code>find</code> command.</p>
<pre><code>find /full/path -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
</code></pre>
<p>Want to remind, that it is... | <p>What I did for now, but may not be the perfect solution, is to find all <code>.git</code> folders and add them through a <code>find</code> command.</p> <pre><code>find /full/path -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \; </code></pre> <p>Want to remind, that it is... | 119, 387, 549, 155837 | bash, cve-2022-24765, git, ubuntu | <h1>How to add directory recursively on git safe.directory?</h1>
<p>According to this <a href="https://stackoverflow.com/questions/71849415/cannot-add-parent-directory-to-safe-directory-on-git">QA</a>, we may use <code>safe.directory</code> argument to add directory to be marked as whitelist, due to <a href="https://gi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,502 | bash | # How to add directory recursively on git safe.directory?
According to this [QA](https://stackoverflow.com/questions/71849415/cannot-add-parent-directory-to-safe-directory-on-git), we may use `safe.directory` argument to add directory to be marked as whitelist, due to [latest CVE](https://github.blog/2022-04-12-git-se... | What I did for now, but may not be the perfect solution, is to find all `.git` folders and add them through a `find` command.
```
find /full/path -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
```
Want to remind, that it is necessary to add the full path in the find com... |
2704635 | Is there a way to find the running time of the last executed command in the shell? | 47 | 2010-04-24 13:37:11 | <p>Is there a command like <code>time</code> that can display the running time details of the last or past executed commands on the shell?</p>
| 34,709 | 309,683 | 2023-06-05 08:53:54 | 2,704,689 | 14 | 2010-04-24 13:54:34 | 273,566 | 2022-05-04 23:58:58 | https://stackoverflow.com/q/2704635 | https://stackoverflow.com/a/2704689 | <p>I do not know, how it is in bash, but in zsh you can define <code>preexec</code> and <code>precmd</code> functions so that they save the current time to variables <code>$STARTTIME</code> (preexec) and <code>$ENDTIME</code> (precmd) so you will be able to find the approximate running time. Or you can define an <code>... | <p>I do not know, how it is in bash, but in zsh you can define <code>preexec</code> and <code>precmd</code> functions so that they save the current time to variables <code>$STARTTIME</code> (preexec) and <code>$ENDTIME</code> (precmd) so you will be able to find the approximate running time. Or you can define an <code>... | 34, 58, 369, 387, 390 | bash, linux, macos, shell, unix | <h1>Is there a way to find the running time of the last executed command in the shell?</h1>
<p>Is there a command like <code>time</code> that can display the running time details of the last or past executed commands on the shell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,503 | bash | # Is there a way to find the running time of the last executed command in the shell?
Is there a command like `time` that can display the running time details of the last or past executed commands on the shell? | I do not know, how it is in bash, but in zsh you can define `preexec` and `precmd` functions so that they save the current time to variables `$STARTTIME` (preexec) and `$ENDTIME` (precmd) so you will be able to find the approximate running time. Or you can define an `accept-line` function so that it will prepend `time`... |
23140501 | Why does bash "echo [t]" result in "t" not "[t]" | 44 | 2014-04-17 18:15:44 | <p>This happens for the character t, and the value root. Quite perplexing</p>
<pre><code>$ echo [s]
[s]
$ echo [t]
t
$ echo [ t ]
[ t ]
$ echo [root]
t
</code></pre>
| 2,451 | 3,546,411 | 2015-04-05 04:16:35 | 23,162,572 | 14 | 2014-04-18 21:21:59 | 315,306 | 2014-04-18 21:21:59 | https://stackoverflow.com/q/23140501 | https://stackoverflow.com/a/23162572 | <p>Being not a shell habitué (and not willing to become) I found surprising how filename expansion is designed to behave when no matches are found. I'll report the <a href="https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html">Bash reference</a></p>
<blockquote>
<p>Bash scans each word for the ... | <p>Being not a shell habitué (and not willing to become) I found surprising how filename expansion is designed to behave when no matches are found. I'll report the <a href="https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html">Bash reference</a></p> <blockquote> <p>Bash scans each word for the ... | 387 | bash | <h1>Why does bash "echo [t]" result in "t" not "[t]"</h1>
<p>This happens for the character t, and the value root. Quite perplexing</p>
<pre><code>$ echo [s]
[s]
$ echo [t]
t
$ echo [ t ]
[ t ]
$ echo [root]
t
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,504 | bash | # Why does bash "echo [t]" result in "t" not "[t]"
This happens for the character t, and the value root. Quite perplexing
```
$ echo [s]
[s]
$ echo [t]
t
$ echo [ t ]
[ t ]
$ echo [root]
t
``` | Being not a shell habitué (and not willing to become) I found surprising how filename expansion is designed to behave when no matches are found. I'll report the [Bash reference](https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
> Bash scans each word for the characters `*`, `?`, and `[`. If o... |
10234327 | convert bash `ls` output to json array | 37 | 2012-04-19 18:19:51 | <p>Is it possible to use a bash script to format the output of the <code>ls</code> to a json array? To be valid json, all names of the dirs and files need to be wrapped in double quotes, seperated by a comma, and the entire thing needs to be wrapped in square brackets. I.e. convert:</p>
<pre><code>jeroen@jeroen-ubuntu... | 43,361 | 318,752 | 2023-07-23 09:57:10 | 10,235,275 | 14 | 2012-04-19 19:23:02 | 852,548 | 2012-04-19 19:23:02 | https://stackoverflow.com/q/10234327 | https://stackoverflow.com/a/10235275 | <p>Use perl as the encoder; it's guaranteed to be non-buggy, is everywhere, and with pipes, it's still reasonably clean:</p>
<pre><code>ls | perl -e 'use JSON; @in=grep(s/\n$//, <>); print encode_json(\@in)."\n";'
</code></pre>
| <p>Use perl as the encoder; it's guaranteed to be non-buggy, is everywhere, and with pipes, it's still reasonably clean:</p> <pre><code>ls | perl -e 'use JSON; @in=grep(s/\n$//, <>); print encode_json(\@in)."\n";' </code></pre> | 58, 387, 549, 1508, 10327 | bash, json, linux, sh, ubuntu | <h1>convert bash `ls` output to json array</h1>
<p>Is it possible to use a bash script to format the output of the <code>ls</code> to a json array? To be valid json, all names of the dirs and files need to be wrapped in double quotes, seperated by a comma, and the entire thing needs to be wrapped in square brackets. I.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,505 | bash | # convert bash `ls` output to json array
Is it possible to use a bash script to format the output of the `ls` to a json array? To be valid json, all names of the dirs and files need to be wrapped in double quotes, seperated by a comma, and the entire thing needs to be wrapped in square brackets. I.e. convert:
```
jer... | Use perl as the encoder; it's guaranteed to be non-buggy, is everywhere, and with pipes, it's still reasonably clean:
```
ls | perl -e 'use JSON; @in=grep(s/\n$//, <>); print encode_json(\@in)."\n";'
``` |
11973775 | Powershell: get output from Receive-Job | 35 | 2012-08-15 17:06:00 | <p>I have a collection of jobs that are running. When they complete I use receive-job and it writes the output to the screen. I'd like to take that output and log it to a file. I don't want to tee the output produced while the jobs are running because with multiple jobs running at once the logging would be interspersed... | 116,044 | 77,359 | 2024-12-30 17:26:34 | 11,991,815 | 14 | 2012-08-16 16:41:59 | 77,359 | 2013-02-28 14:33:19 | https://stackoverflow.com/q/11973775 | https://stackoverflow.com/a/11991815 | <p>NOTE: After some experimentation I have found that using write-output or just outputting a variable directly is not a good solution either. If you have a function that uses either of those methods and also returns a value the output will be concatenated with the return value! </p>
<p>The best way I have found to lo... | <p>NOTE: After some experimentation I have found that using write-output or just outputting a variable directly is not a good solution either. If you have a function that uses either of those methods and also returns a value the output will be concatenated with the return value! </p> <p>The best way I have found to lo... | 526, 955 | jobs, powershell | <h1>Powershell: get output from Receive-Job</h1>
<p>I have a collection of jobs that are running. When they complete I use receive-job and it writes the output to the screen. I'd like to take that output and log it to a file. I don't want to tee the output produced while the jobs are running because with multiple jobs ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,506 | bash | # Powershell: get output from Receive-Job
I have a collection of jobs that are running. When they complete I use receive-job and it writes the output to the screen. I'd like to take that output and log it to a file. I don't want to tee the output produced while the jobs are running because with multiple jobs running a... | NOTE: After some experimentation I have found that using write-output or just outputting a variable directly is not a good solution either. If you have a function that uses either of those methods and also returns a value the output will be concatenated with the return value!
The best way I have found to log output fr... |
2270081 | Bash Script Calls another bash script and waits for it to complete before proceeding | 35 | 2010-02-16 01:24:47 | <p>I have 1 bash script that runs another bash script, however the first bashscript isn't waiting for the second one to complete before proceeding, how can I force it to wait?</p>
<p>For example:</p>
<pre><code>#!/bin/bash
# first.sh
#call to secondary script
sh second.sh
echo "second.sh has completed"
echo "contin... | 75,953 | 174,648 | 2020-04-19 02:34:21 | 2,270,089 | 14 | 2010-02-16 01:27:06 | 20,862 | 2010-02-16 01:27:06 | https://stackoverflow.com/q/2270081 | https://stackoverflow.com/a/2270089 | <p>Normally it does; something else is happening. Are you sure that the other script isn't running something in the background instead? You can try using <code>wait</code> regardless.</p>
| <p>Normally it does; something else is happening. Are you sure that the other script isn't running something in the background instead? You can try using <code>wait</code> regardless.</p> | 387 | bash | <h1>Bash Script Calls another bash script and waits for it to complete before proceeding</h1>
<p>I have 1 bash script that runs another bash script, however the first bashscript isn't waiting for the second one to complete before proceeding, how can I force it to wait?</p>
<p>For example:</p>
<pre><code>#!/bin/bash
#... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,507 | bash | # Bash Script Calls another bash script and waits for it to complete before proceeding
I have 1 bash script that runs another bash script, however the first bashscript isn't waiting for the second one to complete before proceeding, how can I force it to wait?
For example:
```
#!/bin/bash
# first.sh
#call to seconda... | Normally it does; something else is happening. Are you sure that the other script isn't running something in the background instead? You can try using `wait` regardless. |
44840644 | How do I escape "Quotes" in a powershell string? | 34 | 2017-06-30 07:11:49 | <p>I need to send a simple string to a web api using Powershell, and I have to ensure the value in the HTML body has "Quotes" around it, because the content type has to be application/json.</p>
<p>For example:</p>
<pre><code>$specialKey = "101010"
Invoke-RestMethod -Method Put `
-Uri $keyAssignmentUri... | 63,608 | 22,702 | 2023-02-10 08:25:47 | 44,840,778 | 14 | 2017-06-30 07:19:17 | 2,796,058 | 2023-02-10 08:25:47 | https://stackoverflow.com/q/44840644 | https://stackoverflow.com/a/44840778 | <p>Assuming you don't need to do variable substitution in your string, a simple solution is to just surround it with single quotes to make it a literal string:</p>
<pre><code>$specialKey = '"101010"'
</code></pre>
| <p>Assuming you don't need to do variable substitution in your string, a simple solution is to just surround it with single quotes to make it a literal string:</p> <pre><code>$specialKey = '"101010"' </code></pre> | 364, 526 | powershell, rest | <h1>How do I escape "Quotes" in a powershell string?</h1>
<p>I need to send a simple string to a web api using Powershell, and I have to ensure the value in the HTML body has "Quotes" around it, because the content type has to be application/json.</p>
<p>For example:</p>
<pre><code>$specialKey = "101010"
Invoke-RestM... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,508 | bash | # How do I escape "Quotes" in a powershell string?
I need to send a simple string to a web api using Powershell, and I have to ensure the value in the HTML body has "Quotes" around it, because the content type has to be application/json.
For example:
```
$specialKey = "101010"
Invoke-RestMethod -Method Put `
... | Assuming you don't need to do variable substitution in your string, a simple solution is to just surround it with single quotes to make it a literal string:
```
$specialKey = '"101010"'
``` |
34157067 | How do I find the Azure PowerShell version? | 34 | 2015-12-08 13:24:28 | <p>I need to find the installed Azure PowerShell version through cmdlets code. How do I find the Azure PowerShell version?</p>
<p>Note: Other than cmdlets code is also welcome.</p>
| 73,786 | 3,186,681 | 2021-04-09 15:08:26 | 34,157,161 | 14 | 2015-12-08 13:28:45 | 3,186,681 | 2018-12-30 00:22:16 | https://stackoverflow.com/q/34157067 | https://stackoverflow.com/a/34157161 | <p>Use:</p>
<pre><code>(Get-Module azure).Version
</code></pre>
<p>This will return version of installed Azure PowerShell.</p>
<p><a href="https://i.sstatic.net/Fpazb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fpazb.png" alt="Azure PowerShell version"></a></p>
| <p>Use:</p> <pre><code>(Get-Module azure).Version </code></pre> <p>This will return version of installed Azure PowerShell.</p> <p><a href="https://i.sstatic.net/Fpazb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fpazb.png" alt="Azure PowerShell version"></a></p> | 526, 5792, 14158, 81879, 153947 | azure, azure-powershell, powershell, powershell-cmdlet, version | <h1>How do I find the Azure PowerShell version?</h1>
<p>I need to find the installed Azure PowerShell version through cmdlets code. How do I find the Azure PowerShell version?</p>
<p>Note: Other than cmdlets code is also welcome.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,509 | bash | # How do I find the Azure PowerShell version?
I need to find the installed Azure PowerShell version through cmdlets code. How do I find the Azure PowerShell version?
Note: Other than cmdlets code is also welcome. | Use:
```
(Get-Module azure).Version
```
This will return version of installed Azure PowerShell.
[](https://i.sstatic.net/Fpazb.png) |
11783280 | Downloading all the files in a directory with cURL | 34 | 2012-08-02 18:06:54 | <p>I am using cURL to try to download all files in a certain directory.</p>
<p>here's what my list of files looks like:</p>
<p><img src="https://i.sstatic.net/2r8xt.png" alt="enter image description here"></p>
<p>I have tried to do in bash script: <code>iiumlabs.[].csv.pgp</code> and <code>iiumlabs*</code> and I gue... | 190,495 | 117,700 | 2023-03-16 20:20:25 | 11,784,314 | 14 | 2012-08-02 19:18:16 | 165,333 | 2014-03-15 01:43:23 | https://stackoverflow.com/q/11783280 | https://stackoverflow.com/a/11784314 | <p>OK, considering that you are using Windows, the most simple way to do that is to use the standard <code>ftp</code> tool bundled with it. I base the following solution on Windows XP, hoping it'll work as well (or with minor modifications) on other versions.</p>
<p>First of all, you need to create a batch (script) fi... | <p>OK, considering that you are using Windows, the most simple way to do that is to use the standard <code>ftp</code> tool bundled with it. I base the following solution on Windows XP, hoping it'll work as well (or with minor modifications) on other versions.</p> <p>First of all, you need to create a batch (script) fi... | 261, 387, 390, 1290, 1554 | bash, curl, ftp, sftp, shell | <h1>Downloading all the files in a directory with cURL</h1>
<p>I am using cURL to try to download all files in a certain directory.</p>
<p>here's what my list of files looks like:</p>
<p><img src="https://i.sstatic.net/2r8xt.png" alt="enter image description here"></p>
<p>I have tried to do in bash script: <code>iiu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,510 | bash | # Downloading all the files in a directory with cURL
I am using cURL to try to download all files in a certain directory.
here's what my list of files looks like:

I have tried to do in bash script: `iiumlabs.[].csv.pgp` and `iiumlabs*` and I guess cur... | OK, considering that you are using Windows, the most simple way to do that is to use the standard `ftp` tool bundled with it. I base the following solution on Windows XP, hoping it'll work as well (or with minor modifications) on other versions.
First of all, you need to create a batch (script) file for the `ftp` prog... |
14434549 | How to expand shell variables in a text file? | 32 | 2013-01-21 08:04:55 | <p>Consider a ASCII text file (lets say it contains code of a non-shell scripting language):</p>
<p><strong>Text_File.msh:</strong></p>
<pre><code>spool on to '$LOG_FILE_PATH/logfile.log';
login 'username' 'password';
....
</code></pre>
<p>Now if this were a shell script I could run it as <code>$ sh Text_File.msh</c... | 35,367 | 985,766 | 2020-08-15 08:01:09 | 14,434,776 | 14 | 2013-01-21 08:23:44 | 459,745 | 2013-01-21 08:23:44 | https://stackoverflow.com/q/14434549 | https://stackoverflow.com/a/14434776 | <p>This solution is not elegant, but it works. Create a script call shell_expansion.sh:</p>
<pre><code>echo 'cat <<END_OF_TEXT' > temp.sh
cat "$1" >> temp.sh
echo 'END_OF_TEXT' >> temp.sh
bash temp.sh >> "$2"
rm temp.sh
</code></pre>
<p>You can then invoke this script... | <p>This solution is not elegant, but it works. Create a script call shell_expansion.sh:</p> <pre><code>echo 'cat <<END_OF_TEXT' > temp.sh cat "$1" >> temp.sh echo 'END_OF_TEXT' >> temp.sh bash temp.sh >> "$2" rm temp.sh </code></pre> <p>You can then invoke this script... | 34, 387, 390, 1964, 2635 | bash, ksh, shell, solaris, unix | <h1>How to expand shell variables in a text file?</h1>
<p>Consider a ASCII text file (lets say it contains code of a non-shell scripting language):</p>
<p><strong>Text_File.msh:</strong></p>
<pre><code>spool on to '$LOG_FILE_PATH/logfile.log';
login 'username' 'password';
....
</code></pre>
<p>Now if this were a she... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,511 | bash | # How to expand shell variables in a text file?
Consider a ASCII text file (lets say it contains code of a non-shell scripting language):
**Text_File.msh:**
```
spool on to '$LOG_FILE_PATH/logfile.log';
login 'username' 'password';
....
```
Now if this were a shell script I could run it as `$ sh Text_File.msh` and ... | This solution is not elegant, but it works. Create a script call shell_expansion.sh:
```
echo 'cat <<END_OF_TEXT' > temp.sh
cat "$1" >> temp.sh
echo 'END_OF_TEXT' >> temp.sh
bash temp.sh >> "$2"
rm temp.sh
```
You can then invoke this script as followed:
```
bash shell_expansion.sh Text_File.m... |
20398499 | Remove last argument from argument list of shell script (bash) | 31 | 2013-12-05 11:13:44 | <p>This question concerns a bash script that is run in automator osx. I am using automator actions to get and filter a bunch of file references from the finder. Then I append to that list the name of the parent folder, also via an automator action. Automator then feeds these arguments to an action called "run shell scr... | 22,409 | 1,047,256 | 2023-01-15 00:42:53 | 20,398,578 | 14 | 2013-12-05 11:18:14 | 2,235,132 | 2019-07-09 19:35:22 | https://stackoverflow.com/q/20398499 | https://stackoverflow.com/a/20398578 | <p>Assuming that you already have an <code>array</code>, you can say:</p>
<pre><code>unset "array[${#array[@]}-1]"
</code></pre>
<hr>
<p>For example, if your script contains:</p>
<pre><code>array=( "$@" )
unset "array[${#array[@]}-1]" # Removes last element -- also see: help unset
for i in "${array[@]}"; do
ec... | <p>Assuming that you already have an <code>array</code>, you can say:</p> <pre><code>unset "array[${#array[@]}-1]" </code></pre> <hr> <p>For example, if your script contains:</p> <pre><code>array=( "$@" ) unset "array[${#array[@]}-1]" # Removes last element -- also see: help unset for i in "${array[@]}"; do ec... | 387, 390, 8793, 18362 | argument-passing, automator, bash, shell | <h1>Remove last argument from argument list of shell script (bash)</h1>
<p>This question concerns a bash script that is run in automator osx. I am using automator actions to get and filter a bunch of file references from the finder. Then I append to that list the name of the parent folder, also via an automator action.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,512 | bash | # Remove last argument from argument list of shell script (bash)
This question concerns a bash script that is run in automator osx. I am using automator actions to get and filter a bunch of file references from the finder. Then I append to that list the name of the parent folder, also via an automator action. Automato... | Assuming that you already have an `array`, you can say:
```
unset "array[${#array[@]}-1]"
```
---
For example, if your script contains:
```
array=( "$@" )
unset "array[${#array[@]}-1]" # Removes last element -- also see: help unset
for i in "${array[@]}"; do
echo "$i"
done
```
invoking it with: `bash scriptna... |
9738535 | Powershell test for noninteractive mode | 31 | 2012-03-16 13:54:52 | <p>I have a script that may be run manually or may be run by a scheduled task. I need to programmatically determine if I'm running in -noninteractive mode (which is set when run via scheduled task) or normal mode. I've googled around and the best I can find is to add a command line parameter, but I don't have any feasi... | 39,371 | 160,888 | 2024-09-10 13:20:31 | 9,739,171 | 14 | 2012-03-16 14:32:45 | 520,612 | 2020-10-08 18:45:16 | https://stackoverflow.com/q/9738535 | https://stackoverflow.com/a/9739171 | <p>You can check how powershell was called using <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-wmiobject?view=powershell-5.1" rel="nofollow noreferrer"><strong><code>Get-WmiObject</code></strong></a> for WMI objects:</p>
<pre class="lang-bsh prettyprint-override"><code... | <p>You can check how powershell was called using <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-wmiobject?view=powershell-5.1" rel="nofollow noreferrer"><strong><code>Get-WmiObject</code></strong></a> for WMI objects:</p> <pre class="lang-bsh prettyprint-override"><code... | 526 | powershell | <h1>Powershell test for noninteractive mode</h1>
<p>I have a script that may be run manually or may be run by a scheduled task. I need to programmatically determine if I'm running in -noninteractive mode (which is set when run via scheduled task) or normal mode. I've googled around and the best I can find is to add a c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,513 | bash | # Powershell test for noninteractive mode
I have a script that may be run manually or may be run by a scheduled task. I need to programmatically determine if I'm running in -noninteractive mode (which is set when run via scheduled task) or normal mode. I've googled around and the best I can find is to add a command li... | You can check how powershell was called using [**`Get-WmiObject`**](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-wmiobject?view=powershell-5.1) for WMI objects:
```
(gwmi win32_process | ? { $_.processname -eq "powershell.exe" }) | select commandline
#commandline
#----------... |
23614039 | How to get the exit code of spawned process in expect shell script? | 30 | 2014-05-12 16:18:32 | <p>I am trying to execute a script that executes an EXPECT script and a spawned process which has exit code in it. But I'm unable to get the exit code of the spawned process to main script. I'm always getting zero as success.</p>
<p>expect script is :</p>
<pre><code> [Linux Dev:anr ]$ cat testexit.sh
#!/bin/bash
ex... | 38,586 | 2,955,867 | 2019-07-08 15:25:34 | 23,636,473 | 14 | 2014-05-13 16:13:47 | 2,955,867 | 2014-05-13 16:13:47 | https://stackoverflow.com/q/23614039 | https://stackoverflow.com/a/23636473 | <p>With the help of glenn, I got solution.. and my final script is::</p>
<p>expect script is</p>
<pre><code> [Linux Dev:anr ]$ cat testexit.sh
#!/bin/bash
export tmp_script_file="/home/anr/tmp_script_temp.sh"
cp /home/anr/tmp_script $tmp_script_file
chmod a+x $tmp_script_file
cat $tmp_script_file
expect <<... | <p>With the help of glenn, I got solution.. and my final script is::</p> <p>expect script is</p> <pre><code> [Linux Dev:anr ]$ cat testexit.sh #!/bin/bash export tmp_script_file="/home/anr/tmp_script_temp.sh" cp /home/anr/tmp_script $tmp_script_file chmod a+x $tmp_script_file cat $tmp_script_file expect <<... | 34, 58, 387, 390, 9048 | bash, expect, linux, shell, unix | <h1>How to get the exit code of spawned process in expect shell script?</h1>
<p>I am trying to execute a script that executes an EXPECT script and a spawned process which has exit code in it. But I'm unable to get the exit code of the spawned process to main script. I'm always getting zero as success.</p>
<p>expect sc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,514 | bash | # How to get the exit code of spawned process in expect shell script?
I am trying to execute a script that executes an EXPECT script and a spawned process which has exit code in it. But I'm unable to get the exit code of the spawned process to main script. I'm always getting zero as success.
expect script is :
```
... | With the help of glenn, I got solution.. and my final script is::
expect script is
```
[Linux Dev:anr ]$ cat testexit.sh
#!/bin/bash
export tmp_script_file="/home/anr/tmp_script_temp.sh"
cp /home/anr/tmp_script $tmp_script_file
chmod a+x $tmp_script_file
cat $tmp_script_file
expect << 'EOF'
set timeout -1
sp... |
8747845 | How can I detect BSD vs. GNU version of date in shell script | 30 | 2012-01-05 18:35:48 | <p>I am writing a shell script that needs to do some date string manipulation. The script should work across as many *nix variants as possible, so I need to handle situations where the machine might have the BSD or the GNU version of date.</p>
<p>What would be the most elegant way to test for the OS type, so I can sen... | 7,257 | 45,838 | 2022-01-21 16:06:05 | 8,748,193 | 14 | 2012-01-05 19:01:11 | 140,750 | 2022-01-21 16:06:05 | https://stackoverflow.com/q/8747845 | https://stackoverflow.com/a/8748193 | <p>Use portable flags. The standard is available <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html" rel="nofollow noreferrer"> here </a></p>
<p>For the particular problem of printing a relative date, it is probably easier to use perl than date:</p>
<pre><code>perl -E 'say scalar localtime(ti... | <p>Use portable flags. The standard is available <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html" rel="nofollow noreferrer"> here </a></p> <p>For the particular problem of printing a relative date, it is probably easier to use perl than date:</p> <pre><code>perl -E 'say scalar localtime(ti... | 390, 1423, 4072, 5002 | bsd, date, gnu, shell | <h1>How can I detect BSD vs. GNU version of date in shell script</h1>
<p>I am writing a shell script that needs to do some date string manipulation. The script should work across as many *nix variants as possible, so I need to handle situations where the machine might have the BSD or the GNU version of date.</p>
<p>Wh... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,515 | bash | # How can I detect BSD vs. GNU version of date in shell script
I am writing a shell script that needs to do some date string manipulation. The script should work across as many *nix variants as possible, so I need to handle situations where the machine might have the BSD or the GNU version of date.
What would be the ... | Use portable flags. The standard is available [here](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html)
For the particular problem of printing a relative date, it is probably easier to use perl than date:
```
perl -E 'say scalar localtime(time - 86400)'
```
(note that this solution utterly fails o... |
56032478 | How do you get Windows PowerShell to play a sound after .bat job has finished running? | 29 | 2019-05-08 01:48:09 | <p>As the title states, I have a <code>.bat</code> job running within PowerShell that when finished running, I would like a sound notification to go off. I was wondering if there was a PowerShell command that I can add to my existing PowerShell command.</p>
| 23,608 | 4,438,012 | 2023-11-23 21:44:57 | 56,032,635 | 14 | 2019-05-08 02:13:09 | 2,975,396 | 2019-05-08 02:13:09 | https://stackoverflow.com/q/56032478 | https://stackoverflow.com/a/56032635 | <p>you could use powershell automatic variables to check bat file status ..As per <a href="https://stackoverflow.com/a/8693888/2975396">this</a>,<code>$?</code> returns true ,if command is successfull..</p>
<p>below is sample code</p>
<pre><code>$a =Invoke-Command -ScriptBlock {
& "C:\temp1\test.bat"
}
if($?){... | <p>you could use powershell automatic variables to check bat file status ..As per <a href="https://stackoverflow.com/a/8693888/2975396">this</a>,<code>$?</code> returns true ,if command is successfull..</p> <p>below is sample code</p> <pre><code>$a =Invoke-Command -ScriptBlock { & "C:\temp1\test.bat" } if($?){... | 348, 526, 995, 25907 | audio, beep, notifications, powershell | <h1>How do you get Windows PowerShell to play a sound after .bat job has finished running?</h1>
<p>As the title states, I have a <code>.bat</code> job running within PowerShell that when finished running, I would like a sound notification to go off. I was wondering if there was a PowerShell command that I can add to my... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,516 | bash | # How do you get Windows PowerShell to play a sound after .bat job has finished running?
As the title states, I have a `.bat` job running within PowerShell that when finished running, I would like a sound notification to go off. I was wondering if there was a PowerShell command that I can add to my existing PowerShell... | you could use powershell automatic variables to check bat file status ..As per [this](https://stackoverflow.com/a/8693888/2975396),`$?` returns true ,if command is successfull..
below is sample code
```
$a =Invoke-Command -ScriptBlock {
& "C:\temp1\test.bat"
}
if($?){
[console]::beep(500,300)
}
```
You could als... |
8677504 | Setting environment variable globally without restarting Ubuntu | 29 | 2011-12-30 08:15:51 | <p>I know that system wide environment variables can be set by adding entries into</p>
<pre><code>/etc/environment
</code></pre>
<p>or</p>
<pre><code>/etc/profile
</code></pre>
<p>But that requires system restart or X restart.</p>
<p>Is it possible to set an environment variable in Ubuntu / Linux so that immediate... | 34,191 | 341,268 | 2018-01-02 13:37:59 | 16,462,131 | 14 | 2013-05-09 12:46:51 | 1,153,938 | 2013-05-10 11:10:08 | https://stackoverflow.com/q/8677504 | https://stackoverflow.com/a/16462131 | <p>This perl program uses gdb to change the USER variable in all currently running bash shells to whatever is given as the program arg. To set a new variable the internal bash call "set_if_not" could be used</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
my @pids = qx(ps -C bash -o pid=);
my $foo = $ARGV... | <p>This perl program uses gdb to change the USER variable in all currently running bash shells to whatever is given as the program arg. To set a new variable the internal bash call "set_if_not" could be used</p> <pre><code>#!/usr/bin/perl use strict; use warnings; my @pids = qx(ps -C bash -o pid=); my $foo = $ARGV... | 58, 387, 390, 549 | bash, linux, shell, ubuntu | <h1>Setting environment variable globally without restarting Ubuntu</h1>
<p>I know that system wide environment variables can be set by adding entries into</p>
<pre><code>/etc/environment
</code></pre>
<p>or</p>
<pre><code>/etc/profile
</code></pre>
<p>But that requires system restart or X restart.</p>
<p>Is it po... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,517 | bash | # Setting environment variable globally without restarting Ubuntu
I know that system wide environment variables can be set by adding entries into
```
/etc/environment
```
or
```
/etc/profile
```
But that requires system restart or X restart.
Is it possible to set an environment variable in Ubuntu / Linux so that ... | This perl program uses gdb to change the USER variable in all currently running bash shells to whatever is given as the program arg. To set a new variable the internal bash call "set_if_not" could be used
```
#!/usr/bin/perl
use strict;
use warnings;
my @pids = qx(ps -C bash -o pid=);
my $foo = $ARGV[0];
print "cha... |
7254509 | How can I escape single quotes in Bash/Grep? | 29 | 2011-08-31 08:37:34 | <p>I want to search with grep for a string that looks like this:</p>
<pre><code>something ~* 'bla'
</code></pre>
<p>I tried this, but the shell removes the single quotes. Argh...</p>
<pre><code>grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
</code></pre>
<p>What would be the correct search?</p>
| 42,614 | 906,738 | 2023-12-07 00:11:44 | 7,254,616 | 14 | 2011-08-31 08:48:34 | 520,162 | 2011-08-31 08:55:03 | https://stackoverflow.com/q/7254509 | https://stackoverflow.com/a/7254616 | <pre><code>grep -i "something ~\* '[[:alnum:]]*'" /var/log/syslog
</code></pre>
<p>works for me.</p>
<ul>
<li>escape the first <code>*</code> to match a literal <code>*</code> instead of making it the zero-or-more-matches character:<br>
<code>~*</code> would match zero or more occurrences of <code>~</code> while<br>
... | <pre><code>grep -i "something ~\* '[[:alnum:]]*'" /var/log/syslog </code></pre> <p>works for me.</p> <ul> <li>escape the first <code>*</code> to match a literal <code>*</code> instead of making it the zero-or-more-matches character:<br> <code>~*</code> would match zero or more occurrences of <code>~</code> while<br> ... | 58, 387, 1271, 4804 | bash, escaping, grep, linux | <h1>How can I escape single quotes in Bash/Grep?</h1>
<p>I want to search with grep for a string that looks like this:</p>
<pre><code>something ~* 'bla'
</code></pre>
<p>I tried this, but the shell removes the single quotes. Argh...</p>
<pre><code>grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
</code></... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,518 | bash | # How can I escape single quotes in Bash/Grep?
I want to search with grep for a string that looks like this:
```
something ~* 'bla'
```
I tried this, but the shell removes the single quotes. Argh...
```
grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
```
What would be the correct search? | ```
grep -i "something ~\* '[[:alnum:]]*'" /var/log/syslog
```
works for me.
- escape the first `*` to match a literal `*` instead of making it the zero-or-more-matches character:
`~*` would match zero or more occurrences of `~` while
`~\*` matches the expression `~*` after `something`
- use double brackets a... |
5789526 | Log rotating with a Bash script | 28 | 2011-04-26 11:18:47 | <p>I have the following issue: </p>
<p>I have an application, which continuously produces output to stderr and stdout. The output of this application is captured in a logfile (the app is redirected as: <code>&> log.txt</code> ). I don't have any options to produce a proper logging to file for this.</p>
<p>Now,... | 59,218 | 186,193 | 2023-05-16 10:52:39 | 5,793,272 | 14 | 2011-04-26 16:20:32 | 149,900 | 2017-02-14 04:08:31 | https://stackoverflow.com/q/5789526 | https://stackoverflow.com/a/5793272 | <p>Okay, here's an idea, inspired by <a href="http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams" rel="nofollow noreferrer">http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams</a></p>
<ol>
<li><p>make a named pipe:</p>
<pre><code>mkfifo /dev/mypipe
</code></pre></li>
<li><p>redire... | <p>Okay, here's an idea, inspired by <a href="http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams" rel="nofollow noreferrer">http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams</a></p> <ol> <li><p>make a named pipe:</p> <pre><code>mkfifo /dev/mypipe </code></pre></li> <li><p>redire... | 387, 942, 8403 | bash, logging, rotation | <h1>Log rotating with a Bash script</h1>
<p>I have the following issue: </p>
<p>I have an application, which continuously produces output to stderr and stdout. The output of this application is captured in a logfile (the app is redirected as: <code>&> log.txt</code> ). I don't have any options to produce a prop... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,519 | bash | # Log rotating with a Bash script
I have the following issue:
I have an application, which continuously produces output to stderr and stdout. The output of this application is captured in a logfile (the app is redirected as: `&> log.txt` ). I don't have any options to produce a proper logging to file for this.
Now, ... | Okay, here's an idea, inspired by <http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams>
1. make a named pipe:
```
mkfifo /dev/mypipe
```
2. redirect stdout and stderr to the named pipe:
```
&> /dev/mypipe
```
3. read from mypipe into a file:
```
cat < /dev/mypipe > /var/log... |
3918032 | Bash, serial I/O and Arduino | 28 | 2010-10-12 18:54:54 | <p>So, I'm in a bit over my head, and I feel like I'm very close to a solution, but it's just not working quite yet. Here's my situation:</p>
<p>I'm working with an Arduino microcontroller, and I'm attempting to write two Bash scripts (right now running in Mac OS X 10.6) which will (a) print all serial data ... | 65,008 | 174,578 | 2016-05-06 14:47:16 | 3,926,278 | 14 | 2010-10-13 17:23:00 | 40,411 | 2012-02-19 12:56:28 | https://stackoverflow.com/q/3918032 | https://stackoverflow.com/a/3926278 | <p>Try using the tool <a href="http://tldp.org/HOWTO/Serial-HOWTO-12.html#ss12.4" rel="noreferrer">stty</a>:</p>
<pre><code>stty -F /dev/my_serial_port <baud_rate> cs8 cread clocal
</code></pre>
<p>As always, read the manpage before applying the above. <code>cread</code> allows you to receive data. You may wan... | <p>Try using the tool <a href="http://tldp.org/HOWTO/Serial-HOWTO-12.html#ss12.4" rel="noreferrer">stty</a>:</p> <pre><code>stty -F /dev/my_serial_port <baud_rate> cs8 cread clocal </code></pre> <p>As always, read the manpage before applying the above. <code>cread</code> allows you to receive data. You may wan... | 387, 1231, 3716, 5948 | arduino, bash, command-line, serial-port | <h1>Bash, serial I/O and Arduino</h1>
<p>So, I'm in a bit over my head, and I feel like I'm very close to a solution, but it's just not working quite yet. Here's my situation:</p>
<p>I'm working with an Arduino microcontroller, and I'm attempting to write two Bash scripts (right now running in Mac OS X 10.6)... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,520 | bash | # Bash, serial I/O and Arduino
So, I'm in a bit over my head, and I feel like I'm very close to a solution, but it's just not working quite yet. Here's my situation:
I'm working with an Arduino microcontroller, and I'm attempting to write two Bash scripts (right now running in Mac OS X 10.6) which will (a) print all ... | Try using the tool [stty](http://tldp.org/HOWTO/Serial-HOWTO-12.html#ss12.4):
```
stty -F /dev/my_serial_port <baud_rate> cs8 cread clocal
```
As always, read the manpage before applying the above. `cread` allows you to receive data. You may want to omit `clocal` if you are using flow control. If you aren't sure what... |
3332045 | bash: force exec'd process to have unbuffered stdout | 28 | 2010-07-26 03:27:54 | <p>I've got a script like:</p>
<pre><code>#!/bin/bash
exec /usr/bin/some_binary > /tmp/my.log 2>&1
</code></pre>
<p>Problem is that <code>some_binary</code> sends all of its logging to stdout, and buffering makes it so that I only see output in chunks of a few lines. This is annoying when something gets stu... | 22,458 | 67,022 | 2018-09-07 19:47:44 | 3,332,061 | 14 | 2010-07-26 03:35:14 | 26,428 | 2010-07-26 08:23:17 | https://stackoverflow.com/q/3332045 | https://stackoverflow.com/a/3332061 | <p>You might find that the <code>unbuffer</code> script that comes with <a href="http://expect.sourceforge.net/" rel="noreferrer"><code>expect</code></a> may help.</p>
| <p>You might find that the <code>unbuffer</code> script that comes with <a href="http://expect.sourceforge.net/" rel="noreferrer"><code>expect</code></a> may help.</p> | 387, 942, 7932, 43431 | bash, exec, logging, unbuffered-output | <h1>bash: force exec'd process to have unbuffered stdout</h1>
<p>I've got a script like:</p>
<pre><code>#!/bin/bash
exec /usr/bin/some_binary > /tmp/my.log 2>&1
</code></pre>
<p>Problem is that <code>some_binary</code> sends all of its logging to stdout, and buffering makes it so that I only see output in c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,521 | bash | # bash: force exec'd process to have unbuffered stdout
I've got a script like:
```
#!/bin/bash
exec /usr/bin/some_binary > /tmp/my.log 2>&1
```
Problem is that `some_binary` sends all of its logging to stdout, and buffering makes it so that I only see output in chunks of a few lines. This is annoying when something ... | You might find that the `unbuffer` script that comes with [`expect`](http://expect.sourceforge.net/) may help. |
15919347 | How To Execute Windows Shell Commands (Cmd.exe) with Node JS | 26 | 2013-04-10 07:16:08 | <p>I would like to</p>
<pre><code>C:\>ACommandThatGetsData > save.txt
</code></pre>
<p>But instead of parsing and saving the data in the console, I would like to do the above command with <strong>Node.JS</strong></p>
<p>How to execute a shell command with <strong>Node.JS</strong>?</p>
| 64,450 | 1,299,659 | 2023-10-11 12:22:53 | 45,844,825 | 14 | 2017-08-23 16:18:47 | 679,240 | 2023-10-11 12:22:53 | https://stackoverflow.com/q/15919347 | https://stackoverflow.com/a/45844825 | <p>You could also try the <a href="https://www.npmjs.com/package/node-cmd" rel="nofollow noreferrer">node-cmd</a> package:</p>
<pre><code>const nodeCmd = require('node-cmd');
nodeCmd.get('dir', (err, data, stderr) => console.log(data));
</code></pre>
<p>On newer versions of the package, the syntax changed a little:<... | <p>You could also try the <a href="https://www.npmjs.com/package/node-cmd" rel="nofollow noreferrer">node-cmd</a> package:</p> <pre><code>const nodeCmd = require('node-cmd'); nodeCmd.get('dir', (err, data, stderr) => console.log(data)); </code></pre> <p>On newer versions of the package, the syntax changed a little:<... | 2631, 8123, 46426 | cmd, node.js, windows-shell | <h1>How To Execute Windows Shell Commands (Cmd.exe) with Node JS</h1>
<p>I would like to</p>
<pre><code>C:\>ACommandThatGetsData > save.txt
</code></pre>
<p>But instead of parsing and saving the data in the console, I would like to do the above command with <strong>Node.JS</strong></p>
<p>How to execute a shel... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,522 | bash | # How To Execute Windows Shell Commands (Cmd.exe) with Node JS
I would like to
```
C:\>ACommandThatGetsData > save.txt
```
But instead of parsing and saving the data in the console, I would like to do the above command with **Node.JS**
How to execute a shell command with **Node.JS**? | You could also try the [node-cmd](https://www.npmjs.com/package/node-cmd) package:
```
const nodeCmd = require('node-cmd');
nodeCmd.get('dir', (err, data, stderr) => console.log(data));
```
On newer versions of the package, the syntax changed a little:
```
const nodeCmd = require('node-cmd');
nodeCmd.run('dir', (err... |
9907200 | How to minify/obfuscate a bash script | 26 | 2012-03-28 12:10:27 | <p>Of course a bash file cannot be truly obfuscated and will always be readable. And I don't want to wrap them in some binary package.
And renaming local variables wouldn't be worth the trouble.</p>
<p>But is there a reliable simple bash obfuscator or minifier which at least removes all the indentation, all the empty ... | 62,276 | 20,088 | 2017-07-19 12:54:25 | 43,980,200 | 14 | 2017-05-15 12:58:08 | 4,074,806 | 2017-05-15 16:25:51 | https://stackoverflow.com/q/9907200 | https://stackoverflow.com/a/43980200 | <p>Here is a tool that I created for bash scripts minification: <a href="https://github.com/precious/bash_minifier" rel="noreferrer">https://github.com/precious/bash_minifier</a> – it tries to remove all comments and as many spaces/tabs/newlines as possible. It is also available as a service here <a href="http://bash-m... | <p>Here is a tool that I created for bash scripts minification: <a href="https://github.com/precious/bash_minifier" rel="noreferrer">https://github.com/precious/bash_minifier</a> – it tries to remove all comments and as many spaces/tabs/newlines as possible. It is also available as a service here <a href="http://bash-m... | 387, 390, 516, 13347 | bash, minify, obfuscation, shell | <h1>How to minify/obfuscate a bash script</h1>
<p>Of course a bash file cannot be truly obfuscated and will always be readable. And I don't want to wrap them in some binary package.
And renaming local variables wouldn't be worth the trouble.</p>
<p>But is there a reliable simple bash obfuscator or minifier which at le... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,523 | bash | # How to minify/obfuscate a bash script
Of course a bash file cannot be truly obfuscated and will always be readable. And I don't want to wrap them in some binary package.
And renaming local variables wouldn't be worth the trouble.
But is there a reliable simple bash obfuscator or minifier which at least removes all ... | Here is a tool that I created for bash scripts minification: <https://github.com/precious/bash_minifier> – it tries to remove all comments and as many spaces/tabs/newlines as possible. It is also available as a service here [https://bash-minifier.appspot.com/](http://bash-minifier.appspot.com/).
To minify your bash sc... |
24508040 | Use Bash variable within SLURM sbatch script | 25 | 2014-07-01 10:31:34 | <p>I'm trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced.</p>
<p>Here is the script:</p>
<pre><code>#!/bin/bash
# This reads out the number of procs based on the decomposeParDi... | 20,150 | 1,089,823 | 2021-02-16 22:48:13 | 24,510,022 | 14 | 2014-07-01 12:14:46 | 75,652 | 2014-07-01 12:14:46 | https://stackoverflow.com/q/24508040 | https://stackoverflow.com/a/24510022 | <p>This won't work. What happens when you run </p>
<p><code>sbatch myscript.sh</code></p>
<p>is that slurm parses the script for those special #SBATCH lines, generates a job record, stores the batch script somewhere. The batch script is executed only later when the job runs.</p>
<p>So you need to structure you workf... | <p>This won't work. What happens when you run </p> <p><code>sbatch myscript.sh</code></p> <p>is that slurm parses the script for those special #SBATCH lines, generates a job record, stores the batch script somewhere. The batch script is executed only later when the job runs.</p> <p>So you need to structure you workf... | 58, 387, 390, 990, 97759 | awk, bash, linux, shell, slurm | <h1>Use Bash variable within SLURM sbatch script</h1>
<p>I'm trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced.</p>
<p>Here is the script:</p>
<pre><code>#!/bin/bash
# This rea... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,524 | bash | # Use Bash variable within SLURM sbatch script
I'm trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced.
Here is the script:
```
#!/bin/bash
# This reads out the number of procs ... | This won't work. What happens when you run
`sbatch myscript.sh`
is that slurm parses the script for those special #SBATCH lines, generates a job record, stores the batch script somewhere. The batch script is executed only later when the job runs.
So you need to structure you workflow in a slightly different way, and... |
6565694 | Inform right-hand side of pipeline of left-side failure? | 25 | 2011-07-03 21:33:12 | <p>I've grown fond of using a generator-like pattern between functions in my shell scripts. Something like this:</p>
<pre><code>parse_commands /da/cmd/file | process_commands
</code></pre>
<p>However, the basic problem with this pattern is that if parse_command encounters an error, the only way I have found to notify... | 8,491 | 205,674 | 2018-08-29 19:51:56 | 6,566,171 | 14 | 2011-07-03 23:21:18 | 368,630 | 2015-02-09 20:43:46 | https://stackoverflow.com/q/6565694 | https://stackoverflow.com/a/6566171 | <p>Does the pipe process continue even if the first process has ended, or is the issue that you have no way of knowing that the first process failed?</p>
<p>If it's the latter, you can look at the <code>PIPESTATUS</code> variable (which is actually a BASH array). That will give you the exit code of the first command:<... | <p>Does the pipe process continue even if the first process has ended, or is the issue that you have no way of knowing that the first process failed?</p> <p>If it's the latter, you can look at the <code>PIPESTATUS</code> variable (which is actually a BASH array). That will give you the exit code of the first command:<... | 387, 2844, 5813 | bash, pipe, pipeline | <h1>Inform right-hand side of pipeline of left-side failure?</h1>
<p>I've grown fond of using a generator-like pattern between functions in my shell scripts. Something like this:</p>
<pre><code>parse_commands /da/cmd/file | process_commands
</code></pre>
<p>However, the basic problem with this pattern is that if pars... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,525 | bash | # Inform right-hand side of pipeline of left-side failure?
I've grown fond of using a generator-like pattern between functions in my shell scripts. Something like this:
```
parse_commands /da/cmd/file | process_commands
```
However, the basic problem with this pattern is that if parse_command encounters an error, th... | Does the pipe process continue even if the first process has ended, or is the issue that you have no way of knowing that the first process failed?
If it's the latter, you can look at the `PIPESTATUS` variable (which is actually a BASH array). That will give you the exit code of the first command:
```
parse_commands /... |
39371572 | Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs | 24 | 2016-09-07 13:43:22 | <p>When trying to send a message using AWS CLI for SQS, I cannot get the shorthand syntax for the <code>--message-attributes</code> parameter to work.</p>
<p>Specifying a json file works fine, and the reference doesn't show an example for the shorthand option.</p>
<p>Here is the reference for this command which speci... | 19,818 | 1,051,239 | 2022-07-10 20:54:56 | 61,577,092 | 14 | 2020-05-03 15:34:54 | 601,844 | 2022-07-10 20:54:56 | https://stackoverflow.com/q/39371572 | https://stackoverflow.com/a/61577092 | <h1>Your Shorthand Syntax format is correct:</h1>
<blockquote>
<p><strong>MY_KEY</strong>={DataType=<strong>String</strong>, StringValue=<strong>MY_VALUE</strong>}</p>
</blockquote>
<p>You just forgot to enclose the commandline option with single or double quotes:</p>
<pre><code>aws sqs send-message \
--queue-url htt... | <h1>Your Shorthand Syntax format is correct:</h1> <blockquote> <p><strong>MY_KEY</strong>={DataType=<strong>String</strong>, StringValue=<strong>MY_VALUE</strong>}</p> </blockquote> <p>You just forgot to enclose the commandline option with single or double quotes:</p> <pre><code>aws sqs send-message \ --queue-url htt... | 387, 32457, 33388, 99166 | amazon-sqs, amazon-web-services, aws-cli, bash | <h1>Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs</h1>
<p>When trying to send a message using AWS CLI for SQS, I cannot get the shorthand syntax for the <code>--message-attributes</code> parameter to work.</p>
<p>Specifying a json file works fine, and the reference doesn't show... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,526 | bash | # Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs
When trying to send a message using AWS CLI for SQS, I cannot get the shorthand syntax for the `--message-attributes` parameter to work.
Specifying a json file works fine, and the reference doesn't show an example for the shortha... | # Your Shorthand Syntax format is correct:
> **MY_KEY**={DataType=**String**, StringValue=**MY_VALUE**}
You just forgot to enclose the commandline option with single or double quotes:
```
aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name \
--message-body "message bod... |
29422799 | Setting variables with spaces within .env | 24 | 2015-04-02 21:29:21 | <p>I have a <code>.env</code> file with a bunch of variables and I just came across an error.</p>
<p>One of the variables has spaces.</p>
<pre><code>TEST="hello world"
</code></pre>
<p>So when I run this, <a href="https://stackoverflow.com/a/29355840/340688">learned about in this answer here.</a></p>
<pre><code>env... | 42,497 | 340,688 | 2021-02-18 11:20:10 | 29,422,860 | 14 | 2015-04-02 21:33:57 | 4,024,473 | 2015-04-02 21:43:38 | https://stackoverflow.com/q/29422799 | https://stackoverflow.com/a/29422860 | <p>If your command is just a shell command, you could run your command in a subshell like this:</p>
<pre><code>( . .env ; echo "$TEST" )
</code></pre>
<p>The <code>source</code> or <code>.</code> builtin has no problem with assignments containing spaces. It will set the variables in the <code>.env</code> file in the ... | <p>If your command is just a shell command, you could run your command in a subshell like this:</p> <pre><code>( . .env ; echo "$TEST" ) </code></pre> <p>The <code>source</code> or <code>.</code> builtin has no problem with assignments containing spaces. It will set the variables in the <code>.env</code> file in the ... | 387, 3637, 9013 | bash, env, environment-variables | <h1>Setting variables with spaces within .env</h1>
<p>I have a <code>.env</code> file with a bunch of variables and I just came across an error.</p>
<p>One of the variables has spaces.</p>
<pre><code>TEST="hello world"
</code></pre>
<p>So when I run this, <a href="https://stackoverflow.com/a/29355840/340688">learned... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,527 | bash | # Setting variables with spaces within .env
I have a `.env` file with a bunch of variables and I just came across an error.
One of the variables has spaces.
```
TEST="hello world"
```
So when I run this, [learned about in this answer here.](https://stackoverflow.com/a/29355840/340688)
```
env $(<.env)
```
I get t... | If your command is just a shell command, you could run your command in a subshell like this:
```
( . .env ; echo "$TEST" )
```
The `source` or `.` builtin has no problem with assignments containing spaces. It will set the variables in the `.env` file in the current shell's environment.
In the more likely case of cal... |
14177700 | Copy current command at bash prompt to clipboard | 24 | 2013-01-05 23:46:45 | <p>I would like a quick keyboard command sequence to copy the current command at a bash prompt to the clipboard. </p>
<p>So that, for example, to copy the last bash command to the clipboard, I'd press up+<code>[some command sequence]</code> to copy it. Or, for example, to search for a command in bash hisory, I'd use c... | 12,694 | 822,162 | 2022-04-18 09:13:58 | 14,178,540 | 14 | 2013-01-06 02:01:13 | 822,162 | 2013-01-07 08:08:42 | https://stackoverflow.com/q/14177700 | https://stackoverflow.com/a/14178540 | <p>Taking @Lauri's post for inspiration, here's a solution using the bind command:</p>
<pre><code>bind '"\C-]":"\C-e\C-u pbcopy <<"EOF"\n\C-y\nEOF\n"'
</code></pre>
<p>ctrl-] then will copy whatever is on the current bash prompt to the clipboard.</p>
<p>To make it persistent, you can add the bind command as ab... | <p>Taking @Lauri's post for inspiration, here's a solution using the bind command:</p> <pre><code>bind '"\C-]":"\C-e\C-u pbcopy <<"EOF"\n\C-y\nEOF\n"' </code></pre> <p>ctrl-] then will copy whatever is on the current bash prompt to the clipboard.</p> <p>To make it persistent, you can add the bind command as ab... | 369, 387 | bash, macos | <h1>Copy current command at bash prompt to clipboard</h1>
<p>I would like a quick keyboard command sequence to copy the current command at a bash prompt to the clipboard. </p>
<p>So that, for example, to copy the last bash command to the clipboard, I'd press up+<code>[some command sequence]</code> to copy it. Or, for ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,528 | bash | # Copy current command at bash prompt to clipboard
I would like a quick keyboard command sequence to copy the current command at a bash prompt to the clipboard.
So that, for example, to copy the last bash command to the clipboard, I'd press up+`[some command sequence]` to copy it. Or, for example, to search for a com... | Taking @Lauri's post for inspiration, here's a solution using the bind command:
```
bind '"\C-]":"\C-e\C-u pbcopy <<"EOF"\n\C-y\nEOF\n"'
```
ctrl-] then will copy whatever is on the current bash prompt to the clipboard.
To make it persistent, you can add the bind command as above to your `~/.bashrc`, or you can stri... |
45765276 | Getting "numeric argument required" when running a script with arithmetic operations | 23 | 2017-08-18 21:28:53 | <p>I'm trying to write a function that is supposed to convert a time stamp of the form hr:min:sec,ms (i.e 15:41:47,757) to milliseconds. The function is the following:</p>
<pre><code>#!/bin/sh
mili () {
hr=$(echo "$1" | cut -c1-2)
echo "hr is: " $hr
min=$(echo "$1" | cut -c4-5... | 78,635 | 5,158,073 | 2021-11-28 03:54:06 | 45,765,439 | 14 | 2017-08-18 21:46:50 | 3,030,305 | 2021-11-28 03:54:06 | https://stackoverflow.com/q/45765276 | https://stackoverflow.com/a/45765439 | <p>Inside arithmetic, <code>*</code> does not need to be escaped. Also, some parentheses were missing. Thus, replace:</p>
<pre><code>total=$(($hr \* 3600 + $min \* 60 + $sec) \* 1000 + $ms)
</code></pre>
<p>With:</p>
<pre><code>total=$((($hr * 3600 + $min * 60 + $sec) * 1000 + $ms))
</code></pre>
<h3>Alternative</h3>... | <p>Inside arithmetic, <code>*</code> does not need to be escaped. Also, some parentheses were missing. Thus, replace:</p> <pre><code>total=$(($hr \* 3600 + $min \* 60 + $sec) \* 1000 + $ms) </code></pre> <p>With:</p> <pre><code>total=$((($hr * 3600 + $min * 60 + $sec) * 1000 + $ms)) </code></pre> <h3>Alternative</h3>... | 390, 10327 | sh, shell | <h1>Getting "numeric argument required" when running a script with arithmetic operations</h1>
<p>I'm trying to write a function that is supposed to convert a time stamp of the form hr:min:sec,ms (i.e 15:41:47,757) to milliseconds. The function is the following:</p>
<pre><code>#!/bin/sh
mili () {
hr=$(echo "$1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,529 | bash | # Getting "numeric argument required" when running a script with arithmetic operations
I'm trying to write a function that is supposed to convert a time stamp of the form hr:min:sec,ms (i.e 15:41:47,757) to milliseconds. The function is the following:
```
#!/bin/sh
mili () {
hr=$(echo "$1" | cut -c1-2)
echo ... | Inside arithmetic, `*` does not need to be escaped. Also, some parentheses were missing. Thus, replace:
```
total=$(($hr \* 3600 + $min \* 60 + $sec) \* 1000 + $ms)
```
With:
```
total=$((($hr * 3600 + $min * 60 + $sec) * 1000 + $ms))
```
### Alternative
The code can be simplified avoiding the need for multiple ca... |
43165762 | How to get file contents by inode in Bash? | 23 | 2017-04-02 07:29:49 | <p>How can I retrieve file contents in Bash by knowing only the inode of the file?</p>
| 19,946 | 619,271 | 2021-06-01 18:28:36 | 43,165,863 | 14 | 2017-04-02 07:42:27 | 2,667,536 | 2017-04-02 12:26:28 | https://stackoverflow.com/q/43165762 | https://stackoverflow.com/a/43165863 | <p>As per <a href="https://unix.stackexchange.com/a/204724/174821">this unixexchange answer</a>:</p>
<blockquote>
<p>You cannot access files by inodes, because that would break access control via permissions. For example, if you don't have the permission to traverse a directory, then you can't access any of the file... | <p>As per <a href="https://unix.stackexchange.com/a/204724/174821">this unixexchange answer</a>:</p> <blockquote> <p>You cannot access files by inodes, because that would break access control via permissions. For example, if you don't have the permission to traverse a directory, then you can't access any of the file... | 99, 387, 2135 | bash, filesystems, inode | <h1>How to get file contents by inode in Bash?</h1>
<p>How can I retrieve file contents in Bash by knowing only the inode of the file?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,530 | bash | # How to get file contents by inode in Bash?
How can I retrieve file contents in Bash by knowing only the inode of the file? | As per [this unixexchange answer](https://unix.stackexchange.com/a/204724/174821):
> You cannot access files by inodes, because that would break access control via permissions. For example, if you don't have the permission to traverse a directory, then you can't access any of the files in that directory no matter what... |
25358698 | Parse HTML using shell | 23 | 2014-08-18 08:01:05 | <p>I have a HTML with lots of data and part I am interested in:</p>
<pre><code><tr valign=top>
<td><b>Total</b></td>
<td align=right><b>54</b></td>
<td align=right><b>1</b></td>
<td align=right>0 (0/0)</td>
<td align=right>... | 58,882 | 2,873,779 | 2023-07-27 21:41:24 | 25,358,940 | 14 | 2014-08-18 08:16:42 | 445,221 | 2014-08-18 09:41:10 | https://stackoverflow.com/q/25358698 | https://stackoverflow.com/a/25358940 | <pre><code>awk -F '[<>]' '/<td / { gsub(/<b>/, ""); sub(/ .*/, "", $3); print $3 } ' file
</code></pre>
<p>Output:</p>
<pre><code>54
1
0
0
</code></pre>
<p>Another:</p>
<pre><code>awk -F '[<>]' '
/<td><b>Total<\/b><\/td>/ {
while (getline > 0 && /<td ... | <pre><code>awk -F '[<>]' '/<td / { gsub(/<b>/, ""); sub(/ .*/, "", $3); print $3 } ' file </code></pre> <p>Output:</p> <pre><code>54 1 0 0 </code></pre> <p>Another:</p> <pre><code>awk -F '[<>]' ' /<td><b>Total<\/b><\/td>/ { while (getline > 0 && /<td ... | 387, 390, 990, 1357 | awk, bash, parsing, shell | <h1>Parse HTML using shell</h1>
<p>I have a HTML with lots of data and part I am interested in:</p>
<pre><code><tr valign=top>
<td><b>Total</b></td>
<td align=right><b>54</b></td>
<td align=right><b>1</b></td>
<td align=right>0 (0/0)&l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,531 | bash | # Parse HTML using shell
I have a HTML with lots of data and part I am interested in:
```
<tr valign=top>
<td><b>Total</b></td>
<td align=right><b>54</b></td>
<td align=right><b>1</b></td>
<td align=right>0 (0/0)</td>
<td align=right><b>0</b></td>
</tr>
```
I try to use `awk` which now is:
```
awk -F "</*b>|</td>" ... | ```
awk -F '[<>]' '/<td / { gsub(/<b>/, ""); sub(/ .*/, "", $3); print $3 } ' file
```
Output:
```
54
1
0
0
```
Another:
```
awk -F '[<>]' '
/<td><b>Total<\/b><\/td>/ {
while (getline > 0 && /<td /) {
gsub(/<b>/, ""); sub(/ .*/, "", $3)
print $3
}
exit
}' file
``` |
19198721 | Is there a way to look for a flag in a man page? | 23 | 2013-10-05 14:11:32 | <p>I'm trying to come up with a way to find a specific flag in a man-page. Usually, I type '/'
to search for something, followed by something like '-Werror' to find a specific flag.
The thing is though that there are man-pages (gcc is the one motivating me right now) that
have a LOT of references to flags in their text... | 10,178 | 2,092,245 | 2024-06-27 08:40:24 | 24,967,501 | 14 | 2014-07-26 04:21:52 | 45,375 | 2018-07-03 14:21:26 | https://stackoverflow.com/q/19198721 | https://stackoverflow.com/a/24967501 | <p><a href="https://stackoverflow.com/a/19199172/45375">rici's helpful answer</a> explains the problem with the original approach well.</p>
<p>However, there's another thing worth mentioning:</p>
<p><strong><code>man</code>'s output contains <em>formatting control characters</em>, which interfere with text searches</... | <p><a href="https://stackoverflow.com/a/19199172/45375">rici's helpful answer</a> explains the problem with the original approach well.</p> <p>However, there's another thing worth mentioning:</p> <p><strong><code>man</code>'s output contains <em>formatting control characters</em>, which interfere with text searches</... | 34, 58, 387, 10327, 126205 | bash, less-unix, linux, sh, unix | <h1>Is there a way to look for a flag in a man page?</h1>
<p>I'm trying to come up with a way to find a specific flag in a man-page. Usually, I type '/'
to search for something, followed by something like '-Werror' to find a specific flag.
The thing is though that there are man-pages (gcc is the one motivating me right... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,532 | bash | # Is there a way to look for a flag in a man page?
I'm trying to come up with a way to find a specific flag in a man-page. Usually, I type '/'
to search for something, followed by something like '-Werror' to find a specific flag.
The thing is though that there are man-pages (gcc is the one motivating me right now) tha... | [rici's helpful answer](https://stackoverflow.com/a/19199172/45375) explains the problem with the original approach well.
However, there's another thing worth mentioning:
**`man`'s output contains *formatting control characters*, which interfere with text searches**.
If you **pipe to `col -b` before searching**, the... |
52175669 | Is there a Windows 10 PowerShell equivalent to .bashrc for Linux Bash? | 22 | 2018-09-05 00:55:15 | <p>I want to run some commands by default every time I open up power shell. Bash has a .bashrc file that it runs as source when it starts up. Is there a way to do this with powershell?</p>
| 19,956 | 9,064,684 | 2020-01-20 18:28:15 | 59,829,043 | 14 | 2020-01-20 18:28:15 | 4,995,477 | 2020-01-20 18:28:15 | https://stackoverflow.com/q/52175669 | https://stackoverflow.com/a/59829043 | <p>As pointed out by Dai in the comment section, <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7" rel="noreferrer">Powershell Profiles</a> sound like the closest equivalent to the <code>.bashrc</code> file.</p>
<blockquote>
<p>A PowerShell... | <p>As pointed out by Dai in the comment section, <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7" rel="noreferrer">Powershell Profiles</a> sound like the closest equivalent to the <code>.bashrc</code> file.</p> <blockquote> <p>A PowerShell... | 387, 526, 107329 | bash, powershell, windows-10 | <h1>Is there a Windows 10 PowerShell equivalent to .bashrc for Linux Bash?</h1>
<p>I want to run some commands by default every time I open up power shell. Bash has a .bashrc file that it runs as source when it starts up. Is there a way to do this with powershell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,533 | bash | # Is there a Windows 10 PowerShell equivalent to .bashrc for Linux Bash?
I want to run some commands by default every time I open up power shell. Bash has a .bashrc file that it runs as source when it starts up. Is there a way to do this with powershell? | As pointed out by Dai in the comment section, [Powershell Profiles](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7) sound like the closest equivalent to the `.bashrc` file.
> A PowerShell profile is a script that runs when PowerShell starts. You can... |
40898981 | How to discover where 'pip install git+ssh://...' is searching for ssh keys? | 22 | 2016-11-30 21:58:18 | <h2>Question:</h2>
<p>Does anyone know if there's a simple means of discovering where <code>pip install git+ssh:///...</code> is searching for ssh keys?</p>
<h2>Quick background (RESOLVED...see update below):</h2>
<p>I am on Windows 10. I needed to install a private remote repository from github using pip in a conda... | 16,059 | 3,022,254 | 2021-01-04 14:31:15 | 40,900,758 | 14 | 2016-12-01 00:41:39 | 2,522,042 | 2016-12-01 00:41:39 | https://stackoverflow.com/q/40898981 | https://stackoverflow.com/a/40900758 | <p>The <a href="https://git-scm.com/docs/git#git-codeGITSSHCOMMANDcode" rel="noreferrer"><code>GIT_SSH_COMMAND</code></a> environment variable enables overriding the command that Git uses to run ssh. In this case, you want to enable verbose output. On Windows this looks like:</p>
<pre><code>set GIT_SSH_COMMAND=ssh -v
... | <p>The <a href="https://git-scm.com/docs/git#git-codeGITSSHCOMMANDcode" rel="noreferrer"><code>GIT_SSH_COMMAND</code></a> environment variable enables overriding the command that Git uses to run ssh. In this case, you want to enable verbose output. On Windows this looks like:</p> <pre><code>set GIT_SSH_COMMAND=ssh -v ... | 16, 119, 386, 387, 5119 | bash, git, pip, python, ssh | <h1>How to discover where 'pip install git+ssh://...' is searching for ssh keys?</h1>
<h2>Question:</h2>
<p>Does anyone know if there's a simple means of discovering where <code>pip install git+ssh:///...</code> is searching for ssh keys?</p>
<h2>Quick background (RESOLVED...see update below):</h2>
<p>I am on Window... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,534 | bash | # How to discover where 'pip install git+ssh://...' is searching for ssh keys?
## Question:
Does anyone know if there's a simple means of discovering where `pip install git+ssh:///...` is searching for ssh keys?
## Quick background (RESOLVED...see update below):
I am on Windows 10. I needed to install a private rem... | The [`GIT_SSH_COMMAND`](https://git-scm.com/docs/git#git-codeGITSSHCOMMANDcode) environment variable enables overriding the command that Git uses to run ssh. In this case, you want to enable verbose output. On Windows this looks like:
```
set GIT_SSH_COMMAND=ssh -v
```
Then when you run `pip install git+ssh://github.... |
29738751 | With set -e, is it possible to ignore errors for certain commands? | 22 | 2015-04-20 03:12:58 | <p>I have a bash script that I want to globally enable set -e.</p>
<p>But rather than disable it and reenable it all the time, I'm wondering if there is a way of selectively disabling error handling just sometimes.
For example, commands run from systemd can be preceeded by a minus to ignore errors. Does bash has an e... | 12,063 | 134,702 | 2018-07-30 03:41:58 | 29,746,845 | 14 | 2015-04-20 11:38:55 | 258,523 | 2015-04-20 11:38:55 | https://stackoverflow.com/q/29738751 | https://stackoverflow.com/a/29746845 | <p>Add <code>|| :</code> (or anything else that is guaranteed not to fail but that's the simplest) to the end of the command.</p>
<p>Though many people would simply tell you that <code>set -e</code> isn't worth it because it isn't as useful as you might think (and causes issues like this) and manual error checking is ... | <p>Add <code>|| :</code> (or anything else that is guaranteed not to fail but that's the simplest) to the end of the command.</p> <p>Though many people would simply tell you that <code>set -e</code> isn't worth it because it isn't as useful as you might think (and causes issues like this) and manual error checking is ... | 387, 390 | bash, shell | <h1>With set -e, is it possible to ignore errors for certain commands?</h1>
<p>I have a bash script that I want to globally enable set -e.</p>
<p>But rather than disable it and reenable it all the time, I'm wondering if there is a way of selectively disabling error handling just sometimes.
For example, commands run fr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,535 | bash | # With set -e, is it possible to ignore errors for certain commands?
I have a bash script that I want to globally enable set -e.
But rather than disable it and reenable it all the time, I'm wondering if there is a way of selectively disabling error handling just sometimes.
For example, commands run from systemd can b... | Add `|| :` (or anything else that is guaranteed not to fail but that's the simplest) to the end of the command.
Though many people would simply tell you that `set -e` isn't worth it because it isn't as useful as you might think (and causes issues like this) and manual error checking is a better policy.
(I'm not in th... |
22397521 | Execute commands from .bat file on Git Bash Terminal | 22 | 2014-03-14 06:13:35 | <p>I am newbie to Git bash.</p>
<p>Just out of curiosity trying to make a .bat file which contains commands(Dont know if Git Bash supports .bat file) </p>
<p>What I want to achieve is simply drag and drop this .bat file to Git Bash terminal
and commands in the file get executed(Is it possible?).</p>
<p>My commands i... | 48,831 | 1,037,080 | 2019-09-06 10:03:27 | 22,398,033 | 14 | 2014-03-14 06:51:07 | 641,955 | 2019-09-06 10:03:27 | https://stackoverflow.com/q/22397521 | https://stackoverflow.com/a/22398033 | <blockquote>
<p>What I want to achieve is simply drag and drop this .bat file to Git Bash terminal and commands in the file get executed (Is it possible?).</p>
</blockquote>
<p>This is not possible, and probably will never be, because it's not a natural UX. Dragging a file from a file explorer to a Git Bash terminal... | <blockquote> <p>What I want to achieve is simply drag and drop this .bat file to Git Bash terminal and commands in the file get executed (Is it possible?).</p> </blockquote> <p>This is not possible, and probably will never be, because it's not a natural UX. Dragging a file from a file explorer to a Git Bash terminal... | 119, 61874 | git, git-bash | <h1>Execute commands from .bat file on Git Bash Terminal</h1>
<p>I am newbie to Git bash.</p>
<p>Just out of curiosity trying to make a .bat file which contains commands(Dont know if Git Bash supports .bat file) </p>
<p>What I want to achieve is simply drag and drop this .bat file to Git Bash terminal
and commands in... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,536 | bash | # Execute commands from .bat file on Git Bash Terminal
I am newbie to Git bash.
Just out of curiosity trying to make a .bat file which contains commands(Dont know if Git Bash supports .bat file)
What I want to achieve is simply drag and drop this .bat file to Git Bash terminal
and commands in the file get executed(I... | > What I want to achieve is simply drag and drop this .bat file to Git Bash terminal and commands in the file get executed (Is it possible?).
This is not possible, and probably will never be, because it's not a natural UX. Dragging a file from a file explorer to a Git Bash terminal should produce the absolute path to ... |
3586888 | How do I find the top-level parent PID of a given process using bash? | 22 | 2010-08-27 17:56:09 | <p>Let's say I run <code>ps axf</code> and I can see that my command's process tree looks like this:</p>
<pre><code> 800 ? Ss 0:00 /usr/sbin/sshd
10186 ? Ss 0:00 \_ sshd: yukondude [priv]
10251 ? S 0:00 \_ sshd: yukondude@pts/0
10252 pts/0 Ss 0:00 \_ -bash
10778... | 30,887 | 726 | 2026-01-09 18:15:32 | 3,588,480 | 14 | 2010-08-27 22:13:17 | 726 | 2010-08-29 15:40:54 | https://stackoverflow.com/q/3586888 | https://stackoverflow.com/a/3588480 | <p>Failing a better solution, here's a simple (recursive) script to get the top-level parent PID of any process number you give it (or the current shell if you leave out the PID argument):</p>
<pre><code>#!/bin/bash
# Look up the top-level parent Process ID (PID) of the given PID, or the current
# process if unspecifi... | <p>Failing a better solution, here's a simple (recursive) script to get the top-level parent PID of any process number you give it (or the current shell if you leave out the PID argument):</p> <pre><code>#!/bin/bash # Look up the top-level parent Process ID (PID) of the given PID, or the current # process if unspecifi... | 387, 5910 | bash, process | <h1>How do I find the top-level parent PID of a given process using bash?</h1>
<p>Let's say I run <code>ps axf</code> and I can see that my command's process tree looks like this:</p>
<pre><code> 800 ? Ss 0:00 /usr/sbin/sshd
10186 ? Ss 0:00 \_ sshd: yukondude [priv]
10251 ? S 0:00 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,537 | bash | # How do I find the top-level parent PID of a given process using bash?
Let's say I run `ps axf` and I can see that my command's process tree looks like this:
```
800 ? Ss 0:00 /usr/sbin/sshd
10186 ? Ss 0:00 \_ sshd: yukondude [priv]
10251 ? S 0:00 \_ sshd: yukondude@pts/0
10... | Failing a better solution, here's a simple (recursive) script to get the top-level parent PID of any process number you give it (or the current shell if you leave out the PID argument):
```
#!/bin/bash
# Look up the top-level parent Process ID (PID) of the given PID, or the current
# process if unspecified.
function ... |
3215777 | Bash/php - any way to implement tab key autocomplete for arguments? | 22 | 2010-07-09 19:08:19 | <p>I have a PHP command line script which kicks off a job to a job server, with the job name being an argument. The job names are namespaced, such as Foo:Bar_Baz_JobName. Is there a way I could implement auto-completion, like how typing the first few letters of a filename and pressing tab bash completes the file name f... | 5,704 | 332,652 | 2017-07-06 21:50:58 | 3,215,837 | 14 | 2010-07-09 19:17:20 | 56,541 | 2010-07-09 19:17:20 | https://stackoverflow.com/q/3215777 | https://stackoverflow.com/a/3215837 | <p>Autocompletion is done using the GNU readline library, which apparently <a href="http://php.net/manual/en/book.readline.php" rel="noreferrer">is accessible</a> from PHP. Specifically, look at <a href="http://www.php.net/manual/en/function.readline-completion-function.php" rel="noreferrer"><code>readline_completion_f... | <p>Autocompletion is done using the GNU readline library, which apparently <a href="http://php.net/manual/en/book.readline.php" rel="noreferrer">is accessible</a> from PHP. Specifically, look at <a href="http://www.php.net/manual/en/function.readline-completion-function.php" rel="noreferrer"><code>readline_completion_f... | 5, 58, 387 | bash, linux, php | <h1>Bash/php - any way to implement tab key autocomplete for arguments?</h1>
<p>I have a PHP command line script which kicks off a job to a job server, with the job name being an argument. The job names are namespaced, such as Foo:Bar_Baz_JobName. Is there a way I could implement auto-completion, like how typing the fi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,538 | bash | # Bash/php - any way to implement tab key autocomplete for arguments?
I have a PHP command line script which kicks off a job to a job server, with the job name being an argument. The job names are namespaced, such as Foo:Bar_Baz_JobName. Is there a way I could implement auto-completion, like how typing the first few l... | Autocompletion is done using the GNU readline library, which apparently [is accessible](http://php.net/manual/en/book.readline.php) from PHP. Specifically, look at [`readline_completion_function`](http://www.php.net/manual/en/function.readline-completion-function.php). Usage is fairly simple; you call `readline_complet... |
33579181 | How do I remove 'open with code' from my context menu for Visual Studio Code? | 21 | 2015-11-07 04:37:37 | <p>I have uninstalled Visual Studio Code, but the "open with code" option is still in my context menu when I right click a folder.</p>
<p>If I install VS Code again, it will keep the old option and adds a second entry which opens VS code.</p>
<p><a href="https://i.sstatic.net/3Nzwi.png" rel="noreferrer"><img src="htt... | 24,268 | 3,482,995 | 2020-11-25 00:33:20 | 33,579,252 | 14 | 2015-11-07 04:53:01 | 2,903,452 | 2015-11-07 05:00:12 | https://stackoverflow.com/q/33579181 | https://stackoverflow.com/a/33579252 | <p>This <a href="http://www.howtogeek.com/howto/windows-vista/how-to-clean-up-your-messy-windows-context-menu/" rel="noreferrer">link</a> will help you to modify registry.</p>
<p>Most of the menu items that used for all files and folders can be found at one of these keys:</p>
<pre><code>HKEY_CLASSES_ROOT\*\shell
... | <p>This <a href="http://www.howtogeek.com/howto/windows-vista/how-to-clean-up-your-messy-windows-context-menu/" rel="noreferrer">link</a> will help you to modify registry.</p> <p>Most of the menu items that used for all files and folders can be found at one of these keys:</p> <pre><code>HKEY_CLASSES_ROOT\*\shell ... | 64, 9231, 111608 | shell-extensions, visual-studio-code, windows | <h1>How do I remove 'open with code' from my context menu for Visual Studio Code?</h1>
<p>I have uninstalled Visual Studio Code, but the "open with code" option is still in my context menu when I right click a folder.</p>
<p>If I install VS Code again, it will keep the old option and adds a second entry which opens VS... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,539 | bash | # How do I remove 'open with code' from my context menu for Visual Studio Code?
I have uninstalled Visual Studio Code, but the "open with code" option is still in my context menu when I right click a folder.
If I install VS Code again, it will keep the old option and adds a second entry which opens VS code.
[ will help you to modify registry.
Most of the menu items that used for all files and folders can be found at one of these keys:
```
HKEY_CLASSES_ROOT\*\shell
HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers ... |
15041473 | Get the latest file in directory | 21 | 2013-02-23 14:16:29 | <p>I need to get the latest directory name in a folder which start with nlb. </p>
<pre><code>#!/bin/sh
cd /home/ashot/checkout
dirname=`ls -t nlb* | head -1`
echo $dirname
</code></pre>
<p>When the folder contains many folders with name starting nlb, this script works fine, but
when there is only one folder with nam... | 23,805 | 1,356,110 | 2014-10-28 21:04:25 | 15,041,496 | 14 | 2013-02-23 14:17:40 | 4,323 | 2013-02-23 14:17:40 | https://stackoverflow.com/q/15041473 | https://stackoverflow.com/a/15041496 | <p>Add the <code>-d</code> argument to ls. That way it will always print just what it's told, not look inside directories.</p>
| <p>Add the <code>-d</code> argument to ls. That way it will always print just what it's told, not look inside directories.</p> | 34, 387, 390 | bash, shell, unix | <h1>Get the latest file in directory</h1>
<p>I need to get the latest directory name in a folder which start with nlb. </p>
<pre><code>#!/bin/sh
cd /home/ashot/checkout
dirname=`ls -t nlb* | head -1`
echo $dirname
</code></pre>
<p>When the folder contains many folders with name starting nlb, this script works fine, ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,540 | bash | # Get the latest file in directory
I need to get the latest directory name in a folder which start with nlb.
```
#!/bin/sh
cd /home/ashot/checkout
dirname=`ls -t nlb* | head -1`
echo $dirname
```
When the folder contains many folders with name starting nlb, this script works fine, but
when there is only one folder ... | Add the `-d` argument to ls. That way it will always print just what it's told, not look inside directories. |
8962466 | Finding the longest word in a text file | 21 | 2012-01-22 16:11:44 | <p>I am trying to make a a simple script of finding the largest word and its number/length in a text file using bash. I know when I use awk its simple and straight forward but I want to try and use this method...lets say I know if <code>a=wmememememe</code> and if I want to find the length I can use <code>echo {#a}</co... | 19,974 | 1,105,427 | 2020-10-12 04:21:37 | 8,962,512 | 14 | 2012-01-22 16:18:27 | 26,428 | 2012-01-22 16:18:27 | https://stackoverflow.com/q/8962466 | https://stackoverflow.com/a/8962512 | <p>Normally, you'd want to use a <code>while read</code> loop instead of <code>for i in $(cat)</code>, but since you want all the words to be split, in this case it would work out OK.</p>
<pre><code>#!/bin/bash
longest=0
for word in $(<so.txt)
do
len=${#word}
if (( len > longest ))
then
longe... | <p>Normally, you'd want to use a <code>while read</code> loop instead of <code>for i in $(cat)</code>, but since you want all the words to be split, in this case it would work out OK.</p> <pre><code>#!/bin/bash longest=0 for word in $(<so.txt) do len=${#word} if (( len > longest )) then longe... | 34, 58, 387 | bash, linux, unix | <h1>Finding the longest word in a text file</h1>
<p>I am trying to make a a simple script of finding the largest word and its number/length in a text file using bash. I know when I use awk its simple and straight forward but I want to try and use this method...lets say I know if <code>a=wmememememe</code> and if I want... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,541 | bash | # Finding the longest word in a text file
I am trying to make a a simple script of finding the largest word and its number/length in a text file using bash. I know when I use awk its simple and straight forward but I want to try and use this method...lets say I know if `a=wmememememe` and if I want to find the length ... | Normally, you'd want to use a `while read` loop instead of `for i in $(cat)`, but since you want all the words to be split, in this case it would work out OK.
```
#!/bin/bash
longest=0
for word in $(<so.txt)
do
len=${#word}
if (( len > longest ))
then
longest=$len
longword=$word
fi
done... |
4398136 | Use PowerShell for Visual Studio Command Prompt | 21 | 2010-12-09 12:22:43 | <p>In a serious intiative to migrate all my command line operations to PowerShell, I would like to avoid using the old fashioned command console for anything. However, the Visual Studio Command prompt has various environment variables and path settings not found in the default command prompt. How could I create a 'Vi... | 10,197 | 8,741 | 2024-07-22 18:55:33 | 4,398,325 | 14 | 2010-12-09 12:44:57 | 323,582 | 2010-12-09 12:50:18 | https://stackoverflow.com/q/4398136 | https://stackoverflow.com/a/4398325 | <p>You can use for example <a href="https://stackoverflow.com/questions/4384814/how-to-call-batch-script-from-powershell/4385011#4385011">this script</a> to import Visual Studio command prompt environment, see the examples in the script documentation comments, e.g. for Visual Studio 2010:</p>
<pre><code>Invoke-Environ... | <p>You can use for example <a href="https://stackoverflow.com/questions/4384814/how-to-call-batch-script-from-powershell/4385011#4385011">this script</a> to import Visual Studio command prompt environment, see the examples in the script documentation comments, e.g. for Visual Studio 2010:</p> <pre><code>Invoke-Environ... | 64, 526, 33953, 34595 | powershell, visual-studio, windows, windows-7 | <h1>Use PowerShell for Visual Studio Command Prompt</h1>
<p>In a serious intiative to migrate all my command line operations to PowerShell, I would like to avoid using the old fashioned command console for anything. However, the Visual Studio Command prompt has various environment variables and path settings not found... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,542 | bash | # Use PowerShell for Visual Studio Command Prompt
In a serious intiative to migrate all my command line operations to PowerShell, I would like to avoid using the old fashioned command console for anything. However, the Visual Studio Command prompt has various environment variables and path settings not found in the de... | You can use for example [this script](https://stackoverflow.com/questions/4384814/how-to-call-batch-script-from-powershell/4385011#4385011) to import Visual Studio command prompt environment, see the examples in the script documentation comments, e.g. for Visual Studio 2010:
```
Invoke-Environment '"%VS100COMNTOOLS%\v... |
3276247 | Is there a hook in Bash to find out when the cwd changes? | 21 | 2010-07-18 16:12:25 | <p>I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd.</p>
<p>Now I want to port this bit of my .zshrc to bash, but found that chpwd() is ... | 5,703 | 334,761 | 2019-07-20 03:19:10 | 3,276,280 | 14 | 2010-07-18 16:20:32 | 26,428 | 2014-04-12 17:57:54 | https://stackoverflow.com/q/3276247 | https://stackoverflow.com/a/3276280 | <p>You would have to use a DEBUG <code>trap</code> or <code>PROMPT_COMMAND</code>.</p>
<p>Examples:</p>
<pre><code>trap chpwd DEBUG # calls the function before each command
PROMPT_COMMAND=chpwd # calls the function after each command
</code></pre>
<p>Note that the function defined in <code>PROMPT_COMMAND<... | <p>You would have to use a DEBUG <code>trap</code> or <code>PROMPT_COMMAND</code>.</p> <p>Examples:</p> <pre><code>trap chpwd DEBUG # calls the function before each command PROMPT_COMMAND=chpwd # calls the function after each command </code></pre> <p>Note that the function defined in <code>PROMPT_COMMAND<... | 387, 3718, 3791, 10687 | bash, cd, cwd, zsh | <h1>Is there a hook in Bash to find out when the cwd changes?</h1>
<p>I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd.</p>
<p>Now I wan... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,543 | bash | # Is there a hook in Bash to find out when the cwd changes?
I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd.
Now I want to port this b... | You would have to use a DEBUG `trap` or `PROMPT_COMMAND`.
Examples:
```
trap chpwd DEBUG # calls the function before each command
PROMPT_COMMAND=chpwd # calls the function after each command
```
Note that the function defined in `PROMPT_COMMAND` is run before ***each*** prompt, though, even empty ones. |
67160140 | docker: error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect | 20 | 2021-04-19 10:20:32 | <p>I'm trying to run Docker in process isolation mode on Windows Server 2019 (Docker Desktop does not work here, my VPS does not support Hyper-V).
I run this in PowerShell (all in Administrator mode)
<code>docker run -it --isolation=process mcr.microsoft.com/windows/servercore:ltsc2019 cmd.exe /c ping 127.0.0.1 -t</cod... | 79,914 | 769,449 | 2025-12-17 13:22:02 | 67,161,152 | 14 | 2021-04-19 11:29:10 | 909,199 | 2021-04-21 11:11:47 | https://stackoverflow.com/q/67160140 | https://stackoverflow.com/a/67161152 | <p>The pipe access that the error message mentions is a (probably unrelated) issue when <code>docker</code> client is run by non-admin users (see <a href="https://www.axians-infoma.de/techblog/allow-access-to-the-docker-engine-without-admin-rights-on-windows/" rel="noreferrer">here</a>).</p>
<p>I think the most likely ... | <p>The pipe access that the error message mentions is a (probably unrelated) issue when <code>docker</code> client is run by non-admin users (see <a href="https://www.axians-infoma.de/techblog/allow-access-to-the-docker-engine-without-admin-rights-on-windows/" rel="noreferrer">here</a>).</p> <p>I think the most likely ... | 526, 90304, 136697, 150507 | docker, powershell, process-isolation, windows-server-2019 | <h1>docker: error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect</h1>
<p>I'm trying to run Docker in process isolation mode on Windows Server 2019 (Docker Desktop does not work here, my VPS does not support Hyper-V).
I run this in PowerS... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,544 | bash | # docker: error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect
I'm trying to run Docker in process isolation mode on Windows Server 2019 (Docker Desktop does not work here, my VPS does not support Hyper-V).
I run this in PowerShell (all... | The pipe access that the error message mentions is a (probably unrelated) issue when `docker` client is run by non-admin users (see [here](https://www.axians-infoma.de/techblog/allow-access-to-the-docker-engine-without-admin-rights-on-windows/)).
I think the most likely explanation is that the docker service has faile... |
54871891 | How does activating a python virtual environment modify sys.path? | 20 | 2019-02-25 17:45:18 | <p>I create my python virtual environment using:</p>
<pre><code>python3 -m venv venv3
</code></pre>
<p>to activate, I <code>source venv3/bin/activate</code>.</p>
<p><code>venv3/bin/activate</code> doesn't appear to be all that complex:</p>
<pre><code># This file must be used with "source bin/activate" *from bash*
#... | 8,939 | 6,423,456 | 2022-07-02 05:00:56 | 54,928,993 | 14 | 2019-02-28 15:22:38 | 4,201,810 | 2022-07-02 05:00:56 | https://stackoverflow.com/q/54871891 | https://stackoverflow.com/a/54928993 | <p><code>sys.path</code> is initiated in <code>site.py</code>, it is set using the relative path of <code>sys.prefix</code>, which is the path of python executable inside the virtual environment.</p>
<p>if the virtual environment is created <strong>without</strong> option <code>--system-site-packages</code>, which is t... | <p><code>sys.path</code> is initiated in <code>site.py</code>, it is set using the relative path of <code>sys.prefix</code>, which is the path of python executable inside the virtual environment.</p> <p>if the virtual environment is created <strong>without</strong> option <code>--system-site-packages</code>, which is t... | 16, 387, 90848 | bash, python, python-venv | <h1>How does activating a python virtual environment modify sys.path?</h1>
<p>I create my python virtual environment using:</p>
<pre><code>python3 -m venv venv3
</code></pre>
<p>to activate, I <code>source venv3/bin/activate</code>.</p>
<p><code>venv3/bin/activate</code> doesn't appear to be all that complex:</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,545 | bash | # How does activating a python virtual environment modify sys.path?
I create my python virtual environment using:
```
python3 -m venv venv3
```
to activate, I `source venv3/bin/activate`.
`venv3/bin/activate` doesn't appear to be all that complex:
```
# This file must be used with "source bin/activate" *from bash*... | `sys.path` is initiated in `site.py`, it is set using the relative path of `sys.prefix`, which is the path of python executable inside the virtual environment.
if the virtual environment is created **without** option `--system-site-packages`, which is the default, the config value of key `include-system-site-packages`... |
38982640 | Set shell environment variable via python script | 20 | 2016-08-16 19:05:30 | <p>I have some instrument which requires environment variable which I want to set automatically from python code. So I tried several ways to make it happen, but none of them were successful.
Here are some examples:</p>
<ol>
<li><p>I insert following code in my python script</p>
<pre><code> import os
os.system("ex... | 78,158 | 6,449,007 | 2022-07-04 11:31:55 | 38,982,939 | 14 | 2016-08-16 19:25:05 | 271,495 | 2020-06-23 14:15:44 | https://stackoverflow.com/q/38982640 | https://stackoverflow.com/a/38982939 | <p>As long as you start the "instrument" (a script I suppose) from the very same process it should work:</p>
<pre><code>In [1]: os.putenv("VARIABLE", "123")
In [2]: os.system("echo $VARIABLE")
123
</code></pre>
<p>You can't change an environment variable of a different process o... | <p>As long as you start the "instrument" (a script I suppose) from the very same process it should work:</p> <pre><code>In [1]: os.putenv("VARIABLE", "123") In [2]: os.system("echo $VARIABLE") 123 </code></pre> <p>You can't change an environment variable of a different process o... | 16, 387, 390 | bash, python, shell | <h1>Set shell environment variable via python script</h1>
<p>I have some instrument which requires environment variable which I want to set automatically from python code. So I tried several ways to make it happen, but none of them were successful.
Here are some examples:</p>
<ol>
<li><p>I insert following code in my p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,546 | bash | # Set shell environment variable via python script
I have some instrument which requires environment variable which I want to set automatically from python code. So I tried several ways to make it happen, but none of them were successful.
Here are some examples:
1. I insert following code in my python script
```
... | As long as you start the "instrument" (a script I suppose) from the very same process it should work:
```
In [1]: os.putenv("VARIABLE", "123")
In [2]: os.system("echo $VARIABLE")
123
```
You can't change an environment variable of a different process or a parent process. |
31563848 | Iterating through a variable line by line | 20 | 2015-07-22 12:57:38 | <p>I have a small script that outputs text into a variable.
I need to go through it line by one in order to parse it.
I could do this by outputting the variable to a text file and then reading it using Get-Content but that seems a bit redundant.</p>
<p>My script connects to a Fortigate unit and runs a certain query. I... | 52,737 | 1,571,299 | 2022-12-31 14:57:39 | 31,564,924 | 14 | 2015-07-22 13:43:24 | 1,627,055 | 2015-07-22 13:43:24 | https://stackoverflow.com/q/31563848 | https://stackoverflow.com/a/31564924 | <p>By your description, your variable is a string with newlines. You can turn it into an array of single-line string by calling this:</p>
<pre><code>$result = $result -split "`r`n"
</code></pre>
| <p>By your description, your variable is a string with newlines. You can turn it into an array of single-line string by calling this:</p> <pre><code>$result = $result -split "`r`n" </code></pre> | 526 | powershell | <h1>Iterating through a variable line by line</h1>
<p>I have a small script that outputs text into a variable.
I need to go through it line by one in order to parse it.
I could do this by outputting the variable to a text file and then reading it using Get-Content but that seems a bit redundant.</p>
<p>My script conne... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,547 | bash | # Iterating through a variable line by line
I have a small script that outputs text into a variable.
I need to go through it line by one in order to parse it.
I could do this by outputting the variable to a text file and then reading it using Get-Content but that seems a bit redundant.
My script connects to a Fortiga... | By your description, your variable is a string with newlines. You can turn it into an array of single-line string by calling this:
```
$result = $result -split "`r`n"
``` |
20975205 | Format the output of a hash table in Powershell to output to one line | 20 | 2014-01-07 15:15:16 | <p>Is it possible to format the output of a hashtable in Powershell to output all the values onto one line?</p>
<p>e.g. </p>
<p>I have the hash table <strong>$hashErr</strong> with the below values:</p>
<pre><code> $hashErr = @{"server1" = "192.168.17.21";
"server2" = "192.168.17.22";
"se... | 50,245 | 1,623,054 | 2025-01-22 20:16:37 | 20,975,369 | 14 | 2014-01-07 15:23:01 | 67,392 | 2014-01-07 15:23:01 | https://stackoverflow.com/q/20975205 | https://stackoverflow.com/a/20975369 | <p>You can iterate over the keys of a hash table, and then in the loop lookup the values. By using the pipeline you don't need an intermediate collection:</p>
<pre><code>($hashErr.Keys | foreach { "$_ $($hashErr[$_])" }) -join "|"
</code></pre>
| <p>You can iterate over the keys of a hash table, and then in the loop lookup the values. By using the pipeline you don't need an intermediate collection:</p> <pre><code>($hashErr.Keys | foreach { "$_ $($hashErr[$_])" }) -join "|" </code></pre> | 526, 5189 | hashtable, powershell | <h1>Format the output of a hash table in Powershell to output to one line</h1>
<p>Is it possible to format the output of a hashtable in Powershell to output all the values onto one line?</p>
<p>e.g. </p>
<p>I have the hash table <strong>$hashErr</strong> with the below values:</p>
<pre><code> $hashErr = @{"server1" ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,548 | bash | # Format the output of a hash table in Powershell to output to one line
Is it possible to format the output of a hashtable in Powershell to output all the values onto one line?
e.g.
I have the hash table **$hashErr** with the below values:
```
$hashErr = @{"server1" = "192.168.17.21";
"server2" = "19... | You can iterate over the keys of a hash table, and then in the loop lookup the values. By using the pipeline you don't need an intermediate collection:
```
($hashErr.Keys | foreach { "$_ $($hashErr[$_])" }) -join "|"
``` |
14502611 | Does Powershell have a cache that needs to be cleared? | 20 | 2013-01-24 13:33:56 | <p>This morning, I copied a directory from my local, networked drive to temp folder for testing. This error appeared. </p>
<pre><code>Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no
t exist.
At C:\users\xxxxx\desktop\cgc\testcountexcl1.ps1:55 char:... | 90,007 | 1,267,125 | 2023-09-01 20:49:50 | 14,502,941 | 14 | 2013-01-24 13:50:37 | 702,944 | 2014-04-13 15:39:39 | https://stackoverflow.com/q/14502611 | https://stackoverflow.com/a/14502941 | <p>Variables are stored in the session, so if you close your powershell console and open a new one, all custom variables will be gone. If you want to see what variables exists, use <code>Get-Variable</code> . To delete a specific variable(to make sure it's gone), you could use:</p>
<p><code>Remove-Variable varname</co... | <p>Variables are stored in the session, so if you close your powershell console and open a new one, all custom variables will be gone. If you want to see what variables exists, use <code>Get-Variable</code> . To delete a specific variable(to make sure it's gone), you could use:</p> <p><code>Remove-Variable varname</co... | 526, 1763 | caching, powershell | <h1>Does Powershell have a cache that needs to be cleared?</h1>
<p>This morning, I copied a directory from my local, networked drive to temp folder for testing. This error appeared. </p>
<pre><code>Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no
t ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,549 | bash | # Does Powershell have a cache that needs to be cleared?
This morning, I copied a directory from my local, networked drive to temp folder for testing. This error appeared.
```
Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no
t exist.
At C:\users\xx... | Variables are stored in the session, so if you close your powershell console and open a new one, all custom variables will be gone. If you want to see what variables exists, use `Get-Variable` . To delete a specific variable(to make sure it's gone), you could use:
`Remove-Variable varname`.
As for you question. A var... |
8634742 | Powershell: How do I get the exit code returned from a process run inside a PsJob? | 20 | 2011-12-26 10:08:32 | <p>I have the following job in powershell:</p>
<pre><code>$job = start-job {
...
c:\utils\MyToolReturningSomeExitCode.cmd
} -ArgumentList $JobFile
</code></pre>
<p>How do I access the exit code returned by <code>c:\utils\MyToolReturningSomeExitCode.cmd</code> ? I have tried several options, but the only one I cou... | 35,694 | 80,002 | 2012-02-23 07:40:14 | 8,635,765 | 14 | 2011-12-26 12:27:16 | 323,582 | 2011-12-26 12:53:43 | https://stackoverflow.com/q/8634742 | https://stackoverflow.com/a/8635765 | <p>If all you need is to do something in background while the main script does something else then <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx" rel="noreferrer">PowerShell</a> class is enough (and it is normally faster). Besides it allows passing in a live obje... | <p>If all you need is to do something in background while the main script does something else then <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx" rel="noreferrer">PowerShell</a> class is enough (and it is normally faster). Besides it allows passing in a live obje... | 526 | powershell | <h1>Powershell: How do I get the exit code returned from a process run inside a PsJob?</h1>
<p>I have the following job in powershell:</p>
<pre><code>$job = start-job {
...
c:\utils\MyToolReturningSomeExitCode.cmd
} -ArgumentList $JobFile
</code></pre>
<p>How do I access the exit code returned by <code>c:\utils\M... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,550 | bash | # Powershell: How do I get the exit code returned from a process run inside a PsJob?
I have the following job in powershell:
```
$job = start-job {
...
c:\utils\MyToolReturningSomeExitCode.cmd
} -ArgumentList $JobFile
```
How do I access the exit code returned by `c:\utils\MyToolReturningSomeExitCode.cmd` ? I ha... | If all you need is to do something in background while the main script does something else then [PowerShell](http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx) class is enough (and it is normally faster). Besides it allows passing in a live object in order to return something... |
2128949 | How to pipe a here-document through a command and capture the result into a variable? | 20 | 2010-01-24 21:30:55 | <p>Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script? </p>
<p>Requirements:</p>
<ul>
<li>The script needs to be all in one file.</li>
<li>I'd prefer not to write any temp files, if possible.</li>
</ul>
<p>.</p>
<pre><code>#!/bin/bash
c... | 21,690 | 758 | 2025-01-11 23:13:54 | 2,129,072 | 14 | 2010-01-24 21:57:37 | 758 | 2010-01-24 21:57:37 | https://stackoverflow.com/q/2128949 | https://stackoverflow.com/a/2129072 | <p>This seems to work (based on Ignacio's answer). By using a subshell the here-document is correctly piped into xsltproc while still being passed through tail after.</p>
<pre><code>VERSION=$((xsltproc - ../pom.xml | tail -1) << EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://w... | <p>This seems to work (based on Ignacio's answer). By using a subshell the here-document is correctly piped into xsltproc while still being passed through tail after.</p> <pre><code>VERSION=$((xsltproc - ../pom.xml | tail -1) << EOF <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://w... | 387, 390, 7449 | bash, heredoc, shell | <h1>How to pipe a here-document through a command and capture the result into a variable?</h1>
<p>Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script? </p>
<p>Requirements:</p>
<ul>
<li>The script needs to be all in one file.</li>
<li>I'd p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,551 | bash | # How to pipe a here-document through a command and capture the result into a variable?
Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script?
Requirements:
- The script needs to be all in one file.
- I'd prefer not to write any temp files, ... | This seems to work (based on Ignacio's answer). By using a subshell the here-document is correctly piped into xsltproc while still being passed through tail after.
```
VERSION=$((xsltproc - ../pom.xml | tail -1) << EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"... |
783984 | Change path separator in Windows PowerShell | 20 | 2009-04-23 23:29:50 | <p>Is it possible to get PowerShell to always output <code>/</code> instead of <code>\</code>? For example, I'd like the output of get-location to be C:/Documents and Settings/Administrator.</p>
<p><strong>Update</strong></p>
<p>Thanks for the examples of using replace, but I was hoping for this to happen globally (e... | 19,277 | 26,683 | 2009-04-24 16:25:11 | 784,419 | 14 | 2009-04-24 03:41:35 | 615 | 2009-04-24 03:41:35 | https://stackoverflow.com/q/783984 | https://stackoverflow.com/a/784419 | <p>It's a good question. The underlying .NET framework surfaces this as System.IO.Path.DirectorySeparatorChar, and it's a read/write property, so I figured you could do this:</p>
<pre><code>[IO.Path]::DirectorySeparatorChar = '/'
</code></pre>
<p>... and that appears to succeed, except if you then type this:</p>
<pr... | <p>It's a good question. The underlying .NET framework surfaces this as System.IO.Path.DirectorySeparatorChar, and it's a read/write property, so I figured you could do this:</p> <pre><code>[IO.Path]::DirectorySeparatorChar = '/' </code></pre> <p>... and that appears to succeed, except if you then type this:</p> <pr... | 526 | powershell | <h1>Change path separator in Windows PowerShell</h1>
<p>Is it possible to get PowerShell to always output <code>/</code> instead of <code>\</code>? For example, I'd like the output of get-location to be C:/Documents and Settings/Administrator.</p>
<p><strong>Update</strong></p>
<p>Thanks for the examples of using rep... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,552 | bash | # Change path separator in Windows PowerShell
Is it possible to get PowerShell to always output `/` instead of `\`? For example, I'd like the output of get-location to be C:/Documents and Settings/Administrator.
**Update**
Thanks for the examples of using replace, but I was hoping for this to happen globally (e.g. t... | It's a good question. The underlying .NET framework surfaces this as System.IO.Path.DirectorySeparatorChar, and it's a read/write property, so I figured you could do this:
```
[IO.Path]::DirectorySeparatorChar = '/'
```
... and that appears to succeed, except if you then type this:
```
[IO.Path]::DirectorySeparatorC... |
44561378 | Escape password containing @ when using postgres pg_dump command | 19 | 2017-06-15 07:32:35 | <p>I 'm using postgres, I created db, user, password, this is the password:</p>
<p>password = <code>name&text@sob</code></p>
<p>I'm using the following command to dump database and it works on my other databases I have:</p>
<p><code>pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:password@127.0.0.1... | 15,846 | 2,502,605 | 2018-04-18 14:41:00 | 44,562,005 | 14 | 2017-06-15 08:05:23 | 5,315,974 | 2017-06-15 08:46:35 | https://stackoverflow.com/q/44561378 | https://stackoverflow.com/a/44562005 | <p>adding <code>?password=name%26text%40sob</code> as uri parameter should do:</p>
<pre><code>pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:password@127.0.0.1:5432/db_name?password=name%26text%40sob
</code></pre>
<p>as per <a href="https://www.postgresql.org/docs/current/static/libpq-connect.html#... | <p>adding <code>?password=name%26text%40sob</code> as uri parameter should do:</p> <pre><code>pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:password@127.0.0.1:5432/db_name?password=name%26text%40sob </code></pre> <p>as per <a href="https://www.postgresql.org/docs/current/static/libpq-connect.html#... | 256, 390 | postgresql, shell | <h1>Escape password containing @ when using postgres pg_dump command</h1>
<p>I 'm using postgres, I created db, user, password, this is the password:</p>
<p>password = <code>name&text@sob</code></p>
<p>I'm using the following command to dump database and it works on my other databases I have:</p>
<p><code>pg_dum... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,553 | bash | # Escape password containing @ when using postgres pg_dump command
I 'm using postgres, I created db, user, password, this is the password:
password = `name&text@sob`
I'm using the following command to dump database and it works on my other databases I have:
`pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db... | adding `?password=name%26text%40sob` as uri parameter should do:
```
pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:password@127.0.0.1:5432/db_name?password=name%26text%40sob
```
as per <https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING>
> Components of the hierarc... |
35690954 | Running OpenSSH in an Alpine Docker Container | 19 | 2016-02-29 02:22:43 | <p>I've <a href="https://stackoverflow.com/questions/35689976/installing-openssh-on-the-alpine-docker-container">installed OpenSSH</a> and now I wish to run it as described in the <a href="http://wiki.alpinelinux.org/wiki/Setting_up_a_ssh-server" rel="noreferrer">documentation</a> by running <code>/etc/init.d/sshd star... | 54,721 | 1,684,269 | 2021-12-30 20:37:16 | 35,910,070 | 14 | 2016-03-10 07:23:13 | 271,020 | 2016-04-13 16:43:25 | https://stackoverflow.com/q/35690954 | https://stackoverflow.com/a/35910070 | <p>A container is not a full installed environment.
The official document is for that installed alpine on some machine.
With power on, boot up services, etc. that a container does not have.</p>
<p>So, anything in <code>/etc/init.d/</code> can not be used directly in a container which is used by boot up service (like s... | <p>A container is not a full installed environment. The official document is for that installed alpine on some machine. With power on, boot up services, etc. that a container does not have.</p> <p>So, anything in <code>/etc/init.d/</code> can not be used directly in a container which is used by boot up service (like s... | 58, 390, 3305, 90304, 115689 | alpine-linux, docker, linux, openssh, shell | <h1>Running OpenSSH in an Alpine Docker Container</h1>
<p>I've <a href="https://stackoverflow.com/questions/35689976/installing-openssh-on-the-alpine-docker-container">installed OpenSSH</a> and now I wish to run it as described in the <a href="http://wiki.alpinelinux.org/wiki/Setting_up_a_ssh-server" rel="noreferrer">d... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,554 | bash | # Running OpenSSH in an Alpine Docker Container
I've [installed OpenSSH](https://stackoverflow.com/questions/35689976/installing-openssh-on-the-alpine-docker-container) and now I wish to run it as described in the [documentation](http://wiki.alpinelinux.org/wiki/Setting_up_a_ssh-server) by running `/etc/init.d/sshd st... | A container is not a full installed environment.
The official document is for that installed alpine on some machine.
With power on, boot up services, etc. that a container does not have.
So, anything in `/etc/init.d/` can not be used directly in a container which is used by boot up service (like systemd, or alpine's r... |
28090477 | \n in variable in heredoc | 19 | 2015-01-22 13:53:29 | <p>Is there any way to for a Bash heredoc to interpret '\n\' in a heredoc?</p>
<p>I have an iteratively built string in a loop, something like</p>
<pre><code>for i in word1 word2 word3
do
TMP_VAR=$i
ret="$ret\n$TMP_VAR"
done
</code></pre>
<p>and then I want to use the created string in a heredoc:</p>... | 21,462 | 2,144,057 | 2019-01-10 12:15:11 | 28,090,524 | 14 | 2015-01-22 13:55:35 | 2,088,135 | 2015-01-22 13:55:35 | https://stackoverflow.com/q/28090477 | https://stackoverflow.com/a/28090524 | <p>In bash you can use <code>$'\n'</code> to add a newline to a string:</p>
<pre><code>ret="$ret"$'\n'"$TMP_VAR"
</code></pre>
<p>You can also use <code>+=</code> to append to a string:</p>
<pre><code>ret+=$'\n'"$TMP_VAR"
</code></pre>
| <p>In bash you can use <code>$'\n'</code> to add a newline to a string:</p> <pre><code>ret="$ret"$'\n'"$TMP_VAR" </code></pre> <p>You can also use <code>+=</code> to append to a string:</p> <pre><code>ret+=$'\n'"$TMP_VAR" </code></pre> | 276, 387, 4804, 7449 | bash, escaping, heredoc, variables | <h1>\n in variable in heredoc</h1>
<p>Is there any way to for a Bash heredoc to interpret '\n\' in a heredoc?</p>
<p>I have an iteratively built string in a loop, something like</p>
<pre><code>for i in word1 word2 word3
do
TMP_VAR=$i
ret="$ret\n$TMP_VAR"
done
</code></pre>
<p>and then I want to use t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,555 | bash | # \n in variable in heredoc
Is there any way to for a Bash heredoc to interpret '\n\' in a heredoc?
I have an iteratively built string in a loop, something like
```
for i in word1 word2 word3
do
TMP_VAR=$i
ret="$ret\n$TMP_VAR"
done
```
and then I want to use the created string in a heredoc:
```
cat... | In bash you can use `$'\n'` to add a newline to a string:
```
ret="$ret"$'\n'"$TMP_VAR"
```
You can also use `+=` to append to a string:
```
ret+=$'\n'"$TMP_VAR"
``` |
21832822 | Find total size of uncommitted or untracked files in git | 19 | 2014-02-17 15:21:47 | <p>I have a big horrible pile of code and I am setting it up in version control.</p>
<p>I would like a command I can run on Linux to give me the total size of the files that would be committed and pushed if I ran <code>git add -A && git commit -am 'initial commit'</code></p>
<p>The total size is needed, also ... | 2,647 | 543,455 | 2023-07-13 15:59:43 | 21,832,981 | 14 | 2014-02-17 15:28:38 | 543,455 | 2014-02-17 16:00:34 | https://stackoverflow.com/q/21832822 | https://stackoverflow.com/a/21832981 | <p>I think I have answered my own question:</p>
<pre><code>for f in `git status --porcelain | sed 's#^...##'`; do du -cs $f | head -n 1; done | sort -nr; echo "TOTAL:"; du -cs .
</code></pre>
<p>However I'm open to any better ideas or useful tricks. My current output is 13GB :)</p>
<hr>
<p>The above command is bas... | <p>I think I have answered my own question:</p> <pre><code>for f in `git status --porcelain | sed 's#^...##'`; do du -cs $f | head -n 1; done | sort -nr; echo "TOTAL:"; du -cs . </code></pre> <p>However I'm open to any better ideas or useful tricks. My current output is 13GB :)</p> <hr> <p>The above command is bas... | 58, 119, 387 | bash, git, linux | <h1>Find total size of uncommitted or untracked files in git</h1>
<p>I have a big horrible pile of code and I am setting it up in version control.</p>
<p>I would like a command I can run on Linux to give me the total size of the files that would be committed and pushed if I ran <code>git add -A && git commit -... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,556 | bash | # Find total size of uncommitted or untracked files in git
I have a big horrible pile of code and I am setting it up in version control.
I would like a command I can run on Linux to give me the total size of the files that would be committed and pushed if I ran `git add -A && git commit -am 'initial commit'`
The tot... | I think I have answered my own question:
```
for f in `git status --porcelain | sed 's#^...##'`; do du -cs $f | head -n 1; done | sort -nr; echo "TOTAL:"; du -cs .
```
However I'm open to any better ideas or useful tricks. My current output is 13GB :)
---
The above command is basically there, it gives me the total... |
15262196 | Powershell - Tail Windows Event Log? Is it possible? | 19 | 2013-03-07 02:52:47 | <p>How can i use powershell to tail a specific windows event log?
Is it possible?</p>
| 13,398 | 514,316 | 2020-09-30 17:27:41 | 15,262,376 | 14 | 2013-03-07 03:08:44 | 574,168 | 2013-03-07 03:24:41 | https://stackoverflow.com/q/15262196 | https://stackoverflow.com/a/15262376 | <p>I've done this on occasion:</p>
<pre><code>$idx = (get-eventlog -LogName System -Newest 1).Index
while ($true)
{
start-sleep -Seconds 1
$idx2 = (Get-EventLog -LogName System -newest 1).index
get-eventlog -logname system -newest ($idx2 - $idx) | sort index
$idx = $idx2
}
</code></pre>
| <p>I've done this on occasion:</p> <pre><code>$idx = (get-eventlog -LogName System -Newest 1).Index while ($true) { start-sleep -Seconds 1 $idx2 = (Get-EventLog -LogName System -newest 1).index get-eventlog -logname system -newest ($idx2 - $idx) | sort index $idx = $idx2 } </code></pre> | 64, 526, 7896, 18154 | event-log, powershell, tail, windows | <h1>Powershell - Tail Windows Event Log? Is it possible?</h1>
<p>How can i use powershell to tail a specific windows event log?
Is it possible?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,557 | bash | # Powershell - Tail Windows Event Log? Is it possible?
How can i use powershell to tail a specific windows event log?
Is it possible? | I've done this on occasion:
```
$idx = (get-eventlog -LogName System -Newest 1).Index
while ($true)
{
start-sleep -Seconds 1
$idx2 = (Get-EventLog -LogName System -newest 1).index
get-eventlog -logname system -newest ($idx2 - $idx) | sort index
$idx = $idx2
}
``` |
12298437 | copy and paste in vi | 19 | 2012-09-06 10:50:24 | <p>I don't have a huge amount of experience using VI. I am running it on Mac OSX.</p>
<p>I've copied and pasted text before in the editor using (when I say gui in the following I mean the Mac OSX gui) </p>
<ol>
<li>Cursor to highlight and copy i using <code>command C</code> or the gui or the <code>yy</code> command i... | 97,316 | 1,128,171 | 2021-05-05 14:38:07 | 12,298,529 | 14 | 2012-09-06 10:55:13 | 94,335 | 2012-09-06 10:55:13 | https://stackoverflow.com/q/12298437 | https://stackoverflow.com/a/12298529 | <p>You have</p>
<pre><code> :set paste
</code></pre>
<p>Put Vim in Paste mode. This is useful if you want to cut or copy
some text from one window and paste it in Vim. This will avoid
unexpected effects.
Setting this option is useful when using Vim in a terminal, where Vim
cannot distinguish between... | <p>You have</p> <pre><code> :set paste </code></pre> <p>Put Vim in Paste mode. This is useful if you want to cut or copy some text from one window and paste it in Vim. This will avoid unexpected effects. Setting this option is useful when using Vim in a terminal, where Vim cannot distinguish between... | 110, 293, 370, 387, 391 | bash, ide, terminal, vi, vim | <h1>copy and paste in vi</h1>
<p>I don't have a huge amount of experience using VI. I am running it on Mac OSX.</p>
<p>I've copied and pasted text before in the editor using (when I say gui in the following I mean the Mac OSX gui) </p>
<ol>
<li>Cursor to highlight and copy i using <code>command C</code> or the gui or... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,558 | bash | # copy and paste in vi
I don't have a huge amount of experience using VI. I am running it on Mac OSX.
I've copied and pasted text before in the editor using (when I say gui in the following I mean the Mac OSX gui)
1. Cursor to highlight and copy i using `command C` or the gui or the `yy` command in VI.
2. Entering i... | You have
```
:set paste
```
Put Vim in Paste mode. This is useful if you want to cut or copy
some text from one window and paste it in Vim. This will avoid
unexpected effects.
Setting this option is useful when using Vim in a terminal, where Vim
cannot distinguish between typed text and pasted text. |
4369866 | What is the easiest way to "detach/daemonize" a Bash script? | 19 | 2010-12-06 18:51:57 | <p>What I am trying to do is write a <strong>Bash script</strong> that <em>sleeps</em> for a set amount of time before using the mac <em>say</em> command to speak some text.</p>
<p>I'd like to be able to run the command and then close the terminal so it will still speak at the set time. I've looked into nohup, detach,... | 31,980 | 522,498 | 2017-03-30 23:11:37 | 4,369,927 | 14 | 2010-12-06 19:00:16 | 15,168 | 2010-12-06 19:00:16 | https://stackoverflow.com/q/4369866 | https://stackoverflow.com/a/4369927 | <p>Section 3.7.6 of the Bash Manual says:</p>
<blockquote>
<p>The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell
resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to
ensure that they receive the SIGHUP. To prevent the shell from sending the S... | <p>Section 3.7.6 of the Bash Manual says:</p> <blockquote> <p>The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from sending the S... | 387, 2221, 2510, 5910, 15427 | bash, daemon, detach, process, sleep | <h1>What is the easiest way to "detach/daemonize" a Bash script?</h1>
<p>What I am trying to do is write a <strong>Bash script</strong> that <em>sleeps</em> for a set amount of time before using the mac <em>say</em> command to speak some text.</p>
<p>I'd like to be able to run the command and then close the terminal s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,559 | bash | # What is the easiest way to "detach/daemonize" a Bash script?
What I am trying to do is write a **Bash script** that *sleeps* for a set amount of time before using the mac *say* command to speak some text.
I'd like to be able to run the command and then close the terminal so it will still speak at the set time. I've... | Section 3.7.6 of the Bash Manual says:
> The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell
> resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to
> ensure that they receive the SIGHUP. To prevent the shell from sending the SIGHUP signal
> to a par... |
3528020 | Git Bash: Launch Application via Alias without hanging Bash (WIndows) | 19 | 2010-08-20 03:37:41 | <p>I've created several bash aliases in Git Bash on Windows, to launch executables from the bash shell.</p>
<p>The problem I am having is that is seems the bash is waiting for an exit code before it starts responding to input again, as once I close the app it launched, it starts taking commands again.</p>
<p>Is there... | 8,059 | 146,828 | 2025-01-22 19:06:48 | 3,528,098 | 14 | 2010-08-20 03:59:29 | 6,309 | 2025-01-22 19:06:48 | https://stackoverflow.com/q/3528020 | https://stackoverflow.com/a/3528098 | <p>2010: I confirm what <a href="https://stackoverflow.com/users/21656/george">George</a> mentions in the comments:</p>
<p>Launching your alias with '<code>&</code>' allows you to go on without waiting for the return code.</p>
<p><img src="https://i.sstatic.net/Cj2Cn.png" alt="alt text" /></p>
<p>With:</p>
<pre><co... | <p>2010: I confirm what <a href="https://stackoverflow.com/users/21656/george">George</a> mentions in the comments:</p> <p>Launching your alias with '<code>&</code>' allows you to go on without waiting for the return code.</p> <p><img src="https://i.sstatic.net/Cj2Cn.png" alt="alt text" /></p> <p>With:</p> <pre><co... | 119, 387 | bash, git | <h1>Git Bash: Launch Application via Alias without hanging Bash (WIndows)</h1>
<p>I've created several bash aliases in Git Bash on Windows, to launch executables from the bash shell.</p>
<p>The problem I am having is that is seems the bash is waiting for an exit code before it starts responding to input again, as once... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,560 | bash | # Git Bash: Launch Application via Alias without hanging Bash (WIndows)
I've created several bash aliases in Git Bash on Windows, to launch executables from the bash shell.
The problem I am having is that is seems the bash is waiting for an exit code before it starts responding to input again, as once I close the app... | 2010: I confirm what [George](https://stackoverflow.com/users/21656/george) mentions in the comments:
Launching your alias with '`&`' allows you to go on without waiting for the return code.

With:
```
alias npp='notepad.exe&'
```
you won't even have to type in the '`&`'... |
2782602 | BASH: How to remove all files except those named in a manifest? | 19 | 2010-05-06 16:12:06 | <p>I have a manifest file which is just a list of newline separated filenames. How can I remove all files that are <em>not</em> named in the manifest from a folder?</p>
<p>I've tried to build a <code>find ./ ! -name "filename"</code> command dynamically:</p>
<pre><code>command="find ./ ! -name \"MANIFEST\" "
for line... | 9,738 | 140,264 | 2010-05-08 11:50:04 | 2,782,641 | 14 | 2010-05-06 16:17:12 | 4,421 | 2010-05-07 13:10:42 | https://stackoverflow.com/q/2782602 | https://stackoverflow.com/a/2782641 | <p>Using the "set difference" pattern from <a href="http://www.pixelbeat.org/cmdline.html#sets" rel="noreferrer">http://www.pixelbeat.org/cmdline.html#sets</a></p>
<pre><code>(find ./ -type f -printf "%P\n"; cat MANIFEST MANIFEST; echo MANIFEST) |
sort | uniq -u | xargs -r rm
</code></pre>
<p>Note I list MANIFEST t... | <p>Using the "set difference" pattern from <a href="http://www.pixelbeat.org/cmdline.html#sets" rel="noreferrer">http://www.pixelbeat.org/cmdline.html#sets</a></p> <pre><code>(find ./ -type f -printf "%P\n"; cat MANIFEST MANIFEST; echo MANIFEST) | sort | uniq -u | xargs -r rm </code></pre> <p>Note I list MANIFEST t... | 34, 387, 531, 10193 | bash, find, scripting, unix | <h1>BASH: How to remove all files except those named in a manifest?</h1>
<p>I have a manifest file which is just a list of newline separated filenames. How can I remove all files that are <em>not</em> named in the manifest from a folder?</p>
<p>I've tried to build a <code>find ./ ! -name "filename"</code> command dyna... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,561 | bash | # BASH: How to remove all files except those named in a manifest?
I have a manifest file which is just a list of newline separated filenames. How can I remove all files that are *not* named in the manifest from a folder?
I've tried to build a `find ./ ! -name "filename"` command dynamically:
```
command="find ./ ! -... | Using the "set difference" pattern from <http://www.pixelbeat.org/cmdline.html#sets>
```
(find ./ -type f -printf "%P\n"; cat MANIFEST MANIFEST; echo MANIFEST) |
sort | uniq -u | xargs -r rm
```
Note I list MANIFEST twice in case there are files listed there that are not actually present.
Also note the above suppor... |
49252680 | BASH get major/minor version from string | 18 | 2018-03-13 09:36:33 | <p>I am quite new BASH scripting and I am trying to create my own script to download/build from source a package. However I would like to add some interaction to my script to make it future ready for newer versions.</p>
<p>My script asks the user for the version they would like to install and generates the wget comman... | 17,917 | 6,691,275 | 2025-05-09 19:28:52 | 49,254,081 | 14 | 2018-03-13 10:43:00 | 6,691,275 | 2018-03-13 10:43:00 | https://stackoverflow.com/q/49252680 | https://stackoverflow.com/a/49254081 | <p>I have managed to achieve what I was after by doing the following:</p>
<pre><code>shortversion="$(cut -d '.' -f 1 <<< "$packversion")"."$(cut -d '.' -f 2 <<< "$packversion")"
</code></pre>
<p>This then creates a new variable which I can use to create the url.</p>
<pre><code>wget https://example.... | <p>I have managed to achieve what I was after by doing the following:</p> <pre><code>shortversion="$(cut -d '.' -f 1 <<< "$packversion")"."$(cut -d '.' -f 2 <<< "$packversion")" </code></pre> <p>This then creates a new variable which I can use to create the url.</p> <pre><code>wget https://example.... | 58, 387, 4658, 4956, 111433 | bash, centos, devops, linux, system-administration | <h1>BASH get major/minor version from string</h1>
<p>I am quite new BASH scripting and I am trying to create my own script to download/build from source a package. However I would like to add some interaction to my script to make it future ready for newer versions.</p>
<p>My script asks the user for the version they w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,562 | bash | # BASH get major/minor version from string
I am quite new BASH scripting and I am trying to create my own script to download/build from source a package. However I would like to add some interaction to my script to make it future ready for newer versions.
My script asks the user for the version they would like to ins... | I have managed to achieve what I was after by doing the following:
```
shortversion="$(cut -d '.' -f 1 <<< "$packversion")"."$(cut -d '.' -f 2 <<< "$packversion")"
```
This then creates a new variable which I can use to create the url.
```
wget https://example.com/download/$shortversion/src/package-$packversion.tar.... |
49136148 | how to parse json response in powershell | 18 | 2018-03-06 16:55:44 | <p>managed to get the JSON data with </p>
<pre><code>$R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing
$x = $R.Content | Out-String | ConvertFrom-Json
</code></pre>
<p>now I've a JSON file like this :</p>
<pre><code>{
"id": 1000,
"name_with_namespac... | 66,230 | 3,038,574 | 2018-03-06 18:45:13 | 49,136,678 | 14 | 2018-03-06 17:26:17 | 3,245,749 | 2018-03-06 17:26:17 | https://stackoverflow.com/q/49136148 | https://stackoverflow.com/a/49136678 | <p>You're drilling down a level too far when you define your loop. Just iterate <code>$x</code> and then check against the specific property inside the loop.</p>
<pre><code>foreach ($name in $x) {
if ( $name.name_with_namespace -match ".*myProjectName.*" ) {
write-host "$($name.name_with_namespace) - $... | <p>You're drilling down a level too far when you define your loop. Just iterate <code>$x</code> and then check against the specific property inside the loop.</p> <pre><code>foreach ($name in $x) { if ( $name.name_with_namespace -match ".*myProjectName.*" ) { write-host "$($name.name_with_namespace) - $... | 227, 526, 43391 | invoke-command, iteration, powershell | <h1>how to parse json response in powershell</h1>
<p>managed to get the JSON data with </p>
<pre><code>$R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing
$x = $R.Content | Out-String | ConvertFrom-Json
</code></pre>
<p>now I've a JSON file like this :</p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,563 | bash | # how to parse json response in powershell
managed to get the JSON data with
```
$R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing
$x = $R.Content | Out-String | ConvertFrom-Json
```
now I've a JSON file like this :
```
{
"id": 1000,
"name_with_name... | You're drilling down a level too far when you define your loop. Just iterate `$x` and then check against the specific property inside the loop.
```
foreach ($name in $x) {
if ( $name.name_with_namespace -match ".*myProjectName.*" ) {
write-host "$($name.name_with_namespace) - $($name.id)" ... |
44498335 | Command line arguments for msiexec break on PowerShell if they contain space | 18 | 2017-06-12 11:27:43 | <p>I'm trying to set a public property in an InstallShield installer with a value containing space. While running the MSI installer, I'm using below command on PowerShell prompt. Since the value contains a space so I used double quotes to pass the value</p>
<pre><code>msiexec -i "myinstaller.msi" MYDIRPATH=&q... | 10,608 | 465,053 | 2022-11-04 03:01:05 | 44,499,001 | 14 | 2017-06-12 12:04:58 | 4,069,473 | 2017-06-12 12:15:30 | https://stackoverflow.com/q/44498335 | https://stackoverflow.com/a/44499001 | <p><strong>Try with this</strong></p>
<pre><code>msiexec -i "myinstaller.msi" MYDIRPATH=`"C:\new folder\data.txt`"
</code></pre>
<p>The escape character in PowerShell is the grave-accent(`).</p>
| <p><strong>Try with this</strong></p> <pre><code>msiexec -i "myinstaller.msi" MYDIRPATH=`"C:\new folder\data.txt`" </code></pre> <p>The escape character in PowerShell is the grave-accent(`).</p> | 526, 1914, 2015, 31134 | command-line-arguments, installshield, powershell, windows-installer | <h1>Command line arguments for msiexec break on PowerShell if they contain space</h1>
<p>I'm trying to set a public property in an InstallShield installer with a value containing space. While running the MSI installer, I'm using below command on PowerShell prompt. Since the value contains a space so I used double quote... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,564 | bash | # Command line arguments for msiexec break on PowerShell if they contain space
I'm trying to set a public property in an InstallShield installer with a value containing space. While running the MSI installer, I'm using below command on PowerShell prompt. Since the value contains a space so I used double quotes to pass... | **Try with this**
```
msiexec -i "myinstaller.msi" MYDIRPATH=`"C:\new folder\data.txt`"
```
The escape character in PowerShell is the grave-accent(`). |
42935001 | Zipping files with relative path? | 18 | 2017-03-21 18:08:35 | <p>I'm trying to create backups of my USB key. For that, I'd need to zip the content of my USB key (<code>/Volumes/<USB KEY NAME>/</code>). I have this code for the moment<br>
<code>zip -r /Volumes/<USB KEY NAME>/*</code>
That seems to work, except the fact that when I extract my archive, I get : </p>
<p>... | 19,113 | 7,190,378 | 2023-08-31 06:21:29 | 42,935,152 | 14 | 2017-03-21 18:16:16 | 7,576,428 | 2017-03-22 04:49:14 | https://stackoverflow.com/q/42935001 | https://stackoverflow.com/a/42935152 | <p>Try using the <code>-j</code> option.</p>
<p>It stores just the name of the saved files (junk the path), and does not store directory names. By default, <code>zip</code> will store the full path (relative to the current path).</p>
| <p>Try using the <code>-j</code> option.</p> <p>It stores just the name of the saved files (junk the path), and does not store directory names. By default, <code>zip</code> will store the full path (relative to the current path).</p> | 369, 387, 881, 6268 | bash, macos, path, zip | <h1>Zipping files with relative path?</h1>
<p>I'm trying to create backups of my USB key. For that, I'd need to zip the content of my USB key (<code>/Volumes/<USB KEY NAME>/</code>). I have this code for the moment<br>
<code>zip -r /Volumes/<USB KEY NAME>/*</code>
That seems to work, except the fact that wh... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,565 | bash | # Zipping files with relative path?
I'm trying to create backups of my USB key. For that, I'd need to zip the content of my USB key (`/Volumes/<USB KEY NAME>/`). I have this code for the moment
`zip -r /Volumes/<USB KEY NAME>/*`
That seems to work, except the fact that when I extract my archive, I get :
(For simplf... | Try using the `-j` option.
It stores just the name of the saved files (junk the path), and does not store directory names. By default, `zip` will store the full path (relative to the current path). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.