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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
64840636 | What is the difference between PowerShell 5.1, 6, and core? | 6 | 2020-11-15 02:21:57 | <p>From what I understand PowerShell 6 and Core uses the .Net Core framework and is cross-platform while PowerShell 5.1 uses the .Net framework. To my understanding PowersSell Core is also not as developed as 5.1</p>
<p>What would you recommend I start learning? I am still a high school student and want to work in INFO... | 1,286 | 11,422,124 | 2020-11-15 02:51:57 | 64,840,781 | 12 | 2020-11-15 02:51:57 | 3,905,079 | 2020-11-15 02:51:57 | https://stackoverflow.com/q/64840636 | https://stackoverflow.com/a/64840781 | <p>The naming has changed a bit over time. In the beginning, PowerShell was Windows only, as it used the full .NET Framework. These are PowerShell versions 1.0 through 5.1, and nowadays we usually call this "Windows PowerShell". The binary for this is <code>powershell.exe</code>.</p>
<p>Starting with PowerShe... | <p>The naming has changed a bit over time. In the beginning, PowerShell was Windows only, as it used the full .NET Framework. These are PowerShell versions 1.0 through 5.1, and nowadays we usually call this "Windows PowerShell". The binary for this is <code>powershell.exe</code>.</p> <p>Starting with PowerShe... | 526, 130616, 139865 | powershell, powershell-6.0, powershell-core | <h1>What is the difference between PowerShell 5.1, 6, and core?</h1>
<p>From what I understand PowerShell 6 and Core uses the .Net Core framework and is cross-platform while PowerShell 5.1 uses the .Net framework. To my understanding PowersSell Core is also not as developed as 5.1</p>
<p>What would you recommend I star... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,075 | bash | # What is the difference between PowerShell 5.1, 6, and core?
From what I understand PowerShell 6 and Core uses the .Net Core framework and is cross-platform while PowerShell 5.1 uses the .Net framework. To my understanding PowersSell Core is also not as developed as 5.1
What would you recommend I start learning? I a... | The naming has changed a bit over time. In the beginning, PowerShell was Windows only, as it used the full .NET Framework. These are PowerShell versions 1.0 through 5.1, and nowadays we usually call this "Windows PowerShell". The binary for this is `powershell.exe`.
Starting with PowerShell 6.0, the language uses .NET... |
63752791 | Is it possible to use "set -e" but allow certain commands to fail? | 6 | 2020-09-05 10:15:18 | <p>I am working on a backup script and would like to stop the script on error except for certain commands such as <code>veracrypt --mount</code> which returns 1 when already mounted.</p>
<pre class="lang-sh prettyprint-override"><code>#! /bin/sh
set -e
veracrypt --text --mount --pim 0 --keyfiles "" --protec... | 1,421 | 4,579,271 | 2020-09-07 01:43:25 | 63,752,813 | 12 | 2020-09-05 10:18:05 | 14,860 | 2020-09-07 01:43:25 | https://stackoverflow.com/q/63752791 | https://stackoverflow.com/a/63752813 | <p>You can use <code>||</code> to execute something that <em>won't</em> fail if a primary command fails, such as with:</p>
<pre><code>blah || true
{ yada; yada; yada; } || true
</code></pre>
<p>Without the <code>|| true</code>, the script will complain on error then stop. With it, you'll still see the error but the scr... | <p>You can use <code>||</code> to execute something that <em>won't</em> fail if a primary command fails, such as with:</p> <pre><code>blah || true { yada; yada; yada; } || true </code></pre> <p>Without the <code>|| true</code>, the script will complain on error then stop. With it, you'll still see the error but the scr... | 387, 3791, 10327 | bash, sh, zsh | <h1>Is it possible to use "set -e" but allow certain commands to fail?</h1>
<p>I am working on a backup script and would like to stop the script on error except for certain commands such as <code>veracrypt --mount</code> which returns 1 when already mounted.</p>
<pre class="lang-sh prettyprint-override"><code>#! /bin/s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,076 | bash | # Is it possible to use "set -e" but allow certain commands to fail?
I am working on a backup script and would like to stop the script on error except for certain commands such as `veracrypt --mount` which returns 1 when already mounted.
```
#! /bin/sh
set -e
veracrypt --text --mount --pim 0 --keyfiles "" --protect... | You can use `||` to execute something that *won't* fail if a primary command fails, such as with:
```
blah || true
{ yada; yada; yada; } || true
```
Without the `|| true`, the script will complain on error then stop. With it, you'll still see the error but the script will carry on.
---
Another possibility is taking... |
62979947 | How to autocomplete files under specific directory? | 6 | 2020-07-19 11:56:33 | <p>I created a command <code>memo</code> as follows:</p>
<pre class="lang-sh prettyprint-override"><code>memo() {
vi $HOME/memo/$1
}
</code></pre>
<p>I want to apply bash-completion to my <code>memo</code> to open files that is already in <code>$HOME/memo</code> directory:</p>
<pre class="lang-sh prettyprint-override... | 2,288 | 10,051,099 | 2020-07-23 10:12:59 | 62,980,925 | 12 | 2020-07-19 13:28:45 | 900,078 | 2020-07-19 13:28:45 | https://stackoverflow.com/q/62979947 | https://stackoverflow.com/a/62980925 | <p>Here's a simple example:</p>
<pre class="lang-sh prettyprint-override"><code>_memo()
{
local MEMO_DIR=$HOME/memo
local cmd=$1 cur=$2 pre=$3
local arr i file
arr=( $( cd "$MEMO_DIR" && compgen -f -- "$cur" ) )
COMPREPLY=()
for ((i = 0; i < ${#arr[@]}; ++i)); do
... | <p>Here's a simple example:</p> <pre class="lang-sh prettyprint-override"><code>_memo() { local MEMO_DIR=$HOME/memo local cmd=$1 cur=$2 pre=$3 local arr i file arr=( $( cd "$MEMO_DIR" && compgen -f -- "$cur" ) ) COMPREPLY=() for ((i = 0; i < ${#arr[@]}; ++i)); do ... | 387, 59778 | bash, bash-completion | <h1>How to autocomplete files under specific directory?</h1>
<p>I created a command <code>memo</code> as follows:</p>
<pre class="lang-sh prettyprint-override"><code>memo() {
vi $HOME/memo/$1
}
</code></pre>
<p>I want to apply bash-completion to my <code>memo</code> to open files that is already in <code>$HOME/memo</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,077 | bash | # How to autocomplete files under specific directory?
I created a command `memo` as follows:
```
memo() {
vi $HOME/memo/$1
}
```
I want to apply bash-completion to my `memo` to open files that is already in `$HOME/memo` directory:
```
$ memo [TAB] # to show files in $HOME/memo
```
`$HOME/memo` contains directory... | Here's a simple example:
```
_memo()
{
local MEMO_DIR=$HOME/memo
local cmd=$1 cur=$2 pre=$3
local arr i file
arr=( $( cd "$MEMO_DIR" && compgen -f -- "$cur" ) )
COMPREPLY=()
for ((i = 0; i < ${#arr[@]}; ++i)); do
file=${arr[i]}
if [[ -d $MEMO_DIR/$file ]]; then
file... |
62115565 | Syntax error near unexpected token `;' when running a command in Bash | 6 | 2020-05-31 11:32:09 | <p>In Bash in the terminal, it is impossible to run a command that ends with and <code>&</code> (being sent to the background) followed by another command (obviously with a <code>;</code> between them). Why is that? Why can't you run anything with <code>&;</code> or <code>$ ;</code> in it?</p>
<p>I'm trying to... | 7,042 | 6,551,213 | 2021-10-01 15:36:18 | 62,115,639 | 12 | 2020-05-31 11:37:58 | 6,261,018 | 2020-05-31 11:37:58 | https://stackoverflow.com/q/62115565 | https://stackoverflow.com/a/62115639 | <p>The problem is with the semi-colon after the ampersand (&):</p>
<blockquote>
<p>An ampersand does the same thing as a semicolon or newline in that it indicates the end of a command, but it causes Bash to execute the command asynchronously.
<a href="https://mywiki.wooledge.org/BashSheet" rel="noreferrer">Bas... | <p>The problem is with the semi-colon after the ampersand (&):</p> <blockquote> <p>An ampersand does the same thing as a semicolon or newline in that it indicates the end of a command, but it causes Bash to execute the command asynchronously. <a href="https://mywiki.wooledge.org/BashSheet" rel="noreferrer">Bas... | 387 | bash | <h1>Syntax error near unexpected token `;' when running a command in Bash</h1>
<p>In Bash in the terminal, it is impossible to run a command that ends with and <code>&</code> (being sent to the background) followed by another command (obviously with a <code>;</code> between them). Why is that? Why can't you run any... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,078 | bash | # Syntax error near unexpected token `;' when running a command in Bash
In Bash in the terminal, it is impossible to run a command that ends with and `&` (being sent to the background) followed by another command (obviously with a `;` between them). Why is that? Why can't you run anything with `&;` or `$ ;` in it?
I'... | The problem is with the semi-colon after the ampersand (&):
> An ampersand does the same thing as a semicolon or newline in that it indicates the end of a command, but it causes Bash to execute the command asynchronously.
> [BashSheet](https://mywiki.wooledge.org/BashSheet)
Basically, it's as if you were to put doubl... |
58228341 | How to extract specific line from text file | 6 | 2019-10-04 00:12:53 | <p>I got a large log file (user.log) , eg: </p>
<pre><code> 2019-10-02 00:03:55.407095
2019-10-02 00:03:55.410345
2019-10-02 00:03:55.410765
2019-10-02 00:03:55.411187
2019-10-02 00:03:55.411791
2019-10-02 00:03:55.412657
</code></pre>
<p>How do I just extract the line number #3 from the log file as;... | 19,237 | 577,994 | 2019-10-04 19:20:20 | 58,229,053 | 12 | 2019-10-04 02:14:16 | 45,375 | 2019-10-04 19:20:20 | https://stackoverflow.com/q/58228341 | https://stackoverflow.com/a/58229053 | <p>A <strong>simple and <em>memory-efficient</em> approach suitable for processing <em>large</em> input files</strong> is to combine <code>Get-Content</code> with <code>Select-Object</code>:</p>
<pre><code>Get-Content user.log | Select-Object -Skip 2 -First 1
</code></pre>
<ul>
<li><p><code>-Skip 2</code> instructs <... | <p>A <strong>simple and <em>memory-efficient</em> approach suitable for processing <em>large</em> input files</strong> is to combine <code>Get-Content</code> with <code>Select-Object</code>:</p> <pre><code>Get-Content user.log | Select-Object -Skip 2 -First 1 </code></pre> <ul> <li><p><code>-Skip 2</code> instructs <... | 526, 14680, 17938 | line-numbers, powershell, text-files | <h1>How to extract specific line from text file</h1>
<p>I got a large log file (user.log) , eg: </p>
<pre><code> 2019-10-02 00:03:55.407095
2019-10-02 00:03:55.410345
2019-10-02 00:03:55.410765
2019-10-02 00:03:55.411187
2019-10-02 00:03:55.411791
2019-10-02 00:03:55.412657
</code></pre>
<p>How do I ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,079 | bash | # How to extract specific line from text file
I got a large log file (user.log) , eg:
```
2019-10-02 00:03:55.407095
2019-10-02 00:03:55.410345
2019-10-02 00:03:55.410765
2019-10-02 00:03:55.411187
2019-10-02 00:03:55.411791
2019-10-02 00:03:55.412657
```
How do I just extract the line number #3 fr... | A **simple and *memory-efficient* approach suitable for processing *large* input files** is to combine `Get-Content` with `Select-Object`:
```
Get-Content user.log | Select-Object -Skip 2 -First 1
```
- `-Skip 2` instructs `Select-Object` to skip the first 2 input lines output by `Get-Content`.
- Therefore, it is the... |
57965466 | How to escape special characters in PowerShell? | 6 | 2019-09-16 23:21:02 | <p>When my PowerShell script runs, it prompts the user for a password parameter. That password can contain any number of special characters like *\~;(%?.:@/
That password is then used as a parameter for a .exe command, but it is often incorrect due to some special characters not being escaped properly.</p>
<p>An examp... | 109,656 | 12,076,622 | 2024-09-10 16:45:10 | 57,966,347 | 12 | 2019-09-17 01:50:27 | 45,375 | 2024-09-10 16:45:10 | https://stackoverflow.com/q/57965466 | https://stackoverflow.com/a/57966347 |
<p><strong>You're using <code>Invoke-Expression</code> to call an external program</strong>:</p>
<ul>
<li><p><strong>There's <em>no</em> reason to do that</strong>, and <a href="https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/" rel="nofollow noreferrer"><code>Invoke-Express... | <p><strong>You're using <code>Invoke-Expression</code> to call an external program</strong>:</p> <ul> <li><p><strong>There's <em>no</em> reason to do that</strong>, and <a href="https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/" rel="nofollow noreferrer"><code>Invoke-Express... | 360, 526, 4804 | escaping, parameters, powershell | <h1>How to escape special characters in PowerShell?</h1>
<p>When my PowerShell script runs, it prompts the user for a password parameter. That password can contain any number of special characters like *\~;(%?.:@/
That password is then used as a parameter for a .exe command, but it is often incorrect due to some specia... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,080 | bash | # How to escape special characters in PowerShell?
When my PowerShell script runs, it prompts the user for a password parameter. That password can contain any number of special characters like *\~;(%?.:@/
That password is then used as a parameter for a .exe command, but it is often incorrect due to some special charact... | **You're using `Invoke-Expression` to call an external program**:
- **There's *no* reason to do that**, and [`Invoke-Expression` should generally be avoided](https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/): it causes quoting headaches (as in your case), but, more important... |
55601608 | get pytest exit code from shell script | 6 | 2019-04-09 21:29:52 | <p>I'm running pytest test from shell script.
The relevant line in the script looks something like:</p>
<pre><code>pytest pytest_tests --param=$my_param
</code></pre>
<p>According to pytest documentation, "Running pytest can result in six different exit codes" (0-5).
My question is how can I get this exit code from ... | 5,800 | 2,880,391 | 2019-04-09 21:33:23 | 55,601,649 | 12 | 2019-04-09 21:33:23 | 354,577 | 2019-04-09 21:33:23 | https://stackoverflow.com/q/55601608 | https://stackoverflow.com/a/55601649 | <p>After a command runs its exit code should be available via the <a href="https://www.tldp.org/LDP/abs/html/internalvariables.html" rel="noreferrer"><code>$?</code> variable</a>. Try something like this:</p>
<pre><code>pytest pytest_tests --param=$my_param
echo Pytest exited $?
</code></pre>
<p>This works in Bash, a... | <p>After a command runs its exit code should be available via the <a href="https://www.tldp.org/LDP/abs/html/internalvariables.html" rel="noreferrer"><code>$?</code> variable</a>. Try something like this:</p> <pre><code>pytest pytest_tests --param=$my_param echo Pytest exited $? </code></pre> <p>This works in Bash, a... | 16, 390, 48664 | pytest, python, shell | <h1>get pytest exit code from shell script</h1>
<p>I'm running pytest test from shell script.
The relevant line in the script looks something like:</p>
<pre><code>pytest pytest_tests --param=$my_param
</code></pre>
<p>According to pytest documentation, "Running pytest can result in six different exit codes" (0-5).
M... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,081 | bash | # get pytest exit code from shell script
I'm running pytest test from shell script.
The relevant line in the script looks something like:
```
pytest pytest_tests --param=$my_param
```
According to pytest documentation, "Running pytest can result in six different exit codes" (0-5).
My question is how can I get this e... | After a command runs its exit code should be available via the [`$?` variable](https://www.tldp.org/LDP/abs/html/internalvariables.html). Try something like this:
```
pytest pytest_tests --param=$my_param
echo Pytest exited $?
```
This works in Bash, and should work in the regular `sh` Bourne shell and zsh as well.
... |
54028532 | How to extract image from PGP key on command line? | 6 | 2019-01-03 19:21:26 | <p>I've created a private PGP key and then added a photo to it in my Ubuntu's Passwords and keys manager. I can see the photo there, but is there any way to view it from shell and export it as image file?</p>
| 3,582 | 7,292,139 | 2019-01-03 19:21:26 | 54,028,533 | 12 | 2019-01-03 19:21:26 | 7,292,139 | 2019-01-03 19:21:26 | https://stackoverflow.com/q/54028532 | https://stackoverflow.com/a/54028533 | <p>To view the image, use this:<br/></p>
<pre><code>gpg --list-options show-photos --list-keys \
[key identifier (e-mail or ID), leave out to show all keys and photos]
</code></pre>
<p>It internally uses <code>xloadimage</code>, which wasn't preinstalled on my Ubuntu 18.04, so you can either install it, or use <cod... | <p>To view the image, use this:<br/></p> <pre><code>gpg --list-options show-photos --list-keys \ [key identifier (e-mail or ID), leave out to show all keys and photos] </code></pre> <p>It internally uses <code>xloadimage</code>, which wasn't preinstalled on my Ubuntu 18.04, so you can either install it, or use <cod... | 6735, 7408, 10327 | gnupg, pgp, sh | <h1>How to extract image from PGP key on command line?</h1>
<p>I've created a private PGP key and then added a photo to it in my Ubuntu's Passwords and keys manager. I can see the photo there, but is there any way to view it from shell and export it as image file?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,082 | bash | # How to extract image from PGP key on command line?
I've created a private PGP key and then added a photo to it in my Ubuntu's Passwords and keys manager. I can see the photo there, but is there any way to view it from shell and export it as image file? | To view the image, use this:
```
gpg --list-options show-photos --list-keys \
[key identifier (e-mail or ID), leave out to show all keys and photos]
```
It internally uses `xloadimage`, which wasn't preinstalled on my Ubuntu 18.04, so you can either install it, or use `--photo-viewer "eog %i"` (expands `%i` to temp... |
53600256 | AWS lambda CLI 'update-function-code' does not update lambda_handler file | 6 | 2018-12-03 19:06:07 | <p><a href="https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html" rel="noreferrer">update-function-code</a> AWS CLI command updates all code files except the handler function file, <code>lambda_function.py</code></p>
<p>Specifically, I made a bash script that</p>
<ol>
<li>Downloads code z... | 5,237 | 2,246,488 | 2019-09-26 22:41:04 | 53,603,881 | 12 | 2018-12-04 00:15:30 | 2,246,488 | 2018-12-04 00:15:30 | https://stackoverflow.com/q/53600256 | https://stackoverflow.com/a/53603881 | <p><strong>I was verifying the code changes by navigating to the lambda code editor on the AWS web portal, and it appears this was just a client side issue in the web UI.</strong> </p>
<p>It took about 5 minutes before the <code>lambda_function.py</code> was updated in the UI (despite refreshing), whereas the other co... | <p><strong>I was verifying the code changes by navigating to the lambda code editor on the AWS web portal, and it appears this was just a client side issue in the web UI.</strong> </p> <p>It took about 5 minutes before the <code>lambda_function.py</code> was updated in the UI (despite refreshing), whereas the other co... | 16, 387, 33388, 108737 | amazon-web-services, aws-lambda, bash, python | <h1>AWS lambda CLI 'update-function-code' does not update lambda_handler file</h1>
<p><a href="https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html" rel="noreferrer">update-function-code</a> AWS CLI command updates all code files except the handler function file, <code>lambda_function.py</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,083 | bash | # AWS lambda CLI 'update-function-code' does not update lambda_handler file
[update-function-code](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html) AWS CLI command updates all code files except the handler function file, `lambda_function.py`
Specifically, I made a bash script that
1... | **I was verifying the code changes by navigating to the lambda code editor on the AWS web portal, and it appears this was just a client side issue in the web UI.**
It took about 5 minutes before the `lambda_function.py` was updated in the UI (despite refreshing), whereas the other code files did get updated immediatel... |
52948243 | Executing shell command in groovy throws 'unexpected char' error | 6 | 2018-10-23 11:44:19 | <p>I am trying to execute a shell command n groovy</p>
<pre><code>def shellString = "s/\[\|]\|\s\|'\|(\|)//g"
def temp2 = "echo response| sed -e ${shellString}".execute()
</code></pre>
<p>It throws compilation error:</p>
<pre><code>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Workf... | 19,661 | 4,939,289 | 2018-10-23 12:08:27 | 52,948,344 | 12 | 2018-10-23 11:49:49 | 2,194,470 | 2018-10-23 11:49:49 | https://stackoverflow.com/q/52948243 | https://stackoverflow.com/a/52948344 | <p>You need to escape slash to avoid compilation errors:</p>
<pre class="lang-groovy prettyprint-override"><code>def shellString = "s/\\[\\|]\\|\\s\\|'\\|(\\|)//g"
def temp2 = "echo response| sed -e ${shellString}".execute()
println temp2.text
</code></pre>
<p>Output:</p>
<pre><code>response| sed -e s/\[\|]\|\s\|'\... | <p>You need to escape slash to avoid compilation errors:</p> <pre class="lang-groovy prettyprint-override"><code>def shellString = "s/\\[\\|]\\|\\s\\|'\\|(\\|)//g" def temp2 = "echo response| sed -e ${shellString}".execute() println temp2.text </code></pre> <p>Output:</p> <pre><code>response| sed -e s/\[\|]\|\s\|'\... | 390, 849 | groovy, shell | <h1>Executing shell command in groovy throws 'unexpected char' error</h1>
<p>I am trying to execute a shell command n groovy</p>
<pre><code>def shellString = "s/\[\|]\|\s\|'\|(\|)//g"
def temp2 = "echo response| sed -e ${shellString}".execute()
</code></pre>
<p>It throws compilation error:</p>
<pre><code>org.codehau... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,084 | bash | # Executing shell command in groovy throws 'unexpected char' error
I am trying to execute a shell command n groovy
```
def shellString = "s/\[\|]\|\s\|'\|(\|)//g"
def temp2 = "echo response| sed -e ${shellString}".execute()
```
It throws compilation error:
```
org.codehaus.groovy.control.MultipleCompilationErrorsEx... | You need to escape slash to avoid compilation errors:
```
def shellString = "s/\\[\\|]\\|\\s\\|'\\|(\\|)//g"
def temp2 = "echo response| sed -e ${shellString}".execute()
println temp2.text
```
Output:
```
response| sed -e s/\[\|]\|\s\|'\|(\|)//g
``` |
52640820 | How to rename files in bash to increase number in name? | 6 | 2018-10-04 07:00:19 | <p>I have a few thousand files named as follows:</p>
<pre><code>Cyprinus_carpio_600_nanopore_trim_reads.fasta
Cyprinus_carpio_700_nanopore_trim_reads.fasta
Cyprinus_carpio_800_nanopore_trim_reads.fasta
Cyprinus_carpio_900_nanopore_trim_reads.fasta
Vibrio_cholerae_3900_na... | 4,799 | 9,227,141 | 2019-02-24 17:57:07 | 52,641,048 | 12 | 2018-10-04 07:14:50 | 2,836,621 | 2018-10-04 07:20:57 | https://stackoverflow.com/q/52640820 | https://stackoverflow.com/a/52641048 | <p>If you can get hold of the Perl-flavoured version of <code>rename</code>, that is simple like this:</p>
<pre><code>rename -n 's/(\d+)/$1 + 100/e' *fasta
</code></pre>
<p><strong>Sample Output</strong></p>
<pre><code>'Ciprianus_maximus_11_fred.fasta' would be renamed to 'Ciprianus_maximus_111_fred.fasta'
'Ciprianu... | <p>If you can get hold of the Perl-flavoured version of <code>rename</code>, that is simple like this:</p> <pre><code>rename -n 's/(\d+)/$1 + 100/e' *fasta </code></pre> <p><strong>Sample Output</strong></p> <pre><code>'Ciprianus_maximus_11_fred.fasta' would be renamed to 'Ciprianus_maximus_111_fred.fasta' 'Ciprianu... | 58, 387, 4510 | bash, linux, rename | <h1>How to rename files in bash to increase number in name?</h1>
<p>I have a few thousand files named as follows:</p>
<pre><code>Cyprinus_carpio_600_nanopore_trim_reads.fasta
Cyprinus_carpio_700_nanopore_trim_reads.fasta
Cyprinus_carpio_800_nanopore_trim_reads.fasta
Cypri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,085 | bash | # How to rename files in bash to increase number in name?
I have a few thousand files named as follows:
```
Cyprinus_carpio_600_nanopore_trim_reads.fasta
Cyprinus_carpio_700_nanopore_trim_reads.fasta
Cyprinus_carpio_800_nanopore_trim_reads.fasta
Cyprinus_carpio_900_nanop... | If you can get hold of the Perl-flavoured version of `rename`, that is simple like this:
```
rename -n 's/(\d+)/$1 + 100/e' *fasta
```
**Sample Output**
```
'Ciprianus_maximus_11_fred.fasta' would be renamed to 'Ciprianus_maximus_111_fred.fasta'
'Ciprianus_maximus_300_fred.fasta' would be renamed to 'Ciprianus_maxim... |
51062944 | zsh - command not found for written script | 6 | 2018-06-27 12:34:31 | <p>I am using mac and I have a script file <code>print_hello</code>:</p>
<pre><code>#!/bin/bash
echo hello
</code></pre>
<p>and if I run it directly from directory with <code>./print_hello</code> command and zsh terminal it will properly print hello. I would like to add it as a global command, so then writing <code>p... | 6,747 | 5,446,465 | 2018-08-02 10:45:32 | 51,651,665 | 12 | 2018-08-02 10:45:32 | 5,446,465 | 2018-08-02 10:45:32 | https://stackoverflow.com/q/51062944 | https://stackoverflow.com/a/51651665 | <p>It is strange, but the thing that helped me was replacing </p>
<pre><code>~/scripts
</code></pre>
<p>with</p>
<pre><code>$HOME/scripts
</code></pre>
<p>in .zhrc file </p>
| <p>It is strange, but the thing that helped me was replacing </p> <pre><code>~/scripts </code></pre> <p>with</p> <pre><code>$HOME/scripts </code></pre> <p>in .zhrc file </p> | 369, 387, 3791, 28566, 89892 | bash, iterm2, macos, zsh, zshrc | <h1>zsh - command not found for written script</h1>
<p>I am using mac and I have a script file <code>print_hello</code>:</p>
<pre><code>#!/bin/bash
echo hello
</code></pre>
<p>and if I run it directly from directory with <code>./print_hello</code> command and zsh terminal it will properly print hello. I would like to... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,086 | bash | # zsh - command not found for written script
I am using mac and I have a script file `print_hello`:
```
#!/bin/bash
echo hello
```
and if I run it directly from directory with `./print_hello` command and zsh terminal it will properly print hello. I would like to add it as a global command, so then writing `print_hel... | It is strange, but the thing that helped me was replacing
```
~/scripts
```
with
```
$HOME/scripts
```
in .zhrc file |
48048529 | Silver Searcher: how to unignore files in the .gitignore? | 6 | 2018-01-01 09:30:04 | <p>I have a folder of aliases. These are bash files. Some are sensitive, so I keep them in a <code>.gitignore</code>.</p>
<pre><code>~/.bash_utilities
bash_a.sh
bash_b.sh
.gitignore
</code></pre>
<p>.gitignore:
bash_b.sh </p>
<p>The problem is that my Silver Searcher looks at the <code>.gitignore</code> an... | 1,350 | 1,574,104 | 2018-01-01 13:55:38 | 48,050,148 | 12 | 2018-01-01 13:41:04 | 3,691,891 | 2018-01-01 13:55:38 | https://stackoverflow.com/q/48048529 | https://stackoverflow.com/a/48050148 | <p>IIUC, it's well explained in <code>man ag</code>:</p>
<blockquote>
<p>-u --unrestricted</p>
<p>Search all files. This ignores .ignore, .gitignore, etc. It searches binary and hidden files as well.</p>
<p>-U --skip-vcs-ignores</p>
<p>Ignore VCS ignore files (.gitignore, .hgignore), but still use .ignore.</p>
</blockq... | <p>IIUC, it's well explained in <code>man ag</code>:</p> <blockquote> <p>-u --unrestricted</p> <p>Search all files. This ignores .ignore, .gitignore, etc. It searches binary and hidden files as well.</p> <p>-U --skip-vcs-ignores</p> <p>Ignore VCS ignore files (.gitignore, .hgignore), but still use .ignore.</p> </blockq... | 58, 387, 26784, 107470 | ack, ag, bash, linux | <h1>Silver Searcher: how to unignore files in the .gitignore?</h1>
<p>I have a folder of aliases. These are bash files. Some are sensitive, so I keep them in a <code>.gitignore</code>.</p>
<pre><code>~/.bash_utilities
bash_a.sh
bash_b.sh
.gitignore
</code></pre>
<p>.gitignore:
bash_b.sh </p>
<p>The problem... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,087 | bash | # Silver Searcher: how to unignore files in the .gitignore?
I have a folder of aliases. These are bash files. Some are sensitive, so I keep them in a `.gitignore`.
```
~/.bash_utilities
bash_a.sh
bash_b.sh
.gitignore
```
.gitignore:
bash_b.sh
The problem is that my Silver Searcher looks at the `.gitignore`... | IIUC, it's well explained in `man ag`:
> -u --unrestricted
>
> Search all files. This ignores .ignore, .gitignore, etc. It searches binary and hidden files as well.
>
> -U --skip-vcs-ignores
>
> Ignore VCS ignore files (.gitignore, .hgignore), but still use .ignore. |
47577690 | Multiline File in to single JSON string | 6 | 2017-11-30 16:06:24 | <p>I'm trying to JSON encode all of the contents of a single file into a single JSON string for a curl request in BASH. The file is text so it doesn't need to be base64 encoded. The big thing is that the file is multi-lined and the line breaks matter. I'm trying to encode a PEM file. If I strip the \n out of the file,... | 3,333 | 2,091,354 | 2021-04-23 11:52:45 | 47,578,386 | 12 | 2017-11-30 16:42:09 | 997,358 | 2021-04-23 11:52:45 | https://stackoverflow.com/q/47577690 | https://stackoverflow.com/a/47578386 | <p>You could use jq with the -s and -R options, e.g.</p>
<pre><code>jq -sR .
a
b
</code></pre>
<p>Result:</p>
<pre><code>"a\nb\n"
</code></pre>
| <p>You could use jq with the -s and -R options, e.g.</p> <pre><code>jq -sR . a b </code></pre> <p>Result:</p> <pre><code>"a\nb\n" </code></pre> | 387, 1508, 105170 | bash, jq, json | <h1>Multiline File in to single JSON string</h1>
<p>I'm trying to JSON encode all of the contents of a single file into a single JSON string for a curl request in BASH. The file is text so it doesn't need to be base64 encoded. The big thing is that the file is multi-lined and the line breaks matter. I'm trying to encod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,088 | bash | # Multiline File in to single JSON string
I'm trying to JSON encode all of the contents of a single file into a single JSON string for a curl request in BASH. The file is text so it doesn't need to be base64 encoded. The big thing is that the file is multi-lined and the line breaks matter. I'm trying to encode a PEM f... | You could use jq with the -s and -R options, e.g.
```
jq -sR .
a
b
```
Result:
```
"a\nb\n"
``` |
46006674 | ConvertTo-SecureString run without key on different user account, is there a way (with proper credentials) to get this working from a different user? | 6 | 2017-09-01 19:15:38 | <p>I have a VM that I have full access to with access to all accounts. My question below is all run on the <strong>same</strong> machine, just under different user accounts.</p>
<p>If I logon with <code>domain\user1</code> and run the following PowerShell to generate a string of a <code>SecureString</code>:</p>
<pre>... | 8,067 | 1,179,573 | 2017-09-01 20:48:01 | 46,007,790 | 12 | 2017-09-01 20:48:01 | 5,229,138 | 2017-09-01 20:48:01 | https://stackoverflow.com/q/46006674 | https://stackoverflow.com/a/46007790 | <p>Yes, but you will have to recreate the SecureStrings.</p>
<p>The strings encrypted by <code>ConvertTo-SecureString</code> can only be de-crypted by the same computer and user account that encrypted them by default.</p>
<p>You can use work around this with the <code>-Key</code> parameter. <a href="https://www.pdq.c... | <p>Yes, but you will have to recreate the SecureStrings.</p> <p>The strings encrypted by <code>ConvertTo-SecureString</code> can only be de-crypted by the same computer and user account that encrypted them by default.</p> <p>You can use work around this with the <code>-Key</code> parameter. <a href="https://www.pdq.c... | 219, 526 | encryption, powershell | <h1>ConvertTo-SecureString run without key on different user account, is there a way (with proper credentials) to get this working from a different user?</h1>
<p>I have a VM that I have full access to with access to all accounts. My question below is all run on the <strong>same</strong> machine, just under different us... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,089 | bash | # ConvertTo-SecureString run without key on different user account, is there a way (with proper credentials) to get this working from a different user?
I have a VM that I have full access to with access to all accounts. My question below is all run on the **same** machine, just under different user accounts.
If I log... | Yes, but you will have to recreate the SecureStrings.
The strings encrypted by `ConvertTo-SecureString` can only be de-crypted by the same computer and user account that encrypted them by default.
You can use work around this with the `-Key` parameter. [From the helpful folks at PDQ](https://www.pdq.com/blog/secure-p... |
44577344 | Piping docker run container ID to docker exec | 6 | 2017-06-15 21:30:33 | <p>In my development, I find myself issuing a <code>docker run</code> command followed by a <code>docker exec</code> command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was trying to pipe the container ID into my <code>docker exec<... | 4,457 | 867,628 | 2017-06-15 22:36:22 | 44,577,718 | 12 | 2017-06-15 22:01:38 | 1,094,246 | 2017-06-15 22:01:38 | https://stackoverflow.com/q/44577344 | https://stackoverflow.com/a/44577718 | <p>Do this instead:</p>
<pre><code>ID=$(docker run -itd image) && docker exec -it $ID bash
</code></pre>
<p>Because <code>xargs</code> executes it arguments without allocating a new tty.</p>
| <p>Do this instead:</p> <pre><code>ID=$(docker run -itd image) && docker exec -it $ID bash </code></pre> <p>Because <code>xargs</code> executes it arguments without allocating a new tty.</p> | 387, 5813, 7932, 90304 | bash, docker, exec, pipe | <h1>Piping docker run container ID to docker exec</h1>
<p>In my development, I find myself issuing a <code>docker run</code> command followed by a <code>docker exec</code> command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was try... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,090 | bash | # Piping docker run container ID to docker exec
In my development, I find myself issuing a `docker run` command followed by a `docker exec` command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was trying to pipe the container ID in... | Do this instead:
```
ID=$(docker run -itd image) && docker exec -it $ID bash
```
Because `xargs` executes it arguments without allocating a new tty. |
43643827 | Powershell - clarification about foreach | 6 | 2017-04-26 20:21:21 | <p>I am learning powershell and I need someone to give me an initial push to get me through the learning curve. I am familiar with programming and dos but not powershell.</p>
<p>What I would like to do is listing all files from my designated directory and pushing the filenames into an array. I am not very familiar wit... | 4,098 | 1,205,746 | 2017-04-26 20:33:29 | 43,644,036 | 12 | 2017-04-26 20:33:29 | 3,905,079 | 2017-04-26 20:33:29 | https://stackoverflow.com/q/43643827 | https://stackoverflow.com/a/43644036 | <p>Don't confuse <code>foreach</code> (the statement) with <code>ForEach-Object</code> (the cmdlet). Microsoft does a terrible job with this because there is an alias of <code>foreach</code> that points to <code>ForEach-Object</code>, so when you use <code>foreach</code> you have to know which version you're using base... | <p>Don't confuse <code>foreach</code> (the statement) with <code>ForEach-Object</code> (the cmdlet). Microsoft does a terrible job with this because there is an alias of <code>foreach</code> that points to <code>ForEach-Object</code>, so when you use <code>foreach</code> you have to know which version you're using base... | 526 | powershell | <h1>Powershell - clarification about foreach</h1>
<p>I am learning powershell and I need someone to give me an initial push to get me through the learning curve. I am familiar with programming and dos but not powershell.</p>
<p>What I would like to do is listing all files from my designated directory and pushing the f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,091 | bash | # Powershell - clarification about foreach
I am learning powershell and I need someone to give me an initial push to get me through the learning curve. I am familiar with programming and dos but not powershell.
What I would like to do is listing all files from my designated directory and pushing the filenames into an... | Don't confuse `foreach` (the statement) with `ForEach-Object` (the cmdlet). Microsoft does a terrible job with this because there is an alias of `foreach` that points to `ForEach-Object`, so when you use `foreach` you have to know which version you're using based on how you're using it. Their documentation makes this w... |
42090728 | How to get the pshome path for 64-bits? | 6 | 2017-02-07 13:09:19 | <p>The path to home folder in 32-bits is accessible using the <code>$PSHome</code> variable (<code>c:\Windows\System32\WindowsPowerShell\v1.0\</code>).</p>
<p>How to access the variable that contains the path to the 64-bits version (<code>c:\Windows\SysWOW64\WindowsPowerShell\v1.0\</code>) ?</p>
<p><strong>EDIT</stro... | 13,115 | 545,918 | 2017-02-07 13:33:17 | 42,090,946 | 12 | 2017-02-07 13:20:20 | 6,083,222 | 2017-02-07 13:20:20 | https://stackoverflow.com/q/42090728 | https://stackoverflow.com/a/42090946 | <p>You've got it backwards - on 64-bit Windows, <code>C:\WINDOWS\SYSTEM32</code> is for 64-bit stuff; <code>C:\WINDOWS\SYSWOW64</code> is for 32-bit stuff. This is because Microsoft chose to make the "main" directory <code>SYSTEM32</code> for backward compatibility; the new 32-bit folder is called <code>SYSWOW64</code>... | <p>You've got it backwards - on 64-bit Windows, <code>C:\WINDOWS\SYSTEM32</code> is for 64-bit stuff; <code>C:\WINDOWS\SYSWOW64</code> is for 32-bit stuff. This is because Microsoft chose to make the "main" directory <code>SYSTEM32</code> for backward compatibility; the new 32-bit folder is called <code>SYSWOW64</code>... | 526 | powershell | <h1>How to get the pshome path for 64-bits?</h1>
<p>The path to home folder in 32-bits is accessible using the <code>$PSHome</code> variable (<code>c:\Windows\System32\WindowsPowerShell\v1.0\</code>).</p>
<p>How to access the variable that contains the path to the 64-bits version (<code>c:\Windows\SysWOW64\WindowsPowe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,092 | bash | # How to get the pshome path for 64-bits?
The path to home folder in 32-bits is accessible using the `$PSHome` variable (`c:\Windows\System32\WindowsPowerShell\v1.0\`).
How to access the variable that contains the path to the 64-bits version (`c:\Windows\SysWOW64\WindowsPowerShell\v1.0\`) ?
**EDIT**
As Jeff Zeitlin... | You've got it backwards - on 64-bit Windows, `C:\WINDOWS\SYSTEM32` is for 64-bit stuff; `C:\WINDOWS\SYSWOW64` is for 32-bit stuff. This is because Microsoft chose to make the "main" directory `SYSTEM32` for backward compatibility; the new 32-bit folder is called `SYSWOW64` as shorthand for "System for Windows-on-Window... |
41229164 | How to run a scala program in terminal? | 6 | 2016-12-19 18:54:40 | <p>I have created a .scala file in the Scala version of eclipse, it has a main and object. I want to somehow compile this possibly into a jar file, so I can run it from terminal?</p>
<p>any info will be appreciated.</p>
<p>Thanks,
Rhys</p>
| 36,781 | 7,169,431 | 2016-12-24 11:39:41 | 41,229,276 | 12 | 2016-12-19 19:01:45 | 2,661,491 | 2016-12-19 19:01:45 | https://stackoverflow.com/q/41229164 | https://stackoverflow.com/a/41229276 | <p>Here is the full process from the command line:</p>
<pre><code>evan@vbox ~> cat test.scala
object test{
def main(args: Array[String]): Unit = println("Hello!")
}
evan@vbox ~> scalac test.scala
evan@vbox ~> scala test
Hello!
</code></pre>
<p>However if you want to use Scala IDE to its full potential I ... | <p>Here is the full process from the command line:</p> <pre><code>evan@vbox ~> cat test.scala object test{ def main(args: Array[String]): Unit = println("Hello!") } evan@vbox ~> scalac test.scala evan@vbox ~> scala test Hello! </code></pre> <p>However if you want to use Scala IDE to its full potential I ... | 390, 391, 3143, 98880 | apache-spark, scala, shell, terminal | <h1>How to run a scala program in terminal?</h1>
<p>I have created a .scala file in the Scala version of eclipse, it has a main and object. I want to somehow compile this possibly into a jar file, so I can run it from terminal?</p>
<p>any info will be appreciated.</p>
<p>Thanks,
Rhys</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,093 | bash | # How to run a scala program in terminal?
I have created a .scala file in the Scala version of eclipse, it has a main and object. I want to somehow compile this possibly into a jar file, so I can run it from terminal?
any info will be appreciated.
Thanks,
Rhys | Here is the full process from the command line:
```
evan@vbox ~> cat test.scala
object test{
def main(args: Array[String]): Unit = println("Hello!")
}
evan@vbox ~> scalac test.scala
evan@vbox ~> scala test
Hello!
```
However if you want to use Scala IDE to its full potential I would check out [this tutorial](http... |
40845452 | Specify which shell to use in R | 6 | 2016-11-28 13:25:52 | <p>I have to run a shell script inside R. I've considered using R's <code>system</code> function. </p>
<p>However, my script involves <code>source activate</code> and other commands that are not available in /bin/sh shell. Is there a way I can use /bin/bash instead?</p>
<p>Thanks!</p>
| 3,575 | 1,846,042 | 2016-11-28 16:52:59 | 40,845,667 | 12 | 2016-11-28 13:37:55 | 1,646,322 | 2016-11-28 16:52:59 | https://stackoverflow.com/q/40845452 | https://stackoverflow.com/a/40845667 | <p>Invoke <code>/bin/bash</code>, and pass the commands via <code>-c</code> option in one of the following ways:</p>
<pre><code>system(paste("/bin/bash -c", shQuote("Bash commands")))
system2("/bin/bash", args = c("-c", shQuote("Bash commands")))
</code></pre>
<p>If you only want to run a Bash <em>file</em>, supply i... | <p>Invoke <code>/bin/bash</code>, and pass the commands via <code>-c</code> option in one of the following ways:</p> <pre><code>system(paste("/bin/bash -c", shQuote("Bash commands"))) system2("/bin/bash", args = c("-c", shQuote("Bash commands"))) </code></pre> <p>If you only want to run a Bash <em>file</em>, supply i... | 387, 390, 4452 | bash, r, shell | <h1>Specify which shell to use in R</h1>
<p>I have to run a shell script inside R. I've considered using R's <code>system</code> function. </p>
<p>However, my script involves <code>source activate</code> and other commands that are not available in /bin/sh shell. Is there a way I can use /bin/bash instead?</p>
<p>Th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,094 | bash | # Specify which shell to use in R
I have to run a shell script inside R. I've considered using R's `system` function.
However, my script involves `source activate` and other commands that are not available in /bin/sh shell. Is there a way I can use /bin/bash instead?
Thanks! | Invoke `/bin/bash`, and pass the commands via `-c` option in one of the following ways:
```
system(paste("/bin/bash -c", shQuote("Bash commands")))
system2("/bin/bash", args = c("-c", shQuote("Bash commands")))
```
If you only want to run a Bash *file*, supply it with a [shebang](https://en.wikipedia.org/wiki/Shebang... |
38221908 | how to store result of tail command in variable? | 6 | 2016-07-06 10:34:09 | <p>I am developing application in MEAN stack. I want to create a script of image resizing & cropping as a background process when new image uploads to server.</p>
<p>Script watches new image uploads in folder and crop it.</p>
<p>I preferred way of Linux shell scripting as daemon.</p>
<p>I have used following ide... | 16,955 | 4,030,664 | 2016-07-06 10:36:48 | 38,221,958 | 12 | 2016-07-06 10:36:48 | 699,305 | 2016-07-06 10:36:48 | https://stackoverflow.com/q/38221908 | https://stackoverflow.com/a/38221958 | <p>Since <code>tail -f</code> doesn't terminate, you don't want to capture its output in a variable. But since you call it in a loop anyway, call it over and over like this:</p>
<pre><code>OUT=`tail "$path"`
</code></pre>
<p>Or using the modern syntax:</p>
<pre><code>OUT=$(tail "$path")
</code></pre>
| <p>Since <code>tail -f</code> doesn't terminate, you don't want to capture its output in a variable. But since you call it in a loop anyway, call it over and over like this:</p> <pre><code>OUT=`tail "$path"` </code></pre> <p>Or using the modern syntax:</p> <pre><code>OUT=$(tail "$path") </code></pre> | 58, 390, 7896 | linux, shell, tail | <h1>how to store result of tail command in variable?</h1>
<p>I am developing application in MEAN stack. I want to create a script of image resizing & cropping as a background process when new image uploads to server.</p>
<p>Script watches new image uploads in folder and crop it.</p>
<p>I preferred way of Linux sh... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,095 | bash | # how to store result of tail command in variable?
I am developing application in MEAN stack. I want to create a script of image resizing & cropping as a background process when new image uploads to server.
Script watches new image uploads in folder and crop it.
I preferred way of Linux shell scripting as daemon.
I... | Since `tail -f` doesn't terminate, you don't want to capture its output in a variable. But since you call it in a loop anyway, call it over and over like this:
```
OUT=`tail "$path"`
```
Or using the modern syntax:
```
OUT=$(tail "$path")
``` |
38045360 | Run block of bash / shell in node's spawn | 6 | 2016-06-27 03:11:57 | <p>I'm writing a command line utility, and I need stdout to write to TTY or use <code>{stdio: 'inherit'}</code> I've been getting by with <code>exec</code> but it's not going to cut it. I need way for a spawn process to execute the following echo commands below. I know that spawn spins up a child process with a given c... | 5,167 | 340,688 | 2016-06-27 03:33:33 | 38,045,467 | 12 | 2016-06-27 03:27:55 | 45,375 | 2016-06-27 03:33:33 | https://stackoverflow.com/q/38045360 | https://stackoverflow.com/a/38045467 | <p><code>spawn()</code> does <em>not</em> involve a shell, so in order to have it execute shell commands, you must invoke the shell executable <em>explicitly</em> and pass the shell command(s) as an <em>argument</em>:</p>
<pre><code>const child = spawn('/bin/sh', [ '-c', `
echo "alpha"
echo "beta"
` ])
</code></pre>
... | <p><code>spawn()</code> does <em>not</em> involve a shell, so in order to have it execute shell commands, you must invoke the shell executable <em>explicitly</em> and pass the shell command(s) as an <em>argument</em>:</p> <pre><code>const child = spawn('/bin/sh', [ '-c', ` echo "alpha" echo "beta" ` ]) </code></pre> ... | 387, 390, 26115, 46426 | bash, child-process, node.js, shell | <h1>Run block of bash / shell in node's spawn</h1>
<p>I'm writing a command line utility, and I need stdout to write to TTY or use <code>{stdio: 'inherit'}</code> I've been getting by with <code>exec</code> but it's not going to cut it. I need way for a spawn process to execute the following echo commands below. I know... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,096 | bash | # Run block of bash / shell in node's spawn
I'm writing a command line utility, and I need stdout to write to TTY or use `{stdio: 'inherit'}` I've been getting by with `exec` but it's not going to cut it. I need way for a spawn process to execute the following echo commands below. I know that spawn spins up a child pr... | `spawn()` does *not* involve a shell, so in order to have it execute shell commands, you must invoke the shell executable *explicitly* and pass the shell command(s) as an *argument*:
```
const child = spawn('/bin/sh', [ '-c', `
echo "alpha"
echo "beta"
` ])
```
Note I've used `/bin/sh` rather than `/bin/bash` in an ... |
37579921 | bash: "which adb" returns nothing, but "command -v adb" returns what i'd expect | 6 | 2016-06-01 22:37:25 | <p>This is a bash weirdness that's been bugging me.</p>
<p>I'm on OSX.</p>
<p>I've installed the android SDK, and as a result the <code>adb</code> tool is located in a folder in my home directory. That folder appears in my path as reported by <code>env</code> as <code>~/Development/android_sdk_latest/platform-tools</... | 2,038 | 230,851 | 2021-01-20 16:13:23 | 37,580,022 | 12 | 2016-06-01 22:49:14 | 827,263 | 2019-08-11 22:27:14 | https://stackoverflow.com/q/37579921 | https://stackoverflow.com/a/37580022 | <p>You've run into a subtle incompatibility between <code>/bin/bash</code> and the <code>which</code> command.</p>
<p>On my system (Linux Mint), the <code>which</code> command is actually a shell script, not a built-in command, and its first line is <code>#! /bin/sh</code>. That means that it uses <code>/bin/sh</code>... | <p>You've run into a subtle incompatibility between <code>/bin/bash</code> and the <code>which</code> command.</p> <p>On my system (Linux Mint), the <code>which</code> command is actually a shell script, not a built-in command, and its first line is <code>#! /bin/sh</code>. That means that it uses <code>/bin/sh</code>... | 369, 387, 1796, 6268 | bash, command, macos, path | <h1>bash: "which adb" returns nothing, but "command -v adb" returns what i'd expect</h1>
<p>This is a bash weirdness that's been bugging me.</p>
<p>I'm on OSX.</p>
<p>I've installed the android SDK, and as a result the <code>adb</code> tool is located in a folder in my home directory. That folder appears in my path a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,097 | bash | # bash: "which adb" returns nothing, but "command -v adb" returns what i'd expect
This is a bash weirdness that's been bugging me.
I'm on OSX.
I've installed the android SDK, and as a result the `adb` tool is located in a folder in my home directory. That folder appears in my path as reported by `env` as `~/Developm... | You've run into a subtle incompatibility between `/bin/bash` and the `which` command.
On my system (Linux Mint), the `which` command is actually a shell script, not a built-in command, and its first line is `#! /bin/sh`. That means that it uses `/bin/sh`'s handling of the `$PATH` variable.
This can vary depending on ... |
36941027 | How to return PowerShell variable to VBScript | 6 | 2016-04-29 14:33:17 | <p>I have a vbscript to call a PowerShell script in hopes of returning the PowerShell output to an HTA (HTML Application) GUI. Right now I just want to see if I can return the PowerShell output into a MsgBox in the vbscript. I am not having much luck with this.</p>
<p>VBScript Code: </p>
<pre><code>Set shell = Create... | 13,927 | 5,792,155 | 2019-09-01 02:40:43 | 36,941,633 | 12 | 2016-04-29 15:00:04 | 1,371,040 | 2016-04-29 16:02:59 | https://stackoverflow.com/q/36941027 | https://stackoverflow.com/a/36941633 | <p>I think you just want the <em>exit</em> command to get the return value:</p>
<p><strong>VBScript</strong></p>
<pre><code>pscommand = ".\myscript.ps1; exit $LASTEXITCODE"
cmd = "powershell.exe -noprofile -command " & pscommand
Set shell = CreateObject("WScript.Shell")
rv = shell.Run(cmd, , True)
MsgBox "PowerSh... | <p>I think you just want the <em>exit</em> command to get the return value:</p> <p><strong>VBScript</strong></p> <pre><code>pscommand = ".\myscript.ps1; exit $LASTEXITCODE" cmd = "powershell.exe -noprofile -command " & pscommand Set shell = CreateObject("WScript.Shell") rv = shell.Run(cmd, , True) MsgBox "PowerSh... | 494, 526, 11000 | hta, powershell, vbscript | <h1>How to return PowerShell variable to VBScript</h1>
<p>I have a vbscript to call a PowerShell script in hopes of returning the PowerShell output to an HTA (HTML Application) GUI. Right now I just want to see if I can return the PowerShell output into a MsgBox in the vbscript. I am not having much luck with this.</p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,098 | bash | # How to return PowerShell variable to VBScript
I have a vbscript to call a PowerShell script in hopes of returning the PowerShell output to an HTA (HTML Application) GUI. Right now I just want to see if I can return the PowerShell output into a MsgBox in the vbscript. I am not having much luck with this.
VBScript Co... | I think you just want the *exit* command to get the return value:
**VBScript**
```
pscommand = ".\myscript.ps1; exit $LASTEXITCODE"
cmd = "powershell.exe -noprofile -command " & pscommand
Set shell = CreateObject("WScript.Shell")
rv = shell.Run(cmd, , True)
MsgBox "PowerShell returned: " & rv, vbSystemModal
```
**Po... |
36116326 | Programmatically change PowerShell's 16 default console colours | 6 | 2016-03-20 16:25:33 | <p>PowerShell improves on the (frankly) fugly Windows Console colour scheme by assigning a bluish value to one of its 16 console colours ( - the one known as DarkMagenta for some reason - ), and uses this as the default screen background.</p>
<p>I want to programmatically change each of the 16 colours to a custom colo... | 8,082 | 4,171,861 | 2025-11-03 00:06:23 | 36,118,181 | 12 | 2016-03-20 19:04:24 | 702,944 | 2016-03-20 19:27:18 | https://stackoverflow.com/q/36116326 | https://stackoverflow.com/a/36118181 | <p>The console colors are defined in multiple places:</p>
<ul>
<li><strong>Global/Default</strong>: <code>HKCU:\Console</code>. This applies to all <code>conhost.exe</code>-applications including <code>cmd.exe</code> and <code>powershell.exe</code>.</li>
<li><strong>Per process:</strong> <code>HKCU:\Console\<PROCES... | <p>The console colors are defined in multiple places:</p> <ul> <li><strong>Global/Default</strong>: <code>HKCU:\Console</code>. This applies to all <code>conhost.exe</code>-applications including <code>cmd.exe</code> and <code>powershell.exe</code>.</li> <li><strong>Per process:</strong> <code>HKCU:\Console\<PROCES... | 526, 964, 6439 | colors, customization, powershell | <h1>Programmatically change PowerShell's 16 default console colours</h1>
<p>PowerShell improves on the (frankly) fugly Windows Console colour scheme by assigning a bluish value to one of its 16 console colours ( - the one known as DarkMagenta for some reason - ), and uses this as the default screen background.</p>
<p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,099 | bash | # Programmatically change PowerShell's 16 default console colours
PowerShell improves on the (frankly) fugly Windows Console colour scheme by assigning a bluish value to one of its 16 console colours ( - the one known as DarkMagenta for some reason - ), and uses this as the default screen background.
I want to progra... | The console colors are defined in multiple places:
- **Global/Default**: `HKCU:\Console`. This applies to all `conhost.exe`-applications including `cmd.exe` and `powershell.exe`.
- **Per process:** `HKCU:\Console\<PROCESS_PATH_WITH_UNDESCORE>` for process-specific changes. Ex. `HKEY_CURRENT_USER\Console\%SystemRoot%_S... |
34625440 | Using .NET objects within a Powershell (V5) class | 6 | 2016-01-06 04:04:31 | <p>Below is the exact code that I am having trouble with.</p>
<p>A brief description:</p>
<p>I am trying to set up a PowerShell class that will hold objects of different types for easy access. I've done this numerous times in C#, so I thought it would be fairly straight forward. The types wanted are [System.Printing] a... | 6,743 | 4,139,796 | 2022-12-31 16:13:58 | 34,637,458 | 12 | 2016-01-06 16:03:59 | 4,003,407 | 2021-12-28 01:51:30 | https://stackoverflow.com/q/34625440 | https://stackoverflow.com/a/34637458 |
<p>Every PowerShell script is completely parsed before the first statement in the script is executed. An unresolvable type name token inside a class definition is considered a parse error. To solve your problem, you have to load your types before the class definition is parsed, so the class definition has to be in a s... | <p>Every PowerShell script is completely parsed before the first statement in the script is executed. An unresolvable type name token inside a class definition is considered a parse error. To solve your problem, you have to load your types before the class definition is parsed, so the class definition has to be in a s... | 1, 526 | .net, powershell | <h1>Using .NET objects within a Powershell (V5) class</h1>
<p>Below is the exact code that I am having trouble with.</p>
<p>A brief description:</p>
<p>I am trying to set up a PowerShell class that will hold objects of different types for easy access. I've done this numerous times in C#, so I thought it would be fairly... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,100 | bash | # Using .NET objects within a Powershell (V5) class
Below is the exact code that I am having trouble with.
A brief description:
I am trying to set up a PowerShell class that will hold objects of different types for easy access. I've done this numerous times in C#, so I thought it would be fairly straight forward. Th... | Every PowerShell script is completely parsed before the first statement in the script is executed. An unresolvable type name token inside a class definition is considered a parse error. To solve your problem, you have to load your types before the class definition is parsed, so the class definition has to be in a separ... |
34301171 | Format perl regex capture groups | 6 | 2015-12-15 23:07:17 | <p>Consider the following situation. It is hypothetical, but demonstrates a general thing I would like accomplished.</p>
<p>Suppose I have a file, which has one or more lines. On each line, it may have one or more instances of <code>[name]</code>=<code>[value]</code>, where <code>[name]</code> is some variable name ... | 3,801 | 513,038 | 2015-12-16 22:40:48 | 34,301,592 | 12 | 2015-12-15 23:45:47 | 82,262 | 2015-12-16 00:37:48 | https://stackoverflow.com/q/34301171 | https://stackoverflow.com/a/34301592 | <p>You were pretty close. ;-)</p>
<pre><code>$ perl -ne 'print "name: $1, value: $2\n" while /([a-zA-Z]+)=([0-9]+)/g;' test.txt
name: count, value: 5
name: i, value: 1
name: books, value: 2
name: fairies, value: 87
name: water, value: 0
</code></pre>
<p>Edit: since your <a href="https://stackoverflow.com/questions/34... | <p>You were pretty close. ;-)</p> <pre><code>$ perl -ne 'print "name: $1, value: $2\n" while /([a-zA-Z]+)=([0-9]+)/g;' test.txt name: count, value: 5 name: i, value: 1 name: books, value: 2 name: fairies, value: 87 name: water, value: 0 </code></pre> <p>Edit: since your <a href="https://stackoverflow.com/questions/34... | 18, 387, 580 | bash, perl, regex | <h1>Format perl regex capture groups</h1>
<p>Consider the following situation. It is hypothetical, but demonstrates a general thing I would like accomplished.</p>
<p>Suppose I have a file, which has one or more lines. On each line, it may have one or more instances of <code>[name]</code>=<code>[value]</code>, where ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,101 | bash | # Format perl regex capture groups
Consider the following situation. It is hypothetical, but demonstrates a general thing I would like accomplished.
Suppose I have a file, which has one or more lines. On each line, it may have one or more instances of `[name]`=`[value]`, where `[name]` is some variable name and `[val... | You were pretty close. ;-)
```
$ perl -ne 'print "name: $1, value: $2\n" while /([a-zA-Z]+)=([0-9]+)/g;' test.txt
name: count, value: 5
name: i, value: 1
name: books, value: 2
name: fairies, value: 87
name: water, value: 0
```
Edit: since your [comment](https://stackoverflow.com/questions/34301171/format-perl-regex-c... |
32186056 | Zsh - split string by spaces when using dot operator | 6 | 2015-08-24 15:27:22 | <p>Here is my script:</p>
<pre><code>#/bin/bash
list="a b c"
for i in $list; do
echo $i
done
</code></pre>
<p>This works:</p>
<pre><code>➜ ~ ./lol.sh
a
b
c
</code></pre>
<p>This doesn't:</p>
<pre><code>➜ ~ . ./lol.sh
a b c
</code></pre>
<p>Why split does not work with dot command and how can I fix it?</p>... | 9,094 | 227,024 | 2021-01-16 01:18:50 | 32,186,224 | 12 | 2015-08-24 15:34:45 | 14,122 | 2020-05-03 16:56:21 | https://stackoverflow.com/q/32186056 | https://stackoverflow.com/a/32186224 | <p>Lists should never be represented as strings. Use array syntax.</p>
<pre><code>list=( a b c )
for i in "${list[@]}"; do
echo "$i"
done
</code></pre>
<hr>
<p>There are several reasons this is preferable.</p>
<h1>In ZSH:</h1>
<ul>
<li>ZSH breaks POSIX by not performing string-splitting at all on unquoted expans... | <p>Lists should never be represented as strings. Use array syntax.</p> <pre><code>list=( a b c ) for i in "${list[@]}"; do echo "$i" done </code></pre> <hr> <p>There are several reasons this is preferable.</p> <h1>In ZSH:</h1> <ul> <li>ZSH breaks POSIX by not performing string-splitting at all on unquoted expans... | 390, 531, 2193, 3791 | scripting, shell, split, zsh | <h1>Zsh - split string by spaces when using dot operator</h1>
<p>Here is my script:</p>
<pre><code>#/bin/bash
list="a b c"
for i in $list; do
echo $i
done
</code></pre>
<p>This works:</p>
<pre><code>➜ ~ ./lol.sh
a
b
c
</code></pre>
<p>This doesn't:</p>
<pre><code>➜ ~ . ./lol.sh
a b c
</code></pre>
<p>Why ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,102 | bash | # Zsh - split string by spaces when using dot operator
Here is my script:
```
#/bin/bash
list="a b c"
for i in $list; do
echo $i
done
```
This works:
```
➜ ~ ./lol.sh
a
b
c
```
This doesn't:
```
➜ ~ . ./lol.sh
a b c
```
Why split does not work with dot command and how can I fix it? | Lists should never be represented as strings. Use array syntax.
```
list=( a b c )
for i in "${list[@]}"; do
echo "$i"
done
```
---
There are several reasons this is preferable.
# In ZSH:
- ZSH breaks POSIX by not performing string-splitting at all on unquoted expansions unless they explicitly request it. You ca... |
32000064 | What is the difference b/w Bash and Shell script | 6 | 2015-08-13 23:27:44 | <p>I've been writing scripts for both UNIX and Windows for almost 3 years now. I've always been confused about these two terms, for a while I thought that bash scripts were windows cmd scripts and shell scripts were UNIX scripts, but I've learned that this is not correct. So what is the difference between these two ter... | 9,664 | 4,558,644 | 2023-12-01 00:07:22 | 32,000,133 | 12 | 2015-08-13 23:36:27 | 827,263 | 2023-12-01 00:07:22 | https://stackoverflow.com/q/32000064 | https://stackoverflow.com/a/32000133 | <p>"Shell script" is generic term for a script that's executed by a <a href="https://en.wikipedia.org/wiki/Shell_(computing)" rel="nofollow noreferrer">shell</a>.</p>
<p>"Bash script" is a more specific term; it refers to a script that's executed by one specific shell, the <a href="http://www.gnu.or... | <p>"Shell script" is generic term for a script that's executed by a <a href="https://en.wikipedia.org/wiki/Shell_(computing)" rel="nofollow noreferrer">shell</a>.</p> <p>"Bash script" is a more specific term; it refers to a script that's executed by one specific shell, the <a href="http://www.gnu.or... | 58, 387, 390, 531, 2631 | bash, cmd, linux, scripting, shell | <h1>What is the difference b/w Bash and Shell script</h1>
<p>I've been writing scripts for both UNIX and Windows for almost 3 years now. I've always been confused about these two terms, for a while I thought that bash scripts were windows cmd scripts and shell scripts were UNIX scripts, but I've learned that this is no... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,103 | bash | # What is the difference b/w Bash and Shell script
I've been writing scripts for both UNIX and Windows for almost 3 years now. I've always been confused about these two terms, for a while I thought that bash scripts were windows cmd scripts and shell scripts were UNIX scripts, but I've learned that this is not correct... | "Shell script" is generic term for a script that's executed by a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).
"Bash script" is a more specific term; it refers to a script that's executed by one specific shell, the [Bash shell](http://www.gnu.org/software/bash/).
A shell is a command interpreter program. ... |
31778704 | How to remove First and Last Line in Powershell | 6 | 2015-08-03 02:40:19 | <p>This script will do some processing on csv file notably removing first line (subsequent to <a href="https://stackoverflow.com/questions/31732889/how-to-export-to-non-standard-csv-with-powershell">How to export to "non-standard" CSV with Powershell</a> ) :</p>
<pre><code>Import-Csv in.csv -header Date,Time... | 23,162 | 310,291 | 2017-12-05 17:01:13 | 31,779,491 | 12 | 2015-08-03 04:34:26 | 153,982 | 2017-05-15 12:18:10 | https://stackoverflow.com/q/31778704 | https://stackoverflow.com/a/31779491 | <p>Depending on the version of PowerShell you have, you can use the <code>-SkipLast</code> parameter, e.g.:</p>
<pre><code>... | Select -Skip 1 | Select -SkipLast 1
</code></pre>
<p><code>SkipLast</code> is available for PowerShell 5.0 and higher. </p>
<p>If you don't have that parameter, you can install it via the ... | <p>Depending on the version of PowerShell you have, you can use the <code>-SkipLast</code> parameter, e.g.:</p> <pre><code>... | Select -Skip 1 | Select -SkipLast 1 </code></pre> <p><code>SkipLast</code> is available for PowerShell 5.0 and higher. </p> <p>If you don't have that parameter, you can install it via the ... | 526 | powershell | <h1>How to remove First and Last Line in Powershell</h1>
<p>This script will do some processing on csv file notably removing first line (subsequent to <a href="https://stackoverflow.com/questions/31732889/how-to-export-to-non-standard-csv-with-powershell">How to export to "non-standard" CSV with Powershell</a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,104 | bash | # How to remove First and Last Line in Powershell
This script will do some processing on csv file notably removing first line (subsequent to [How to export to "non-standard" CSV with Powershell](https://stackoverflow.com/questions/31732889/how-to-export-to-non-standard-csv-with-powershell) ) :
```
Import-Csv in.csv -... | Depending on the version of PowerShell you have, you can use the `-SkipLast` parameter, e.g.:
```
... | Select -Skip 1 | Select -SkipLast 1
```
`SkipLast` is available for PowerShell 5.0 and higher.
If you don't have that parameter, you can install it via the Microsoft Website. Windows 7 is the earliest OS version t... |
31732348 | How to disable line breaks in bc? | 6 | 2015-07-30 19:22:15 | <p>Is there a way to disable <code>bc</code>'s feature of splitting long numbers into several lines, something like <code>scale</code> variable for controlling decimal places? Sure, I can use <code>sed</code>, but is there a <code>bc</code> way of doing that? Man page at <a href="http://www.gnu.org/software/bc/manual/h... | 4,050 | 815,741 | 2015-07-30 19:58:18 | 31,732,480 | 12 | 2015-07-30 19:30:35 | 1,426,891 | 2015-07-30 19:58:18 | https://stackoverflow.com/q/31732348 | https://stackoverflow.com/a/31732480 | <p>The <a href="http://www.gnu.org/software/bc/manual/html_mono/bc.html#SEC23" rel="noreferrer">online bc man page</a> doesn't match what I have under "Environment Variables"; the man page for my version (v1.06.95) dated 2006-06-11 claims that you can set BC_LINE_LENGTH=0 to disable line breaks, as a GNU-specific exten... | <p>The <a href="http://www.gnu.org/software/bc/manual/html_mono/bc.html#SEC23" rel="noreferrer">online bc man page</a> doesn't match what I have under "Environment Variables"; the man page for my version (v1.06.95) dated 2006-06-11 claims that you can set BC_LINE_LENGTH=0 to disable line breaks, as a GNU-specific exten... | 387, 9313, 34696 | bash, bc, line-breaks | <h1>How to disable line breaks in bc?</h1>
<p>Is there a way to disable <code>bc</code>'s feature of splitting long numbers into several lines, something like <code>scale</code> variable for controlling decimal places? Sure, I can use <code>sed</code>, but is there a <code>bc</code> way of doing that? Man page at <a hr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,105 | bash | # How to disable line breaks in bc?
Is there a way to disable `bc`'s feature of splitting long numbers into several lines, something like `scale` variable for controlling decimal places? Sure, I can use `sed`, but is there a `bc` way of doing that? Man page at <http://www.gnu.org/software/bc/manual/html_mono/bc.html> ... | The [online bc man page](http://www.gnu.org/software/bc/manual/html_mono/bc.html#SEC23) doesn't match what I have under "Environment Variables"; the man page for my version (v1.06.95) dated 2006-06-11 claims that you can set BC_LINE_LENGTH=0 to disable line breaks, as a GNU-specific extension:
> BC_LINE_LENGTH
>
> Thi... |
31003079 | How do I view the list of commits that haven't been pushed yet? | 6 | 2015-06-23 12:40:06 | <p>I like documenting minor changes as separate commits and finally use <code>git interactive --rebase</code> to combine commits and change commit messages like I deem appropriate. </p>
<p>Is there a way to determine which commits I haven't pushed yet <strong>without manually checking Github</strong> i.e. is there a w... | 1,414 | 3,281,476 | 2015-06-23 12:49:32 | 31,003,150 | 12 | 2015-06-23 12:44:05 | 724,411 | 2015-06-23 12:44:05 | https://stackoverflow.com/q/31003079 | https://stackoverflow.com/a/31003150 | <p>If you do a <code>git log origin/master..HEAD</code>, it should show you all the commits that have not been pushed (assuming you are on master, of course). </p>
| <p>If you do a <code>git log origin/master..HEAD</code>, it should show you all the commits that have not been pushed (assuming you are on master, of course). </p> | 119, 61874 | git, git-bash | <h1>How do I view the list of commits that haven't been pushed yet?</h1>
<p>I like documenting minor changes as separate commits and finally use <code>git interactive --rebase</code> to combine commits and change commit messages like I deem appropriate. </p>
<p>Is there a way to determine which commits I haven't pushe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,106 | bash | # How do I view the list of commits that haven't been pushed yet?
I like documenting minor changes as separate commits and finally use `git interactive --rebase` to combine commits and change commit messages like I deem appropriate.
Is there a way to determine which commits I haven't pushed yet **without manually che... | If you do a `git log origin/master..HEAD`, it should show you all the commits that have not been pushed (assuming you are on master, of course). |
30505707 | Docker Ubuntu image missing prompt, color and completion? | 6 | 2015-05-28 11:46:23 | <p>If I create a new Docker image based from <code>ubuntu:14.04</code> image and run it with:</p>
<pre><code>docker run -i --name="TEST" ubuntu:14.04 /bin/bash
</code></pre>
<p>then I will have a minimalistic Ubuntu with Bash running, but I won't get a prompt and the auto-completion for files/folders does not work. A... | 2,323 | 2,138,851 | 2015-05-28 11:53:17 | 30,505,873 | 12 | 2015-05-28 11:53:17 | 1,911,099 | 2015-05-28 11:53:17 | https://stackoverflow.com/q/30505707 | https://stackoverflow.com/a/30505873 | <p>You're missing <code>-t</code> flag to allocate a pseudo-tty for your container:</p>
<p><code>docker run -it --name="TEST" ubuntu:14.04 /bin/bash</code></p>
| <p>You're missing <code>-t</code> flag to allocate a pseudo-tty for your container:</p> <p><code>docker run -it --name="TEST" ubuntu:14.04 /bin/bash</code></p> | 387, 549, 90304, 108477 | bash, docker, dockerfile, ubuntu | <h1>Docker Ubuntu image missing prompt, color and completion?</h1>
<p>If I create a new Docker image based from <code>ubuntu:14.04</code> image and run it with:</p>
<pre><code>docker run -i --name="TEST" ubuntu:14.04 /bin/bash
</code></pre>
<p>then I will have a minimalistic Ubuntu with Bash running, but I won't get ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,107 | bash | # Docker Ubuntu image missing prompt, color and completion?
If I create a new Docker image based from `ubuntu:14.04` image and run it with:
```
docker run -i --name="TEST" ubuntu:14.04 /bin/bash
```
then I will have a minimalistic Ubuntu with Bash running, but I won't get a prompt and the auto-completion for files/f... | You're missing `-t` flag to allocate a pseudo-tty for your container:
`docker run -it --name="TEST" ubuntu:14.04 /bin/bash` |
29204103 | Wget does not fetch google search results | 6 | 2015-03-23 06:04:06 | <p>I noticed when running <code>wget https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=foo</code> and similar queries, I don't get the search results, but the google homepage. </p>
<p>There seems to be some redirect within the google page. Does anyone know a fix to <code>wget</co... | 11,019 | null | 2015-05-21 14:03:45 | 29,204,248 | 12 | 2015-03-23 06:17:54 | 548,225 | 2015-03-23 06:17:54 | https://stackoverflow.com/q/29204103 | https://stackoverflow.com/a/29204248 | <p>You can use this curl commands to pull Google query results:</p>
<pre><code>curl -sA "Chrome" -L 'http://www.google.com/search?hl=en&q=time' -o search.html
</code></pre>
<p>For using <code>https</code> URL:</p>
<pre><code>curl -k -sA "Chrome" -L 'https://www.google.com/search?hl=en&q=time' -o ssearch.html... | <p>You can use this curl commands to pull Google query results:</p> <pre><code>curl -sA "Chrome" -L 'http://www.google.com/search?hl=en&q=time' -o search.html </code></pre> <p>For using <code>https</code> URL:</p> <pre><code>curl -k -sA "Chrome" -L 'https://www.google.com/search?hl=en&q=time' -o ssearch.html... | 387, 5583 | bash, wget | <h1>Wget does not fetch google search results</h1>
<p>I noticed when running <code>wget https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=foo</code> and similar queries, I don't get the search results, but the google homepage. </p>
<p>There seems to be some redirect within the go... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,108 | bash | # Wget does not fetch google search results
I noticed when running `wget https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=foo` and similar queries, I don't get the search results, but the google homepage.
There seems to be some redirect within the google page. Does anyone know a fix to `wg... | You can use this curl commands to pull Google query results:
```
curl -sA "Chrome" -L 'http://www.google.com/search?hl=en&q=time' -o search.html
```
For using `https` URL:
```
curl -k -sA "Chrome" -L 'https://www.google.com/search?hl=en&q=time' -o ssearch.html
```
`-A` option sets a custom user-agent `Chrome` in re... |
28055346 | Bash unbound variable array (script: s3-bash) | 6 | 2015-01-20 21:20:20 | <p>I am working with: <a href="https://code.google.com/p/s3-bash/" rel="noreferrer" title="s3-bash">s3-bash</a>, when I run it in my local environment (<code>OS X 10.10.1</code>) I don't have any problems, when I try to run it on a <code>ubuntu server 14.04.1</code> I get the following error: </p>
<pre><code>./s3-comm... | 7,333 | 216,194 | 2022-11-11 14:43:13 | 28,058,737 | 12 | 2015-01-21 02:43:01 | 258,523 | 2015-03-18 22:58:29 | https://stackoverflow.com/q/28055346 | https://stackoverflow.com/a/28058737 | <p>There appears to be a bash behaviour change at play here.</p>
<p>Found by kojiro: <a href="http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n559" rel="noreferrer">CHANGES</a></p>
<blockquote>
<p>hhhh. Fixed a bug that caused `declare' and `test' to find variables that
had been given attributes but ... | <p>There appears to be a bash behaviour change at play here.</p> <p>Found by kojiro: <a href="http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n559" rel="noreferrer">CHANGES</a></p> <blockquote> <p>hhhh. Fixed a bug that caused `declare' and `test' to find variables that had been given attributes but ... | 387 | bash | <h1>Bash unbound variable array (script: s3-bash)</h1>
<p>I am working with: <a href="https://code.google.com/p/s3-bash/" rel="noreferrer" title="s3-bash">s3-bash</a>, when I run it in my local environment (<code>OS X 10.10.1</code>) I don't have any problems, when I try to run it on a <code>ubuntu server 14.04.1</code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,109 | bash | # Bash unbound variable array (script: s3-bash)
I am working with: [s3-bash](https://code.google.com/p/s3-bash/ "s3-bash"), when I run it in my local environment (`OS X 10.10.1`) I don't have any problems, when I try to run it on a `ubuntu server 14.04.1` I get the following error:
```
./s3-common-functions: line 66:... | There appears to be a bash behaviour change at play here.
Found by kojiro: [CHANGES](http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n559)
> hhhh. Fixed a bug that caused `declare' and `test' to find variables that
> had been given attributes but not assigned values. Such variables are
> not set.
```
$ bash -... |
27954717 | Is there a way to run a JavaScript file inside the Node.js shell? | 6 | 2015-01-15 00:02:13 | <p>I am new to <code>Node.js</code> and I was wondering if there was a way of executing a <code>JavaScript</code> file from inside the Node shell. Let me explain it this way:</p>
<p>Instead of doing this:</p>
<p><code>$ node file.js</code></p>
<p>which will execute the script but will close the Node shell afterwards... | 6,838 | 3,023,947 | 2015-01-22 15:40:38 | 27,954,882 | 12 | 2015-01-15 00:19:27 | 3,023,947 | 2015-01-15 00:19:27 | https://stackoverflow.com/q/27954717 | https://stackoverflow.com/a/27954882 | <p>Executing the following command inside <code>Node.js</code> Shell worked:</p>
<pre><code>.load foo.js
</code></pre>
| <p>Executing the following command inside <code>Node.js</code> Shell worked:</p> <pre><code>.load foo.js </code></pre> | 3, 390, 46426 | javascript, node.js, shell | <h1>Is there a way to run a JavaScript file inside the Node.js shell?</h1>
<p>I am new to <code>Node.js</code> and I was wondering if there was a way of executing a <code>JavaScript</code> file from inside the Node shell. Let me explain it this way:</p>
<p>Instead of doing this:</p>
<p><code>$ node file.js</code></p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,110 | bash | # Is there a way to run a JavaScript file inside the Node.js shell?
I am new to `Node.js` and I was wondering if there was a way of executing a `JavaScript` file from inside the Node shell. Let me explain it this way:
Instead of doing this:
`$ node file.js`
which will execute the script but will close the Node shel... | Executing the following command inside `Node.js` Shell worked:
```
.load foo.js
``` |
27842462 | Getting a file with hash (#) in path by curl | 6 | 2015-01-08 14:29:07 | <p>I want to use <code>curl</code> (v 7.22.0) to download some files from a server, where they name directories like <code>report#1</code>, <code>report#2</code>, etc. So i tried...</p>
<pre><code>curl sftp://sftp.example.com/report#1/main.png -u login:pass -o tmp.txt
</code></pre>
<p>...but <code>curl</code> gives m... | 5,798 | 4,106,160 | 2022-07-22 21:46:12 | 27,842,658 | 12 | 2015-01-08 14:39:50 | 3,776,858 | 2022-07-22 21:46:12 | https://stackoverflow.com/q/27842462 | https://stackoverflow.com/a/27842658 | <p>Try this:</p>
<p>Replace in URL <code>#</code> with <code>%23</code>.</p>
| <p>Try this:</p> <p>Replace in URL <code>#</code> with <code>%23</code>.</p> | 365, 387, 1554 | bash, curl, url | <h1>Getting a file with hash (#) in path by curl</h1>
<p>I want to use <code>curl</code> (v 7.22.0) to download some files from a server, where they name directories like <code>report#1</code>, <code>report#2</code>, etc. So i tried...</p>
<pre><code>curl sftp://sftp.example.com/report#1/main.png -u login:pass -o tmp.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,111 | bash | # Getting a file with hash (#) in path by curl
I want to use `curl` (v 7.22.0) to download some files from a server, where they name directories like `report#1`, `report#2`, etc. So i tried...
```
curl sftp://sftp.example.com/report#1/main.png -u login:pass -o tmp.txt
```
...but `curl` gives me *"no such file or dir... | Try this:
Replace in URL `#` with `%23`. |
26788831 | List of nodes in a particular node in .csproj file with Powershell | 6 | 2014-11-06 20:30:09 | <p>I would like to ask some help because I'm totally lost.</p>
<p>I would like to check whether nodes in a particular part of the .csproj files contains proper data or not. In the xml snippet below I would like to get back the value of the "title" under the PropertyGroup belongs to "Debug|x64" profile.</p>
<p><strong... | 5,083 | 825,968 | 2019-11-13 18:00:15 | 26,789,090 | 12 | 2014-11-06 20:46:57 | null | 2014-11-06 20:46:57 | https://stackoverflow.com/q/26788831 | https://stackoverflow.com/a/26789090 | <p>Do you have to use xpath? Otherwise I would suggest something like this:</p>
<pre><code>$file = [xml](gc .\test.csproj)
$file.Project.PropertyGroup | ? Condition -Like '*Debug|x64*' | select Title
</code></pre>
| <p>Do you have to use xpath? Otherwise I would suggest something like this:</p> <pre><code>$file = [xml](gc .\test.csproj) $file.Project.PropertyGroup | ? Condition -Like '*Debug|x64*' | select Title </code></pre> | 19, 526, 1227, 10101 | csproj, powershell, xml, xpath | <h1>List of nodes in a particular node in .csproj file with Powershell</h1>
<p>I would like to ask some help because I'm totally lost.</p>
<p>I would like to check whether nodes in a particular part of the .csproj files contains proper data or not. In the xml snippet below I would like to get back the value of the "ti... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,112 | bash | # List of nodes in a particular node in .csproj file with Powershell
I would like to ask some help because I'm totally lost.
I would like to check whether nodes in a particular part of the .csproj files contains proper data or not. In the xml snippet below I would like to get back the value of the "title" under the P... | Do you have to use xpath? Otherwise I would suggest something like this:
```
$file = [xml](gc .\test.csproj)
$file.Project.PropertyGroup | ? Condition -Like '*Debug|x64*' | select Title
``` |
5187242 | Encode a String to be used as shell argument | 6 | 2011-03-03 22:10:16 | <p>I need to use a name of file as an argument in linux shell command. The problem is, java gives me that name as it is, saving all that spaces and other characters, and thus shell complains. Is there a method to escape all those problematic characters before passing the string to shell?</p>
| 6,928 | 486,057 | 2020-09-03 10:00:27 | 26,538,384 | 12 | 2014-10-23 22:13:36 | 3,070,326 | 2014-10-23 22:20:30 | https://stackoverflow.com/q/5187242 | https://stackoverflow.com/a/26538384 | <p>Had the same problem, single quotes wasn't sufficient (as already pointed out by Robert)</p>
<p>Solution:</p>
<pre><code>import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
public class YourFancyClass {
public static final Escaper SHELL_ESCAPE;
static {
final Escaper... | <p>Had the same problem, single quotes wasn't sufficient (as already pointed out by Robert)</p> <p>Solution:</p> <pre><code>import com.google.common.escape.Escaper; import com.google.common.escape.Escapers; public class YourFancyClass { public static final Escaper SHELL_ESCAPE; static { final Escaper... | 17, 390, 4804 | escaping, java, shell | <h1>Encode a String to be used as shell argument</h1>
<p>I need to use a name of file as an argument in linux shell command. The problem is, java gives me that name as it is, saving all that spaces and other characters, and thus shell complains. Is there a method to escape all those problematic characters before passin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,113 | bash | # Encode a String to be used as shell argument
I need to use a name of file as an argument in linux shell command. The problem is, java gives me that name as it is, saving all that spaces and other characters, and thus shell complains. Is there a method to escape all those problematic characters before passing the str... | Had the same problem, single quotes wasn't sufficient (as already pointed out by Robert)
Solution:
```
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
public class YourFancyClass {
public static final Escaper SHELL_ESCAPE;
static {
final Escapers.Builder builder = E... |
26363230 | Catching mysqldump error in bash script | 6 | 2014-10-14 14:22:31 | <p>I'm currently trying to write a script that backs up several of my sites along with their databases.</p>
<p>All is working well but I'm trying to be a little cleverer with my log - basically, at the moment it will attempt to run mysqldump and will echo success or failure.</p>
<p>What I'd rather do is output the ac... | 7,409 | 1,717,445 | 2016-04-26 20:09:50 | 26,364,287 | 12 | 2014-10-14 15:12:52 | 874,188 | 2014-10-14 15:12:52 | https://stackoverflow.com/q/26363230 | https://stackoverflow.com/a/26364287 | <blockquote>
<p>So I added "2> $LOG_LOCATION |"</p>
</blockquote>
<p>This is an error -- the pipe character is superfluous, and changes the meaning from a simple redirection into a pipeline.</p>
<p>Anyway, the proper way to use <code>if</code> is to run the actual command whose success you want to check as the cond... | <blockquote> <p>So I added "2> $LOG_LOCATION |"</p> </blockquote> <p>This is an error -- the pipe character is superfluous, and changes the meaning from a simple redirection into a pipeline.</p> <p>Anyway, the proper way to use <code>if</code> is to run the actual command whose success you want to check as the cond... | 21, 379, 387, 390 | bash, error-handling, mysql, shell | <h1>Catching mysqldump error in bash script</h1>
<p>I'm currently trying to write a script that backs up several of my sites along with their databases.</p>
<p>All is working well but I'm trying to be a little cleverer with my log - basically, at the moment it will attempt to run mysqldump and will echo success or fai... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,114 | bash | # Catching mysqldump error in bash script
I'm currently trying to write a script that backs up several of my sites along with their databases.
All is working well but I'm trying to be a little cleverer with my log - basically, at the moment it will attempt to run mysqldump and will echo success or failure.
What I'd ... | > So I added "2> $LOG_LOCATION |"
This is an error -- the pipe character is superfluous, and changes the meaning from a simple redirection into a pipeline.
Anyway, the proper way to use `if` is to run the actual command whose success you want to check as the condition.
```
if mysqldump -u "$DB_USER" --password="$DB_... |
26157703 | "stdin: is not a tty" from cronjob | 6 | 2014-10-02 09:11:34 | <p>I'm getting the following mail every time I execute a specific cronjob. The called script runs fine when I'm calling it directly and even from cron. So the message I get is not an actual error, since the script does exactly what it is supposed to do.</p>
<p>Here is the cron.d entry:</p>
<pre><code>* * * * * ... | 20,375 | 226,496 | 2021-08-06 08:57:30 | 26,187,244 | 12 | 2014-10-03 21:44:25 | 2,231,691 | 2014-10-03 21:44:25 | https://stackoverflow.com/q/26157703 | https://stackoverflow.com/a/26187244 | <p>You actually have two questions here.</p>
<ol>
<li>Why it prints <code>stdin: is not a tty</code>?</li>
</ol>
<p>This warning message is printed by <code>bash -l</code>. The <code>-l</code> (<code>--login</code>) options asks <code>bash</code> to start the login shell, e.g. the one which is usually started when yo... | <p>You actually have two questions here.</p> <ol> <li>Why it prints <code>stdin: is not a tty</code>?</li> </ol> <p>This warning message is printed by <code>bash -l</code>. The <code>-l</code> (<code>--login</code>) options asks <code>bash</code> to start the login shell, e.g. the one which is usually started when yo... | 58, 387, 601 | bash, cron, linux | <h1>"stdin: is not a tty" from cronjob</h1>
<p>I'm getting the following mail every time I execute a specific cronjob. The called script runs fine when I'm calling it directly and even from cron. So the message I get is not an actual error, since the script does exactly what it is supposed to do.</p>
<p>Here is the cr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,115 | bash | # "stdin: is not a tty" from cronjob
I'm getting the following mail every time I execute a specific cronjob. The called script runs fine when I'm calling it directly and even from cron. So the message I get is not an actual error, since the script does exactly what it is supposed to do.
Here is the cron.d entry:
```... | You actually have two questions here.
1. Why it prints `stdin: is not a tty`?
This warning message is printed by `bash -l`. The `-l` (`--login`) options asks `bash` to start the login shell, e.g. the one which is usually started when you enter your password. In this case `bash` expects its `stdin` to be a real termin... |
25976065 | Escaping dollar sign and curly brace in Bash | 6 | 2014-09-22 14:04:41 | <p>I'm making a script that needs to write ${somestring} to a file.
The way I figured doing this was by escaping the dollar sign, but when it executes, the string ends up empty.</p>
<p>Is there a way to escape this correctly?</p>
<p>My code:</p>
<pre><code># \$\{somestring\} works, but leaves the \'s which I don't want... | 10,899 | 3,014,890 | 2025-05-27 01:53:11 | 25,976,158 | 12 | 2014-09-22 14:09:06 | 1,983,854 | 2014-09-22 14:09:06 | https://stackoverflow.com/q/25976065 | https://stackoverflow.com/a/25976158 | <p>Just use single quotes, so that <code>${}</code> won't be interpreted:</p>
<pre><code>$ myvar=5
$ echo 'this is ${myvar}'
this is ${myvar}
$ echo "this is ${myvar}"
this is 5
</code></pre>
<hr>
<p>Note, though, that your approach is working (at least to me on Bash):</p>
<pre><code>$ myvar=("Yes I require multipl... | <p>Just use single quotes, so that <code>${}</code> won't be interpreted:</p> <pre><code>$ myvar=5 $ echo 'this is ${myvar}' this is ${myvar} $ echo "this is ${myvar}" this is 5 </code></pre> <hr> <p>Note, though, that your approach is working (at least to me on Bash):</p> <pre><code>$ myvar=("Yes I require multipl... | 387, 390, 4804 | bash, escaping, shell | <h1>Escaping dollar sign and curly brace in Bash</h1>
<p>I'm making a script that needs to write ${somestring} to a file.
The way I figured doing this was by escaping the dollar sign, but when it executes, the string ends up empty.</p>
<p>Is there a way to escape this correctly?</p>
<p>My code:</p>
<pre><code># \$\{som... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,116 | bash | # Escaping dollar sign and curly brace in Bash
I'm making a script that needs to write ${somestring} to a file.
The way I figured doing this was by escaping the dollar sign, but when it executes, the string ends up empty.
Is there a way to escape this correctly?
My code:
```
# \$\{somestring\} works, but leaves the... | Just use single quotes, so that `${}` won't be interpreted:
```
$ myvar=5
$ echo 'this is ${myvar}'
this is ${myvar}
$ echo "this is ${myvar}"
this is 5
```
---
Note, though, that your approach is working (at least to me on Bash):
```
$ myvar=("Yes I require multiple lines.
test \${somestring} test");
$ echo "$my... |
25570510 | Get all git branches that matches regex and split it into array | 6 | 2014-08-29 14:34:26 | <p>I'm trying to get from my git repo all branches (<code>git branches -a</code>) that matches regex (<code>grep xxx</code>).</p>
<p>Normally in command line I write this:</p>
<pre><code>git branch -a | grep xxx
</code></pre>
<p>So I'm trying to do the same in .sh file:</p>
<ol>
<li>get all branches that matches re... | 13,606 | 1,819,402 | 2014-08-29 18:47:48 | 25,571,646 | 12 | 2014-08-29 15:39:19 | 7,552 | 2014-08-29 15:39:19 | https://stackoverflow.com/q/25570510 | https://stackoverflow.com/a/25571646 | <p>Etan has the simple approach in his comment. </p>
<p>You error may be happening because you fail to quote <code>$1</code>, so if you're passing a regular expression with wildcards (like <code>script 'release-.*'</code>), the shell will examine the variable before handing it off to <code>grep</code> -- word splittin... | <p>Etan has the simple approach in his comment. </p> <p>You error may be happening because you fail to quote <code>$1</code>, so if you're passing a regular expression with wildcards (like <code>script 'release-.*'</code>), the shell will examine the variable before handing it off to <code>grep</code> -- word splittin... | 18, 119, 387, 76220 | bash, git, git-branch, regex | <h1>Get all git branches that matches regex and split it into array</h1>
<p>I'm trying to get from my git repo all branches (<code>git branches -a</code>) that matches regex (<code>grep xxx</code>).</p>
<p>Normally in command line I write this:</p>
<pre><code>git branch -a | grep xxx
</code></pre>
<p>So I'm trying t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,117 | bash | # Get all git branches that matches regex and split it into array
I'm trying to get from my git repo all branches (`git branches -a`) that matches regex (`grep xxx`).
Normally in command line I write this:
```
git branch -a | grep xxx
```
So I'm trying to do the same in .sh file:
1. get all branches that matches r... | Etan has the simple approach in his comment.
You error may be happening because you fail to quote `$1`, so if you're passing a regular expression with wildcards (like `script 'release-.*'`), the shell will examine the variable before handing it off to `grep` -- word splitting and filename expansion will occur. You **m... |
23473386 | Length of a sequence of numbers using seq in shell | 6 | 2014-05-05 13:11:29 | <p>I am new to shell scripting and I am trying a simple task of getting the length of a sequence of numbers generated using <code>seq</code>.</p>
<p>With the help of a related post here: <a href="https://stackoverflow.com/questions/1886374/how-to-find-the-array-length-in-unix-shell">How to find the array length in uni... | 2,751 | 2,564,979 | 2014-05-05 13:18:21 | 23,473,443 | 12 | 2014-05-05 13:13:54 | 2,235,132 | 2014-05-05 13:13:54 | https://stackoverflow.com/q/23473386 | https://stackoverflow.com/a/23473443 | <p>You need to store the output in an array to find the length of the array:</p>
<pre><code>$ b=($(seq 1 1 10))
$ echo ${#b[@]}
10
</code></pre>
<p>Saying <code>b=$(seq 1 1 10)</code> doesn't produce an array.</p>
| <p>You need to store the output in an array to find the length of the array:</p> <pre><code>$ b=($(seq 1 1 10)) $ echo ${#b[@]} 10 </code></pre> <p>Saying <code>b=$(seq 1 1 10)</code> doesn't produce an array.</p> | 387, 390, 39302 | bash, seq, shell | <h1>Length of a sequence of numbers using seq in shell</h1>
<p>I am new to shell scripting and I am trying a simple task of getting the length of a sequence of numbers generated using <code>seq</code>.</p>
<p>With the help of a related post here: <a href="https://stackoverflow.com/questions/1886374/how-to-find-the-arr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,118 | bash | # Length of a sequence of numbers using seq in shell
I am new to shell scripting and I am trying a simple task of getting the length of a sequence of numbers generated using `seq`.
With the help of a related post here: [How to find the array length in unix shell?](https://stackoverflow.com/questions/1886374/how-to-fi... | You need to store the output in an array to find the length of the array:
```
$ b=($(seq 1 1 10))
$ echo ${#b[@]}
10
```
Saying `b=$(seq 1 1 10)` doesn't produce an array. |
22647399 | Limit for bash loop | 6 | 2014-03-25 22:12:45 | <p>I have problem with mass creation dummy files and directories.
I want to create something like this:</p>
<pre><code>dummy_directory_1/dummy_file_1
dummy_directory_2/dummy_file_2
dummy_directory_3/dummy_file_3
</code></pre>
<p>using loop:</p>
<pre><code>for(( i=1; $i <=1000; i++ )); do
mkdir $(date --date="... | 3,366 | 3,461,823 | 2014-03-25 22:59:10 | 22,647,480 | 12 | 2014-03-25 22:17:23 | 1,350,899 | 2014-03-25 22:45:30 | https://stackoverflow.com/q/22647399 | https://stackoverflow.com/a/22647480 | <p>Your code only works if the two <code>date</code> calls generating the name of the directory are executed within the same second, if that happens to change inbetween you end up with two different values for the direcory name.</p>
<p>Try to store the value in a variable first:</p>
<pre><code>for(( i=1; i <= 1000... | <p>Your code only works if the two <code>date</code> calls generating the name of the directory are executed within the same second, if that happens to change inbetween you end up with two different values for the direcory name.</p> <p>Try to store the value in a variable first:</p> <pre><code>for(( i=1; i <= 1000... | 58, 387, 2314 | bash, linux, loops | <h1>Limit for bash loop</h1>
<p>I have problem with mass creation dummy files and directories.
I want to create something like this:</p>
<pre><code>dummy_directory_1/dummy_file_1
dummy_directory_2/dummy_file_2
dummy_directory_3/dummy_file_3
</code></pre>
<p>using loop:</p>
<pre><code>for(( i=1; $i <=1000; i++ ));... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,119 | bash | # Limit for bash loop
I have problem with mass creation dummy files and directories.
I want to create something like this:
```
dummy_directory_1/dummy_file_1
dummy_directory_2/dummy_file_2
dummy_directory_3/dummy_file_3
```
using loop:
```
for(( i=1; $i <=1000; i++ )); do
mkdir $(date --date="$i day ago" +%Y%m%... | Your code only works if the two `date` calls generating the name of the directory are executed within the same second, if that happens to change inbetween you end up with two different values for the direcory name.
Try to store the value in a variable first:
```
for(( i=1; i <= 1000; i++ )); do
name=$(date --date... |
22457922 | linux mail adding content type headers not working | 6 | 2014-03-17 15:07:52 | <p>i am using <strong>mail</strong> command to send mails from my linux system. </p>
<p>The problem i am getting is the Content type of the mail is always as <code>Content-Type: text/plain; charset=us-ascii</code>. </p>
<p>I am sending the html content and it is displaying as plain text.</p>
<p>This is what i have t... | 21,907 | 790,454 | 2014-03-17 15:13:32 | 22,458,065 | 12 | 2014-03-17 15:13:32 | 426,305 | 2014-03-17 15:13:32 | https://stackoverflow.com/q/22457922 | https://stackoverflow.com/a/22458065 | <p>Try </p>
<pre><code>echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" foo@example.com
</code></pre>
<p><a href="https://stackoverflow.com/questions/2591755/how-send-html-mail-using-linux-command-line">How to send HTML email using linux command li... | <p>Try </p> <pre><code>echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" foo@example.com </code></pre> <p><a href="https://stackoverflow.com/questions/2591755/how-send-html-mail-using-linux-command-line">How to send HTML email using linux command li... | 58, 387, 390, 50224 | bash, linux, mailx, shell | <h1>linux mail adding content type headers not working</h1>
<p>i am using <strong>mail</strong> command to send mails from my linux system. </p>
<p>The problem i am getting is the Content type of the mail is always as <code>Content-Type: text/plain; charset=us-ascii</code>. </p>
<p>I am sending the html content and i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,120 | bash | # linux mail adding content type headers not working
i am using **mail** command to send mails from my linux system.
The problem i am getting is the Content type of the mail is always as `Content-Type: text/plain; charset=us-ascii`.
I am sending the html content and it is displaying as plain text.
This is what i ha... | Try
```
echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" foo@example.com
```
[How to send HTML email using linux command line](https://stackoverflow.com/questions/2591755/how-send-html-mail-using-linux-command-line) |
21943458 | loop that prepends the filename to the beginning of each line in a tab separated file (thus generating a new column)) | 6 | 2014-02-21 19:27:05 | <p>I'm pretty new at this and try to loop over around 19000 files (all in one dir) in order to insert at the beginning of each line in each file the corresponding filename.</p>
<p>I will later concatenate these files to get a file containing all the data i need for my analyses. </p>
<p>File names show the following ... | 5,637 | 3,265,621 | 2017-07-31 03:25:01 | 21,943,533 | 12 | 2014-02-21 19:31:46 | 970,195 | 2014-02-21 19:37:16 | https://stackoverflow.com/q/21943458 | https://stackoverflow.com/a/21943533 | <p>To insert filename at the begining of each line of each file, try something like: </p>
<pre><code>awk '{print FILENAME, $0}' V*
</code></pre>
<p><code>FILENAME</code> is a built-in variable that carries the name of the file.
<code>V*</code> will glob to all the files in your directory. </p>
<p>If you wish to put... | <p>To insert filename at the begining of each line of each file, try something like: </p> <pre><code>awk '{print FILENAME, $0}' V* </code></pre> <p><code>FILENAME</code> is a built-in variable that carries the name of the file. <code>V*</code> will glob to all the files in your directory. </p> <p>If you wish to put... | 58, 387, 990, 5282 | awk, bash, linux, sed | <h1>loop that prepends the filename to the beginning of each line in a tab separated file (thus generating a new column))</h1>
<p>I'm pretty new at this and try to loop over around 19000 files (all in one dir) in order to insert at the beginning of each line in each file the corresponding filename.</p>
<p>I will late... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,121 | bash | # loop that prepends the filename to the beginning of each line in a tab separated file (thus generating a new column))
I'm pretty new at this and try to loop over around 19000 files (all in one dir) in order to insert at the beginning of each line in each file the corresponding filename.
I will later concatenate the... | To insert filename at the begining of each line of each file, try something like:
```
awk '{print FILENAME, $0}' V*
```
`FILENAME` is a built-in variable that carries the name of the file.
`V*` will glob to all the files in your directory.
If you wish to put a separator between the name and lines you can do:
```
aw... |
21340189 | Can I Pass Arguments To A Powershell Function The Unix Way? | 6 | 2014-01-24 18:51:02 | <p>I have a PowerShell function that basically looks like this:</p>
<pre><code>function DoSomething-ToTask {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[strehg[]]$TaskNums
)
foreach ($TaskNum in $TaskNums) {
do something $TaskNum
}
}
</code></pre>
<p>The goa... | 665 | 1,380,901 | 2015-12-25 06:01:34 | 21,340,261 | 12 | 2014-01-24 18:54:42 | null | 2014-01-24 19:02:00 | https://stackoverflow.com/q/21340189 | https://stackoverflow.com/a/21340261 | <p>Yes, you can use the <code>ValueFromRemainingArguments</code> parameter attribute.</p>
<pre><code>function DoSomething-ToTask {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true, ValueFromRemainingArguments = $true)]
[int[]]$TaskNums
)
foreach ($TaskNum in $TaskNums) {
... | <p>Yes, you can use the <code>ValueFromRemainingArguments</code> parameter attribute.</p> <pre><code>function DoSomething-ToTask { [cmdletbinding()] param( [Parameter(Mandatory=$true, ValueFromRemainingArguments = $true)] [int[]]$TaskNums ) foreach ($TaskNum in $TaskNums) { ... | 526, 531 | powershell, scripting | <h1>Can I Pass Arguments To A Powershell Function The Unix Way?</h1>
<p>I have a PowerShell function that basically looks like this:</p>
<pre><code>function DoSomething-ToTask {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[strehg[]]$TaskNums
)
foreach ($TaskNum in $TaskNu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,122 | bash | # Can I Pass Arguments To A Powershell Function The Unix Way?
I have a PowerShell function that basically looks like this:
```
function DoSomething-ToTask {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[strehg[]]$TaskNums
)
foreach ($TaskNum in $TaskNums) {
do som... | Yes, you can use the `ValueFromRemainingArguments` parameter attribute.
```
function DoSomething-ToTask {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true, ValueFromRemainingArguments = $true)]
[int[]]$TaskNums
)
foreach ($TaskNum in $TaskNums) {
do something $TaskNum
... |
21188210 | Why is $DebugPreference getting lost in a module? | 6 | 2014-01-17 14:27:18 | <p>I have a powershell script and I have set the <code>$DebugPreference</code> to <code>"Continue"</code>. However when I call <code>Write-Debug</code> from a module that is called from my script, the <code>$DebugPreference</code> changed to <code>"SilentlyContinue"</code>. Why is that? How can I keep <code>$DebugPrefe... | 7,364 | 38,211 | 2014-01-18 10:25:10 | 21,197,557 | 12 | 2014-01-17 22:59:39 | 1,242 | 2014-01-18 10:25:10 | https://stackoverflow.com/q/21188210 | https://stackoverflow.com/a/21197557 | <p>As <a href="https://stackoverflow.com/a/17112513/608772">JPBlanc's link</a> in his comment explains: It is a variable scope issue. The module's scope chain goes directly to the global scope and not through any script scopes. Even if it is imported from a script.</p>
<p><img src="https://i.sstatic.net/X3rss.png" alt... | <p>As <a href="https://stackoverflow.com/a/17112513/608772">JPBlanc's link</a> in his comment explains: It is a variable scope issue. The module's scope chain goes directly to the global scope and not through any script scopes. Even if it is imported from a script.</p> <p><img src="https://i.sstatic.net/X3rss.png" alt... | 276, 526 | powershell, variables | <h1>Why is $DebugPreference getting lost in a module?</h1>
<p>I have a powershell script and I have set the <code>$DebugPreference</code> to <code>"Continue"</code>. However when I call <code>Write-Debug</code> from a module that is called from my script, the <code>$DebugPreference</code> changed to <code>"SilentlyCont... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,123 | bash | # Why is $DebugPreference getting lost in a module?
I have a powershell script and I have set the `$DebugPreference` to `"Continue"`. However when I call `Write-Debug` from a module that is called from my script, the `$DebugPreference` changed to `"SilentlyContinue"`. Why is that? How can I keep `$DebugPreference` the... | As [JPBlanc's link](https://stackoverflow.com/a/17112513/608772) in his comment explains: It is a variable scope issue. The module's scope chain goes directly to the global scope and not through any script scopes. Even if it is imported from a script.

Your code will wo... |
20496798 | Command find and convert using ffmpeg | 6 | 2013-12-10 14:15:01 | <p>I would like to combine the two following commands to find mp4 files and convert them to mp3 and save them with same name.
The two command line:</p>
<pre><code>find ./ -name '*.mp4'
ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3
</code></pre>
| 7,137 | 1,243,177 | 2023-04-16 02:02:22 | 20,496,943 | 12 | 2013-12-10 14:21:46 | 2,768,341 | 2013-12-10 14:54:40 | https://stackoverflow.com/q/20496798 | https://stackoverflow.com/a/20496943 | <p>With <code>find</code>'s <code>-exec</code> functionality:</p>
<pre><code>find ./ -name '*.mp4' -exec bash -c 'ffmpeg -i $0 -vn -acodec libmp3lame -ac 2 \
-ab 160k -ar 48000 ${0/mp4/mp3}' {} \;
</code></pre>
<p>This should make <code>xyz.mp4</code> to <code>xyz.mp3</code>.</p>
| <p>With <code>find</code>'s <code>-exec</code> functionality:</p> <pre><code>find ./ -name '*.mp4' -exec bash -c 'ffmpeg -i $0 -vn -acodec libmp3lame -ac 2 \ -ab 160k -ar 48000 ${0/mp4/mp3}' {} \; </code></pre> <p>This should make <code>xyz.mp4</code> to <code>xyz.mp3</code>.</p> | 369, 390, 1231, 3847 | command-line, ffmpeg, macos, shell | <h1>Command find and convert using ffmpeg</h1>
<p>I would like to combine the two following commands to find mp4 files and convert them to mp3 and save them with same name.
The two command line:</p>
<pre><code>find ./ -name '*.mp4'
ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3
</code></... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,124 | bash | # Command find and convert using ffmpeg
I would like to combine the two following commands to find mp4 files and convert them to mp3 and save them with same name.
The two command line:
```
find ./ -name '*.mp4'
ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3
``` | With `find`'s `-exec` functionality:
```
find ./ -name '*.mp4' -exec bash -c 'ffmpeg -i $0 -vn -acodec libmp3lame -ac 2 \
-ab 160k -ar 48000 ${0/mp4/mp3}' {} \;
```
This should make `xyz.mp4` to `xyz.mp3`. |
20056628 | Compare objects in an if statement Powershell | 6 | 2013-11-18 19:56:35 | <p>I'm trying to compare two files and if their content matches I want it to preform the tasks in the if statement in Powershell 4.0</p>
<p>Here is the gist of what I have:</p>
<pre><code>$old = Get-Content .\Old.txt
$new = Get-Content .\New.txt
if ($old.Equals($new)) {
Write-Host "They are the same"
}
</code></pre>... | 24,947 | 2,996,779 | 2013-11-18 20:19:10 | 20,056,767 | 12 | 2013-11-18 20:05:00 | 153,982 | 2013-11-18 20:19:10 | https://stackoverflow.com/q/20056628 | https://stackoverflow.com/a/20056767 | <p><code>Get-Content</code> returns an array of strings. In PowerShell (and .NET) <code>.Equals()</code> on an array is doing a reference comparison i.e. is this the same exact array instance. An easy way to do what you want if the files aren't too large is to read the file contents as a string e.g.:</p>
<pre><code>$... | <p><code>Get-Content</code> returns an array of strings. In PowerShell (and .NET) <code>.Equals()</code> on an array is doing a reference comparison i.e. is this the same exact array instance. An easy way to do what you want if the files aren't too large is to read the file contents as a string e.g.:</p> <pre><code>$... | 139, 526, 2773, 95686 | if-statement, powershell, powershell-4.0, string | <h1>Compare objects in an if statement Powershell</h1>
<p>I'm trying to compare two files and if their content matches I want it to preform the tasks in the if statement in Powershell 4.0</p>
<p>Here is the gist of what I have:</p>
<pre><code>$old = Get-Content .\Old.txt
$new = Get-Content .\New.txt
if ($old.Equals($... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,125 | bash | # Compare objects in an if statement Powershell
I'm trying to compare two files and if their content matches I want it to preform the tasks in the if statement in Powershell 4.0
Here is the gist of what I have:
```
$old = Get-Content .\Old.txt
$new = Get-Content .\New.txt
if ($old.Equals($new)) {
Write-Host "They a... | `Get-Content` returns an array of strings. In PowerShell (and .NET) `.Equals()` on an array is doing a reference comparison i.e. is this the same exact array instance. An easy way to do what you want if the files aren't too large is to read the file contents as a string e.g.:
```
$old = Get-Content .\Old.txt -raw
$new... |
20037729 | how to print the nth line from the end of a file in bash? | 6 | 2013-11-17 23:44:19 | <p>Is there a way to print the nth line of a file, counting from the back of the file?</p>
<p>I know how to do it from the front of the file, but doing it from the back of the file seems to be more tricky.</p>
| 5,702 | 788,171 | 2013-11-18 04:45:31 | 20,037,759 | 12 | 2013-11-17 23:47:22 | 900,873 | 2013-11-17 23:53:02 | https://stackoverflow.com/q/20037729 | https://stackoverflow.com/a/20037759 | <p>The quick and easy way is <code>tail -n $n file | head -n 1</code>.</p>
<p>A more fun way with <code>awk</code> is:</p>
<pre><code>awk -v n=$n '{x[NR%n]=$0}END{print x[(NR+1)%n]}' file
</code></pre>
<p>If you have fewer than <code>n</code> lines, the <code>tail | head</code> method will print the first line of th... | <p>The quick and easy way is <code>tail -n $n file | head -n 1</code>.</p> <p>A more fun way with <code>awk</code> is:</p> <pre><code>awk -v n=$n '{x[NR%n]=$0}END{print x[(NR+1)%n]}' file </code></pre> <p>If you have fewer than <code>n</code> lines, the <code>tail | head</code> method will print the first line of th... | 387, 5282, 7896 | bash, sed, tail | <h1>how to print the nth line from the end of a file in bash?</h1>
<p>Is there a way to print the nth line of a file, counting from the back of the file?</p>
<p>I know how to do it from the front of the file, but doing it from the back of the file seems to be more tricky.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,126 | bash | # how to print the nth line from the end of a file in bash?
Is there a way to print the nth line of a file, counting from the back of the file?
I know how to do it from the front of the file, but doing it from the back of the file seems to be more tricky. | The quick and easy way is `tail -n $n file | head -n 1`.
A more fun way with `awk` is:
```
awk -v n=$n '{x[NR%n]=$0}END{print x[(NR+1)%n]}' file
```
If you have fewer than `n` lines, the `tail | head` method will print the first line of the file, the `awk` way will print a blank line. |
19271959 | How can I check the last character in a string in bash? | 6 | 2013-10-09 12:25:05 | <p>I need to ensure that the last character in a string is a <code>/</code> </p>
<pre><code>x="test.com/"
if [[ $x =~ //$/ ]] ; then
x=$x"extention"
else
x=$x"/extention"
fi
</code></pre>
<p>at the moment, false always fires.</p>
| 11,510 | 445,126 | 2013-10-09 12:46:57 | 19,271,994 | 12 | 2013-10-09 12:26:50 | 1,983,854 | 2013-10-09 12:26:50 | https://stackoverflow.com/q/19271959 | https://stackoverflow.com/a/19271994 | <p>Like this, for example:</p>
<pre><code>$ x="test.com/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.com"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.c//om/"
$ [[ "$x" == ... | <p>Like this, for example:</p> <pre><code>$ x="test.com/" $ [[ "$x" == */ ]] && echo "yes" yes $ x="test.com" $ [[ "$x" == */ ]] && echo "yes" $ $ x="test.c/om" $ [[ "$x" == */ ]] && echo "yes" $ $ x="test.c/om/" $ [[ "$x" == */ ]] && echo "yes" yes $ x="test.c//om/" $ [[ "$x" == ... | 18, 387, 390, 1231 | bash, command-line, regex, shell | <h1>How can I check the last character in a string in bash?</h1>
<p>I need to ensure that the last character in a string is a <code>/</code> </p>
<pre><code>x="test.com/"
if [[ $x =~ //$/ ]] ; then
x=$x"extention"
else
x=$x"/extention"
fi
</code></pre>
<p>at the moment, false always fires.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,127 | bash | # How can I check the last character in a string in bash?
I need to ensure that the last character in a string is a `/`
```
x="test.com/"
if [[ $x =~ //$/ ]] ; then
x=$x"extention"
else
x=$x"/extention"
fi
```
at the moment, false always fires. | Like this, for example:
```
$ x="test.com/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.com"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.c//om/"
$ [[ "$x" == */ ]] && echo "yes"
yes
``` |
18602119 | Python command line argument semicolon-loop error | 6 | 2013-09-03 21:54:25 | <p>I was trying out <code>python -mtimeit</code>so I put <code>python -mtimeit "n = 0; while n < 10: pass"</code>
Then an invalid syntax error showed up. same with semicolon and for loop.</p>
<p>However, when I try semicolon and loop individually. Both worked fine. </p>
<pre><code>python -c "for i in range(10): pr... | 1,666 | 2,325,350 | 2021-11-28 14:06:13 | 18,602,584 | 12 | 2013-09-03 22:34:32 | null | 2013-09-03 22:34:32 | https://stackoverflow.com/q/18602119 | https://stackoverflow.com/a/18602584 | <p><code>while</code>, <code>for</code> can't have semicolon before, they need to be on one line. If you looked at <a href="http://docs.python.org/2/reference/grammar.html">Python grammar</a>:</p>
<pre><code>compound_stmt ::= if_stmt
| while_stmt
| for_stmt
| t... | <p><code>while</code>, <code>for</code> can't have semicolon before, they need to be on one line. If you looked at <a href="http://docs.python.org/2/reference/grammar.html">Python grammar</a>:</p> <pre><code>compound_stmt ::= if_stmt | while_stmt | for_stmt | t... | 16, 387, 20342 | bash, python, timeit | <h1>Python command line argument semicolon-loop error</h1>
<p>I was trying out <code>python -mtimeit</code>so I put <code>python -mtimeit "n = 0; while n < 10: pass"</code>
Then an invalid syntax error showed up. same with semicolon and for loop.</p>
<p>However, when I try semicolon and loop individually. Both work... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,128 | bash | # Python command line argument semicolon-loop error
I was trying out `python -mtimeit`so I put `python -mtimeit "n = 0; while n < 10: pass"`
Then an invalid syntax error showed up. same with semicolon and for loop.
However, when I try semicolon and loop individually. Both worked fine.
```
python -c "for i in range(1... | `while`, `for` can't have semicolon before, they need to be on one line. If you looked at [Python grammar](http://docs.python.org/2/reference/grammar.html):
```
compound_stmt ::= if_stmt
| while_stmt
| for_stmt
| try_stmt
| with_stmt
... |
18536693 | What does `echo $?` mean in bash? | 6 | 2013-08-30 15:36:54 | <p>I came upon the following command:</p>
<pre><code>echo $?
</code></pre>
<p>what does that command do?</p>
| 21,983 | 81,800 | 2020-05-27 07:16:06 | 18,536,713 | 12 | 2013-08-30 15:37:50 | 456,188 | 2013-08-30 16:12:16 | https://stackoverflow.com/q/18536693 | https://stackoverflow.com/a/18536713 | <p>Echoes (prints) the exit value for the previous command.</p>
<p>If it failed it will be different than zero (<code>0</code>).</p>
<pre><code>$ cd ~
$ echo $?
> 0
$ cd //whatever/
> bash: cd: //whatever/: No such file or directory
$ echo $?
> 1
</code></pre>
<p>Programs exit with a status code. Every pro... | <p>Echoes (prints) the exit value for the previous command.</p> <p>If it failed it will be different than zero (<code>0</code>).</p> <pre><code>$ cd ~ $ echo $? > 0 $ cd //whatever/ > bash: cd: //whatever/: No such file or directory $ echo $? > 1 </code></pre> <p>Programs exit with a status code. Every pro... | 387, 390, 1796, 11225 | bash, command, command-line-interface, shell | <h1>What does `echo $?` mean in bash?</h1>
<p>I came upon the following command:</p>
<pre><code>echo $?
</code></pre>
<p>what does that command do?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,129 | bash | # What does `echo $?` mean in bash?
I came upon the following command:
```
echo $?
```
what does that command do? | Echoes (prints) the exit value for the previous command.
If it failed it will be different than zero (`0`).
```
$ cd ~
$ echo $?
> 0
$ cd //whatever/
> bash: cd: //whatever/: No such file or directory
$ echo $?
> 1
```
Programs exit with a status code. Every program is unique and has a different set of failure codes... |
18087772 | How to alias 'clear' to CTRL+L keystroke | 6 | 2013-08-06 18:28:36 | <p>I have a habit of issuing the <code>clear</code> command.</p>
<p>When I run cygwin, the package containing <code>clear</code> isn't installed and I don't have the option of installing it. <kbd>Ctrl</kbd>+<kbd>L</kbd> is a good substitute; however, I still issue the <code>clear</code> command habitually.</p>
<p>I'd... | 2,639 | 1,566,525 | 2013-08-06 18:34:03 | 18,087,898 | 12 | 2013-08-06 18:34:03 | 1,899,640 | 2013-08-06 18:34:03 | https://stackoverflow.com/q/18087772 | https://stackoverflow.com/a/18087898 | <p><code>clear</code> clears the screen simply by outputting some ANSI escapes sequences. You can do the same thing with <code>printf</code>:</p>
<pre><code>alias clear='printf "\e[H\e[2J"'
</code></pre>
| <p><code>clear</code> clears the screen simply by outputting some ANSI escapes sequences. You can do the same thing with <code>printf</code>:</p> <pre><code>alias clear='printf "\e[H\e[2J"' </code></pre> | 387, 1448 | alias, bash | <h1>How to alias 'clear' to CTRL+L keystroke</h1>
<p>I have a habit of issuing the <code>clear</code> command.</p>
<p>When I run cygwin, the package containing <code>clear</code> isn't installed and I don't have the option of installing it. <kbd>Ctrl</kbd>+<kbd>L</kbd> is a good substitute; however, I still issue the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,130 | bash | # How to alias 'clear' to CTRL+L keystroke
I have a habit of issuing the `clear` command.
When I run cygwin, the package containing `clear` isn't installed and I don't have the option of installing it. `Ctrl`+`L` is a good substitute; however, I still issue the `clear` command habitually.
I'd like to alias the `clea... | `clear` clears the screen simply by outputting some ANSI escapes sequences. You can do the same thing with `printf`:
```
alias clear='printf "\e[H\e[2J"'
``` |
17838620 | shell script containing ldapmodify - hardcoding commands | 6 | 2013-07-24 15:34:48 | <p>I'm trying to run an ldapmodify command in a shell script, but I don't want to specify an external file containing commands (-f flag). This would just be for convenience - the commands in the external file would be dynamic, so it would be nice to avoid writing a new file every time the shell script ran ldapmodify. I... | 11,039 | 2,336,976 | 2017-04-18 21:38:35 | 17,839,157 | 12 | 2013-07-24 15:58:31 | 810,802 | 2013-07-24 15:58:31 | https://stackoverflow.com/q/17838620 | https://stackoverflow.com/a/17839157 | <p>Use a "here" document:</p>
<pre><code>ldapmodify .. <<!
dn: dc=example,dc=com
changetype: modify
replace: description
-
add: description
description: The new description
!
</code></pre>
<p>For example.</p>
| <p>Use a "here" document:</p> <pre><code>ldapmodify .. <<! dn: dc=example,dc=com changetype: modify replace: description - add: description description: The new description ! </code></pre> <p>For example.</p> | 58, 390, 4645, 10401 | active-directory, ldap, linux, shell | <h1>shell script containing ldapmodify - hardcoding commands</h1>
<p>I'm trying to run an ldapmodify command in a shell script, but I don't want to specify an external file containing commands (-f flag). This would just be for convenience - the commands in the external file would be dynamic, so it would be nice to avoi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,131 | bash | # shell script containing ldapmodify - hardcoding commands
I'm trying to run an ldapmodify command in a shell script, but I don't want to specify an external file containing commands (-f flag). This would just be for convenience - the commands in the external file would be dynamic, so it would be nice to avoid writing... | Use a "here" document:
```
ldapmodify .. <<!
dn: dc=example,dc=com
changetype: modify
replace: description
-
add: description
description: The new description
!
```
For example. |
17510339 | How can I force bash to expand a variable to pass it as an argument? | 6 | 2013-07-07 08:10:02 | <p>I found a weird behavior that I don't know how to workaround.</p>
<pre><code>$ var1=*
$ echo $var1
Audiobooks Downloads Desktop (etc.)
$ ls $var1
Audiobooks:
Downloads:
(etc)
</code></pre>
<p>All seems OK. At declaration, the variable gets expanded and everything else works. But see this:</p>
<pre><code>$ var2... | 4,535 | 1,468,388 | 2013-07-07 15:00:32 | 17,513,260 | 12 | 2013-07-07 15:00:32 | 89,817 | 2013-07-07 15:00:32 | https://stackoverflow.com/q/17510339 | https://stackoverflow.com/a/17513260 | <p>The order in which the shell parses various aspects of the command line is not obvious, and it <em>matters</em> for things like this.</p>
<p>First, the wildcards aren't expanded at declaration, they're expanded after the variable value is substituted (note: in these examples I'll pretend I have your filesystem):</p... | <p>The order in which the shell parses various aspects of the command line is not obvious, and it <em>matters</em> for things like this.</p> <p>First, the wildcards aren't expanded at declaration, they're expanded after the variable value is substituted (note: in these examples I'll pretend I have your filesystem):</p... | 276, 387, 1110 | bash, expand, variables | <h1>How can I force bash to expand a variable to pass it as an argument?</h1>
<p>I found a weird behavior that I don't know how to workaround.</p>
<pre><code>$ var1=*
$ echo $var1
Audiobooks Downloads Desktop (etc.)
$ ls $var1
Audiobooks:
Downloads:
(etc)
</code></pre>
<p>All seems OK. At declaration, the variable... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,132 | bash | # How can I force bash to expand a variable to pass it as an argument?
I found a weird behavior that I don't know how to workaround.
```
$ var1=*
$ echo $var1
Audiobooks Downloads Desktop (etc.)
$ ls $var1
Audiobooks:
Downloads:
(etc)
```
All seems OK. At declaration, the variable gets expanded and everything els... | The order in which the shell parses various aspects of the command line is not obvious, and it *matters* for things like this.
First, the wildcards aren't expanded at declaration, they're expanded after the variable value is substituted (note: in these examples I'll pretend I have your filesystem):
```
$ var1=*
$ ech... |
17262827 | bash locate command with pattern | 6 | 2013-06-23 16:27:47 | <p>I try to find a file with <code>locate</code> command.</p>
<p>It behaves itself some strange with patterns, at least not like <code>ls</code> or <code>find</code> commands.</p>
<p>I do the following:</p>
<pre><code>sh@sh:~$ locate rhythmdb
/home/sh/.local/share/rhythmbox/rhythmdb.xml
sh@sh:~$ locate "rhyth*"
sh@s... | 12,037 | 758,158 | 2013-06-23 18:59:05 | 17,262,976 | 12 | 2013-06-23 16:47:01 | 1,815,797 | 2013-06-23 18:59:05 | https://stackoverflow.com/q/17262827 | https://stackoverflow.com/a/17262976 | <p>From <code>man locate</code>:</p>
<pre><code>If --regex is not specified, PATTERNs can contain globbing characters. If any
PATTERN contains no globbing characters, locate behaves as if the pattern
were \*PATTERN*.
</code></pre>
<p>Hence, when you issue</p>
<pre><code>locate rhyth*
</code></pre>
<p><code>loca... | <p>From <code>man locate</code>:</p> <pre><code>If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were \*PATTERN*. </code></pre> <p>Hence, when you issue</p> <pre><code>locate rhyth* </code></pre> <p><code>loca... | 387, 26269 | bash, locate | <h1>bash locate command with pattern</h1>
<p>I try to find a file with <code>locate</code> command.</p>
<p>It behaves itself some strange with patterns, at least not like <code>ls</code> or <code>find</code> commands.</p>
<p>I do the following:</p>
<pre><code>sh@sh:~$ locate rhythmdb
/home/sh/.local/share/rhythmbox/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,133 | bash | # bash locate command with pattern
I try to find a file with `locate` command.
It behaves itself some strange with patterns, at least not like `ls` or `find` commands.
I do the following:
```
sh@sh:~$ locate rhythmdb
/home/sh/.local/share/rhythmbox/rhythmdb.xml
sh@sh:~$ locate "rhyth*"
sh@sh:~$ locate 'rhyth*'
sh@s... | From `man locate`:
```
If --regex is not specified, PATTERNs can contain globbing characters. If any
PATTERN contains no globbing characters, locate behaves as if the pattern
were \*PATTERN*.
```
Hence, when you issue
```
locate rhyth*
```
`locate` will not find it, because there are no files that match this pa... |
17167385 | Filter non-alphabetic characters out of string in shell script | 6 | 2013-06-18 11:09:49 | <p>Very simple question but can't seem to find a simple answer...</p>
<p>I am writing a bash script which needs to remove all non-alphabetic and non-numeric characters. Eg. I want...</p>
<pre><code>INPUT_STRING="ABC# .1-2-3"
OUTPUT_STRING= # some form of processing on $INPUT_STRING #
echo $OUTPUT_STRING
ABC123
</co... | 16,453 | 1,083,811 | 2015-11-03 23:42:45 | 17,167,432 | 12 | 2013-06-18 11:12:53 | 1,983,854 | 2013-06-18 11:12:53 | https://stackoverflow.com/q/17167385 | https://stackoverflow.com/a/17167432 | <p>You can use <code>sed</code> to strip all chars that are not <code>a-z</code>, <code>A-Z</code> or <code>0-9</code>:</p>
<pre><code>$ echo "ABC# .1-2-3" | sed 's/[^a-zA-Z0-9]//g'
ABC123
</code></pre>
<p>So in your case,</p>
<pre><code>$ INPUT_STRING="ABC# .1-2-3"
$ OUTPUT_STRING=$(echo $INPUT_STRING | sed 's/[^a-... | <p>You can use <code>sed</code> to strip all chars that are not <code>a-z</code>, <code>A-Z</code> or <code>0-9</code>:</p> <pre><code>$ echo "ABC# .1-2-3" | sed 's/[^a-zA-Z0-9]//g' ABC123 </code></pre> <p>So in your case,</p> <pre><code>$ INPUT_STRING="ABC# .1-2-3" $ OUTPUT_STRING=$(echo $INPUT_STRING | sed 's/[^a-... | 18, 387, 390, 531 | bash, regex, scripting, shell | <h1>Filter non-alphabetic characters out of string in shell script</h1>
<p>Very simple question but can't seem to find a simple answer...</p>
<p>I am writing a bash script which needs to remove all non-alphabetic and non-numeric characters. Eg. I want...</p>
<pre><code>INPUT_STRING="ABC# .1-2-3"
OUTPUT_STRING= # som... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,134 | bash | # Filter non-alphabetic characters out of string in shell script
Very simple question but can't seem to find a simple answer...
I am writing a bash script which needs to remove all non-alphabetic and non-numeric characters. Eg. I want...
```
INPUT_STRING="ABC# .1-2-3"
OUTPUT_STRING= # some form of processing on $IN... | You can use `sed` to strip all chars that are not `a-z`, `A-Z` or `0-9`:
```
$ echo "ABC# .1-2-3" | sed 's/[^a-zA-Z0-9]//g'
ABC123
```
So in your case,
```
$ INPUT_STRING="ABC# .1-2-3"
$ OUTPUT_STRING=$(echo $INPUT_STRING | sed 's/[^a-zA-Z0-9]//g')
$ echo $OUTPUT_STRING
ABC123
``` |
16665176 | How can I make a PSDrive created within a function accessible out of this function? | 6 | 2013-05-21 08:14:50 | <p>I assume creating a new PS-Drive within a function makes that drive only accessible within that function.</p>
<p>How can I make a PS-Drive created by calling a function from the MAIN accessible out of that function?</p>
<pre><code> $temproraryPSDriveName = "temproraryDrive"
Create-PSDriveBy $temproraryPSDriveNam... | 3,684 | 136,141 | 2013-05-21 08:21:03 | 16,665,256 | 12 | 2013-05-21 08:21:03 | 520,612 | 2013-05-21 08:21:03 | https://stackoverflow.com/q/16665176 | https://stackoverflow.com/a/16665256 | <p>Give global scope to your PSDRIVE:</p>
<pre><code>New-PSDrive -Name qq -PSProvider filesystem -Root c:\windows -Scope global
</code></pre>
| <p>Give global scope to your PSDRIVE:</p> <pre><code>New-PSDrive -Name qq -PSProvider filesystem -Root c:\windows -Scope global </code></pre> | 1, 526 | .net, powershell | <h1>How can I make a PSDrive created within a function accessible out of this function?</h1>
<p>I assume creating a new PS-Drive within a function makes that drive only accessible within that function.</p>
<p>How can I make a PS-Drive created by calling a function from the MAIN accessible out of that function?</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,135 | bash | # How can I make a PSDrive created within a function accessible out of this function?
I assume creating a new PS-Drive within a function makes that drive only accessible within that function.
How can I make a PS-Drive created by calling a function from the MAIN accessible out of that function?
```
$temproraryPSDriv... | Give global scope to your PSDRIVE:
```
New-PSDrive -Name qq -PSProvider filesystem -Root c:\windows -Scope global
``` |
15824493 | My .bash_profile is locked. How do I edit it? | 6 | 2013-04-05 01:33:44 | <p>I'm a bit new to this area on my Mac. I made my .bash_profile yesterday without any problems. Now when I open it, textedit says it's locked and does not let me unlock it. I tried using chmod 644 to change the permissions, but that didn't help. </p>
<p>What am I missing here?</p>
| 16,959 | 903,402 | 2013-04-05 01:40:17 | 15,824,542 | 12 | 2013-04-05 01:40:17 | 1,671,448 | 2013-04-05 01:40:17 | https://stackoverflow.com/q/15824493 | https://stackoverflow.com/a/15824542 | <p>Give yourself write permissions for that file:</p>
<pre><code>/usr/bin/sudo /bin/chmod u+rwx /Users/yourusername/.bash_profile
/usr/bin/sudo /usr/sbin/chown yourusername /Users/yourusername/.bash_profile
</code></pre>
| <p>Give yourself write permissions for that file:</p> <pre><code>/usr/bin/sudo /bin/chmod u+rwx /Users/yourusername/.bash_profile /usr/bin/sudo /usr/sbin/chown yourusername /Users/yourusername/.bash_profile </code></pre> | 369, 387 | bash, macos | <h1>My .bash_profile is locked. How do I edit it?</h1>
<p>I'm a bit new to this area on my Mac. I made my .bash_profile yesterday without any problems. Now when I open it, textedit says it's locked and does not let me unlock it. I tried using chmod 644 to change the permissions, but that didn't help. </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 | 11,136 | bash | # My .bash_profile is locked. How do I edit it?
I'm a bit new to this area on my Mac. I made my .bash_profile yesterday without any problems. Now when I open it, textedit says it's locked and does not let me unlock it. I tried using chmod 644 to change the permissions, but that didn't help.
What am I missing here? | Give yourself write permissions for that file:
```
/usr/bin/sudo /bin/chmod u+rwx /Users/yourusername/.bash_profile
/usr/bin/sudo /usr/sbin/chown yourusername /Users/yourusername/.bash_profile
``` |
14803308 | bash awk first 1st column and 3rd column with everything after | 6 | 2013-02-10 22:25:25 | <p>I am working on the following bash script:</p>
<pre><code># contents of dbfake file
1 100% file 1
2 99% file name 2
3 100% file name 3
#!/bin/bash
# cat out data
cat dbfake |
# select lines containing 100%
grep 100% |
# print the first and third columns
awk '{print $1, $3}' |
# echo out id and file name and l... | 19,739 | 1,814,739 | 2013-02-11 01:25:43 | 14,803,365 | 12 | 2013-02-10 22:31:11 | 236,528 | 2013-02-10 22:31:11 | https://stackoverflow.com/q/14803308 | https://stackoverflow.com/a/14803365 | <p>You can use cut instead of awk in this case:</p>
<pre><code> cut -f1,3- -d ' '
</code></pre>
| <p>You can use cut instead of awk in this case:</p> <pre><code> cut -f1,3- -d ' ' </code></pre> | 387, 990, 10326 | awk, bash, xargs | <h1>bash awk first 1st column and 3rd column with everything after</h1>
<p>I am working on the following bash script:</p>
<pre><code># contents of dbfake file
1 100% file 1
2 99% file name 2
3 100% file name 3
#!/bin/bash
# cat out data
cat dbfake |
# select lines containing 100%
grep 100% |
# print the first and... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,137 | bash | # bash awk first 1st column and 3rd column with everything after
I am working on the following bash script:
```
# contents of dbfake file
1 100% file 1
2 99% file name 2
3 100% file name 3
#!/bin/bash
# cat out data
cat dbfake |
# select lines containing 100%
grep 100% |
# print the first and third columns
awk '... | You can use cut instead of awk in this case:
```
cut -f1,3- -d ' '
``` |
13420799 | Enabling execution policy for PowerShell from C# | 6 | 2012-11-16 16:43:13 | <p>I have an ASP.NET MVC 4 page that calls a piece of PowerShell. However, I am running into a problem as a module I am using is not signed, so I have to enable the <em>Unrestricted</em> policy. How can I force the PowerShell child to use <em>Unrestricted</em> policy?</p>
<p>I have enabled this in my script, but it is... | 15,748 | 757,697 | 2020-09-02 01:47:32 | 13,447,260 | 12 | 2012-11-19 03:28:11 | 1,427,220 | 2012-11-19 16:27:25 | https://stackoverflow.com/q/13420799 | https://stackoverflow.com/a/13447260 | <p>If you only need to run the one script with no interactions you can set the execution policy via the command prompt like so:</p>
<pre><code>string command = "/c powershell -executionpolicy unrestricted C:\script1.ps1";
System.Diagnostics.Process.Start("cmd.exe",command);
</code></pre>
| <p>If you only need to run the one script with no interactions you can set the execution policy via the command prompt like so:</p> <pre><code>string command = "/c powershell -executionpolicy unrestricted C:\script1.ps1"; System.Diagnostics.Process.Start("cmd.exe",command); </code></pre> | 9, 526 | c#, powershell | <h1>Enabling execution policy for PowerShell from C#</h1>
<p>I have an ASP.NET MVC 4 page that calls a piece of PowerShell. However, I am running into a problem as a module I am using is not signed, so I have to enable the <em>Unrestricted</em> policy. How can I force the PowerShell child to use <em>Unrestricted</em> p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,138 | bash | # Enabling execution policy for PowerShell from C#
I have an ASP.NET MVC 4 page that calls a piece of PowerShell. However, I am running into a problem as a module I am using is not signed, so I have to enable the *Unrestricted* policy. How can I force the PowerShell child to use *Unrestricted* policy?
I have enabled ... | If you only need to run the one script with no interactions you can set the execution policy via the command prompt like so:
```
string command = "/c powershell -executionpolicy unrestricted C:\script1.ps1";
System.Diagnostics.Process.Start("cmd.exe",command);
``` |
13215666 | script for changing prefix of filename in bash | 6 | 2012-11-04 03:00:31 | <p>From</p>
<pre><code>abcd_if_vb.c
abcd_if_av.c
</code></pre>
<p>to</p>
<pre><code>edfg_if_vb.c
edfg_if_av.c
</code></pre>
<p>The problem is to catch what file have <code>abcd</code> prefix.</p>
| 3,206 | 278,235 | 2012-11-04 09:54:06 | 13,215,700 | 12 | 2012-11-04 03:05:49 | 20,862 | 2012-11-04 03:05:49 | https://stackoverflow.com/q/13215666 | https://stackoverflow.com/a/13215700 | <p>Not really.</p>
<pre><code>for file in abcd*
do
mv "$file" "edfg${file#abcd}"
done
</code></pre>
| <p>Not really.</p> <pre><code>for file in abcd* do mv "$file" "edfg${file#abcd}" done </code></pre> | 387, 990, 5282 | awk, bash, sed | <h1>script for changing prefix of filename in bash</h1>
<p>From</p>
<pre><code>abcd_if_vb.c
abcd_if_av.c
</code></pre>
<p>to</p>
<pre><code>edfg_if_vb.c
edfg_if_av.c
</code></pre>
<p>The problem is to catch what file have <code>abcd</code> prefix.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,139 | bash | # script for changing prefix of filename in bash
From
```
abcd_if_vb.c
abcd_if_av.c
```
to
```
edfg_if_vb.c
edfg_if_av.c
```
The problem is to catch what file have `abcd` prefix. | Not really.
```
for file in abcd*
do
mv "$file" "edfg${file#abcd}"
done
``` |
13111881 | Scripting virtualenvwrapper mkvirtualenv | 6 | 2012-10-28 18:47:38 | <p>I'm writing a <a href="http://github.com/greenmoss/NotOrion" rel="nofollow noreferrer">game</a> in python 2.7, and want to script the "bootstrap" of my game's development environment, and then invoke <a href="https://github.com/seomoz/shovel" rel="nofollow noreferrer">shovel</a>. If virtualenvwrapper is not detected... | 3,165 | 1,090,611 | 2014-02-27 18:49:56 | 13,112,193 | 12 | 2012-10-28 19:22:59 | 59,984 | 2014-02-27 18:49:56 | https://stackoverflow.com/q/13111881 | https://stackoverflow.com/a/13112193 | <p>Your script should be able to do:</p>
<pre><code># 'which' will print absolute path to virtualenvwrapper.sh
source `which virtualenvwrapper.sh`
</code></pre>
<p>I use that for some deployment scripts.</p>
| <p>Your script should be able to do:</p> <pre><code># 'which' will print absolute path to virtualenvwrapper.sh source `which virtualenvwrapper.sh` </code></pre> <p>I use that for some deployment scripts.</p> | 387, 55427 | bash, virtualenvwrapper | <h1>Scripting virtualenvwrapper mkvirtualenv</h1>
<p>I'm writing a <a href="http://github.com/greenmoss/NotOrion" rel="nofollow noreferrer">game</a> in python 2.7, and want to script the "bootstrap" of my game's development environment, and then invoke <a href="https://github.com/seomoz/shovel" rel="nofollow noreferrer... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,140 | bash | # Scripting virtualenvwrapper mkvirtualenv
I'm writing a [game](http://github.com/greenmoss/NotOrion) in python 2.7, and want to script the "bootstrap" of my game's development environment, and then invoke [shovel](https://github.com/seomoz/shovel). If virtualenvwrapper is not detected, I will use a [virtualenv bootst... | Your script should be able to do:
```
# 'which' will print absolute path to virtualenvwrapper.sh
source `which virtualenvwrapper.sh`
```
I use that for some deployment scripts. |
12682631 | Change the type name of a Powershell object from PSCustomObject to something I choose? | 6 | 2012-10-01 23:42:58 | <p>I have a script that uses custom objects. I create them with a pseudo-constructor like this: </p>
<pre><code>function New-TestResult
{
$trProps = @{
name = "";
repo = @{};
vcs = $Skipped;
clean = New-StageResult; # This is another pseudo-constructor
build = New-Stage... | 11,445 | 868,206 | 2024-06-04 13:54:02 | 12,682,824 | 12 | 2012-10-02 00:09:27 | 153,982 | 2012-10-02 00:09:27 | https://stackoverflow.com/q/12682631 | https://stackoverflow.com/a/12682824 | <p>Sure, try this after creating $testResult:</p>
<pre><code>$testResult.psobject.TypeNames.Insert(0, "MyType")
</code></pre>
<p>The heart of the PowerShell extended type system is the psobject wrapper (at least in V1 and V2). This wrapper allows you to add properties and methods, modify type names list and get at t... | <p>Sure, try this after creating $testResult:</p> <pre><code>$testResult.psobject.TypeNames.Insert(0, "MyType") </code></pre> <p>The heart of the PowerShell extended type system is the psobject wrapper (at least in V1 and V2). This wrapper allows you to add properties and methods, modify type names list and get at t... | 526 | powershell | <h1>Change the type name of a Powershell object from PSCustomObject to something I choose?</h1>
<p>I have a script that uses custom objects. I create them with a pseudo-constructor like this: </p>
<pre><code>function New-TestResult
{
$trProps = @{
name = "";
repo = @{};
vcs = $Skipped;
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,141 | bash | # Change the type name of a Powershell object from PSCustomObject to something I choose?
I have a script that uses custom objects. I create them with a pseudo-constructor like this:
```
function New-TestResult
{
$trProps = @{
name = "";
repo = @{};
vcs = $Skipped;
clean = New-... | Sure, try this after creating $testResult:
```
$testResult.psobject.TypeNames.Insert(0, "MyType")
```
The heart of the PowerShell extended type system is the psobject wrapper (at least in V1 and V2). This wrapper allows you to add properties and methods, modify type names list and get at the underlying .NET object e.... |
12555849 | Generating variations with bash | 6 | 2012-09-23 20:09:02 | <p>Looking for en nicer solution for the next code:</p>
<pre><code>for i in a b c
do
for j in A B C
do
for k in 1 2 3
do
echo "$i$j$k"
done
done
done
</code></pre>
<p>Sure is here some simpler solution.</p>
| 214 | 869,025 | 2012-09-23 20:24:50 | 12,555,874 | 12 | 2012-09-23 20:12:33 | 1,692,877 | 2012-09-23 20:24:50 | https://stackoverflow.com/q/12555849 | https://stackoverflow.com/a/12555874 | <p>This is a bit simpler</p>
<pre><code>echo {a,b,c}{A,B,C}{1,2,3}
</code></pre>
<p>or if want one per line, so</p>
<pre><code>echo {a,b,c}{A,B,C}{1,2,3} | xargs -n1
</code></pre>
<p>BTW, you can use the above bracer expansion for example saving keyboard typing for example when need make backup files, like:</p>
<p... | <p>This is a bit simpler</p> <pre><code>echo {a,b,c}{A,B,C}{1,2,3} </code></pre> <p>or if want one per line, so</p> <pre><code>echo {a,b,c}{A,B,C}{1,2,3} | xargs -n1 </code></pre> <p>BTW, you can use the above bracer expansion for example saving keyboard typing for example when need make backup files, like:</p> <p... | 387 | bash | <h1>Generating variations with bash</h1>
<p>Looking for en nicer solution for the next code:</p>
<pre><code>for i in a b c
do
for j in A B C
do
for k in 1 2 3
do
echo "$i$j$k"
done
done
done
</code></pre>
<p>Sure is here some simpler solution.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,142 | bash | # Generating variations with bash
Looking for en nicer solution for the next code:
```
for i in a b c
do
for j in A B C
do
for k in 1 2 3
do
echo "$i$j$k"
done
done
done
```
Sure is here some simpler solution. | This is a bit simpler
```
echo {a,b,c}{A,B,C}{1,2,3}
```
or if want one per line, so
```
echo {a,b,c}{A,B,C}{1,2,3} | xargs -n1
```
BTW, you can use the above bracer expansion for example saving keyboard typing for example when need make backup files, like:
```
cp /some/long/path/And_very-ugly-fileName{,.copy}
```... |
12264044 | Telnet inside a shell script | 6 | 2012-09-04 13:01:47 | <p>How can I run telnet inside a shell script and execute commands on the remote server?</p>
<p>I do not have expect installed on my solaris machine because of security reasons.
I also do not have the perl <code>net::telnet</code> module installed.</p>
<p>So with out using expect and perl how can I do it?</p>
<p>I t... | 41,135 | 134,713 | 2017-11-14 22:10:04 | 12,264,226 | 12 | 2012-09-04 13:11:57 | 1,184,892 | 2012-09-04 13:29:45 | https://stackoverflow.com/q/12264044 | https://stackoverflow.com/a/12264226 | <p>Some of your commands might be discarded. You can achieve finer control with ordinary script constructs and then send required commands through a pipe with <code>echo</code>. Group the list of commands to make one "session":-</p>
<pre><code>{
sleep 5
echo user
sleep 3
echo password
sleep 3
echo ls
sleep 5
echo exit... | <p>Some of your commands might be discarded. You can achieve finer control with ordinary script constructs and then send required commands through a pipe with <code>echo</code>. Group the list of commands to make one "session":-</p> <pre><code>{ sleep 5 echo user sleep 3 echo password sleep 3 echo ls sleep 5 echo exit... | 34, 390, 6056 | shell, telnet, unix | <h1>Telnet inside a shell script</h1>
<p>How can I run telnet inside a shell script and execute commands on the remote server?</p>
<p>I do not have expect installed on my solaris machine because of security reasons.
I also do not have the perl <code>net::telnet</code> module installed.</p>
<p>So with out using expect... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,143 | bash | # Telnet inside a shell script
How can I run telnet inside a shell script and execute commands on the remote server?
I do not have expect installed on my solaris machine because of security reasons.
I also do not have the perl `net::telnet` module installed.
So with out using expect and perl how can I do it?
I trie... | Some of your commands might be discarded. You can achieve finer control with ordinary script constructs and then send required commands through a pipe with `echo`. Group the list of commands to make one "session":-
```
{
sleep 5
echo user
sleep 3
echo password
sleep 3
echo ls
sleep 5
echo exit
} | telnet 172.16.65.209... |
12206013 | What does an ellipsis do in PowerShell? | 6 | 2012-08-30 21:46:05 | <p>I'm familiar with the basic <a href="http://technet.microsoft.com/en-us/library/hh847732" rel="noreferrer">range operator</a>:</p>
<pre><code>.. Range operator
Represents the sequential integers in an integer array, given an upper and lower boundary.
1..10
10..1
foreach ($a in 1..$max) {write-host $a}
<... | 317 | 628,391 | 2012-08-30 21:46:05 | 12,206,016 | 12 | 2012-08-30 21:46:05 | 628,391 | 2012-08-30 21:46:05 | https://stackoverflow.com/q/12206013 | https://stackoverflow.com/a/12206016 | <p>The range operator is still being used - as it turns out, the second input (in this case, <code>.3</code>) to the range operator is being implicitly cast to an integer, since the range operator only accepts integers as inputs.</p>
<p>This can be verified by using a right-side value higher than <code>.5</code>:</p>
... | <p>The range operator is still being used - as it turns out, the second input (in this case, <code>.3</code>) to the range operator is being implicitly cast to an integer, since the range operator only accepts integers as inputs.</p> <p>This can be verified by using a right-side value higher than <code>.5</code>:</p> ... | 526 | powershell | <h1>What does an ellipsis do in PowerShell?</h1>
<p>I'm familiar with the basic <a href="http://technet.microsoft.com/en-us/library/hh847732" rel="noreferrer">range operator</a>:</p>
<pre><code>.. Range operator
Represents the sequential integers in an integer array, given an upper and lower boundary.
1..10
10... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,144 | bash | # What does an ellipsis do in PowerShell?
I'm familiar with the basic [range operator](http://technet.microsoft.com/en-us/library/hh847732):
```
.. Range operator
Represents the sequential integers in an integer array, given an upper and lower boundary.
1..10
10..1
foreach ($a in 1..$max) {write-host $a}
... | The range operator is still being used - as it turns out, the second input (in this case, `.3`) to the range operator is being implicitly cast to an integer, since the range operator only accepts integers as inputs.
This can be verified by using a right-side value higher than `.5`:
```
PS C:\> 5...6
5
4
3
2
1
```
Th... |
11394232 | Powershell calling Powershell script | 6 | 2012-07-09 11:34:37 | <p>How does the behaviour differ between <code>& powershell .\other.ps1</code> and <code>& .\other.ps1</code>? </p>
<p>Edit: In particular, how do they differ if there's an error in <code>other.ps1</code>?</p>
| 831 | 284,795 | 2013-09-26 15:53:45 | 11,394,292 | 12 | 2012-07-09 11:38:53 | 73,070 | 2012-07-09 11:38:53 | https://stackoverflow.com/q/11394232 | https://stackoverflow.com/a/11394292 | <p>You get another PowerShell process in the former case and the script cannot read variables defined in your current session:</p>
<pre><code>PS> $foo = 'bar'
PS> 'Write-Host $foo'|Set-Content x.ps1
PS> & powershell .\x.ps1
PS> & .\x.ps1
bar
</code></pre>
| <p>You get another PowerShell process in the former case and the script cannot read variables defined in your current session:</p> <pre><code>PS> $foo = 'bar' PS> 'Write-Host $foo'|Set-Content x.ps1 PS> & powershell .\x.ps1 PS> & .\x.ps1 bar </code></pre> | 526 | powershell | <h1>Powershell calling Powershell script</h1>
<p>How does the behaviour differ between <code>& powershell .\other.ps1</code> and <code>& .\other.ps1</code>? </p>
<p>Edit: In particular, how do they differ if there's an error in <code>other.ps1</code>?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,145 | bash | # Powershell calling Powershell script
How does the behaviour differ between `& powershell .\other.ps1` and `& .\other.ps1`?
Edit: In particular, how do they differ if there's an error in `other.ps1`? | You get another PowerShell process in the former case and the script cannot read variables defined in your current session:
```
PS> $foo = 'bar'
PS> 'Write-Host $foo'|Set-Content x.ps1
PS> & powershell .\x.ps1
PS> & .\x.ps1
bar
``` |
10839568 | find(1): "Parameter format not correct" under CygWin | 6 | 2012-05-31 18:55:45 | <p>I'm trying to build Bochs from source. Therefore, I wrote an configure script. I didn't write my script from scratch - it's based on the <code>.conf.win32-vcpp</code> sh script out of the Bochs tarball. And the part of the script, which causes the problem, is <strong>out of the original</strong> Nochs tarball <stro... | 5,864 | 1,315,356 | 2012-05-31 19:31:16 | 10,840,077 | 12 | 2012-05-31 19:31:16 | 14,122 | 2012-05-31 19:31:16 | https://stackoverflow.com/q/10839568 | https://stackoverflow.com/a/10840077 | <p>Be sure your Cygwin installation includes the <code>findutils</code> package, and that Cygwin's <code>find</code> is first in your <code>PATH</code> (before the native Windows one).</p>
<p>If <code>find --help</code> returns <code>FIND: Paramater format not correct</code> (or your localized equivalent), this is a s... | <p>Be sure your Cygwin installation includes the <code>findutils</code> package, and that Cygwin's <code>find</code> is first in your <code>PATH</code> (before the native Windows one).</p> <p>If <code>find --help</code> returns <code>FIND: Paramater format not correct</code> (or your localized equivalent), this is a s... | 387, 390, 1231, 1731 | bash, command-line, cygwin, shell | <h1>find(1): "Parameter format not correct" under CygWin</h1>
<p>I'm trying to build Bochs from source. Therefore, I wrote an configure script. I didn't write my script from scratch - it's based on the <code>.conf.win32-vcpp</code> sh script out of the Bochs tarball. And the part of the script, which causes the proble... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,146 | bash | # find(1): "Parameter format not correct" under CygWin
I'm trying to build Bochs from source. Therefore, I wrote an configure script. I didn't write my script from scratch - it's based on the `.conf.win32-vcpp` sh script out of the Bochs tarball. And the part of the script, which causes the problem, is **out of the or... | Be sure your Cygwin installation includes the `findutils` package, and that Cygwin's `find` is first in your `PATH` (before the native Windows one).
If `find --help` returns `FIND: Paramater format not correct` (or your localized equivalent), this is a sure sign that it's the Windows one, rather than the Cygwin one, c... |
10680786 | How to view file date of result of find command in bash | 6 | 2012-05-21 07:05:18 | <p>I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not show the filedate column in result, also I tried this:</p>
<pre><... | 12,790 | 516,512 | 2013-04-10 14:49:47 | 10,680,842 | 12 | 2012-05-21 07:09:51 | 259,310 | 2012-05-21 07:09:51 | https://stackoverflow.com/q/10680786 | https://stackoverflow.com/a/10680842 | <p>You need either <code>xargs</code> or <code>-exec</code> for this:</p>
<pre><code>find . -ctime 1 -exec ls -l {} \;
find . -ctime 1 | xargs ls -l
</code></pre>
<p>(The first executes <code>ls</code> on every found file individually, the second bunches them up into one ore more big <code>ls</code> invocations, so ... | <p>You need either <code>xargs</code> or <code>-exec</code> for this:</p> <pre><code>find . -ctime 1 -exec ls -l {} \; find . -ctime 1 | xargs ls -l </code></pre> <p>(The first executes <code>ls</code> on every found file individually, the second bunches them up into one ore more big <code>ls</code> invocations, so ... | 387, 3589, 10193 | bash, find, ls | <h1>How to view file date of result of find command in bash</h1>
<p>I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,147 | bash | # How to view file date of result of find command in bash
I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not show the f... | You need either `xargs` or `-exec` for this:
```
find . -ctime 1 -exec ls -l {} \;
find . -ctime 1 | xargs ls -l
```
(The first executes `ls` on every found file individually, the second bunches them up into one ore more big `ls` invocations, so that they may be formatted slightly better.) |
10483945 | How can I force grep to only return files and ignore directories? | 6 | 2012-05-07 14:34:04 | <p>I'm trying to use grep to automatically locate the bibtex program in the user's bin folder.</p>
<p>The problem is, it frequently returns a directory with the name bibtex, which means that the script fails to automatically run the command.</p>
<p>How can I force grep (or indeed the locate command) to automatically ... | 3,482 | 1,073,964 | 2012-05-07 16:39:29 | 10,483,976 | 12 | 2012-05-07 14:37:02 | 2,998 | 2012-05-07 14:37:02 | https://stackoverflow.com/q/10483945 | https://stackoverflow.com/a/10483976 | <p>The <code>find</code> command?</p>
<pre><code>find /bin -name bibtex -type f
</code></pre>
<p>Looks for a file name "bibtex" of type "f", which is a regular file.</p>
| <p>The <code>find</code> command?</p> <pre><code>find /bin -name bibtex -type f </code></pre> <p>Looks for a file name "bibtex" of type "f", which is a regular file.</p> | 34, 387, 1271, 26269 | bash, grep, locate, unix | <h1>How can I force grep to only return files and ignore directories?</h1>
<p>I'm trying to use grep to automatically locate the bibtex program in the user's bin folder.</p>
<p>The problem is, it frequently returns a directory with the name bibtex, which means that the script fails to automatically run the command.</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,148 | bash | # How can I force grep to only return files and ignore directories?
I'm trying to use grep to automatically locate the bibtex program in the user's bin folder.
The problem is, it frequently returns a directory with the name bibtex, which means that the script fails to automatically run the command.
How can I force g... | The `find` command?
```
find /bin -name bibtex -type f
```
Looks for a file name "bibtex" of type "f", which is a regular file. |
10403886 | I'm trying to find files with multiple extensions in a shell script | 6 | 2012-05-01 20:27:19 | <p>Here's what I have so far</p>
<pre><code>DIR="/home/username/Pictures/Wallpapers"
while [ 1 -eq 1 ]
do
PIC=$(ls $DIR/*.jpg | shuf -n1)
PIC1="file://"$PIC
gsettings set org.gnome.desktop.background picture-uri $PIC1
sleep 30;
done
</code></pre>
<p>The script works, but I can't figure out how to ex... | 9,764 | 1,368,559 | 2012-05-01 21:29:13 | 10,403,967 | 12 | 2012-05-01 20:34:00 | 1,360,989 | 2012-05-01 20:34:00 | https://stackoverflow.com/q/10403886 | https://stackoverflow.com/a/10403967 | <p>How about using find?</p>
<pre><code>find $DIR -name \*.jpg -o -name \*.png -o -name \*.gif -print
</code></pre>
| <p>How about using find?</p> <pre><code>find $DIR -name \*.jpg -o -name \*.png -o -name \*.gif -print </code></pre> | 58, 390 | linux, shell | <h1>I'm trying to find files with multiple extensions in a shell script</h1>
<p>Here's what I have so far</p>
<pre><code>DIR="/home/username/Pictures/Wallpapers"
while [ 1 -eq 1 ]
do
PIC=$(ls $DIR/*.jpg | shuf -n1)
PIC1="file://"$PIC
gsettings set org.gnome.desktop.background picture-uri $PIC1
sleep ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,149 | bash | # I'm trying to find files with multiple extensions in a shell script
Here's what I have so far
```
DIR="/home/username/Pictures/Wallpapers"
while [ 1 -eq 1 ]
do
PIC=$(ls $DIR/*.jpg | shuf -n1)
PIC1="file://"$PIC
gsettings set org.gnome.desktop.background picture-uri $PIC1
sleep 30;
done
```
The sc... | How about using find?
```
find $DIR -name \*.jpg -o -name \*.png -o -name \*.gif -print
``` |
9686360 | "< <(command-here)" shell idiom resulting in "redirection unexpected" | 6 | 2012-03-13 14:45:59 | <p>This command works fine:</p>
<pre><code>$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
</code></pre>
<p>However, I don't understand how exactly <code>stable</code> is passed as a parameter to the shell script that is downloaded by curl. That's the reason... | 2,941 | 513,342 | 2012-03-13 15:09:37 | 9,686,394 | 12 | 2012-03-13 14:48:14 | 14,122 | 2012-03-13 15:09:37 | https://stackoverflow.com/q/9686360 | https://stackoverflow.com/a/9686394 | <h2>Regarding the "redirection unexpected" error:</h2>
<p>That's not related to <code>stable</code>, it's related to your script using <code>/bin/sh</code>, not <code>bash</code>. The <code><()</code> syntax is unavailable in POSIX shells, which includes bash when invoked as <code>/bin/sh</code> (in which case it t... | <h2>Regarding the "redirection unexpected" error:</h2> <p>That's not related to <code>stable</code>, it's related to your script using <code>/bin/sh</code>, not <code>bash</code>. The <code><()</code> syntax is unavailable in POSIX shells, which includes bash when invoked as <code>/bin/sh</code> (in which case it t... | 387, 390, 1701, 31901 | bash, http-redirect, shell, stdin | <h1>"< <(command-here)" shell idiom resulting in "redirection unexpected"</h1>
<p>This command works fine:</p>
<pre><code>$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
</code></pre>
<p>However, I don't understand how exactly <code>stable</code> is passed a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,150 | bash | # "< <(command-here)" shell idiom resulting in "redirection unexpected"
This command works fine:
```
$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
```
However, I don't understand how exactly `stable` is passed as a parameter to the shell script that is download... | ## Regarding the "redirection unexpected" error:
That's not related to `stable`, it's related to your script using `/bin/sh`, not `bash`. The `<()` syntax is unavailable in POSIX shells, which includes bash when invoked as `/bin/sh` (in which case it turns off nonstandard functionality for compatibility reasons).
Mak... |
9212459 | Can I access My Custom .NET Class from PowerShell? | 6 | 2012-02-09 14:16:53 | <p>I have a couple of questions and doubts to regarding PowerShell and .NET Classes.</p>
<p>I am trying to write a class 'foo' that will call Rest web service and perform some tasks. If I deploy the class in GAC then can I call it from PowerShell?</p>
| 5,783 | 581,922 | 2012-02-09 14:42:27 | 9,212,538 | 12 | 2012-02-09 14:21:38 | 520,612 | 2012-02-09 14:42:27 | https://stackoverflow.com/q/9212459 | https://stackoverflow.com/a/9212538 | <p>Try:</p>
<pre><code>ADD-TYPE -AssemblyName myassemblyname
</code></pre>
<p>or</p>
<pre><code>[System.Reflection.Assembly]::LoadWithPartialName("myassemblyname")
</code></pre>
<p>to access method/properties of your assembly you can do this:</p>
<pre><code>[myassemblyname]::mymethod()
[myassemblyname]::myproperty... | <p>Try:</p> <pre><code>ADD-TYPE -AssemblyName myassemblyname </code></pre> <p>or</p> <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("myassemblyname") </code></pre> <p>to access method/properties of your assembly you can do this:</p> <pre><code>[myassemblyname]::mymethod() [myassemblyname]::myproperty... | 1, 9, 526, 2579 | .net, c#, powershell, web-services | <h1>Can I access My Custom .NET Class from PowerShell?</h1>
<p>I have a couple of questions and doubts to regarding PowerShell and .NET Classes.</p>
<p>I am trying to write a class 'foo' that will call Rest web service and perform some tasks. If I deploy the class in GAC then can I call it from PowerShell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,151 | bash | # Can I access My Custom .NET Class from PowerShell?
I have a couple of questions and doubts to regarding PowerShell and .NET Classes.
I am trying to write a class 'foo' that will call Rest web service and perform some tasks. If I deploy the class in GAC then can I call it from PowerShell? | Try:
```
ADD-TYPE -AssemblyName myassemblyname
```
or
```
[System.Reflection.Assembly]::LoadWithPartialName("myassemblyname")
```
to access method/properties of your assembly you can do this:
```
[myassemblyname]::mymethod()
[myassemblyname]::myproperty
``` |
8995482 | [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm": What does it do? | 6 | 2012-01-24 22:54:28 | <p>I am installing Ruby on Rails on Mac OS X. The tutorial I am following says to add:</p>
<pre><code>[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
</code></pre>
<p>to <code>~/.bash_profile</code>.</p>
<p>What does this line do?</p>
<p>Thanks</p>
| 2,539 | 716,082 | 2012-04-19 19:45:07 | 8,995,550 | 12 | 2012-01-24 23:00:09 | 970,195 | 2012-01-24 23:17:13 | https://stackoverflow.com/q/8995482 | https://stackoverflow.com/a/8995550 | <p><strong><code>[[ -s "$HOME/.rvm/scripts/rvm" ]]</code></strong></p>
<p>This portion is a test condition (<code>[[</code> is the new test command). <strong><code>-s</code></strong> returns <strong><code>TRUE</code></strong> if the file <code>rvm</code> present over at <code>$HOME/.rvm/scripts/</code> location <stron... | <p><strong><code>[[ -s "$HOME/.rvm/scripts/rvm" ]]</code></strong></p> <p>This portion is a test condition (<code>[[</code> is the new test command). <strong><code>-s</code></strong> returns <strong><code>TRUE</code></strong> if the file <code>rvm</code> present over at <code>$HOME/.rvm/scripts/</code> location <stron... | 387 | bash | <h1>[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm": What does it do?</h1>
<p>I am installing Ruby on Rails on Mac OS X. The tutorial I am following says to add:</p>
<pre><code>[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
</code></pre>
<p>to <code>~/.bash_profile</code>.</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,152 | bash | # [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm": What does it do?
I am installing Ruby on Rails on Mac OS X. The tutorial I am following says to add:
```
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
```
to `~/.bash_profile`.
What does this line do?
Thanks | **`[[ -s "$HOME/.rvm/scripts/rvm" ]]`**
This portion is a test condition (`[[` is the new test command). **`-s`** returns **`TRUE`** if the file `rvm` present over at `$HOME/.rvm/scripts/` location **`exists and is of size greater than zero`**.
**`&&`**
This is a logical **`and`** operator. It executes the statement... |
8978954 | Why it needs an extra pair of bracket? | 6 | 2012-01-23 21:37:17 | <p>The following powershell script</p>
<pre><code>"one","two","three" | % { "$(($l++)): $_" }
</code></pre>
<p>will print</p>
<pre>
1: one
2: two
3: three
</pre>
<p>However, after remove the bracket around <code>$l++</code></p>
<pre><code>"one","two","three" | % { "$($l++): $_" }
</code></pre>
<p>it will print</p... | 342 | 825,920 | 2014-02-19 10:31:46 | 8,979,298 | 12 | 2012-01-23 22:07:41 | 1,021,945 | 2012-01-23 22:07:41 | https://stackoverflow.com/q/8978954 | https://stackoverflow.com/a/8979298 | <p>This is because <code>$l++</code> is a <strong>voidable statement</strong>. In powershell certain types of
expressions, when used as statements, are not displayed.
Voidable statements include assignments and the increment/decrement operators. When they are used in an expression, they return a value, but when they’r... | <p>This is because <code>$l++</code> is a <strong>voidable statement</strong>. In powershell certain types of expressions, when used as statements, are not displayed. Voidable statements include assignments and the increment/decrement operators. When they are used in an expression, they return a value, but when they’r... | 526 | powershell | <h1>Why it needs an extra pair of bracket?</h1>
<p>The following powershell script</p>
<pre><code>"one","two","three" | % { "$(($l++)): $_" }
</code></pre>
<p>will print</p>
<pre>
1: one
2: two
3: three
</pre>
<p>However, after remove the bracket around <code>$l++</code></p>
<pre><code>"one","two","three" | % { "$... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,153 | bash | # Why it needs an extra pair of bracket?
The following powershell script
```
"one","two","three" | % { "$(($l++)): $_" }
```
will print
```
1: one
2: two
3: three
```
However, after remove the bracket around `$l++`
```
"one","two","three" | % { "$($l++): $_" }
```
it will print
```
: one
: two
: three
``` | This is because `$l++` is a **voidable statement**. In powershell certain types of
expressions, when used as statements, are not displayed.
Voidable statements include assignments and the increment/decrement operators. When they are used in an expression, they return a value, but when they’re used as a standalone state... |
8884480 | Starting and killing java app with shell script (Debian) | 6 | 2012-01-16 18:21:08 | <p>I'm new to UNIX. I want to start my java app with a script like so:</p>
<pre><code>#!/bin/sh
java -jar /usr/ScriptCheck.jar &
echo $! > /var/run/ScriptCheck.pid
</code></pre>
<p>This is supposedly working. It does run the app and it does write the pid file. But when I try to stop the process with a differen... | 7,593 | 1,053,867 | 2012-01-18 12:45:00 | 8,884,735 | 12 | 2012-01-16 18:42:30 | 306,042 | 2012-01-16 18:59:32 | https://stackoverflow.com/q/8884480 | https://stackoverflow.com/a/8884735 | <p>You're passing a file name as an argument to <code>kill</code> when it expects a (proces id) number, so just read the process id from that file and pass it to <code>kill</code>:</p>
<pre><code>#!/bin/sh
PID=$(cat /var/run/ScriptCheck.pid)
kill -9 $PID
</code></pre>
| <p>You're passing a file name as an argument to <code>kill</code> when it expects a (proces id) number, so just read the process id from that file and pass it to <code>kill</code>:</p> <pre><code>#!/bin/sh PID=$(cat /var/run/ScriptCheck.pid) kill -9 $PID </code></pre> | 17, 58, 390, 1012 | debian, java, linux, shell | <h1>Starting and killing java app with shell script (Debian)</h1>
<p>I'm new to UNIX. I want to start my java app with a script like so:</p>
<pre><code>#!/bin/sh
java -jar /usr/ScriptCheck.jar &
echo $! > /var/run/ScriptCheck.pid
</code></pre>
<p>This is supposedly working. It does run the app and it does writ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,154 | bash | # Starting and killing java app with shell script (Debian)
I'm new to UNIX. I want to start my java app with a script like so:
```
#!/bin/sh
java -jar /usr/ScriptCheck.jar &
echo $! > /var/run/ScriptCheck.pid
```
This is supposedly working. It does run the app and it does write the pid file. But when I try to stop t... | You're passing a file name as an argument to `kill` when it expects a (proces id) number, so just read the process id from that file and pass it to `kill`:
```
#!/bin/sh
PID=$(cat /var/run/ScriptCheck.pid)
kill -9 $PID
``` |
8873431 | ksh function return value in parentheses | 6 | 2012-01-15 21:14:47 | <p>In the following very simple ksh script example, I need to ask if func1 results equal to 4 , </p>
<p>This is what I did in the example but this script does not print the "function result = 4" as I expected it to.</p>
<p>What do I need to change in the [[......]] in order to print the "function result = 4" </p>
<... | 37,513 | null | 2012-06-06 20:32:31 | 8,874,005 | 12 | 2012-01-15 22:42:42 | 620,097 | 2012-01-15 22:49:38 | https://stackoverflow.com/q/8873431 | https://stackoverflow.com/a/8874005 | <p>You need</p>
<pre><code>#!/bin/ksh
func1()
{
print -- 4
}
[[ $(func1) = 4 ]] && print "function result = 4"
</code></pre>
<p>OR</p>
<pre><code>#!/bin/ksh
func1()
{
return 4
}
func1 ; [[ $? == 4 ]] && print "function result = 4"
</code></pre>
<p>There are several i... | <p>You need</p> <pre><code>#!/bin/ksh func1() { print -- 4 } [[ $(func1) = 4 ]] && print "function result = 4" </code></pre> <p>OR</p> <pre><code>#!/bin/ksh func1() { return 4 } func1 ; [[ $? == 4 ]] && print "function result = 4" </code></pre> <p>There are several i... | 58, 387, 390, 1964, 5569 | bash, function, ksh, linux, shell | <h1>ksh function return value in parentheses</h1>
<p>In the following very simple ksh script example, I need to ask if func1 results equal to 4 , </p>
<p>This is what I did in the example but this script does not print the "function result = 4" as I expected it to.</p>
<p>What do I need to change in the [[......]] in... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,155 | bash | # ksh function return value in parentheses
In the following very simple ksh script example, I need to ask if func1 results equal to 4 ,
This is what I did in the example but this script does not print the "function result = 4" as I expected it to.
What do I need to change in the [[......]] in order to print the "fun... | You need
```
#!/bin/ksh
func1()
{
print -- 4
}
[[ $(func1) = 4 ]] && print "function result = 4"
```
OR
```
#!/bin/ksh
func1()
{
return 4
}
func1 ; [[ $? == 4 ]] && print "function result = 4"
```
There are several issues in the code that you present, so let me try to explain (You're ... |
8729566 | How can I use Regex to pull just the CN from a Distinguished Name with PowerShell | 6 | 2012-01-04 15:42:43 | <p>I have a bunch of strings that are DN's of groups from AD. I need to pull out the Common Name.
An example string is "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local"</p>
<p>What I am looking for is some PowerShell Code that will pull "Group Name I Want" out of that string and discard the rest. </p>... | 25,032 | 45,571 | 2019-05-10 19:23:22 | 8,729,599 | 12 | 2012-01-04 15:45:07 | 1,021,945 | 2012-01-04 15:45:07 | https://stackoverflow.com/q/8729566 | https://stackoverflow.com/a/8729599 | <pre><code>$s = "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local"
$s -replace "(CN=)(.*?),.*",'$2'
</code></pre>
| <pre><code>$s = "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local" $s -replace "(CN=)(.*?),.*",'$2' </code></pre> | 18, 526, 4645 | ldap, powershell, regex | <h1>How can I use Regex to pull just the CN from a Distinguished Name with PowerShell</h1>
<p>I have a bunch of strings that are DN's of groups from AD. I need to pull out the Common Name.
An example string is "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local"</p>
<p>What I am looking for is some Power... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,156 | bash | # How can I use Regex to pull just the CN from a Distinguished Name with PowerShell
I have a bunch of strings that are DN's of groups from AD. I need to pull out the Common Name.
An example string is "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local"
What I am looking for is some PowerShell Code that ... | ```
$s = "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local"
$s -replace "(CN=)(.*?),.*",'$2'
``` |
7595256 | Cancel multiple SharePoint Workflows using PowerShell | 6 | 2011-09-29 09:31:09 | <p>How is it possible to cancel all running workflows in a SharePoint (2010) List?</p>
<p>I found this script via technet.</p>
<p><a href="http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/d3913265-9712-4e61-9e38-1f9b78c8f718/" rel="noreferrer">http://social.technet.microsoft.com/Forum... | 21,617 | 730,733 | 2014-04-21 10:17:03 | 7,758,968 | 12 | 2011-10-13 18:50:00 | 244,132 | 2011-10-13 18:50:00 | https://stackoverflow.com/q/7595256 | https://stackoverflow.com/a/7758968 | <p>Give this one a shot.</p>
<p>I modified it so that it is done on a specific list on a specific web.</p>
<pre><code>#Site URL
$web = Get-SPWeb "http://urlforsite.com";
$web.AllowUnsafeUpdates = $true;
#List Name
$list = $web.Lists["ListName"];
# Iterate through all Items in List and all Workflows on Items. ... | <p>Give this one a shot.</p> <p>I modified it so that it is done on a specific list on a specific web.</p> <pre><code>#Site URL $web = Get-SPWeb "http://urlforsite.com"; $web.AllowUnsafeUpdates = $true; #List Name $list = $web.Lists["ListName"]; # Iterate through all Items in List and all Workflows on Items. ... | 526, 669, 43266 | powershell, sharepoint, sharepoint-workflow | <h1>Cancel multiple SharePoint Workflows using PowerShell</h1>
<p>How is it possible to cancel all running workflows in a SharePoint (2010) List?</p>
<p>I found this script via technet.</p>
<p><a href="http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/d3913265-9712-4e61-9e38-1f9b78c8f7... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,157 | bash | # Cancel multiple SharePoint Workflows using PowerShell
How is it possible to cancel all running workflows in a SharePoint (2010) List?
I found this script via technet.
<http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/d3913265-9712-4e61-9e38-1f9b78c8f718/>
CODE:
```
using (SPSite ... | Give this one a shot.
I modified it so that it is done on a specific list on a specific web.
```
#Site URL
$web = Get-SPWeb "http://urlforsite.com";
$web.AllowUnsafeUpdates = $true;
#List Name
$list = $web.Lists["ListName"];
# Iterate through all Items in List and all Workflows on Items.
foreach ($item... |
7151408 | Powershell, Mass moving files of a certain type | 6 | 2011-08-22 17:50:10 | <p>I want to make a script which will take a parent directory which has a number of child directories which have files in them. Using a listing I wish to move all of the files in the child directories in to the parent directory. </p>
<p>I have created the following code so far which gives a listing of all the files of... | 18,202 | 1,395,967 | 2017-12-07 06:59:28 | 7,153,226 | 12 | 2011-08-22 20:29:02 | 9,833 | 2011-08-22 20:29:02 | https://stackoverflow.com/q/7151408 | https://stackoverflow.com/a/7153226 | <p>A few things:</p>
<ol>
<li><p>You can pass the text you write to the screen directly to the read-host cmdlet, it saves you a line per user input.</p></li>
<li><p>As a rule of thumb, if you plan to do more with an output of a command, DO NOT pipe it to the format-* cmdlets. The format cmdlets produces formatting obj... | <p>A few things:</p> <ol> <li><p>You can pass the text you write to the screen directly to the read-host cmdlet, it saves you a line per user input.</p></li> <li><p>As a rule of thumb, if you plan to do more with an output of a command, DO NOT pipe it to the format-* cmdlets. The format cmdlets produces formatting obj... | 526, 578, 5310 | file, powershell, recursion | <h1>Powershell, Mass moving files of a certain type</h1>
<p>I want to make a script which will take a parent directory which has a number of child directories which have files in them. Using a listing I wish to move all of the files in the child directories in to the parent directory. </p>
<p>I have created the follow... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,158 | bash | # Powershell, Mass moving files of a certain type
I want to make a script which will take a parent directory which has a number of child directories which have files in them. Using a listing I wish to move all of the files in the child directories in to the parent directory.
I have created the following code so far w... | A few things:
1. You can pass the text you write to the screen directly to the read-host cmdlet, it saves you a line per user input.
2. As a rule of thumb, if you plan to do more with an output of a command, DO NOT pipe it to the format-* cmdlets. The format cmdlets produces formatting objects that instructs powershel... |
7051920 | How can you tell if bash is being accessed from a remote machine? | 6 | 2011-08-13 16:53:33 | <p>I am trying to write out a dynamic bash profile for a few machines, and was wondering if there is a variable that allows <code>.bashrc</code> if it is being accessed remotely. I've seen a few examples using X variables, but that is irrelevant to both machines. </p>
| 1,402 | 140,448 | 2011-08-13 18:05:21 | 7,052,278 | 12 | 2011-08-13 17:57:11 | 140,740 | 2011-08-13 17:57:11 | https://stackoverflow.com/q/7051920 | https://stackoverflow.com/a/7052278 | <pre><code>if [ "$SSH_CONNECTION" ]; then
echo I am remote
else
echo I am local
fi
</code></pre>
| <pre><code>if [ "$SSH_CONNECTION" ]; then echo I am remote else echo I am local fi </code></pre> | 387 | bash | <h1>How can you tell if bash is being accessed from a remote machine?</h1>
<p>I am trying to write out a dynamic bash profile for a few machines, and was wondering if there is a variable that allows <code>.bashrc</code> if it is being accessed remotely. I've seen a few examples using X variables, but that is irrelevant... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,159 | bash | # How can you tell if bash is being accessed from a remote machine?
I am trying to write out a dynamic bash profile for a few machines, and was wondering if there is a variable that allows `.bashrc` if it is being accessed remotely. I've seen a few examples using X variables, but that is irrelevant to both machines. | ```
if [ "$SSH_CONNECTION" ]; then
echo I am remote
else
echo I am local
fi
``` |
4136066 | Powershell does not release the memory | 6 | 2010-11-09 16:32:20 | <p>When running this script from <a href="https://stackoverflow.com/questions/4126603/powershell-or-batch-find-and-replace-characters">Powershell or Batch: find and replace characters</a> in Windows XP (Powershell 1.0) all goes well. But after script has stopped processing a text file, Powershell still holds over 1 000... | 10,372 | 477,087 | 2014-07-04 16:11:21 | 4,136,335 | 12 | 2010-11-09 17:00:41 | 353,410 | 2010-11-09 17:00:41 | https://stackoverflow.com/q/4136066 | https://stackoverflow.com/a/4136335 | <p>Try </p>
<pre><code> [GC]::Collect()
</code></pre>
<p>That enforces garbage collection</p>
| <p>Try </p> <pre><code> [GC]::Collect() </code></pre> <p>That enforces garbage collection</p> | 526, 2167, 2678 | memory-leaks, memory-management, powershell | <h1>Powershell does not release the memory</h1>
<p>When running this script from <a href="https://stackoverflow.com/questions/4126603/powershell-or-batch-find-and-replace-characters">Powershell or Batch: find and replace characters</a> in Windows XP (Powershell 1.0) all goes well. But after script has stopped processin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,160 | bash | # Powershell does not release the memory
When running this script from [Powershell or Batch: find and replace characters](https://stackoverflow.com/questions/4126603/powershell-or-batch-find-and-replace-characters) in Windows XP (Powershell 1.0) all goes well. But after script has stopped processing a text file, Power... | Try
```
[GC]::Collect()
```
That enforces garbage collection |
3936283 | Showing WinForms dialog with focus from powershell script | 6 | 2010-10-14 18:23:08 | <p>One of my coworkers just came to me with an interesting problem.</p>
<p>He's displaying a WinForms form from a PowerShell script, and while the form opens successfully it does not get focus. Instead the PowerShell command window retains focus until the form is explicitly clicked.</p>
<p>The script is being run fro... | 5,821 | 1,512 | 2022-11-14 13:35:05 | 3,936,806 | 12 | 2010-10-14 19:29:19 | 1,512 | 2010-10-14 19:29:19 | https://stackoverflow.com/q/3936283 | https://stackoverflow.com/a/3936806 | <p>This is how we got it working (the first line is the one we were missing):</p>
<pre><code>$WinForm.Add_Shown({$WinForm.Activate()})
$WinForm.ShowDialog($this) | out-null
</code></pre>
| <p>This is how we got it working (the first line is the one we were missing):</p> <pre><code>$WinForm.Add_Shown({$WinForm.Activate()}) $WinForm.ShowDialog($this) | out-null </code></pre> | 526, 865, 4183, 36252 | focus, powershell, user-interface, winforms | <h1>Showing WinForms dialog with focus from powershell script</h1>
<p>One of my coworkers just came to me with an interesting problem.</p>
<p>He's displaying a WinForms form from a PowerShell script, and while the form opens successfully it does not get focus. Instead the PowerShell command window retains focus until ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,161 | bash | # Showing WinForms dialog with focus from powershell script
One of my coworkers just came to me with an interesting problem.
He's displaying a WinForms form from a PowerShell script, and while the form opens successfully it does not get focus. Instead the PowerShell command window retains focus until the form is expl... | This is how we got it working (the first line is the one we were missing):
```
$WinForm.Add_Shown({$WinForm.Activate()})
$WinForm.ShowDialog($this) | out-null
``` |
3752621 | How do I determine if a gif is animated? | 6 | 2010-09-20 14:54:50 | <p>I have large number of files with .gif extension. I would like to move all animated gifs to another directory. How can I do this using linux shell?</p>
| 2,534 | 267,895 | 2010-09-20 16:06:06 | 3,752,732 | 12 | 2010-09-20 15:05:35 | 77,696 | 2010-09-20 16:06:06 | https://stackoverflow.com/q/3752621 | https://stackoverflow.com/a/3752732 | <p>Basically, if <a href="http://www.imagemagick.org/script/identify.php" rel="noreferrer">identify</a> returns more than one line for a GIF, it's likely animated because it contains more than one image. You may get false positives, however.</p>
<p>Example use in shell:</p>
<pre><code>for i in *.gif; do
if [ `iden... | <p>Basically, if <a href="http://www.imagemagick.org/script/identify.php" rel="noreferrer">identify</a> returns more than one line for a GIF, it's likely animated because it contains more than one image. You may get false positives, however.</p> <p>Example use in shell:</p> <pre><code>for i in *.gif; do if [ `iden... | 387, 8040, 11605 | animated-gif, bash, gif | <h1>How do I determine if a gif is animated?</h1>
<p>I have large number of files with .gif extension. I would like to move all animated gifs to another directory. How can I do this using linux shell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,162 | bash | # How do I determine if a gif is animated?
I have large number of files with .gif extension. I would like to move all animated gifs to another directory. How can I do this using linux shell? | Basically, if [identify](http://www.imagemagick.org/script/identify.php) returns more than one line for a GIF, it's likely animated because it contains more than one image. You may get false positives, however.
Example use in shell:
```
for i in *.gif; do
if [ `identify "$i" | wc -l` -gt 1 ] ; then
echo move "$... |
2615371 | Bash: Correct way to Iterate over Map | 6 | 2010-04-10 23:10:14 | <p>In Bash I can create a <strong>map</strong> (hashtable) with this common construction</p>
<pre><code>hput() {
eval "$1""$2"='$3'
}
hget() {
eval echo '${'"$1$2"'#hash}'
}
</code></pre>
<p>and then use it like this: </p>
<pre><code>hput capitals France Paris
hput capitals Spain Madrid
echo "$(hget capitals F... | 19,505 | 231,211 | 2011-08-04 14:12:35 | 2,615,433 | 12 | 2010-04-10 23:34:01 | 131,527 | 2010-04-10 23:34:01 | https://stackoverflow.com/q/2615371 | https://stackoverflow.com/a/2615433 | <p>if you have bash 4.0 , you can use <a href="http://tldp.org/LDP/abs/html/bashver4.html" rel="noreferrer">associative arrays</a>. else you can make use of <code>awk</code>s associative arrays</p>
| <p>if you have bash 4.0 , you can use <a href="http://tldp.org/LDP/abs/html/bashver4.html" rel="noreferrer">associative arrays</a>. else you can make use of <code>awk</code>s associative arrays</p> | 227, 387, 1834, 5189 | bash, dictionary, hashtable, iteration | <h1>Bash: Correct way to Iterate over Map</h1>
<p>In Bash I can create a <strong>map</strong> (hashtable) with this common construction</p>
<pre><code>hput() {
eval "$1""$2"='$3'
}
hget() {
eval echo '${'"$1$2"'#hash}'
}
</code></pre>
<p>and then use it like this: </p>
<pre><code>hput capitals France Paris
hpu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,163 | bash | # Bash: Correct way to Iterate over Map
In Bash I can create a **map** (hashtable) with this common construction
```
hput() {
eval "$1""$2"='$3'
}
hget() {
eval echo '${'"$1$2"'#hash}'
}
```
and then use it like this:
```
hput capitals France Paris
hput capitals Spain Madrid
echo "$(hget capitals France)"
```
... | if you have bash 4.0 , you can use [associative arrays](http://tldp.org/LDP/abs/html/bashver4.html). else you can make use of `awk`s associative arrays |
1685252 | PowerShell: how to copy only selected files from source directory? | 6 | 2009-11-06 03:33:11 | <p>I'm a Powershell newbie, trying to get a simple script to run.</p>
<p>I have a list of files that I want to copy from some src_dir to a dst_dir. I wrote a simple script (which is obviously wrong since it didnt do anything when I executed it).</p>
<p>Could someone please help check to see what I'm doing wrong?</p>
... | 16,923 | 65,313 | 2017-08-11 14:20:08 | 1,685,310 | 12 | 2009-11-06 03:52:51 | 65,313 | 2009-11-06 03:52:51 | https://stackoverflow.com/q/1685252 | https://stackoverflow.com/a/1685310 | <p>Oh..that was actually pretty easy:</p>
<pre><code># source and destionation directory
$src_dir = "C:\Users\Pac\Desktop\C4new\"
$dst_dir = "C:\Users\Pac\Desktop\csci578-hw3\Prism\C4new"
# list of files from source directory that I want to copy to destination folder
# unconditionally
$file_list = "C4newArchitecture.... | <p>Oh..that was actually pretty easy:</p> <pre><code># source and destionation directory $src_dir = "C:\Users\Pac\Desktop\C4new\" $dst_dir = "C:\Users\Pac\Desktop\csci578-hw3\Prism\C4new" # list of files from source directory that I want to copy to destination folder # unconditionally $file_list = "C4newArchitecture.... | 526 | powershell | <h1>PowerShell: how to copy only selected files from source directory?</h1>
<p>I'm a Powershell newbie, trying to get a simple script to run.</p>
<p>I have a list of files that I want to copy from some src_dir to a dst_dir. I wrote a simple script (which is obviously wrong since it didnt do anything when I executed it... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,164 | bash | # PowerShell: how to copy only selected files from source directory?
I'm a Powershell newbie, trying to get a simple script to run.
I have a list of files that I want to copy from some src_dir to a dst_dir. I wrote a simple script (which is obviously wrong since it didnt do anything when I executed it).
Could someon... | Oh..that was actually pretty easy:
```
# source and destionation directory
$src_dir = "C:\Users\Pac\Desktop\C4new\"
$dst_dir = "C:\Users\Pac\Desktop\csci578-hw3\Prism\C4new"
# list of files from source directory that I want to copy to destination folder
# unconditionally
$file_list = "C4newArchitecture.java",
... |
844632 | Can I put something in in bashrc to hide text editor (~ extension) files? | 6 | 2009-05-10 03:32:08 | <p>I'd like to do ls without seeing all the ~ files generated by vim. Is it possible?</p>
| 1,501 | 94,633 | 2011-05-15 21:38:50 | 844,636 | 12 | 2009-05-10 03:39:18 | 53,850 | 2009-05-10 16:26:43 | https://stackoverflow.com/q/844632 | https://stackoverflow.com/a/844636 | <p>This is better solved from within vim, as opposed to bash.</p>
<p>Use</p>
<pre><code>set backupdir=~/.backup,/tmp
</code></pre>
<p>to put all your ~ files in the <code>~/.backup</code> directory. Change that directory to whatever you want. The <code>/tmp</code> means that it will act as a fallback to the <code>~/... | <p>This is better solved from within vim, as opposed to bash.</p> <p>Use</p> <pre><code>set backupdir=~/.backup,/tmp </code></pre> <p>to put all your ~ files in the <code>~/.backup</code> directory. Change that directory to whatever you want. The <code>/tmp</code> means that it will act as a fallback to the <code>~/... | 58, 387 | bash, linux | <h1>Can I put something in in bashrc to hide text editor (~ extension) files?</h1>
<p>I'd like to do ls without seeing all the ~ files generated by vim. Is it possible?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,165 | bash | # Can I put something in in bashrc to hide text editor (~ extension) files?
I'd like to do ls without seeing all the ~ files generated by vim. Is it possible? | This is better solved from within vim, as opposed to bash.
Use
```
set backupdir=~/.backup,/tmp
```
to put all your ~ files in the `~/.backup` directory. Change that directory to whatever you want. The `/tmp` means that it will act as a fallback to the `~/.backup` directory.
If you don't want backup files to be gen... |
345518 | parsing a line in bash | 6 | 2008-12-05 23:36:18 | <p>I have a file that has one entry per line. Each line has the following format:</p>
<pre><code> "group:permissions:users"
</code></pre>
<p>Permissions and users could have more than one value separated by comas like this:</p>
<pre><code> "grp1:create,delete:yo,el,ella"
</code></pre>
<p>I want is to return the f... | 28,148 | null | 2012-07-19 04:24:24 | 345,528 | 12 | 2008-12-05 23:41:14 | 20,840 | 2008-12-05 23:41:14 | https://stackoverflow.com/q/345518 | https://stackoverflow.com/a/345528 | <p>You can use awk, with the -F option to use : as the field separator: </p>
<pre><code>[user@host]$ echo "grp1:create,delete:yo,el,ella" | awk -F ':' '{print $3}'
yo,el,ella
</code></pre>
<p>That will get you just the users string, separated by commas. Then you can do whatever you want with that string. If you want ... | <p>You can use awk, with the -F option to use : as the field separator: </p> <pre><code>[user@host]$ echo "grp1:create,delete:yo,el,ella" | awk -F ':' '{print $3}' yo,el,ella </code></pre> <p>That will get you just the users string, separated by commas. Then you can do whatever you want with that string. If you want ... | 387, 1357 | bash, parsing | <h1>parsing a line in bash</h1>
<p>I have a file that has one entry per line. Each line has the following format:</p>
<pre><code> "group:permissions:users"
</code></pre>
<p>Permissions and users could have more than one value separated by comas like this:</p>
<pre><code> "grp1:create,delete:yo,el,ella"
</code></pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,166 | bash | # parsing a line in bash
I have a file that has one entry per line. Each line has the following format:
```
"group:permissions:users"
```
Permissions and users could have more than one value separated by comas like this:
```
"grp1:create,delete:yo,el,ella"
```
I want is to return the following:
```
yo
el
ella
`... | You can use awk, with the -F option to use : as the field separator:
```
[user@host]$ echo "grp1:create,delete:yo,el,ella" | awk -F ':' '{print $3}'
yo,el,ella
```
That will get you just the users string, separated by commas. Then you can do whatever you want with that string. If you want to literally print each user... |
42735929 | How to delete a word in iTerm in mac os | 116 | 2017-03-11 13:44:18 | <p>I am using iTerm as a terminal in my mac. I am not able to delete a word in command line for ex in command <code>cd /path/to/dir</code>, i want to delete just <code>path</code> word , then how can i do that in iTerm.</p>
<p>basically what is the shortcut to delete a word in iTerm. </p>
<p>I looked at <a href="http... | 44,383 | 4,296,092 | 2025-02-11 11:02:16 | 42,736,566 | 11 | 2017-03-11 14:48:54 | 4,984,832 | 2017-03-11 14:48:54 | https://stackoverflow.com/q/42735929 | https://stackoverflow.com/a/42736566 | <p><kbd>esc</kbd>+<kbd>d</kbd> should work as a default.</p>
<p>Or you can add a <code>Send Escape Sequence</code> based keyboard mapping for <code>esc-d</code>:</p>
<p><a href="https://i.sstatic.net/Ftawu.png" rel="noreferrer"><img src="https://i.sstatic.net/Ftawu.png" alt="enter image description here"></a></p>
| <p><kbd>esc</kbd>+<kbd>d</kbd> should work as a default.</p> <p>Or you can add a <code>Send Escape Sequence</code> based keyboard mapping for <code>esc-d</code>:</p> <p><a href="https://i.sstatic.net/Ftawu.png" rel="noreferrer"><img src="https://i.sstatic.net/Ftawu.png" alt="enter image description here"></a></p> | 369, 390, 25122 | iterm, macos, shell | <h1>How to delete a word in iTerm in mac os</h1>
<p>I am using iTerm as a terminal in my mac. I am not able to delete a word in command line for ex in command <code>cd /path/to/dir</code>, i want to delete just <code>path</code> word , then how can i do that in iTerm.</p>
<p>basically what is the shortcut to delete a ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,167 | bash | # How to delete a word in iTerm in mac os
I am using iTerm as a terminal in my mac. I am not able to delete a word in command line for ex in command `cd /path/to/dir`, i want to delete just `path` word , then how can i do that in iTerm.
basically what is the shortcut to delete a word in iTerm.
I looked at <https://a... | `esc`+`d` should work as a default.
Or you can add a `Send Escape Sequence` based keyboard mapping for `esc-d`:
[](https://i.sstatic.net/Ftawu.png) |
2416662 | What are the PowerShell equivalents of Bash's && and || operators? | 74 | 2010-03-10 12:04:26 | <p>In Bash I can easily do something like</p>
<pre><code>command1 && command2 || command3
</code></pre>
<p>which means to run command1 and if command1 succeeds to run command2 and if command1 fails to run command3.</p>
<p>What's the equivalent in PowerShell?</p>
| 43,847 | 4,886 | 2025-11-16 16:49:19 | 2,416,889 | 11 | 2010-03-10 12:43:31 | 99,492 | 2023-05-28 19:42:54 | https://stackoverflow.com/q/2416662 | https://stackoverflow.com/a/2416889 | <p>What Bash must be doing is interpreting the integer exit code of the commands as true or false when passed to the logical operators. PowerShell doesn't do this - but a function can be made to wrap the command and create the same behavior:</p>
<pre><code>> function Get-ExitBoolean($cmd) { & $cmd | Out-Null; $... | <p>What Bash must be doing is interpreting the integer exit code of the commands as true or false when passed to the logical operators. PowerShell doesn't do this - but a function can be made to wrap the command and create the same behavior:</p> <pre><code>> function Get-ExitBoolean($cmd) { & $cmd | Out-Null; $... | 387, 526, 3915 | bash, language-comparisons, powershell | <h1>What are the PowerShell equivalents of Bash's && and || operators?</h1>
<p>In Bash I can easily do something like</p>
<pre><code>command1 && command2 || command3
</code></pre>
<p>which means to run command1 and if command1 succeeds to run command2 and if command1 fails to run command3.</p>
<p>What's the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,168 | bash | # What are the PowerShell equivalents of Bash's && and || operators?
In Bash I can easily do something like
```
command1 && command2 || command3
```
which means to run command1 and if command1 succeeds to run command2 and if command1 fails to run command3.
What's the equivalent in PowerShell? | What Bash must be doing is interpreting the integer exit code of the commands as true or false when passed to the logical operators. PowerShell doesn't do this - but a function can be made to wrap the command and create the same behavior:
```
> function Get-ExitBoolean($cmd) { & $cmd | Out-Null; $? }
```
([$? is a bo... |
3760086 | Automatic tagging of releases | 71 | 2010-09-21 12:05:52 | <p>How do you tag your release versions in git?</p>
<p>Now I have each release identified by build number, but they increment even if there are no changes in the repo. My idea is to have it generated automatically on successful deployment on staging server. E.g.</p>
<ul>
<li>run Hudson build</li>
<li>when successful,... | 81,870 | 234,780 | 2022-10-14 04:52:29 | 3,760,464 | 11 | 2010-09-21 12:55:51 | 6,309 | 2019-08-17 01:27:02 | https://stackoverflow.com/q/3760086 | https://stackoverflow.com/a/3760464 | <p>What you are talking about is more akin to a <a href="https://stackoverflow.com/questions/677436/how-to-get-the-git-commit-count/677510#677510">technical revision number</a> like the one <a href="https://stackoverflow.com/questions/1238992/branch-master-tag-revision-increments-using-git">a <code>git describe</code> ... | <p>What you are talking about is more akin to a <a href="https://stackoverflow.com/questions/677436/how-to-get-the-git-commit-count/677510#677510">technical revision number</a> like the one <a href="https://stackoverflow.com/questions/1238992/branch-master-tag-revision-increments-using-git">a <code>git describe</code> ... | 119, 387, 3858 | bash, git, hudson | <h1>Automatic tagging of releases</h1>
<p>How do you tag your release versions in git?</p>
<p>Now I have each release identified by build number, but they increment even if there are no changes in the repo. My idea is to have it generated automatically on successful deployment on staging server. E.g.</p>
<ul>
<li>run... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,169 | bash | # Automatic tagging of releases
How do you tag your release versions in git?
Now I have each release identified by build number, but they increment even if there are no changes in the repo. My idea is to have it generated automatically on successful deployment on staging server. E.g.
- run Hudson build
- when succes... | What you are talking about is more akin to a [technical revision number](https://stackoverflow.com/questions/677436/how-to-get-the-git-commit-count/677510#677510) like the one [a `git describe` would generate](https://stackoverflow.com/questions/1238992/branch-master-tag-revision-increments-using-git).
That is differe... |
7132514 | How to unzip a piped zip file (from "wget -qO-")? | 59 | 2011-08-20 14:54:50 | <p>Any ideas on how to unzip a piped zip file like this:</p>
<pre><code>wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
</code></pre>
<p>I wished to unzip the file to a directory, like we used to do with a normal file:</p>
<pre><code>wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip... | 80,082 | 559,742 | 2024-04-15 23:41:19 | 7,142,865 | 11 | 2011-08-22 03:22:20 | 204,606 | 2019-11-01 02:01:37 | https://stackoverflow.com/q/7132514 | https://stackoverflow.com/a/7142865 | <pre><code>wget -q -O tmp.zip http://downloads.wordpress.org/plugin/akismet.2.5.3.zip && unzip tmp.zip && rm tmp.zip
</code></pre>
| <pre><code>wget -q -O tmp.zip http://downloads.wordpress.org/plugin/akismet.2.5.3.zip && unzip tmp.zip && rm tmp.zip </code></pre> | 387, 5583, 7597 | bash, unzip, wget | <h1>How to unzip a piped zip file (from "wget -qO-")?</h1>
<p>Any ideas on how to unzip a piped zip file like this:</p>
<pre><code>wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
</code></pre>
<p>I wished to unzip the file to a directory, like we used to do with a normal file:</p>
<pre><code>wget -... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,170 | bash | # How to unzip a piped zip file (from "wget -qO-")?
Any ideas on how to unzip a piped zip file like this:
```
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
```
I wished to unzip the file to a directory, like we used to do with a normal file:
```
wget -qO- http://downloads.wordpress.org/plugin/ak... | ```
wget -q -O tmp.zip http://downloads.wordpress.org/plugin/akismet.2.5.3.zip && unzip tmp.zip && rm tmp.zip
``` |
7851889 | Kill process after a given time bash? | 44 | 2011-10-21 15:42:55 | <p>I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.</p>
<p>If it takes longer then 5 seconds to connect, kill the process<br>
Else kill the sleep/kill process.</p>
<p>The issue I'm having is how ... | 60,896 | 685,022 | 2020-07-09 00:10:54 | 7,855,501 | 11 | 2011-10-21 21:30:31 | 988,052 | 2020-07-09 00:10:54 | https://stackoverflow.com/q/7851889 | https://stackoverflow.com/a/7855501 | <p>I don't know if it's identical but I did fix a similar issue a few years ago. However I'm a programmer, not a Unix-like sysadmin so take the following with a grain of salt because my Bash-fu may not be that strong...</p>
<p>Basically I did fork, fork and fork : )</p>
<p><strike>Out of memory</strike> After founding... | <p>I don't know if it's identical but I did fix a similar issue a few years ago. However I'm a programmer, not a Unix-like sysadmin so take the following with a grain of salt because my Bash-fu may not be that strong...</p> <p>Basically I did fork, fork and fork : )</p> <p><strike>Out of memory</strike> After founding... | 387, 5779 | bash, kill | <h1>Kill process after a given time bash?</h1>
<p>I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.</p>
<p>If it takes longer then 5 seconds to connect, kill the process<br>
Else kill the sleep/kil... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,171 | bash | # Kill process after a given time bash?
I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.
If it takes longer then 5 seconds to connect, kill the process
Else kill the sleep/kill process.
The is... | I don't know if it's identical but I did fix a similar issue a few years ago. However I'm a programmer, not a Unix-like sysadmin so take the following with a grain of salt because my Bash-fu may not be that strong...
Basically I did fork, fork and fork : )
Out of memory After founding back my old code (which I amazin... |
2488715 | idioms for returning multiple values in shell scripting | 40 | 2010-03-21 21:06:27 | <p>Are there any idioms for returning multiple values from a bash function within a script?</p>
<p><a href="http://tldp.org/LDP/abs/html/assortedtips.html" rel="noreferrer">http://tldp.org/LDP/abs/html/assortedtips.html</a> describes how to echo multiple values and process the results (e.g., example 35-17), but that g... | 56,891 | 194,089 | 2024-03-08 06:09:11 | 2,489,972 | 11 | 2010-03-22 04:06:37 | 105,927 | 2010-03-22 04:06:37 | https://stackoverflow.com/q/2488715 | https://stackoverflow.com/a/2489972 | <p>Much as I love shell, it's probably the case that as soon as you're throwing arbitrary structured data around, Unix bourne/posix shell is not the right choice.</p>
<p>If there are characters which do not occur inside fields, then separate with one of those. The classic example is <code>/etc/passwd</code>, <code>/e... | <p>Much as I love shell, it's probably the case that as soon as you're throwing arbitrary structured data around, Unix bourne/posix shell is not the right choice.</p> <p>If there are characters which do not occur inside fields, then separate with one of those. The classic example is <code>/etc/passwd</code>, <code>/e... | 390, 3485 | idioms, shell | <h1>idioms for returning multiple values in shell scripting</h1>
<p>Are there any idioms for returning multiple values from a bash function within a script?</p>
<p><a href="http://tldp.org/LDP/abs/html/assortedtips.html" rel="noreferrer">http://tldp.org/LDP/abs/html/assortedtips.html</a> describes how to echo multiple... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,172 | bash | # idioms for returning multiple values in shell scripting
Are there any idioms for returning multiple values from a bash function within a script?
<http://tldp.org/LDP/abs/html/assortedtips.html> describes how to echo multiple values and process the results (e.g., example 35-17), but that gets tricky if some of the r... | Much as I love shell, it's probably the case that as soon as you're throwing arbitrary structured data around, Unix bourne/posix shell is not the right choice.
If there are characters which do not occur inside fields, then separate with one of those. The classic example is `/etc/passwd`, `/etc/group` and various other... |
32926740 | How to kill a process by its pid on Linux? | 37 | 2015-10-03 19:41:28 | <p>I'm new to Linux and I'm building a program that receives the name of a process, gets its PID (I have no problem with that part) and then passes the PID to the <code>kill</code> command, but its not working.</p>
<p>It goes something like this:</p>
<pre><code>read -p "Process to kill: " proceso
proid= pidof... | 337,755 | 5,405,203 | 2025-04-21 20:03:17 | 32,926,763 | 11 | 2015-10-03 19:44:06 | 641,955 | 2015-10-03 20:37:50 | https://stackoverflow.com/q/32926740 | https://stackoverflow.com/a/32926763 | <p>Instead of this:</p>
<blockquote>
<pre><code>proid= pidof $proceso
</code></pre>
</blockquote>
<p>You probably meant this:</p>
<pre><code>proid=$(pidof $proceso)
</code></pre>
<p>Even so,
the program might not get killed.
By default, <code>kill PID</code> sends the <code>TERM</code> signal to the specified proce... | <p>Instead of this:</p> <blockquote> <pre><code>proid= pidof $proceso </code></pre> </blockquote> <p>You probably meant this:</p> <pre><code>proid=$(pidof $proceso) </code></pre> <p>Even so, the program might not get killed. By default, <code>kill PID</code> sends the <code>TERM</code> signal to the specified proce... | 58, 387, 1796, 5779, 5910 | bash, command, kill, linux, process | <h1>How to kill a process by its pid on Linux?</h1>
<p>I'm new to Linux and I'm building a program that receives the name of a process, gets its PID (I have no problem with that part) and then passes the PID to the <code>kill</code> command, but its not working.</p>
<p>It goes something like this:</p>
<pre><code>read -... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,173 | bash | # How to kill a process by its pid on Linux?
I'm new to Linux and I'm building a program that receives the name of a process, gets its PID (I have no problem with that part) and then passes the PID to the `kill` command, but its not working.
It goes something like this:
```
read -p "Process to kill: " proceso
proid=... | Instead of this:
> ```
> proid= pidof $proceso
> ```
You probably meant this:
```
proid=$(pidof $proceso)
```
Even so,
the program might not get killed.
By default, `kill PID` sends the `TERM` signal to the specified process,
giving it a chance to shut down in an orderly manner,
for example clean up resources it's ... |
2135770 | Bash for loop with wildcards and hidden files | 37 | 2010-01-25 21:26:12 | <p>Just witting a simple shell script and little confused:</p>
<p>Here is my script:</p>
<pre><code>% for f in $FILES; do echo "Processing $f file.."; done
</code></pre>
<p>The Command: </p>
<pre><code>ls -la | grep bash
</code></pre>
<p>produces:</p>
<pre><code>% ls -a | grep bash
.bash_from_cshrc
.bash_history... | 28,653 | 251,589 | 2024-10-01 03:10:52 | 2,135,812 | 11 | 2010-01-25 21:32:51 | 149,237 | 2010-01-25 21:35:25 | https://stackoverflow.com/q/2135770 | https://stackoverflow.com/a/2135812 | <p><code>FILES=".bash*"</code> works because the hidden files name begin with a <code>.</code></p>
<p><code>FILES="bash*"</code> doesn't work because the hidden files name begin with a <code>.</code> not a <code>b</code></p>
<p><code>FILES="*bash*"</code> doesn't work because the <code>*</code> wildcard at the beginn... | <p><code>FILES=".bash*"</code> works because the hidden files name begin with a <code>.</code></p> <p><code>FILES="bash*"</code> doesn't work because the hidden files name begin with a <code>.</code> not a <code>b</code></p> <p><code>FILES="*bash*"</code> doesn't work because the <code>*</code> wildcard at the beginn... | 387, 531, 2314, 5997 | bash, loops, scripting, wildcard | <h1>Bash for loop with wildcards and hidden files</h1>
<p>Just witting a simple shell script and little confused:</p>
<p>Here is my script:</p>
<pre><code>% for f in $FILES; do echo "Processing $f file.."; done
</code></pre>
<p>The Command: </p>
<pre><code>ls -la | grep bash
</code></pre>
<p>produces:</p>
<pre><... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,174 | bash | # Bash for loop with wildcards and hidden files
Just witting a simple shell script and little confused:
Here is my script:
```
% for f in $FILES; do echo "Processing $f file.."; done
```
The Command:
```
ls -la | grep bash
```
produces:
```
% ls -a | grep bash
.bash_from_cshrc
.bash_history
.bash_profile
.bashrc... | `FILES=".bash*"` works because the hidden files name begin with a `.`
`FILES="bash*"` doesn't work because the hidden files name begin with a `.` not a `b`
`FILES="*bash*"` doesn't work because the `*` wildcard at the beginning of a string omits hidden files. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.