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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
48053201 | docker run throws "invalid reference format: repository name must be lowercase" using $(pwd) in volume flag | 10 | 2018-01-01 21:00:12 | <p><code>docker run</code> throws an "invalid reference format: repository name must be lowercase" error when using <code>$(pwd)</code> in the volume flag (<code>-v</code>). This is the command that is currently causing the issue:</p>
<pre><code>docker run --rm -v $(pwd)/app/polymer:/home/polymer/app jefferyb/polymer-... | 13,461 | 2,230,347 | 2018-01-02 00:26:43 | 48,053,202 | 15 | 2018-01-01 21:00:12 | 2,230,347 | 2018-01-01 21:08:30 | https://stackoverflow.com/q/48053201 | https://stackoverflow.com/a/48053202 | <p>For my own circumstance, the output of <code>pwd</code> contained a directory with a space (i.e. /something/Problematic Directory/something-else). This was resolved by wrapping <code>$(pwd)</code> in quotation marks to explicitly identify it as a string:</p>
<pre><code>docker run --rm -v "$(pwd)/app/polymer":/home/... | <p>For my own circumstance, the output of <code>pwd</code> contained a directory with a space (i.e. /something/Problematic Directory/something-else). This was resolved by wrapping <code>$(pwd)</code> in quotation marks to explicitly identify it as a string:</p> <pre><code>docker run --rm -v "$(pwd)/app/polymer":/home/... | 390, 90304 | docker, shell | <h1>docker run throws "invalid reference format: repository name must be lowercase" using $(pwd) in volume flag</h1>
<p><code>docker run</code> throws an "invalid reference format: repository name must be lowercase" error when using <code>$(pwd)</code> in the volume flag (<code>-v</code>). This is the command that is c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,263 | bash | # docker run throws "invalid reference format: repository name must be lowercase" using $(pwd) in volume flag
`docker run` throws an "invalid reference format: repository name must be lowercase" error when using `$(pwd)` in the volume flag (`-v`). This is the command that is currently causing the issue:
```
docker ru... | For my own circumstance, the output of `pwd` contained a directory with a space (i.e. /something/Problematic Directory/something-else). This was resolved by wrapping `$(pwd)` in quotation marks to explicitly identify it as a string:
```
docker run --rm -v "$(pwd)/app/polymer":/home/polymer/app jefferyb/polymer-cli pol... |
47026533 | Total number of lines in a directory | 10 | 2017-10-31 01:17:32 | <p>I have a directory with thousands of files (100K for now). When I use <code>wc -l ./*</code>, I'll get: <br></p>
<pre><code> c1 ./test1.txt
c2 ./test2.txt
...
cn ./testn.txt
c1+c2+...+cn total
</code></pre>
<p>Because there are a lot of files in the directory, I just want to s... | 17,473 | 6,753,906 | 2023-09-30 08:48:29 | 47,026,899 | 15 | 2017-10-31 02:12:43 | 6,369,159 | 2023-09-30 08:48:29 | https://stackoverflow.com/q/47026533 | https://stackoverflow.com/a/47026899 | <p>If what you want is the total number of lines and nothing else, then I would suggest the following command:</p>
<pre><code>cat * | wc -l
</code></pre>
<p>This <a href="https://en.wiktionary.org/wiki/concatenate#English" rel="nofollow noreferrer">concatenates</a> the contents of all of the files in the current workin... | <p>If what you want is the total number of lines and nothing else, then I would suggest the following command:</p> <pre><code>cat * | wc -l </code></pre> <p>This <a href="https://en.wiktionary.org/wiki/concatenate#English" rel="nofollow noreferrer">concatenates</a> the contents of all of the files in the current workin... | 58, 387, 531, 1231 | bash, command-line, linux, scripting | <h1>Total number of lines in a directory</h1>
<p>I have a directory with thousands of files (100K for now). When I use <code>wc -l ./*</code>, I'll get: <br></p>
<pre><code> c1 ./test1.txt
c2 ./test2.txt
...
cn ./testn.txt
c1+c2+...+cn total
</code></pre>
<p>Because there are a l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,264 | bash | # Total number of lines in a directory
I have a directory with thousands of files (100K for now). When I use `wc -l ./*`, I'll get:
```
c1 ./test1.txt
c2 ./test2.txt
...
cn ./testn.txt
c1+c2+...+cn total
```
Because there are a lot of files in the directory, I just want to see ... | If what you want is the total number of lines and nothing else, then I would suggest the following command:
```
cat * | wc -l
```
This [concatenates](https://en.wiktionary.org/wiki/concatenate#English) the contents of all of the files in the current working directory and pipes the resulting blob of text through `wc -... |
43308663 | Measure-Object : The property "length" cannot be found in the input for any objects | 10 | 2017-04-09 15:40:17 | <p>I'm creating a menu and one of the options is to report on folder size for a specified folder and display it back to the user. After I put in the folder name </p>
<pre><code>cls
$Path = Read-Host -Prompt 'Please enter the folder name: '
$FolderItems = (Get-ChildItem $Path -recurse | Measure-Object -property length... | 23,025 | 7,835,383 | 2017-04-09 15:52:17 | 43,308,784 | 15 | 2017-04-09 15:52:17 | 702,944 | 2017-04-09 15:52:17 | https://stackoverflow.com/q/43308663 | https://stackoverflow.com/a/43308784 | <p>There are no files in the folders, so you only get <code>DirectoryInfo</code>-objects which doesn't have a <code>length</code>-property. You can avoid this by filtering for files-only using:</p>
<pre><code>(Get-ChildItem $Path -Recurse | Where-Object { -not $_.PSIsContainer } | Measure-Object -property length -sum)... | <p>There are no files in the folders, so you only get <code>DirectoryInfo</code>-objects which doesn't have a <code>length</code>-property. You can avoid this by filtering for files-only using:</p> <pre><code>(Get-ChildItem $Path -Recurse | Where-Object { -not $_.PSIsContainer } | Measure-Object -property length -sum)... | 526 | powershell | <h1>Measure-Object : The property "length" cannot be found in the input for any objects</h1>
<p>I'm creating a menu and one of the options is to report on folder size for a specified folder and display it back to the user. After I put in the folder name </p>
<pre><code>cls
$Path = Read-Host -Prompt 'Please enter the f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,265 | bash | # Measure-Object : The property "length" cannot be found in the input for any objects
I'm creating a menu and one of the options is to report on folder size for a specified folder and display it back to the user. After I put in the folder name
```
cls
$Path = Read-Host -Prompt 'Please enter the folder name: '
$Folde... | There are no files in the folders, so you only get `DirectoryInfo`-objects which doesn't have a `length`-property. You can avoid this by filtering for files-only using:
```
(Get-ChildItem $Path -Recurse | Where-Object { -not $_.PSIsContainer } | Measure-Object -property length -sum)
```
Or for PS 3.0+
```
(Get-Child... |
38483692 | What does " :: " do and how do you use " :: " in powershell scripts? | 10 | 2016-07-20 14:11:48 | <p>Is it the equivalent of objectName.method or attribute in C#? An example or 2 would be helpful to learn exactly how to use this syntax of ::</p>
| 16,106 | 6,595,879 | 2023-09-03 13:32:53 | 38,483,877 | 15 | 2016-07-20 14:21:00 | 712,649 | 2023-09-03 13:32:53 | https://stackoverflow.com/q/38483692 | https://stackoverflow.com/a/38483877 | <p>From the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3#static-member-operator-" rel="nofollow noreferrer">about_Operators</a> help topic:</p>
<pre class="lang-none prettyprint-override"><code>:: Static member operator
Calls the st... | <p>From the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3#static-member-operator-" rel="nofollow noreferrer">about_Operators</a> help topic:</p> <pre class="lang-none prettyprint-override"><code>:: Static member operator Calls the st... | 276, 526, 7992 | operators, powershell, variables | <h1>What does " :: " do and how do you use " :: " in powershell scripts?</h1>
<p>Is it the equivalent of objectName.method or attribute in C#? An example or 2 would be helpful to learn exactly how to use this syntax of ::</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,266 | bash | # What does " :: " do and how do you use " :: " in powershell scripts?
Is it the equivalent of objectName.method or attribute in C#? An example or 2 would be helpful to learn exactly how to use this syntax of :: | From the [about_Operators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3#static-member-operator-) help topic:
```
:: Static member operator
Calls the static properties operator and methods of a .NET
Framework class. To find the static pr... |
33433420 | How to interactively expand a bang command in bash? | 10 | 2015-10-30 10:08:48 | <p>Shells like zsh and bash have <em>bang commands</em> which start with an exclamation mark and expand to items in the user's history.</p>
<p>To get the last argument of the the last command that was run, one can use <code>!$</code>, e.g.</p>
<pre><code>$ echo one two three
$ echo !$ !$ !$
> three three three
</c... | 2,635 | 201,318 | 2015-10-30 12:24:35 | 33,435,083 | 15 | 2015-10-30 11:37:39 | 1,126,841 | 2015-10-30 11:37:39 | https://stackoverflow.com/q/33433420 | https://stackoverflow.com/a/33435083 | <p>There are a few options you can use for history expansion. One is the <code>:p</code> modifier, which prints the expanded command instead of executing it.</p>
<pre><code>$ echo foo
$ !!:p
echo foo
</code></pre>
<p>Another is to use the <code>histverify</code> option, which puts the result of history expansion in t... | <p>There are a few options you can use for history expansion. One is the <code>:p</code> modifier, which prints the expanded command instead of executing it.</p> <pre><code>$ echo foo $ !!:p echo foo </code></pre> <p>Another is to use the <code>histverify</code> option, which puts the result of history expansion in t... | 387, 390, 3791 | bash, shell, zsh | <h1>How to interactively expand a bang command in bash?</h1>
<p>Shells like zsh and bash have <em>bang commands</em> which start with an exclamation mark and expand to items in the user's history.</p>
<p>To get the last argument of the the last command that was run, one can use <code>!$</code>, e.g.</p>
<pre><code>$ ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,267 | bash | # How to interactively expand a bang command in bash?
Shells like zsh and bash have *bang commands* which start with an exclamation mark and expand to items in the user's history.
To get the last argument of the the last command that was run, one can use `!$`, e.g.
```
$ echo one two three
$ echo !$ !$ !$
> three th... | There are a few options you can use for history expansion. One is the `:p` modifier, which prints the expanded command instead of executing it.
```
$ echo foo
$ !!:p
echo foo
```
Another is to use the `histverify` option, which puts the result of history expansion in the shell buffer for editing instead of immediatel... |
33407839 | Select-Object returns the first result as my column name instead of as a result | 10 | 2015-10-29 07:02:37 | <p>The following script checks mailboxes in a specified OU for users with the default permission set to Owner. I have tried everything to add the column "Name" from the variable <code>$Mailbox</code> to the Select-Object results in the following code. The result will add a column header with the first results... | 29,528 | 5,493,968 | 2020-09-29 22:31:32 | 33,408,129 | 15 | 2015-10-29 07:21:53 | 5,497,482 | 2020-09-29 22:30:40 | https://stackoverflow.com/q/33407839 | https://stackoverflow.com/a/33408129 | <p>Instead of</p>
<pre><code>Select-Object Identity, AccessRights, $MailBox.Name}
</code></pre>
<p>Add this</p>
<pre><code>Select-Object Identity, AccessRights, @{l="Name";e={$MailBox.Name}}}
</code></pre>
<p>where <code>l</code> stands for Label and <code>e</code> stands for Expression.</p>
<p>You can re... | <p>Instead of</p> <pre><code>Select-Object Identity, AccessRights, $MailBox.Name} </code></pre> <p>Add this</p> <pre><code>Select-Object Identity, AccessRights, @{l="Name";e={$MailBox.Name}}} </code></pre> <p>where <code>l</code> stands for Label and <code>e</code> stands for Expression.</p> <p>You can re... | 526 | powershell | <h1>Select-Object returns the first result as my column name instead of as a result</h1>
<p>The following script checks mailboxes in a specified OU for users with the default permission set to Owner. I have tried everything to add the column "Name" from the variable <code>$Mailbox</code> to the Select-Object ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,268 | bash | # Select-Object returns the first result as my column name instead of as a result
The following script checks mailboxes in a specified OU for users with the default permission set to Owner. I have tried everything to add the column "Name" from the variable `$Mailbox` to the Select-Object results in the following code.... | Instead of
```
Select-Object Identity, AccessRights, $MailBox.Name}
```
Add this
```
Select-Object Identity, AccessRights, @{l="Name";e={$MailBox.Name}}}
```
where `l` stands for Label and `e` stands for Expression.
You can read more about custom tables here <https://technet.microsoft.com/en-us/library/ee692794.... |
31885409 | Why would a correct shell script give a wrapped/truncated/corrupted error message? | 10 | 2015-08-07 19:39:24 | <p>I have a shell script with a command that seems like it should work, but instead it fails with an odd wrapped/truncated/corrupted error message. Example:</p>
<pre><code>$ ls -l myfile
-rw-r----- 1 me me 0 Aug 7 12:36 myfile
$ cat myscript
ls -l myfile
$ bash myscript
: No such file or directory
</code></pre>
<p>... | 4,301 | 1,899,640 | 2016-09-01 12:36:57 | 31,885,410 | 15 | 2015-08-07 19:39:24 | 1,899,640 | 2015-08-07 19:39:24 | https://stackoverflow.com/q/31885409 | https://stackoverflow.com/a/31885410 | <p>TL;DR: Your script or data has Windows style CRLF line endings.</p>
<p>Convert to Unix style by deleting the carriage returns. </p>
<hr>
<h3>How do I check if my script or data has carriage returns?</h3>
<p>They're detectable as <code>^M</code> in the output of <code>cat -v yourscript</code>:</p>
<pre><code>$ c... | <p>TL;DR: Your script or data has Windows style CRLF line endings.</p> <p>Convert to Unix style by deleting the carriage returns. </p> <hr> <h3>How do I check if my script or data has carriage returns?</h3> <p>They're detectable as <code>^M</code> in the output of <code>cat -v yourscript</code>:</p> <pre><code>$ c... | 387, 390, 10327, 14899 | bash, carriage-return, sh, shell | <h1>Why would a correct shell script give a wrapped/truncated/corrupted error message?</h1>
<p>I have a shell script with a command that seems like it should work, but instead it fails with an odd wrapped/truncated/corrupted error message. Example:</p>
<pre><code>$ ls -l myfile
-rw-r----- 1 me me 0 Aug 7 12:36 myfile... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,269 | bash | # Why would a correct shell script give a wrapped/truncated/corrupted error message?
I have a shell script with a command that seems like it should work, but instead it fails with an odd wrapped/truncated/corrupted error message. Example:
```
$ ls -l myfile
-rw-r----- 1 me me 0 Aug 7 12:36 myfile
$ cat myscript
ls ... | TL;DR: Your script or data has Windows style CRLF line endings.
Convert to Unix style by deleting the carriage returns.
---
### How do I check if my script or data has carriage returns?
They're detectable as `^M` in the output of `cat -v yourscript`:
```
$ cat -v myscript
ls -l myfile^M
```
If your script doesn't... |
28533250 | Keep being prompted to enter passphrase for .ssh/id_rsa | 10 | 2015-02-16 01:19:22 | <p>I followed the tutorial <a href="https://help.github.com/articles/generating-ssh-keys/" rel="noreferrer">here</a> to set up ssh for github in cygwin on Window 7. However, every time I do <code>git push origin master</code>, I keep being prompted the following: </p>
<p><code>Enter passphrase for /cygdrive/c/Users/my... | 4,790 | 1,841,131 | 2017-08-22 19:46:59 | 28,533,498 | 15 | 2015-02-16 01:58:14 | 1,108,891 | 2015-02-16 02:44:11 | https://stackoverflow.com/q/28533250 | https://stackoverflow.com/a/28533498 | <p>Add the following to your <code>~/.bash_profile</code>. When bash starts, this does two things: 1. starts the ssh-agent (otherwise it might spawn and die for each push/pull) and 2. tells the agent to remember your passphrase. In some Linux distributions, this happens automatically, unfortunately that isn't the case ... | <p>Add the following to your <code>~/.bash_profile</code>. When bash starts, this does two things: 1. starts the ssh-agent (otherwise it might spawn and die for each push/pull) and 2. tells the agent to remember your passphrase. In some Linux distributions, this happens automatically, unfortunately that isn't the case ... | 119, 386, 387, 1731 | bash, cygwin, git, ssh | <h1>Keep being prompted to enter passphrase for .ssh/id_rsa</h1>
<p>I followed the tutorial <a href="https://help.github.com/articles/generating-ssh-keys/" rel="noreferrer">here</a> to set up ssh for github in cygwin on Window 7. However, every time I do <code>git push origin master</code>, I keep being prompted the fo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,271 | bash | # Keep being prompted to enter passphrase for .ssh/id_rsa
I followed the tutorial [here](https://help.github.com/articles/generating-ssh-keys/) to set up ssh for github in cygwin on Window 7. However, every time I do `git push origin master`, I keep being prompted the following:
`Enter passphrase for /cygdrive/c/User... | Add the following to your `~/.bash_profile`. When bash starts, this does two things: 1. starts the ssh-agent (otherwise it might spawn and die for each push/pull) and 2. tells the agent to remember your passphrase. In some Linux distributions, this happens automatically, unfortunately that isn't the case with Cygwin.
... |
27691434 | Python Virtualenv Check Environment | 10 | 2014-12-29 15:16:38 | <p>I am writing a bash script which need to start a service using <code>virtualenv</code>. I imagine my bash script to look like this:</p>
<pre><code>#!/bin/bash
source /root/user/python-ev/bin/activate
IPYTHON_OPTS="notebook --port 8889 --profile pyspark" pyspark --master spark://701.datafireball.com:7077
</... | 5,883 | 1,953,475 | 2024-03-26 00:27:44 | 27,691,578 | 15 | 2014-12-29 15:26:27 | 4,398,718 | 2014-12-29 15:37:49 | https://stackoverflow.com/q/27691434 | https://stackoverflow.com/a/27691578 | <p>You can check for the environment variable <strong>VIRTUAL_ENV</strong> and see if it has the correct source path. Now if it doesn't exist then you know it's not activated. If it does, you need to check and see if it has the correct path.</p>
<p>The correct bash snippet that will work to check if the variable is se... | <p>You can check for the environment variable <strong>VIRTUAL_ENV</strong> and see if it has the correct source path. Now if it doesn't exist then you know it's not activated. If it does, you need to check and see if it has the correct path.</p> <p>The correct bash snippet that will work to check if the variable is se... | 16, 387, 14529 | bash, python, virtualenv | <h1>Python Virtualenv Check Environment</h1>
<p>I am writing a bash script which need to start a service using <code>virtualenv</code>. I imagine my bash script to look like this:</p>
<pre><code>#!/bin/bash
source /root/user/python-ev/bin/activate
IPYTHON_OPTS="notebook --port 8889 --profile pyspark" pyspark ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,272 | bash | # Python Virtualenv Check Environment
I am writing a bash script which need to start a service using `virtualenv`. I imagine my bash script to look like this:
```
#!/bin/bash
source /root/user/python-ev/bin/activate
IPYTHON_OPTS="notebook --port 8889 --profile pyspark" pyspark --master spark://701.datafireball.com:70... | You can check for the environment variable **VIRTUAL_ENV** and see if it has the correct source path. Now if it doesn't exist then you know it's not activated. If it does, you need to check and see if it has the correct path.
The correct bash snippet that will work to check if the variable is set or not is the followi... |
26407989 | Create a session in the background if it doesn't exist but do not attach in tmux | 10 | 2014-10-16 15:16:21 | <p>I've looked at <a href="https://stackoverflow.com/questions/3432536/create-session-if-none-exists">this similar question</a> which asks about creating a <code>tmux</code> session, or attaching if it doesn't exist. </p>
<p>What I'd like to do is a little different: create a <code>tmux</code> session if it doesn't ex... | 9,411 | 939,259 | 2016-01-23 14:54:16 | 26,408,906 | 15 | 2014-10-16 16:00:44 | 215,392 | 2014-10-16 16:00:44 | https://stackoverflow.com/q/26407989 | https://stackoverflow.com/a/26408906 | <p>If you try to create a session with the same name tmux returns an error with exit code 1.</p>
<pre><code>drizzt@liara ~ % tmux new-session -d -s test
drizzt@liara ~ % tmux new-session -d -s test
duplicate session: test
drizzt@liara ~ % echo $?
1
drizzt@liara ~ %
</code></pre>
<p>If you don't like the duplicate s... | <p>If you try to create a session with the same name tmux returns an error with exit code 1.</p> <pre><code>drizzt@liara ~ % tmux new-session -d -s test drizzt@liara ~ % tmux new-session -d -s test duplicate session: test drizzt@liara ~ % echo $? 1 drizzt@liara ~ % </code></pre> <p>If you don't like the duplicate s... | 390, 60238 | shell, tmux | <h1>Create a session in the background if it doesn't exist but do not attach in tmux</h1>
<p>I've looked at <a href="https://stackoverflow.com/questions/3432536/create-session-if-none-exists">this similar question</a> which asks about creating a <code>tmux</code> session, or attaching if it doesn't exist. </p>
<p>What... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,273 | bash | # Create a session in the background if it doesn't exist but do not attach in tmux
I've looked at [this similar question](https://stackoverflow.com/questions/3432536/create-session-if-none-exists) which asks about creating a `tmux` session, or attaching if it doesn't exist.
What I'd like to do is a little different: ... | If you try to create a session with the same name tmux returns an error with exit code 1.
```
drizzt@liara ~ % tmux new-session -d -s test
drizzt@liara ~ % tmux new-session -d -s test
duplicate session: test
drizzt@liara ~ % echo $?
1
drizzt@liara ~ %
```
If you don't like the duplicate session error you can do some... |
11160931 | Trouble with powershell commas | 10 | 2012-06-22 17:07:40 | <p>Im trying to write a very brief powershell script that runs a few commands, pipes their output to a text file, and then does a search against a keyword.</p>
<p>I cant figure out what to change however for this line:</p>
<pre><code>wmic service get name, startname | out-File "$pwd\admin\wmic.txt"
WMIC.exe : Invali... | 19,630 | 1,475,442 | 2021-06-03 18:21:58 | 26,007,070 | 15 | 2014-09-24 01:23:23 | 4,072,684 | 2014-09-24 02:00:06 | https://stackoverflow.com/q/11160931 | https://stackoverflow.com/a/26007070 | <pre class="lang-powershell prettyprint-override"><code>wmic service get name"," startname| out-File "$pwd\admin\wmic.txt"
</code></pre>
<p>This is easy to resolve comma, no change at all.</p>
| <pre class="lang-powershell prettyprint-override"><code>wmic service get name"," startname| out-File "$pwd\admin\wmic.txt" </code></pre> <p>This is easy to resolve comma, no change at all.</p> | 526, 61774 | powershell, wmic | <h1>Trouble with powershell commas</h1>
<p>Im trying to write a very brief powershell script that runs a few commands, pipes their output to a text file, and then does a search against a keyword.</p>
<p>I cant figure out what to change however for this line:</p>
<pre><code>wmic service get name, startname | out-File ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,274 | bash | # Trouble with powershell commas
Im trying to write a very brief powershell script that runs a few commands, pipes their output to a text file, and then does a search against a keyword.
I cant figure out what to change however for this line:
```
wmic service get name, startname | out-File "$pwd\admin\wmic.txt"
WMIC... | ```
wmic service get name"," startname| out-File "$pwd\admin\wmic.txt"
```
This is easy to resolve comma, no change at all. |
23998364 | Bash Completion script to complete file path after certain arguments options | 10 | 2014-06-02 15:42:55 | <p>I am writing a bash completion script for a command-line tool:</p>
<pre><code>_plink()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--1 --23file --a1-allele --a2-allele --adjust --aec"
if [[ ${cur} == --*file ]] || [[ ${cur} == ... | 6,612 | 562,222 | 2019-11-22 09:56:48 | 23,999,768 | 15 | 2014-06-02 17:05:06 | 7,412 | 2019-11-22 09:31:36 | https://stackoverflow.com/q/23998364 | https://stackoverflow.com/a/23999768 | <p>You can use <code>compgen -f</code> to complete filenames, like this:</p>
<pre><code>if [[ ${prev} == --*file ]] || [[ ${prev} == --out ]]; then
COMPREPLY=( $(compgen -f -- ${cur}) )
elif ...
</code></pre>
<p>However, <code>compgen -f</code> isn't great at completing filenames because it doesn't honour spaces ... | <p>You can use <code>compgen -f</code> to complete filenames, like this:</p> <pre><code>if [[ ${prev} == --*file ]] || [[ ${prev} == --out ]]; then COMPREPLY=( $(compgen -f -- ${cur}) ) elif ... </code></pre> <p>However, <code>compgen -f</code> isn't great at completing filenames because it doesn't honour spaces ... | 387, 390, 4682 | autocomplete, bash, shell | <h1>Bash Completion script to complete file path after certain arguments options</h1>
<p>I am writing a bash completion script for a command-line tool:</p>
<pre><code>_plink()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--1 --23file --... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,275 | bash | # Bash Completion script to complete file path after certain arguments options
I am writing a bash completion script for a command-line tool:
```
_plink()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--1 --23file --a1-allele --a2-allel... | You can use `compgen -f` to complete filenames, like this:
```
if [[ ${prev} == --*file ]] || [[ ${prev} == --out ]]; then
COMPREPLY=( $(compgen -f -- ${cur}) )
elif ...
```
However, `compgen -f` isn't great at completing filenames because it doesn't honour spaces in filenames.
A better way is to use the `_filed... |
23713582 | Git Bash giving sh.exe: ruby: command not found | 10 | 2014-05-17 16:22:39 | <p>I am using Git Bash on Windows Vista Business. I am trying to install Redmine. Basically on step 4, I need to get RubyGem installed before I install the bundler as part of the dependency install (<a href="http://www.redmine.org/projects/redmine/wiki/RedmineInstall" rel="noreferrer">http://www.redmine.org/projects/re... | 21,410 | 3,648,008 | 2017-12-06 22:45:39 | 23,714,590 | 15 | 2014-05-17 18:11:48 | 3,399,164 | 2015-03-02 20:56:06 | https://stackoverflow.com/q/23713582 | https://stackoverflow.com/a/23714590 | <p>If you already installed ruby, you have to include correct path.</p>
<p>Right click <code>My Computer</code>, click <code>Properties</code>, go to <code>Advanced System Settings</code> left navigation, click on <code>Environment Variables...</code> button, go to <code>System Variables</code> below, select <code>Pat... | <p>If you already installed ruby, you have to include correct path.</p> <p>Right click <code>My Computer</code>, click <code>Properties</code>, go to <code>Advanced System Settings</code> left navigation, click on <code>Environment Variables...</code> button, go to <code>System Variables</code> below, select <code>Pat... | 12, 119, 387 | bash, git, ruby | <h1>Git Bash giving sh.exe: ruby: command not found</h1>
<p>I am using Git Bash on Windows Vista Business. I am trying to install Redmine. Basically on step 4, I need to get RubyGem installed before I install the bundler as part of the dependency install (<a href="http://www.redmine.org/projects/redmine/wiki/RedmineIns... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,276 | bash | # Git Bash giving sh.exe: ruby: command not found
I am using Git Bash on Windows Vista Business. I am trying to install Redmine. Basically on step 4, I need to get RubyGem installed before I install the bundler as part of the dependency install (<http://www.redmine.org/projects/redmine/wiki/RedmineInstall>). I downloa... | If you already installed ruby, you have to include correct path.
Right click `My Computer`, click `Properties`, go to `Advanced System Settings` left navigation, click on `Environment Variables...` button, go to `System Variables` below, select `Path`, click `Edit` and in the beginning of the path enter: `C:\Ruby200\b... |
22389795 | How do I schedule a timed reboot of my server in seconds? | 10 | 2014-03-13 20:09:00 | <p>I’m using bash shell on Linux …</p>
<pre><code>$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<p>although it would be nice if I could come up with a solution in any bash supported environment. My question is, in my ... | 31,322 | 1,235,929 | 2016-03-11 09:10:44 | 22,389,816 | 15 | 2014-03-13 20:10:44 | 841,108 | 2016-03-11 09:10:44 | https://stackoverflow.com/q/22389795 | https://stackoverflow.com/a/22389816 | <p>Try</p>
<pre><code> sleep 5 ; reboot
</code></pre>
<p>on your terminal (as root). If you want it in the background, try</p>
<pre><code> ( sleep 5 ; reboot ) &
</code></pre>
<p>See also <a href="http://man7.org/linux/man-pages/man8/shutdown.8.html" rel="noreferrer">shutdown(8)</a></p>
| <p>Try</p> <pre><code> sleep 5 ; reboot </code></pre> <p>on your terminal (as root). If you want it in the background, try</p> <pre><code> ( sleep 5 ; reboot ) & </code></pre> <p>See also <a href="http://man7.org/linux/man-pages/man8/shutdown.8.html" rel="noreferrer">shutdown(8)</a></p> | 58, 387, 390, 4569 | bash, linux, reboot, shell | <h1>How do I schedule a timed reboot of my server in seconds?</h1>
<p>I’m using bash shell on Linux …</p>
<pre><code>$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<p>although it would be nice if I could come up with a ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,277 | bash | # How do I schedule a timed reboot of my server in seconds?
I’m using bash shell on Linux …
```
$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
```
although it would be nice if I could come up with a solution in any bash supported en... | Try
```
sleep 5 ; reboot
```
on your terminal (as root). If you want it in the background, try
```
( sleep 5 ; reboot ) &
```
See also [shutdown(8)](http://man7.org/linux/man-pages/man8/shutdown.8.html) |
21551341 | Powershell Select-object from cert store | 10 | 2014-02-04 11:34:10 | <p>Essentially I am trying to get the serial number of a certificate by using the subject so I can use it in a variable in CertUtil.</p>
<p>I am so close yet so far as you will see below can anybody help please?</p>
<pre><code>cd cert:\localmachine\my
$serno = get-childitem | where { $_.subject -eq "XXXXXXXXXXXXXXXX... | 23,492 | 1,979,810 | 2014-02-04 11:40:08 | 21,551,483 | 15 | 2014-02-04 11:40:08 | 107,660 | 2014-02-04 11:40:08 | https://stackoverflow.com/q/21551341 | https://stackoverflow.com/a/21551483 | <p>Don't use <code>format-list</code>, you already have all the properties. <code>format-list</code> will convert your nice <code>X509Certificate2</code> object into a set of format objects which isn't what you want at all. Also use <code>-expandproperty</code> on the <code>select</code>:</p>
<pre><code>PS>get-chil... | <p>Don't use <code>format-list</code>, you already have all the properties. <code>format-list</code> will convert your nice <code>X509Certificate2</code> object into a set of format objects which isn't what you want at all. Also use <code>-expandproperty</code> on the <code>select</code>:</p> <pre><code>PS>get-chil... | 526, 5954, 24067 | certificate, powershell, powershell-2.0 | <h1>Powershell Select-object from cert store</h1>
<p>Essentially I am trying to get the serial number of a certificate by using the subject so I can use it in a variable in CertUtil.</p>
<p>I am so close yet so far as you will see below can anybody help please?</p>
<pre><code>cd cert:\localmachine\my
$serno = get-ch... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,278 | bash | # Powershell Select-object from cert store
Essentially I am trying to get the serial number of a certificate by using the subject so I can use it in a variable in CertUtil.
I am so close yet so far as you will see below can anybody help please?
```
cd cert:\localmachine\my
$serno = get-childitem | where { $_.subjec... | Don't use `format-list`, you already have all the properties. `format-list` will convert your nice `X509Certificate2` object into a set of format objects which isn't what you want at all. Also use `-expandproperty` on the `select`:
```
PS>get-childitem | where { $_.subject -eq "CN=localhost" } | select -expandproperty... |
20852807 | Setting private key permissions with PowerShell | 10 | 2013-12-31 06:20:15 | <p>I have a PowerShell script that installs pfx certificate into the <em>LocalMachine</em> certificate store. The function looks like this:</p>
<pre><code>function Add-Certificate {
param
(
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$pfxPath,
[Parameter(Position=2, Man... | 22,096 | 50,354 | 2023-08-29 12:01:12 | 20,853,659 | 15 | 2013-12-31 07:33:15 | null | 2013-12-31 07:51:18 | https://stackoverflow.com/q/20852807 | https://stackoverflow.com/a/20853659 | <p>The problem is the when the <code>X509Certificate2</code> was getting imported via the <code>Import()</code> method, the <code>X509KeyStorageFlags</code> were not configured to write the private key to the computer's private key store. I've updated the function to include the appropriate <code>X509KeyStorageFlags</c... | <p>The problem is the when the <code>X509Certificate2</code> was getting imported via the <code>Import()</code> method, the <code>X509KeyStorageFlags</code> were not configured to write the private key to the computer's private key store. I've updated the function to include the appropriate <code>X509KeyStorageFlags</c... | 359, 526, 20837 | permissions, pfx, powershell | <h1>Setting private key permissions with PowerShell</h1>
<p>I have a PowerShell script that installs pfx certificate into the <em>LocalMachine</em> certificate store. The function looks like this:</p>
<pre><code>function Add-Certificate {
param
(
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,279 | bash | # Setting private key permissions with PowerShell
I have a PowerShell script that installs pfx certificate into the *LocalMachine* certificate store. The function looks like this:
```
function Add-Certificate {
param
(
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$pfxPath,
... | The problem is the when the `X509Certificate2` was getting imported via the `Import()` method, the `X509KeyStorageFlags` were not configured to write the private key to the computer's private key store. I've updated the function to include the appropriate `X509KeyStorageFlags`.
```
function Add-Certificate {
[Cmdl... |
20391943 | How to activate python virtual environment by shell script | 10 | 2013-12-05 05:10:49 | <p>I wrote a shell script as.</p>
<pre><code> source ve/bin/activate
</code></pre>
<p>Saved it as activate_shell.sh latter when I ran the script with command.</p>
<pre><code> bash activate_shell.sh
</code></pre>
<p>The script is being run with no error but the virtual environment is not being activated. </p>
| 14,535 | 992,665 | 2014-03-15 02:16:36 | 20,392,267 | 15 | 2013-12-05 05:36:34 | 223,424 | 2014-03-15 02:16:36 | https://stackoverflow.com/q/20391943 | https://stackoverflow.com/a/20392267 | <p>Your activation script path, <code>ve/bin/activate</code>, is relative. The script will only work from one directory. But the problem is not here.</p>
<p>What does <code>bin/activate</code> do? It modifies the shell <em>in which it runs</em>. This is why you have to <code>source</code> it and not invoke as a regula... | <p>Your activation script path, <code>ve/bin/activate</code>, is relative. The script will only work from one directory. But the problem is not here.</p> <p>What does <code>bin/activate</code> do? It modifies the shell <em>in which it runs</em>. This is why you have to <code>source</code> it and not invoke as a regula... | 16, 390, 549, 14529 | python, shell, ubuntu, virtualenv | <h1>How to activate python virtual environment by shell script</h1>
<p>I wrote a shell script as.</p>
<pre><code> source ve/bin/activate
</code></pre>
<p>Saved it as activate_shell.sh latter when I ran the script with command.</p>
<pre><code> bash activate_shell.sh
</code></pre>
<p>The script is being run wit... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,280 | bash | # How to activate python virtual environment by shell script
I wrote a shell script as.
```
source ve/bin/activate
```
Saved it as activate_shell.sh latter when I ran the script with command.
```
bash activate_shell.sh
```
The script is being run with no error but the virtual environment is not being activ... | Your activation script path, `ve/bin/activate`, is relative. The script will only work from one directory. But the problem is not here.
What does `bin/activate` do? It modifies the shell *in which it runs*. This is why you have to `source` it and not invoke as a regular program.
The script you wrote starts its own co... |
19468016 | bash to batch rename files with adding numbers | 10 | 2013-10-19 15:58:09 | <p>I have a bunch of .jpg files with random names. I want a bash script to rename them like this:</p>
<pre><code>basename-0.jpg
basename-1.jpg
basename-2.jpg
.
.
.
.
basename-1000.jpg
</code></pre>
<p>I wrote this:</p>
<pre><code>n = 0;
for file in *.jpg ; do mv "${file}" basename"${n}".jpg; n+=1; done
</code></pr... | 10,389 | 517,235 | 2013-10-19 18:55:53 | 19,468,181 | 15 | 2013-10-19 16:16:10 | 1,437,346 | 2013-10-19 16:16:10 | https://stackoverflow.com/q/19468016 | https://stackoverflow.com/a/19468181 | <p>Use <code>$((expression))</code> for arithmetic expansion in bash shell</p>
<pre><code>n=0;
for file in *.jpg ; do mv "${file}" basename"${n}".jpg; n=$((n+1)); done
</code></pre>
| <p>Use <code>$((expression))</code> for arithmetic expansion in bash shell</p> <pre><code>n=0; for file in *.jpg ; do mv "${file}" basename"${n}".jpg; n=$((n+1)); done </code></pre> | 387, 13475 | bash, batch-rename | <h1>bash to batch rename files with adding numbers</h1>
<p>I have a bunch of .jpg files with random names. I want a bash script to rename them like this:</p>
<pre><code>basename-0.jpg
basename-1.jpg
basename-2.jpg
.
.
.
.
basename-1000.jpg
</code></pre>
<p>I wrote this:</p>
<pre><code>n = 0;
for file in *.jpg ; do m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,281 | bash | # bash to batch rename files with adding numbers
I have a bunch of .jpg files with random names. I want a bash script to rename them like this:
```
basename-0.jpg
basename-1.jpg
basename-2.jpg
.
.
.
.
basename-1000.jpg
```
I wrote this:
```
n = 0;
for file in *.jpg ; do mv "${file}" basename"${n}".jpg; n+=1; done... | Use `$((expression))` for arithmetic expansion in bash shell
```
n=0;
for file in *.jpg ; do mv "${file}" basename"${n}".jpg; n=$((n+1)); done
``` |
19284296 | How to assign an associative array to another variable in zsh? | 10 | 2013-10-09 23:03:58 | <p>In zsh, is there a way to assign an associative array to another variable? I would like to to something like this:</p>
<pre><code>typeset -A orig
orig=(key1 val1 key2 val2)
typeset -A other
other=$orig
print '$orig: '$orig
print '$other: '$other
print '$orig[key1]: '$orig[key1]
print '$other[key1]: '$other[key1]
<... | 6,050 | 1,342,387 | 2023-05-08 11:59:20 | 19,284,682 | 15 | 2013-10-09 23:43:07 | 1,126,841 | 2013-10-09 23:43:07 | https://stackoverflow.com/q/19284296 | https://stackoverflow.com/a/19284682 | <p>You have to delve into the wonderful world of parameter expansion flags :) The <code>k</code> and <code>v</code> flags can be used together to force an associative array to expand to both its keys and values.</p>
<pre><code>$ typeset -A orig
$ orig=(key1 val1 key2 val2)
$ print ${(kv)orig}
key1 val1 key2 val2
</cod... | <p>You have to delve into the wonderful world of parameter expansion flags :) The <code>k</code> and <code>v</code> flags can be used together to force an associative array to expand to both its keys and values.</p> <pre><code>$ typeset -A orig $ orig=(key1 val1 key2 val2) $ print ${(kv)orig} key1 val1 key2 val2 </cod... | 114, 390, 2575, 3791 | arrays, associative-array, shell, zsh | <h1>How to assign an associative array to another variable in zsh?</h1>
<p>In zsh, is there a way to assign an associative array to another variable? I would like to to something like this:</p>
<pre><code>typeset -A orig
orig=(key1 val1 key2 val2)
typeset -A other
other=$orig
print '$orig: '$orig
print '$other: '$oth... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,282 | bash | # How to assign an associative array to another variable in zsh?
In zsh, is there a way to assign an associative array to another variable? I would like to to something like this:
```
typeset -A orig
orig=(key1 val1 key2 val2)
typeset -A other
other=$orig
print '$orig: '$orig
print '$other: '$other
print '$orig[key1... | You have to delve into the wonderful world of parameter expansion flags :) The `k` and `v` flags can be used together to force an associative array to expand to both its keys and values.
```
$ typeset -A orig
$ orig=(key1 val1 key2 val2)
$ print ${(kv)orig}
key1 val1 key2 val2
```
Then you can use the `set` command t... |
15509576 | How do I create a file listener in linux? | 10 | 2013-03-19 20:17:52 | <p>I am trying to create a listener on a specific directory that kicks off a Linux command whenever a file shows up in this path. For example, whenever a file shows up in a directory like C:/home/ I would like to read a string of text from that file and then kick off another command. I was thinking of using a loop but ... | 10,296 | 529,941 | 2013-03-19 21:52:47 | 15,509,623 | 15 | 2013-03-19 20:20:55 | 1,698,415 | 2013-03-19 21:52:47 | https://stackoverflow.com/q/15509576 | https://stackoverflow.com/a/15509623 | <p>To get notified about events like file creation, opening, modifying etc. look into <a href="http://en.wikipedia.org/wiki/Inotify" rel="noreferrer">inotify</a>. A good way to use it from bash is with the <code>inotifywait</code> command - <a href="http://linux.die.net/man/1/inotifywait" rel="noreferrer">here</a> is i... | <p>To get notified about events like file creation, opening, modifying etc. look into <a href="http://en.wikipedia.org/wiki/Inotify" rel="noreferrer">inotify</a>. A good way to use it from bash is with the <code>inotifywait</code> command - <a href="http://linux.die.net/man/1/inotifywait" rel="noreferrer">here</a> is i... | 58, 387, 390, 11273 | bash, linux, listener, shell | <h1>How do I create a file listener in linux?</h1>
<p>I am trying to create a listener on a specific directory that kicks off a Linux command whenever a file shows up in this path. For example, whenever a file shows up in a directory like C:/home/ I would like to read a string of text from that file and then kick off a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,283 | bash | # How do I create a file listener in linux?
I am trying to create a listener on a specific directory that kicks off a Linux command whenever a file shows up in this path. For example, whenever a file shows up in a directory like C:/home/ I would like to read a string of text from that file and then kick off another co... | To get notified about events like file creation, opening, modifying etc. look into [inotify](http://en.wikipedia.org/wiki/Inotify). A good way to use it from bash is with the `inotifywait` command - [here](http://linux.die.net/man/1/inotifywait) is its man page. It will block until an event you care about happens. For ... |
14802963 | Formatting an integer x.xxxxx as xx.xxx | 10 | 2013-02-10 21:48:20 | <p>I have a number, <code>$int</code>,</p>
<pre><code>$int = 9.5587452369
</code></pre>
<p>I want this number to be in the format xx.xxx
I tried:</p>
<pre><code>$int = "{0:N3}" -f ($int)
$int = "{0:D2}" -f ($int)
</code></pre>
<p>or</p>
<pre><code>$int = "{0:D2}" -f ("{0:N3}" -f ($int))
</code></pre>
<p>But it do... | 12,911 | 2,059,688 | 2024-08-22 13:16:15 | 14,802,991 | 15 | 2013-02-10 21:51:56 | 702,944 | 2013-02-10 22:07:31 | https://stackoverflow.com/q/14802963 | https://stackoverflow.com/a/14802991 | <p>Use the <code>toString()</code> method with specified format.</p>
<pre><code>PS > $int = 9.5587452369
PS > $int.ToString("00.000")
09,559
</code></pre>
<p>Or</p>
<pre><code>PS > "{0:00.000}" -f $int
09,559
</code></pre>
<p>Read more at <a href="http://msdn.microsoft.com/en-us/library/0c899ak8.aspx">MSD... | <p>Use the <code>toString()</code> method with specified format.</p> <pre><code>PS > $int = 9.5587452369 PS > $int.ToString("00.000") 09,559 </code></pre> <p>Or</p> <pre><code>PS > "{0:00.000}" -f $int 09,559 </code></pre> <p>Read more at <a href="http://msdn.microsoft.com/en-us/library/0c899ak8.aspx">MSD... | 526, 555 | formatting, powershell | <h1>Formatting an integer x.xxxxx as xx.xxx</h1>
<p>I have a number, <code>$int</code>,</p>
<pre><code>$int = 9.5587452369
</code></pre>
<p>I want this number to be in the format xx.xxx
I tried:</p>
<pre><code>$int = "{0:N3}" -f ($int)
$int = "{0:D2}" -f ($int)
</code></pre>
<p>or</p>
<pre><code>$int = "{0:D2}" -f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,284 | bash | # Formatting an integer x.xxxxx as xx.xxx
I have a number, `$int`,
```
$int = 9.5587452369
```
I want this number to be in the format xx.xxx
I tried:
```
$int = "{0:N3}" -f ($int)
$int = "{0:D2}" -f ($int)
```
or
```
$int = "{0:D2}" -f ("{0:N3}" -f ($int))
```
But it doesn't work. Any Ideas? | Use the `toString()` method with specified format.
```
PS > $int = 9.5587452369
PS > $int.ToString("00.000")
09,559
```
Or
```
PS > "{0:00.000}" -f $int
09,559
```
Read more at [MSDN - Custom Numeric Format Strings](http://msdn.microsoft.com/en-us/library/0c899ak8.aspx) |
14438406 | What is the meaning of "-" (minus) in this bash command? | 10 | 2013-01-21 12:15:27 | <p>Could somebody explain to me what is the meaning of the <code>-</code> (minus) sign in the following command?</p>
<pre><code>wget -O - "https://www.some-domain.com/file.tar.gz" | tar xzf -
</code></pre>
| 10,172 | 268,167 | 2020-09-04 14:21:58 | 14,438,441 | 15 | 2013-01-21 12:16:56 | 1,501,222 | 2013-01-21 13:42:42 | https://stackoverflow.com/q/14438406 | https://stackoverflow.com/a/14438441 | <p><code>-</code> depends on the command and how it responds to it. but it usually means the stdout/stdin in bash commands.</p>
<p>In this case, <code>-</code> is the argument to the <code>-O</code> option, so
the downloaded data is not saved in a file, but printed to stdout, so it can be piped to the tar command</p>... | <p><code>-</code> depends on the command and how it responds to it. but it usually means the stdout/stdin in bash commands.</p> <p>In this case, <code>-</code> is the argument to the <code>-O</code> option, so the downloaded data is not saved in a file, but printed to stdout, so it can be piped to the tar command</p>... | 387 | bash | <h1>What is the meaning of "-" (minus) in this bash command?</h1>
<p>Could somebody explain to me what is the meaning of the <code>-</code> (minus) sign in the following command?</p>
<pre><code>wget -O - "https://www.some-domain.com/file.tar.gz" | tar xzf -
</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,285 | bash | # What is the meaning of "-" (minus) in this bash command?
Could somebody explain to me what is the meaning of the `-` (minus) sign in the following command?
```
wget -O - "https://www.some-domain.com/file.tar.gz" | tar xzf -
``` | `-` depends on the command and how it responds to it. but it usually means the stdout/stdin in bash commands.
In this case, `-` is the argument to the `-O` option, so
the downloaded data is not saved in a file, but printed to stdout, so it can be piped to the tar command |
14061876 | control to the next statement after running eval command | 10 | 2012-12-27 22:02:09 | <p>I have written a bash script to run a service in background and exit from the script to command line. But after running the eval command, control does not go the next statement.</p>
<pre><code>COMMAND="nohup java -jar jenkins.war"
echo "starting service"
eval $COMMAND
echo "service running"
exit
</code></pre>
<p>e... | 6,133 | 1,164,061 | 2012-12-28 03:28:39 | 14,061,950 | 15 | 2012-12-27 22:08:56 | 1,815,797 | 2012-12-27 22:55:00 | https://stackoverflow.com/q/14061876 | https://stackoverflow.com/a/14061950 | <p>Please, don't put a command with its arguments in a <em>string</em>. Put your command and its arguments in an <em>array</em> (and don't use upper-case variable names, that's a terribly bad practice), and <strong>do not use <code>eval</code></strong>. <code>eval</code> is evil!</p>
<pre><code>command=( nohup java -j... | <p>Please, don't put a command with its arguments in a <em>string</em>. Put your command and its arguments in an <em>array</em> (and don't use upper-case variable names, that's a terribly bad practice), and <strong>do not use <code>eval</code></strong>. <code>eval</code> is evil!</p> <pre><code>command=( nohup java -j... | 387 | bash | <h1>control to the next statement after running eval command</h1>
<p>I have written a bash script to run a service in background and exit from the script to command line. But after running the eval command, control does not go the next statement.</p>
<pre><code>COMMAND="nohup java -jar jenkins.war"
echo "starting serv... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,286 | bash | # control to the next statement after running eval command
I have written a bash script to run a service in background and exit from the script to command line. But after running the eval command, control does not go the next statement.
```
COMMAND="nohup java -jar jenkins.war"
echo "starting service"
eval $COMMAND
e... | Please, don't put a command with its arguments in a *string*. Put your command and its arguments in an *array* (and don't use upper-case variable names, that's a terribly bad practice), and **do not use `eval`**. `eval` is evil!
```
command=( nohup java -jar jenkins.war )
echo "starting service"
"${command[@]}" 2> /de... |
14054791 | awk: find and replace in certain field only | 10 | 2012-12-27 12:33:45 | <p>I have a text file like this:</p>
<pre><code>$ cat test
12 13 2100 s
12 13 3100 s
100 13 100 s
12 13 300 s
</code></pre>
<p>I want the output to be like this:</p>
<pre><code>$ cat test
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
</code></pre>
<p>I only want to replace <code>100</code> in field 3 (once ... | 33,386 | 1,253,826 | 2012-12-27 16:01:26 | 14,054,895 | 15 | 2012-12-27 12:41:23 | 751,863 | 2012-12-27 12:51:18 | https://stackoverflow.com/q/14054791 | https://stackoverflow.com/a/14054895 | <p>Here's one way using <code>awk</code>:</p>
<pre><code>awk '{ sub(/100$/, "2000", $3) }1' file
</code></pre>
<p>Results:</p>
<pre><code>12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
</code></pre>
| <p>Here's one way using <code>awk</code>:</p> <pre><code>awk '{ sub(/100$/, "2000", $3) }1' file </code></pre> <p>Results:</p> <pre><code>12 13 22000 s 12 13 32000 s 100 13 2000 s 12 13 300 s </code></pre> | 58, 387, 990 | awk, bash, linux | <h1>awk: find and replace in certain field only</h1>
<p>I have a text file like this:</p>
<pre><code>$ cat test
12 13 2100 s
12 13 3100 s
100 13 100 s
12 13 300 s
</code></pre>
<p>I want the output to be like this:</p>
<pre><code>$ cat test
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
</code></pre>
<p>I on... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,287 | bash | # awk: find and replace in certain field only
I have a text file like this:
```
$ cat test
12 13 2100 s
12 13 3100 s
100 13 100 s
12 13 300 s
```
I want the output to be like this:
```
$ cat test
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
```
I only want to replace `100` in field 3 (once `100` is contai... | Here's one way using `awk`:
```
awk '{ sub(/100$/, "2000", $3) }1' file
```
Results:
```
12 13 22000 s
12 13 32000 s
100 13 2000 s
12 13 300 s
``` |
13801795 | How expensive is a bash function call really? | 10 | 2012-12-10 13:20:26 | <p>Just out if interest, are there any sources on how expensive function calls in Bash really are? I expect them to be several times slower than executing the code within them directly but I can't seem to find anything about this.</p>
| 2,008 | 1,178,669 | 2022-11-20 14:46:01 | 13,802,976 | 15 | 2012-12-10 14:32:34 | 1,815,797 | 2022-11-20 14:46:01 | https://stackoverflow.com/q/13801795 | https://stackoverflow.com/a/13802976 | <p>I don't really agree that performance should not be a worry when programming in bash. It's actually a very good question to ask.</p>
<p>Here's a possible benchmark, comparing the builtin <code>true</code> and the command <code>true</code>, the full path of which is <code>/bin/true</code> on my machine.</p>
<p>On my ... | <p>I don't really agree that performance should not be a worry when programming in bash. It's actually a very good question to ask.</p> <p>Here's a possible benchmark, comparing the builtin <code>true</code> and the command <code>true</code>, the full path of which is <code>/bin/true</code> on my machine.</p> <p>On my ... | 387 | bash | <h1>How expensive is a bash function call really?</h1>
<p>Just out if interest, are there any sources on how expensive function calls in Bash really are? I expect them to be several times slower than executing the code within them directly but I can't seem to find anything about 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,288 | bash | # How expensive is a bash function call really?
Just out if interest, are there any sources on how expensive function calls in Bash really are? I expect them to be several times slower than executing the code within them directly but I can't seem to find anything about this. | I don't really agree that performance should not be a worry when programming in bash. It's actually a very good question to ask.
Here's a possible benchmark, comparing the builtin `true` and the command `true`, the full path of which is `/bin/true` on my machine.
On my machine:
```
$ time for i in {0..1000}; do true... |
12989615 | Check if file is in a given directory (or sub-directory) in bash | 10 | 2012-10-20 14:50:42 | <p>How can I check if a given file is in a directory, including any directories with that directory, and so on? I want to do a small sanity check in a bash script to check that the user isn't trying to alter a file outside the project directory.</p>
| 25,382 | 341,673 | 2025-02-07 20:44:01 | 12,989,651 | 15 | 2012-10-20 14:54:09 | 1,741,864 | 2012-10-20 14:59:14 | https://stackoverflow.com/q/12989615 | https://stackoverflow.com/a/12989651 | <p>Use find (it searches recursively from the cwd or in the supplied directory path):</p>
<pre><code>find $directory_path -name $file_name | wc -l
</code></pre>
<p>Example of using this as part of a bash script:</p>
<pre><code>#!/bin/bash
...
directory_path=~/src/reviewboard/reviewboard
file_name=views.py
file_cou... | <p>Use find (it searches recursively from the cwd or in the supplied directory path):</p> <pre><code>find $directory_path -name $file_name | wc -l </code></pre> <p>Example of using this as part of a bash script:</p> <pre><code>#!/bin/bash ... directory_path=~/src/reviewboard/reviewboard file_name=views.py file_cou... | 387 | bash | <h1>Check if file is in a given directory (or sub-directory) in bash</h1>
<p>How can I check if a given file is in a directory, including any directories with that directory, and so on? I want to do a small sanity check in a bash script to check that the user isn't trying to alter a file outside the project directory.<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,289 | bash | # Check if file is in a given directory (or sub-directory) in bash
How can I check if a given file is in a directory, including any directories with that directory, and so on? I want to do a small sanity check in a bash script to check that the user isn't trying to alter a file outside the project directory. | Use find (it searches recursively from the cwd or in the supplied directory path):
```
find $directory_path -name $file_name | wc -l
```
Example of using this as part of a bash script:
```
#!/bin/bash
...
directory_path=~/src/reviewboard/reviewboard
file_name=views.py
file_count=$(find $directory_path -name $file_... |
11722365 | Linux: Outputting DD results to a text file | 10 | 2012-07-30 13:15:27 | <p>I'm writing a script that tests the read and write speeds of my HDD. I've been able to output the read speeds using the hdparm command. I'm using this line to test the write speeds:
dd if=/dev/zero of=/tmp/test.data bs=1k count=128k</p>
<p>This outputs to the window:</p>
<p>131072+0 records in
131072+0 records out... | 8,938 | 1,353,558 | 2012-07-30 17:17:21 | 11,722,415 | 15 | 2012-07-30 13:18:32 | 437,025 | 2012-07-30 13:18:32 | https://stackoverflow.com/q/11722365 | https://stackoverflow.com/a/11722415 | <p>They're output to stderr, so try using <code>2></code> instead of <code>></code></p>
<pre><code>dd if=/dev/zero of=/tmp/test.data bs=1k count=128k 2> output.txt
</code></pre>
| <p>They're output to stderr, so try using <code>2></code> instead of <code>></code></p> <pre><code>dd if=/dev/zero of=/tmp/test.data bs=1k count=128k 2> output.txt </code></pre> | 58, 387, 390 | bash, linux, shell | <h1>Linux: Outputting DD results to a text file</h1>
<p>I'm writing a script that tests the read and write speeds of my HDD. I've been able to output the read speeds using the hdparm command. I'm using this line to test the write speeds:
dd if=/dev/zero of=/tmp/test.data bs=1k count=128k</p>
<p>This outputs to the win... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,290 | bash | # Linux: Outputting DD results to a text file
I'm writing a script that tests the read and write speeds of my HDD. I've been able to output the read speeds using the hdparm command. I'm using this line to test the write speeds:
dd if=/dev/zero of=/tmp/test.data bs=1k count=128k
This outputs to the window:
131072+0 r... | They're output to stderr, so try using `2>` instead of `>`
```
dd if=/dev/zero of=/tmp/test.data bs=1k count=128k 2> output.txt
``` |
10782739 | How to change to temp directory in PowerShell? | 10 | 2012-05-28 10:00:59 | <p>In PowerShell I can echo the value of <code>%TEMP%</code> using the command <code>$Env:TEMP</code>. Here is the output on my machine:</p>
<pre><code>PS> $Env:temp
C:\Users\IAIN~1.COR\AppData\Local\Temp
</code></pre>
<p>When I try to change to the directory using the <code>cd</code> command, I receive this error... | 28,414 | 111,424 | 2023-07-03 15:58:17 | 10,783,291 | 15 | 2012-05-28 10:43:07 | 111,424 | 2014-07-13 21:58:11 | https://stackoverflow.com/q/10782739 | https://stackoverflow.com/a/10783291 | <p>You don't need to access the <code>%TEMP%</code> environment variable directly.</p>
<p>.NET provides a <code>GetTempPath</code> method as a more general solution. </p>
<pre><code>$TempDir = [System.IO.Path]::GetTempPath()
cd $TempDir
</code></pre>
<p>On my machine, this changes to the directory <code>C:\Users\Iai... | <p>You don't need to access the <code>%TEMP%</code> environment variable directly.</p> <p>.NET provides a <code>GetTempPath</code> method as a more general solution. </p> <pre><code>$TempDir = [System.IO.Path]::GetTempPath() cd $TempDir </code></pre> <p>On my machine, this changes to the directory <code>C:\Users\Iai... | 526, 15691 | powershell, temp | <h1>How to change to temp directory in PowerShell?</h1>
<p>In PowerShell I can echo the value of <code>%TEMP%</code> using the command <code>$Env:TEMP</code>. Here is the output on my machine:</p>
<pre><code>PS> $Env:temp
C:\Users\IAIN~1.COR\AppData\Local\Temp
</code></pre>
<p>When I try to change to the directory... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,291 | bash | # How to change to temp directory in PowerShell?
In PowerShell I can echo the value of `%TEMP%` using the command `$Env:TEMP`. Here is the output on my machine:
```
PS> $Env:temp
C:\Users\IAIN~1.COR\AppData\Local\Temp
```
When I try to change to the directory using the `cd` command, I receive this error:
```
PS> cd... | You don't need to access the `%TEMP%` environment variable directly.
.NET provides a `GetTempPath` method as a more general solution.
```
$TempDir = [System.IO.Path]::GetTempPath()
cd $TempDir
```
On my machine, this changes to the directory `C:\Users\Iain.CORP\AppData\Local\Temp`.
Remarks from [the documentation](... |
10060500 | bash: How to evaluate PS1, PS2, ...? | 10 | 2012-04-08 04:57:03 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/3451993/echo-expanded-ps1">Echo expanded PS1</a> </p>
</blockquote>
<p>Is there any way to 'evaluate' <code>PS1</code>, <code>PS2</code>, etc from within a bash script?</p>
<p>Although, I can use alternate mea... | 6,939 | 125,540 | 2024-10-21 00:53:28 | 10,060,576 | 15 | 2012-04-08 05:17:30 | 14,860 | 2024-10-21 00:53:28 | https://stackoverflow.com/q/10060500 | https://stackoverflow.com/a/10060576 | <p>One great advantage of open source software is that the source is, well, open :-)</p>
<p>If you download the code for <code>bash</code> (I'm looking at version 4.2), there's a <code>y.tab.c</code> file which contains the <code>decode_prompt_string()</code> function:</p>
<pre><code>char *decode_prompt_string (string)... | <p>One great advantage of open source software is that the source is, well, open :-)</p> <p>If you download the code for <code>bash</code> (I'm looking at version 4.2), there's a <code>y.tab.c</code> file which contains the <code>decode_prompt_string()</code> function:</p> <pre><code>char *decode_prompt_string (string)... | 387, 18315, 53034 | bash, evaluate, ps1 | <h1>bash: How to evaluate PS1, PS2, ...?</h1>
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/3451993/echo-expanded-ps1">Echo expanded PS1</a> </p>
</blockquote>
<p>Is there any way to 'evaluate' <code>PS1</code>, <code>PS2</code>, etc from within a bash scr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,292 | bash | # bash: How to evaluate PS1, PS2, ...?
> **Possible Duplicate:**
> [Echo expanded PS1](https://stackoverflow.com/questions/3451993/echo-expanded-ps1)
Is there any way to 'evaluate' `PS1`, `PS2`, etc from within a bash script?
Although, I can use alternate means to get all elements of my current `PS1`, I would real... | One great advantage of open source software is that the source is, well, open :-)
If you download the code for `bash` (I'm looking at version 4.2), there's a `y.tab.c` file which contains the `decode_prompt_string()` function:
```
char *decode_prompt_string (string) char *string; { ... }
```
You can try to extract t... |
9859903 | Using the exec() family to run the "cd" command | 10 | 2012-03-25 11:51:34 | <p>I know that <code>cd</code> is a shell built-in ,and I can run it by using <code>system()</code>.</p>
<p>But is that possible to run the <code>cd</code> command by the <code>exec()</code> family, like <code>execvp()</code>?</p>
<p>Edit: And I just noticed that <code>system("cd")</code> is also meaningless。Thanks f... | 22,619 | 1,284,016 | 2012-11-10 18:30:53 | 9,859,965 | 15 | 2012-03-25 12:02:54 | 596,781 | 2012-03-25 12:02:54 | https://stackoverflow.com/q/9859903 | https://stackoverflow.com/a/9859965 | <p><code>exec</code> loads an <em>executable file</em> and replaces the current program image with it. As you rightly noted, <code>cd</code> is <em>not</em> an executable file, but rather a shell builtin. So the executable that you want to run is the shell itself. This is of course what <code>system()</code> does for y... | <p><code>exec</code> loads an <em>executable file</em> and replaces the current program image with it. As you rightly noted, <code>cd</code> is <em>not</em> an executable file, but rather a shell builtin. So the executable that you want to run is the shell itself. This is of course what <code>system()</code> does for y... | 8, 58, 390, 7932 | c, exec, linux, shell | <h1>Using the exec() family to run the "cd" command</h1>
<p>I know that <code>cd</code> is a shell built-in ,and I can run it by using <code>system()</code>.</p>
<p>But is that possible to run the <code>cd</code> command by the <code>exec()</code> family, like <code>execvp()</code>?</p>
<p>Edit: And I just noticed th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,293 | bash | # Using the exec() family to run the "cd" command
I know that `cd` is a shell built-in ,and I can run it by using `system()`.
But is that possible to run the `cd` command by the `exec()` family, like `execvp()`?
Edit: And I just noticed that `system("cd")` is also meaningless。Thanks for the help of everyone. | `exec` loads an *executable file* and replaces the current program image with it. As you rightly noted, `cd` is *not* an executable file, but rather a shell builtin. So the executable that you want to run is the shell itself. This is of course what `system()` does for you, but if you want to be explicit about it, you c... |
8713158 | place a multi-line output inside a variable | 10 | 2012-01-03 13:41:50 | <p>I'm writing a script in bash and I want it to execute a command and to handle each line separately. for example:</p>
<pre><code>LINES=$(df)
echo $LINES
</code></pre>
<p>it will return all the output converting new lines with spaces. </p>
<p>example:</p>
<p>if the output was supposed to be:</p>
<pre><code>1
2
3
... | 16,097 | 80,932 | 2021-12-27 12:04:16 | 8,713,184 | 15 | 2012-01-03 13:43:45 | 122,727 | 2021-12-27 12:04:16 | https://stackoverflow.com/q/8713158 | https://stackoverflow.com/a/8713184 | <p>Generally in bash <code>$v</code> is asking for trouble in most cases. Almost always what you really mean is <code>"$v"</code> in <strong>double quotes</strong>:</p>
<pre class="lang-sh prettyprint-override"><code>LINES="$(df)"
echo "$LINES"
</code></pre>
| <p>Generally in bash <code>$v</code> is asking for trouble in most cases. Almost always what you really mean is <code>"$v"</code> in <strong>double quotes</strong>:</p> <pre class="lang-sh prettyprint-override"><code>LINES="$(df)" echo "$LINES" </code></pre> | 387, 29051 | bash, bash4 | <h1>place a multi-line output inside a variable</h1>
<p>I'm writing a script in bash and I want it to execute a command and to handle each line separately. for example:</p>
<pre><code>LINES=$(df)
echo $LINES
</code></pre>
<p>it will return all the output converting new lines with spaces. </p>
<p>example:</p>
<p>if ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,294 | bash | # place a multi-line output inside a variable
I'm writing a script in bash and I want it to execute a command and to handle each line separately. for example:
```
LINES=$(df)
echo $LINES
```
it will return all the output converting new lines with spaces.
example:
if the output was supposed to be:
```
1
2
3
```
t... | Generally in bash `$v` is asking for trouble in most cases. Almost always what you really mean is `"$v"` in **double quotes**:
```
LINES="$(df)"
echo "$LINES"
``` |
8100817 | Redirect STDOUT and STDERR to socket in C? | 10 | 2011-11-11 22:36:30 | <p>I am trying to redirect STDOUT AND STDERR to a socket.</p>
<p>I did:</p>
<pre><code>if(fork() == 0)
{
dup2(newsock, STDOUT_FILENO);
dup2(newsock, STDERR_FILENO);
execvp();
}
</code></pre>
<p>Somehow, it only showed the first little part of the output.</p>
<p>for example, it showed on "mkdir" when I try ... | 21,192 | 864,493 | 2020-12-01 10:37:39 | 8,102,513 | 15 | 2011-11-12 04:16:09 | 929,459 | 2011-11-12 04:42:18 | https://stackoverflow.com/q/8100817 | https://stackoverflow.com/a/8102513 | <p>Your use of <code>dup2()</code> looks fine, so the problem is probably elsewhere. The simple program I threw together to test with does not have the issues you are experiencing, so I'll just go over the core of it (around the <code>fork()</code>/<code>execvp()</code> area) with some error checking omitted for brevi... | <p>Your use of <code>dup2()</code> looks fine, so the problem is probably elsewhere. The simple program I threw together to test with does not have the issues you are experiencing, so I'll just go over the core of it (around the <code>fork()</code>/<code>execvp()</code> area) with some error checking omitted for brevi... | 8, 387, 390, 4867, 43326 | bash, c, dup, shell, stdout | <h1>Redirect STDOUT and STDERR to socket in C?</h1>
<p>I am trying to redirect STDOUT AND STDERR to a socket.</p>
<p>I did:</p>
<pre><code>if(fork() == 0)
{
dup2(newsock, STDOUT_FILENO);
dup2(newsock, STDERR_FILENO);
execvp();
}
</code></pre>
<p>Somehow, it only showed the first little part of the output.</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,295 | bash | # Redirect STDOUT and STDERR to socket in C?
I am trying to redirect STDOUT AND STDERR to a socket.
I did:
```
if(fork() == 0)
{
dup2(newsock, STDOUT_FILENO);
dup2(newsock, STDERR_FILENO);
execvp();
}
```
Somehow, it only showed the first little part of the output.
for example, it showed on "mkdir" when I... | Your use of `dup2()` looks fine, so the problem is probably elsewhere. The simple program I threw together to test with does not have the issues you are experiencing, so I'll just go over the core of it (around the `fork()`/`execvp()` area) with some error checking omitted for brevity:
```
int lsock, /* listening s... |
7421993 | How to list all binding variables with GroovyShell | 10 | 2011-09-14 19:36:50 | <p>I'm very new to Groovy. How can I list all variables I passed to Binding constructor ?</p>
<p>Considering I have following :</p>
<pre><code>@Test
public void test() {
List<String> outputNames = Arrays.asList("returnValue", "ce");
String script = getScript();
Script compiledScript = compileScrip... | 14,835 | 306,488 | 2011-09-14 20:12:02 | 7,422,385 | 15 | 2011-09-14 20:12:02 | 306,488 | 2011-09-14 20:12:02 | https://stackoverflow.com/q/7421993 | https://stackoverflow.com/a/7422385 | <p><code>Script compiledScript</code> represents the script, if you look at its source code, you'll see that it has property binding and getter+setter and Binding has a variable "variables". So you go :</p>
<pre><code>binding.variables.each{
println it.key
println it.value
}
</code></pre>
<p>For <code>Map<St... | <p><code>Script compiledScript</code> represents the script, if you look at its source code, you'll see that it has property binding and getter+setter and Binding has a variable "variables". So you go :</p> <pre><code>binding.variables.each{ println it.key println it.value } </code></pre> <p>For <code>Map<St... | 849, 1137, 3951 | binding, groovy, groovyshell | <h1>How to list all binding variables with GroovyShell</h1>
<p>I'm very new to Groovy. How can I list all variables I passed to Binding constructor ?</p>
<p>Considering I have following :</p>
<pre><code>@Test
public void test() {
List<String> outputNames = Arrays.asList("returnValue", "ce");
String sc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,296 | bash | # How to list all binding variables with GroovyShell
I'm very new to Groovy. How can I list all variables I passed to Binding constructor ?
Considering I have following :
```
@Test
public void test() {
List<String> outputNames = Arrays.asList("returnValue", "ce");
String script = getScript();
Script co... | `Script compiledScript` represents the script, if you look at its source code, you'll see that it has property binding and getter+setter and Binding has a variable "variables". So you go :
```
binding.variables.each{
println it.key
println it.value
}
```
For `Map<String, String>` ...
you can also set propertie... |
3434948 | Bash script to safely create symlinks? | 10 | 2010-08-08 15:52:02 | <p>I'm trying to store all my profile configuration files (~/.xxx) in git. I'm pretty horrible at bash scripting but I imagine this will be pretty straight forward for you scripting gurus.</p>
<p>Basically, I'd like a script that will create symbolic links in my home directory to files in my repo. Twist is, I'd like i... | 5,744 | 1,946 | 2010-08-08 16:20:15 | 3,435,025 | 15 | 2010-08-08 16:11:05 | 387,076 | 2010-08-08 16:11:05 | https://stackoverflow.com/q/3434948 | https://stackoverflow.com/a/3435025 | <p>The <code>ln</code> command is already conservative about erasing, so maybe the KISS approach is good enough for you:</p>
<pre><code>ln -s git-stuff/home/.[!.]* .
</code></pre>
<p>If a file or link already exists, you'll get an error message and this link will be skipped.</p>
<p>If you want the files to have a di... | <p>The <code>ln</code> command is already conservative about erasing, so maybe the KISS approach is good enough for you:</p> <pre><code>ln -s git-stuff/home/.[!.]* . </code></pre> <p>If a file or link already exists, you'll get an error message and this link will be skipped.</p> <p>If you want the files to have a di... | 387, 1122 | bash, symlink | <h1>Bash script to safely create symlinks?</h1>
<p>I'm trying to store all my profile configuration files (~/.xxx) in git. I'm pretty horrible at bash scripting but I imagine this will be pretty straight forward for you scripting gurus.</p>
<p>Basically, I'd like a script that will create symbolic links in my home dir... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,297 | bash | # Bash script to safely create symlinks?
I'm trying to store all my profile configuration files (~/.xxx) in git. I'm pretty horrible at bash scripting but I imagine this will be pretty straight forward for you scripting gurus.
Basically, I'd like a script that will create symbolic links in my home directory to files ... | The `ln` command is already conservative about erasing, so maybe the KISS approach is good enough for you:
```
ln -s git-stuff/home/.[!.]* .
```
If a file or link already exists, you'll get an error message and this link will be skipped.
If you want the files to have a different name in your repository, pass the `-n... |
3385049 | how to pass keyboard input along to linux command? | 10 | 2010-08-02 04:44:21 | <p>I run a linux command that sometimes asks for user input (press 1 or 2).</p>
<p>I always want to answer 1, how can I pass this value automatically ?</p>
| 17,678 | 364,914 | 2010-08-02 04:47:51 | 3,385,064 | 15 | 2010-08-02 04:47:51 | 68,587 | 2010-08-02 04:47:51 | https://stackoverflow.com/q/3385049 | https://stackoverflow.com/a/3385064 | <p>Use the pipe <code>|</code> operator to connect the output of one command to the input of another.</p>
<pre><code>echo 1 | command
</code></pre>
<p>If you want to repeat some input to a command, you can use <code>yes</code>. By default it sends the string "y" repeatedly but it also repeat a different string of you... | <p>Use the pipe <code>|</code> operator to connect the output of one command to the input of another.</p> <pre><code>echo 1 | command </code></pre> <p>If you want to repeat some input to a command, you can use <code>yes</code>. By default it sends the string "y" repeatedly but it also repeat a different string of you... | 387 | bash | <h1>how to pass keyboard input along to linux command?</h1>
<p>I run a linux command that sometimes asks for user input (press 1 or 2).</p>
<p>I always want to answer 1, how can I pass this value automatically ?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,298 | bash | # how to pass keyboard input along to linux command?
I run a linux command that sometimes asks for user input (press 1 or 2).
I always want to answer 1, how can I pass this value automatically ? | Use the pipe `|` operator to connect the output of one command to the input of another.
```
echo 1 | command
```
If you want to repeat some input to a command, you can use `yes`. By default it sends the string "y" repeatedly but it also repeat a different string of your choice.
```
yes | cp * /tmp # Answer "y" to a... |
2472629 | Temporary operation in a temporary directory in shell script | 10 | 2010-03-18 19:07:30 | <p>I need a fresh temporary directory to do some work in a shell script. When the work is done (or if I kill the job midway), I want the script to change back to the old working directory and wipe out the temporary one. In Ruby, it might look like this:</p>
<pre><code>require 'tmpdir'
Dir.mktmpdir 'my_build' do |temp... | 10,359 | 2,938 | 2010-03-19 01:18:56 | 2,473,583 | 15 | 2010-03-18 21:53:22 | 290,900 | 2010-03-18 21:53:22 | https://stackoverflow.com/q/2472629 | https://stackoverflow.com/a/2473583 | <p>Here you go:</p>
<pre><code>#!/bin/bash
TDIR=`mktemp -d`
trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT
cd $TDIR
# do important stuff here
cd -
rm -rf $TDIR
exit 0
</code></pre>
| <p>Here you go:</p> <pre><code>#!/bin/bash TDIR=`mktemp -d` trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT cd $TDIR # do important stuff here cd - rm -rf $TDIR exit 0 </code></pre> | 387, 390, 17512, 25827 | bash, shell, temporary-directory, temporary-files | <h1>Temporary operation in a temporary directory in shell script</h1>
<p>I need a fresh temporary directory to do some work in a shell script. When the work is done (or if I kill the job midway), I want the script to change back to the old working directory and wipe out the temporary one. In Ruby, it might look like th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,299 | bash | # Temporary operation in a temporary directory in shell script
I need a fresh temporary directory to do some work in a shell script. When the work is done (or if I kill the job midway), I want the script to change back to the old working directory and wipe out the temporary one. In Ruby, it might look like this:
```
... | Here you go:
```
#!/bin/bash
TDIR=`mktemp -d`
trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT
cd $TDIR
# do important stuff here
cd -
rm -rf $TDIR
exit 0
``` |
2159763 | In Powershell, what's the most efficient way to split a large text file by record type? | 10 | 2010-01-29 03:44:24 | <p>I am using Powershell for some ETL work, reading compressed text files in and splitting them out depending on the first three characters of each line. </p>
<p>If I were just filtering the input file, I could pipe the filtered stream to Out-File and be done with it. But I need to redirect the output to more than one... | 6,651 | 117,079 | 2013-08-16 15:56:42 | 2,160,212 | 15 | 2010-01-29 06:06:30 | 75,224 | 2010-01-29 13:00:26 | https://stackoverflow.com/q/2159763 | https://stackoverflow.com/a/2160212 | <h2>Reading</h2>
<p>As for reading the file and parsing, I would go with <code>switch</code> statement:</p>
<pre><code>switch -file c:\temp\stackoverflow.testfile2.txt -regex {
"^001" {Add-Content c:\temp\stackoverflow.testfile.001.txt $_}
"^002" {Add-Content c:\temp\stackoverflow.testfile.002.txt $_}
"^003" {A... | <h2>Reading</h2> <p>As for reading the file and parsing, I would go with <code>switch</code> statement:</p> <pre><code>switch -file c:\temp\stackoverflow.testfile2.txt -regex { "^001" {Add-Content c:\temp\stackoverflow.testfile.001.txt $_} "^002" {Add-Content c:\temp\stackoverflow.testfile.002.txt $_} "^003" {A... | 526, 2278, 17938 | etl, powershell, text-files | <h1>In Powershell, what's the most efficient way to split a large text file by record type?</h1>
<p>I am using Powershell for some ETL work, reading compressed text files in and splitting them out depending on the first three characters of each line. </p>
<p>If I were just filtering the input file, I could pipe 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,300 | bash | # In Powershell, what's the most efficient way to split a large text file by record type?
I am using Powershell for some ETL work, reading compressed text files in and splitting them out depending on the first three characters of each line.
If I were just filtering the input file, I could pipe the filtered stream to ... | ## Reading
As for reading the file and parsing, I would go with `switch` statement:
```
switch -file c:\temp\stackoverflow.testfile2.txt -regex {
"^001" {Add-Content c:\temp\stackoverflow.testfile.001.txt $_}
"^002" {Add-Content c:\temp\stackoverflow.testfile.002.txt $_}
"^003" {Add-Content c:\temp\stackoverflo... |
1586477 | Bash globbing - autoexpand for a few specific cases? | 10 | 2009-10-19 00:39:09 | <p>I understand that the wildcard <code>*</code> (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period.</p>
<p>There are two use cases that I would think are useful, but I don't know how to properly do:</p>
<ol>
<li><p>How c... | 3,240 | 121,112 | 2014-10-12 04:33:20 | 1,586,569 | 15 | 2009-10-19 01:22:08 | 56,338 | 2009-10-19 01:22:08 | https://stackoverflow.com/q/1586477 | https://stackoverflow.com/a/1586569 | <p>To expand on <a href="https://stackoverflow.com/questions/1586477/bash-globbing-autoexpand-for-a-few-specific-cases/1586499#1586499">paviums answer</a> and answer the second part of your question, all files except <code>.</code> and <code>..</code> could be specified like this:</p>
<pre><code>{.[!.]*,*}
</code></pr... | <p>To expand on <a href="https://stackoverflow.com/questions/1586477/bash-globbing-autoexpand-for-a-few-specific-cases/1586499#1586499">paviums answer</a> and answer the second part of your question, all files except <code>.</code> and <code>..</code> could be specified like this:</p> <pre><code>{.[!.]*,*} </code></pr... | 387, 1062, 3889, 19863 | bash, expansion, filenames, glob | <h1>Bash globbing - autoexpand for a few specific cases?</h1>
<p>I understand that the wildcard <code>*</code> (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period.</p>
<p>There are two use cases that I would think are usefu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,301 | bash | # Bash globbing - autoexpand for a few specific cases?
I understand that the wildcard `*` (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period.
There are two use cases that I would think are useful, but I don't know how to ... | To expand on [paviums answer](https://stackoverflow.com/questions/1586477/bash-globbing-autoexpand-for-a-few-specific-cases/1586499#1586499) and answer the second part of your question, all files except `.` and `..` could be specified like this:
```
{.[!.]*,*}
```
Depending on your exact use case it might be better t... |
859517 | OSX equivalent of ShellExecute? | 10 | 2009-05-13 18:15:52 | <p>I've got a C++ app that I'm porting from Win32 to OSX. I'd like to be able to launch arbitrary files as if the user opened them. This is easy on windows using ShellExecute. How do I accomplish the same thing on the Mac? </p>
<p>Thanks!</p>
| 11,450 | 23,524 | 2015-04-24 21:53:45 | 859,529 | 15 | 2009-05-13 18:18:04 | 33,686 | 2009-05-13 18:18:04 | https://stackoverflow.com/q/859517 | https://stackoverflow.com/a/859529 | <p>You can call <code>system();</code> in any C++ application. On OSX, you can use the <a href="http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/open.1.html" rel="noreferrer">open</a> command to launch things as if they were clicked on.</p>
<p>From the documentation for open:</p>
<blockquote>
... | <p>You can call <code>system();</code> in any C++ application. On OSX, you can use the <a href="http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/open.1.html" rel="noreferrer">open</a> command to launch things as if they were clicked on.</p> <p>From the documentation for open:</p> <blockquote> ... | 10, 369, 7839 | c++, macos, shellexecute | <h1>OSX equivalent of ShellExecute?</h1>
<p>I've got a C++ app that I'm porting from Win32 to OSX. I'd like to be able to launch arbitrary files as if the user opened them. This is easy on windows using ShellExecute. How do I accomplish the same thing on the Mac? </p>
<p>Thanks!</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,302 | bash | # OSX equivalent of ShellExecute?
I've got a C++ app that I'm porting from Win32 to OSX. I'd like to be able to launch arbitrary files as if the user opened them. This is easy on windows using ShellExecute. How do I accomplish the same thing on the Mac?
Thanks! | You can call `system();` in any C++ application. On OSX, you can use the [open](http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/open.1.html) command to launch things as if they were clicked on.
From the documentation for open:
> The open command opens a file (or a directory or URL), just as if... |
69261782 | Why does the same curl command output different things in windows and linux? | 9 | 2021-09-20 23:18:26 | <p>Why does the same <code>curl -o file https://www.link.com/</code> command output different things?</p>
<p>For example if i run the command <code>curl -o source.txt https://www.youtube.com/playlist?list=PLIx6FwnpuyNW9RxmWaGzKumLu-gUPy-q4</code> with a YouTube playlist link.</p>
<p>Linux output everything including al... | 7,257 | 16,961,402 | 2026-01-22 21:16:30 | 69,262,432 | 15 | 2021-09-21 01:27:02 | 1,238,413 | 2026-01-22 21:13:48 | https://stackoverflow.com/q/69261782 | https://stackoverflow.com/a/69262432 | <p><code>Curl.exe</code> is present out of the box on Windows machines with Windows 10 1803 or higher (which means since roughly March of 2018) and similar server releases.</p>
<p>However, <code>curl</code> (with no .exe) has a somewhat weird history and some shortcuts are left behind built into PowerShell, and I think... | <p><code>Curl.exe</code> is present out of the box on Windows machines with Windows 10 1803 or higher (which means since roughly March of 2018) and similar server releases.</p> <p>However, <code>curl</code> (with no .exe) has a somewhat weird history and some shortcuts are left behind built into PowerShell, and I think... | 58, 64, 391, 526, 1554 | curl, linux, powershell, terminal, windows | <h1>Why does the same curl command output different things in windows and linux?</h1>
<p>Why does the same <code>curl -o file https://www.link.com/</code> command output different things?</p>
<p>For example if i run the command <code>curl -o source.txt https://www.youtube.com/playlist?list=PLIx6FwnpuyNW9RxmWaGzKumLu-gU... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,303 | bash | # Why does the same curl command output different things in windows and linux?
Why does the same `curl -o file https://www.link.com/` command output different things?
For example if i run the command `curl -o source.txt https://www.youtube.com/playlist?list=PLIx6FwnpuyNW9RxmWaGzKumLu-gUPy-q4` with a YouTube playlist ... | `Curl.exe` is present out of the box on Windows machines with Windows 10 1803 or higher (which means since roughly March of 2018) and similar server releases.
However, `curl` (with no .exe) has a somewhat weird history and some shortcuts are left behind built into PowerShell, and I think that is what's causing you som... |
55284908 | What is the equivalent to Bash's exec $@ in Python? | 9 | 2019-03-21 16:18:15 | <p>Some bash scripts end their execution with <code>exec "$@"</code>, often invoking a series of commands before finally replacing their execution with the arguments passed initially to the script.</p>
<p>If you were to write a Python script to replace that bash script, what would the final command be?</p>
| 4,338 | 1,420,079 | 2019-03-22 10:31:38 | 55,284,909 | 15 | 2019-03-21 16:18:15 | 1,420,079 | 2019-03-22 10:31:38 | https://stackoverflow.com/q/55284908 | https://stackoverflow.com/a/55284909 | <p>In bash, </p>
<blockquote>
<p>"$@" is an array-like construct of all positional parameters, {$1, $2,
$3 ...}.</p>
</blockquote>
<p>See <a href="https://stackoverflow.com/a/5163260/1420079">https://stackoverflow.com/a/5163260/1420079</a></p>
<p>So <code>exec "$@"</code> would invoke all of the additional posit... | <p>In bash, </p> <blockquote> <p>"$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.</p> </blockquote> <p>See <a href="https://stackoverflow.com/a/5163260/1420079">https://stackoverflow.com/a/5163260/1420079</a></p> <p>So <code>exec "$@"</code> would invoke all of the additional posit... | 16, 387 | bash, python | <h1>What is the equivalent to Bash's exec $@ in Python?</h1>
<p>Some bash scripts end their execution with <code>exec "$@"</code>, often invoking a series of commands before finally replacing their execution with the arguments passed initially to the script.</p>
<p>If you were to write a Python script to replace that ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,304 | bash | # What is the equivalent to Bash's exec $@ in Python?
Some bash scripts end their execution with `exec "$@"`, often invoking a series of commands before finally replacing their execution with the arguments passed initially to the script.
If you were to write a Python script to replace that bash script, what would the... | In bash,
> "$@" is an array-like construct of all positional parameters, {$1, $2,
> $3 ...}.
See <https://stackoverflow.com/a/5163260/1420079>
So `exec "$@"` would invoke all of the additional positional parameters, with the first argument being the program name, and then subsequent arguments being the arguments to ... |
54094472 | Kubectl: get a shell to a running container under Windows | 9 | 2019-01-08 15:00:37 | <p>I'm trying to log into running container using Kubectl, according to instructions in <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/" rel="noreferrer">https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/</a>, but I'm failing miserabl... | 18,828 | null | 2022-08-29 07:03:25 | 54,109,648 | 15 | 2019-01-09 11:59:34 | 9,892,073 | 2019-01-09 11:59:34 | https://stackoverflow.com/q/54094472 | https://stackoverflow.com/a/54109648 | <p>Seems it might be related to this github <a href="https://github.com/kubernetes/kubernetes/issues/37471" rel="noreferrer">issue.</a></p>
<p>One of the workarounds might be to use winpty as specified <a href="https://github.com/Microsoft/WSL/issues/2271#issuecomment-317006437" rel="noreferrer">here</a>.<br>
<code>wi... | <p>Seems it might be related to this github <a href="https://github.com/kubernetes/kubernetes/issues/37471" rel="noreferrer">issue.</a></p> <p>One of the workarounds might be to use winpty as specified <a href="https://github.com/Microsoft/WSL/issues/2271#issuecomment-317006437" rel="noreferrer">here</a>.<br> <code>wi... | 64, 390, 120010 | kubectl, shell, windows | <h1>Kubectl: get a shell to a running container under Windows</h1>
<p>I'm trying to log into running container using Kubectl, according to instructions in <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/" rel="noreferrer">https://kubernetes.io/docs/tasks/debug-application... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,305 | bash | # Kubectl: get a shell to a running container under Windows
I'm trying to log into running container using Kubectl, according to instructions in <https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/>, but I'm failing miserably:
```
kubectl exec -it mycontainer -- /bin/bash
```
> Un... | Seems it might be related to this github [issue.](https://github.com/kubernetes/kubernetes/issues/37471)
One of the workarounds might be to use winpty as specified [here](https://github.com/Microsoft/WSL/issues/2271#issuecomment-317006437).
`winpty kubectl.exe exec -it pod-name -- sh`
You can also try `/bin/sh` ins... |
50625619 | Why doesn't the cut command work for a "docker image ls" command? | 9 | 2018-05-31 13:34:47 | <p>I'm trying to get the docker image id for a certain image so I do</p>
<pre><code>$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
123456789012.dkr.ecr.us-east-1.amazonaws.com/some-name1 60 ... | 4,389 | 1,401,560 | 2019-06-13 10:44:44 | 50,625,687 | 15 | 2018-05-31 13:38:18 | 7,200,715 | 2019-06-13 10:44:44 | https://stackoverflow.com/q/50625619 | https://stackoverflow.com/a/50625687 | <p>Because you have several " " between each data.</p>
<p>Easier way is to strip whitespaces to a single space and cut:</p>
<pre><code>docker image ls | grep name1 | tr -s ' ' | cut -d " " -f 3
</code></pre>
<hr>
<p><strong>EDIT:</strong>
<a href="https://stackoverflow.com/a/50626142/7200715">chepner's answer is t... | <p>Because you have several " " between each data.</p> <p>Easier way is to strip whitespaces to a single space and cut:</p> <pre><code>docker image ls | grep name1 | tr -s ' ' | cut -d " " -f 3 </code></pre> <hr> <p><strong>EDIT:</strong> <a href="https://stackoverflow.com/a/50626142/7200715">chepner's answer is t... | 387, 390 | bash, shell | <h1>Why doesn't the cut command work for a "docker image ls" command?</h1>
<p>I'm trying to get the docker image id for a certain image so I do</p>
<pre><code>$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
12345678... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,306 | bash | # Why doesn't the cut command work for a "docker image ls" command?
I'm trying to get the docker image id for a certain image so I do
```
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
123456789012.dkr.ecr.us-east... | Because you have several " " between each data.
Easier way is to strip whitespaces to a single space and cut:
```
docker image ls | grep name1 | tr -s ' ' | cut -d " " -f 3
```
---
**EDIT:**
[chepner's answer is to prefere](https://stackoverflow.com/a/50626142/7200715), *but I let this one live since original quest... |
50518798 | How to add work item as child to parent? | 9 | 2018-05-24 22:02:05 | <p>I've been able to find documentation on creating work items via the VSTS REST API, however, I haven't been able to find anything creating a work item and linking it to a Parent work item.</p>
<p>Searching around, I've seen some links regarding a <code>System.LinkTypes.Hierarchy-Reverse</code>, but no API reference ... | 6,863 | 8,728,860 | 2018-05-25 03:49:05 | 50,521,246 | 15 | 2018-05-25 03:49:05 | 6,936,103 | 2018-05-25 03:49:05 | https://stackoverflow.com/q/50518798 | https://stackoverflow.com/a/50521246 | <p>To add a work item with parent work item linked, you should use the REST API as:</p>
<pre><code>POST https://{accountName}.visualstudio.com/{project}/_apis/wit/workitems/${type}?api-version=4.1
</code></pre>
<p>application/json-patch+json:</p>
<pre><code>[
{
"op": "add",
"path": "/fields/System.Title",
... | <p>To add a work item with parent work item linked, you should use the REST API as:</p> <pre><code>POST https://{accountName}.visualstudio.com/{project}/_apis/wit/workitems/${type}?api-version=4.1 </code></pre> <p>application/json-patch+json:</p> <pre><code>[ { "op": "add", "path": "/fields/System.Title", ... | 364, 526, 116537, 134617 | azure-devops, azure-devops-rest-api, powershell, rest | <h1>How to add work item as child to parent?</h1>
<p>I've been able to find documentation on creating work items via the VSTS REST API, however, I haven't been able to find anything creating a work item and linking it to a Parent work item.</p>
<p>Searching around, I've seen some links regarding a <code>System.LinkTyp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,307 | bash | # How to add work item as child to parent?
I've been able to find documentation on creating work items via the VSTS REST API, however, I haven't been able to find anything creating a work item and linking it to a Parent work item.
Searching around, I've seen some links regarding a `System.LinkTypes.Hierarchy-Reverse`... | To add a work item with parent work item linked, you should use the REST API as:
```
POST https://{accountName}.visualstudio.com/{project}/_apis/wit/workitems/${type}?api-version=4.1
```
application/json-patch+json:
```
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "title"... |
49057054 | Adding an Alias to a Microsoft O365 Group | 9 | 2018-03-01 19:10:28 | <p>Wanted to add an answer to what I learned after researching and succeeding with this issue.</p>
<p>I have a Microsoft O365 account where I run my business. I am using Microsoft Teams so my executive team can see information and emails specific to that function. For instance, Human Resources. That team is setup t... | 40,326 | 1,544,175 | 2023-09-15 13:55:16 | 49,057,055 | 15 | 2018-03-01 19:10:28 | 1,544,175 | 2018-03-01 19:10:28 | https://stackoverflow.com/q/49057054 | https://stackoverflow.com/a/49057055 | <p>There is a link that describes how to use PowerShell to add an alias:</p>
<p><a href="https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_password-mso_o365b/add-additional-smtp-aliases-to-office-365-groups/b017e4b9-a0e2-4295-a40e-9ca2ec359965?auth=1" rel="noreferrer">Add Additional SMTP Aliase... | <p>There is a link that describes how to use PowerShell to add an alias:</p> <p><a href="https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_password-mso_o365b/add-additional-smtp-aliases-to-office-365-groups/b017e4b9-a0e2-4295-a40e-9ca2ec359965?auth=1" rel="noreferrer">Add Additional SMTP Aliase... | 526, 67718, 122862 | microsoft-teams, office365, powershell | <h1>Adding an Alias to a Microsoft O365 Group</h1>
<p>Wanted to add an answer to what I learned after researching and succeeding with this issue.</p>
<p>I have a Microsoft O365 account where I run my business. I am using Microsoft Teams so my executive team can see information and emails specific to that function. F... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,308 | bash | # Adding an Alias to a Microsoft O365 Group
Wanted to add an answer to what I learned after researching and succeeding with this issue.
I have a Microsoft O365 account where I run my business. I am using Microsoft Teams so my executive team can see information and emails specific to that function. For instance, Human... | There is a link that describes how to use PowerShell to add an alias:
[Add Additional SMTP Aliases to Office 365 Groups](https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_password-mso_o365b/add-additional-smtp-aliases-to-office-365-groups/b017e4b9-a0e2-4295-a40e-9ca2ec359965?auth=1)
**Concise ... |
48812216 | "docker run" command to evaluate bash $variable inside the container | 9 | 2018-02-15 16:41:58 | <p>How can I run a command inside a docker container, using <code>docker run</code>, where bash variables are evaluated <em>inside</em> the container?</p>
<p>E.g.:</p>
<pre><code>$ SOMEONE=host
$ docker run --env SOMEONE=busybox busybox echo "Hello $SOMEONE"
Hello host
</code></pre>
<p>How can I make it output <code... | 6,520 | 613,540 | 2023-01-18 18:43:40 | 48,812,290 | 15 | 2018-02-15 16:45:25 | 14,122 | 2018-02-15 18:22:45 | https://stackoverflow.com/q/48812216 | https://stackoverflow.com/a/48812290 | <ul>
<li><p>To prevent the replacement from happening from the outer shell, one needs to use single quotes, not double.</p></li>
<li><p>To ensure that there <em>is</em> an inner shell that <em>can</em> do a replacement (<code>echo</code> doesn't have any such functionality itself!), we need to explicitly call <code>sh ... | <ul> <li><p>To prevent the replacement from happening from the outer shell, one needs to use single quotes, not double.</p></li> <li><p>To ensure that there <em>is</em> an inner shell that <em>can</em> do a replacement (<code>echo</code> doesn't have any such functionality itself!), we need to explicitly call <code>sh ... | 387, 1364, 9013, 90304 | bash, containers, docker, environment-variables | <h1>"docker run" command to evaluate bash $variable inside the container</h1>
<p>How can I run a command inside a docker container, using <code>docker run</code>, where bash variables are evaluated <em>inside</em> the container?</p>
<p>E.g.:</p>
<pre><code>$ SOMEONE=host
$ docker run --env SOMEONE=busybox busybox ech... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,309 | bash | # "docker run" command to evaluate bash $variable inside the container
How can I run a command inside a docker container, using `docker run`, where bash variables are evaluated *inside* the container?
E.g.:
```
$ SOMEONE=host
$ docker run --env SOMEONE=busybox busybox echo "Hello $SOMEONE"
Hello host
```
How can I ... | - To prevent the replacement from happening from the outer shell, one needs to use single quotes, not double.
- To ensure that there *is* an inner shell that *can* do a replacement (`echo` doesn't have any such functionality itself!), we need to explicitly call `sh -c`; otherwise, Docker will just directly invoke `exec... |
48787560 | How to escape special characters in ansible shell module | 9 | 2018-02-14 12:43:49 | <p>I tried bash escape and double quotes methods to escape the special characters in below shell command, But both didn't work, What is the proper way to escape special characters in ansible playbook?</p>
<pre><code> The offending line appears to be:
name: Syncing system date with htpdate failed!, Tr... | 34,157 | 2,460,764 | 2020-02-04 11:44:38 | 48,790,552 | 15 | 2018-02-14 15:19:22 | 93,745 | 2018-02-14 15:19:22 | https://stackoverflow.com/q/48787560 | https://stackoverflow.com/a/48790552 | <p>One of the problems here is the colon followed by a space <code>:</code>. This is usually an indicator for a mapping key.</p>
<p>YAML does not allow nested mappings on one line, e.g.:</p>
<pre><code>foo: bar: baz
</code></pre>
<p>That's why YAML designers chose to forbid <code>:</code> in a mapping value if it's ... | <p>One of the problems here is the colon followed by a space <code>:</code>. This is usually an indicator for a mapping key.</p> <p>YAML does not allow nested mappings on one line, e.g.:</p> <pre><code>foo: bar: baz </code></pre> <p>That's why YAML designers chose to forbid <code>:</code> in a mapping value if it's ... | 387, 1852, 86394 | ansible, bash, yaml | <h1>How to escape special characters in ansible shell module</h1>
<p>I tried bash escape and double quotes methods to escape the special characters in below shell command, But both didn't work, What is the proper way to escape special characters in ansible playbook?</p>
<pre><code> The offending line appears to be:
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,310 | bash | # How to escape special characters in ansible shell module
I tried bash escape and double quotes methods to escape the special characters in below shell command, But both didn't work, What is the proper way to escape special characters in ansible playbook?
```
The offending line appears to be:
name... | One of the problems here is the colon followed by a space `:`. This is usually an indicator for a mapping key.
YAML does not allow nested mappings on one line, e.g.:
```
foo: bar: baz
```
That's why YAML designers chose to forbid `:` in a mapping value if it's on the same line as the key. (It could have been been so... |
48166091 | Using PowerShell to test an FTP connection | 9 | 2018-01-09 10:26:47 | <p>I have a PowerShell script that performs checks on some servers, for example <code>Test-Connection</code> for PING.</p>
<p>I wish to check one of the servers that has an FTP server by performing an "FTP Open" command. I don't need to log in or upload/download any files, just need to know if the FTP server responds ... | 26,799 | null | 2018-01-09 10:54:16 | 48,166,572 | 15 | 2018-01-09 10:54:16 | 2,208,505 | 2018-01-09 10:54:16 | https://stackoverflow.com/q/48166091 | https://stackoverflow.com/a/48166572 | <p><a href="https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=win10-ps" rel="noreferrer">Test-NetConnection</a> is native Powershell and can be used to test simple connectivity on FTP Port 21:</p>
<pre><code>Test-NetConnection -ComputerName ftp.contoso.com -Port 21
</code></pre>
| <p><a href="https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=win10-ps" rel="noreferrer">Test-NetConnection</a> is native Powershell and can be used to test simple connectivity on FTP Port 21:</p> <pre><code>Test-NetConnection -ComputerName ftp.contoso.com -Port 21 </code></pre> | 261, 526 | ftp, powershell | <h1>Using PowerShell to test an FTP connection</h1>
<p>I have a PowerShell script that performs checks on some servers, for example <code>Test-Connection</code> for PING.</p>
<p>I wish to check one of the servers that has an FTP server by performing an "FTP Open" command. I don't need to log in or upload/download any ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,311 | bash | # Using PowerShell to test an FTP connection
I have a PowerShell script that performs checks on some servers, for example `Test-Connection` for PING.
I wish to check one of the servers that has an FTP server by performing an "FTP Open" command. I don't need to log in or upload/download any files, just need to know if... | [Test-NetConnection](https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=win10-ps) is native Powershell and can be used to test simple connectivity on FTP Port 21:
```
Test-NetConnection -ComputerName ftp.contoso.com -Port 21
``` |
48059128 | Why does Select-String add empty lines? | 9 | 2018-01-02 10:18:22 | <p>Here is a minimal repro example.</p>
<p>Expected result:</p>
<pre><code>PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String "b"
b
PS C:\>
</code></pre>
<p>Actual result:</p>
<pre><code>PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String "b"
b
PS C:\>
</code></pre>
<p>As you can ... | 5,228 | 87,698 | 2018-01-02 12:14:29 | 48,060,726 | 15 | 2018-01-02 12:07:37 | 503,046 | 2018-01-02 12:14:29 | https://stackoverflow.com/q/48059128 | https://stackoverflow.com/a/48060726 | <p>The reason for weird output is that Powershell is all about objects. In this particular case, <code>Select-String</code> returns <code>MatchInfo</code> object(s). Like so,</p>
<pre><code>PS C:\> $o = ("a", "b") | Select-String "b"
PS C:\> $o
b
PS C:\> $o.GetType()
IsPublic IsSerial Name ... | <p>The reason for weird output is that Powershell is all about objects. In this particular case, <code>Select-String</code> returns <code>MatchInfo</code> object(s). Like so,</p> <pre><code>PS C:\> $o = ("a", "b") | Select-String "b" PS C:\> $o b PS C:\> $o.GetType() IsPublic IsSerial Name ... | 526 | powershell | <h1>Why does Select-String add empty lines?</h1>
<p>Here is a minimal repro example.</p>
<p>Expected result:</p>
<pre><code>PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String "b"
b
PS C:\>
</code></pre>
<p>Actual result:</p>
<pre><code>PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,312 | bash | # Why does Select-String add empty lines?
Here is a minimal repro example.
Expected result:
```
PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String "b"
b
PS C:\>
```
Actual result:
```
PS C:\> ("a", "b")
a
b
PS C:\> ("a", "b") | Select-String "b"
b
PS C:\>
```
As you can see, the second output has one em... | The reason for weird output is that Powershell is all about objects. In this particular case, `Select-String` returns `MatchInfo` object(s). Like so,
```
PS C:\> $o = ("a", "b") | Select-String "b"
PS C:\> $o
b
PS C:\> $o.GetType()
IsPublic IsSerial Name BaseType
-------- ------... |
47356782 | PowerShell Capture Git Output | 9 | 2017-11-17 18:07:40 | <h3>Problem</h3>
<p>I am running some git commands through PowerShell but I am having issues capturing the output.</p>
<p>Many of the ways I have looked into have failed to capture any output at all until I tried using <code>Out-File</code> . Unfortunately, despite how well this has been working for me, I have found ... | 12,140 | 8,371,580 | 2022-09-06 22:22:40 | 47,367,768 | 15 | 2017-11-18 15:32:16 | 6,309 | 2019-07-13 04:39:44 | https://stackoverflow.com/q/47356782 | https://stackoverflow.com/a/47367768 | <p>As I explained <a href="https://stackoverflow.com/a/37771637/6309">here</a>, or <a href="https://stackoverflow.com/a/37561629/6309">here</a>, Git command output are done on stderr, not stdout.</p>
<p>So in your case, you need to pipe stderr.<br>
See "<a href="https://stackoverflow.com/a/8938256/6309">Redirection of... | <p>As I explained <a href="https://stackoverflow.com/a/37771637/6309">here</a>, or <a href="https://stackoverflow.com/a/37561629/6309">here</a>, Git command output are done on stderr, not stdout.</p> <p>So in your case, you need to pipe stderr.<br> See "<a href="https://stackoverflow.com/a/8938256/6309">Redirection of... | 119, 526, 942 | git, logging, powershell | <h1>PowerShell Capture Git Output</h1>
<h3>Problem</h3>
<p>I am running some git commands through PowerShell but I am having issues capturing the output.</p>
<p>Many of the ways I have looked into have failed to capture any output at all until I tried using <code>Out-File</code> . Unfortunately, despite how well this... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,313 | bash | # PowerShell Capture Git Output
### Problem
I am running some git commands through PowerShell but I am having issues capturing the output.
Many of the ways I have looked into have failed to capture any output at all until I tried using `Out-File` . Unfortunately, despite how well this has been working for me, I have... | As I explained [here](https://stackoverflow.com/a/37771637/6309), or [here](https://stackoverflow.com/a/37561629/6309), Git command output are done on stderr, not stdout.
So in your case, you need to pipe stderr.
See "[Redirection of standard and error output appending to the same log-file](https://stackoverflow.com... |
45819444 | Bash command history is not written when a window is closed | 9 | 2017-08-22 13:46:50 | <p>I found that the "bash for ubuntu for windows" installed on my laptop cannot load the command history once I reboot the "bash for ubuntu for windows".</p>
<p>More precisely, if I open the terminal, and input some commands, then all commands I inputted in this terminal session can be found by the arrow keys. But if ... | 5,976 | 4,381,436 | 2017-08-27 01:09:52 | 45,819,569 | 15 | 2017-08-22 13:52:02 | 171,318 | 2017-08-22 13:58:42 | https://stackoverflow.com/q/45819444 | https://stackoverflow.com/a/45819569 | <p>You need to leave the shell by typing <code>exit</code> or <kbd>Ctrl</kbd>+<kbd>d</kbd> rather than just closing the window. <code>exit</code> will write the history implicitly, you can explicitly trigger a history write with <code>history -w</code> at any time.</p>
| <p>You need to leave the shell by typing <code>exit</code> or <kbd>Ctrl</kbd>+<kbd>d</kbd> rather than just closing the window. <code>exit</code> will write the history implicitly, you can explicitly trigger a history write with <code>history -w</code> at any time.</p> | 58, 64, 387, 549 | bash, linux, ubuntu, windows | <h1>Bash command history is not written when a window is closed</h1>
<p>I found that the "bash for ubuntu for windows" installed on my laptop cannot load the command history once I reboot the "bash for ubuntu for windows".</p>
<p>More precisely, if I open the terminal, and input some commands, then all commands I inpu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,314 | bash | # Bash command history is not written when a window is closed
I found that the "bash for ubuntu for windows" installed on my laptop cannot load the command history once I reboot the "bash for ubuntu for windows".
More precisely, if I open the terminal, and input some commands, then all commands I inputted in this ter... | You need to leave the shell by typing `exit` or `Ctrl`+`d` rather than just closing the window. `exit` will write the history implicitly, you can explicitly trigger a history write with `history -w` at any time. |
45796762 | Concat array elements with comma and single quote - Bash | 9 | 2017-08-21 12:09:10 | <p>How to convert array elements with single quotes and comma in Bash.</p>
<pre><code>arr=("element1" "element2" "element3")
#element1 element2 element3
</code></pre>
<p><strong>Desired result</strong>
<code>'element1','element2','element3'</code></p>
<p>From <a href="https://stackoverflow.com/a/1527146/5811973">Mar... | 5,068 | 5,811,973 | 2017-08-21 12:36:28 | 45,796,972 | 15 | 2017-08-21 12:19:01 | 3,161,993 | 2017-08-21 12:19:01 | https://stackoverflow.com/q/45796762 | https://stackoverflow.com/a/45796972 | <pre><code>[akshay@localhost tmp]$ arr=("element1" "element2" "element3")
[akshay@localhost tmp]$ joined=$(printf ",'%s'" "${arr[@]}")
[akshay@localhost tmp]$ echo ${joined:1}
'element1','element2','element3'
</code></pre>
| <pre><code>[akshay@localhost tmp]$ arr=("element1" "element2" "element3") [akshay@localhost tmp]$ joined=$(printf ",'%s'" "${arr[@]}") [akshay@localhost tmp]$ echo ${joined:1} 'element1','element2','element3' </code></pre> | 114, 387, 26793 | arrays, bash, ifs | <h1>Concat array elements with comma and single quote - Bash</h1>
<p>How to convert array elements with single quotes and comma in Bash.</p>
<pre><code>arr=("element1" "element2" "element3")
#element1 element2 element3
</code></pre>
<p><strong>Desired result</strong>
<code>'element1','element2','element3'</code></p>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,315 | bash | # Concat array elements with comma and single quote - Bash
How to convert array elements with single quotes and comma in Bash.
```
arr=("element1" "element2" "element3")
#element1 element2 element3
```
**Desired result**
`'element1','element2','element3'`
From [Martin Clayton](https://stackoverflow.com/a/1527146/58... | ```
[akshay@localhost tmp]$ arr=("element1" "element2" "element3")
[akshay@localhost tmp]$ joined=$(printf ",'%s'" "${arr[@]}")
[akshay@localhost tmp]$ echo ${joined:1}
'element1','element2','element3'
``` |
44310166 | How do I cd to the closest parent folder that has a .git folder with bash? | 9 | 2017-06-01 14:23:49 | <p>When working on projects that are version controlled I often end up in a nested folder. Using <code>cd ../../</code> gets a bit cumbersome, so I was wondering if there is a way to define an alias in bash that cd's to the parent until it reaches a folder with a <code>.git</code> folder, or it reaches <code>~</code>.<... | 2,342 | null | 2017-06-01 19:38:10 | 44,310,225 | 15 | 2017-06-01 14:26:38 | 507,762 | 2017-06-01 19:38:10 | https://stackoverflow.com/q/44310166 | https://stackoverflow.com/a/44310225 | <p>The command you're looking for is <code>git rev-parse --show-toplevel</code>, you can make a bash function that uses it.</p>
<pre><code>gr() {
cd "$(git rev-parse --show-toplevel)"
}
</code></pre>
<p>I also have in my <code>~/.gitconfig</code>:</p>
<pre><code>[alias]
root = rev-parse --show-toplevel
</cod... | <p>The command you're looking for is <code>git rev-parse --show-toplevel</code>, you can make a bash function that uses it.</p> <pre><code>gr() { cd "$(git rev-parse --show-toplevel)" } </code></pre> <p>I also have in my <code>~/.gitconfig</code>:</p> <pre><code>[alias] root = rev-parse --show-toplevel </cod... | 119, 387, 3718 | bash, cd, git | <h1>How do I cd to the closest parent folder that has a .git folder with bash?</h1>
<p>When working on projects that are version controlled I often end up in a nested folder. Using <code>cd ../../</code> gets a bit cumbersome, so I was wondering if there is a way to define an alias in bash that cd's to the parent until... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,316 | bash | # How do I cd to the closest parent folder that has a .git folder with bash?
When working on projects that are version controlled I often end up in a nested folder. Using `cd ../../` gets a bit cumbersome, so I was wondering if there is a way to define an alias in bash that cd's to the parent until it reaches a folder... | The command you're looking for is `git rev-parse --show-toplevel`, you can make a bash function that uses it.
```
gr() {
cd "$(git rev-parse --show-toplevel)"
}
```
I also have in my `~/.gitconfig`:
```
[alias]
root = rev-parse --show-toplevel
```
Which makes this command a little more reasonable looking. |
42652185 | How to quote nested sub-shell arguments correctly? | 9 | 2017-03-07 15:30:34 | <p>How to pass a string with spaces to a command which returns itself a string with spaces?</p>
<p>I tried the following four versions.</p>
<pre><code>arg='one arg'
arg() { echo "arg: $1"; }
printf '1 |%s|\n' $(arg "$arg")
printf '2 |%s|\n' "$(arg $arg)"
printf '3 |%s|\n' "$(arg \"$arg\")"
printf '4 |%s|\n' "$(arg ... | 1,010 | 402,322 | 2017-03-07 15:47:46 | 42,652,212 | 15 | 2017-03-07 15:32:07 | 14,122 | 2017-03-07 15:47:46 | https://stackoverflow.com/q/42652185 | https://stackoverflow.com/a/42652212 | <h3>The Syntax</h3>
<p>Using <code>$()</code> creates a new quoting context. Thus, double quotes <em>inside</em> a command substitution are completely independent of those outside it, and inside of closing the outer double quotes start a new and independent pair.</p>
<pre><code>arg='one arg'
arg() { echo "arg: $1"; ... | <h3>The Syntax</h3> <p>Using <code>$()</code> creates a new quoting context. Thus, double quotes <em>inside</em> a command substitution are completely independent of those outside it, and inside of closing the outer double quotes start a new and independent pair.</p> <pre><code>arg='one arg' arg() { echo "arg: $1"; ... | 387, 10804 | bash, quoting | <h1>How to quote nested sub-shell arguments correctly?</h1>
<p>How to pass a string with spaces to a command which returns itself a string with spaces?</p>
<p>I tried the following four versions.</p>
<pre><code>arg='one arg'
arg() { echo "arg: $1"; }
printf '1 |%s|\n' $(arg "$arg")
printf '2 |%s|\n' "$(arg $arg)"
p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,317 | bash | # How to quote nested sub-shell arguments correctly?
How to pass a string with spaces to a command which returns itself a string with spaces?
I tried the following four versions.
```
arg='one arg'
arg() { echo "arg: $1"; }
printf '1 |%s|\n' $(arg "$arg")
printf '2 |%s|\n' "$(arg $arg)"
printf '3 |%s|\n' "$(arg \"$... | ### The Syntax
Using `$()` creates a new quoting context. Thus, double quotes *inside* a command substitution are completely independent of those outside it, and inside of closing the outer double quotes start a new and independent pair.
```
arg='one arg'
arg() { echo "arg: $1"; }
printf '? |%s|\n' "$(arg "$arg")"
... |
41415173 | Why does this PowerShell script produce an error? | 9 | 2017-01-01 11:39:37 | <p>I have a file called <code>Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL</code> in a directory <code>C:\Hans\Hans4\</code>.</p>
<p>Code to create this is below (though the error occurs regardless of file contents)</p>
<pre><code>$fileContents = @"
[{000214A0-0000-0000-C000-000000000046}]
Prop... | 1,479 | 5,258,174 | 2017-01-03 08:05:24 | 41,418,282 | 15 | 2017-01-01 19:23:53 | 73,226 | 2017-01-03 08:05:24 | https://stackoverflow.com/q/41415173 | https://stackoverflow.com/a/41418282 | <p>The problem is the filename that is piped into the function and passed to <code>Get-Content</code></p>
<blockquote>
<p>C:\Hans\Hans4\Eric Clapton - Nothing But The Blues - Full Concert
(1994) <strong>[HQ]</strong>.URL</p>
</blockquote>
<p>You are encountering the problem described <a href="https://technet.micr... | <p>The problem is the filename that is piped into the function and passed to <code>Get-Content</code></p> <blockquote> <p>C:\Hans\Hans4\Eric Clapton - Nothing But The Blues - Full Concert (1994) <strong>[HQ]</strong>.URL</p> </blockquote> <p>You are encountering the problem described <a href="https://technet.micr... | 526 | powershell | <h1>Why does this PowerShell script produce an error?</h1>
<p>I have a file called <code>Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL</code> in a directory <code>C:\Hans\Hans4\</code>.</p>
<p>Code to create this is below (though the error occurs regardless of file contents)</p>
<pre><code>$file... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,318 | bash | # Why does this PowerShell script produce an error?
I have a file called `Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL` in a directory `C:\Hans\Hans4\`.
Code to create this is below (though the error occurs regardless of file contents)
```
$fileContents = @"
[{000214A0-0000-0000-C000-000000000... | The problem is the filename that is piped into the function and passed to `Get-Content`
> C:\Hans\Hans4\Eric Clapton - Nothing But The Blues - Full Concert
> (1994) **[HQ]**.URL
You are encountering the problem described [here](https://technet.microsoft.com/en-us/library/ff730956.aspx).
It contains square brackets t... |
40588240 | sed to remove all characters except letters and ' | 9 | 2016-11-14 11:58:15 | <p>I am using this sed command to strip documents of all their (for me) unnecessary characters. </p>
<pre><code>sed 's/[^a-zA-Z]/ /g'
</code></pre>
<p>However after mining my data a bit I realized a pretty basic mistake:
not including <code>'</code> cuts all my <code>don't</code>s into <code>don t</code>s, which suck... | 18,631 | 6,300,663 | 2018-09-14 16:24:32 | 40,588,334 | 15 | 2016-11-14 12:02:15 | 6,451,573 | 2016-11-14 12:55:42 | https://stackoverflow.com/q/40588240 | https://stackoverflow.com/a/40588334 | <p>Good old double-quotes in action to protect the single quote without any need of escaping:</p>
<pre><code>sed "s/[^a-zA-Z']/ /g" <<< "don't ... do this"
</code></pre>
<p>gives:</p>
<pre><code>don't do this
</code></pre>
<p>EDIT: your code seems to replace non-letters by space, but your question stat... | <p>Good old double-quotes in action to protect the single quote without any need of escaping:</p> <pre><code>sed "s/[^a-zA-Z']/ /g" <<< "don't ... do this" </code></pre> <p>gives:</p> <pre><code>don't do this </code></pre> <p>EDIT: your code seems to replace non-letters by space, but your question stat... | 387, 5282 | bash, sed | <h1>sed to remove all characters except letters and '</h1>
<p>I am using this sed command to strip documents of all their (for me) unnecessary characters. </p>
<pre><code>sed 's/[^a-zA-Z]/ /g'
</code></pre>
<p>However after mining my data a bit I realized a pretty basic mistake:
not including <code>'</code> cuts all ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,319 | bash | # sed to remove all characters except letters and '
I am using this sed command to strip documents of all their (for me) unnecessary characters.
```
sed 's/[^a-zA-Z]/ /g'
```
However after mining my data a bit I realized a pretty basic mistake:
not including `'` cuts all my `don't`s into `don t`s, which sucks.
So i... | Good old double-quotes in action to protect the single quote without any need of escaping:
```
sed "s/[^a-zA-Z']/ /g" <<< "don't ... do this"
```
gives:
```
don't do this
```
EDIT: your code seems to replace non-letters by space, but your question states otherwise, so I'm giving you the other version, to remove... |
39385795 | Suppress Openssl output during grep | 9 | 2016-09-08 08:12:53 | <p>I often use <code>grep</code> for openssl results when testing TLS security. For example:</p>
<pre><code>$ openssl s_client -tls1_2 -connect 172.11.15.32:443 </dev/null | grep 'IS s'
depth=0 C = US, ST = asd, O = Billing, CN = asdasd, emailAddress = root@asdasd
verify error:num=18:self signed certificate
verify ... | 20,589 | 6,325,645 | 2016-09-08 08:28:51 | 39,386,098 | 15 | 2016-09-08 08:28:51 | 1,983,854 | 2016-09-08 08:28:51 | https://stackoverflow.com/q/39385795 | https://stackoverflow.com/a/39386098 | <p>As indicated in comments, the problem is that the command <code>openssl</code> displays part of its output through <code>stderr</code>. Then, this will show no matter what you pipe.</p>
<p>So if you want to just show what <code>grep</code> has filtered to you, you have to previously redirect <code>stderr</code> to ... | <p>As indicated in comments, the problem is that the command <code>openssl</code> displays part of its output through <code>stderr</code>. Then, this will show no matter what you pipe.</p> <p>So if you want to just show what <code>grep</code> has filtered to you, you have to previously redirect <code>stderr</code> to ... | 387, 1271 | bash, grep | <h1>Suppress Openssl output during grep</h1>
<p>I often use <code>grep</code> for openssl results when testing TLS security. For example:</p>
<pre><code>$ openssl s_client -tls1_2 -connect 172.11.15.32:443 </dev/null | grep 'IS s'
depth=0 C = US, ST = asd, O = Billing, CN = asdasd, emailAddress = root@asdasd
verify... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,320 | bash | # Suppress Openssl output during grep
I often use `grep` for openssl results when testing TLS security. For example:
```
$ openssl s_client -tls1_2 -connect 172.11.15.32:443 </dev/null | grep 'IS s'
depth=0 C = US, ST = asd, O = Billing, CN = asdasd, emailAddress = root@asdasd
verify error:num=18:self signed certific... | As indicated in comments, the problem is that the command `openssl` displays part of its output through `stderr`. Then, this will show no matter what you pipe.
So if you want to just show what `grep` has filtered to you, you have to previously redirect `stderr` to `/dev/null` so that it does not "jump the pipe":
```
... |
38126254 | How do I set the build number in Teamcity? | 9 | 2016-06-30 14:33:22 | <p>I'm trying to set the build number format in Teamcity using Powershell (kinda like in this Octopus Deploy <a href="https://octopus.com/blog/teamcity-version-numbers-based-on-branches" rel="noreferrer">blog post</a>).</p>
<p>However, I don't know if the way Teamcity handles the service messages has changed since the... | 14,361 | 190,701 | 2016-07-04 10:54:23 | 38,182,736 | 15 | 2016-07-04 10:41:38 | 471,210 | 2016-07-04 10:41:38 | https://stackoverflow.com/q/38126254 | https://stackoverflow.com/a/38182736 | <p>It seems the last line of the script should be:</p>
<pre><code>Write-Host "##teamcity[buildNumber '${buildNumber}']"
</code></pre>
<p>A note: for the script to work, if should be specified as inline script in TeamCity build step (which makes TeamCity %-references to work).</p>
<p>BTW, you can make TeamCity displ... | <p>It seems the last line of the script should be:</p> <pre><code>Write-Host "##teamcity[buildNumber '${buildNumber}']" </code></pre> <p>A note: for the script to work, if should be specified as inline script in TeamCity build step (which makes TeamCity %-references to work).</p> <p>BTW, you can make TeamCity displ... | 526, 604 | powershell, teamcity | <h1>How do I set the build number in Teamcity?</h1>
<p>I'm trying to set the build number format in Teamcity using Powershell (kinda like in this Octopus Deploy <a href="https://octopus.com/blog/teamcity-version-numbers-based-on-branches" rel="noreferrer">blog post</a>).</p>
<p>However, I don't know if the way Teamcit... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,321 | bash | # How do I set the build number in Teamcity?
I'm trying to set the build number format in Teamcity using Powershell (kinda like in this Octopus Deploy [blog post](https://octopus.com/blog/teamcity-version-numbers-based-on-branches)).
However, I don't know if the way Teamcity handles the service messages has changed s... | It seems the last line of the script should be:
```
Write-Host "##teamcity[buildNumber '${buildNumber}']"
```
A note: for the script to work, if should be specified as inline script in TeamCity build step (which makes TeamCity %-references to work).
BTW, you can make TeamCity display short branch name by using +:ref... |
37557974 | Returning a value from within a ForEach in Powershell | 9 | 2016-06-01 01:17:02 | <p>This seems really basic, but I can't see how or why it behaves this way:</p>
<pre><code>function ReturnStuff{
$a=1,2,3,4,5
$a.ForEach{
return $_
}
}
ReturnStuff
</code></pre>
<p>Why does this give me:
1
2
3
4
5
instead of just 1?</p>
| 19,528 | 1,063,215 | 2016-06-01 01:54:12 | 37,558,236 | 15 | 2016-06-01 01:54:12 | 551,834 | 2016-06-01 01:54:12 | https://stackoverflow.com/q/37557974 | https://stackoverflow.com/a/37558236 | <p>It looks like you are calling <code>ForEach</code> (a function in <code>[System.Array]</code>) with a parameter which is a scriptblock. Essentially, you are defining and returning <code>{ Return $_ }</code> every iteration of the loop.</p>
<p>This means <code>ReturnStuff</code> will capture output each time, and be... | <p>It looks like you are calling <code>ForEach</code> (a function in <code>[System.Array]</code>) with a parameter which is a scriptblock. Essentially, you are defining and returning <code>{ Return $_ }</code> every iteration of the loop.</p> <p>This means <code>ReturnStuff</code> will capture output each time, and be... | 526, 631, 2314 | foreach, loops, powershell | <h1>Returning a value from within a ForEach in Powershell</h1>
<p>This seems really basic, but I can't see how or why it behaves this way:</p>
<pre><code>function ReturnStuff{
$a=1,2,3,4,5
$a.ForEach{
return $_
}
}
ReturnStuff
</code></pre>
<p>Why does this give me:
1
2
3
4
5
instead of just 1?</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,322 | bash | # Returning a value from within a ForEach in Powershell
This seems really basic, but I can't see how or why it behaves this way:
```
function ReturnStuff{
$a=1,2,3,4,5
$a.ForEach{
return $_
}
}
ReturnStuff
```
Why does this give me:
1
2
3
4
5
instead of just 1? | It looks like you are calling `ForEach` (a function in `[System.Array]`) with a parameter which is a scriptblock. Essentially, you are defining and returning `{ Return $_ }` every iteration of the loop.
This means `ReturnStuff` will capture output each time, and because this function does nothing with the output of th... |
32629301 | get json object from stringify object using jq filter in shell script | 9 | 2015-09-17 11:32:14 | <p>i am wring the shell script as i am new. my query is
i have json object like</p>
<pre><code>{
"logo": {"name":"logo.png","type":"image\/jpeg","tmp_name":"C:\\xampp\\tmp\\php8B97.tmp","error":0,"size":110290},
"template":"template1",
"firstname":"a",
"lastname":"a",
"username":"a",
"password":"aa"... | 7,647 | 5,022,996 | 2015-09-17 15:15:00 | 32,633,865 | 15 | 2015-09-17 15:09:40 | 997,358 | 2015-09-17 15:15:00 | https://stackoverflow.com/q/32629301 | https://stackoverflow.com/a/32633865 | <p><em>fromjson</em> is your friend:</p>
<pre><code>$ jq '.categoriesListArr | fromjson' detail.json
</code></pre>
<p>Or, if you want to retain the original structure:</p>
<pre><code>$ jq '.categoriesListArr |= fromjson' detail.json
</code></pre>
| <p><em>fromjson</em> is your friend:</p> <pre><code>$ jq '.categoriesListArr | fromjson' detail.json </code></pre> <p>Or, if you want to retain the original structure:</p> <pre><code>$ jq '.categoriesListArr |= fromjson' detail.json </code></pre> | 58, 390, 1508, 105170 | jq, json, linux, shell | <h1>get json object from stringify object using jq filter in shell script</h1>
<p>i am wring the shell script as i am new. my query is
i have json object like</p>
<pre><code>{
"logo": {"name":"logo.png","type":"image\/jpeg","tmp_name":"C:\\xampp\\tmp\\php8B97.tmp","error":0,"size":110290},
"template":"template1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,323 | bash | # get json object from stringify object using jq filter in shell script
i am wring the shell script as i am new. my query is
i have json object like
```
{
"logo": {"name":"logo.png","type":"image\/jpeg","tmp_name":"C:\\xampp\\tmp\\php8B97.tmp","error":0,"size":110290},
"template":"template1",
"firstname":"a"... | *fromjson* is your friend:
```
$ jq '.categoriesListArr | fromjson' detail.json
```
Or, if you want to retain the original structure:
```
$ jq '.categoriesListArr |= fromjson' detail.json
``` |
31869731 | What is the meaning of "0,/xxx" in sed? | 9 | 2015-08-07 04:31:32 | <p>A sed command used in a script as following:</p>
<pre><code>sed -i "0,/^ENABLE_DEBUG.*/s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/" MakeConfig
</code></pre>
<p>I knows that</p>
<pre><code>s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/
</code></pre>
<p>is to substitutes line prefix </p>
<p><code>ENABLE_DEBUG</code> as <code>EN... | 7,462 | 5,200,480 | 2015-08-07 06:38:52 | 31,869,777 | 15 | 2015-08-07 04:37:32 | 3,030,305 | 2015-08-07 06:38:52 | https://stackoverflow.com/q/31869731 | https://stackoverflow.com/a/31869777 | <p><code>0,/^ENABLE_DEBUG.*/</code> means that the substitution will only occur on lines from the beginning, <code>0</code>, to the first line that matches <code>/^ENABLE_DEBUG.*/</code>. No substitution will be made on subsequent lines even if they match <code>/^ENABLE_DEBUG.*/</code></p>
<h3>Other examples of range... | <p><code>0,/^ENABLE_DEBUG.*/</code> means that the substitution will only occur on lines from the beginning, <code>0</code>, to the first line that matches <code>/^ENABLE_DEBUG.*/</code>. No substitution will be made on subsequent lines even if they match <code>/^ENABLE_DEBUG.*/</code></p> <h3>Other examples of range... | 387, 5282 | bash, sed | <h1>What is the meaning of "0,/xxx" in sed?</h1>
<p>A sed command used in a script as following:</p>
<pre><code>sed -i "0,/^ENABLE_DEBUG.*/s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/" MakeConfig
</code></pre>
<p>I knows that</p>
<pre><code>s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/
</code></pre>
<p>is to substitutes line pref... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,324 | bash | # What is the meaning of "0,/xxx" in sed?
A sed command used in a script as following:
```
sed -i "0,/^ENABLE_DEBUG.*/s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/" MakeConfig
```
I knows that
```
s/^ENABLE_DEBUG.*/ENABLE_DEBUG = YES/
```
is to substitutes line prefix
`ENABLE_DEBUG` as `ENABLE_DEBUG = YES`
But no idea a... | `0,/^ENABLE_DEBUG.*/` means that the substitution will only occur on lines from the beginning, `0`, to the first line that matches `/^ENABLE_DEBUG.*/`. No substitution will be made on subsequent lines even if they match `/^ENABLE_DEBUG.*/`
### Other examples of ranges
This will substitute only on lines 2 through 5:
... |
31806010 | An easy way to output an array in a single line | 9 | 2015-08-04 09:50:20 | <p>I have an array in a line of <code>$a=@(1,2,3,4,56)</code>. When I do <code>Write-Debug $a</code> I get an exception in a line of "Array is not a String". If I do <code>$a | out-string | write-debug</code> I get a list of values in a column. I can write a function that'll write an array in a row (or a string without... | 17,561 | 1,627,055 | 2021-02-09 18:50:50 | 31,806,134 | 15 | 2015-08-04 09:55:40 | 1,163,423 | 2015-08-04 09:55:40 | https://stackoverflow.com/q/31806010 | https://stackoverflow.com/a/31806134 | <p>Yes, using <code>-join</code>:</p>
<pre><code>$a -join ','
</code></pre>
| <p>Yes, using <code>-join</code>:</p> <pre><code>$a -join ',' </code></pre> | 114, 526, 10232 | arrays, powershell, string-formatting | <h1>An easy way to output an array in a single line</h1>
<p>I have an array in a line of <code>$a=@(1,2,3,4,56)</code>. When I do <code>Write-Debug $a</code> I get an exception in a line of "Array is not a String". If I do <code>$a | out-string | write-debug</code> I get a list of values in a column. I can write a func... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,325 | bash | # An easy way to output an array in a single line
I have an array in a line of `$a=@(1,2,3,4,56)`. When I do `Write-Debug $a` I get an exception in a line of "Array is not a String". If I do `$a | out-string | write-debug` I get a list of values in a column. I can write a function that'll write an array in a row (or a... | Yes, using `-join`:
```
$a -join ','
``` |
31712946 | Print specific lines of a file in Terminal | 9 | 2015-07-29 23:38:01 | <p>This seems pretty silly, but I haven't found a tool that does this, so I figured I'd ask just to make sure one doesn't exist before trying to code it up myself:</p>
<p>Is there any easy way to <code>cat</code> or <code>less</code> specific lines of a file?</p>
<p>I'm hoping for behavior like this:</p>
<pre><code>... | 17,040 | 3,211,197 | 2015-07-30 02:51:22 | 31,714,440 | 15 | 2015-07-30 02:51:22 | 5,045,048 | 2015-07-30 02:51:22 | https://stackoverflow.com/q/31712946 | https://stackoverflow.com/a/31714440 | <p>yes awk and sed can help</p>
<p>for lines 5 to 10</p>
<pre><code>awk 'NR>4&&NR<11' file.txt
sed -n '5,10p' file.txt
</code></pre>
<p>for lines 10 to last line</p>
<pre><code>awk 'NR>9' file.txt
sed -n '10,$p' file.txt
</code></pre>
| <p>yes awk and sed can help</p> <p>for lines 5 to 10</p> <pre><code>awk 'NR>4&&NR<11' file.txt sed -n '5,10p' file.txt </code></pre> <p>for lines 10 to last line</p> <pre><code>awk 'NR>9' file.txt sed -n '10,$p' file.txt </code></pre> | 369, 390, 391, 1231 | command-line, macos, shell, terminal | <h1>Print specific lines of a file in Terminal</h1>
<p>This seems pretty silly, but I haven't found a tool that does this, so I figured I'd ask just to make sure one doesn't exist before trying to code it up myself:</p>
<p>Is there any easy way to <code>cat</code> or <code>less</code> specific lines of a file?</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,326 | bash | # Print specific lines of a file in Terminal
This seems pretty silly, but I haven't found a tool that does this, so I figured I'd ask just to make sure one doesn't exist before trying to code it up myself:
Is there any easy way to `cat` or `less` specific lines of a file?
I'm hoping for behavior like this:
```
# -s... | yes awk and sed can help
for lines 5 to 10
```
awk 'NR>4&&NR<11' file.txt
sed -n '5,10p' file.txt
```
for lines 10 to last line
```
awk 'NR>9' file.txt
sed -n '10,$p' file.txt
``` |
30379527 | Get a list of s3 buckets associated with amazon access key using powershell? | 9 | 2015-05-21 16:34:43 | <p>I have tried googling how I could retrieve a list of available s3 buckets associated with an Amazon Access Key, but either I am searching the wrong terms, or I haven't went through enough results.</p>
<p>I have an access key and secret key, but I do not know the bucket name(s) associated with either the account or ... | 16,158 | 1,770,228 | 2015-05-21 19:55:28 | 30,383,037 | 15 | 2015-05-21 19:47:48 | 775,544 | 2015-05-21 19:53:03 | https://stackoverflow.com/q/30379527 | https://stackoverflow.com/a/30383037 | <p>Assuming that you've already set up your <a href="http://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html" rel="noreferrer">AWS Credentials</a> the way you want, you can simply call <a href="http://docs.aws.amazon.com/powershell/latest/reference/items/Get-S3Bucket.html" rel="noref... | <p>Assuming that you've already set up your <a href="http://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html" rel="noreferrer">AWS Credentials</a> the way you want, you can simply call <a href="http://docs.aws.amazon.com/powershell/latest/reference/items/Get-S3Bucket.html" rel="noref... | 526, 11444, 33388, 100823 | amazon-s3, amazon-web-services, aws-powershell, powershell | <h1>Get a list of s3 buckets associated with amazon access key using powershell?</h1>
<p>I have tried googling how I could retrieve a list of available s3 buckets associated with an Amazon Access Key, but either I am searching the wrong terms, or I haven't went through enough results.</p>
<p>I have an access key and s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,327 | bash | # Get a list of s3 buckets associated with amazon access key using powershell?
I have tried googling how I could retrieve a list of available s3 buckets associated with an Amazon Access Key, but either I am searching the wrong terms, or I haven't went through enough results.
I have an access key and secret key, but I... | Assuming that you've already set up your [AWS Credentials](http://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html) the way you want, you can simply call [Get-S3Bucket](http://docs.aws.amazon.com/powershell/latest/reference/items/Get-S3Bucket.html). This invokes ListBuckets, and retu... |
29418050 | Package tar.gz into a shell script | 9 | 2015-04-02 16:38:36 | <p>I'd like to know how to package a tar.gz file into a shell script, just like idk**.bin does. So I can deliver the program in one shell file instead of tar.gz</p>
| 9,432 | 319,077 | 2015-04-04 09:48:30 | 29,418,549 | 15 | 2015-04-02 17:07:27 | 974,063 | 2015-04-02 17:13:24 | https://stackoverflow.com/q/29418050 | https://stackoverflow.com/a/29418549 | <p>There is a <a href="http://www.linuxjournal.com/node/1005818" rel="noreferrer">Linux Journal article</a> explaining how to do this in detail, with code for packing the payload, etc. As Etan Reisner says in his comment, the extraction/installation script knows how to cut its tail off to obtain the payload which was c... | <p>There is a <a href="http://www.linuxjournal.com/node/1005818" rel="noreferrer">Linux Journal article</a> explaining how to do this in detail, with code for packing the payload, etc. As Etan Reisner says in his comment, the extraction/installation script knows how to cut its tail off to obtain the payload which was c... | 58, 390, 529, 8773 | installation, linux, shell, tar | <h1>Package tar.gz into a shell script</h1>
<p>I'd like to know how to package a tar.gz file into a shell script, just like idk**.bin does. So I can deliver the program in one shell file instead of tar.gz</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,328 | bash | # Package tar.gz into a shell script
I'd like to know how to package a tar.gz file into a shell script, just like idk**.bin does. So I can deliver the program in one shell file instead of tar.gz | There is a [Linux Journal article](http://www.linuxjournal.com/node/1005818) explaining how to do this in detail, with code for packing the payload, etc. As Etan Reisner says in his comment, the extraction/installation script knows how to cut its tail off to obtain the payload which was concatenated earlier. Here's an ... |
28971833 | Where does Powershell ISE store tabs when it crashes? | 9 | 2015-03-10 18:53:05 | <p>My Powershell ISE is crashing upon being launched; and I believe it is due to a tab/file that is being loaded when ISE returns from being exited incorrectly. As a result, I'm currently unable to launch ISE.. I'm looking for the file/location where Powershell ISE stores the tabs/files that are currently opened so tha... | 29,427 | 776,890 | 2021-05-06 20:42:00 | 28,974,651 | 15 | 2015-03-10 21:43:23 | 712,649 | 2018-01-15 23:39:07 | https://stackoverflow.com/q/28971833 | https://stackoverflow.com/a/28974651 | <p>Using <a href="https://technet.microsoft.com/en-us/library/bb896645.aspx" rel="noreferrer">Process Monitor</a>, I've found that the ISE stores and loads its recovered files from:</p>
<pre><code>%LOCALAPPDATA%\Microsoft_Corporation\powershell_ise.exe_StrongName_lw2v2vm3wmtzzpebq33gybmeoxukb04w\3.0.0.0\AutoSaveFiles
... | <p>Using <a href="https://technet.microsoft.com/en-us/library/bb896645.aspx" rel="noreferrer">Process Monitor</a>, I've found that the ISE stores and loads its recovered files from:</p> <pre><code>%LOCALAPPDATA%\Microsoft_Corporation\powershell_ise.exe_StrongName_lw2v2vm3wmtzzpebq33gybmeoxukb04w\3.0.0.0\AutoSaveFiles ... | 64, 178, 526, 22864 | crash, powershell, powershell-ise, windows | <h1>Where does Powershell ISE store tabs when it crashes?</h1>
<p>My Powershell ISE is crashing upon being launched; and I believe it is due to a tab/file that is being loaded when ISE returns from being exited incorrectly. As a result, I'm currently unable to launch ISE.. I'm looking for the file/location where Powers... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,329 | bash | # Where does Powershell ISE store tabs when it crashes?
My Powershell ISE is crashing upon being launched; and I believe it is due to a tab/file that is being loaded when ISE returns from being exited incorrectly. As a result, I'm currently unable to launch ISE.. I'm looking for the file/location where Powershell ISE ... | Using [Process Monitor](https://technet.microsoft.com/en-us/library/bb896645.aspx), I've found that the ISE stores and loads its recovered files from:
```
%LOCALAPPDATA%\Microsoft_Corporation\powershell_ise.exe_StrongName_lw2v2vm3wmtzzpebq33gybmeoxukb04w\3.0.0.0\AutoSaveFiles
```
Holds true for both Windows 7 with PS... |
27626800 | Run bash script from another script and exit first script while second is running | 9 | 2014-12-23 19:30:10 | <p>First bash script is:</p>
<pre><code>./second #takes too long
</code></pre>
<p>I want kill first bash script while second bash script is still running.</p>
<p>Can I do that?</p>
<p><strong>UPDATE</strong></p>
<p>First script run by cronjob!</p>
| 8,811 | 4,323,200 | 2014-12-23 20:08:45 | 27,627,302 | 15 | 2014-12-23 20:08:45 | 7,552 | 2014-12-23 20:08:45 | https://stackoverflow.com/q/27626800 | https://stackoverflow.com/a/27627302 | <p>If the last thing that the first script does is to call the second script, then do this:</p>
<pre><code>exec ./second
</code></pre>
<p>which <em>replaces</em> the first script's process with the second.</p>
<p>otherwise</p>
<pre><code>nohup ./second &
disown
</code></pre>
| <p>If the last thing that the first script does is to call the second script, then do this:</p> <pre><code>exec ./second </code></pre> <p>which <em>replaces</em> the first script's process with the second.</p> <p>otherwise</p> <pre><code>nohup ./second & disown </code></pre> | 58, 387 | bash, linux | <h1>Run bash script from another script and exit first script while second is running</h1>
<p>First bash script is:</p>
<pre><code>./second #takes too long
</code></pre>
<p>I want kill first bash script while second bash script is still running.</p>
<p>Can I do that?</p>
<p><strong>UPDATE</strong></p>
<p>First scr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,330 | bash | # Run bash script from another script and exit first script while second is running
First bash script is:
```
./second #takes too long
```
I want kill first bash script while second bash script is still running.
Can I do that?
**UPDATE**
First script run by cronjob! | If the last thing that the first script does is to call the second script, then do this:
```
exec ./second
```
which *replaces* the first script's process with the second.
otherwise
```
nohup ./second &
disown
``` |
26984637 | powershell variable syntax $($a)? | 9 | 2014-11-18 00:37:09 | <p>I have a simple question regarding why something works the way it does and I cant seem to readily find out why.
I was trying to run the following command:</p>
<p><code>foreach($a in $list){set-mailboxcalendarpermissions -identity $($a):\calendar</code></p>
<p>while it works just fine, I don't know what adding the ... | 8,121 | 2,127,822 | 2024-08-10 00:46:24 | 26,984,792 | 15 | 2014-11-18 00:54:41 | 696,808 | 2014-11-18 05:26:57 | https://stackoverflow.com/q/26984637 | https://stackoverflow.com/a/26984792 | <p><code>$()</code> is a <a href="http://technet.microsoft.com/en-us/library/hh847732.aspx">subexpression operator</a>. It means "evaluate this first, and do it separately as an independent statement".</p>
<p>Most often, its used when you're using an inline string. Say:</p>
<pre><code>$x = Get-ChildItem C:\;
$x | F... | <p><code>$()</code> is a <a href="http://technet.microsoft.com/en-us/library/hh847732.aspx">subexpression operator</a>. It means "evaluate this first, and do it separately as an independent statement".</p> <p>Most often, its used when you're using an inline string. Say:</p> <pre><code>$x = Get-ChildItem C:\; $x | F... | 526 | powershell | <h1>powershell variable syntax $($a)?</h1>
<p>I have a simple question regarding why something works the way it does and I cant seem to readily find out why.
I was trying to run the following command:</p>
<p><code>foreach($a in $list){set-mailboxcalendarpermissions -identity $($a):\calendar</code></p>
<p>while it wor... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,331 | bash | # powershell variable syntax $($a)?
I have a simple question regarding why something works the way it does and I cant seem to readily find out why.
I was trying to run the following command:
`foreach($a in $list){set-mailboxcalendarpermissions -identity $($a):\calendar`
while it works just fine, I don't know what ad... | `$()` is a [subexpression operator](http://technet.microsoft.com/en-us/library/hh847732.aspx). It means "evaluate this first, and do it separately as an independent statement".
Most often, its used when you're using an inline string. Say:
```
$x = Get-ChildItem C:\;
$x | ForEach-Object {
Write-Output "The file is... |
26417658 | subprocess.call() arguments ignored when using shell=True w/ list | 9 | 2014-10-17 03:59:46 | <p>I am trying to get python's subprocess.call method to accept some args commands through a list (consisting of a sequence of strings) as advised in the python documentation. To explore this behavior before putting it into my actual script, I opened up IPython, ran some commands involving different combinations of she... | 3,782 | 4,134,449 | 2022-09-06 21:44:52 | 26,417,712 | 15 | 2014-10-17 04:07:41 | 1,126,841 | 2014-10-17 04:16:10 | https://stackoverflow.com/q/26417658 | https://stackoverflow.com/a/26417712 | <p>When <code>shell</code> is True, the first argument is appended to <code>["/bin/sh", "-c"]</code>. If that argument is a list, the resulting list is</p>
<pre><code>["/bin/sh", "-c", "ls", "-al"]
</code></pre>
<p>That is, only <code>ls</code>, not <code>ls -al</code> is used as the argument to the <code>-c</code> o... | <p>When <code>shell</code> is True, the first argument is appended to <code>["/bin/sh", "-c"]</code>. If that argument is a list, the resulting list is</p> <pre><code>["/bin/sh", "-c", "ls", "-al"] </code></pre> <p>That is, only <code>ls</code>, not <code>ls -al</code> is used as the argument to the <code>-c</code> o... | 16, 387, 390, 2348, 8632 | bash, call, python, shell, subprocess | <h1>subprocess.call() arguments ignored when using shell=True w/ list</h1>
<p>I am trying to get python's subprocess.call method to accept some args commands through a list (consisting of a sequence of strings) as advised in the python documentation. To explore this behavior before putting it into my actual script, I o... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,332 | bash | # subprocess.call() arguments ignored when using shell=True w/ list
I am trying to get python's subprocess.call method to accept some args commands through a list (consisting of a sequence of strings) as advised in the python documentation. To explore this behavior before putting it into my actual script, I opened up ... | When `shell` is True, the first argument is appended to `["/bin/sh", "-c"]`. If that argument is a list, the resulting list is
```
["/bin/sh", "-c", "ls", "-al"]
```
That is, only `ls`, not `ls -al` is used as the argument to the `-c` option. `-al` is used as the first argument the shell itself, not `ls`.
When using... |
26068999 | Bash printf %q invalid directive | 9 | 2014-09-26 22:08:53 | <p>I want to change my PS1 in my .bashrc file.
I've found a script using printf with %q directive to escape characters :</p>
<pre><code>#!/bin/bash
STR=$(printf "%q" "PS1=\u@\h:\w\$ ")
sed -i '/PS1/c\'"$STR" ~/.bashrc
</code></pre>
<p>The problem is that I get this error :</p>
<pre><code>script.sh: 2: printf: %q: in... | 11,275 | 3,552,679 | 2024-08-22 01:16:03 | 26,069,697 | 15 | 2014-09-26 23:27:45 | 827,263 | 2017-02-16 18:16:36 | https://stackoverflow.com/q/26068999 | https://stackoverflow.com/a/26069697 | <p>The <code>printf</code> command is built into bash. It's also an external command, typically installed in <code>/usr/bin/printf</code>. On most Linux systems, <code>/usr/bin/printf</code> is the GNU coreutils implementation.</p>
<p>Older releases of the GNU coreutils <code>printf</code> command do not support the <... | <p>The <code>printf</code> command is built into bash. It's also an external command, typically installed in <code>/usr/bin/printf</code>. On most Linux systems, <code>/usr/bin/printf</code> is the GNU coreutils implementation.</p> <p>Older releases of the GNU coreutils <code>printf</code> command do not support the <... | 58, 387, 1156, 5282, 53034 | bash, linux, printf, ps1, sed | <h1>Bash printf %q invalid directive</h1>
<p>I want to change my PS1 in my .bashrc file.
I've found a script using printf with %q directive to escape characters :</p>
<pre><code>#!/bin/bash
STR=$(printf "%q" "PS1=\u@\h:\w\$ ")
sed -i '/PS1/c\'"$STR" ~/.bashrc
</code></pre>
<p>The problem is that I get this error :</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,333 | bash | # Bash printf %q invalid directive
I want to change my PS1 in my .bashrc file.
I've found a script using printf with %q directive to escape characters :
```
#!/bin/bash
STR=$(printf "%q" "PS1=\u@\h:\w\$ ")
sed -i '/PS1/c\'"$STR" ~/.bashrc
```
The problem is that I get this error :
```
script.sh: 2: printf: %q: inva... | The `printf` command is built into bash. It's also an external command, typically installed in `/usr/bin/printf`. On most Linux systems, `/usr/bin/printf` is the GNU coreutils implementation.
Older releases of the GNU coreutils `printf` command do not support the `%q` format specifier; it was introduced in version 8.2... |
23280393 | Powershell Arrays and Parenthesis | 9 | 2014-04-24 21:40:32 | <p>Coming from other programming languages, I would expect the following statements to all produce the same result. Can someone explain why the parenthesis make a difference here?</p>
<pre><code>PS D:\> "ab", "cd"
ab
cd
PS D:\> "a"+"b" , "c"+"d"
ab cd
PS D:\> "a"+"b" , ("c"+"d")
ab cd
PS D:\> ("a... | 921 | 787,757 | 2014-04-24 23:26:16 | 23,280,806 | 15 | 2014-04-24 22:12:06 | 1,248,365 | 2014-04-24 23:26:16 | https://stackoverflow.com/q/23280393 | https://stackoverflow.com/a/23280806 |
<p>The applicable rules are as follows:</p>
<ul>
<li>The <code>,</code> is a unary or binary operator that creates an array of the operand(s), and it has higher precedence than the <code>+</code> operator.</li>
<li>The <code>+</code> operator can be used for numerical addition, string concatenation, and array concat... | <p>The applicable rules are as follows:</p> <ul> <li>The <code>,</code> is a unary or binary operator that creates an array of the operand(s), and it has higher precedence than the <code>+</code> operator.</li> <li>The <code>+</code> operator can be used for numerical addition, string concatenation, and array concat... | 367, 526 | powershell, syntax | <h1>Powershell Arrays and Parenthesis</h1>
<p>Coming from other programming languages, I would expect the following statements to all produce the same result. Can someone explain why the parenthesis make a difference here?</p>
<pre><code>PS D:\> "ab", "cd"
ab
cd
PS D:\> "a"+"b" , "c"+"d"
ab cd
PS D:\>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,334 | bash | # Powershell Arrays and Parenthesis
Coming from other programming languages, I would expect the following statements to all produce the same result. Can someone explain why the parenthesis make a difference here?
```
PS D:\> "ab", "cd"
ab
cd
PS D:\> "a"+"b" , "c"+"d"
ab cd
PS D:\> "a"+"b" , ("c"+"d")
ab cd
... | The applicable rules are as follows:
- The `,` is a unary or binary operator that creates an array of the operand(s), and it has higher precedence than the `+` operator.
- The `+` operator can be used for numerical addition, string concatenation, and array concatenation. The data type of the ***left*** operand determi... |
22408455 | How to list only the dot files and dot folder names (without the content in them) | 9 | 2014-03-14 14:53:47 | <p>I want to list only the files and folders that are hidden (starting with dot). When I use the command</p>
<pre><code>ls .??*
</code></pre>
<p>I get the output</p>
<pre><code>.gitignore
.git:
COMMIT_EDITMSG FETCH_HEAD HEAD ORIG_HEAD branches config description hooks in... | 5,006 | 48,912 | 2014-03-14 15:03:50 | 22,408,516 | 15 | 2014-03-14 14:56:17 | 164,835 | 2014-03-14 15:03:50 | https://stackoverflow.com/q/22408455 | https://stackoverflow.com/a/22408516 | <p>try:</p>
<pre><code>ls -d .*
</code></pre>
<p>fyi</p>
<pre><code> -d, --directory
list directories themselves, not their contents
</code></pre>
<p>if your ls is not alias of other command, the output of above <code>ls -d .*</code> will output files/dirs in same line. If you want to have them each in ... | <p>try:</p> <pre><code>ls -d .* </code></pre> <p>fyi</p> <pre><code> -d, --directory list directories themselves, not their contents </code></pre> <p>if your ls is not alias of other command, the output of above <code>ls -d .*</code> will output files/dirs in same line. If you want to have them each in ... | 58, 390, 3589 | linux, ls, shell | <h1>How to list only the dot files and dot folder names (without the content in them)</h1>
<p>I want to list only the files and folders that are hidden (starting with dot). When I use the command</p>
<pre><code>ls .??*
</code></pre>
<p>I get the output</p>
<pre><code>.gitignore
.git:
COMMIT_EDITMSG FETCH_HEAD H... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,335 | bash | # How to list only the dot files and dot folder names (without the content in them)
I want to list only the files and folders that are hidden (starting with dot). When I use the command
```
ls .??*
```
I get the output
```
.gitignore
.git:
COMMIT_EDITMSG FETCH_HEAD HEAD ORIG_HEAD branches ... | try:
```
ls -d .*
```
fyi
```
-d, --directory
list directories themselves, not their contents
```
if your ls is not alias of other command, the output of above `ls -d .*` will output files/dirs in same line. If you want to have them each in its own line:
```
ls -d1 .*
```
if you want colored output:
... |
21822054 | How to force os.system() to use bash instead of shell | 9 | 2014-02-17 06:17:15 | <p>I've tried what's told in <a href="https://stackoverflow.com/questions/20906073/how-to-force-bin-bash-interpreter-for-oneliners">How to force /bin/bash interpreter for oneliners</a></p>
<p>By doing </p>
<pre><code>os.system('GREPDB="my command"')
os.system('/bin/bash -c \'$GREPDB\'')
</code></pre>
<p>However no l... | 38,605 | 2,453,153 | 2018-09-13 08:39:39 | 21,822,142 | 15 | 2014-02-17 06:23:50 | 2,225,682 | 2014-02-17 06:40:14 | https://stackoverflow.com/q/21822054 | https://stackoverflow.com/a/21822142 | <p>Both commands are executed in different subshells.</p>
<p>Setting variables in the first <code>system</code> call does not affect the second <code>system</code> call. </p>
<p>You need to put two command in one string (combining them with <code>;</code>).</p>
<pre><code>>>> import os
>>> os.syste... | <p>Both commands are executed in different subshells.</p> <p>Setting variables in the first <code>system</code> call does not affect the second <code>system</code> call. </p> <p>You need to put two command in one string (combining them with <code>;</code>).</p> <pre><code>>>> import os >>> os.syste... | 16, 387, 19575 | bash, python, python-2.4 | <h1>How to force os.system() to use bash instead of shell</h1>
<p>I've tried what's told in <a href="https://stackoverflow.com/questions/20906073/how-to-force-bin-bash-interpreter-for-oneliners">How to force /bin/bash interpreter for oneliners</a></p>
<p>By doing </p>
<pre><code>os.system('GREPDB="my command"')
os.sy... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,336 | bash | # How to force os.system() to use bash instead of shell
I've tried what's told in [How to force /bin/bash interpreter for oneliners](https://stackoverflow.com/questions/20906073/how-to-force-bin-bash-interpreter-for-oneliners)
By doing
```
os.system('GREPDB="my command"')
os.system('/bin/bash -c \'$GREPDB\'')
```
H... | Both commands are executed in different subshells.
Setting variables in the first `system` call does not affect the second `system` call.
You need to put two command in one string (combining them with `;`).
```
>>> import os
>>> os.system('GREPDB="echo 123"; /bin/bash -c "$GREPDB"')
123
0
```
**NOTE** You need to u... |
21435002 | In a PowerShell script, is it possible to tell whether a default parameter value is being used? | 9 | 2014-01-29 15:09:11 | <p>Lets say I have a simple script with one parameter, which has a default value:</p>
<pre><code>param(
[string] $logOutput = "C:\SomeFolder\File.txt"
)
# Script...
</code></pre>
<p>And lets say a user runs the script like so:</p>
<pre><code>PS C:\> .\MyScript.ps1 -logOutput "C:\SomeFolder\File.txt"
</code></... | 3,995 | 1,169,092 | 2014-01-30 14:34:19 | 21,443,987 | 15 | 2014-01-29 22:25:12 | 2,797,457 | 2014-01-29 22:25:12 | https://stackoverflow.com/q/21435002 | https://stackoverflow.com/a/21443987 | <p>The simplest way to tell if a parameter was specified or not when you have a default is to look at $PSBoundParameters. For example:</p>
<pre><code>if ($PSBoundParameters.ContainsKey('LogPath')) {
# User specified -LogPath
} else {
# User did not specify -LogPath
}
</code></pre>
| <p>The simplest way to tell if a parameter was specified or not when you have a default is to look at $PSBoundParameters. For example:</p> <pre><code>if ($PSBoundParameters.ContainsKey('LogPath')) { # User specified -LogPath } else { # User did not specify -LogPath } </code></pre> | 526 | powershell | <h1>In a PowerShell script, is it possible to tell whether a default parameter value is being used?</h1>
<p>Lets say I have a simple script with one parameter, which has a default value:</p>
<pre><code>param(
[string] $logOutput = "C:\SomeFolder\File.txt"
)
# Script...
</code></pre>
<p>And lets say a user runs th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,337 | bash | # In a PowerShell script, is it possible to tell whether a default parameter value is being used?
Lets say I have a simple script with one parameter, which has a default value:
```
param(
[string] $logOutput = "C:\SomeFolder\File.txt"
)
# Script...
```
And lets say a user runs the script like so:
```
PS C:\> .\... | The simplest way to tell if a parameter was specified or not when you have a default is to look at $PSBoundParameters. For example:
```
if ($PSBoundParameters.ContainsKey('LogPath')) {
# User specified -LogPath
} else {
# User did not specify -LogPath
}
``` |
20394840 | How to set a PNG file in a Gnome Shell extension for St.Icon | 9 | 2013-12-05 08:21:35 | <p>My Gnome Shell extension has a folder 'icons' and there is an icon file called 'MyIcon.png' inside. I want to take it as a parameter to an St.Icon object.</p>
<pre><code>let icon = new St.Icon({ /* I need what to code here*/ });
</code></pre>
<p>Thanks for any help.</p>
<p>Selcuk.</p>
| 4,077 | 1,818,122 | 2019-04-21 16:46:42 | 21,104,282 | 15 | 2014-01-14 00:57:20 | 3,166,598 | 2019-04-21 16:46:42 | https://stackoverflow.com/q/20394840 | https://stackoverflow.com/a/21104282 | <p>Here is a solution for GnomeShell v3.8.4:</p>
<pre><code>const St = imports.gi.St;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Gio = imports.gi.Gio;
let gicon = Gio.icon_new_for_string(Me.path + "/icons/my_icon.png");
icon = new St.Icon({ gicon });
</code></pre>
| <p>Here is a solution for GnomeShell v3.8.4:</p> <pre><code>const St = imports.gi.St; const Me = imports.misc.extensionUtils.getCurrentExtension(); const Gio = imports.gi.Gio; let gicon = Gio.icon_new_for_string(Me.path + "/icons/my_icon.png"); icon = new St.Icon({ gicon }); </code></pre> | 3294, 68385, 78339 | gnome, gnome-shell, gnome-shell-extensions | <h1>How to set a PNG file in a Gnome Shell extension for St.Icon</h1>
<p>My Gnome Shell extension has a folder 'icons' and there is an icon file called 'MyIcon.png' inside. I want to take it as a parameter to an St.Icon object.</p>
<pre><code>let icon = new St.Icon({ /* I need what to code here*/ });
</code></pre>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,338 | bash | # How to set a PNG file in a Gnome Shell extension for St.Icon
My Gnome Shell extension has a folder 'icons' and there is an icon file called 'MyIcon.png' inside. I want to take it as a parameter to an St.Icon object.
```
let icon = new St.Icon({ /* I need what to code here*/ });
```
Thanks for any help.
Selcuk. | Here is a solution for GnomeShell v3.8.4:
```
const St = imports.gi.St;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Gio = imports.gi.Gio;
let gicon = Gio.icon_new_for_string(Me.path + "/icons/my_icon.png");
icon = new St.Icon({ gicon });
``` |
20553916 | syntax error near unexpected token `&' (using "|&") | 9 | 2013-12-12 20:47:39 | <p>I have syntax error near unexpected token <code>&</code> in next :
in bash scripts its'go like this :</p>
<pre><code>#!/bin/bash
var1=`(/usr/bin/time cdifonline -CD 186821 -ALL > /dev/null)|& grep real|awk '{print $2}'`
</code></pre>
<p>when i issue this command on cli i get good output, problem is whe... | 27,455 | 3,097,093 | 2015-10-28 07:16:48 | 20,554,395 | 15 | 2013-12-12 21:14:58 | 827,263 | 2013-12-13 16:08:54 | https://stackoverflow.com/q/20553916 | https://stackoverflow.com/a/20554395 | <p>You can use the sequence <code>|&</code> to pipe both stdout and stderr from one process to another.</p>
<p>You cannot have a space between the <code>|</code> and the <code>&</code>. (csh and tcsh allow a space; bash does not.) I suspect you happen to be typing it without the space when you run the command ... | <p>You can use the sequence <code>|&</code> to pipe both stdout and stderr from one process to another.</p> <p>You cannot have a space between the <code>|</code> and the <code>&</code>. (csh and tcsh allow a space; bash does not.) I suspect you happen to be typing it without the space when you run the command ... | 387, 390, 990 | awk, bash, shell | <h1>syntax error near unexpected token `&' (using "|&")</h1>
<p>I have syntax error near unexpected token <code>&</code> in next :
in bash scripts its'go like this :</p>
<pre><code>#!/bin/bash
var1=`(/usr/bin/time cdifonline -CD 186821 -ALL > /dev/null)|& grep real|awk '{print $2}'`
</code></pre>
<p>when ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,339 | bash | # syntax error near unexpected token `&' (using "|&")
I have syntax error near unexpected token `&` in next :
in bash scripts its'go like this :
```
#!/bin/bash
var1=`(/usr/bin/time cdifonline -CD 186821 -ALL > /dev/null)|& grep real|awk '{print $2}'`
```
when i issue this command on cli i get good output, problem i... | You can use the sequence `|&` to pipe both stdout and stderr from one process to another.
You cannot have a space between the `|` and the `&`. (csh and tcsh allow a space; bash does not.) I suspect you happen to be typing it without the space when you run the command interactively; the syntax is the same either way.
... |
20069840 | Can hard links get broken? | 9 | 2013-11-19 11:07:23 | <p>I have the feeling that from time to time my hard links get broken.</p>
<p>I use to synchronize a couple of copies by creating links via, e.g.: </p>
<pre><code>link ~/work/genDocs/bibs/SKM.bib SKM.bib
</code></pre>
<p>Once a while I recognize that a synchronization hasn't taken place and I "renew" the link. Perso... | 1,855 | 1,820,962 | 2013-11-19 14:46:59 | 20,070,006 | 15 | 2013-11-19 11:15:22 | 1,115,979 | 2013-11-19 11:15:22 | https://stackoverflow.com/q/20069840 | https://stackoverflow.com/a/20070006 | <p>This can happen if the original file (<code>~/work/genDocs/bibs/SKM.bib</code>) is recreated instead of being modified in-place. A new inode will be created, but your link will still point to the old inode. You can fix the issue by creating symbolic links with <code>ln -s</code> instead of hard links with <code>link... | <p>This can happen if the original file (<code>~/work/genDocs/bibs/SKM.bib</code>) is recreated instead of being modified in-place. A new inode will be created, but your link will still point to the old inode. You can fix the issue by creating symbolic links with <code>ln -s</code> instead of hard links with <code>link... | 34, 119, 387 | bash, git, unix | <h1>Can hard links get broken?</h1>
<p>I have the feeling that from time to time my hard links get broken.</p>
<p>I use to synchronize a couple of copies by creating links via, e.g.: </p>
<pre><code>link ~/work/genDocs/bibs/SKM.bib SKM.bib
</code></pre>
<p>Once a while I recognize that a synchronization hasn't taken... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,340 | bash | # Can hard links get broken?
I have the feeling that from time to time my hard links get broken.
I use to synchronize a couple of copies by creating links via, e.g.:
```
link ~/work/genDocs/bibs/SKM.bib SKM.bib
```
Once a while I recognize that a synchronization hasn't taken place and I "renew" the link. Personally... | This can happen if the original file (`~/work/genDocs/bibs/SKM.bib`) is recreated instead of being modified in-place. A new inode will be created, but your link will still point to the old inode. You can fix the issue by creating symbolic links with `ln -s` instead of hard links with `link`. See [What is the difference... |
18777833 | Matching newlines in regular expression with powershell | 9 | 2013-09-13 03:29:50 | <p>I have some data that looks like this:</p>
<pre><code>:setvar DatabaseName "CI_1814903104"
:setvar DefaultFilePrefix "CI_1814903104"
--etc.
GO
</code></pre>
<p>I wish to replace all sql cmd variable lines (lines that start with :setvar) with an empty string such that the data looks like this:</p>
<pre><code>... | 31,799 | 933,526 | 2013-09-13 04:16:46 | 18,777,938 | 15 | 2013-09-13 03:43:18 | 775,544 | 2013-09-13 04:16:46 | https://stackoverflow.com/q/18777833 | https://stackoverflow.com/a/18777938 | <p>This assumes that your data is being read in from some file. Depending on how you are reading in your data, you may have a collection of strings instead of a single string. </p>
<pre><code>PS C:\> $script = Get-Content data.txt
# Get-Content returns each line as a string object in an Object[].
PS C:\> $scri... | <p>This assumes that your data is being read in from some file. Depending on how you are reading in your data, you may have a collection of strings instead of a single string. </p> <pre><code>PS C:\> $script = Get-Content data.txt # Get-Content returns each line as a string object in an Object[]. PS C:\> $scri... | 18, 526 | powershell, regex | <h1>Matching newlines in regular expression with powershell</h1>
<p>I have some data that looks like this:</p>
<pre><code>:setvar DatabaseName "CI_1814903104"
:setvar DefaultFilePrefix "CI_1814903104"
--etc.
GO
</code></pre>
<p>I wish to replace all sql cmd variable lines (lines that start with :setvar) with an ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,341 | bash | # Matching newlines in regular expression with powershell
I have some data that looks like this:
```
:setvar DatabaseName "CI_1814903104"
:setvar DefaultFilePrefix "CI_1814903104"
--etc.
GO
```
I wish to replace all sql cmd variable lines (lines that start with :setvar) with an empty string such that the data l... | This assumes that your data is being read in from some file. Depending on how you are reading in your data, you may have a collection of strings instead of a single string.
```
PS C:\> $script = Get-Content data.txt
# Get-Content returns each line as a string object in an Object[].
PS C:\> $script.GetType()
IsPublic... |
18569518 | Pass a function (with arguments) as a parameter in PowerShell | 9 | 2013-09-02 09:13:25 | <p>I've been successfully passing no-argument functions around in PowerShell using ScriptBlocks. However, I can't get this to work if the function has arguments. Is there a way to do this in PowerShell? (v2 preferably)</p>
<pre><code>Function Add([int] $x, [int] $y)
{
return $x + $y
}
Function Apply([scriptblock... | 11,257 | 738,851 | 2014-12-16 21:34:26 | 18,570,332 | 15 | 2013-09-02 09:55:16 | 738,851 | 2013-09-02 09:55:16 | https://stackoverflow.com/q/18569518 | https://stackoverflow.com/a/18570332 | <p>Ok, I found the answer <a href="https://stackoverflow.com/q/8448808/738851">here</a>:</p>
<p>I wanted <code>${function:Add}</code> rather than <code>{ Add }</code> in the call to <code>Apply</code>.</p>
| <p>Ok, I found the answer <a href="https://stackoverflow.com/q/8448808/738851">here</a>:</p> <p>I wanted <code>${function:Add}</code> rather than <code>{ Add }</code> in the call to <code>Apply</code>.</p> | 526, 2556, 24067, 38126 | first-class-functions, functional-programming, powershell, powershell-2.0 | <h1>Pass a function (with arguments) as a parameter in PowerShell</h1>
<p>I've been successfully passing no-argument functions around in PowerShell using ScriptBlocks. However, I can't get this to work if the function has arguments. Is there a way to do this in PowerShell? (v2 preferably)</p>
<pre><code>Function Add([... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,342 | bash | # Pass a function (with arguments) as a parameter in PowerShell
I've been successfully passing no-argument functions around in PowerShell using ScriptBlocks. However, I can't get this to work if the function has arguments. Is there a way to do this in PowerShell? (v2 preferably)
```
Function Add([int] $x, [int] $y) ... | Ok, I found the answer [here](https://stackoverflow.com/q/8448808/738851):
I wanted `${function:Add}` rather than `{ Add }` in the call to `Apply`. |
17777014 | Signing an F# Assembly (Strong name component) | 9 | 2013-07-21 21:16:25 | <p>I found this article on CodeProject:
<a href="http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus">http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus</a></p>
<p>and thought it would be nice to give it a try, but in F#. So I came up with the following ... | 1,446 | 2,545,980 | 2015-11-03 18:38:53 | 18,164,592 | 15 | 2013-08-10 17:35:39 | 323,316 | 2013-08-10 17:35:39 | https://stackoverflow.com/q/17777014 | https://stackoverflow.com/a/18164592 | <p>One way to sign an F# assembly is via the <code>AssemblyFileKeyAttribute</code> attribute.</p>
<p>Create a new module and in it put:</p>
<pre><code>module AssemblyProperties
open System
open System.Reflection;
open System.Runtime.InteropServices;
[<assembly:AssemblyKeyFileAttribute("MyKey.snk")>]
do()
</c... | <p>One way to sign an F# assembly is via the <code>AssemblyFileKeyAttribute</code> attribute.</p> <p>Create a new module and in it put:</p> <pre><code>module AssemblyProperties open System open System.Reflection; open System.Runtime.InteropServices; [<assembly:AssemblyKeyFileAttribute("MyKey.snk")>] do() </c... | 162, 1198, 1515, 9231, 21947 | code-translation, com, f#, shell-extensions, strongname | <h1>Signing an F# Assembly (Strong name component)</h1>
<p>I found this article on CodeProject:
<a href="http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus">http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus</a></p>
<p>and thought it would be nice to gi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,343 | bash | # Signing an F# Assembly (Strong name component)
I found this article on CodeProject:
<http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus>
and thought it would be nice to give it a try, but in F#. So I came up with the following code:
```
open System
open System.IO
open System.Text
o... | One way to sign an F# assembly is via the `AssemblyFileKeyAttribute` attribute.
Create a new module and in it put:
```
module AssemblyProperties
open System
open System.Reflection;
open System.Runtime.InteropServices;
[<assembly:AssemblyKeyFileAttribute("MyKey.snk")>]
do()
```
Where `"MyKey.snk"` is the path to y... |
17614643 | How do I get a bash script working on FreeBSD, OpenBSD and Linux without modifying it? | 9 | 2013-07-12 12:12:21 | <p>Sorry, the headline might be a bit irritating, but I didn't know anything better. Anyway, I want a bash script to work on FreeBSD, OpenBSD and Linux without modifying it, but bash isn't located at the same place in Linux and BSD.</p>
<p>So, if I write <code>#!/bin/bash</code> then it won't work on BSD, because the ... | 6,491 | 1,392,778 | 2013-10-29 21:38:28 | 17,614,713 | 15 | 2013-07-12 12:16:15 | 1,630,171 | 2013-07-12 12:16:15 | https://stackoverflow.com/q/17614643 | https://stackoverflow.com/a/17614713 | <p>Using <code>env</code> in the shebang (<code>#!/usr/bin/env bash</code>) should make the script OS agnostic.</p>
| <p>Using <code>env</code> in the shebang (<code>#!/usr/bin/env bash</code>) should make the script OS agnostic.</p> | 58, 387, 1313, 2796 | bash, freebsd, linux, openbsd | <h1>How do I get a bash script working on FreeBSD, OpenBSD and Linux without modifying it?</h1>
<p>Sorry, the headline might be a bit irritating, but I didn't know anything better. Anyway, I want a bash script to work on FreeBSD, OpenBSD and Linux without modifying it, but bash isn't located at the same place in Linux ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,344 | bash | # How do I get a bash script working on FreeBSD, OpenBSD and Linux without modifying it?
Sorry, the headline might be a bit irritating, but I didn't know anything better. Anyway, I want a bash script to work on FreeBSD, OpenBSD and Linux without modifying it, but bash isn't located at the same place in Linux and BSD.
... | Using `env` in the shebang (`#!/usr/bin/env bash`) should make the script OS agnostic. |
17071584 | How to use Jenkins Environment variables in python script | 9 | 2013-06-12 17:24:10 | <p>so I have a bash script in which I use the environment variables from Jenkins
for example:
QUALIFIER=<code>echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12</code></p>
<p>Essentially I'm taking the build id, along with job name to determine which script to call from my main script. I want to use python instead so I w... | 40,147 | 2,273,132 | 2020-11-20 05:38:22 | 17,075,691 | 15 | 2013-06-12 21:29:42 | 48,140 | 2013-06-13 19:51:30 | https://stackoverflow.com/q/17071584 | https://stackoverflow.com/a/17075691 | <p>That's what you need if I understand you correctly:</p>
<pre><code>QUALIFIER="$(echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12)"
export QUALIFIER
python my_script.py
</code></pre>
<p>And in your Python script:</p>
<pre><code>import os
qualifier = os.environ['QUALIFIER']
</code></pre>
<p>or without the shell part:... | <p>That's what you need if I understand you correctly:</p> <pre><code>QUALIFIER="$(echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12)" export QUALIFIER python my_script.py </code></pre> <p>And in your Python script:</p> <pre><code>import os qualifier = os.environ['QUALIFIER'] </code></pre> <p>or without the shell part:... | 16, 387, 9013, 64999 | bash, environment-variables, jenkins, python | <h1>How to use Jenkins Environment variables in python script</h1>
<p>so I have a bash script in which I use the environment variables from Jenkins
for example:
QUALIFIER=<code>echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12</code></p>
<p>Essentially I'm taking the build id, along with job name to determine which scri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,345 | bash | # How to use Jenkins Environment variables in python script
so I have a bash script in which I use the environment variables from Jenkins
for example:
QUALIFIER=`echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12`
Essentially I'm taking the build id, along with job name to determine which script to call from my main scrip... | That's what you need if I understand you correctly:
```
QUALIFIER="$(echo $BUILD_ID | sed "s/[-_]//g" | cut -c1-12)"
export QUALIFIER
python my_script.py
```
And in your Python script:
```
import os
qualifier = os.environ['QUALIFIER']
```
or without the shell part:
```
import os
import re
qualifier = re.sub(r'[-_]... |
15308226 | How to type ASCII code "00" and "01" in linux bash? | 9 | 2013-03-09 07:03:46 | <p>I have program which looks like this:</p>
<pre><code>/* buf_overflow.c */
#include <stdio.h>
int main(){
char buf[4];
char exploit_buf[4];
fgets(buf, 4, stdin);
gets(exploit_buf);
printf("exploit_buf: %s\n", exploit_buf);
return 0;
}
</code></pre>
<p>I'm going to use the vulnerability... | 41,454 | 1,408,347 | 2017-05-24 18:53:54 | 15,308,250 | 15 | 2013-03-09 07:07:15 | 1,204,143 | 2013-03-09 10:09:49 | https://stackoverflow.com/q/15308226 | https://stackoverflow.com/a/15308250 | <p>You can use <code>echo -e</code>:</p>
<pre><code>$ echo -ne 'AAAAAAAA\x01\x00\x00\x00' | python -c 'import sys; print repr(sys.stdin.read())'
'AAAAAAAA\x01\x00\x00\x00'
</code></pre>
<p><code>-e</code> allows <code>echo</code> to interpret escape codes, and <code>-n</code> suppresses the trailing newline.</p>
<p>... | <p>You can use <code>echo -e</code>:</p> <pre><code>$ echo -ne 'AAAAAAAA\x01\x00\x00\x00' | python -c 'import sys; print repr(sys.stdin.read())' 'AAAAAAAA\x01\x00\x00\x00' </code></pre> <p><code>-e</code> allows <code>echo</code> to interpret escape codes, and <code>-n</code> suppresses the trailing newline.</p> <p>... | 387, 1391, 1843 | ascii, bash, hex | <h1>How to type ASCII code "00" and "01" in linux bash?</h1>
<p>I have program which looks like this:</p>
<pre><code>/* buf_overflow.c */
#include <stdio.h>
int main(){
char buf[4];
char exploit_buf[4];
fgets(buf, 4, stdin);
gets(exploit_buf);
printf("exploit_buf: %s\n", exploit_buf);
ret... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,346 | bash | # How to type ASCII code "00" and "01" in linux bash?
I have program which looks like this:
```
/* buf_overflow.c */
#include <stdio.h>
int main(){
char buf[4];
char exploit_buf[4];
fgets(buf, 4, stdin);
gets(exploit_buf);
printf("exploit_buf: %s\n", exploit_buf);
return 0;
}
```
I'm going to... | You can use `echo -e`:
```
$ echo -ne 'AAAAAAAA\x01\x00\x00\x00' | python -c 'import sys; print repr(sys.stdin.read())'
'AAAAAAAA\x01\x00\x00\x00'
```
`-e` allows `echo` to interpret escape codes, and `-n` suppresses the trailing newline.
Note that the Python program prints out the string representation of what it r... |
15002937 | How to stop making tmux auto setting RBENV_VERSION | 9 | 2013-02-21 13:02:21 | <p>tmux is auto setting RBENV_VERSION when I start tmux...</p>
<p>Anyone know how to stop it?</p>
<p>Because it auto sets it, I need to do </p>
<p><code>$ export RBENV_VERSION</code></p>
<p>to unset it and make .ruby-version work. Thx.</p>
| 1,536 | 1,446,551 | 2023-08-31 16:44:31 | 15,021,934 | 15 | 2013-02-22 10:25:24 | 193,688 | 2013-02-22 10:25:24 | https://stackoverflow.com/q/15002937 | https://stackoverflow.com/a/15021934 | <p><em>tmux</em> itself will never set (or unset) RBENV_VERSION of its own accord. You have some bit of configuration that is causing this.</p>
<p>My guess is that RBENV_VERSION was set when you started your <em>tmux</em> server and that is is now part of the <em>tmux</em> “global environment” (the base environment in... | <p><em>tmux</em> itself will never set (or unset) RBENV_VERSION of its own accord. You have some bit of configuration that is causing this.</p> <p>My guess is that RBENV_VERSION was set when you started your <em>tmux</em> server and that is is now part of the <em>tmux</em> “global environment” (the base environment in... | 12, 390, 60238, 74013 | rbenv, ruby, shell, tmux | <h1>How to stop making tmux auto setting RBENV_VERSION</h1>
<p>tmux is auto setting RBENV_VERSION when I start tmux...</p>
<p>Anyone know how to stop it?</p>
<p>Because it auto sets it, I need to do </p>
<p><code>$ export RBENV_VERSION</code></p>
<p>to unset it and make .ruby-version work. Thx.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,347 | bash | # How to stop making tmux auto setting RBENV_VERSION
tmux is auto setting RBENV_VERSION when I start tmux...
Anyone know how to stop it?
Because it auto sets it, I need to do
`$ export RBENV_VERSION`
to unset it and make .ruby-version work. Thx. | *tmux* itself will never set (or unset) RBENV_VERSION of its own accord. You have some bit of configuration that is causing this.
My guess is that RBENV_VERSION was set when you started your *tmux* server and that is is now part of the *tmux* “global environment” (the base environment inherited by all the processes st... |
13365553 | Setting an argument with bash | 9 | 2012-11-13 17:22:55 | <p>I frequently run a simple bash command:</p>
<pre><code>rpm -Uvh --define "_transaction_color 3" myPackage.rpm
</code></pre>
<p>which works properly.</p>
<p>But now I'm trying to script it into a bash file, and make it more flexible:</p>
<pre><code>#!/bin/bash
INSTALL_CMD=rpm
INSTALL_OPT="-Uvh --define '_transact... | 2,762 | 34,824 | 2018-03-02 03:00:42 | 13,365,648 | 15 | 2012-11-13 17:28:40 | 1,491,895 | 2016-04-07 12:47:54 | https://stackoverflow.com/q/13365553 | https://stackoverflow.com/a/13365648 | <p>The problem is that quotes are not processed after variable substitution. So it looks like you're trying to define a macro named <code>'_transaction_color</code>.</p>
<p>Try using an array:</p>
<pre><code>INSTALL_OPT=(-Uvh --define '_transaction_color 3')
</code></pre>
<p>then:</p>
<pre><code>"$INSTALL_CMD" "${I... | <p>The problem is that quotes are not processed after variable substitution. So it looks like you're trying to define a macro named <code>'_transaction_color</code>.</p> <p>Try using an array:</p> <pre><code>INSTALL_OPT=(-Uvh --define '_transaction_color 3') </code></pre> <p>then:</p> <pre><code>"$INSTALL_CMD" "${I... | 34, 58, 387 | bash, linux, unix | <h1>Setting an argument with bash</h1>
<p>I frequently run a simple bash command:</p>
<pre><code>rpm -Uvh --define "_transaction_color 3" myPackage.rpm
</code></pre>
<p>which works properly.</p>
<p>But now I'm trying to script it into a bash file, and make it more flexible:</p>
<pre><code>#!/bin/bash
INSTALL_CMD=rp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,348 | bash | # Setting an argument with bash
I frequently run a simple bash command:
```
rpm -Uvh --define "_transaction_color 3" myPackage.rpm
```
which works properly.
But now I'm trying to script it into a bash file, and make it more flexible:
```
#!/bin/bash
INSTALL_CMD=rpm
INSTALL_OPT="-Uvh --define '_transaction_color 3'... | The problem is that quotes are not processed after variable substitution. So it looks like you're trying to define a macro named `'_transaction_color`.
Try using an array:
```
INSTALL_OPT=(-Uvh --define '_transaction_color 3')
```
then:
```
"$INSTALL_CMD" "${INSTALL_OPT[@]}" myPackage.rpm
```
It's important to put... |
11146264 | Get current computer's distinguished name in powershell without using the ActiveDirectory module | 9 | 2012-06-21 20:30:58 | <p>I have a script that I need to find the full Distinguished name (<code>CN=MyComputer, OU=Computers, DC=vw, DC=local</code>) of the computer it is running on, however I can not guarantee that the <code>ActiveDirectory</code> module will be available on all computers that this script will be run on. Is there a way to ... | 65,714 | 80,274 | 2024-07-05 11:09:22 | 11,146,959 | 15 | 2012-06-21 21:22:32 | 9,833 | 2012-06-21 21:22:32 | https://stackoverflow.com/q/11146264 | https://stackoverflow.com/a/11146959 | <p>Try this (requires v2):</p>
<pre><code>$filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))"
([adsisearcher]$filter).FindOne().Properties.distinguishedname
</code></pre>
| <p>Try this (requires v2):</p> <pre><code>$filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))" ([adsisearcher]$filter).FindOne().Properties.distinguishedname </code></pre> | 526, 10401 | active-directory, powershell | <h1>Get current computer's distinguished name in powershell without using the ActiveDirectory module</h1>
<p>I have a script that I need to find the full Distinguished name (<code>CN=MyComputer, OU=Computers, DC=vw, DC=local</code>) of the computer it is running on, however I can not guarantee that the <code>ActiveDire... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,349 | bash | # Get current computer's distinguished name in powershell without using the ActiveDirectory module
I have a script that I need to find the full Distinguished name (`CN=MyComputer, OU=Computers, DC=vw, DC=local`) of the computer it is running on, however I can not guarantee that the `ActiveDirectory` module will be ava... | Try this (requires v2):
```
$filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))"
([adsisearcher]$filter).FindOne().Properties.distinguishedname
``` |
11131318 | How to use Bash script variables in Expect conditional statements | 9 | 2012-06-21 04:01:15 | <p>I am writing a Bash script and using Expect to do sftp. Now in the Expect block I want to access a Bash variable in a conditional statement. But, I am unable to do so. How can do this?</p>
<p>Also, the execution of this script is controlled from a C program and I want redirect the output to a log file (which again i... | 54,321 | 1,222,555 | 2020-06-24 18:33:48 | 11,131,886 | 15 | 2012-06-21 05:17:06 | 459,745 | 2020-06-24 18:30:52 | https://stackoverflow.com/q/11131318 | https://stackoverflow.com/a/11131886 | <p>You don't need to use Bash. Expect can handle all that:</p>
<pre><code>#!/usr/bin/expect
set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set action [lindex $argv 3]
set path [lindex $argv 4]
puts "Starting...."
puts "\"$action\""
spawn sftp $user@$host
e... | <p>You don't need to use Bash. Expect can handle all that:</p> <pre><code>#!/usr/bin/expect set host [lindex $argv 0] set user [lindex $argv 1] set pass [lindex $argv 2] set action [lindex $argv 3] set path [lindex $argv 4] puts "Starting...." puts "\"$action\"" spawn sftp $user@$host e... | 387, 9048 | bash, expect | <h1>How to use Bash script variables in Expect conditional statements</h1>
<p>I am writing a Bash script and using Expect to do sftp. Now in the Expect block I want to access a Bash variable in a conditional statement. But, I am unable to do so. How can do this?</p>
<p>Also, the execution of this script is controlled f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,350 | bash | # How to use Bash script variables in Expect conditional statements
I am writing a Bash script and using Expect to do sftp. Now in the Expect block I want to access a Bash variable in a conditional statement. But, I am unable to do so. How can do this?
Also, the execution of this script is controlled from a C program... | You don't need to use Bash. Expect can handle all that:
```
#!/usr/bin/expect
set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set action [lindex $argv 3]
set path [lindex $argv 4]
puts "Starting...."
puts "\"$action\""
spawn sftp $user@$host
expect "password:"
send "$pass\r"
expect"sf... |
11035180 | count number of tab characters in linux | 9 | 2012-06-14 14:23:42 | <p>I want to count the numbers of <code>hard tab characters</code> in my documents in unix shell. </p>
<p>How can I do it?</p>
<p>I tried something like </p>
<p><code>grep -c \t foo</code></p>
<p>but it gives counts of t in file foo.</p>
| 11,665 | 730,313 | 2012-06-14 21:49:47 | 11,035,959 | 15 | 2012-06-14 15:02:59 | 140,750 | 2012-06-14 15:02:59 | https://stackoverflow.com/q/11035180 | https://stackoverflow.com/a/11035959 | <p>Use tr to discard everything except tabs, and then count:</p>
<pre><code>< input-file tr -dc \\t | wc -c
</code></pre>
| <p>Use tr to discard everything except tabs, and then count:</p> <pre><code>< input-file tr -dc \\t | wc -c </code></pre> | 34, 387, 1271, 2829 | bash, csh, grep, unix | <h1>count number of tab characters in linux</h1>
<p>I want to count the numbers of <code>hard tab characters</code> in my documents in unix shell. </p>
<p>How can I do it?</p>
<p>I tried something like </p>
<p><code>grep -c \t foo</code></p>
<p>but it gives counts of t in file foo.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,351 | bash | # count number of tab characters in linux
I want to count the numbers of `hard tab characters` in my documents in unix shell.
How can I do it?
I tried something like
`grep -c \t foo`
but it gives counts of t in file foo. | Use tr to discard everything except tabs, and then count:
```
< input-file tr -dc \\t | wc -c
``` |
10794564 | How to pipe help content to select-string in PowerShell? | 9 | 2012-05-29 07:07:14 | <p>I simply want to find specific part in the help about some command:</p>
<pre class="lang-sh prettyprint-override"><code>help rd | select-string -pattern 'cmd'
</code></pre>
<p>but I get nothing but errors. What is wrong?</p>
| 14,643 | 587,467 | 2014-07-17 08:38:43 | 10,795,647 | 15 | 2012-05-29 08:33:10 | 9,833 | 2012-05-29 13:03:59 | https://stackoverflow.com/q/10794564 | https://stackoverflow.com/a/10795647 | <p>In the ISE, the help function emits MamlCommandHelpInfo objects. Internally, the help function pipes the output of Get-Help to the 'more' utility (enables help paging in the console). In the ISE, 'more' is a simply writes to the pipeline whatever it gets.</p>
<p>To work around this, convert the output to strings. T... | <p>In the ISE, the help function emits MamlCommandHelpInfo objects. Internally, the help function pipes the output of Get-Help to the 'more' utility (enables help paging in the console). In the ISE, 'more' is a simply writes to the pipeline whatever it gets.</p> <p>To work around this, convert the output to strings. T... | 526 | powershell | <h1>How to pipe help content to select-string in PowerShell?</h1>
<p>I simply want to find specific part in the help about some command:</p>
<pre class="lang-sh prettyprint-override"><code>help rd | select-string -pattern 'cmd'
</code></pre>
<p>but I get nothing but errors. What is wrong?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,352 | bash | # How to pipe help content to select-string in PowerShell?
I simply want to find specific part in the help about some command:
```
help rd | select-string -pattern 'cmd'
```
but I get nothing but errors. What is wrong? | In the ISE, the help function emits MamlCommandHelpInfo objects. Internally, the help function pipes the output of Get-Help to the 'more' utility (enables help paging in the console). In the ISE, 'more' is a simply writes to the pipeline whatever it gets.
To work around this, convert the output to strings. This will w... |
3102562 | How does one add a secondary verb to a file type in Windows shell? | 9 | 2010-06-23 14:34:45 | <p>The basic idea with Windows shell programming is that you can associate a given file type (extension) with what MS is currently calling a progid (e.g. Company.Type.Ver):</p>
<p>HKCR\.txt
@=Acme.Text.1</p>
<p>HKCR\Acme.Text.1
@=This is the progid for text file associations for Acme</p>
<p>And then Acme Corp ca... | 2,509 | 112,755 | 2012-05-20 13:20:42 | 10,673,760 | 15 | 2012-05-20 13:20:42 | 964,243 | 2012-05-20 13:20:42 | https://stackoverflow.com/q/3102562 | https://stackoverflow.com/a/10673760 | <p>This is possible, and it's very easy to do (once you know where to look). The magic lies in the key <code>HKEY_CLASSES_ROOT\SystemFileAssociations</code>. Here you will find many subkeys named after file extensions. Simply create your desired shell/open/command keys under these.</p>
<p>Here is an example registry f... | <p>This is possible, and it's very easy to do (once you know where to look). The magic lies in the key <code>HKEY_CLASSES_ROOT\SystemFileAssociations</code>. Here you will find many subkeys named after file extensions. Simply create your desired shell/open/command keys under these.</p> <p>Here is an example registry f... | 64, 263, 8123 | registry, windows, windows-shell | <h1>How does one add a secondary verb to a file type in Windows shell?</h1>
<p>The basic idea with Windows shell programming is that you can associate a given file type (extension) with what MS is currently calling a progid (e.g. Company.Type.Ver):</p>
<p>HKCR\.txt
@=Acme.Text.1</p>
<p>HKCR\Acme.Text.1
@=This is ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,353 | bash | # How does one add a secondary verb to a file type in Windows shell?
The basic idea with Windows shell programming is that you can associate a given file type (extension) with what MS is currently calling a progid (e.g. Company.Type.Ver):
HKCR\.txt
@=Acme.Text.1
HKCR\Acme.Text.1
@=This is the progid for text file as... | This is possible, and it's very easy to do (once you know where to look). The magic lies in the key `HKEY_CLASSES_ROOT\SystemFileAssociations`. Here you will find many subkeys named after file extensions. Simply create your desired shell/open/command keys under these.
Here is an example registry file showing the struc... |
9608483 | How to match pattern at the end of line/text | 9 | 2012-03-07 20:22:33 | <p>I am very new to bash. So if this is a pretty basic question, please pardon me.</p>
<p>I am trying to replace file extension '<code>.gzip</code>' with '<code>.gz</code>'.</p>
<p>E.g.:</p>
<pre><code>testfile.xml.gzip => testfile.xml.gz
</code></pre>
<p>Someone has written a script which does this:</p>
<pre><... | 39,403 | 645,226 | 2015-11-19 06:57:42 | 9,608,540 | 15 | 2012-03-07 20:26:31 | 183,066 | 2012-03-07 20:40:05 | https://stackoverflow.com/q/9608483 | https://stackoverflow.com/a/9608540 | <p>Use <code>$</code> to match the end of the line:</p>
<pre><code>FILE=`echo ${FILE} | sed 's/.gz$//g'`
</code></pre>
<p>Anyway, what this command does is remove the trailing <code>.gz</code> extension from the filename, which isn't what you're looking for according to your question. To do that, the answer from dnsm... | <p>Use <code>$</code> to match the end of the line:</p> <pre><code>FILE=`echo ${FILE} | sed 's/.gz$//g'` </code></pre> <p>Anyway, what this command does is remove the trailing <code>.gz</code> extension from the filename, which isn't what you're looking for according to your question. To do that, the answer from dnsm... | 387, 5282 | bash, sed | <h1>How to match pattern at the end of line/text</h1>
<p>I am very new to bash. So if this is a pretty basic question, please pardon me.</p>
<p>I am trying to replace file extension '<code>.gzip</code>' with '<code>.gz</code>'.</p>
<p>E.g.:</p>
<pre><code>testfile.xml.gzip => testfile.xml.gz
</code></pre>
<p>Som... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,354 | bash | # How to match pattern at the end of line/text
I am very new to bash. So if this is a pretty basic question, please pardon me.
I am trying to replace file extension '`.gzip`' with '`.gz`'.
E.g.:
```
testfile.xml.gzip => testfile.xml.gz
```
Someone has written a script which does this:
```
GZIP=`echo ${FILE} | gre... | Use `$` to match the end of the line:
```
FILE=`echo ${FILE} | sed 's/.gz$//g'`
```
Anyway, what this command does is remove the trailing `.gz` extension from the filename, which isn't what you're looking for according to your question. To do that, the answer from dnsmkl is the way to go with `sed`.
Note that since ... |
8643403 | How do I write a shell script that displays SQLite results? | 9 | 2011-12-27 10:06:54 | <p>I have written a script that adds an entry to the SQLite database. Now I want to display the results after adding that entry. Here's my script:</p>
<pre><code>echo 'insert into myTable (Date, Details, Category, Average) values (datetime('\''now'\'','\''localtime'\''), '\'''$1''\'', '\'''$2''\'', '$3');'|sqlite3 /Use... | 23,964 | 1,009,687 | 2024-07-03 06:01:08 | 8,649,732 | 15 | 2011-12-27 22:00:23 | 620,097 | 2024-04-15 17:43:08 | https://stackoverflow.com/q/8643403 | https://stackoverflow.com/a/8649732 | <p>One common way to solve this problem is to use a shell feature called a here document, try this:</p>
<pre><code> sqlite3 /Users/user/Documents/Test/dbName.dba <<EOS
insert into myTable (Date, Details, Category, Average)
values(datetime('now','localtime'), '$1', '$2', '$3');
select &q... | <p>One common way to solve this problem is to use a shell feature called a here document, try this:</p> <pre><code> sqlite3 /Users/user/Documents/Test/dbName.dba <<EOS insert into myTable (Date, Details, Category, Average) values(datetime('now','localtime'), '$1', '$2', '$3'); select &q... | 121, 390 | shell, sqlite | <h1>How do I write a shell script that displays SQLite results?</h1>
<p>I have written a script that adds an entry to the SQLite database. Now I want to display the results after adding that entry. Here's my script:</p>
<pre><code>echo 'insert into myTable (Date, Details, Category, Average) values (datetime('\''now'\''... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,355 | bash | # How do I write a shell script that displays SQLite results?
I have written a script that adds an entry to the SQLite database. Now I want to display the results after adding that entry. Here's my script:
```
echo 'insert into myTable (Date, Details, Category, Average) values (datetime('\''now'\'','\''localtime'\'')... | One common way to solve this problem is to use a shell feature called a here document, try this:
```
sqlite3 /Users/user/Documents/Test/dbName.dba <<EOS
insert into myTable (Date, Details, Category, Average)
values(datetime('now','localtime'), '$1', '$2', '$3');
select "Category1 total = " ... |
7852148 | Function in bash to commit and push in one command | 9 | 2011-10-21 16:04:41 | <p>I try to commit and push in one command, typing something like:</p>
<p><code>gm "This is my commit message"</code></p>
<p>Which would run: </p>
<p><code>git commit -am "This is my commit message" && git push</code></p>
<p>I've tried this function in my <code>.bashrc</code>:</p>
<pre><code>function gm() ... | 10,969 | null | 2016-06-30 13:48:58 | 7,852,202 | 15 | 2011-10-21 16:08:47 | 3,978 | 2011-10-22 16:12:45 | https://stackoverflow.com/q/7852148 | https://stackoverflow.com/a/7852202 | <p>You need quotes around both the place calling the function and the git command.</p>
<pre><code>function gm() {
git commit -am "$1" && git push
}
gm "This is my message"
</code></pre>
<p>An alternative approach is:</p>
<pre><code>function gm() {
git commit -am "$*" && git push
}
gm This... | <p>You need quotes around both the place calling the function and the git command.</p> <pre><code>function gm() { git commit -am "$1" && git push } gm "This is my message" </code></pre> <p>An alternative approach is:</p> <pre><code>function gm() { git commit -am "$*" && git push } gm This... | 119, 387 | bash, git | <h1>Function in bash to commit and push in one command</h1>
<p>I try to commit and push in one command, typing something like:</p>
<p><code>gm "This is my commit message"</code></p>
<p>Which would run: </p>
<p><code>git commit -am "This is my commit message" && git push</code></p>
<p>I've tried this functio... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,356 | bash | # Function in bash to commit and push in one command
I try to commit and push in one command, typing something like:
`gm "This is my commit message"`
Which would run:
`git commit -am "This is my commit message" && git push`
I've tried this function in my `.bashrc`:
```
function gm() {
git commit -am $1 && gi... | You need quotes around both the place calling the function and the git command.
```
function gm() {
git commit -am "$1" && git push
}
gm "This is my message"
```
An alternative approach is:
```
function gm() {
git commit -am "$*" && git push
}
gm This is my message
```
But this will mean that:
```
gm T... |
7482510 | Variable incrementing in bash | 9 | 2011-09-20 08:54:36 | <p>Consider the following script:</p>
<pre><code>#!/bin/bash
num=0
cat file | while read line; do
echo "$line"
lines[$num]="$line"
((num++))
echo "num = $num"
done
echo "end num = $num"
i=0
while [ $i -lt $num ]; do
echo "${lines[$i]}"
((i++))
done
</code></pre>
<p>Normally, it should read ... | 17,960 | 294,813 | 2013-08-14 02:03:52 | 7,482,544 | 15 | 2011-09-20 08:56:51 | 14,860 | 2011-09-20 09:07:39 | https://stackoverflow.com/q/7482510 | https://stackoverflow.com/a/7482544 | <p>Why? It's because this:</p>
<pre><code>cat file | while read line; do
echo "$line"
lines[$num]="$line"
((num++))
echo "num = $num"
done
</code></pre>
<p>runs the <code>while</code> statement in a separate process, with its own environment, not touching the parent environment. You'll find, similarly... | <p>Why? It's because this:</p> <pre><code>cat file | while read line; do echo "$line" lines[$num]="$line" ((num++)) echo "num = $num" done </code></pre> <p>runs the <code>while</code> statement in a separate process, with its own environment, not touching the parent environment. You'll find, similarly... | 58, 276, 387 | bash, linux, variables | <h1>Variable incrementing in bash</h1>
<p>Consider the following script:</p>
<pre><code>#!/bin/bash
num=0
cat file | while read line; do
echo "$line"
lines[$num]="$line"
((num++))
echo "num = $num"
done
echo "end num = $num"
i=0
while [ $i -lt $num ]; do
echo "${lines[$i]}"
((i++))
done
</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,357 | bash | # Variable incrementing in bash
Consider the following script:
```
#!/bin/bash
num=0
cat file | while read line; do
echo "$line"
lines[$num]="$line"
((num++))
echo "num = $num"
done
echo "end num = $num"
i=0
while [ $i -lt $num ]; do
echo "${lines[$i]}"
((i++))
done
```
Normally, it should... | Why? It's because this:
```
cat file | while read line; do
echo "$line"
lines[$num]="$line"
((num++))
echo "num = $num"
done
```
runs the `while` statement in a separate process, with its own environment, not touching the parent environment. You'll find, similarly, that the `lines` array is not there ... |
6527004 | Why does xargs -L yield the right format, while xargs -n doesn't? | 9 | 2011-06-29 20:42:41 | <p>Consider the following:</p>
<pre><code>$ echo index.html* | xargs -L 1 ls -l
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21 index.html.2
-rw-r--r-- 1 zeki zeki 146589 2011-05-05 12:29 index.html.3
$... | 2,925 | 319,845 | 2022-12-11 15:02:51 | 6,527,296 | 15 | 2011-06-29 21:09:08 | 643,977 | 2011-06-29 21:09:08 | https://stackoverflow.com/q/6527004 | https://stackoverflow.com/a/6527296 | <p><code>-L</code> splits by lines; <code>echo</code> doesn't separate its output by lines but by spaces, so a single <code>ls -l</code> is run and that formats all the columns as a group.</p>
<p><code>-n</code> splits by parameters; in the absence of <code>-L</code> or <code>-0</code>, the separator is whitespace (po... | <p><code>-L</code> splits by lines; <code>echo</code> doesn't separate its output by lines but by spaces, so a single <code>ls -l</code> is run and that formats all the columns as a group.</p> <p><code>-n</code> splits by parameters; in the absence of <code>-L</code> or <code>-0</code>, the separator is whitespace (po... | 34, 58, 390, 1084, 10326 | linux, shell, unix, whitespace, xargs | <h1>Why does xargs -L yield the right format, while xargs -n doesn't?</h1>
<p>Consider the following:</p>
<pre><code>$ echo index.html* | xargs -L 1 ls -l
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,358 | bash | # Why does xargs -L yield the right format, while xargs -n doesn't?
Consider the following:
```
$ echo index.html* | xargs -L 1 ls -l
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1
-rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21 index.html.2
-rw-r-... | `-L` splits by lines; `echo` doesn't separate its output by lines but by spaces, so a single `ls -l` is run and that formats all the columns as a group.
`-n` splits by parameters; in the absence of `-L` or `-0`, the separator is whitespace (possibly modified by quoting), so each filename gets its own `ls -l` run and t... |
6255303 | bash piping prevents global variable assignment | 9 | 2011-06-06 16:47:07 | <pre><code>unset v
function f {
v=1
}
f | cat
echo v=$v
f
echo v=$v
</code></pre>
<p>Why does piping (to any command) prevent the first echo command from printing 1? The second echo prints 1. I'm using a bash shell. I can see this by copy/paste or by running this as a script.</p>
| 2,633 | 766,233 | 2011-06-06 20:28:48 | 6,255,356 | 15 | 2011-06-06 16:51:18 | 600,500 | 2011-06-06 20:28:48 | https://stackoverflow.com/q/6255303 | https://stackoverflow.com/a/6255356 | <p>All components of a pipeline (if more than one) are executed in a subshell, and their variable assignments do not persist to the main shell.</p>
<p>The reason for this is that bash does not support real multithreading (with concurrent access to variables), only subprocesses which run in parallel.</p>
<hr>
<p><str... | <p>All components of a pipeline (if more than one) are executed in a subshell, and their variable assignments do not persist to the main shell.</p> <p>The reason for this is that bash does not support real multithreading (with concurrent access to variables), only subprocesses which run in parallel.</p> <hr> <p><str... | 276, 387, 5813 | bash, pipe, variables | <h1>bash piping prevents global variable assignment</h1>
<pre><code>unset v
function f {
v=1
}
f | cat
echo v=$v
f
echo v=$v
</code></pre>
<p>Why does piping (to any command) prevent the first echo command from printing 1? The second echo prints 1. I'm using a bash shell. I can see this by copy/paste or by runni... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,359 | bash | # bash piping prevents global variable assignment
```
unset v
function f {
v=1
}
f | cat
echo v=$v
f
echo v=$v
```
Why does piping (to any command) prevent the first echo command from printing 1? The second echo prints 1. I'm using a bash shell. I can see this by copy/paste or by running this as a script. | All components of a pipeline (if more than one) are executed in a subshell, and their variable assignments do not persist to the main shell.
The reason for this is that bash does not support real multithreading (with concurrent access to variables), only subprocesses which run in parallel.
---
**How to avoid this**:... |
5652986 | PHP sudo in shell_exec | 9 | 2011-04-13 17:11:50 | <p>I want to execute a command as root with shell_exec. Now I know this is dangerous, but believe me, you need to login with MOD_AUTH and have the right privilleges to come to this page. It's secure. How can I get this done?</p>
| 44,794 | 670,979 | 2016-07-07 14:59:36 | 5,711,685 | 15 | 2011-04-19 04:43:02 | null | 2011-04-19 04:49:00 | https://stackoverflow.com/q/5652986 | https://stackoverflow.com/a/5711685 | <p>You could use the latest SVN version of <a href="http://phpseclib.sourceforge.net/" rel="noreferrer">phpseclib, a pure PHP SSH implementation</a>, to do this. eg.</p>
<pre><code><?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
$ssh->login('username', 'password');
$ssh->read('[prompt... | <p>You could use the latest SVN version of <a href="http://phpseclib.sourceforge.net/" rel="noreferrer">phpseclib, a pure PHP SSH implementation</a>, to do this. eg.</p> <pre><code><?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); $ssh->login('username', 'password'); $ssh->read('[prompt... | 5, 390, 1674, 8646, 12079 | php, root, shell, shell-exec, sudo | <h1>PHP sudo in shell_exec</h1>
<p>I want to execute a command as root with shell_exec. Now I know this is dangerous, but believe me, you need to login with MOD_AUTH and have the right privilleges to come to this page. It's secure. How can I get this done?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,360 | bash | # PHP sudo in shell_exec
I want to execute a command as root with shell_exec. Now I know this is dangerous, but believe me, you need to login with MOD_AUTH and have the right privilleges to come to this page. It's secure. How can I get this done? | You could use the latest SVN version of [phpseclib, a pure PHP SSH implementation](http://phpseclib.sourceforge.net/), to do this. eg.
```
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
$ssh->login('username', 'password');
$ssh->read('[prompt]');
$ssh->write("sudo command\n");
$ssh->read('Pass... |
1928398 | PowerShell: suppress Write-Progress output | 9 | 2009-12-18 14:08:21 | <p>I have a PowerShell script that calls a CmdLet which in turn reports its progress using Write-Progress, and I would like to hide the progress bar.<br>
In is it possible to suppress or redirect the output of the Write-Progress CmdLet? </p>
| 3,589 | 15,622 | 2009-12-18 16:02:21 | 1,928,794 | 15 | 2009-12-18 15:15:42 | 153,982 | 2009-12-18 16:02:21 | https://stackoverflow.com/q/1928398 | https://stackoverflow.com/a/1928794 | <p>Try setting this preference variable before calling the cmdlet that utilizes Write-Progress:</p>
<pre><code>$ProgressPreference = 'SilentlyContinue'
</code></pre>
<p>You may want to revert back to 'Continue' afterwards.</p>
| <p>Try setting this preference variable before calling the cmdlet that utilizes Write-Progress:</p> <pre><code>$ProgressPreference = 'SilentlyContinue' </code></pre> <p>You may want to revert back to 'Continue' afterwards.</p> | 526, 7060, 31901 | http-redirect, powershell, progress | <h1>PowerShell: suppress Write-Progress output</h1>
<p>I have a PowerShell script that calls a CmdLet which in turn reports its progress using Write-Progress, and I would like to hide the progress bar.<br>
In is it possible to suppress or redirect the output of the Write-Progress CmdLet? </p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,361 | bash | # PowerShell: suppress Write-Progress output
I have a PowerShell script that calls a CmdLet which in turn reports its progress using Write-Progress, and I would like to hide the progress bar.
In is it possible to suppress or redirect the output of the Write-Progress CmdLet? | Try setting this preference variable before calling the cmdlet that utilizes Write-Progress:
```
$ProgressPreference = 'SilentlyContinue'
```
You may want to revert back to 'Continue' afterwards. |
538504 | Uses for this bash filename extraction technique? | 9 | 2009-02-11 19:59:52 | <p>I have a portion of a bash script that is getting a filename without extension, but I'm trying to understand what is really going on here. What are the "%%"'s for? Can someone elaborate on what bash is doing behind the scenes? How can this technique be used on a general basis?</p>
<pre><code>#!/bin/bash
for src... | 15,729 | 46,425 | 2010-01-21 15:51:41 | 538,527 | 15 | 2009-02-11 20:08:37 | 55,925 | 2009-02-11 20:08:37 | https://stackoverflow.com/q/538504 | https://stackoverflow.com/a/538527 | <p>It gets rid of the filename extension (<em>here</em>: <code>.tif</code>), sample:</p>
<pre><code>$ for A in test.py test.sh test.xml test.xsl; do echo "$A: ${A%%.*}"; done
test.py: test
test.sh: test
test.xml: test
test.xsl: test
</code></pre>
<p>from bash manual:</p>
<pre><code> ${parameter%%word}
Th... | <p>It gets rid of the filename extension (<em>here</em>: <code>.tif</code>), sample:</p> <pre><code>$ for A in test.py test.sh test.xml test.xsl; do echo "$A: ${A%%.*}"; done test.py: test test.sh: test test.xml: test test.xsl: test </code></pre> <p>from bash manual:</p> <pre><code> ${parameter%%word} Th... | 58, 387, 390, 1062, 7992 | bash, filenames, linux, operators, shell | <h1>Uses for this bash filename extraction technique?</h1>
<p>I have a portion of a bash script that is getting a filename without extension, but I'm trying to understand what is really going on here. What are the "%%"'s for? Can someone elaborate on what bash is doing behind the scenes? How can this technique be us... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,362 | bash | # Uses for this bash filename extraction technique?
I have a portion of a bash script that is getting a filename without extension, but I'm trying to understand what is really going on here. What are the "%%"'s for? Can someone elaborate on what bash is doing behind the scenes? How can this technique be used on a gene... | It gets rid of the filename extension (*here*: `.tif`), sample:
```
$ for A in test.py test.sh test.xml test.xsl; do echo "$A: ${A%%.*}"; done
test.py: test
test.sh: test
test.xml: test
test.xsl: test
```
from bash manual:
```
${parameter%%word}
The word is expanded to produce a pattern just as in pathn... |
63518723 | How to unzip on Amazon Linux 2? | 8 | 2020-08-21 07:50:38 | <p>I have a file names awscliv2.zip and I'm trying to unzip it.</p>
<p>So first I tried:</p>
<pre><code>unzip awscliv2.zip
</code></pre>
<p>But got:</p>
<blockquote>
<p>-bash: unzip: command not found</p>
</blockquote>
<p>And then I tried:</p>
<pre><code>tar xvf awscliv2.zip
</code></pre>
<p>But got:</p>
<blockquote>
<... | 34,080 | 1,026,271 | 2020-08-21 07:52:09 | 63,518,752 | 15 | 2020-08-21 07:52:09 | 248,823 | 2020-08-21 07:52:09 | https://stackoverflow.com/q/63518723 | https://stackoverflow.com/a/63518752 | <p>You can install <code>unzip</code> using:</p>
<pre><code>sudo yum install unzip
</code></pre>
| <p>You can install <code>unzip</code> using:</p> <pre><code>sudo yum install unzip </code></pre> | 387, 7597, 33388, 124614, 136111 | amazon-linux, amazon-linux-2, amazon-web-services, bash, unzip | <h1>How to unzip on Amazon Linux 2?</h1>
<p>I have a file names awscliv2.zip and I'm trying to unzip it.</p>
<p>So first I tried:</p>
<pre><code>unzip awscliv2.zip
</code></pre>
<p>But got:</p>
<blockquote>
<p>-bash: unzip: command not found</p>
</blockquote>
<p>And then I tried:</p>
<pre><code>tar xvf awscliv2.zip
</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,363 | bash | # How to unzip on Amazon Linux 2?
I have a file names awscliv2.zip and I'm trying to unzip it.
So first I tried:
```
unzip awscliv2.zip
```
But got:
> -bash: unzip: command not found
And then I tried:
```
tar xvf awscliv2.zip
```
But got:
> tar: This does not look like a tar archive
>
> tar: Skipping to next h... | You can install `unzip` using:
```
sudo yum install unzip
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.