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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
47041712 | Is it secure to use a password argument in a Windows command? | 10 | 2017-10-31 17:53:37 | <p>Imagine that we have a program or script that can take a password (or other sensitive information) argument: </p>
<pre><code>> program.exe /password:secret
</code></pre>
<p>For Linux, best practice generally recommends <em>against</em> specifying the password directly on the command-line because of potential se... | 10,119 | 5,209,322 | 2024-10-17 14:01:52 | 47,041,982 | 13 | 2017-10-31 18:10:31 | 3,905,079 | 2017-10-31 19:10:00 | https://stackoverflow.com/q/47041712 | https://stackoverflow.com/a/47041982 | <p>Windows historically didn't save command history between sessions, only within the session. This was true for the command prompt and for PowerShell.</p>
<p>As <a href="https://stackoverflow.com/users/2102693/bill-stewart">Bill Stewart</a> pointed out, Windows PowerShell on Windows 10 and Windows 2016 includes PSRea... | <p>Windows historically didn't save command history between sessions, only within the session. This was true for the command prompt and for PowerShell.</p> <p>As <a href="https://stackoverflow.com/users/2102693/bill-stewart">Bill Stewart</a> pointed out, Windows PowerShell on Windows 10 and Windows 2016 includes PSRea... | 64, 136, 390, 526, 25844 | powershell, security, shell, windows, windows-scripting | <h1>Is it secure to use a password argument in a Windows command?</h1>
<p>Imagine that we have a program or script that can take a password (or other sensitive information) argument: </p>
<pre><code>> program.exe /password:secret
</code></pre>
<p>For Linux, best practice generally recommends <em>against</em> speci... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,269 | bash | # Is it secure to use a password argument in a Windows command?
Imagine that we have a program or script that can take a password (or other sensitive information) argument:
```
> program.exe /password:secret
```
For Linux, best practice generally recommends *against* specifying the password directly on the command-l... | Windows historically didn't save command history between sessions, only within the session. This was true for the command prompt and for PowerShell.
As [Bill Stewart](https://stackoverflow.com/users/2102693/bill-stewart) pointed out, Windows PowerShell on Windows 10 and Windows 2016 includes PSReadline by default, whi... |
46399679 | What is the exact meaning / purpose of the J and R flags in jshell? | 10 | 2017-09-25 07:24:57 | <p>From the help information:</p>
<pre><code>-J<flag> Pass <flag> directly to the runtime system.
Use one -J for each runtime flag or flag argument
-R<flag> Pass <flag> to the remote runtime system.
Use one -R for each remote... | 920 | 868,941 | 2017-10-25 11:30:44 | 46,408,157 | 13 | 2017-09-25 14:49:52 | 5,449,250 | 2017-09-25 14:57:19 | https://stackoverflow.com/q/46399679 | https://stackoverflow.com/a/46408157 | <p>As I understand it, JShell has 3 main 'places' to execute code:</p>
<ul>
<li><p>In the current process (see <a href="https://docs.oracle.com/javase/9/docs/api/jdk/jshell/execution/DirectExecutionControl.html" rel="noreferrer">DirectExecutionControl</a>)</p></li>
<li><p>In the same JVM as the JShell client (see <a h... | <p>As I understand it, JShell has 3 main 'places' to execute code:</p> <ul> <li><p>In the current process (see <a href="https://docs.oracle.com/javase/9/docs/api/jdk/jshell/execution/DirectExecutionControl.html" rel="noreferrer">DirectExecutionControl</a>)</p></li> <li><p>In the same JVM as the JShell client (see <a h... | 4317, 109916, 116030 | java-9, jshell, runtime | <h1>What is the exact meaning / purpose of the J and R flags in jshell?</h1>
<p>From the help information:</p>
<pre><code>-J<flag> Pass <flag> directly to the runtime system.
Use one -J for each runtime flag or flag argument
-R<flag> Pass <flag> t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,270 | bash | # What is the exact meaning / purpose of the J and R flags in jshell?
From the help information:
```
-J<flag> Pass <flag> directly to the runtime system.
Use one -J for each runtime flag or flag argument
-R<flag> Pass <flag> to the remote runtime system.
... | As I understand it, JShell has 3 main 'places' to execute code:
- In the current process (see [DirectExecutionControl](https://docs.oracle.com/javase/9/docs/api/jdk/jshell/execution/DirectExecutionControl.html))
- In the same JVM as the JShell client (see [LocalExecutionControl](https://docs.oracle.com/javase/9/docs/a... |
45848637 | PowerShell Class Inheritance from separate file using Import-Module | 10 | 2017-08-23 20:20:18 | <p>What am I doing wrong here - or does PowerShell v5 not support separate class files and inheritance?</p>
<p>foo.ps1:</p>
<pre><code>class foo
{
[STRING] $test = 'Hello World';
[STRING] PrintTest()
{
return $this.test;
}
}
</code></pre>
<p>bar.ps1:</p>
<pre><code>Import-Module "$PSScriptRoot\fo... | 12,253 | 1,277,764 | 2024-02-27 16:45:37 | 45,849,435 | 13 | 2017-08-23 21:19:27 | 6,320,829 | 2017-12-04 17:41:03 | https://stackoverflow.com/q/45848637 | https://stackoverflow.com/a/45849435 | <p>Firstly, a module file should have the extension <code>.psm1</code> so you're going to want to change that. If you do not name them this way, the <code>Using</code> statement I referenced below will show an error.</p>
<p>bar.psm1 should contain a reference to the module, because <a href="https://info.sapien.com/ind... | <p>Firstly, a module file should have the extension <code>.psm1</code> so you're going to want to change that. If you do not name them this way, the <code>Using</code> statement I referenced below will show an error.</p> <p>bar.psm1 should contain a reference to the module, because <a href="https://info.sapien.com/ind... | 526, 926, 5187 | class, inheritance, powershell | <h1>PowerShell Class Inheritance from separate file using Import-Module</h1>
<p>What am I doing wrong here - or does PowerShell v5 not support separate class files and inheritance?</p>
<p>foo.ps1:</p>
<pre><code>class foo
{
[STRING] $test = 'Hello World';
[STRING] PrintTest()
{
return $this.test;
}... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,271 | bash | # PowerShell Class Inheritance from separate file using Import-Module
What am I doing wrong here - or does PowerShell v5 not support separate class files and inheritance?
foo.ps1:
```
class foo
{
[STRING] $test = 'Hello World';
[STRING] PrintTest()
{
return $this.test;
}
}
```
bar.ps1:
```
Impor... | Firstly, a module file should have the extension `.psm1` so you're going to want to change that. If you do not name them this way, the `Using` statement I referenced below will show an error.
bar.psm1 should contain a reference to the module, because [modules do not import classes](https://info.sapien.com/index.php/sc... |
45067317 | Powershell: How to Update/Replace data and values in Json and XML Object | 10 | 2017-07-12 20:52:27 | <p>So I am having a bit of a problem here, I can't seem to figure out how to update data values in an Object </p>
<p>so lets say for example the FOLLOWING json </p>
<pre><code>{
"People": 263,
"Hungry": true,
"Fruits": {
"Apples": 1 "Oranges": 2
},
"Places": {
"Places": [{
... | 30,542 | 6,860,953 | 2020-11-23 18:25:19 | 45,069,068 | 13 | 2017-07-12 23:28:55 | 3,245,749 | 2020-11-23 18:25:19 | https://stackoverflow.com/q/45067317 | https://stackoverflow.com/a/45069068 | <p>The JSON becomes a custom object with nested objects, so really it is fairly simple. To start, let's fix the JSON by adding a comma after the Apples value, and convert it to an object...</p>
<pre><code>$JSON = @'
{
"People": 263,
"Hungry": true,
"Fruits": {
"Appl... | <p>The JSON becomes a custom object with nested objects, so really it is fairly simple. To start, let's fix the JSON by adding a comma after the Apples value, and convert it to an object...</p> <pre><code>$JSON = @' { "People": 263, "Hungry": true, "Fruits": { "Appl... | 526, 1508, 6981, 10481 | json, object, powershell, updates | <h1>Powershell: How to Update/Replace data and values in Json and XML Object</h1>
<p>So I am having a bit of a problem here, I can't seem to figure out how to update data values in an Object </p>
<p>so lets say for example the FOLLOWING json </p>
<pre><code>{
"People": 263,
"Hungry": true,
"Fruits": {
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,272 | bash | # Powershell: How to Update/Replace data and values in Json and XML Object
So I am having a bit of a problem here, I can't seem to figure out how to update data values in an Object
so lets say for example the FOLLOWING json
```
{
"People": 263,
"Hungry": true,
"Fruits": {
"Apples": 1 "Oranges": 2... | The JSON becomes a custom object with nested objects, so really it is fairly simple. To start, let's fix the JSON by adding a comma after the Apples value, and convert it to an object...
```
$JSON = @'
{
"People": 263,
"Hungry": true,
"Fruits": {
"Apples": 1,
"Oranges": 2
... |
44739947 | Piping the contents of a file to ls | 10 | 2017-06-24 19:01:58 | <p>I have a file called <strong>"input.txt."</strong> that contains one line:</p>
<pre><code>/bin
</code></pre>
<p>I would like to make the contents of the file be the input of the command <code>ls</code></p>
<p>I tried doing </p>
<pre><code>cat input.txt | ls
</code></pre>
<p>but it doesn't output the list of fil... | 12,528 | 5,765,194 | 2020-09-27 14:47:32 | 44,739,979 | 13 | 2017-06-24 19:05:18 | 797,049 | 2020-09-27 14:47:32 | https://stackoverflow.com/q/44739947 | https://stackoverflow.com/a/44739979 | <p>You are looking for the <code>xargs</code> (<em>transpose arguments</em>) command.</p>
<pre><code>xargs ls < input.txt
</code></pre>
<p>You say you want <code>/bin</code> to be the "input" to <code>ls</code>, but that's not correct; <code>ls</code> doesn't do anything with its input. Instead, you want <... | <p>You are looking for the <code>xargs</code> (<em>transpose arguments</em>) command.</p> <pre><code>xargs ls < input.txt </code></pre> <p>You say you want <code>/bin</code> to be the "input" to <code>ls</code>, but that's not correct; <code>ls</code> doesn't do anything with its input. Instead, you want <... | 387 | bash | <h1>Piping the contents of a file to ls</h1>
<p>I have a file called <strong>"input.txt."</strong> that contains one line:</p>
<pre><code>/bin
</code></pre>
<p>I would like to make the contents of the file be the input of the command <code>ls</code></p>
<p>I tried doing </p>
<pre><code>cat input.txt | ls
</code></p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,273 | bash | # Piping the contents of a file to ls
I have a file called **"input.txt."** that contains one line:
```
/bin
```
I would like to make the contents of the file be the input of the command `ls`
I tried doing
```
cat input.txt | ls
```
but it doesn't output the list of files in the **/bin** directory
I also tried
... | You are looking for the `xargs` (*transpose arguments*) command.
```
xargs ls < input.txt
```
You say you want `/bin` to be the "input" to `ls`, but that's not correct; `ls` doesn't do anything with its input. Instead, you want `/bin` to be passed as a command-line *argument* to `ls`, as if you had typed `ls /bin`.
... |
42101389 | Running Docker on Mac, build works, run errors: : /bin/sh: 1: [: missing ] | 10 | 2017-02-07 22:41:49 | <p>Running Docker on Mac, I can build my image, but on running, I get the following error: </p>
<pre><code>/bin/sh: 1: [: missing ]
</code></pre>
<p>I create the image in a local directory with
a dockerfile, requirements.txt and a python script file. - 3 files-
using docker build </p>
<p>Dockerfile: </p>
<pre><co... | 12,120 | 7,496,896 | 2018-09-25 10:11:23 | 42,101,705 | 13 | 2017-02-07 23:07:06 | 14,122 | 2018-04-30 12:35:51 | https://stackoverflow.com/q/42101389 | https://stackoverflow.com/a/42101705 | <pre><code>CMD [ "python", "./quandlData.py"
</code></pre>
<p>is being parsed as a shell command, not an array -- and the <code>[</code> command (when invoked that way, rather than by its alternate name <code>test</code>) requires its last argument to be <code>]</code>.</p>
<p>In this case, however, adding a trailing... | <pre><code>CMD [ "python", "./quandlData.py" </code></pre> <p>is being parsed as a shell command, not an array -- and the <code>[</code> command (when invoked that way, rather than by its alternate name <code>test</code>) requires its last argument to be <code>]</code>.</p> <p>In this case, however, adding a trailing... | 369, 387, 90304 | bash, docker, macos | <h1>Running Docker on Mac, build works, run errors: : /bin/sh: 1: [: missing ]</h1>
<p>Running Docker on Mac, I can build my image, but on running, I get the following error: </p>
<pre><code>/bin/sh: 1: [: missing ]
</code></pre>
<p>I create the image in a local directory with
a dockerfile, requirements.txt and a py... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,274 | bash | # Running Docker on Mac, build works, run errors: : /bin/sh: 1: [: missing ]
Running Docker on Mac, I can build my image, but on running, I get the following error:
```
/bin/sh: 1: [: missing ]
```
I create the image in a local directory with
a dockerfile, requirements.txt and a python script file. - 3 files-
using ... | ```
CMD [ "python", "./quandlData.py"
```
is being parsed as a shell command, not an array -- and the `[` command (when invoked that way, rather than by its alternate name `test`) requires its last argument to be `]`.
In this case, however, adding a trailing `]` will cause your `CMD` to parse as an array describing a... |
42032201 | awk replace all occurrences of a string globally | 10 | 2017-02-03 20:05:06 | <p>I have a bash script that substitutes strings in another file:</p>
<pre><code>...
# make MC input script
sig=2.6
awk -v sig="$sig" '{
sub(/XSIGX/, sig);
print;
}' input.txt > output.txt
</code></pre>
<p>When I run this on <code>input.txt</code> I get the following as <code>output.txt</code> (... | 10,040 | 1,493,707 | 2017-10-02 12:19:58 | 42,032,328 | 13 | 2017-02-03 20:14:08 | 3,988,526 | 2017-02-03 20:14:08 | https://stackoverflow.com/q/42032201 | https://stackoverflow.com/a/42032328 | <p>In AWK function <code>sub</code> replaces one/first instance. If you replace <code>sub</code> with <code>gsub</code> should replace all instances. Hence this should work ok:</p>
<pre><code>sig=2.6
awk -v sig="$sig" '{
gsub(/XSIGX/, sig);
print;
}' input.txt > output.txt
</code></pre>
| <p>In AWK function <code>sub</code> replaces one/first instance. If you replace <code>sub</code> with <code>gsub</code> should replace all instances. Hence this should work ok:</p> <pre><code>sig=2.6 awk -v sig="$sig" '{ gsub(/XSIGX/, sig); print; }' input.txt > output.txt </code></pre> | 139, 387, 990, 2498 | awk, bash, replace, string | <h1>awk replace all occurrences of a string globally</h1>
<p>I have a bash script that substitutes strings in another file:</p>
<pre><code>...
# make MC input script
sig=2.6
awk -v sig="$sig" '{
sub(/XSIGX/, sig);
print;
}' input.txt > output.txt
</code></pre>
<p>When I run this on <code>input.t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,275 | bash | # awk replace all occurrences of a string globally
I have a bash script that substitutes strings in another file:
```
...
# make MC input script
sig=2.6
awk -v sig="$sig" '{
sub(/XSIGX/, sig);
print;
}' input.txt > output.txt
```
When I run this on `input.txt` I get the following as `output.txt` (... | In AWK function `sub` replaces one/first instance. If you replace `sub` with `gsub` should replace all instances. Hence this should work ok:
```
sig=2.6
awk -v sig="$sig" '{
gsub(/XSIGX/, sig);
print;
}' input.txt > output.txt
``` |
41349109 | Why does ((count++)) return 1 exit code first time run | 10 | 2016-12-27 16:57:52 | <p>I have no idea why the indicated line below is returning 1 while the subsequent executions of <code>((count++))</code> are returning 0. </p>
<pre><code>[me@server ~]$ count=0
[me@server ~]$ echo $?
0
[me@server ~]$ count++
-bash: count++: command not found
[me@server ~]$ (count++)
-bash: count++: command not found
... | 690 | null | 2023-06-21 09:37:30 | 41,349,216 | 13 | 2016-12-27 17:05:24 | 5,291,015 | 2023-06-21 09:37:30 | https://stackoverflow.com/q/41349109 | https://stackoverflow.com/a/41349216 | <p>See the excerpt from the <code>help let</code> page,</p>
<blockquote>
<p>If the last ARG evaluates to 0, let returns 1; 0 is returned
otherwise.</p>
</blockquote>
<p>Since the operation is post-increment, <code>((count++))</code>, for the very first time <code>0</code> is retained, hence returning <code>1</code></p>... | <p>See the excerpt from the <code>help let</code> page,</p> <blockquote> <p>If the last ARG evaluates to 0, let returns 1; 0 is returned otherwise.</p> </blockquote> <p>Since the operation is post-increment, <code>((count++))</code>, for the very first time <code>0</code> is retained, hence returning <code>1</code></p>... | 387 | bash | <h1>Why does ((count++)) return 1 exit code first time run</h1>
<p>I have no idea why the indicated line below is returning 1 while the subsequent executions of <code>((count++))</code> are returning 0. </p>
<pre><code>[me@server ~]$ count=0
[me@server ~]$ echo $?
0
[me@server ~]$ count++
-bash: count++: command not f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,276 | bash | # Why does ((count++)) return 1 exit code first time run
I have no idea why the indicated line below is returning 1 while the subsequent executions of `((count++))` are returning 0.
```
[me@server ~]$ count=0
[me@server ~]$ echo $?
0
[me@server ~]$ count++
-bash: count++: command not found
[me@server ~]$ (count++)
-b... | See the excerpt from the `help let` page,
> If the last ARG evaluates to 0, let returns 1; 0 is returned
> otherwise.
Since the operation is post-increment, `((count++))`, for the very first time `0` is retained, hence returning `1`
Notice, the same does not happen for pre-increment `((++count))`, since the value is... |
39983121 | How to detect if system has IPv6 enabled in a UNIX shell script? | 10 | 2016-10-11 17:27:09 | <p>I have a shell script, that is being executed on various POSIX environments such as Linux, Mac OSX or even Cygwin. The script needs to reliably detect if given system has IPv6 enabled. E.g. I can use at least IPv6 local loopback (::1).
So the question is:
How to detect if system has ipv6 enabled in a UNIX shell in a... | 18,843 | 1,640,284 | 2016-10-12 16:22:09 | 39,983,364 | 13 | 2016-10-11 17:41:48 | 6,864,688 | 2016-10-11 18:25:26 | https://stackoverflow.com/q/39983121 | https://stackoverflow.com/a/39983364 | <p>This can be tested by checking the existance of <code>/proc/net/if_inet6</code> as follows:</p>
<pre><code>test -f /proc/net/if_inet6 && echo "IPv6 supported" || echo "IPv6 not supported"
</code></pre>
<p>I've tested it on Ubuntu, Mint, Raspberry PI and Bash shell in Windows, and it works in all these envi... | <p>This can be tested by checking the existance of <code>/proc/net/if_inet6</code> as follows:</p> <pre><code>test -f /proc/net/if_inet6 && echo "IPv6 supported" || echo "IPv6 not supported" </code></pre> <p>I've tested it on Ubuntu, Mint, Raspberry PI and Bash shell in Windows, and it works in all these envi... | 34, 58, 369, 390, 10485 | ipv6, linux, macos, shell, unix | <h1>How to detect if system has IPv6 enabled in a UNIX shell script?</h1>
<p>I have a shell script, that is being executed on various POSIX environments such as Linux, Mac OSX or even Cygwin. The script needs to reliably detect if given system has IPv6 enabled. E.g. I can use at least IPv6 local loopback (::1).
So the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,277 | bash | # How to detect if system has IPv6 enabled in a UNIX shell script?
I have a shell script, that is being executed on various POSIX environments such as Linux, Mac OSX or even Cygwin. The script needs to reliably detect if given system has IPv6 enabled. E.g. I can use at least IPv6 local loopback (::1).
So the question ... | This can be tested by checking the existance of `/proc/net/if_inet6` as follows:
```
test -f /proc/net/if_inet6 && echo "IPv6 supported" || echo "IPv6 not supported"
```
I've tested it on Ubuntu, Mint, Raspberry PI and Bash shell in Windows, and it works in all these environments. |
37497914 | Node http-server not working on Windows 10 Ubuntu Bash | 10 | 2016-05-28 10:30:57 | <p>I just tried to install NodeJS <code>http-server</code> on Windows 10 Ubuntu Bash, installation worked fine but running it to serve a static site <code>$http-server src</code> throws this error:</p>
<pre><code>$ http-server src
/usr/lib/node_modules/http-server/bin/http-server:14
var ifaces = os.networkInterfaces(... | 5,522 | 785,349 | 2017-04-22 10:39:23 | 38,774,518 | 13 | 2016-08-04 18:10:40 | 690,188 | 2017-04-22 10:39:23 | https://stackoverflow.com/q/37497914 | https://stackoverflow.com/a/38774518 | <p><strong>Update:</strong> This issue has been fixed since the Windows 10 Creators Update (April 2017).</p>
<p>This is currently a known issue[<a href="https://github.com/Microsoft/BashOnWindows/issues/118" rel="nofollow noreferrer">1</a>][<a href="https://github.com/Microsoft/BashOnWindows/issues/744" rel="nofollow ... | <p><strong>Update:</strong> This issue has been fixed since the Windows 10 Creators Update (April 2017).</p> <p>This is currently a known issue[<a href="https://github.com/Microsoft/BashOnWindows/issues/118" rel="nofollow noreferrer">1</a>][<a href="https://github.com/Microsoft/BashOnWindows/issues/744" rel="nofollow ... | 64, 387, 549, 46426, 119526 | bash, node.js, ubuntu, windows, windows-subsystem-for-linux | <h1>Node http-server not working on Windows 10 Ubuntu Bash</h1>
<p>I just tried to install NodeJS <code>http-server</code> on Windows 10 Ubuntu Bash, installation worked fine but running it to serve a static site <code>$http-server src</code> throws this error:</p>
<pre><code>$ http-server src
/usr/lib/node_modules/h... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,278 | bash | # Node http-server not working on Windows 10 Ubuntu Bash
I just tried to install NodeJS `http-server` on Windows 10 Ubuntu Bash, installation worked fine but running it to serve a static site `$http-server src` throws this error:
```
$ http-server src
/usr/lib/node_modules/http-server/bin/http-server:14
var ifaces =... | **Update:** This issue has been fixed since the Windows 10 Creators Update (April 2017).
This is currently a known issue[[1](https://github.com/Microsoft/BashOnWindows/issues/118)][[2](https://github.com/Microsoft/BashOnWindows/issues/744)][[3](https://github.com/Microsoft/BashOnWindows/issues/468)][[4](https://github... |
38304271 | Bash extract user for a particular host from ssh config file | 10 | 2016-07-11 10:08:49 | <p>I'm writing a bash script where I need to obtain a particular user from an ssh config file. The ssh config file looks a little something like this: </p>
<pre><code>HOST blag
HostName blag.net.au
Port 2683
User blaguser
Host bloo
User ABCDEF
IdentityFile ~/.ssh/id_rsa
HOST biff
HostName biff.net.... | 5,427 | 3,003,045 | 2020-04-07 22:08:47 | 38,305,248 | 13 | 2016-07-11 11:00:40 | 2,196,426 | 2019-11-08 08:58:30 | https://stackoverflow.com/q/38304271 | https://stackoverflow.com/a/38305248 | <p>You can use <code>ssh</code> configuration test mode to parse the configuration file and return you the expected value:</p>
<pre><code>ssh -G hostname | grep "^user "
</code></pre>
<p>This should work since <code>openssh-6.8</code>.</p>
| <p>You can use <code>ssh</code> configuration test mode to parse the configuration file and return you the expected value:</p> <pre><code>ssh -G hostname | grep "^user " </code></pre> <p>This should work since <code>openssh-6.8</code>.</p> | 386, 387, 5282 | bash, sed, ssh | <h1>Bash extract user for a particular host from ssh config file</h1>
<p>I'm writing a bash script where I need to obtain a particular user from an ssh config file. The ssh config file looks a little something like this: </p>
<pre><code>HOST blag
HostName blag.net.au
Port 2683
User blaguser
Host bloo
Use... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,279 | bash | # Bash extract user for a particular host from ssh config file
I'm writing a bash script where I need to obtain a particular user from an ssh config file. The ssh config file looks a little something like this:
```
HOST blag
HostName blag.net.au
Port 2683
User blaguser
Host bloo
User ABCDEF
IdentityFi... | You can use `ssh` configuration test mode to parse the configuration file and return you the expected value:
```
ssh -G hostname | grep "^user "
```
This should work since `openssh-6.8`. |
35063332 | Insert single quote with sed | 10 | 2016-01-28 13:50:43 | <p>I want to add some text on a line:</p>
<pre><code>sudo sed -i '5imytext 16/16' /file
</code></pre>
<p>Now I've added <code>mytext 16/16</code> on line 5 of the file, but I actually want to add the text <code>'mytext' 16/16</code> (<code>mytext</code> between single quotes).</p>
<p>I tried</p>
<pre><code>sudo sed... | 21,022 | 4,525,448 | 2022-11-20 19:22:23 | 35,063,427 | 13 | 2016-01-28 13:53:58 | 2,088,135 | 2016-01-28 14:31:58 | https://stackoverflow.com/q/35063332 | https://stackoverflow.com/a/35063427 | <p>The single quotes that you're trying to use in your insertion string are interfering with the ones around the sed command.</p>
<p>The simplest thing to do is to use different quotes around your sed command:</p>
<pre><code>"5i'mytext' 16/16"
</code></pre>
<p>Normally it's best to use single quotes around a sed com... | <p>The single quotes that you're trying to use in your insertion string are interfering with the ones around the sed command.</p> <p>The simplest thing to do is to use different quotes around your sed command:</p> <pre><code>"5i'mytext' 16/16" </code></pre> <p>Normally it's best to use single quotes around a sed com... | 387, 390, 5282 | bash, sed, shell | <h1>Insert single quote with sed</h1>
<p>I want to add some text on a line:</p>
<pre><code>sudo sed -i '5imytext 16/16' /file
</code></pre>
<p>Now I've added <code>mytext 16/16</code> on line 5 of the file, but I actually want to add the text <code>'mytext' 16/16</code> (<code>mytext</code> between single quotes).</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,280 | bash | # Insert single quote with sed
I want to add some text on a line:
```
sudo sed -i '5imytext 16/16' /file
```
Now I've added `mytext 16/16` on line 5 of the file, but I actually want to add the text `'mytext' 16/16` (`mytext` between single quotes).
I tried
```
sudo sed -i '5i'mytext' 16/16' /file
```
but it didn'... | The single quotes that you're trying to use in your insertion string are interfering with the ones around the sed command.
The simplest thing to do is to use different quotes around your sed command:
```
"5i'mytext' 16/16"
```
Normally it's best to use single quotes around a sed command but it would be more tricky i... |
34906389 | Is there a way to prevent git from opening a password prompt box on Windows? | 10 | 2016-01-20 17:17:33 | <p>While pushing on a remote repository using git bash, my password is required and asked. This is not a problem.</p>
<p>The issue is that I was used to just type my password into the git console, but then I switched from Linux to Windows and my password is asked into a prompt box instead of the console.</p>
<p><a hr... | 12,125 | 2,291,710 | 2022-04-02 21:37:42 | 34,907,883 | 13 | 2016-01-20 18:37:53 | 2,291,710 | 2016-01-20 18:45:00 | https://stackoverflow.com/q/34906389 | https://stackoverflow.com/a/34907883 | <p>This seems to be related with the <code>core.askPass</code> option of <a href="https://git-scm.com/docs/git-config" rel="noreferrer">git-config</a>.</p>
<p>The documentation says:</p>
<blockquote>
<p><strong>core.askPass</strong><br>
Some commands (e.g. svn and http interfaces) that interactively ask
for a p... | <p>This seems to be related with the <code>core.askPass</code> option of <a href="https://git-scm.com/docs/git-config" rel="noreferrer">git-config</a>.</p> <p>The documentation says:</p> <blockquote> <p><strong>core.askPass</strong><br> Some commands (e.g. svn and http interfaces) that interactively ask for a p... | 64, 119, 9938, 61874, 63671 | command-prompt, git, git-bash, password-prompt, windows | <h1>Is there a way to prevent git from opening a password prompt box on Windows?</h1>
<p>While pushing on a remote repository using git bash, my password is required and asked. This is not a problem.</p>
<p>The issue is that I was used to just type my password into the git console, but then I switched from Linux to Wi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,281 | bash | # Is there a way to prevent git from opening a password prompt box on Windows?
While pushing on a remote repository using git bash, my password is required and asked. This is not a problem.
The issue is that I was used to just type my password into the git console, but then I switched from Linux to Windows and my pas... | This seems to be related with the `core.askPass` option of [git-config](https://git-scm.com/docs/git-config).
The documentation says:
> **core.askPass**
> Some commands (e.g. svn and http interfaces) that interactively ask
> for a password can be told to use an external program given via the
> value of this variabl... |
33265705 | Access mongo shell running in docker container in linux script | 10 | 2015-10-21 17:32:38 | <p>I want to create a bash script that removes a user from a mongodb database that is running inside a docker container.</p>
<p>Normally through the terminal I would execute <code>docker exec -it mycontainername bash</code> </p>
<p>and then once I'm in the container I execute <code>mongo mydbname --eval "db.users.rem... | 7,205 | 5,100,278 | 2015-10-21 17:43:43 | 33,265,902 | 13 | 2015-10-21 17:43:43 | 5,100,278 | 2015-10-21 17:43:43 | https://stackoverflow.com/q/33265705 | https://stackoverflow.com/a/33265902 | <p>Found out you can replace <code>bash</code> with the name of the shell you want to open, so in this case <code>mongo</code>.</p>
| <p>Found out you can replace <code>bash</code> with the name of the shell you want to open, so in this case <code>mongo</code>.</p> | 58, 387, 390, 30073, 90304 | bash, docker, linux, mongodb, shell | <h1>Access mongo shell running in docker container in linux script</h1>
<p>I want to create a bash script that removes a user from a mongodb database that is running inside a docker container.</p>
<p>Normally through the terminal I would execute <code>docker exec -it mycontainername bash</code> </p>
<p>and then once ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,282 | bash | # Access mongo shell running in docker container in linux script
I want to create a bash script that removes a user from a mongodb database that is running inside a docker container.
Normally through the terminal I would execute `docker exec -it mycontainername bash`
and then once I'm in the container I execute `mon... | Found out you can replace `bash` with the name of the shell you want to open, so in this case `mongo`. |
31749844 | Stopping & Restarting Services Remotely Using Set-Service | 10 | 2015-07-31 15:26:40 | <p>I've got a list of 10-15 services that I routinely need to restart on 6 servers. I have a script that calls a list of services, then calls a list of the servers, and then stops all the services:</p>
<pre><code>$Services = Get-Content -Path "C:\Powershell\Services.txt"
$Machines = Get-Content -Path "C:\Powershell\Ma... | 61,757 | 5,098,880 | 2019-06-13 11:51:13 | 31,750,476 | 13 | 2015-07-31 16:00:39 | 1,630,171 | 2019-06-13 11:51:13 | https://stackoverflow.com/q/31749844 | https://stackoverflow.com/a/31750476 | <p>To restart services simply use <a href="https://technet.microsoft.com/en-us/library/hh849823.aspx" rel="noreferrer"><code>Restart-Service</code></a>:</p>
<pre><code>$Services = Get-Content -Path "C:\Powershell\Services.txt"
$Machines = Get-Content -Path "C:\Powershell\Machines.txt"
Get-Service -Name $Services -Comp... | <p>To restart services simply use <a href="https://technet.microsoft.com/en-us/library/hh849823.aspx" rel="noreferrer"><code>Restart-Service</code></a>:</p> <pre><code>$Services = Get-Content -Path "C:\Powershell\Services.txt" $Machines = Get-Content -Path "C:\Powershell\Machines.txt" Get-Service -Name $Services -Comp... | 526, 627 | powershell, service | <h1>Stopping & Restarting Services Remotely Using Set-Service</h1>
<p>I've got a list of 10-15 services that I routinely need to restart on 6 servers. I have a script that calls a list of services, then calls a list of the servers, and then stops all the services:</p>
<pre><code>$Services = Get-Content -Path "C:\Power... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,283 | bash | # Stopping & Restarting Services Remotely Using Set-Service
I've got a list of 10-15 services that I routinely need to restart on 6 servers. I have a script that calls a list of services, then calls a list of the servers, and then stops all the services:
```
$Services = Get-Content -Path "C:\Powershell\Services.txt"
... | To restart services simply use [`Restart-Service`](https://technet.microsoft.com/en-us/library/hh849823.aspx):
```
$Services = Get-Content -Path "C:\Powershell\Services.txt"
$Machines = Get-Content -Path "C:\Powershell\Machines.txt"
Get-Service -Name $Services -ComputerName $Machines | Restart-Service
```
Since accor... |
30790533 | start-process with a special name, or handle to kill it | 10 | 2015-06-11 20:12:23 | <p>We have a number of node.js programes that all are created with powershell. We used the start-process to spawn the node.js executable in the background (node.exe).</p>
<p>We would like to give each one a different "handle" so that we can later use the powershell command stop-process to kill them. e.g. start-process... | 15,081 | 959,460 | 2015-06-11 21:51:13 | 30,790,640 | 13 | 2015-06-11 20:19:00 | 821,878 | 2015-06-11 21:29:49 | https://stackoverflow.com/q/30790533 | https://stackoverflow.com/a/30790640 | <p>One method is to use the <code>-PassThru</code> parameter, which causes <code>Start-Process</code> to return an object which can be used to control the process. When you're done with the process, pipe the object to <code>Stop-Process</code> (or call the object's <code>Kill()</code> method)</p>
<p>In cases where you... | <p>One method is to use the <code>-PassThru</code> parameter, which causes <code>Start-Process</code> to return an object which can be used to control the process. When you're done with the process, pipe the object to <code>Stop-Process</code> (or call the object's <code>Kill()</code> method)</p> <p>In cases where you... | 526, 73157 | powershell, powershell-3.0 | <h1>start-process with a special name, or handle to kill it</h1>
<p>We have a number of node.js programes that all are created with powershell. We used the start-process to spawn the node.js executable in the background (node.exe).</p>
<p>We would like to give each one a different "handle" so that we can later use the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,284 | bash | # start-process with a special name, or handle to kill it
We have a number of node.js programes that all are created with powershell. We used the start-process to spawn the node.js executable in the background (node.exe).
We would like to give each one a different "handle" so that we can later use the powershell comm... | One method is to use the `-PassThru` parameter, which causes `Start-Process` to return an object which can be used to control the process. When you're done with the process, pipe the object to `Stop-Process` (or call the object's `Kill()` method)
In cases where you need to store the object across PS sessions, you can ... |
29644410 | Powershell - how do I edit an existing property in a custom object | 10 | 2015-04-15 07:45:07 | <p>I looking for way how update noteproperty in existing psobject, for example I have system.array of psobjects ($a): </p>
<pre><code>Group Assigment
----- ---------
Group1 Home
Group2 Office
</cod... | 70,245 | 2,425,242 | 2021-01-27 22:03:19 | 29,644,865 | 13 | 2015-04-15 08:08:01 | 381,149 | 2015-04-15 08:08:01 | https://stackoverflow.com/q/29644410 | https://stackoverflow.com/a/29644865 | <p>It's not really clear what is your problem : select the good object or update it's value ?</p>
<pre><code>$col=@()
$props=@{"group"="group1";"assignment"="home"}
$col += new-object pscustomobject -property $props
$props2=@{"group"="group2";"assignment"="office"}
$col += new-object pscustomobject -property $props2
... | <p>It's not really clear what is your problem : select the good object or update it's value ?</p> <pre><code>$col=@() $props=@{"group"="group1";"assignment"="home"} $col += new-object pscustomobject -property $props $props2=@{"group"="group2";"assignment"="office"} $col += new-object pscustomobject -property $props2 ... | 526, 5826, 77232 | edit, powershell, psobject | <h1>Powershell - how do I edit an existing property in a custom object</h1>
<p>I looking for way how update noteproperty in existing psobject, for example I have system.array of psobjects ($a): </p>
<pre><code>Group Assigment
----- ---------
Group1 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,285 | bash | # Powershell - how do I edit an existing property in a custom object
I looking for way how update noteproperty in existing psobject, for example I have system.array of psobjects ($a):
```
Group Assigment
----- ---------
Group1 ... | It's not really clear what is your problem : select the good object or update it's value ?
```
$col=@()
$props=@{"group"="group1";"assignment"="home"}
$col += new-object pscustomobject -property $props
$props2=@{"group"="group2";"assignment"="office"}
$col += new-object pscustomobject -property $props2
#select objec... |
29183957 | Unix Bash - Assign if/else to Variable | 10 | 2015-03-21 14:41:29 | <p>I have been creating to assign the output of if/else to a variable but keep on getting an error. </p>
<p><em>For Example:</em></p>
<pre><code>mathstester=$(If [ 2 = 2 ]
Then echo equal
Else
echo "not equal"
fi)
</code></pre>
<p>So whenever I add <code>$mathstester</code> in a script, laid out like this:</p>
<pr... | 40,930 | 4,369,393 | 2017-10-19 10:42:35 | 29,187,701 | 13 | 2015-03-21 20:30:31 | 89,817 | 2015-03-21 20:30:31 | https://stackoverflow.com/q/29183957 | https://stackoverflow.com/a/29187701 | <p>Putting the <code>if</code> statement in the assignment is rather clumsy and easy to get wrong. The more standard way to do this is to put the assignment inside the <code>if</code>:</p>
<pre><code>if [ 2 = 2 ]; then
mathstester="equal"
else
mathstester="not equal"
fi
</code></pre>
<p>As for testing variabl... | <p>Putting the <code>if</code> statement in the assignment is rather clumsy and easy to get wrong. The more standard way to do this is to put the assignment inside the <code>if</code>:</p> <pre><code>if [ 2 = 2 ]; then mathstester="equal" else mathstester="not equal" fi </code></pre> <p>As for testing variabl... | 34, 387 | bash, unix | <h1>Unix Bash - Assign if/else to Variable</h1>
<p>I have been creating to assign the output of if/else to a variable but keep on getting an error. </p>
<p><em>For Example:</em></p>
<pre><code>mathstester=$(If [ 2 = 2 ]
Then echo equal
Else
echo "not equal"
fi)
</code></pre>
<p>So whenever I add <code>$mathstester<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,286 | bash | # Unix Bash - Assign if/else to Variable
I have been creating to assign the output of if/else to a variable but keep on getting an error.
*For Example:*
```
mathstester=$(If [ 2 = 2 ]
Then echo equal
Else
echo "not equal"
fi)
```
So whenever I add `$mathstester` in a script, laid out like this:
```
echo "Equation... | Putting the `if` statement in the assignment is rather clumsy and easy to get wrong. The more standard way to do this is to put the assignment inside the `if`:
```
if [ 2 = 2 ]; then
mathstester="equal"
else
mathstester="not equal"
fi
```
As for testing variables, you can use something like `if [ "$b" = 2 ]` ... |
28582135 | Return variable from node.js to sh script | 10 | 2015-02-18 11:11:04 | <p>Is it possible to execute node.js app from .sh script, return some variable and continue the .sh script?
Something like:</p>
<pre><code>#!/bin/sh
SOME_VARIABLE = node app.js
echo ${SOME_VARIABLE}
</code></pre>
| 8,973 | 2,976,581 | 2018-05-02 11:03:32 | 28,582,291 | 13 | 2015-02-18 11:18:17 | 4,272,464 | 2018-05-02 11:03:32 | https://stackoverflow.com/q/28582135 | https://stackoverflow.com/a/28582291 | <p>Firstly, ensure you're using <code>bash</code>, not <code>sh</code>, as there are significant differences in functionality between the two.</p>
<p>One simple solution is command substitution, although be aware that trailing newlines in the command output will be stripped. Also, when echoing, to protect the contents... | <p>Firstly, ensure you're using <code>bash</code>, not <code>sh</code>, as there are significant differences in functionality between the two.</p> <p>One simple solution is command substitution, although be aware that trailing newlines in the command output will be stripped. Also, when echoing, to protect the contents... | 387, 10327, 46426 | bash, node.js, sh | <h1>Return variable from node.js to sh script</h1>
<p>Is it possible to execute node.js app from .sh script, return some variable and continue the .sh script?
Something like:</p>
<pre><code>#!/bin/sh
SOME_VARIABLE = node app.js
echo ${SOME_VARIABLE}
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,287 | bash | # Return variable from node.js to sh script
Is it possible to execute node.js app from .sh script, return some variable and continue the .sh script?
Something like:
```
#!/bin/sh
SOME_VARIABLE = node app.js
echo ${SOME_VARIABLE}
``` | Firstly, ensure you're using `bash`, not `sh`, as there are significant differences in functionality between the two.
One simple solution is command substitution, although be aware that trailing newlines in the command output will be stripped. Also, when echoing, to protect the contents of the variable (such as spaces... |
25483778 | Command to create ssh config file using git bash(windows)? | 10 | 2014-08-25 10:23:24 | <p>I could only find details about configuring the config file, but i could no where find how to create a config file manually. I have generated rsa key, which is under .ssh folder but i couldn't find the config file being created there.</p>
| 19,336 | 3,488,935 | 2014-08-25 10:59:02 | 25,484,408 | 13 | 2014-08-25 10:59:02 | 1,170,333 | 2014-08-25 10:59:02 | https://stackoverflow.com/q/25483778 | https://stackoverflow.com/a/25484408 | <p>You can simply create it by yourself:</p>
<pre><code>touch ~/.ssh/config
</code></pre>
<p>or go to <code>.ssh</code> directory and do only:</p>
<pre><code>touch config
</code></pre>
<p>And then fill it with data.</p>
| <p>You can simply create it by yourself:</p> <pre><code>touch ~/.ssh/config </code></pre> <p>or go to <code>.ssh</code> directory and do only:</p> <pre><code>touch config </code></pre> <p>And then fill it with data.</p> | 119, 386, 25308, 61874 | git, git-bash, ssh, ssh-keys | <h1>Command to create ssh config file using git bash(windows)?</h1>
<p>I could only find details about configuring the config file, but i could no where find how to create a config file manually. I have generated rsa key, which is under .ssh folder but i couldn't find the config file being created there.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,288 | bash | # Command to create ssh config file using git bash(windows)?
I could only find details about configuring the config file, but i could no where find how to create a config file manually. I have generated rsa key, which is under .ssh folder but i couldn't find the config file being created there. | You can simply create it by yourself:
```
touch ~/.ssh/config
```
or go to `.ssh` directory and do only:
```
touch config
```
And then fill it with data. |
24398691 | How to get the real line number of a failing Bash command? | 10 | 2014-06-25 01:08:42 | <p>In the process of coming up with a way to catch errors in my Bash scripts, I've been experimenting with "set -e", "set -E", and the "trap" command. In the process, I've discovered some strange behavior in how <code>$LINENO</code> is evaluated in the context of functions. First, here's a stripped down version of how ... | 10,317 | 2,141,391 | 2025-01-17 12:18:21 | 24,399,288 | 13 | 2014-06-25 02:31:30 | 14,122 | 2014-06-25 03:06:18 | https://stackoverflow.com/q/24398691 | https://stackoverflow.com/a/24399288 | <p>For bash releases prior to 4.1, a special level of awful, hacky, performance-killing hell is needed to work around an issue wherein, on errors, the system jumps back to the function definition point before invoking an error handler.</p>
<pre><code>#!/bin/bash
set -E
set -o functrace
function handle_error {
l... | <p>For bash releases prior to 4.1, a special level of awful, hacky, performance-killing hell is needed to work around an issue wherein, on errors, the system jumps back to the function definition point before invoking an error handler.</p> <pre><code>#!/bin/bash set -E set -o functrace function handle_error { l... | 387 | bash | <h1>How to get the real line number of a failing Bash command?</h1>
<p>In the process of coming up with a way to catch errors in my Bash scripts, I've been experimenting with "set -e", "set -E", and the "trap" command. In the process, I've discovered some strange behavior in how <code>$LINENO</code> is evaluated in the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,289 | bash | # How to get the real line number of a failing Bash command?
In the process of coming up with a way to catch errors in my Bash scripts, I've been experimenting with "set -e", "set -E", and the "trap" command. In the process, I've discovered some strange behavior in how `$LINENO` is evaluated in the context of function... | For bash releases prior to 4.1, a special level of awful, hacky, performance-killing hell is needed to work around an issue wherein, on errors, the system jumps back to the function definition point before invoking an error handler.
```
#!/bin/bash
set -E
set -o functrace
function handle_error {
local retval=$?
... |
23300567 | 'If' statements and one line Python scripts from the command line | 10 | 2014-04-25 18:35:44 | <p>Why do I receive a syntax error for the following one-liner Python code?</p>
<pre class="lang-none prettyprint-override"><code>python -c 'import re; if True: print "HELLO";'
File "<string>", line 1
import re; if True: print "HELLO";
^
SyntaxError: invalid syn... | 14,298 | 1,762,181 | 2022-04-27 10:19:06 | 23,301,247 | 13 | 2014-04-25 19:16:56 | 291,709 | 2022-04-27 09:46:44 | https://stackoverflow.com/q/23300567 | https://stackoverflow.com/a/23301247 | <p>One option to work around this limitation is to specify the command with the <code>$'string'</code> format using the newline escape sequence <code>\n</code>.</p>
<pre><code>python -c $'import re\nif True: print "HELLO";'
</code></pre>
<p>Note: this is supported by shells, such as <a href="https://en.wikipe... | <p>One option to work around this limitation is to specify the command with the <code>$'string'</code> format using the newline escape sequence <code>\n</code>.</p> <pre><code>python -c $'import re\nif True: print "HELLO";' </code></pre> <p>Note: this is supported by shells, such as <a href="https://en.wikipe... | 16, 387, 390, 1231 | bash, command-line, python, shell | <h1>'If' statements and one line Python scripts from the command line</h1>
<p>Why do I receive a syntax error for the following one-liner Python code?</p>
<pre class="lang-none prettyprint-override"><code>python -c 'import re; if True: print "HELLO";'
File "<string>", line 1
import re; i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,290 | bash | # 'If' statements and one line Python scripts from the command line
Why do I receive a syntax error for the following one-liner Python code?
```
python -c 'import re; if True: print "HELLO";'
File "<string>", line 1
import re; if True: print "HELLO";
^
SyntaxError: invalid syntax
```
The follow... | One option to work around this limitation is to specify the command with the `$'string'` format using the newline escape sequence `\n`.
```
python -c $'import re\nif True: print "HELLO";'
```
Note: this is supported by shells, such as [Bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) and [Z shell](https://e... |
23116034 | Run Python module with absolute path | 10 | 2014-04-16 17:16:54 | <p>For this file layout:</p>
<pre><code>devel/
pkg/
__init__.py
moduleA.py
moduleB.py
test/
__init__.py
test_A.py
test_B.py
</code></pre>
<p>If I am in the directory which contains the pkg (devel), I can run:</p>
<pre><code>python -m pkg.test.t... | 9,194 | 1,447,885 | 2014-04-16 17:24:31 | 23,116,162 | 13 | 2014-04-16 17:24:31 | 1,126,841 | 2014-04-16 17:24:31 | https://stackoverflow.com/q/23116034 | https://stackoverflow.com/a/23116162 | <p>Add <code>/Users/me/docs/devel</code> to your module search path:</p>
<pre><code>PYTHONPATH=/Users/me/docs/devel python -m pkg.test.test_A
</code></pre>
| <p>Add <code>/Users/me/docs/devel</code> to your module search path:</p> <pre><code>PYTHONPATH=/Users/me/docs/devel python -m pkg.test.test_A </code></pre> | 16, 387, 5686 | bash, python, python-module | <h1>Run Python module with absolute path</h1>
<p>For this file layout:</p>
<pre><code>devel/
pkg/
__init__.py
moduleA.py
moduleB.py
test/
__init__.py
test_A.py
test_B.py
</code></pre>
<p>If I am in the directory which contains the pkg (devel), I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,291 | bash | # Run Python module with absolute path
For this file layout:
```
devel/
pkg/
__init__.py
moduleA.py
moduleB.py
test/
__init__.py
test_A.py
test_B.py
```
If I am in the directory which contains the pkg (devel), I can run:
```
python -m pkg.test.... | Add `/Users/me/docs/devel` to your module search path:
```
PYTHONPATH=/Users/me/docs/devel python -m pkg.test.test_A
``` |
22516804 | How to get a substring after the last underscore (_) in unix shell script | 10 | 2014-03-19 19:58:08 | <p>I have a String like this</p>
<pre><code>this_is_test_string1_22
this_is_also_test_string12_6
</code></pre>
<p>I wanted to split and extracts string around the last underscore.
That is i wanted the outputs like this</p>
<pre><code>this_is_test_string1 and 22
this_is_also_test_string12 and 6
</code></pre>
<p>Can... | 15,667 | 1,831,032 | 2014-03-19 21:52:42 | 22,516,857 | 13 | 2014-03-19 20:01:23 | 548,225 | 2014-03-19 21:52:42 | https://stackoverflow.com/q/22516804 | https://stackoverflow.com/a/22516857 | <p>You can do</p>
<pre><code>s='this_is_test_string1_22'
</code></pre>
<p>In BASH:</p>
<pre><code>echo "${s##*_}"
22
</code></pre>
<p>OR using sed:</p>
<pre><code>sed 's/^.*_\([^_]*\)$/\1/' <<< 'this_is_test_string1_22'
22
</code></pre>
<p><strong>EDIT</strong> for sh:</p>
<pre><code>echo "$s" | sed 's/... | <p>You can do</p> <pre><code>s='this_is_test_string1_22' </code></pre> <p>In BASH:</p> <pre><code>echo "${s##*_}" 22 </code></pre> <p>OR using sed:</p> <pre><code>sed 's/^.*_\([^_]*\)$/\1/' <<< 'this_is_test_string1_22' 22 </code></pre> <p><strong>EDIT</strong> for sh:</p> <pre><code>echo "$s" | sed 's/... | 34, 390, 4371 | shell, substring, unix | <h1>How to get a substring after the last underscore (_) in unix shell script</h1>
<p>I have a String like this</p>
<pre><code>this_is_test_string1_22
this_is_also_test_string12_6
</code></pre>
<p>I wanted to split and extracts string around the last underscore.
That is i wanted the outputs like this</p>
<pre><code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,292 | bash | # How to get a substring after the last underscore (_) in unix shell script
I have a String like this
```
this_is_test_string1_22
this_is_also_test_string12_6
```
I wanted to split and extracts string around the last underscore.
That is i wanted the outputs like this
```
this_is_test_string1 and 22
this_is_also_tes... | You can do
```
s='this_is_test_string1_22'
```
In BASH:
```
echo "${s##*_}"
22
```
OR using sed:
```
sed 's/^.*_\([^_]*\)$/\1/' <<< 'this_is_test_string1_22'
22
```
**EDIT** for sh:
```
echo "$s" | sed 's/^.*_\([^_]*\)$/\1/'
``` |
21238053 | How to list AD group membership for AD users using input list? | 10 | 2014-01-20 15:38:34 | <p>I'm fairly new PS user... Looking for some assistance with a powershell script to obtain list of security groups user is member of.</p>
<p>To describe what I need:</p>
<ul>
<li>I have input list (txt file) with many users (samaccountnames). Every name is on a new line.</li>
<li>I need the script to search these na... | 167,111 | 3,215,439 | 2017-06-30 13:42:25 | 21,239,092 | 13 | 2014-01-20 16:24:01 | null | 2014-01-20 16:24:01 | https://stackoverflow.com/q/21238053 | https://stackoverflow.com/a/21239092 | <p><strong>First</strong>: As it currently stands, the <code>$User</code> variable does not have a <code>.Users</code> property. In your code, <code>$User</code> simply represents one line (the "current" line in the foreach loop) from the text file.</p>
<pre><code>$getmembership = Get-ADUser $User -Properties MemberOf... | <p><strong>First</strong>: As it currently stands, the <code>$User</code> variable does not have a <code>.Users</code> property. In your code, <code>$User</code> simply represents one line (the "current" line in the foreach loop) from the text file.</p> <pre><code>$getmembership = Get-ADUser $User -Properties MemberOf... | 67, 526, 10401 | active-directory, membership, powershell | <h1>How to list AD group membership for AD users using input list?</h1>
<p>I'm fairly new PS user... Looking for some assistance with a powershell script to obtain list of security groups user is member of.</p>
<p>To describe what I need:</p>
<ul>
<li>I have input list (txt file) with many users (samaccountnames). Ev... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,293 | bash | # How to list AD group membership for AD users using input list?
I'm fairly new PS user... Looking for some assistance with a powershell script to obtain list of security groups user is member of.
To describe what I need:
- I have input list (txt file) with many users (samaccountnames). Every name is on a new line.
... | **First**: As it currently stands, the `$User` variable does not have a `.Users` property. In your code, `$User` simply represents one line (the "current" line in the foreach loop) from the text file.
```
$getmembership = Get-ADUser $User -Properties MemberOf | Select -ExpandProperty memberof
```
**Secondly**, I do n... |
20775290 | show process's full command line in powershell? | 10 | 2013-12-25 17:36:39 | <p>When I run this command</p>
<p><code>PS C:\> gwmi Win32_Process | select CommandLine</code></p>
<p>It cuts off the command line. How can I get it to show the full command line?</p>
<p><img src="https://i.sstatic.net/IW2JE.png" alt="enter image description here"></p>
| 20,032 | 385,907 | 2024-03-11 17:56:39 | 20,775,356 | 13 | 2013-12-25 17:46:25 | 574,168 | 2020-03-07 18:43:05 | https://stackoverflow.com/q/20775290 | https://stackoverflow.com/a/20775356 | <p>That being done by the default formatting, which is using <code>Format-Table</code>. Try format-list </p>
<pre><code>gwmi win32_process | select commandline | format-list
</code></pre>
| <p>That being done by the default formatting, which is using <code>Format-Table</code>. Try format-list </p> <pre><code>gwmi win32_process | select commandline | format-list </code></pre> | 526 | powershell | <h1>show process's full command line in powershell?</h1>
<p>When I run this command</p>
<p><code>PS C:\> gwmi Win32_Process | select CommandLine</code></p>
<p>It cuts off the command line. How can I get it to show the full command line?</p>
<p><img src="https://i.sstatic.net/IW2JE.png" alt="enter image descriptio... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,294 | bash | # show process's full command line in powershell?
When I run this command
`PS C:\> gwmi Win32_Process | select CommandLine`
It cuts off the command line. How can I get it to show the full command line?
 | That being done by the default formatting, which is using `Format-Table`. Try format-list
```
gwmi win32_process | select commandline | format-list
``` |
18781264 | How to log the time taken for a unix command? | 10 | 2013-09-13 08:05:05 | <p>I know my script is going to take more than 10 hours to run. Is there a way to log the time it starts and the time it ends ?</p>
<p>Does the <code>time</code> command just time the process or do I get the output of the process that I'm timing ? </p>
| 18,053 | 610,569 | 2016-04-05 23:27:54 | 18,781,467 | 13 | 2013-09-13 08:15:59 | 2,583,876 | 2013-09-13 08:28:44 | https://stackoverflow.com/q/18781264 | https://stackoverflow.com/a/18781467 | <p>Use the <code>time</code> command (<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?time" rel="noreferrer">details</a>):</p>
<pre><code>time your_prog
</code></pre>
<p>If <code>time</code> does not fit for you, I would try to log the output of <code>date</code> (<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?date" rel... | <p>Use the <code>time</code> command (<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?time" rel="noreferrer">details</a>):</p> <pre><code>time your_prog </code></pre> <p>If <code>time</code> does not fit for you, I would try to log the output of <code>date</code> (<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?date" rel... | 34, 390, 603, 1796 | command, shell, time, unix | <h1>How to log the time taken for a unix command?</h1>
<p>I know my script is going to take more than 10 hours to run. Is there a way to log the time it starts and the time it ends ?</p>
<p>Does the <code>time</code> command just time the process or do I get the output of the process that I'm timing ? </p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,295 | bash | # How to log the time taken for a unix command?
I know my script is going to take more than 10 hours to run. Is there a way to log the time it starts and the time it ends ?
Does the `time` command just time the process or do I get the output of the process that I'm timing ? | Use the `time` command ([details](http://unixhelp.ed.ac.uk/CGI/man-cgi?time)):
```
time your_prog
```
If `time` does not fit for you, I would try to log the output of `date` ([details](http://unixhelp.ed.ac.uk/CGI/man-cgi?date)) before and after the execution of your program, e.g.
```
date > log.txt; your_prog; date... |
17815551 | How do I check if a variable is unset AND use set -u in my bash prelude? | 10 | 2013-07-23 16:15:38 | <p>I know that <code>set -u</code> will fail the script if there are any unbound variables referenced, but in my bash script, I'm checking to see if a certain variable is unset within an if statement before I attempt to do something with it, like so: </p>
<pre><code>if [[ -z "${SOME_VARIABLE}" ]] ; then
echo '$SOM... | 1,712 | 1,094,541 | 2013-09-16 21:25:44 | 17,815,795 | 13 | 2013-07-23 16:27:14 | 1,338,292 | 2013-09-16 21:25:44 | https://stackoverflow.com/q/17815551 | https://stackoverflow.com/a/17815795 | <p>You could use an expansion:</p>
<pre><code>if [ -z "${SOME_VARIABLE:-}" ]; then
echo '$SOME_VARIABLE' is not set
else
do_stuff_with_SOME_VARIABLE
fi
</code></pre>
<p>This expands <code>$SOME_VARIABLE</code> to null. Read more about parameter substitution <a href="http://tldp.org/LDP/Bash-Beginners-Guide/ht... | <p>You could use an expansion:</p> <pre><code>if [ -z "${SOME_VARIABLE:-}" ]; then echo '$SOME_VARIABLE' is not set else do_stuff_with_SOME_VARIABLE fi </code></pre> <p>This expands <code>$SOME_VARIABLE</code> to null. Read more about parameter substitution <a href="http://tldp.org/LDP/Bash-Beginners-Guide/ht... | 139, 276, 387, 37019 | bash, string, unset, variables | <h1>How do I check if a variable is unset AND use set -u in my bash prelude?</h1>
<p>I know that <code>set -u</code> will fail the script if there are any unbound variables referenced, but in my bash script, I'm checking to see if a certain variable is unset within an if statement before I attempt to do something with ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,296 | bash | # How do I check if a variable is unset AND use set -u in my bash prelude?
I know that `set -u` will fail the script if there are any unbound variables referenced, but in my bash script, I'm checking to see if a certain variable is unset within an if statement before I attempt to do something with it, like so:
```
if... | You could use an expansion:
```
if [ -z "${SOME_VARIABLE:-}" ]; then
echo '$SOME_VARIABLE' is not set
else
do_stuff_with_SOME_VARIABLE
fi
```
This expands `$SOME_VARIABLE` to null. Read more about parameter substitution [here](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html#sect_03_04_03) (see t... |
16345407 | How to pass 'yes' to python manage.py flush? | 10 | 2013-05-02 18:41:09 | <p>According to <a href="https://stackoverflow.com/questions/3385049/how-to-pass-keyboard-input-along-to-linux-command">this StackOverflow thread about piping input</a>, running <code>echo "yes" | command</code> should pass <code>yes</code> to the first prompt of a command. However, <code>echo "yes" | python manage.py ... | 12,894 | 1,305,724 | 2013-05-02 20:53:18 | 16,347,534 | 13 | 2013-05-02 20:53:18 | 372,757 | 2013-05-02 20:53:18 | https://stackoverflow.com/q/16345407 | https://stackoverflow.com/a/16347534 | <p>Reading your comments, it appears you want to get the first one automated, and then have it ask for the rest.</p>
<p>You may or may not have learned this from that link:</p>
<p>The manage script asks for input on stdin.
Echo passes its output to its stdout, then closes.</p>
<p>You want to pass the echoed 'yes' to... | <p>Reading your comments, it appears you want to get the first one automated, and then have it ask for the rest.</p> <p>You may or may not have learned this from that link:</p> <p>The manage script asks for input on stdin. Echo passes its output to its stdout, then closes.</p> <p>You want to pass the echoed 'yes' to... | 243, 387, 5003 | bash, django, prompt | <h1>How to pass 'yes' to python manage.py flush?</h1>
<p>According to <a href="https://stackoverflow.com/questions/3385049/how-to-pass-keyboard-input-along-to-linux-command">this StackOverflow thread about piping input</a>, running <code>echo "yes" | command</code> should pass <code>yes</code> to the first prompt of a ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,297 | bash | # How to pass 'yes' to python manage.py flush?
According to [this StackOverflow thread about piping input](https://stackoverflow.com/questions/3385049/how-to-pass-keyboard-input-along-to-linux-command), running `echo "yes" | command` should pass `yes` to the first prompt of a command. However, `echo "yes" | python man... | Reading your comments, it appears you want to get the first one automated, and then have it ask for the rest.
You may or may not have learned this from that link:
The manage script asks for input on stdin.
Echo passes its output to its stdout, then closes.
You want to pass the echoed 'yes' to stdout, followed by rea... |
15157666 | How do I echo a backspace from php cli? | 10 | 2013-03-01 12:21:11 | <p>This question: <a href="https://askubuntu.com/questions/16149/overwrite-previous-output-in-bash-instead-of-appending-it">https://askubuntu.com/questions/16149/overwrite-previous-output-in-bash-instead-of-appending-it</a></p>
<p>Explains how to do a countdown as a bash script. I want to do the same thing, but I need... | 8,872 | 494,643 | 2013-03-01 19:19:44 | 15,158,385 | 13 | 2013-03-01 12:58:48 | 1,741,542 | 2013-03-01 19:19:44 | https://stackoverflow.com/q/15157666 | https://stackoverflow.com/a/15158385 | <p>From <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double" rel="noreferrer">Strings - Double quoted</a>, there is no <code>\b</code> recognized as an escape sequence. You can use the <a href="http://en.wikipedia.org/wiki/ASCII" rel="noreferrer">ASCII</a> backspace hex o... | <p>From <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double" rel="noreferrer">Strings - Double quoted</a>, there is no <code>\b</code> recognized as an escape sequence. You can use the <a href="http://en.wikipedia.org/wiki/ASCII" rel="noreferrer">ASCII</a> backspace hex o... | 5, 387, 11225 | bash, command-line-interface, php | <h1>How do I echo a backspace from php cli?</h1>
<p>This question: <a href="https://askubuntu.com/questions/16149/overwrite-previous-output-in-bash-instead-of-appending-it">https://askubuntu.com/questions/16149/overwrite-previous-output-in-bash-instead-of-appending-it</a></p>
<p>Explains how to do a countdown as a bas... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,298 | bash | # How do I echo a backspace from php cli?
This question: <https://askubuntu.com/questions/16149/overwrite-previous-output-in-bash-instead-of-appending-it>
Explains how to do a countdown as a bash script. I want to do the same thing, but I need to do it in PHP. Is there a way to echo a backspace?
e.g.
```
echo "Coun... | From [Strings - Double quoted](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double), there is no `\b` recognized as an escape sequence. You can use the [ASCII](http://en.wikipedia.org/wiki/ASCII) backspace hex or octal code
```
$bs = "\x08";
echo "Counting down 60";
sleep(1);
ech... |
11134857 | Using sendmail for HTML body and binary attachment | 10 | 2012-06-21 09:04:23 | <p>Objective: To send mail (using sendmail) with HTML body and binary attachment.</p>
<p>Followed the guidelines specified in the following links</p>
<p><a href="http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html">http://www.unix.com/shell-programming-scripting/159522-sendmail... | 44,182 | 1,471,464 | 2021-01-15 09:23:02 | 11,725,308 | 13 | 2012-07-30 16:09:45 | 1,471,464 | 2012-07-30 16:16:36 | https://stackoverflow.com/q/11134857 | https://stackoverflow.com/a/11725308 | <p>Changing the Content transfer encoding type within the email from base64 to uuencode resolved the issue.
Thanks for the inputs so far.</p>
<p>Given below is the revised script that works.</p>
<pre><code>#!/usr/bin/ksh
export MAILFROM="noreply@domain.com"
export MAILTO="mail.to@gmail.com"
export SUBJECT="Test PDF ... | <p>Changing the Content transfer encoding type within the email from base64 to uuencode resolved the issue. Thanks for the inputs so far.</p> <p>Given below is the revised script that works.</p> <pre><code>#!/usr/bin/ksh export MAILFROM="noreply@domain.com" export MAILTO="mail.to@gmail.com" export SUBJECT="Test PDF ... | 34, 390, 1964, 3836, 36619 | ksh, sendmail, shell, unix, uuencode | <h1>Using sendmail for HTML body and binary attachment</h1>
<p>Objective: To send mail (using sendmail) with HTML body and binary attachment.</p>
<p>Followed the guidelines specified in the following links</p>
<p><a href="http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html">htt... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,299 | bash | # Using sendmail for HTML body and binary attachment
Objective: To send mail (using sendmail) with HTML body and binary attachment.
Followed the guidelines specified in the following links
<http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html>
<http://www.unix.com/shell-progra... | Changing the Content transfer encoding type within the email from base64 to uuencode resolved the issue.
Thanks for the inputs so far.
Given below is the revised script that works.
```
#!/usr/bin/ksh
export MAILFROM="noreply@domain.com"
export MAILTO="mail.to@gmail.com"
export SUBJECT="Test PDF for Email"
export BOD... |
11092616 | GNU Screen: How can I create a screen in the background if it doesn't exist? | 10 | 2012-06-18 23:46:14 | <p>"screen -R -D -S test" will create a session named test if it doesn't exist, or connect to it if it does</p>
<p>"screen -d -m -S test" will create a new detached session named test, whether it exists or not, possibly leading to multiple sessions named test:</p>
<pre><code>There are several suitable screens on:
... | 6,167 | 939,259 | 2012-06-19 00:16:35 | 11,092,727 | 13 | 2012-06-19 00:03:41 | 73,492 | 2012-06-19 00:16:35 | https://stackoverflow.com/q/11092616 | https://stackoverflow.com/a/11092727 | <p>I believe you're looking for the <code>-d -R</code> combination:</p>
<pre><code>screen -d -R -S test
</code></pre>
<p>From <code>man screen</code>:</p>
<pre><code> -d -R Reattach a session and if necessary detach or even create it
first
</code></pre>
<p><strong>EDIT</strong></p>
<p>If yo... | <p>I believe you're looking for the <code>-d -R</code> combination:</p> <pre><code>screen -d -R -S test </code></pre> <p>From <code>man screen</code>:</p> <pre><code> -d -R Reattach a session and if necessary detach or even create it first </code></pre> <p><strong>EDIT</strong></p> <p>If yo... | 390, 5024 | gnu-screen, shell | <h1>GNU Screen: How can I create a screen in the background if it doesn't exist?</h1>
<p>"screen -R -D -S test" will create a session named test if it doesn't exist, or connect to it if it does</p>
<p>"screen -d -m -S test" will create a new detached session named test, whether it exists or not, possibly leading to mu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,300 | bash | # GNU Screen: How can I create a screen in the background if it doesn't exist?
"screen -R -D -S test" will create a session named test if it doesn't exist, or connect to it if it does
"screen -d -m -S test" will create a new detached session named test, whether it exists or not, possibly leading to multiple sessions ... | I believe you're looking for the `-d -R` combination:
```
screen -d -R -S test
```
From `man screen`:
```
-d -R Reattach a session and if necessary detach or even create it
first
```
**EDIT**
If you just want to create a background screen only if it doesn't exist, a little shell function i... |
10504916 | In bash how do I use ls to list a single folder | 10 | 2012-05-08 19:10:52 | <p>I often use <code>ls</code> (in long format: <code>ll</code>) to list a single file, just to see the attributes. How do I list a single folder, <em>without</em> expanding the content.</p>
<p><strong>Example</strong></p>
<pre><code>hpek@melda:~/temp/test$ ls
file.txt folder
hpek@melda:~/temp/test$ ls file.txt
file... | 5,231 | 1,021,175 | 2012-05-08 20:22:49 | 10,504,930 | 13 | 2012-05-08 19:11:45 | 714,501 | 2012-05-08 19:11:45 | https://stackoverflow.com/q/10504916 | https://stackoverflow.com/a/10504930 | <blockquote>
<p>How do I list a single folder, without expanding the content.</p>
</blockquote>
<p>Try passing the <code>-d</code> switch.</p>
<pre><code>cnicutar@lemon:~$ ls -ld /etc
drwxr-xr-x 144 root root 12288 May 8 18:50 /etc
</code></pre>
| <blockquote> <p>How do I list a single folder, without expanding the content.</p> </blockquote> <p>Try passing the <code>-d</code> switch.</p> <pre><code>cnicutar@lemon:~$ ls -ld /etc drwxr-xr-x 144 root root 12288 May 8 18:50 /etc </code></pre> | 387, 3589 | bash, ls | <h1>In bash how do I use ls to list a single folder</h1>
<p>I often use <code>ls</code> (in long format: <code>ll</code>) to list a single file, just to see the attributes. How do I list a single folder, <em>without</em> expanding the content.</p>
<p><strong>Example</strong></p>
<pre><code>hpek@melda:~/temp/test$ ls
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,301 | bash | # In bash how do I use ls to list a single folder
I often use `ls` (in long format: `ll`) to list a single file, just to see the attributes. How do I list a single folder, *without* expanding the content.
**Example**
```
hpek@melda:~/temp/test$ ls
file.txt folder
hpek@melda:~/temp/test$ ls file.txt
file.txt
hpek@me... | > How do I list a single folder, without expanding the content.
Try passing the `-d` switch.
```
cnicutar@lemon:~$ ls -ld /etc
drwxr-xr-x 144 root root 12288 May 8 18:50 /etc
``` |
10133274 | How to run C++ application in Android SHELL | 10 | 2012-04-12 23:29:01 | <p>I want to run <code>hello world</code> written on C++ and compiled with <code>Android toolchain 9</code>, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.</p>
<p>I used <code>Android 2.3.3 - Api Level 10</code></p>
<p>Application was compiled by cro... | 7,010 | 1,038,424 | 2013-08-13 05:42:36 | 10,297,223 | 13 | 2012-04-24 11:48:24 | 1,353,267 | 2013-08-13 05:42:36 | https://stackoverflow.com/q/10133274 | https://stackoverflow.com/a/10297223 | <p>By default, the SD card is mounted with option <code>noexec</code>, that disallows the execution of any file on the card, no matter what it's permissions(even <code>-rwxrwxrwx</code>), so you need to move the file to another location and then execute it.</p>
<p>The easiest is to move the file to <code>/data/local/t... | <p>By default, the SD card is mounted with option <code>noexec</code>, that disallows the execution of any file on the card, no matter what it's permissions(even <code>-rwxrwxrwx</code>), so you need to move the file to another location and then execute it.</p> <p>The easiest is to move the file to <code>/data/local/t... | 390, 1386, 4747, 42420 | android, android-ndk, g++, shell | <h1>How to run C++ application in Android SHELL</h1>
<p>I want to run <code>hello world</code> written on C++ and compiled with <code>Android toolchain 9</code>, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.</p>
<p>I used <code>Android 2.3.3 - Api Le... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,302 | bash | # How to run C++ application in Android SHELL
I want to run `hello world` written on C++ and compiled with `Android toolchain 9`, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.
I used `Android 2.3.3 - Api Level 10`
Application was compiled by cross ... | By default, the SD card is mounted with option `noexec`, that disallows the execution of any file on the card, no matter what it's permissions(even `-rwxrwxrwx`), so you need to move the file to another location and then execute it.
The easiest is to move the file to `/data/local/tmp/` and execute it using the full pa... |
9981516 | how to escape special characters in .gitconfig proxy authentication | 10 | 2012-04-02 18:10:45 | <p>I'm trying to use git behind a proxy and i have set up the proxy details in the .gitconfig files as follows.</p>
<pre><code> [http]
proxy = http://<username>:<password>@<proxy_ip>:<proxy_port>
</code></pre>
<p>The problem is that the username and password field contain the '@' characte... | 5,486 | 581,420 | 2012-04-02 20:00:22 | 9,981,882 | 13 | 2012-04-02 18:35:47 | 6,309 | 2012-04-02 18:35:47 | https://stackoverflow.com/q/9981516 | https://stackoverflow.com/a/9981882 | <p>Replacing <code>@</code> with <code>%40</code>. (as illustrated, for instance, in <a href="https://bugzilla.redhat.com/show_bug.cgi?id=682412" rel="noreferrer">this bug report</a>)</p>
<pre><code>export http_proxy=http://username%40domain.com:password@host:port
</code></pre>
| <p>Replacing <code>@</code> with <code>%40</code>. (as illustrated, for instance, in <a href="https://bugzilla.redhat.com/show_bug.cgi?id=682412" rel="noreferrer">this bug report</a>)</p> <pre><code>export http_proxy=http://username%40domain.com:password@host:port </code></pre> | 58, 119, 387, 760 | bash, git, linux, proxy | <h1>how to escape special characters in .gitconfig proxy authentication</h1>
<p>I'm trying to use git behind a proxy and i have set up the proxy details in the .gitconfig files as follows.</p>
<pre><code> [http]
proxy = http://<username>:<password>@<proxy_ip>:<proxy_port>
</code></pre>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,303 | bash | # how to escape special characters in .gitconfig proxy authentication
I'm trying to use git behind a proxy and i have set up the proxy details in the .gitconfig files as follows.
```
[http]
proxy = http://<username>:<password>@<proxy_ip>:<proxy_port>
```
The problem is that the username and password field cont... | Replacing `@` with `%40`. (as illustrated, for instance, in [this bug report](https://bugzilla.redhat.com/show_bug.cgi?id=682412))
```
export http_proxy=http://username%40domain.com:password@host:port
``` |
8881038 | How to set focus back to form after opening up a process (Notepad)? | 10 | 2012-01-16 13:58:11 | <p>I open up a notepad from my program using <code>Process.Start()</code> but the new opened notepad covers the screen. But I do want my application to maintain its focus.</p>
<p>I similarly (using the same Process.Start) open up MS Excel and Word but to get focus back to my form all I need to write is:</p>
<pre><cod... | 32,536 | 661,933 | 2020-06-04 23:08:18 | 8,910,385 | 13 | 2012-01-18 12:53:11 | 661,933 | 2012-01-18 15:23:28 | https://stackoverflow.com/q/8881038 | https://stackoverflow.com/a/8910385 | <p>I tried almost everything on internet (so sure about it :)). At best I could get my form on top of all other forms, but without focus (going by @Hans Passant's method). Going by heavy blocks of codes all over, I somehow felt this aint gonna be easy. So I always used <code>SetForegroundWindow()</code> with chunks of ... | <p>I tried almost everything on internet (so sure about it :)). At best I could get my form on top of all other forms, but without focus (going by @Hans Passant's method). Going by heavy blocks of codes all over, I somehow felt this aint gonna be easy. So I always used <code>SetForegroundWindow()</code> with chunks of ... | 9, 4183, 5910, 8123, 36252 | c#, focus, process, windows-shell, winforms | <h1>How to set focus back to form after opening up a process (Notepad)?</h1>
<p>I open up a notepad from my program using <code>Process.Start()</code> but the new opened notepad covers the screen. But I do want my application to maintain its focus.</p>
<p>I similarly (using the same Process.Start) open up MS Excel and... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,304 | bash | # How to set focus back to form after opening up a process (Notepad)?
I open up a notepad from my program using `Process.Start()` but the new opened notepad covers the screen. But I do want my application to maintain its focus.
I similarly (using the same Process.Start) open up MS Excel and Word but to get focus back... | I tried almost everything on internet (so sure about it :)). At best I could get my form on top of all other forms, but without focus (going by @Hans Passant's method). Going by heavy blocks of codes all over, I somehow felt this aint gonna be easy. So I always used `SetForegroundWindow()` with chunks of other code. Ne... |
8084142 | Check if rpm exists in bash script silently | 10 | 2011-11-10 18:03:25 | <p>I'm trying to do a quick check to see if an rpm is installed in a bash script using an if statement. But I want to do it silently. Currently, when I run the script, and the rpm does exist, it outputs the output of rpm to the screen which I dont want.</p>
<pre><code>if rpm -qa | grep glib; then
do something
fi
<... | 36,666 | 695,727 | 2022-10-19 10:32:47 | 8,085,659 | 13 | 2011-11-10 20:12:08 | 906,208 | 2011-11-10 20:12:08 | https://stackoverflow.com/q/8084142 | https://stackoverflow.com/a/8085659 | <p>1) You can add -q switch to grep</p>
<pre><code>if rpm -qa | grep -q glib; then
do something
fi
</code></pre>
<p>2) You can redirect stout and/or stderr output to /dev/null</p>
<pre><code>if rpm -qa | grep glib 2>&1 > /dev/null; then
do something
fi
</code></pre>
| <p>1) You can add -q switch to grep</p> <pre><code>if rpm -qa | grep -q glib; then do something fi </code></pre> <p>2) You can redirect stout and/or stderr output to /dev/null</p> <pre><code>if rpm -qa | grep glib 2>&1 > /dev/null; then do something fi </code></pre> | 387, 5652 | bash, rpm | <h1>Check if rpm exists in bash script silently</h1>
<p>I'm trying to do a quick check to see if an rpm is installed in a bash script using an if statement. But I want to do it silently. Currently, when I run the script, and the rpm does exist, it outputs the output of rpm to the screen which I dont want.</p>
<pre><co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,305 | bash | # Check if rpm exists in bash script silently
I'm trying to do a quick check to see if an rpm is installed in a bash script using an if statement. But I want to do it silently. Currently, when I run the script, and the rpm does exist, it outputs the output of rpm to the screen which I dont want.
```
if rpm -qa | grep... | 1) You can add -q switch to grep
```
if rpm -qa | grep -q glib; then
do something
fi
```
2) You can redirect stout and/or stderr output to /dev/null
```
if rpm -qa | grep glib 2>&1 > /dev/null; then
do something
fi
``` |
7169509 | Get folder (or sub-files/folders) last modification date and time | 10 | 2011-08-24 01:32:26 | <p>Is it possible to get the modification date and time of a folder?<br>
I know you can use <code>stat -f "%m" folder</code>, but it doesn't reflect sub-files/folders changes.</p>
<p>Things that doesn't work:</p>
<ul>
<li><code>ls -l folder</code> - doesn't reflect changes inside the folder</li>
<li><code>stat -f "%m... | 30,647 | 640,584 | 2022-10-21 12:10:50 | 7,169,732 | 13 | 2011-08-24 02:14:03 | 640,584 | 2014-12-27 19:26:17 | https://stackoverflow.com/q/7169509 | https://stackoverflow.com/a/7169732 | <p>Solution:</p>
<pre><code>find . -exec stat -f "%m" \{} \; | sort -n -r | head -1
</code></pre>
<p>Explanation:</p>
<ol>
<li>the <code>find</code> command traverses the current directory (<code>.</code>) and for each file encountered executes (<code>-exec</code>) the command <code>stat -f "%m"</code>. <code>stat -... | <p>Solution:</p> <pre><code>find . -exec stat -f "%m" \{} \; | sort -n -r | head -1 </code></pre> <p>Explanation:</p> <ol> <li>the <code>find</code> command traverses the current directory (<code>.</code>) and for each file encountered executes (<code>-exec</code>) the command <code>stat -f "%m"</code>. <code>stat -... | 369, 387 | bash, macos | <h1>Get folder (or sub-files/folders) last modification date and time</h1>
<p>Is it possible to get the modification date and time of a folder?<br>
I know you can use <code>stat -f "%m" folder</code>, but it doesn't reflect sub-files/folders changes.</p>
<p>Things that doesn't work:</p>
<ul>
<li><code>ls -l folder</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,306 | bash | # Get folder (or sub-files/folders) last modification date and time
Is it possible to get the modification date and time of a folder?
I know you can use `stat -f "%m" folder`, but it doesn't reflect sub-files/folders changes.
Things that doesn't work:
- `ls -l folder` - doesn't reflect changes inside the folder
- ... | Solution:
```
find . -exec stat -f "%m" \{} \; | sort -n -r | head -1
```
Explanation:
1. the `find` command traverses the current directory (`.`) and for each file encountered executes (`-exec`) the command `stat -f "%m"`. `stat -f "%m"` prints the last modification unix timestamp of the file.
2. `sort -n -r` sorts... |
6934848 | In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to? | 10 | 2011-08-04 00:22:42 | <p>In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to? </p>
<p>I don't want to redirect the output. I just want to be able to read/print it after a command is run.</p>
| 18,904 | 279,998 | 2020-05-13 20:20:37 | 6,934,931 | 13 | 2011-08-04 00:36:30 | null | 2011-08-04 00:36:30 | https://stackoverflow.com/q/6934848 | https://stackoverflow.com/a/6934931 | <p>Nope, there's no way to see a line sent to <code>stdout</code> unless <code>stdout</code>'s already been sent somewhere. If it was sent to a console, copy the text from that console. If you sent it to a file, <code>tail -n 1</code> that file. If you can re-run the command which generates the line you want to see, I ... | <p>Nope, there's no way to see a line sent to <code>stdout</code> unless <code>stdout</code>'s already been sent somewhere. If it was sent to a console, copy the text from that console. If you sent it to a file, <code>tail -n 1</code> that file. If you can re-run the command which generates the line you want to see, I ... | 34, 58, 387 | bash, linux, unix | <h1>In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to?</h1>
<p>In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to? </p>
<p>I don't want to redirect the output. I just want to be able to read/print it after a command ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,307 | bash | # In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to?
In bash, is there a way to echo/print the last stdout? Is there a variable that stdout is assigned to?
I don't want to redirect the output. I just want to be able to read/print it after a command is run. | Nope, there's no way to see a line sent to `stdout` unless `stdout`'s already been sent somewhere. If it was sent to a console, copy the text from that console. If you sent it to a file, `tail -n 1` that file. If you can re-run the command which generates the line you want to see, I would suggest piping it to `tail -n ... |
6848606 | Print only values smaller than certain threshold in bash | 10 | 2011-07-27 17:25:57 | <p>I have a file with more than 10000 lines like this, mostly numbers and some strings;</p>
<p>-40</p>
<p>-50</p>
<p>stringA</p>
<p>100</p>
<p>20</p>
<p>-200</p>
<p>...</p>
<p>I would like to write a bash (or other) script that reading this file only outputs numbers (no strings) and only those values smaller th... | 17,260 | 171,546 | 2011-07-27 17:51:27 | 6,848,893 | 13 | 2011-07-27 17:51:27 | 399,680 | 2011-07-27 17:51:27 | https://stackoverflow.com/q/6848606 | https://stackoverflow.com/a/6848893 | <pre><code>cat filename | awk '{if($1==$1+0 && $1<THRESHOLD_VALUE)print $1}' | sort -n
</code></pre>
<p>The $1==$1+0 ensure that the string is a number, it will then check that it is less than THRESHOLD_VALUE (change this to whatever number you wish. Print it out if it passes, and sort.</p>
| <pre><code>cat filename | awk '{if($1==$1+0 && $1<THRESHOLD_VALUE)print $1}' | sort -n </code></pre> <p>The $1==$1+0 ensure that the string is a number, it will then check that it is less than THRESHOLD_VALUE (change this to whatever number you wish. Print it out if it passes, and sort.</p> | 134, 387, 531, 10052 | bash, filter, scripting, sorting | <h1>Print only values smaller than certain threshold in bash</h1>
<p>I have a file with more than 10000 lines like this, mostly numbers and some strings;</p>
<p>-40</p>
<p>-50</p>
<p>stringA</p>
<p>100</p>
<p>20</p>
<p>-200</p>
<p>...</p>
<p>I would like to write a bash (or other) script that reading this file ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,308 | bash | # Print only values smaller than certain threshold in bash
I have a file with more than 10000 lines like this, mostly numbers and some strings;
-40
-50
stringA
100
20
-200
...
I would like to write a bash (or other) script that reading this file only outputs numbers (no strings) and only those values smaller t... | ```
cat filename | awk '{if($1==$1+0 && $1<THRESHOLD_VALUE)print $1}' | sort -n
```
The $1==$1+0 ensure that the string is a number, it will then check that it is less than THRESHOLD_VALUE (change this to whatever number you wish. Print it out if it passes, and sort. |
6692221 | CakePHP: Run shell job from controller | 10 | 2011-07-14 11:07:52 | <p>Is it possible to use dispatchShell from a Controller?</p>
<p>My mission is to start a shell job when the user has signed up.</p>
<p>I'm using CakePHP 2.0</p>
| 20,598 | 194,515 | 2017-05-16 10:31:57 | 6,697,141 | 13 | 2011-07-14 17:00:50 | 41,874 | 2014-02-17 15:14:32 | https://stackoverflow.com/q/6692221 | https://stackoverflow.com/a/6697141 | <p>If you can't mitigate the need to do this as dogmatic suggests then, read on.</p>
<p>So you have a (potentially) long-running job you want to perform and you don't want the user to wait.</p>
<p>As the PHP code your user is executing happens during a request that has been started by Apache, any code that is execute... | <p>If you can't mitigate the need to do this as dogmatic suggests then, read on.</p> <p>So you have a (potentially) long-running job you want to perform and you don't want the user to wait.</p> <p>As the PHP code your user is executing happens during a request that has been started by Apache, any code that is execute... | 390, 3437 | cakephp, shell | <h1>CakePHP: Run shell job from controller</h1>
<p>Is it possible to use dispatchShell from a Controller?</p>
<p>My mission is to start a shell job when the user has signed up.</p>
<p>I'm using CakePHP 2.0</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,309 | bash | # CakePHP: Run shell job from controller
Is it possible to use dispatchShell from a Controller?
My mission is to start a shell job when the user has signed up.
I'm using CakePHP 2.0 | If you can't mitigate the need to do this as dogmatic suggests then, read on.
So you have a (potentially) long-running job you want to perform and you don't want the user to wait.
As the PHP code your user is executing happens during a request that has been started by Apache, any code that is executed will stall that... |
6436209 | values of true and false in shell | 10 | 2011-06-22 07:11:08 | <p>I read that in shell,
true command returns 0 => logical true.
false command return 1 => logical false.
But I get surprising results when i run.</p>
<pre><code>if [ 0 ]
then
echo "0 is true."
else
echo "0 is false."
fi
if [ 1 ]
then
echo "1 is true."
else
echo "1 is false."
fi
if [ false ]
then
echo "false is true... | 47,097 | 548,634 | 2019-09-10 15:55:57 | 6,436,322 | 13 | 2011-06-22 07:22:07 | 15,168 | 2019-09-10 15:55:57 | https://stackoverflow.com/q/6436209 | https://stackoverflow.com/a/6436322 | <p>The test <code>if [ 0 ]</code> tests whether <code>0</code> is the empty string (it isn't) and returns true if it is not empty. The test <code>if [ 1 ]</code> similarly tests whether <code>1</code> is the empty string and returns true if it is not empty. Likewise, the other two tests check whether the strings <cod... | <p>The test <code>if [ 0 ]</code> tests whether <code>0</code> is the empty string (it isn't) and returns true if it is not empty. The test <code>if [ 1 ]</code> similarly tests whether <code>1</code> is the empty string and returns true if it is not empty. Likewise, the other two tests check whether the strings <cod... | 34, 390 | shell, unix | <h1>values of true and false in shell</h1>
<p>I read that in shell,
true command returns 0 => logical true.
false command return 1 => logical false.
But I get surprising results when i run.</p>
<pre><code>if [ 0 ]
then
echo "0 is true."
else
echo "0 is false."
fi
if [ 1 ]
then
echo "1 is true."
else
echo "1 is false.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,310 | bash | # values of true and false in shell
I read that in shell,
true command returns 0 => logical true.
false command return 1 => logical false.
But I get surprising results when i run.
```
if [ 0 ]
then
echo "0 is true."
else
echo "0 is false."
fi
if [ 1 ]
then
echo "1 is true."
else
echo "1 is false."
fi
if [ false ]
t... | The test `if [ 0 ]` tests whether `0` is the empty string (it isn't) and returns true if it is not empty. The test `if [ 1 ]` similarly tests whether `1` is the empty string and returns true if it is not empty. Likewise, the other two tests check whether the strings `true` and `false` are empty...
If you want to test ... |
4653829 | Checking if a file is readable and exists in one if condition: if [[ -r -f "/file.png" ]] | 10 | 2011-01-11 03:10:09 | <p>I was writing an if statement which checked if a file is readable and exists by doing the following:</p>
<pre><code>if [[ -r "$upFN" && -f "$upFN" ]]; then
....
fi
</code></pre>
<p>Then I thought, surly you can make this smaller, something maybe like this:</p>
<pre><code>if [[ -r -f "$upFN" ]]; then
....
... | 28,541 | 138,541 | 2016-06-01 01:16:27 | 4,653,992 | 13 | 2011-01-11 03:45:18 | 41,747 | 2011-01-11 03:45:18 | https://stackoverflow.com/q/4653829 | https://stackoverflow.com/a/4653992 | <p>AFAICT, there is no way to combine them further. As a portability note, <code>[[ expr ]]</code> is less portable than <code>[ expr ]</code> or <code>test expr</code>. The C-style <code>&&</code> and <code>||</code> are only included in bash so you might want to consider using the POSIX syntax of <code>-a</... | <p>AFAICT, there is no way to combine them further. As a portability note, <code>[[ expr ]]</code> is less portable than <code>[ expr ]</code> or <code>test expr</code>. The C-style <code>&&</code> and <code>||</code> are only included in bash so you might want to consider using the POSIX syntax of <code>-a</... | 387, 1012, 2773 | bash, debian, if-statement | <h1>Checking if a file is readable and exists in one if condition: if [[ -r -f "/file.png" ]] </h1>
<p>I was writing an if statement which checked if a file is readable and exists by doing the following:</p>
<pre><code>if [[ -r "$upFN" && -f "$upFN" ]]; then
....
fi
</code></pre>
<p>Then I thought, surly you ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,311 | bash | # Checking if a file is readable and exists in one if condition: if [[ -r -f "/file.png" ]]
I was writing an if statement which checked if a file is readable and exists by doing the following:
```
if [[ -r "$upFN" && -f "$upFN" ]]; then
....
fi
```
Then I thought, surly you can make this smaller, something maybe lik... | AFAICT, there is no way to combine them further. As a portability note, `[[ expr ]]` is less portable than `[ expr ]` or `test expr`. The C-style `&&` and `||` are only included in bash so you might want to consider using the POSIX syntax of `-a` for *and* and `-o` for *or*. Personally, I prefer using `test expr` since... |
3342335 | Dump memory of a process | 10 | 2010-07-27 09:43:08 | <p>When reading the /proc/$PID/maps you get the mapped memory regions.
Is ther a way to dump one of this regions?</p>
<pre><code>$ cat /proc/18448/maps
...[snip]...
0059e000-005b1000 r-xp 00000000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0
005b1000-005b2000 r--p 00012000 08:11 40 /usr/local/lib/... | 14,957 | 343,957 | 2016-06-23 07:48:04 | 3,344,402 | 13 | 2010-07-27 14:01:26 | 149,482 | 2016-06-23 07:48:04 | https://stackoverflow.com/q/3342335 | https://stackoverflow.com/a/3344402 | <p>Nah! Call <a href="http://linux.die.net/man/2/ptrace" rel="nofollow noreferrer"><code>ptrace()</code></a> with <code>PTRACE ATTACH</code>. Then open <a href="http://linux.die.net/man/5/proc" rel="nofollow noreferrer"><code>/proc/<pid>/mem</code></a>, seek to the region offset, and read the length of the region... | <p>Nah! Call <a href="http://linux.die.net/man/2/ptrace" rel="nofollow noreferrer"><code>ptrace()</code></a> with <code>PTRACE ATTACH</code>. Then open <a href="http://linux.die.net/man/5/proc" rel="nofollow noreferrer"><code>/proc/<pid>/mem</code></a>, seek to the region offset, and read the length of the region... | 8, 58, 387, 2723 | bash, c, linux, memory-dump | <h1>Dump memory of a process</h1>
<p>When reading the /proc/$PID/maps you get the mapped memory regions.
Is ther a way to dump one of this regions?</p>
<pre><code>$ cat /proc/18448/maps
...[snip]...
0059e000-005b1000 r-xp 00000000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0
005b1000-005b2000 r--p 0001200... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,312 | bash | # Dump memory of a process
When reading the /proc/$PID/maps you get the mapped memory regions.
Is ther a way to dump one of this regions?
```
$ cat /proc/18448/maps
...[snip]...
0059e000-005b1000 r-xp 00000000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0
005b1000-005b2000 r--p 00012000 08:11 40 /u... | Nah! Call [`ptrace()`](http://linux.die.net/man/2/ptrace) with `PTRACE ATTACH`. Then open [`/proc/<pid>/mem`](http://linux.die.net/man/5/proc), seek to the region offset, and read the length of the region as given in `/proc</pid>/maps`.
Here's a [program I wrote](https://github.com/anacrolix/archive/blob/master/tibia/... |
3270337 | How to write a PowerShell function to get directories? | 10 | 2010-07-17 05:08:56 | <p>Using PowerShell I can get the directories with the following command:</p>
<pre><code>Get-ChildItem -Path $path -Include "obj" -Recurse | `
Where-Object { $_.PSIsContainer }
</code></pre>
<p>I would prefer to write a function so the command is more readable. For example:</p>
<pre><code>Get-Directories -Path "... | 13,962 | 22,941 | 2015-11-12 13:13:47 | 3,270,377 | 13 | 2010-07-17 05:26:17 | 6,920 | 2010-07-17 05:26:17 | https://stackoverflow.com/q/3270337 | https://stackoverflow.com/a/3270377 | <p>Try this:</p>
<pre><code># nouns should be singular unless results are guaranteed to be plural.
# arguments have been changed to match cmdlet parameter types
Function Get-Directory([string[]]$path, [string[]]$include, [switch]$recurse)
{
Get-ChildItem -Path $path -Include $include -Recurse:$recurse | `
... | <p>Try this:</p> <pre><code># nouns should be singular unless results are guaranteed to be plural. # arguments have been changed to match cmdlet parameter types Function Get-Directory([string[]]$path, [string[]]$include, [switch]$recurse) { Get-ChildItem -Path $path -Include $include -Recurse:$recurse | ` ... | 218, 526, 29006 | directory, get-childitem, powershell | <h1>How to write a PowerShell function to get directories?</h1>
<p>Using PowerShell I can get the directories with the following command:</p>
<pre><code>Get-ChildItem -Path $path -Include "obj" -Recurse | `
Where-Object { $_.PSIsContainer }
</code></pre>
<p>I would prefer to write a function so the command is mor... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,313 | bash | # How to write a PowerShell function to get directories?
Using PowerShell I can get the directories with the following command:
```
Get-ChildItem -Path $path -Include "obj" -Recurse | `
Where-Object { $_.PSIsContainer }
```
I would prefer to write a function so the command is more readable. For example:
```
Get... | Try this:
```
# nouns should be singular unless results are guaranteed to be plural.
# arguments have been changed to match cmdlet parameter types
Function Get-Directory([string[]]$path, [string[]]$include, [switch]$recurse)
{
Get-ChildItem -Path $path -Include $include -Recurse:$recurse | `
Where-Objec... |
3135626 | What's the easiest in a shell script to ensure its not run as root? | 10 | 2010-06-28 19:46:49 | <p>I have a Java application executed from a ([ba]sh) shell script and unfortunately sometimes the people responsible for deploying it and starting it fail to switch to the appropriate user before starting the application. In this situation I'd like the application to not run at the very least, and ideally issue a war... | 514 | 85,306 | 2010-12-09 22:38:53 | 3,135,674 | 13 | 2010-06-28 19:52:01 | 372,200 | 2010-06-28 19:57:42 | https://stackoverflow.com/q/3135626 | https://stackoverflow.com/a/3135674 | <p>Example in bash:</p>
<pre><code>if [ `id -u` = 0 ]; then
echo "You are root, go away!"
exit 1
fi
</code></pre>
| <p>Example in bash:</p> <pre><code>if [ `id -u` = 0 ]; then echo "You are root, go away!" exit 1 fi </code></pre> | 17, 136, 390 | java, security, shell | <h1>What's the easiest in a shell script to ensure its not run as root?</h1>
<p>I have a Java application executed from a ([ba]sh) shell script and unfortunately sometimes the people responsible for deploying it and starting it fail to switch to the appropriate user before starting the application. In this situation I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,314 | bash | # What's the easiest in a shell script to ensure its not run as root?
I have a Java application executed from a ([ba]sh) shell script and unfortunately sometimes the people responsible for deploying it and starting it fail to switch to the appropriate user before starting the application. In this situation I'd like th... | Example in bash:
```
if [ `id -u` = 0 ]; then
echo "You are root, go away!"
exit 1
fi
``` |
2225976 | Ignore a path entry with bash tab-completion | 10 | 2010-02-09 00:45:37 | <p>I have two commands, <code>foo</code> and <code>foo-bar</code>, where <code>foo</code> is a symlink to <code>foo-bar</code>. I want to be able to type <code>f</code>+TAB (pretend these are the only two commands on the path that begin with <code>f</code>) and have one of them be completed (meaning the full name <stro... | 2,033 | 192,236 | 2021-08-10 23:45:49 | 2,226,088 | 13 | 2010-02-09 01:14:28 | 29,809 | 2010-07-16 05:28:14 | https://stackoverflow.com/q/2225976 | https://stackoverflow.com/a/2226088 | <p>You use FIGNORE, although it has some strange properties.</p>
<p>FIGNORE requires a proper suffix. So to ignore foo-bar, any of these will work:</p>
<pre><code>FIGNORE=bar
FIGNORE=-bar
FIGNORE=r
FIGNORE=oo-bar
</code></pre>
<p>The import thing is <strong>not</strong> to try <code>FIGNORE=foo-bar</code> since it'... | <p>You use FIGNORE, although it has some strange properties.</p> <p>FIGNORE requires a proper suffix. So to ignore foo-bar, any of these will work:</p> <pre><code>FIGNORE=bar FIGNORE=-bar FIGNORE=r FIGNORE=oo-bar </code></pre> <p>The import thing is <strong>not</strong> to try <code>FIGNORE=foo-bar</code> since it'... | 387, 4682, 6268, 12891 | autocomplete, bash, path, tab-completion | <h1>Ignore a path entry with bash tab-completion</h1>
<p>I have two commands, <code>foo</code> and <code>foo-bar</code>, where <code>foo</code> is a symlink to <code>foo-bar</code>. I want to be able to type <code>f</code>+TAB (pretend these are the only two commands on the path that begin with <code>f</code>) and have... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,315 | bash | # Ignore a path entry with bash tab-completion
I have two commands, `foo` and `foo-bar`, where `foo` is a symlink to `foo-bar`. I want to be able to type `f`+TAB (pretend these are the only two commands on the path that begin with `f`) and have one of them be completed (meaning the full name **and** the space after).
... | You use FIGNORE, although it has some strange properties.
FIGNORE requires a proper suffix. So to ignore foo-bar, any of these will work:
```
FIGNORE=bar
FIGNORE=-bar
FIGNORE=r
FIGNORE=oo-bar
```
The import thing is **not** to try `FIGNORE=foo-bar` since it's not a proper suffix. |
1948107 | PS: Get index in an array list | 10 | 2009-12-22 18:00:39 | <p>I have an array of strings. Not sure if there is simple way to get the index of an item first found in the array?</p>
<pre><code># example array
$array = "A", "B", "C"
$item = "B"
# the following line gets null, any way to get its index?
$index = $array | where {$_ -eq $item} | ForEach-Object { $_.Index }
</code></... | 53,670 | 62,776 | 2009-12-23 02:16:57 | 1,948,139 | 13 | 2009-12-22 18:05:39 | 25,911 | 2009-12-22 18:05:39 | https://stackoverflow.com/q/1948107 | https://stackoverflow.com/a/1948139 | <p>Use a for loop (or a foreach loop that iterates over the array index...same difference). I don't know of any system variable that holds the current array index inside a foreach loop, and I don't think one exists.</p>
<pre><code># example array
$array = "A", "B", "C"
$item = "B"
0..($array.Count - 1) | Where { $arra... | <p>Use a for loop (or a foreach loop that iterates over the array index...same difference). I don't know of any system variable that holds the current array index inside a foreach loop, and I don't think one exists.</p> <pre><code># example array $array = "A", "B", "C" $item = "B" 0..($array.Count - 1) | Where { $arra... | 526 | powershell | <h1>PS: Get index in an array list</h1>
<p>I have an array of strings. Not sure if there is simple way to get the index of an item first found in the array?</p>
<pre><code># example array
$array = "A", "B", "C"
$item = "B"
# the following line gets null, any way to get its index?
$index = $array | where {$_ -eq $item}... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,316 | bash | # PS: Get index in an array list
I have an array of strings. Not sure if there is simple way to get the index of an item first found in the array?
```
# example array
$array = "A", "B", "C"
$item = "B"
# the following line gets null, any way to get its index?
$index = $array | where {$_ -eq $item} | ForEach-Object { ... | Use a for loop (or a foreach loop that iterates over the array index...same difference). I don't know of any system variable that holds the current array index inside a foreach loop, and I don't think one exists.
```
# example array
$array = "A", "B", "C"
$item = "B"
0..($array.Count - 1) | Where { $array[$_] -eq $ite... |
644772 | Structs or Objects in Powershell 2 | 10 | 2009-03-13 21:59:57 | <p>Does the latest version of Powershell have the ability to do something like JavaScript's:</p>
<pre><code>var point = new Object();
point.x = 12;
point.y = 50;
</code></pre>
<p>If not, what is the equivalent or workaround? </p>
<p><strong>UPDATE</strong><br>
Read all comments</p>
| 15,093 | 36,590 | 2022-05-05 17:37:57 | 644,825 | 13 | 2009-03-13 22:20:56 | 23,283 | 2009-03-13 22:20:56 | https://stackoverflow.com/q/644772 | https://stackoverflow.com/a/644825 | <p>The syntax is not directly supported by the functionality is there via the add-member cmdlet's. Awhile ago, I wrapped this functionality in a general purpose tuple function.</p>
<p>This will give you the ability to one line create these objects. </p>
<pre><code>$point = New-Tuple "x",12,"y",50
</code></pre>
<p>... | <p>The syntax is not directly supported by the functionality is there via the add-member cmdlet's. Awhile ago, I wrapped this functionality in a general purpose tuple function.</p> <p>This will give you the ability to one line create these objects. </p> <pre><code>$point = New-Tuple "x",12,"y",50 </code></pre> <p>... | 526, 3676, 24067 | powershell, powershell-2.0, tuples | <h1>Structs or Objects in Powershell 2</h1>
<p>Does the latest version of Powershell have the ability to do something like JavaScript's:</p>
<pre><code>var point = new Object();
point.x = 12;
point.y = 50;
</code></pre>
<p>If not, what is the equivalent or workaround? </p>
<p><strong>UPDATE</strong><br>
Read all com... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,317 | bash | # Structs or Objects in Powershell 2
Does the latest version of Powershell have the ability to do something like JavaScript's:
```
var point = new Object();
point.x = 12;
point.y = 50;
```
If not, what is the equivalent or workaround?
**UPDATE**
Read all comments | The syntax is not directly supported by the functionality is there via the add-member cmdlet's. Awhile ago, I wrapped this functionality in a general purpose tuple function.
This will give you the ability to one line create these objects.
```
$point = New-Tuple "x",12,"y",50
```
Here is the code for New-Tuple
```
f... |
617369 | Powershell Joins | 10 | 2009-03-06 00:56:21 | <p>Im trying to join a number of elements of an array into a string using this;</p>
<pre><code>$a = "h","e","l","l","o"
$b = [string]::join("", $a[0,1,2,3])
</code></pre>
<p>But I get a 'Missing ')' in method call' error. The join documentation only mentions joining all the elements of an array, not elements at spec... | 2,669 | null | 2016-01-19 17:13:46 | 617,384 | 13 | 2009-03-06 01:05:37 | 4,035 | 2009-03-11 02:48:31 | https://stackoverflow.com/q/617369 | https://stackoverflow.com/a/617384 | <p>Wrap the content of "$a[0,1,2,3]" with "$()" or "()"</p>
<pre><code>PS> [string]::join("", $($a[0,1,2,3]))
hell
PS> [string]::join("", ($a[0,1,2,3]))
hell
</code></pre>
<p>-- Or --</p>
<p>you can use range operator ".."</p>
<pre><code>PS> [string]::join("", $a[0..3])
hell
</code></pre>
| <p>Wrap the content of "$a[0,1,2,3]" with "$()" or "()"</p> <pre><code>PS> [string]::join("", $($a[0,1,2,3])) hell PS> [string]::join("", ($a[0,1,2,3])) hell </code></pre> <p>-- Or --</p> <p>you can use range operator ".."</p> <pre><code>PS> [string]::join("", $a[0..3]) hell </code></pre> | 139, 526, 3626 | join, powershell, string | <h1>Powershell Joins</h1>
<p>Im trying to join a number of elements of an array into a string using this;</p>
<pre><code>$a = "h","e","l","l","o"
$b = [string]::join("", $a[0,1,2,3])
</code></pre>
<p>But I get a 'Missing ')' in method call' error. The join documentation only mentions joining all the elements of an a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,318 | bash | # Powershell Joins
Im trying to join a number of elements of an array into a string using this;
```
$a = "h","e","l","l","o"
$b = [string]::join("", $a[0,1,2,3])
```
But I get a 'Missing ')' in method call' error. The join documentation only mentions joining all the elements of an array, not elements at specific ind... | Wrap the content of "$a[0,1,2,3]" with "$()" or "()"
```
PS> [string]::join("", $($a[0,1,2,3]))
hell
PS> [string]::join("", ($a[0,1,2,3]))
hell
```
-- Or --
you can use range operator ".."
```
PS> [string]::join("", $a[0..3])
hell
``` |
71268012 | Sticky Header using shell less command | 9 | 2022-02-25 15:22:25 | <p>I have a text table that I am displaying using <code>less -S -R</code>.</p>
<p><a href="https://i.sstatic.net/cXm53.gif" rel="noreferrer"><img src="https://i.sstatic.net/cXm53.gif" alt="enter image description here" /></a></p>
<p><strong>I would like that 3rd and 4th line of the output (the last 2 blue lines) to be ... | 1,614 | 6,331,353 | 2024-01-10 20:32:31 | 71,308,346 | 13 | 2022-03-01 12:14:38 | 1,627,296 | 2024-01-10 20:32:31 | https://stackoverflow.com/q/71268012 | https://stackoverflow.com/a/71308346 | <p>A <code>--header</code> option was recently <a href="http://www.greenwoodsoftware.com/less/news.600.html" rel="nofollow noreferrer">added in less 600</a> (released on 2022-01-07) for that:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>--header=N[,M]
Sets the number of header lines and co... | <p>A <code>--header</code> option was recently <a href="http://www.greenwoodsoftware.com/less/news.600.html" rel="nofollow noreferrer">added in less 600</a> (released on 2022-01-07) for that:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>--header=N[,M] Sets the number of header lines and co... | 390, 391, 3791, 29657 | less, shell, terminal, zsh | <h1>Sticky Header using shell less command</h1>
<p>I have a text table that I am displaying using <code>less -S -R</code>.</p>
<p><a href="https://i.sstatic.net/cXm53.gif" rel="noreferrer"><img src="https://i.sstatic.net/cXm53.gif" alt="enter image description here" /></a></p>
<p><strong>I would like that 3rd and 4th l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,319 | bash | # Sticky Header using shell less command
I have a text table that I am displaying using `less -S -R`.
[](https://i.sstatic.net/cXm53.gif)
**I would like that 3rd and 4th line of the output (the last 2 blue lines) to be a sticky header, so that it would ... | A `--header` option was recently [added in less 600](http://www.greenwoodsoftware.com/less/news.600.html) (released on 2022-01-07) for that:
> ```
> --header=N[,M]
> Sets the number of header lines and columns displayed on the
> screen. The value may be of the form "N,M" where N and M are
> integers, ... |
67226131 | How to delete .htaccess file recursive based on size or content | 9 | 2021-04-23 07:59:48 | <p>I am seeking a terminal command to recursively go through folder structures and either delete <code>.htaccess</code> files with permission of 0444 and/or if possible to match the first line in the file for a safety measure.</p>
<p>Had a few accounts compromised on a server, which cleared up the malware / rootkits bu... | 13,716 | 4,520,308 | 2024-09-04 08:41:36 | 67,226,519 | 13 | 2021-04-23 08:26:41 | 14,523,221 | 2021-04-23 08:53:59 | https://stackoverflow.com/q/67226131 | https://stackoverflow.com/a/67226519 | <p>You can use <code>find</code> to go recursively through multiple directories, search for files and execute a command like <code>rm</code> on the result.</p>
<pre><code>find . -type f -perm 0444 -name ".htaccess" -exec echo rm {} \;
</code></pre>
<ul>
<li><code>.</code> current diretory / can be other path ... | <p>You can use <code>find</code> to go recursively through multiple directories, search for files and execute a command like <code>rm</code> on the result.</p> <pre><code>find . -type f -perm 0444 -name ".htaccess" -exec echo rm {} \; </code></pre> <ul> <li><code>.</code> current diretory / can be other path ... | 58, 387, 390 | bash, linux, shell | <h1>How to delete .htaccess file recursive based on size or content</h1>
<p>I am seeking a terminal command to recursively go through folder structures and either delete <code>.htaccess</code> files with permission of 0444 and/or if possible to match the first line in the file for a safety measure.</p>
<p>Had a few acc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,320 | bash | # How to delete .htaccess file recursive based on size or content
I am seeking a terminal command to recursively go through folder structures and either delete `.htaccess` files with permission of 0444 and/or if possible to match the first line in the file for a safety measure.
Had a few accounts compromised on a ser... | You can use `find` to go recursively through multiple directories, search for files and execute a command like `rm` on the result.
```
find . -type f -perm 0444 -name ".htaccess" -exec echo rm {} \;
```
- `.` current diretory / can be other path e.g. `/etc`
- `-type f` search for files
- `-perm 0444` permission 0444
... |
61978350 | Difference between shebang flags vs. set builtin flags | 9 | 2020-05-23 20:43:17 | <p>Is there a difference in behaviours with respect to the flags passed to the script on the shebang line vs. using the <code>set</code> builtin?</p>
<p>For example:</p>
<pre><code>#!/bin/bash -e
# do stuff
</code></pre>
<p>vs.</p>
<pre><code>#!/bin/bash
set -e
# do stuff
</code></pre>
<p>(The question is not spe... | 2,138 | 1,275,169 | 2021-02-10 18:42:26 | 61,978,606 | 13 | 2020-05-23 21:09:44 | 9,072,753 | 2021-02-10 18:42:26 | https://stackoverflow.com/q/61978350 | https://stackoverflow.com/a/61978606 | <blockquote>
<p>are there any other differences in functionality/behaviour?</p>
</blockquote>
<p>When your file has executable permissions and is executed, then the shebang line is parsed by the kernel.</p>
<p>When your file is executed under the shell like <code>bash ./script.sh</code> then the shebang is just a comme... | <blockquote> <p>are there any other differences in functionality/behaviour?</p> </blockquote> <p>When your file has executable permissions and is executed, then the shebang line is parsed by the kernel.</p> <p>When your file is executed under the shell like <code>bash ./script.sh</code> then the shebang is just a comme... | 387, 1993, 10327 | bash, posix, sh | <h1>Difference between shebang flags vs. set builtin flags</h1>
<p>Is there a difference in behaviours with respect to the flags passed to the script on the shebang line vs. using the <code>set</code> builtin?</p>
<p>For example:</p>
<pre><code>#!/bin/bash -e
# do stuff
</code></pre>
<p>vs.</p>
<pre><code>#!/bin/b... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,321 | bash | # Difference between shebang flags vs. set builtin flags
Is there a difference in behaviours with respect to the flags passed to the script on the shebang line vs. using the `set` builtin?
For example:
```
#!/bin/bash -e
# do stuff
```
vs.
```
#!/bin/bash
set -e
# do stuff
```
(The question is not specific to `-... | > are there any other differences in functionality/behaviour?
When your file has executable permissions and is executed, then the shebang line is parsed by the kernel.
When your file is executed under the shell like `bash ./script.sh` then the shebang is just a comment. So it will be ignored, and your script will be ... |
58859092 | How do I correctly use the ansible hostname module? | 9 | 2019-11-14 14:27:40 | <p>I am trying to use ansible to modify the hostnames of a dozen newly created Virtual Machines, and I am failing to understand how to loop correctly. </p>
<p>Here is the playbook I've written: </p>
<pre><code>---
- hosts: k8s_kvm_vms
tasks:
- name: "update hostnames"
hostname:
name: "{{ item }}"
wi... | 24,422 | 7,495,254 | 2021-03-29 13:43:33 | 58,859,781 | 13 | 2019-11-14 15:00:26 | 11,399,171 | 2019-11-14 15:00:26 | https://stackoverflow.com/q/58859092 | https://stackoverflow.com/a/58859781 | <p>You can create a new variable for each of the servers in the inventory like </p>
<pre><code>[k8s_kvm_vms]
server1 new_hostname=centos1
server2 new_hostname=centos2
</code></pre>
<p>Playbook:</p>
<pre><code>---
- hosts: k8s_kvm_vms
tasks:
- name: "update hostnames"
hostname:
name: "{{ new_hostname }... | <p>You can create a new variable for each of the servers in the inventory like </p> <pre><code>[k8s_kvm_vms] server1 new_hostname=centos1 server2 new_hostname=centos2 </code></pre> <p>Playbook:</p> <pre><code>--- - hosts: k8s_kvm_vms tasks: - name: "update hostnames" hostname: name: "{{ new_hostname }... | 387, 4658, 9952, 86394 | ansible, bash, system-administration, virtual-machine | <h1>How do I correctly use the ansible hostname module?</h1>
<p>I am trying to use ansible to modify the hostnames of a dozen newly created Virtual Machines, and I am failing to understand how to loop correctly. </p>
<p>Here is the playbook I've written: </p>
<pre><code>---
- hosts: k8s_kvm_vms
tasks:
- name: "up... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,322 | bash | # How do I correctly use the ansible hostname module?
I am trying to use ansible to modify the hostnames of a dozen newly created Virtual Machines, and I am failing to understand how to loop correctly.
Here is the playbook I've written:
```
---
- hosts: k8s_kvm_vms
tasks:
- name: "update hostnames"
hostname:... | You can create a new variable for each of the servers in the inventory like
```
[k8s_kvm_vms]
server1 new_hostname=centos1
server2 new_hostname=centos2
```
Playbook:
```
---
- hosts: k8s_kvm_vms
tasks:
- name: "update hostnames"
hostname:
name: "{{ new_hostname }}"
``` |
56612034 | Wait for multiple simultaneous powershell commands in other sessions to finish before running next commands | 9 | 2019-06-15 16:08:58 | <p>I am trying to get a master powershell script to do the following:</p>
<ol>
<li>Run commands in 3 other powershell sessions (they all go for about ~1h - I'd like them to run concurrently, so that the jobs they do can all get done at the same time)</li>
<li>Wait for <strong>all 3</strong> other powershell sessions t... | 10,614 | 5,783,745 | 2025-10-21 14:29:36 | 56,612,574 | 13 | 2019-06-15 17:21:46 | 45,375 | 2025-10-21 12:34:56 | https://stackoverflow.com/q/56612034 | https://stackoverflow.com/a/56612574 | <p>You are indeed looking for <strong>Powershell <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs" rel="nofollow noreferrer"><em>background jobs</em></a></strong>, as <a href="https://stackoverflow.com/users/3080908/lee-dailey">Lee Dailey</a> advises.</p>
<p>Howeve... | <p>You are indeed looking for <strong>Powershell <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs" rel="nofollow noreferrer"><em>background jobs</em></a></strong>, as <a href="https://stackoverflow.com/users/3080908/lee-dailey">Lee Dailey</a> advises.</p> <p>Howeve... | 526 | powershell | <h1>Wait for multiple simultaneous powershell commands in other sessions to finish before running next commands</h1>
<p>I am trying to get a master powershell script to do the following:</p>
<ol>
<li>Run commands in 3 other powershell sessions (they all go for about ~1h - I'd like them to run concurrently, so that the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,323 | bash | # Wait for multiple simultaneous powershell commands in other sessions to finish before running next commands
I am trying to get a master powershell script to do the following:
1. Run commands in 3 other powershell sessions (they all go for about ~1h - I'd like them to run concurrently, so that the jobs they do can a... | You are indeed looking for **Powershell [*background jobs*](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs)**, as [Lee Dailey](https://stackoverflow.com/users/3080908/lee-dailey) advises.
However, **jobs are heavy-handed, because each job runs in its own *process***, whi... |
55300421 | How can I make npm projects with Bash shell commands work on Windows? | 9 | 2019-03-22 13:14:03 | <p>I have some NPM scripts on a project i recently took over that go like this: </p>
<pre><code>{
"package": "yarn package-common && mv './dist/APP® TV.wgt' ''./package/$(yarn -s filename)''",
"package-common": "tizen package -t wgt -s APP -- ./dist && rimraf package && mkdir package",
... | 12,736 | 5,536,214 | 2023-09-19 14:11:52 | 55,303,370 | 13 | 2019-03-22 15:50:11 | 45,375 | 2023-09-19 14:11:52 | https://stackoverflow.com/q/55300421 | https://stackoverflow.com/a/55303370 |
<p>Your basic choices for <strong>going <em>cross-platform</em> without <em>platform-specific</em> scripts</strong> are:</p>
<ul>
<li><p><strong>Use Bash also on Windows</strong>:</p>
<ul>
<li><p>Run your npm scripts from Bash <strong>via <a href="https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux" rel="nofollo... | <p>Your basic choices for <strong>going <em>cross-platform</em> without <em>platform-specific</em> scripts</strong> are:</p> <ul> <li><p><strong>Use Bash also on Windows</strong>:</p> <ul> <li><p>Run your npm scripts from Bash <strong>via <a href="https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux" rel="nofollo... | 390, 526, 1231, 2631, 61387 | cmd, command-line, npm, powershell, shell | <h1>How can I make npm projects with Bash shell commands work on Windows?</h1>
<p>I have some NPM scripts on a project i recently took over that go like this: </p>
<pre><code>{
"package": "yarn package-common && mv './dist/APP® TV.wgt' ''./package/$(yarn -s filename)''",
"package-common": "tizen packag... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,324 | bash | # How can I make npm projects with Bash shell commands work on Windows?
I have some NPM scripts on a project i recently took over that go like this:
```
{
"package": "yarn package-common && mv './dist/APP® TV.wgt' ''./package/$(yarn -s filename)''",
"package-common": "tizen package -t wgt -s APP -- ./dist && ... | Your basic choices for **going *cross-platform* without *platform-specific* scripts** are:
- **Use Bash also on Windows**:
- Run your npm scripts from Bash **via [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)** and **use the existing Bash commands** typically contained in `package.json` files, suc... |
54100496 | Check if an app is installed on macOS using the Terminal | 9 | 2019-01-08 22:13:33 | <p>I'm making a small cross-platform CLI tool in TypeScript/NodeJs. Its key feature requires that it needs to check which browsers are installed on the host. On Linux and Windows, it works flawlessly. I did a lot of research on how I can achieve that and currently I'm using "reg query" for Windows and "w... | 28,414 | 10,884,348 | 2024-02-15 10:05:35 | 54,164,811 | 13 | 2019-01-12 23:25:51 | 4,142,266 | 2019-01-12 23:25:51 | https://stackoverflow.com/q/54100496 | https://stackoverflow.com/a/54164811 | <p>The command:</p>
<pre><code>mdfind "kMDItemKind == 'Application'"
</code></pre>
<p>will output a list of installed Apps on the system (one per line) with their paths. E.g.:</p>
<blockquote>
<p>/Applications/Safari Technology Preview.app<br>
/Applications/Safari.app</p>
</blockquote>
<p>You can search your su... | <p>The command:</p> <pre><code>mdfind "kMDItemKind == 'Application'" </code></pre> <p>will output a list of installed Apps on the system (one per line) with their paths. E.g.:</p> <blockquote> <p>/Applications/Safari Technology Preview.app<br> /Applications/Safari.app</p> </blockquote> <p>You can search your su... | 369, 387, 390, 391 | bash, macos, shell, terminal | <h1>Check if an app is installed on macOS using the Terminal</h1>
<p>I'm making a small cross-platform CLI tool in TypeScript/NodeJs. Its key feature requires that it needs to check which browsers are installed on the host. On Linux and Windows, it works flawlessly. I did a lot of research on how I can achieve that and... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,325 | bash | # Check if an app is installed on macOS using the Terminal
I'm making a small cross-platform CLI tool in TypeScript/NodeJs. Its key feature requires that it needs to check which browsers are installed on the host. On Linux and Windows, it works flawlessly. I did a lot of research on how I can achieve that and currentl... | The command:
```
mdfind "kMDItemKind == 'Application'"
```
will output a list of installed Apps on the system (one per line) with their paths. E.g.:
> /Applications/Safari Technology Preview.app
> /Applications/Safari.app
You can search your supported browsers in this list. |
51034076 | Bash semicolon being equal to newline is not exactly true? | 9 | 2018-06-26 02:30:24 | <p>I've read in multiple articles that semicolon(<code>;</code>) in UNIX-like shells is equal to a new line.<br>
However, the following is confusing me and I'm having no luck googling it either. </p>
<p>I'm guessing it's an issue with <code>do</code> in shell, but "bash semicolon do" is not exactly the most google-fri... | 7,250 | 3,018,443 | 2023-02-10 09:29:05 | 51,034,170 | 13 | 2018-06-26 02:42:49 | 3,266,847 | 2018-06-26 02:42:49 | https://stackoverflow.com/q/51034076 | https://stackoverflow.com/a/51034170 | <p>Looking at the <a href="https://www.gnu.org/software/bash/manual/bash.html#index-for" rel="noreferrer">syntax of the <code>for</code>/<code>do</code> loop</a>,</p>
<pre><code>for <i>name</i> [ [in [<i>words</i> …] ] ; ] do <i>commands</i>; done</code></pre>
<p>we can see that <code>do</code> is followed by <em><co... | <p>Looking at the <a href="https://www.gnu.org/software/bash/manual/bash.html#index-for" rel="noreferrer">syntax of the <code>for</code>/<code>do</code> loop</a>,</p> <pre><code>for <i>name</i> [ [in [<i>words</i> …] ] ; ] do <i>commands</i>; done</code></pre> <p>we can see that <code>do</code> is followed by <em><co... | 387, 390 | bash, shell | <h1>Bash semicolon being equal to newline is not exactly true?</h1>
<p>I've read in multiple articles that semicolon(<code>;</code>) in UNIX-like shells is equal to a new line.<br>
However, the following is confusing me and I'm having no luck googling it either. </p>
<p>I'm guessing it's an issue with <code>do</code> ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,326 | bash | # Bash semicolon being equal to newline is not exactly true?
I've read in multiple articles that semicolon(`;`) in UNIX-like shells is equal to a new line.
However, the following is confusing me and I'm having no luck googling it either.
I'm guessing it's an issue with `do` in shell, but "bash semicolon do" is not ... | Looking at the [syntax of the `for`/`do` loop](https://www.gnu.org/software/bash/manual/bash.html#index-for),
```
for name [ [in [words …] ] ; ] do commands; done
```
we can see that `do` is followed by *`commands`* immediately, so using a newline after `do` doesn't replace a semicolon, but a space.
The description ... |
44634478 | Why does ADB commands break a bash script loop? | 9 | 2017-06-19 15:28:55 | <p>I'm noticing a problem when running multiple adb commands from a shell script loop most of the commands does not execute.</p>
<p><strong>This is an example script.</strong></p>
<p>Script name: <code>adbscript.sh</code>:</p>
<pre><code>#!/bin/bash
devicecount=0
while read device; do
((devicecount++))
seri... | 3,659 | 1,204,365 | 2017-06-19 18:11:40 | 44,634,888 | 13 | 2017-06-19 15:48:10 | 16,406 | 2017-06-19 15:48:10 | https://stackoverflow.com/q/44634478 | https://stackoverflow.com/a/44634888 | <p><code>adb shell</code> connects stdin to the command running on the device, which will generally consume stdin until a EOF is reached. So these commands consume all of the rest of your device names, causing the loop to exit.</p>
<p>Run <code>adb</code> with a stdin redirection, so they get an immediate EOF without... | <p><code>adb shell</code> connects stdin to the command running on the device, which will generally consume stdin until a EOF is reached. So these commands consume all of the rest of your device names, causing the loop to exit.</p> <p>Run <code>adb</code> with a stdin redirection, so they get an immediate EOF without... | 387, 22975 | adb, bash | <h1>Why does ADB commands break a bash script loop?</h1>
<p>I'm noticing a problem when running multiple adb commands from a shell script loop most of the commands does not execute.</p>
<p><strong>This is an example script.</strong></p>
<p>Script name: <code>adbscript.sh</code>:</p>
<pre><code>#!/bin/bash
devicecou... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,327 | bash | # Why does ADB commands break a bash script loop?
I'm noticing a problem when running multiple adb commands from a shell script loop most of the commands does not execute.
**This is an example script.**
Script name: `adbscript.sh`:
```
#!/bin/bash
devicecount=0
while read device; do
((devicecount++))
seria... | `adb shell` connects stdin to the command running on the device, which will generally consume stdin until a EOF is reached. So these commands consume all of the rest of your device names, causing the loop to exit.
Run `adb` with a stdin redirection, so they get an immediate EOF without messing with what you're trying ... |
44235158 | How to disable a shopt option in Bash? | 9 | 2017-05-29 05:28:34 | <p>How to disable a <code>shopt</code> option, for example <code>extglob</code>?</p>
<p>I have this in my <code>.bashrc</code> file:</p>
<pre><code>shopt -s extglob
</code></pre>
| 5,096 | 3,815,539 | 2019-04-18 13:29:42 | 44,235,200 | 13 | 2017-05-29 05:33:16 | 6,862,601 | 2019-04-18 13:29:42 | https://stackoverflow.com/q/44235158 | https://stackoverflow.com/a/44235200 | <p>Use the <code>-u</code> option:</p>
<pre><code>shopt -u extglob
</code></pre>
<ul>
<li><code>-s</code> is for setting and <code>-u</code> is for unsetting.</li>
</ul>
<p>From <code>help shopt</code> (or <code>shopt --help</code> as well on BSD systems):</p>
<pre><code>Options:
-o restrict OPTNAMEs to those ... | <p>Use the <code>-u</code> option:</p> <pre><code>shopt -u extglob </code></pre> <ul> <li><code>-s</code> is for setting and <code>-u</code> is for unsetting.</li> </ul> <p>From <code>help shopt</code> (or <code>shopt --help</code> as well on BSD systems):</p> <pre><code>Options: -o restrict OPTNAMEs to those ... | 387, 135295 | bash, shopt | <h1>How to disable a shopt option in Bash?</h1>
<p>How to disable a <code>shopt</code> option, for example <code>extglob</code>?</p>
<p>I have this in my <code>.bashrc</code> file:</p>
<pre><code>shopt -s extglob
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,328 | bash | # How to disable a shopt option in Bash?
How to disable a `shopt` option, for example `extglob`?
I have this in my `.bashrc` file:
```
shopt -s extglob
``` | Use the `-u` option:
```
shopt -u extglob
```
- `-s` is for setting and `-u` is for unsetting.
From `help shopt` (or `shopt --help` as well on BSD systems):
```
Options:
-o restrict OPTNAMEs to those defined for use with `set -o'
-p print each shell option with an indication of its status
-q suppress... |
41176637 | Bash/SH, Same command different output? | 9 | 2016-12-16 03:03:15 | <pre><code>$ cat a.sh
#!/bin/bash
echo -n "apple" | shasum -a 256
$ sh -x a.sh
+ echo -n apple
+ shasum -a 256
d9d20ed0e313ce50526de6185500439af174bf56be623f1c5fe74fbb73b60972 -
$ bash -x a.sh
+ echo -n apple
+ shasum -a 256
3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b -
</code></pre>
<p>And th... | 242 | 2,038,901 | 2017-01-17 02:50:43 | 41,176,680 | 13 | 2016-12-16 03:09:27 | 45,375 | 2017-01-17 02:50:43 | https://stackoverflow.com/q/41176637 | https://stackoverflow.com/a/41176680 | <p>Per POSIX, <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html" rel="nofollow noreferrer"><code>echo</code></a> supports no options.</p>
<p>Therefore, when <code>echo -n</code> is run with <code>sh</code>, it outputs <em>literal</em> <code>-n</code> instead of interpreting <code>-n</code> a... | <p>Per POSIX, <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html" rel="nofollow noreferrer"><code>echo</code></a> supports no options.</p> <p>Therefore, when <code>echo -n</code> is run with <code>sh</code>, it outputs <em>literal</em> <code>-n</code> instead of interpreting <code>-n</code> a... | 58, 387, 390, 10327 | bash, linux, sh, shell | <h1>Bash/SH, Same command different output?</h1>
<pre><code>$ cat a.sh
#!/bin/bash
echo -n "apple" | shasum -a 256
$ sh -x a.sh
+ echo -n apple
+ shasum -a 256
d9d20ed0e313ce50526de6185500439af174bf56be623f1c5fe74fbb73b60972 -
$ bash -x a.sh
+ echo -n apple
+ shasum -a 256
3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,329 | bash | # Bash/SH, Same command different output?
```
$ cat a.sh
#!/bin/bash
echo -n "apple" | shasum -a 256
$ sh -x a.sh
+ echo -n apple
+ shasum -a 256
d9d20ed0e313ce50526de6185500439af174bf56be623f1c5fe74fbb73b60972 -
$ bash -x a.sh
+ echo -n apple
+ shasum -a 256
3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b99... | Per POSIX, [`echo`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html) supports no options.
Therefore, when `echo -n` is run with `sh`, it outputs *literal* `-n` instead of interpreting `-n` as the no-trailing-newline option:
```
$ sh -c 'echo -n "apple"'
-n apple # !! Note the -n a... |
40248408 | PowerShell Remoting to a Workgroup Computer | 9 | 2016-10-25 19:43:31 | <p>I'm trying to remote powershell from my domain joined PC to a server in our DMZ but I cannot figure out how to get it working.</p>
<p>The DMZ server has a listener configured for HTTP on the default port 5985 that is enabled. The two NIC's in the machine are both labeled for Public networks so I changed the Windows... | 11,506 | 3,969,420 | 2023-12-21 19:18:37 | 40,266,799 | 13 | 2016-10-26 15:51:52 | 3,969,420 | 2016-10-26 15:51:52 | https://stackoverflow.com/q/40248408 | https://stackoverflow.com/a/40266799 | <p>I eventually figured this out, there were a couple of issues with what I was doing. First the link at <a href="https://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgroup-machines/" rel="noreferrer">https://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgro... | <p>I eventually figured this out, there were a couple of issues with what I was doing. First the link at <a href="https://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgroup-machines/" rel="noreferrer">https://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgro... | 526, 63177 | powershell, powershell-remoting | <h1>PowerShell Remoting to a Workgroup Computer</h1>
<p>I'm trying to remote powershell from my domain joined PC to a server in our DMZ but I cannot figure out how to get it working.</p>
<p>The DMZ server has a listener configured for HTTP on the default port 5985 that is enabled. The two NIC's in the machine are both... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,330 | bash | # PowerShell Remoting to a Workgroup Computer
I'm trying to remote powershell from my domain joined PC to a server in our DMZ but I cannot figure out how to get it working.
The DMZ server has a listener configured for HTTP on the default port 5985 that is enabled. The two NIC's in the machine are both labeled for Pub... | I eventually figured this out, there were a couple of issues with what I was doing. First the link at <https://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgroup-machines/> has some incorrect information. It states that the LocalAccountTokenFilterPolicy registry entry should be on the cli... |
39257543 | grep multipe wildcards in string | 9 | 2016-08-31 19:26:35 | <p>Say I have a file that contains:</p>
<pre><code>Release 2.1 OS: RHEL File: package_el6_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el6_2.0.1.1_i686.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_i686.rpm
</code></pre>
<p>I want to grep and mat... | 9,255 | 2,334,324 | 2016-08-31 20:06:43 | 39,258,001 | 13 | 2016-08-31 19:57:11 | 2,988,730 | 2016-08-31 20:00:37 | https://stackoverflow.com/q/39257543 | https://stackoverflow.com/a/39258001 | <p>Your attempt is very close. <code>*</code> in shell glob terms is roughly equivalent to <code>.*</code> in regex terms. <code>.</code> means "any character" and <code>*</code> is means "repeated any number of times (including zero).</p>
<p>Your regex just needs <code>.</code> before each <code>*</code>. The trailin... | <p>Your attempt is very close. <code>*</code> in shell glob terms is roughly equivalent to <code>.*</code> in regex terms. <code>.</code> means "any character" and <code>*</code> is means "repeated any number of times (including zero).</p> <p>Your regex just needs <code>.</code> before each <code>*</code>. The trailin... | 58, 390, 1271 | grep, linux, shell | <h1>grep multipe wildcards in string</h1>
<p>Say I have a file that contains:</p>
<pre><code>Release 2.1 OS: RHEL File: package_el6_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el6_2.0.1.1_i686.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_i686.rp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,331 | bash | # grep multipe wildcards in string
Say I have a file that contains:
```
Release 2.1 OS: RHEL File: package_el6_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el6_2.0.1.1_i686.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_x86_64.rpm
Release 2.1 OS: RHEL File: package_el7_2.0.1.1_i686.rpm
```
I want to gre... | Your attempt is very close. `*` in shell glob terms is roughly equivalent to `.*` in regex terms. `.` means "any character" and `*` is means "repeated any number of times (including zero).
Your regex just needs `.` before each `*`. The trailing `*` is not necessary:
```
package.*el6.*x86_64
```
Here is a sample run ... |
39186373 | How can I use tilde in the powershell prompt? | 9 | 2016-08-27 22:29:21 | <p>So I get that: </p>
<pre><code>function global:prompt {
# Commands go here
}
</code></pre>
<p>Sets the prompt in powershell. I can use <code>Get-Location</code> to get the current working directory. And I can <code>cd ~</code> and be in my home dir.</p>
<p>But can I make the prompt use the tilde? E.g., if I'm... | 10,774 | 123,671 | 2016-08-27 23:36:02 | 39,186,481 | 13 | 2016-08-27 22:48:11 | 702,944 | 2016-08-27 23:36:02 | https://stackoverflow.com/q/39186373 | https://stackoverflow.com/a/39186481 | <p>You can replace <code>$HOME</code> with <code>~</code> using normal string replacement. Ex.</p>
<p>Get the current prompt-function:</p>
<pre><code>Get-Content Function:\prompt
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
# .Link
# http://go.microsof... | <p>You can replace <code>$HOME</code> with <code>~</code> using normal string replacement. Ex.</p> <p>Get the current prompt-function:</p> <pre><code>Get-Content Function:\prompt "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; # .Link # http://go.microsof... | 526, 9938 | command-prompt, powershell | <h1>How can I use tilde in the powershell prompt?</h1>
<p>So I get that: </p>
<pre><code>function global:prompt {
# Commands go here
}
</code></pre>
<p>Sets the prompt in powershell. I can use <code>Get-Location</code> to get the current working directory. And I can <code>cd ~</code> and be in my home dir.</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,332 | bash | # How can I use tilde in the powershell prompt?
So I get that:
```
function global:prompt {
# Commands go here
}
```
Sets the prompt in powershell. I can use `Get-Location` to get the current working directory. And I can `cd ~` and be in my home dir.
But can I make the prompt use the tilde? E.g., if I'm in `/ho... | You can replace `$HOME` with `~` using normal string replacement. Ex.
Get the current prompt-function:
```
Get-Content Function:\prompt
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
# .Link
# http://go.microsoft.com/fwlink/?LinkID=225750
# .ExternalHel... |
37566064 | why questionmark comes in the end of filename when i create .txt file through shell script? | 9 | 2016-06-01 10:28:42 | <p>I am writing one shell script in which I am supposed to create 1 text file. When I do this, a question mark comes at the end of file name. what is the reason?</p>
<p>I am trying below methods in bash script.</p>
<p>1) <code>grep ERROR a1* > text.txt</code></p>
<p>2) <code>touch text.txt</code></p>
<p>In both ... | 18,082 | 6,203,120 | 2021-02-10 09:42:34 | 37,567,514 | 13 | 2016-06-01 11:35:42 | 887,539 | 2021-02-10 09:42:34 | https://stackoverflow.com/q/37566064 | https://stackoverflow.com/a/37567514 | <p>Sounds like you script uses <code>\r\n</code> as line endings, this is typical DOS style line endings. Unix like systems uses <code>\n</code>. You should try to change the line feeds, eg with your favorite text editor:</p>
<pre><code>vim +'set ff=unix | x' my_script
</code></pre>
<p>Or with <code>dos2unix</code>:</p... | <p>Sounds like you script uses <code>\r\n</code> as line endings, this is typical DOS style line endings. Unix like systems uses <code>\n</code>. You should try to change the line feeds, eg with your favorite text editor:</p> <pre><code>vim +'set ff=unix | x' my_script </code></pre> <p>Or with <code>dos2unix</code>:</p... | 58, 387, 390, 1271 | bash, grep, linux, shell | <h1>why questionmark comes in the end of filename when i create .txt file through shell script?</h1>
<p>I am writing one shell script in which I am supposed to create 1 text file. When I do this, a question mark comes at the end of file name. what is the reason?</p>
<p>I am trying below methods in bash script.</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,333 | bash | # why questionmark comes in the end of filename when i create .txt file through shell script?
I am writing one shell script in which I am supposed to create 1 text file. When I do this, a question mark comes at the end of file name. what is the reason?
I am trying below methods in bash script.
1) `grep ERROR a1* > t... | Sounds like you script uses `\r\n` as line endings, this is typical DOS style line endings. Unix like systems uses `\n`. You should try to change the line feeds, eg with your favorite text editor:
```
vim +'set ff=unix | x' my_script
```
Or with `dos2unix`:
```
dos2unix my_script
```
Or with GNU sed:
```
sed -i 's... |
37473108 | How do you add environment variables to your django project | 9 | 2016-05-27 00:41:12 | <p>I'm trying to set up my project so that it can use environment variables locally</p>
<p>Ive tried adding it to the end of my activate file and a list of other things. I'm trying to use this</p>
<pre><code>from .base import *
if os.environ['DJANGO_SERVER_TYPE'] == 'local':
try:
from .local ... | 28,060 | 3,650,429 | 2016-05-27 01:23:34 | 37,473,332 | 13 | 2016-05-27 01:18:15 | 291,040 | 2016-05-27 01:18:15 | https://stackoverflow.com/q/37473108 | https://stackoverflow.com/a/37473332 | <p>If you're running it through the Django web server, you can pass environment variables the same way you would to any other command:</p>
<pre><code>DJANGO_SERVER_TYPE="local" ./manage.py runserver
</code></pre>
<p>If you're running it through a web server like Apache, you can set environment variables through your ... | <p>If you're running it through the Django web server, you can pass environment variables the same way you would to any other command:</p> <pre><code>DJANGO_SERVER_TYPE="local" ./manage.py runserver </code></pre> <p>If you're running it through a web server like Apache, you can set environment variables through your ... | 16, 243, 387, 2533, 9013 | bash, development-environment, django, environment-variables, python | <h1>How do you add environment variables to your django project</h1>
<p>I'm trying to set up my project so that it can use environment variables locally</p>
<p>Ive tried adding it to the end of my activate file and a list of other things. I'm trying to use this</p>
<pre><code>from .base import *
if os.environ['D... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,334 | bash | # How do you add environment variables to your django project
I'm trying to set up my project so that it can use environment variables locally
Ive tried adding it to the end of my activate file and a list of other things. I'm trying to use this
```
from .base import *
if os.environ['DJANGO_SERVER_TYPE'] == 'loc... | If you're running it through the Django web server, you can pass environment variables the same way you would to any other command:
```
DJANGO_SERVER_TYPE="local" ./manage.py runserver
```
If you're running it through a web server like Apache, you can set environment variables through your virtual host configuration:... |
35113917 | Suppressing The Command Window Opening When Using Start-Process | 9 | 2016-01-31 12:39:03 | <p>I'm trying to find a way to get PowerShell not to spawn a command window when running an executable using <code>Start-Process</code>.</p>
<p>If I call the executable directly within the script (e.g. <code>.\program.exe</code>) then the program runs (with its arguments) and the output is returned to the PowerShell w... | 31,246 | 5,863,783 | 2016-02-01 15:58:21 | 35,114,544 | 13 | 2016-01-31 13:48:25 | 4,003,407 | 2016-02-01 15:58:21 | https://stackoverflow.com/q/35113917 | https://stackoverflow.com/a/35114544 | <p>You should prefix the executable name with the current directory when you use the <code>-NoNewWindow</code> switch:</p>
<pre><code>Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime" -Wait -NoNewWindow
</code... | <p>You should prefix the executable name with the current directory when you use the <code>-NoNewWindow</code> switch:</p> <pre><code>Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime" -Wait -NoNewWindow </code... | 64, 526 | powershell, windows | <h1>Suppressing The Command Window Opening When Using Start-Process</h1>
<p>I'm trying to find a way to get PowerShell not to spawn a command window when running an executable using <code>Start-Process</code>.</p>
<p>If I call the executable directly within the script (e.g. <code>.\program.exe</code>) then the program... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,335 | bash | # Suppressing The Command Window Opening When Using Start-Process
I'm trying to find a way to get PowerShell not to spawn a command window when running an executable using `Start-Process`.
If I call the executable directly within the script (e.g. `.\program.exe`) then the program runs (with its arguments) and the out... | You should prefix the executable name with the current directory when you use the `-NoNewWindow` switch:
```
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "download --autoDownloadOn --autoDownloadStartTime $StartTime --autoDownloadEndTime $EndTime" -Wait -NoNewWindow
```
**Background information:*... |
34438189 | bash: sleep process not getting killed | 9 | 2015-12-23 14:48:42 | <p>I wrote a simple bash script which does nothing but sleeps.</p>
<pre><code>#!/bin/bash
echo "Sleeping..."
sleep 180s
</code></pre>
<p>I see two processes running on my system after I run the script:</p>
<pre><code>user 22880 0.0 0.0 12428 1412 pts/28 S+ 20:12 0:00 /bin/bash ./sleep.sh
user 22881 0.0 ... | 8,066 | 1,369,241 | 2019-02-13 13:42:53 | 34,438,469 | 13 | 2015-12-23 15:05:52 | 1,126,841 | 2015-12-23 15:05:52 | https://stackoverflow.com/q/34438189 | https://stackoverflow.com/a/34438469 | <p><code>kill -15 22880</code> will send a signal to the shell executing the script, but not the <code>sleep</code> command. To send the signal to every process in the process <em>group</em>, you should be able to specify a <em>negative</em> process ID.</p>
<pre><code>kill -15 -22880
</code></pre>
<p>Alternately, ens... | <p><code>kill -15 22880</code> will send a signal to the shell executing the script, but not the <code>sleep</code> command. To send the signal to every process in the process <em>group</em>, you should be able to specify a <em>negative</em> process ID.</p> <pre><code>kill -15 -22880 </code></pre> <p>Alternately, ens... | 387, 390, 2221, 2481 | bash, shell, signals, sleep | <h1>bash: sleep process not getting killed</h1>
<p>I wrote a simple bash script which does nothing but sleeps.</p>
<pre><code>#!/bin/bash
echo "Sleeping..."
sleep 180s
</code></pre>
<p>I see two processes running on my system after I run the script:</p>
<pre><code>user 22880 0.0 0.0 12428 1412 pts/28 S+ 20:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,336 | bash | # bash: sleep process not getting killed
I wrote a simple bash script which does nothing but sleeps.
```
#!/bin/bash
echo "Sleeping..."
sleep 180s
```
I see two processes running on my system after I run the script:
```
user 22880 0.0 0.0 12428 1412 pts/28 S+ 20:12 0:00 /bin/bash ./sleep.sh
user 22881 0... | `kill -15 22880` will send a signal to the shell executing the script, but not the `sleep` command. To send the signal to every process in the process *group*, you should be able to specify a *negative* process ID.
```
kill -15 -22880
```
Alternately, ensure that the script kills its children before exiting.
```
tra... |
32612859 | Bash retrieve column number from column name | 9 | 2015-09-16 15:29:05 | <p>Is there a better way (such as a one liner in AWK) where I can get the column number in a table with headings from a column name? I want to be able to process a column independent of what the column number actually is (such as when another column is added the script will not need to change).</p>
<p>For example, gi... | 14,204 | 5,296,516 | 2017-11-17 16:58:44 | 32,616,101 | 13 | 2015-09-16 18:32:02 | 1,435,869 | 2017-11-17 16:58:44 | https://stackoverflow.com/q/32612859 | https://stackoverflow.com/a/32616101 | <p>another alternative with a lot of pipes</p>
<pre><code>$ head -1 table | tr -s ' ' '\n' | nl -nln | grep "Target" | cut -f1
</code></pre>
<p>extract first row, transpose, number lines, find column name, extract number</p>
<p>Or, <code>awk</code> to the rescue!</p>
<pre><code>$ awk -v RS='\t' '/Target/{print NR;... | <p>another alternative with a lot of pipes</p> <pre><code>$ head -1 table | tr -s ' ' '\n' | nl -nln | grep "Target" | cut -f1 </code></pre> <p>extract first row, transpose, number lines, find column name, extract number</p> <p>Or, <code>awk</code> to the rescue!</p> <pre><code>$ awk -v RS='\t' '/Target/{print NR;... | 387, 390, 990 | awk, bash, shell | <h1>Bash retrieve column number from column name</h1>
<p>Is there a better way (such as a one liner in AWK) where I can get the column number in a table with headings from a column name? I want to be able to process a column independent of what the column number actually is (such as when another column is added the sc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,337 | bash | # Bash retrieve column number from column name
Is there a better way (such as a one liner in AWK) where I can get the column number in a table with headings from a column name? I want to be able to process a column independent of what the column number actually is (such as when another column is added the script will ... | another alternative with a lot of pipes
```
$ head -1 table | tr -s ' ' '\n' | nl -nln | grep "Target" | cut -f1
```
extract first row, transpose, number lines, find column name, extract number
Or, `awk` to the rescue!
```
$ awk -v RS='\t' '/Target/{print NR; exit}' file.tsv
3
``` |
32404367 | Append file to file in bash without cat | 9 | 2015-09-04 18:22:51 | <p>It's easy to append an existing file to another file with <code>cat</code>: <code>cat file1 >> file2</code></p>
<p>Sometimes I have read what people wrote, "do not use <code>cat</code> unless you are concatenating two files." This is sensible. One does not really need cat if it is taking only one argument: <c... | 5,467 | 1,306,666 | 2021-04-18 09:41:06 | 32,404,833 | 13 | 2015-09-04 18:54:35 | 1,126,841 | 2015-09-04 18:54:35 | https://stackoverflow.com/q/32404367 | https://stackoverflow.com/a/32404833 | <p>This <em>is</em> an orthodox use of <code>cat</code>. The "useless use of <code>cat</code>" involves using <code>cat</code> to read the contents of a <em>single</em> file and pipe them to another program which could just as easily read directly from the file using input redirection. Here, <code>cat</code> is doing a... | <p>This <em>is</em> an orthodox use of <code>cat</code>. The "useless use of <code>cat</code>" involves using <code>cat</code> to read the contents of a <em>single</em> file and pipe them to another program which could just as easily read directly from the file using input redirection. Here, <code>cat</code> is doing a... | 387, 5310, 6051 | append, bash, file | <h1>Append file to file in bash without cat</h1>
<p>It's easy to append an existing file to another file with <code>cat</code>: <code>cat file1 >> file2</code></p>
<p>Sometimes I have read what people wrote, "do not use <code>cat</code> unless you are concatenating two files." This is sensible. One does not real... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,338 | bash | # Append file to file in bash without cat
It's easy to append an existing file to another file with `cat`: `cat file1 >> file2`
Sometimes I have read what people wrote, "do not use `cat` unless you are concatenating two files." This is sensible. One does not really need cat if it is taking only one argument: `cat fil... | This *is* an orthodox use of `cat`. The "useless use of `cat`" involves using `cat` to read the contents of a *single* file and pipe them to another program which could just as easily read directly from the file using input redirection. Here, `cat` is doing all the reading *and* writing; there isn't anything simpler yo... |
30684796 | Rename a bunch of PNG images with ".jpg" extension to ".png" | 9 | 2015-06-06 15:54:59 | <p>So I have a folder with thousands of image files, all of them saved as <code>.jpg</code>.</p>
<p>The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to <code>.png</code>. For example, the Ubuntu image viewer throws t... | 11,489 | 4,981,596 | 2022-12-09 01:24:58 | 30,684,898 | 13 | 2015-06-06 16:08:44 | 635,608 | 2015-06-06 16:08:44 | https://stackoverflow.com/q/30684796 | https://stackoverflow.com/a/30684898 | <pre><code>for f in *.jpg ; do
if [[ $(file -b --mime-type "$f") = image/png ]] ; then
mv "$f" "${f/%.jpg/.png}"
fi
done
</code></pre>
<p>This gets a list of <code>.jpg</code> files, then for each calls the <code>file</code> utility on it to get the mime type. If that's <code>image/png</code>, then it renames ... | <pre><code>for f in *.jpg ; do if [[ $(file -b --mime-type "$f") = image/png ]] ; then mv "$f" "${f/%.jpg/.png}" fi done </code></pre> <p>This gets a list of <code>.jpg</code> files, then for each calls the <code>file</code> utility on it to get the mime type. If that's <code>image/png</code>, then it renames ... | 387, 531, 1383, 1585, 4985 | bash, image, jpeg, png, scripting | <h1>Rename a bunch of PNG images with ".jpg" extension to ".png"</h1>
<p>So I have a folder with thousands of image files, all of them saved as <code>.jpg</code>.</p>
<p>The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extensi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,339 | bash | # Rename a bunch of PNG images with ".jpg" extension to ".png"
So I have a folder with thousands of image files, all of them saved as `.jpg`.
The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to `.png`. For example, ... | ```
for f in *.jpg ; do
if [[ $(file -b --mime-type "$f") = image/png ]] ; then
mv "$f" "${f/%.jpg/.png}"
fi
done
```
This gets a list of `.jpg` files, then for each calls the `file` utility on it to get the mime type. If that's `image/png`, then it renames the file using a [string manipulation](http://tldp.or... |
29702039 | Can PowerShell dot notation be used on multiple lines? | 9 | 2015-04-17 14:29:03 | <p>To make scripts more readable I would like to break things up on multiple lines. Is this possible in PowerShell's dot notation? </p>
<p>For example, take this:</p>
<pre><code>(GC myfile.txt).Replace('a',b').Replace('c','d').Replace('e','f') | SC newfile.txt
</code></pre>
<p>And write it like this:</p>
<pre><co... | 471 | 5,836 | 2019-04-21 14:11:28 | 29,702,119 | 13 | 2015-04-17 14:32:52 | 1,303,090 | 2015-04-17 14:32:52 | https://stackoverflow.com/q/29702039 | https://stackoverflow.com/a/29702119 | <p>I found the same issue, the easiest way to solve it is to place the point before breaking the line</p>
<pre><code>(GC myfile.txt).Replace('a',b').
Replace('c','d')
</code></pre>
| <p>I found the same issue, the easiest way to solve it is to place the point before breaking the line</p> <pre><code>(GC myfile.txt).Replace('a',b'). Replace('c','d') </code></pre> | 526 | powershell | <h1>Can PowerShell dot notation be used on multiple lines?</h1>
<p>To make scripts more readable I would like to break things up on multiple lines. Is this possible in PowerShell's dot notation? </p>
<p>For example, take this:</p>
<pre><code>(GC myfile.txt).Replace('a',b').Replace('c','d').Replace('e','f') | SC new... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,340 | bash | # Can PowerShell dot notation be used on multiple lines?
To make scripts more readable I would like to break things up on multiple lines. Is this possible in PowerShell's dot notation?
For example, take this:
```
(GC myfile.txt).Replace('a',b').Replace('c','d').Replace('e','f') | SC newfile.txt
```
And write it lik... | I found the same issue, the easiest way to solve it is to place the point before breaking the line
```
(GC myfile.txt).Replace('a',b').
Replace('c','d')
``` |
28698694 | SMB Client Commands Through Shell Script | 9 | 2015-02-24 14:42:43 | <p>I have a shell script, which I am using to access the SMB Client:</p>
<pre><code>#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username
recurse
prompt
mput baclupfiles
exit
</code></pre>
<p>Right now, the script runs, accesses the server, and then asks for a manual input of the co... | 34,227 | 2,393,127 | 2020-10-01 13:16:58 | 28,719,195 | 13 | 2015-02-25 12:35:56 | 2,393,127 | 2015-02-25 12:35:56 | https://stackoverflow.com/q/28698694 | https://stackoverflow.com/a/28719195 | <p>I worked out a solution to this, and sharing for future references.</p>
<pre><code>#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username << SMBCLIENTCOMMANDS
recurse
prompt
mput backupfiles
exit
SMBCLIENTCOMMANDS
</code></pre>
<p>This will enter the commands between the two... | <p>I worked out a solution to this, and sharing for future references.</p> <pre><code>#!/bin/bash cd /home/username smbclient //link/to/server$ password -W domain -U username << SMBCLIENTCOMMANDS recurse prompt mput backupfiles exit SMBCLIENTCOMMANDS </code></pre> <p>This will enter the commands between the two... | 34, 390, 706 | shell, smb, unix | <h1>SMB Client Commands Through Shell Script</h1>
<p>I have a shell script, which I am using to access the SMB Client:</p>
<pre><code>#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username
recurse
prompt
mput baclupfiles
exit
</code></pre>
<p>Right now, the script runs, accesses the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,341 | bash | # SMB Client Commands Through Shell Script
I have a shell script, which I am using to access the SMB Client:
```
#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username
recurse
prompt
mput baclupfiles
exit
```
Right now, the script runs, accesses the server, and then asks for a manua... | I worked out a solution to this, and sharing for future references.
```
#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username << SMBCLIENTCOMMANDS
recurse
prompt
mput backupfiles
exit
SMBCLIENTCOMMANDS
```
This will enter the commands between the two `SMBCLIENTCOMMANDS` statements i... |
28560515 | Replace string variable with string variable using Sed | 9 | 2015-02-17 11:04:50 | <p>I have a file called <strong>ethernet</strong> containing multiple lines. I have saved one of these lines as a variable called <strong>old_line</strong>. The contents of this variable looks like this:</p>
<pre><code>SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="2r:11:89:89:9g:ah", ATTR{dev_id}=="0... | 60,011 | 2,835,098 | 2020-07-09 20:08:24 | 28,563,120 | 13 | 2015-02-17 13:57:53 | 3,210,257 | 2015-02-17 13:57:53 | https://stackoverflow.com/q/28560515 | https://stackoverflow.com/a/28563120 | <p>You need to escape your <code>oldline</code> so that it contains no regex special characters, luckily this can be done with sed.</p>
<pre><code>old_line=$(echo "${old_line}" | sed -e 's/[]$.*[\^]/\\&/g' )
sed -i -e "s/${old_line}/${new_line}/g" ethernet
</code></pre>
| <p>You need to escape your <code>oldline</code> so that it contains no regex special characters, luckily this can be done with sed.</p> <pre><code>old_line=$(echo "${old_line}" | sed -e 's/[]$.*[\^]/\\&/g' ) sed -i -e "s/${old_line}/${new_line}/g" ethernet </code></pre> | 18, 58, 387, 5282 | bash, linux, regex, sed | <h1>Replace string variable with string variable using Sed</h1>
<p>I have a file called <strong>ethernet</strong> containing multiple lines. I have saved one of these lines as a variable called <strong>old_line</strong>. The contents of this variable looks like this:</p>
<pre><code>SUBSYSTEM=="net", ACTION=="add", DRI... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,342 | bash | # Replace string variable with string variable using Sed
I have a file called **ethernet** containing multiple lines. I have saved one of these lines as a variable called **old_line**. The contents of this variable looks like this:
```
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="2r:11:89:89:9g:ah"... | You need to escape your `oldline` so that it contains no regex special characters, luckily this can be done with sed.
```
old_line=$(echo "${old_line}" | sed -e 's/[]$.*[\^]/\\&/g' )
sed -i -e "s/${old_line}/${new_line}/g" ethernet
``` |
25627336 | Integrate bash test scripts in cmake | 9 | 2014-09-02 15:43:57 | <p>I have a C++ cmake project that uses Boost Test for unit testing. Now I would like to expose a series of bash scripts (used for integration testing) to cmake. Suppose each of this script to return 0 in case of <strong>PASS</strong> or something != 0 in case of <strong>FAILURE</strong>. I would like each script to be... | 5,666 | 870,914 | 2014-09-02 16:44:31 | 25,628,373 | 13 | 2014-09-02 16:44:31 | 2,898,458 | 2014-09-02 16:44:31 | https://stackoverflow.com/q/25627336 | https://stackoverflow.com/a/25628373 | <p>Basically, you want to start by locating the bash program</p>
<pre><code>find_program (BASH_PROGRAM bash)
</code></pre>
<p>Then just add your script to the list of tests</p>
<pre><code>if (BASH_PROGRAM)
add_test (mytest ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/script.sh)
endif (BASH_PROGRAM)
</code></pre>
<... | <p>Basically, you want to start by locating the bash program</p> <pre><code>find_program (BASH_PROGRAM bash) </code></pre> <p>Then just add your script to the list of tests</p> <pre><code>if (BASH_PROGRAM) add_test (mytest ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/script.sh) endif (BASH_PROGRAM) </code></pre> <... | 10, 387, 8822 | bash, c++, cmake | <h1>Integrate bash test scripts in cmake</h1>
<p>I have a C++ cmake project that uses Boost Test for unit testing. Now I would like to expose a series of bash scripts (used for integration testing) to cmake. Suppose each of this script to return 0 in case of <strong>PASS</strong> or something != 0 in case of <strong>FA... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,343 | bash | # Integrate bash test scripts in cmake
I have a C++ cmake project that uses Boost Test for unit testing. Now I would like to expose a series of bash scripts (used for integration testing) to cmake. Suppose each of this script to return 0 in case of **PASS** or something != 0 in case of **FAILURE**. I would like each s... | Basically, you want to start by locating the bash program
```
find_program (BASH_PROGRAM bash)
```
Then just add your script to the list of tests
```
if (BASH_PROGRAM)
add_test (mytest ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/script.sh)
endif (BASH_PROGRAM)
```
And all of that should work. |
25224994 | How to bash cat or tee into a file, with sudo, with EOF, and with silent output | 9 | 2014-08-10 02:33:09 | <p>I'm basically trying to write a script that sets up a virtual host, and I can't figure out the syntax needed to output a block of code to a root protected file, and then silence the output. I've been trying something like this:</p>
<pre><code>sudo tee /etc/apache2/other/$NAME.conf <<EOF
NameVirtualHost *:80
&... | 11,067 | 945,775 | 2014-08-10 02:56:28 | 25,225,101 | 13 | 2014-08-10 02:56:28 | 3,030,305 | 2014-08-10 02:56:28 | https://stackoverflow.com/q/25224994 | https://stackoverflow.com/a/25225101 | <p>A Here document is different from a do-loop: the redirect should appear on the line with the command:</p>
<pre><code>sudo tee /etc/apache2/other/$NAME.conf &>/dev/null <<EOF
NameVirtualHost *:80
<Virtualhost *:80>
ServerName $NAME.dev
ServerAlias www.$NAME.dev
DocumentRoot... | <p>A Here document is different from a do-loop: the redirect should appear on the line with the command:</p> <pre><code>sudo tee /etc/apache2/other/$NAME.conf &>/dev/null <<EOF NameVirtualHost *:80 <Virtualhost *:80> ServerName $NAME.dev ServerAlias www.$NAME.dev DocumentRoot... | 387 | bash | <h1>How to bash cat or tee into a file, with sudo, with EOF, and with silent output</h1>
<p>I'm basically trying to write a script that sets up a virtual host, and I can't figure out the syntax needed to output a block of code to a root protected file, and then silence the output. I've been trying something like this:<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,344 | bash | # How to bash cat or tee into a file, with sudo, with EOF, and with silent output
I'm basically trying to write a script that sets up a virtual host, and I can't figure out the syntax needed to output a block of code to a root protected file, and then silence the output. I've been trying something like this:
```
sudo... | A Here document is different from a do-loop: the redirect should appear on the line with the command:
```
sudo tee /etc/apache2/other/$NAME.conf &>/dev/null <<EOF
NameVirtualHost *:80
<Virtualhost *:80>
ServerName $NAME.dev
ServerAlias www.$NAME.dev
DocumentRoot /var/www/$NAME
<Directo... |
22406841 | Powershell list the dates between a range of dates. | 9 | 2014-03-14 13:47:49 | <p>I am writing a script in <code>PowerShell</code> and I need to know the dates between a range of dates.</p>
<p>The script is to automate reporting. Let's say there is a bunch of logged data, but the data only gets collected on weekdays, no weekends and no holidays. I FTP and collect the last 15 generations logged.<... | 16,217 | 2,057,853 | 2021-07-07 15:54:31 | 22,407,161 | 13 | 2014-03-14 14:00:57 | 3,168,105 | 2021-07-07 15:54:31 | https://stackoverflow.com/q/22406841 | https://stackoverflow.com/a/22407161 | <p>Maybe something like:</p>
<pre><code>$excelDate = get-date "03/07/2014"
$currentDate = get-date "03/14/2014"
for ( $i = $excelDate.AddDays(1); $i -lt $currentDate; $i=$i.AddDays(1) ) {
$i.ToShortDateString()
}
</code></pre>
| <p>Maybe something like:</p> <pre><code>$excelDate = get-date "03/07/2014" $currentDate = get-date "03/14/2014" for ( $i = $excelDate.AddDays(1); $i -lt $currentDate; $i=$i.AddDays(1) ) { $i.ToShortDateString() } </code></pre> | 522, 526, 5002 | date, excel, powershell | <h1>Powershell list the dates between a range of dates.</h1>
<p>I am writing a script in <code>PowerShell</code> and I need to know the dates between a range of dates.</p>
<p>The script is to automate reporting. Let's say there is a bunch of logged data, but the data only gets collected on weekdays, no weekends and no... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,345 | bash | # Powershell list the dates between a range of dates.
I am writing a script in `PowerShell` and I need to know the dates between a range of dates.
The script is to automate reporting. Let's say there is a bunch of logged data, but the data only gets collected on weekdays, no weekends and no holidays. I FTP and collec... | Maybe something like:
```
$excelDate = get-date "03/07/2014"
$currentDate = get-date "03/14/2014"
for ( $i = $excelDate.AddDays(1); $i -lt $currentDate; $i=$i.AddDays(1) ) {
$i.ToShortDateString()
}
``` |
22052015 | Pipe two different outputs into a command that takes two inputs | 9 | 2014-02-26 20:01:05 | <p>It seems like this should be pretty easy but it's not intuitive to me how to do it. I have two files and I want to diff their first columns (this is an example, I'm sure there are other ways to do this). So I might do <code>cut -d, -f1 file1 > tmp1</code>, <code>cut -d, -f1 file2 > tmp2</code> and then <code... | 2,440 | 1,146,679 | 2014-02-26 20:37:50 | 22,052,066 | 13 | 2014-02-26 20:03:39 | 171,318 | 2014-02-26 20:03:39 | https://stackoverflow.com/q/22052015 | https://stackoverflow.com/a/22052066 | <p>Good news! You can use <a href="http://tldp.org/LDP/abs/html/process-sub.html" rel="noreferrer">process substitution</a> in bash:</p>
<pre><code>diff <(cut -d, -f1 file1) <(cut -d, -f1 file2)
</code></pre>
| <p>Good news! You can use <a href="http://tldp.org/LDP/abs/html/process-sub.html" rel="noreferrer">process substitution</a> in bash:</p> <pre><code>diff <(cut -d, -f1 file1) <(cut -d, -f1 file2) </code></pre> | 34, 387, 390, 5813 | bash, pipe, shell, unix | <h1>Pipe two different outputs into a command that takes two inputs</h1>
<p>It seems like this should be pretty easy but it's not intuitive to me how to do it. I have two files and I want to diff their first columns (this is an example, I'm sure there are other ways to do this). So I might do <code>cut -d, -f1 file1 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,346 | bash | # Pipe two different outputs into a command that takes two inputs
It seems like this should be pretty easy but it's not intuitive to me how to do it. I have two files and I want to diff their first columns (this is an example, I'm sure there are other ways to do this). So I might do `cut -d, -f1 file1 > tmp1`, `cut -d... | Good news! You can use [process substitution](http://tldp.org/LDP/abs/html/process-sub.html) in bash:
```
diff <(cut -d, -f1 file1) <(cut -d, -f1 file2)
``` |
21805166 | Start PowerShell script when USB drive is inserted | 9 | 2014-02-15 23:33:52 | <p>Is there any way the PowerShell script located on a USB drive can be started the moment the drive is inserted in PC? It has to copy all PDF files from PC to the USB drive, but that's not the question. The only thing I don't know is how to start the script as soon as the USB drive is inserted.</p>
<p>Can anyone help... | 30,929 | 3,236,528 | 2014-02-16 02:21:02 | 21,806,420 | 13 | 2014-02-16 02:14:04 | null | 2014-02-16 02:21:02 | https://stackoverflow.com/q/21805166 | https://stackoverflow.com/a/21806420 | <p>You can use Windows Management Instrumentation (WMI) events to detect when a USB flash drive is inserted. You can create a temporary event registration using the <code>Register-WmiEvent</code> cmdlet.</p>
<p>Let's say that you have a script file called <code>c:\test\script.ps1</code>. This script will be used to re... | <p>You can use Windows Management Instrumentation (WMI) events to detect when a USB flash drive is inserted. You can create a temporary event registration using the <code>Register-WmiEvent</code> cmdlet.</p> <p>Let's say that you have a script file called <code>c:\test\script.ps1</code>. This script will be used to re... | 64, 526 | powershell, windows | <h1>Start PowerShell script when USB drive is inserted</h1>
<p>Is there any way the PowerShell script located on a USB drive can be started the moment the drive is inserted in PC? It has to copy all PDF files from PC to the USB drive, but that's not the question. The only thing I don't know is how to start the script a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,347 | bash | # Start PowerShell script when USB drive is inserted
Is there any way the PowerShell script located on a USB drive can be started the moment the drive is inserted in PC? It has to copy all PDF files from PC to the USB drive, but that's not the question. The only thing I don't know is how to start the script as soon as... | You can use Windows Management Instrumentation (WMI) events to detect when a USB flash drive is inserted. You can create a temporary event registration using the `Register-WmiEvent` cmdlet.
Let's say that you have a script file called `c:\test\script.ps1`. This script will be used to respond to events when they occur.... |
18880901 | Nested quotes bash | 9 | 2013-09-18 19:40:17 | <p>I want to nest multiple strings like this : </p>
<pre><code>sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"
</code></pre>
<p>With 2 nested quotes I managed to make my command works : </p>
<pre><code>awk "/pattern/{print \"hello\"}1" file > file.tmp
</code></pre>
<p>I cannot use single quo... | 15,410 | 2,447,053 | 2015-08-21 22:36:43 | 18,880,987 | 13 | 2013-09-18 19:44:16 | 445,221 | 2013-09-18 19:44:16 | https://stackoverflow.com/q/18880901 | https://stackoverflow.com/a/18880987 | <p>You can still place single quotes as long as the variables are intended to be initially expanded before the whole command string is executed on the shell on the remote server.</p>
<pre><code>sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp"
</code></pre>
| <p>You can still place single quotes as long as the variables are intended to be initially expanded before the whole command string is executed on the shell on the remote server.</p> <pre><code>sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp" </code></pre> | 139, 387, 390, 1796, 3610 | bash, command, nested, shell, string | <h1>Nested quotes bash</h1>
<p>I want to nest multiple strings like this : </p>
<pre><code>sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"
</code></pre>
<p>With 2 nested quotes I managed to make my command works : </p>
<pre><code>awk "/pattern/{print \"hello\"}1" file > file.tmp
</code></pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,348 | bash | # Nested quotes bash
I want to nest multiple strings like this :
```
sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"
```
With 2 nested quotes I managed to make my command works :
```
awk "/pattern/{print \"hello\"}1" file > file.tmp
```
I cannot use single quote (') because there are variables in... | You can still place single quotes as long as the variables are intended to be initially expanded before the whole command string is executed on the shell on the remote server.
```
sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp"
``` |
17215004 | Pass gdb variable to a shell command excuted from gdb | 9 | 2013-06-20 13:32:19 | <p>I want to execute a shell command from gdb, this shell command needs an argument, and this argument is a gdb variable. How to make gdb interpret this variable before passing the command and argument to the shell interpreter ?</p>
<p>For example, in a gdb prompt:</p>
<pre><code>(gdb) set $my_arg = 2
(gdb) shell ec... | 4,256 | 1,732,470 | 2013-06-21 06:19:38 | 17,221,805 | 13 | 2013-06-20 19:08:30 | 1,442,050 | 2013-06-20 19:08:30 | https://stackoverflow.com/q/17215004 | https://stackoverflow.com/a/17221805 | <p>With a new version of gdb, you can use "eval":</p>
<pre><code>(gdb) set $val = 2
(gdb) eval "shell echo %d", $val
2
</code></pre>
<p>If you have an older version of gdb, then the best you can do is use "set logging" to write things to a file, then use shell utilities like sed to rewrite the file into the form you ... | <p>With a new version of gdb, you can use "eval":</p> <pre><code>(gdb) set $val = 2 (gdb) eval "shell echo %d", $val 2 </code></pre> <p>If you have an older version of gdb, then the best you can do is use "set logging" to write things to a file, then use shell utilities like sed to rewrite the file into the form you ... | 387, 390, 1962, 42420, 89177 | android-ndk, bash, gdb, ndk-gdb, shell | <h1>Pass gdb variable to a shell command excuted from gdb</h1>
<p>I want to execute a shell command from gdb, this shell command needs an argument, and this argument is a gdb variable. How to make gdb interpret this variable before passing the command and argument to the shell interpreter ?</p>
<p>For example, in a g... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,349 | bash | # Pass gdb variable to a shell command excuted from gdb
I want to execute a shell command from gdb, this shell command needs an argument, and this argument is a gdb variable. How to make gdb interpret this variable before passing the command and argument to the shell interpreter ?
For example, in a gdb prompt:
```
(... | With a new version of gdb, you can use "eval":
```
(gdb) set $val = 2
(gdb) eval "shell echo %d", $val
2
```
If you have an older version of gdb, then the best you can do is use "set logging" to write things to a file, then use shell utilities like sed to rewrite the file into the form you want. |
15432689 | Shell - Suppress output of a single command | 9 | 2013-03-15 12:37:37 | <p>I have a <code>rm *.o</code> command in <code>Makefile</code> to remove all the object files generated during compilation. However some error information will be output if some <code>.o</code> file does not exist. So how can I suppress the error information output?</p>
| 9,372 | 1,553,886 | 2013-03-15 13:44:08 | 15,432,937 | 13 | 2013-03-15 12:48:17 | 459,745 | 2013-03-15 12:48:17 | https://stackoverflow.com/q/15432689 | https://stackoverflow.com/a/15432937 | <p>In the context of <code>make</code>, more importantly than the output, you don't want make to treat the result of <code>rm</code> as failure. There are two ways to deal with it:</p>
<pre><code>clean:
-rm *.o 2> /dev/null
rm -f *.o 2> /dev/null
</code></pre>
<p>The first way is to prefix the comma... | <p>In the context of <code>make</code>, more importantly than the output, you don't want make to treat the result of <code>rm</code> as failure. There are two ways to deal with it:</p> <pre><code>clean: -rm *.o 2> /dev/null rm -f *.o 2> /dev/null </code></pre> <p>The first way is to prefix the comma... | 58, 390, 4301 | linux, makefile, shell | <h1>Shell - Suppress output of a single command</h1>
<p>I have a <code>rm *.o</code> command in <code>Makefile</code> to remove all the object files generated during compilation. However some error information will be output if some <code>.o</code> file does not exist. So how can I suppress the error information output... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,350 | bash | # Shell - Suppress output of a single command
I have a `rm *.o` command in `Makefile` to remove all the object files generated during compilation. However some error information will be output if some `.o` file does not exist. So how can I suppress the error information output? | In the context of `make`, more importantly than the output, you don't want make to treat the result of `rm` as failure. There are two ways to deal with it:
```
clean:
-rm *.o 2> /dev/null
rm -f *.o 2> /dev/null
```
The first way is to prefix the command with a minus sign, which tells `make` to ignore the ... |
15429674 | How to run SVN export without the prompt of username and password | 9 | 2013-03-15 10:15:09 | <p>Is it possible for me to do an SVN export without being prompt for the user and pass?</p>
<p>I give my username and pass, in the command:</p>
<pre><code>svn export --username bavhbavh --password blahblah svn://svn.someSite.com/folder/folder2/exportFile"
</code></pre>
<p>But when running it, it still seems to ask ... | 14,691 | 2,166,351 | 2013-09-20 08:49:28 | 15,429,926 | 13 | 2013-03-15 10:27:25 | 2,165,700 | 2013-03-15 10:27:25 | https://stackoverflow.com/q/15429674 | https://stackoverflow.com/a/15429926 | <p>I do this same thing in one of my build scripts, although I also use this parameter <code>--non-interactive</code> (do no interactive prompting) and it seems to work pretty well.</p>
<p>So your command would look something like this:</p>
<pre><code>svn export --username bavhbavh --password blahblah --non-interacti... | <p>I do this same thing in one of my build scripts, although I also use this parameter <code>--non-interactive</code> (do no interactive prompting) and it seems to work pretty well.</p> <p>So your command would look something like this:</p> <pre><code>svn export --username bavhbavh --password blahblah --non-interacti... | 63, 387, 390, 1796 | bash, command, shell, svn | <h1>How to run SVN export without the prompt of username and password</h1>
<p>Is it possible for me to do an SVN export without being prompt for the user and pass?</p>
<p>I give my username and pass, in the command:</p>
<pre><code>svn export --username bavhbavh --password blahblah svn://svn.someSite.com/folder/folder... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,351 | bash | # How to run SVN export without the prompt of username and password
Is it possible for me to do an SVN export without being prompt for the user and pass?
I give my username and pass, in the command:
```
svn export --username bavhbavh --password blahblah svn://svn.someSite.com/folder/folder2/exportFile"
```
But when... | I do this same thing in one of my build scripts, although I also use this parameter `--non-interactive` (do no interactive prompting) and it seems to work pretty well.
So your command would look something like this:
```
svn export --username bavhbavh --password blahblah --non-interactive svn://svn.someSite.com/folder... |
15418149 | How do I test if a string starts with another in bash? | 9 | 2013-03-14 19:10:00 | <p>Very similar but not duplicate : <a href="https://stackoverflow.com/a/2172367/57883">https://stackoverflow.com/a/2172367/57883</a></p>
<p>I'm in Git Bash 3.1 (at least that's what comes up in the prompt when I type bash inside git bash.</p>
<p>and <code>$ test [["DEV-0" == D*]] || echo 'fail'</code> prints fail.</... | 19,697 | 57,883 | 2013-03-14 20:54:28 | 15,418,206 | 13 | 2013-03-14 19:12:44 | 1,275,169 | 2013-03-14 19:12:44 | https://stackoverflow.com/q/15418149 | https://stackoverflow.com/a/15418206 | <p>You missed a space there:</p>
<pre><code> if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi
^^
</code></pre>
| <p>You missed a space there:</p> <pre><code> if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi ^^ </code></pre> | 387, 61874 | bash, git-bash | <h1>How do I test if a string starts with another in bash?</h1>
<p>Very similar but not duplicate : <a href="https://stackoverflow.com/a/2172367/57883">https://stackoverflow.com/a/2172367/57883</a></p>
<p>I'm in Git Bash 3.1 (at least that's what comes up in the prompt when I type bash inside git bash.</p>
<p>and <co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,352 | bash | # How do I test if a string starts with another in bash?
Very similar but not duplicate : <https://stackoverflow.com/a/2172367/57883>
I'm in Git Bash 3.1 (at least that's what comes up in the prompt when I type bash inside git bash.
and `$ test [["DEV-0" == D*]] || echo 'fail'` prints fail.
`if [['DEV-0-1' == DEV* ... | You missed a space there:
```
if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi
^^
``` |
15073048 | Bash "not": inverting the exit status of a command | 9 | 2013-02-25 17:42:36 | <p>I know I can do this...</p>
<pre><code>if diff -q $f1 $f2
then
echo "they're the same"
else
echo "they're different"
fi
</code></pre>
<p>But what if I want to negate the condition that I'm checking? i.e. something like this (which obviously doesn't work)</p>
<pre><code>if not diff -q $f1 $f2
then
echo... | 9,093 | 262,271 | 2019-12-03 23:39:11 | 15,073,098 | 13 | 2013-02-25 17:45:38 | 140,750 | 2019-12-03 23:39:11 | https://stackoverflow.com/q/15073048 | https://stackoverflow.com/a/15073098 | <pre><code>if ! diff -q "$f1" "$f2"; then ...
</code></pre>
| <pre><code>if ! diff -q "$f1" "$f2"; then ... </code></pre> | 387, 39271 | bash, conditional-statements | <h1>Bash "not": inverting the exit status of a command</h1>
<p>I know I can do this...</p>
<pre><code>if diff -q $f1 $f2
then
echo "they're the same"
else
echo "they're different"
fi
</code></pre>
<p>But what if I want to negate the condition that I'm checking? i.e. something like this (which obviously doesn'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,353 | bash | # Bash "not": inverting the exit status of a command
I know I can do this...
```
if diff -q $f1 $f2
then
echo "they're the same"
else
echo "they're different"
fi
```
But what if I want to negate the condition that I'm checking? i.e. something like this (which obviously doesn't work)
```
if not diff -q $f1 $... | ```
if ! diff -q "$f1" "$f2"; then ...
``` |
14352725 | How do you pipe scripts into NodeJs from command line? | 9 | 2013-01-16 06:45:37 | <p>From command line, I'd like to take a script from my paste board (FYI: pbpaste is an OSX feature) and pipe it into the Node's repl command line tool. For example:</p>
<p><code>
pbpaste | node -e
</code></p>
<p>This does not evaluate the contents in my clipboard. How do I get the runtime to do this?</p>
| 6,297 | 20,176 | 2013-01-16 07:26:15 | 14,353,241 | 13 | 2013-01-16 07:26:15 | 785,065 | 2013-01-16 07:26:15 | https://stackoverflow.com/q/14352725 | https://stackoverflow.com/a/14353241 | <p>The <code>-e</code> option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to <code>node</code> directly.</p>
<pre><code>pbpaste | node
</code></pre>
| <p>The <code>-e</code> option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to <code>node</code> directly.</p> <pre><code>pbpaste | node </code></pre> | 390, 1231, 46426 | command-line, node.js, shell | <h1>How do you pipe scripts into NodeJs from command line?</h1>
<p>From command line, I'd like to take a script from my paste board (FYI: pbpaste is an OSX feature) and pipe it into the Node's repl command line tool. For example:</p>
<p><code>
pbpaste | node -e
</code></p>
<p>This does not evaluate the contents in m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,354 | bash | # How do you pipe scripts into NodeJs from command line?
From command line, I'd like to take a script from my paste board (FYI: pbpaste is an OSX feature) and pipe it into the Node's repl command line tool. For example:
`pbpaste | node -e`
This does not evaluate the contents in my clipboard. How do I get the runtime... | The `-e` option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to `node` directly.
```
pbpaste | node
``` |
13738087 | How can I remove all imported modules in PowerShell? | 9 | 2012-12-06 06:26:34 | <p>I wan to remove all imported modules before importing them so that I can get the fresh ones by overwriting the ones in the memory.</p>
<p>How can I remove all imported modules in PowerShell?</p>
<p>Thanks</p>
| 15,333 | 136,141 | 2012-12-06 06:39:39 | 13,738,124 | 13 | 2012-12-06 06:29:44 | 520,612 | 2012-12-06 06:39:39 | https://stackoverflow.com/q/13738087 | https://stackoverflow.com/a/13738124 | <p>this should do it:</p>
<pre><code>get-module | Remove-Module
</code></pre>
<p>this remove also imported modules in <code>$profile</code>.</p>
<p><a href="http://technet.microsoft.com/en-us/magazine/ff642467.aspx">More about this</a></p>
| <p>this should do it:</p> <pre><code>get-module | Remove-Module </code></pre> <p>this remove also imported modules in <code>$profile</code>.</p> <p><a href="http://technet.microsoft.com/en-us/magazine/ff642467.aspx">More about this</a></p> | 1, 526, 3849 | .net, module, powershell | <h1>How can I remove all imported modules in PowerShell?</h1>
<p>I wan to remove all imported modules before importing them so that I can get the fresh ones by overwriting the ones in the memory.</p>
<p>How can I remove all imported modules in PowerShell?</p>
<p>Thanks</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,355 | bash | # How can I remove all imported modules in PowerShell?
I wan to remove all imported modules before importing them so that I can get the fresh ones by overwriting the ones in the memory.
How can I remove all imported modules in PowerShell?
Thanks | this should do it:
```
get-module | Remove-Module
```
this remove also imported modules in `$profile`.
[More about this](http://technet.microsoft.com/en-us/magazine/ff642467.aspx) |
13206311 | Bash - function with optional arguments and missing logic | 9 | 2012-11-03 05:32:59 | <p>I'm trying make simple function for the useradd command and to quickly improve my poor shell programming skills.</p>
<pre><code>useradd -m -g [initial_group] -G [additional_groups] -s [login_shell] [username]
</code></pre>
<p>Right now I'm somewhat unsure how to function with optional arguments. After some Googli... | 15,764 | 1,587,716 | 2014-05-10 16:18:05 | 13,211,621 | 13 | 2012-11-03 17:24:48 | 89,817 | 2012-11-04 02:45:14 | https://stackoverflow.com/q/13206311 | https://stackoverflow.com/a/13211621 | <p>@rob mayoff's answer is the simplest way to accomplish this, but I thought I'd take a stab at turning your pseudo code into real shell syntax to point out some standard gotchas for people used to "real" programming languages. Three general notes first:</p>
<ul>
<li>Different shells have different capabilities, so u... | <p>@rob mayoff's answer is the simplest way to accomplish this, but I thought I'd take a stab at turning your pseudo code into real shell syntax to point out some standard gotchas for people used to "real" programming languages. Three general notes first:</p> <ul> <li>Different shells have different capabilities, so u... | 387 | bash | <h1>Bash - function with optional arguments and missing logic</h1>
<p>I'm trying make simple function for the useradd command and to quickly improve my poor shell programming skills.</p>
<pre><code>useradd -m -g [initial_group] -G [additional_groups] -s [login_shell] [username]
</code></pre>
<p>Right now I'm somewhat... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,356 | bash | # Bash - function with optional arguments and missing logic
I'm trying make simple function for the useradd command and to quickly improve my poor shell programming skills.
```
useradd -m -g [initial_group] -G [additional_groups] -s [login_shell] [username]
```
Right now I'm somewhat unsure how to function with opti... | @rob mayoff's answer is the simplest way to accomplish this, but I thought I'd take a stab at turning your pseudo code into real shell syntax to point out some standard gotchas for people used to "real" programming languages. Three general notes first:
- Different shells have different capabilities, so use bash (i.e. ... |
13052028 | Interacting with a .db file from Linux shell | 9 | 2012-10-24 15:07:12 | <p>I recently installed minidlna, a lightweight UPnP server, on my Raspberry Pi. Since this lacks the web interface of other programs such as Mediatomb, I thought it could be an interesting project for me to write one.</p>
<p>I believe minidlna stores library information in a single file named "files.db".</p>... | 86,151 | 1,040,915 | 2025-07-29 12:45:03 | 13,053,474 | 13 | 2012-10-24 16:27:42 | 1,014,586 | 2012-10-24 16:27:42 | https://stackoverflow.com/q/13052028 | https://stackoverflow.com/a/13053474 | <p>You will have to install a package named 'sqlite' or 'sqlite3'.</p>
<p>Then you will be able to interact with your .db file using</p>
<pre><code>$ sqlite3 files.db
> SELECT blah FROM your_table WHERE ......
</code></pre>
<p>In your post you mention 'SQLite3', the package name should have no caps letters.</p>
... | <p>You will have to install a package named 'sqlite' or 'sqlite3'.</p> <p>Then you will be able to interact with your .db file using</p> <pre><code>$ sqlite3 files.db > SELECT blah FROM your_table WHERE ...... </code></pre> <p>In your post you mention 'SQLite3', the package name should have no caps letters.</p> ... | 30, 58, 390, 77858 | database, linux, raspberry-pi, shell | <h1>Interacting with a .db file from Linux shell</h1>
<p>I recently installed minidlna, a lightweight UPnP server, on my Raspberry Pi. Since this lacks the web interface of other programs such as Mediatomb, I thought it could be an interesting project for me to write one.</p>
<p>I believe minidlna stores library inform... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,357 | bash | # Interacting with a .db file from Linux shell
I recently installed minidlna, a lightweight UPnP server, on my Raspberry Pi. Since this lacks the web interface of other programs such as Mediatomb, I thought it could be an interesting project for me to write one.
I believe minidlna stores library information in a sing... | You will have to install a package named 'sqlite' or 'sqlite3'.
Then you will be able to interact with your .db file using
```
$ sqlite3 files.db
> SELECT blah FROM your_table WHERE ......
```
In your post you mention 'SQLite3', the package name should have no caps letters.
Did you run an `apt-cache search sqlite` ... |
11771605 | How to ensure that we are using powershell 2.0? | 9 | 2012-08-02 05:37:23 | <p>We are providing scripts to clients that will be working only in Powershell 2.0.</p>
<p>Through command we can ensure that powershell 2.0 is installed like below</p>
<pre><code>$version = Get-host | Select-object Version
</code></pre>
<p>But if we provide script how to ensure that they are executing it from Power... | 2,530 | 399,145 | 2012-08-02 12:23:11 | 11,772,011 | 13 | 2012-08-02 06:17:43 | 73,070 | 2012-08-02 07:17:43 | https://stackoverflow.com/q/11771605 | https://stackoverflow.com/a/11772011 | <p>You can annotate your script with <a href="http://technet.microsoft.com/en-us/library/hh847765"><code>#requires</code></a> and state that it shouldn't run on anything less than PowerShell v2:</p>
<pre><code>#requires -Version 2.0
</code></pre>
<p><sub>(Side note: This is surprisingly hard to find even if you know ... | <p>You can annotate your script with <a href="http://technet.microsoft.com/en-us/library/hh847765"><code>#requires</code></a> and state that it shouldn't run on anything less than PowerShell v2:</p> <pre><code>#requires -Version 2.0 </code></pre> <p><sub>(Side note: This is surprisingly hard to find even if you know ... | 526, 24067 | powershell, powershell-2.0 | <h1>How to ensure that we are using powershell 2.0?</h1>
<p>We are providing scripts to clients that will be working only in Powershell 2.0.</p>
<p>Through command we can ensure that powershell 2.0 is installed like below</p>
<pre><code>$version = Get-host | Select-object Version
</code></pre>
<p>But if we provide s... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,358 | bash | # How to ensure that we are using powershell 2.0?
We are providing scripts to clients that will be working only in Powershell 2.0.
Through command we can ensure that powershell 2.0 is installed like below
```
$version = Get-host | Select-object Version
```
But if we provide script how to ensure that they are execut... | You can annotate your script with [`#requires`](http://technet.microsoft.com/en-us/library/hh847765) and state that it shouldn't run on anything less than PowerShell v2:
```
#requires -Version 2.0
```
(Side note: This is surprisingly hard to find even if you know vaguely that it exists.) |
11418502 | Bash string to array with IFS | 9 | 2012-07-10 17:17:39 | <p>I'm having trouble using the IFS to convert my string into an array. Here is what I have as my string: </p>
<pre><code>"Jun01 Jun02 Jun03 Jun04 Jun05 ..." #in that format, separated by spaces
</code></pre>
<p>And here is the code I have tried: </p>
<pre><code>IFS=" " #set it to space character
DATES_ARRAY=($DATES... | 50,590 | 624,869 | 2013-05-09 18:19:56 | 11,418,930 | 13 | 2012-07-10 17:44:22 | 495,451 | 2012-07-10 17:44:22 | https://stackoverflow.com/q/11418502 | https://stackoverflow.com/a/11418930 | <p>It does work, but it's unnecessary anyway because space is guaranteed to be in IFS by default. Don't set it manually. Doing so can cause problems.</p>
<p>Basically, never use word-splitting in Bash. Sometimes it's required to bite the bullet and use it if restricted to POSIX sh, if used very carefully. If you're go... | <p>It does work, but it's unnecessary anyway because space is guaranteed to be in IFS by default. Don't set it manually. Doing so can cause problems.</p> <p>Basically, never use word-splitting in Bash. Sometimes it's required to bite the bullet and use it if restricted to POSIX sh, if used very carefully. If you're go... | 114, 139, 387, 531 | arrays, bash, scripting, string | <h1>Bash string to array with IFS</h1>
<p>I'm having trouble using the IFS to convert my string into an array. Here is what I have as my string: </p>
<pre><code>"Jun01 Jun02 Jun03 Jun04 Jun05 ..." #in that format, separated by spaces
</code></pre>
<p>And here is the code I have tried: </p>
<pre><code>IFS=" " #set it... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,359 | bash | # Bash string to array with IFS
I'm having trouble using the IFS to convert my string into an array. Here is what I have as my string:
```
"Jun01 Jun02 Jun03 Jun04 Jun05 ..." #in that format, separated by spaces
```
And here is the code I have tried:
```
IFS=" " #set it to space character
DATES_ARRAY=($DATES_STRING... | It does work, but it's unnecessary anyway because space is guaranteed to be in IFS by default. Don't set it manually. Doing so can cause problems.
Basically, never use word-splitting in Bash. Sometimes it's required to bite the bullet and use it if restricted to POSIX sh, if used very carefully. If you're going to set... |
11020223 | Plotting and saving R graph | 9 | 2012-06-13 17:29:20 | <p>I have a bash script that tracks memory usage over time as a command is run. It spawns the desired command and then writes a log with column1 = "memory in use by program (gigs)" and column 2 is the time elapsed so far in seconds. e.g.</p>
<pre><code>31.282 1470
31.565 1480
31.848 1490
31.989 1500
32.273 1510
32.414... | 12,892 | 1,283,949 | 2012-06-18 16:15:59 | 11,020,286 | 13 | 2012-06-13 17:33:29 | 429,846 | 2012-06-13 17:45:01 | https://stackoverflow.com/q/11020223 | https://stackoverflow.com/a/11020286 | <p>Wrap your plot calls in:</p>
<pre><code>jpeg("myplot.jpg")
....plot code here....
dev.off()
</code></pre>
<p>or </p>
<pre><code>png("myplot.png")
....plot code here....
dev.off()
</code></pre>
<p>See their respective help pages: <code>?png</code> for details of other arguments.</p>
<p>For a PNG this would be:</... | <p>Wrap your plot calls in:</p> <pre><code>jpeg("myplot.jpg") ....plot code here.... dev.off() </code></pre> <p>or </p> <pre><code>png("myplot.png") ....plot code here.... dev.off() </code></pre> <p>See their respective help pages: <code>?png</code> for details of other arguments.</p> <p>For a PNG this would be:</... | 387, 4452 | bash, r | <h1>Plotting and saving R graph</h1>
<p>I have a bash script that tracks memory usage over time as a command is run. It spawns the desired command and then writes a log with column1 = "memory in use by program (gigs)" and column 2 is the time elapsed so far in seconds. e.g.</p>
<pre><code>31.282 1470
31.565 1480
31.84... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,360 | bash | # Plotting and saving R graph
I have a bash script that tracks memory usage over time as a command is run. It spawns the desired command and then writes a log with column1 = "memory in use by program (gigs)" and column 2 is the time elapsed so far in seconds. e.g.
```
31.282 1470
31.565 1480
31.848 1490
31.989 1500
3... | Wrap your plot calls in:
```
jpeg("myplot.jpg")
....plot code here....
dev.off()
```
or
```
png("myplot.png")
....plot code here....
dev.off()
```
See their respective help pages: `?png` for details of other arguments.
For a PNG this would be:
```
png("my_plot.png", height = 800, width = 600)
plot(heisenberg$V2,h... |
10618676 | PowerShell - Why "Divide By Zero Exception" is not being Caught? | 9 | 2012-05-16 12:36:09 | <p>On my Machine each one of the following code snippets throws and exception instead of printing to the standard output "1" and "2"
Why the exception is not being Caught?</p>
<pre><code>try {
[int]$a = 1/0
}
catch {
write 1
}
finally {
write 2
}
try {
[int]$a = 1/0
}
catch [System.Exception] {
wr... | 6,098 | 625,265 | 2018-03-10 01:19:51 | 10,618,907 | 13 | 2012-05-16 12:48:41 | 52,598 | 2012-05-16 12:56:32 | https://stackoverflow.com/q/10618676 | https://stackoverflow.com/a/10618907 | <p>As you are using constants, <strong>the interpreter tries to precompute the result</strong> and fails with a division by zero error. Your code does not even get executed so there's nothing to trap.</p>
<p>You can verify this for yourself by changing your code to use variables, forcing it to be executed.</p>
<pre><... | <p>As you are using constants, <strong>the interpreter tries to precompute the result</strong> and fails with a division by zero error. Your code does not even get executed so there's nothing to trap.</p> <p>You can verify this for yourself by changing your code to use variables, forcing it to be executed.</p> <pre><... | 1, 526, 5142, 21488, 24067 | .net, divide-by-zero, exception, powershell, powershell-2.0 | <h1>PowerShell - Why "Divide By Zero Exception" is not being Caught?</h1>
<p>On my Machine each one of the following code snippets throws and exception instead of printing to the standard output "1" and "2"
Why the exception is not being Caught?</p>
<pre><code>try {
[int]$a = 1/0
}
catch {
write 1
}
finally {
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,361 | bash | # PowerShell - Why "Divide By Zero Exception" is not being Caught?
On my Machine each one of the following code snippets throws and exception instead of printing to the standard output "1" and "2"
Why the exception is not being Caught?
```
try {
[int]$a = 1/0
}
catch {
write 1
}
finally {
write 2
}
try {... | As you are using constants, **the interpreter tries to precompute the result** and fails with a division by zero error. Your code does not even get executed so there's nothing to trap.
You can verify this for yourself by changing your code to use variables, forcing it to be executed.
```
try {
$divisor = 0
[i... |
9362788 | Script organization (all my functions are cluttering my script) | 9 | 2012-02-20 14:32:49 | <p>I have a large script which I'm now cleaning up with the use of functions.
But, I've found that it gets kinda messy to put them all at the top of the script.. I have to scroll past hundreds of lines of codes to get to the script itself..</p>
<p>How do you guys keep your scripts tidy? Do you have your functions in a... | 15,868 | 1,114,155 | 2018-12-04 17:01:02 | 9,363,000 | 13 | 2012-02-20 14:46:21 | 251,123 | 2016-06-17 12:22:55 | https://stackoverflow.com/q/9362788 | https://stackoverflow.com/a/9363000 | <h1>Try #Region and #EndRegion</h1>
<p>If you use <a href="http://en.community.dell.com/techcenter/powergui/" rel="nofollow noreferrer">PowerGUI</a> script editor you can use regions like this:</p>
<pre><code>#region Set of functions A
function foo {
Write-Host "Just a function"
}
function bar {
ret... | <h1>Try #Region and #EndRegion</h1> <p>If you use <a href="http://en.community.dell.com/techcenter/powergui/" rel="nofollow noreferrer">PowerGUI</a> script editor you can use regions like this:</p> <pre><code>#region Set of functions A function foo { Write-Host "Just a function" } function bar { ret... | 526, 5569 | function, powershell | <h1>Script organization (all my functions are cluttering my script)</h1>
<p>I have a large script which I'm now cleaning up with the use of functions.
But, I've found that it gets kinda messy to put them all at the top of the script.. I have to scroll past hundreds of lines of codes to get to the script itself..</p>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,362 | bash | # Script organization (all my functions are cluttering my script)
I have a large script which I'm now cleaning up with the use of functions.
But, I've found that it gets kinda messy to put them all at the top of the script.. I have to scroll past hundreds of lines of codes to get to the script itself..
How do you guy... | # Try #Region and #EndRegion
If you use [PowerGUI](http://en.community.dell.com/techcenter/powergui/) script editor you can use regions like this:
```
#region Set of functions A
function foo {
Write-Host "Just a function"
}
function bar {
return "Just another function"
}
#endregion
```
When you open the s... |
9083467 | Writing a shell script to install cron job | 9 | 2012-01-31 16:49:54 | <p>This is the first time i am writing a shell script and i have very little information in the given timeline. Though i am reading through different tutorials but i thought to ask what i want here as well.</p>
<p>I want to write a shell script, which on any machine, edit the cronjob, add a new script to be executed a... | 18,331 | 504,717 | 2018-09-23 20:43:00 | 9,084,788 | 13 | 2012-01-31 18:19:28 | 15,168 | 2012-01-31 19:48:23 | https://stackoverflow.com/q/9083467 | https://stackoverflow.com/a/9084788 | <h3>Simple Answer to Original Question</h3>
<p>It all seems like routine shell scripting:</p>
<pre><code># Clobber previous edition of script!
cronscript=$HOME/scripts/cronSqlprocedure.sh
cat <<EOF > $cronscript
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1
export PATH=\$ORACLE_HOME/bin:\$PATH
e... | <h3>Simple Answer to Original Question</h3> <p>It all seems like routine shell scripting:</p> <pre><code># Clobber previous edition of script! cronscript=$HOME/scripts/cronSqlprocedure.sh cat <<EOF > $cronscript export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1 export PATH=\$ORACLE_HOME/bin:\$PATH e... | 58, 387, 390, 601 | bash, cron, linux, shell | <h1>Writing a shell script to install cron job</h1>
<p>This is the first time i am writing a shell script and i have very little information in the given timeline. Though i am reading through different tutorials but i thought to ask what i want here as well.</p>
<p>I want to write a shell script, which on any machine,... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,363 | bash | # Writing a shell script to install cron job
This is the first time i am writing a shell script and i have very little information in the given timeline. Though i am reading through different tutorials but i thought to ask what i want here as well.
I want to write a shell script, which on any machine, edit the cronjo... | ### Simple Answer to Original Question
It all seems like routine shell scripting:
```
# Clobber previous edition of script!
cronscript=$HOME/scripts/cronSqlprocedure.sh
cat <<EOF > $cronscript
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1
export PATH=\$ORACLE_HOME/bin:\$PATH
export ORACLE_SID=HEER
...and... |
9041656 | Difference between Bash shell and Bash terminal? | 9 | 2012-01-27 23:56:10 | <p>Ok, I hope this question makes some sense but what is the difference between a bash shell and a bash terminal? Example. When I first open up terminal I have a prompt with my current dir and my user name. In the terminal window header it says -bash- , when I type echo $SHELL I get bash. So by default the shell is bas... | 7,216 | 823,119 | 2012-01-27 23:59:32 | 9,041,684 | 13 | 2012-01-27 23:59:32 | 207,248 | 2012-01-27 23:59:32 | https://stackoverflow.com/q/9041656 | https://stackoverflow.com/a/9041684 | <p>There is no difference, they are both instances of the <code>bash</code> shell.</p>
<p>The reason you are seeing a different prompt is that your initial login shell sources <code>~/.bash_profile</code> where presumably you have your prompt set. When you type <code>bash</code> it invokes another shell but because t... | <p>There is no difference, they are both instances of the <code>bash</code> shell.</p> <p>The reason you are seeing a different prompt is that your initial login shell sources <code>~/.bash_profile</code> where presumably you have your prompt set. When you type <code>bash</code> it invokes another shell but because t... | 387, 391 | bash, terminal | <h1>Difference between Bash shell and Bash terminal?</h1>
<p>Ok, I hope this question makes some sense but what is the difference between a bash shell and a bash terminal? Example. When I first open up terminal I have a prompt with my current dir and my user name. In the terminal window header it says -bash- , when I t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,364 | bash | # Difference between Bash shell and Bash terminal?
Ok, I hope this question makes some sense but what is the difference between a bash shell and a bash terminal? Example. When I first open up terminal I have a prompt with my current dir and my user name. In the terminal window header it says -bash- , when I type echo ... | There is no difference, they are both instances of the `bash` shell.
The reason you are seeing a different prompt is that your initial login shell sources `~/.bash_profile` where presumably you have your prompt set. When you type `bash` it invokes another shell but because this one isn't a login shell, it *doesn't* so... |
8759285 | Alternatives to xargs -l | 9 | 2012-01-06 14:25:02 | <p>I want to rename a bunch of dirs from DIR to DIR.OLD. Ideally I would use the following:</p>
<pre><code>find . -maxdepth 1 -type d -name \"*.y\" -mtime +`expr 2 \* 365` -print0 | xargs -0 -r -I file mv file file.old
</code></pre>
<p>But the machine I want to execute this on has BusyBox installed and the BusyBox xa... | 17,320 | 597,864 | 2015-12-18 15:32:06 | 8,759,498 | 13 | 2012-01-06 14:40:37 | 566,344 | 2015-12-18 15:32:06 | https://stackoverflow.com/q/8759285 | https://stackoverflow.com/a/8759498 | <p>You can use <code>-exec</code> and <code>{}</code> features of the <code>find</code> command so you don't need any pipes at all:</p>
<pre><code>find -maxdepth 1 -type d -name "*.y" -mtime +`expr 2 \* 365` -exec mv "{}" "{}.old" \;
</code></pre>
<p>Also you don't need to specify '.' path - this is default for <code... | <p>You can use <code>-exec</code> and <code>{}</code> features of the <code>find</code> command so you don't need any pipes at all:</p> <pre><code>find -maxdepth 1 -type d -name "*.y" -mtime +`expr 2 \* 365` -exec mv "{}" "{}.old" \; </code></pre> <p>Also you don't need to specify '.' path - this is default for <code... | 387, 390, 10193, 10326, 41655 | bash, busybox, find, shell, xargs | <h1>Alternatives to xargs -l</h1>
<p>I want to rename a bunch of dirs from DIR to DIR.OLD. Ideally I would use the following:</p>
<pre><code>find . -maxdepth 1 -type d -name \"*.y\" -mtime +`expr 2 \* 365` -print0 | xargs -0 -r -I file mv file file.old
</code></pre>
<p>But the machine I want to execute this on has Bu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,365 | bash | # Alternatives to xargs -l
I want to rename a bunch of dirs from DIR to DIR.OLD. Ideally I would use the following:
```
find . -maxdepth 1 -type d -name \"*.y\" -mtime +`expr 2 \* 365` -print0 | xargs -0 -r -I file mv file file.old
```
But the machine I want to execute this on has BusyBox installed and the BusyBox x... | You can use `-exec` and `{}` features of the `find` command so you don't need any pipes at all:
```
find -maxdepth 1 -type d -name "*.y" -mtime +`expr 2 \* 365` -exec mv "{}" "{}.old" \;
```
Also you don't need to specify '.' path - this is default for `find`. And you used extra slashes in `"*.y"`. Of course if your ... |
7415235 | bash: debug option and functions | 9 | 2011-09-14 11:00:03 | <p>If I run </p>
<pre><code>bash -x myscript.sh
</code></pre>
<p>I'll get debugging output.</p>
<p>But if I have a function in <code>myscript.sh</code>, the code in the function is immune to -x option. It writes to output only the name of the function.</p>
<p>How to obtain debugging output for functions in bash scr... | 11,203 | 319,875 | 2018-10-28 01:47:14 | 7,416,255 | 13 | 2011-09-14 12:23:19 | 716,256 | 2011-09-14 12:23:19 | https://stackoverflow.com/q/7415235 | https://stackoverflow.com/a/7416255 | <p>With bash, you can use <code>functrace</code> option in your script</p>
<pre><code>set -o functrace
</code></pre>
<p>See manpage for <code>bash</code> for other debugger options.</p>
| <p>With bash, you can use <code>functrace</code> option in your script</p> <pre><code>set -o functrace </code></pre> <p>See manpage for <code>bash</code> for other debugger options.</p> | 34, 277, 387, 1964, 5569 | bash, debugging, function, ksh, unix | <h1>bash: debug option and functions</h1>
<p>If I run </p>
<pre><code>bash -x myscript.sh
</code></pre>
<p>I'll get debugging output.</p>
<p>But if I have a function in <code>myscript.sh</code>, the code in the function is immune to -x option. It writes to output only the name of the function.</p>
<p>How to obtain ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,366 | bash | # bash: debug option and functions
If I run
```
bash -x myscript.sh
```
I'll get debugging output.
But if I have a function in `myscript.sh`, the code in the function is immune to -x option. It writes to output only the name of the function.
How to obtain debugging output for functions in bash scripts?
**Update:*... | With bash, you can use `functrace` option in your script
```
set -o functrace
```
See manpage for `bash` for other debugger options. |
7036352 | What's wrong with the following GNU make shell variable expansion? | 9 | 2011-08-12 06:24:35 | <p>On this line:</p>
<pre><code>GCCVER:=$(shell a=`mktemp` && echo $'#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$a" -xc -; "$a"; rm "$a")
</code></pre>
<p>I get:</p>
<pre><code>*** unterminated call to function `shell': missing `)'. Stop.
</code></pre>
<p>Wh... | 5,667 | 149,482 | 2011-08-13 12:46:28 | 7,036,426 | 13 | 2011-08-12 06:33:36 | 493,161 | 2011-08-13 12:46:28 | https://stackoverflow.com/q/7036352 | https://stackoverflow.com/a/7036426 | <p>when using <code>$</code> for Bash inside a Makefile, you need to double them: <code>$$a</code> for example. I'm not familiar with the notation <code>$'</code> but I'll have to assume you know what you're doing with that. unless it's a Makefile construct, you need to double the dollar sign on that one too.</p>
<p>a... | <p>when using <code>$</code> for Bash inside a Makefile, you need to double them: <code>$$a</code> for example. I'm not familiar with the notation <code>$'</code> but I'll have to assume you know what you're doing with that. unless it's a Makefile construct, you need to double the dollar sign on that one too.</p> <p>a... | 390, 1477, 4301, 13213, 19749 | gcc, gnu-make, makefile, shell, variable-expansion | <h1>What's wrong with the following GNU make shell variable expansion?</h1>
<p>On this line:</p>
<pre><code>GCCVER:=$(shell a=`mktemp` && echo $'#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$a" -xc -; "$a"; rm "$a")
</code></pre>
<p>I get:</p>
<pre><code>*** unt... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,367 | bash | # What's wrong with the following GNU make shell variable expansion?
On this line:
```
GCCVER:=$(shell a=`mktemp` && echo $'#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$a" -xc -; "$a"; rm "$a")
```
I get:
```
*** unterminated call to function `shell': missing `)'. Stop.
``... | when using `$` for Bash inside a Makefile, you need to double them: `$$a` for example. I'm not familiar with the notation `$'` but I'll have to assume you know what you're doing with that. unless it's a Makefile construct, you need to double the dollar sign on that one too.
also, the hash sign `#` is terminating the s... |
6758897 | How to set up an automatic (re)start of a background ssh tunnel | 9 | 2011-07-20 08:13:21 | <p>I am a beginner user of linux, and also quite newbie at ssh and tunnels.</p>
<p>Anyway, my goal is to maintain a ssh tunnel open in background. </p>
<p>In order to do that, I wrote the following batch that I then added into crontab (the batch is automatically processed every 5 minutes during workdays and from 8am ... | 22,130 | 498,190 | 2025-12-04 14:45:10 | 6,767,800 | 13 | 2011-07-20 20:04:01 | 831,145 | 2011-07-20 20:04:01 | https://stackoverflow.com/q/6758897 | https://stackoverflow.com/a/6767800 | <p>Instead of checking the <code>ssh</code> process with <code>ps</code> you can do the following trick</p>
<p>create script, that does the following and add it to your crontab via <code>crontab -e</code></p>
<pre><code>#!/bin/sh
REMOTEUSER=username
REMOTEHOST=remotehost
SSH_REMOTEPORT=22
SSH_LOCALPORT=10022
TUNN... | <p>Instead of checking the <code>ssh</code> process with <code>ps</code> you can do the following trick</p> <p>create script, that does the following and add it to your crontab via <code>crontab -e</code></p> <pre><code>#!/bin/sh REMOTEUSER=username REMOTEHOST=remotehost SSH_REMOTEPORT=22 SSH_LOCALPORT=10022 TUNN... | 58, 386, 387 | bash, linux, ssh | <h1>How to set up an automatic (re)start of a background ssh tunnel</h1>
<p>I am a beginner user of linux, and also quite newbie at ssh and tunnels.</p>
<p>Anyway, my goal is to maintain a ssh tunnel open in background. </p>
<p>In order to do that, I wrote the following batch that I then added into crontab (the batch... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,368 | bash | # How to set up an automatic (re)start of a background ssh tunnel
I am a beginner user of linux, and also quite newbie at ssh and tunnels.
Anyway, my goal is to maintain a ssh tunnel open in background.
In order to do that, I wrote the following batch that I then added into crontab (the batch is automatically proces... | Instead of checking the `ssh` process with `ps` you can do the following trick
create script, that does the following and add it to your crontab via `crontab -e`
```
#!/bin/sh
REMOTEUSER=username
REMOTEHOST=remotehost
SSH_REMOTEPORT=22
SSH_LOCALPORT=10022
TUNNEL_REMOTEPORT=8080
TUNNEL_LOCALPORT=8080
createTunnel... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.