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
33732061
Why docker exec is killing nohup process on exit?
13
2015-11-16 09:29:55
<p>I have running docker ubuntu container with just a bash script inside. I want to start my application inside that container with docker exec like that:</p> <pre><code>docker exec -it 0b3fc9dd35f2 ./main.sh </code></pre> <p>Inside main script I want to run another application with nohup as this is a long running ap...
23,325
4,193,748
2017-09-01 06:58:45
34,518,145
15
2015-12-29 19:57:49
3,746,786
2015-12-29 19:57:49
https://stackoverflow.com/q/33732061
https://stackoverflow.com/a/34518145
<p>This is not an answer, but I still don't have the required reputation to comment.</p> <p>I don't know why the nohup doesn't work. But I did a workaround that worked, using your ideas:</p> <pre><code>docker exec -ti running_container bash -c 'nohup ./main.sh &amp;&gt; output &amp; sleep 1' </code></pre>
<p>This is not an answer, but I still don't have the required reputation to comment.</p> <p>I don't know why the nohup doesn't work. But I did a workaround that worked, using your ideas:</p> <pre><code>docker exec -ti running_container bash -c 'nohup ./main.sh &amp;&gt; output &amp; sleep 1' </code></pre>
387, 18966, 90304
bash, docker, nohup
<h1>Why docker exec is killing nohup process on exit?</h1> <p>I have running docker ubuntu container with just a bash script inside. I want to start my application inside that container with docker exec like that:</p> <pre><code>docker exec -it 0b3fc9dd35f2 ./main.sh </code></pre> <p>Inside main script I want to run ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,162
bash
# Why docker exec is killing nohup process on exit? I have running docker ubuntu container with just a bash script inside. I want to start my application inside that container with docker exec like that: ``` docker exec -it 0b3fc9dd35f2 ./main.sh ``` Inside main script I want to run another application with nohup as...
This is not an answer, but I still don't have the required reputation to comment. I don't know why the nohup doesn't work. But I did a workaround that worked, using your ideas: ``` docker exec -ti running_container bash -c 'nohup ./main.sh &> output & sleep 1' ```
33255834
Powershell - Rename filename by removing the last few characters
13
2015-10-21 09:40:54
<p>I want to remove the last 11 characters of multiple files names. For example I have these file names:</p> <pre><code>ABCDE_2015_10_20 HIJKL_2015_10_20 MNOPQ_2015_10_20 RSTUV_2015_10_20 </code></pre> <p>would like to rename them to </p> <pre><code>ABCDE HIJKL MNOPQ RSTUV </code></pre> <p>I have tried using the fo...
55,393
4,324,265
2019-02-21 11:58:54
33,256,114
15
2015-10-21 09:52:38
3,115,685
2015-10-21 09:57:50
https://stackoverflow.com/q/33255834
https://stackoverflow.com/a/33256114
<p>You're almost there, you just need to tell <code>substring</code> exactly where to start and end:</p> <pre><code>Get-ChildItem 'E:\Thomson Reuters\Stage' | rename-item -newname { $_.name.substring(0,$_.name.length-11) } </code></pre> <p>By passing two integers to <code>substring</code> you give it the StartIndex ...
<p>You're almost there, you just need to tell <code>substring</code> exactly where to start and end:</p> <pre><code>Get-ChildItem 'E:\Thomson Reuters\Stage' | rename-item -newname { $_.name.substring(0,$_.name.length-11) } </code></pre> <p>By passing two integers to <code>substring</code> you give it the StartIndex ...
526
powershell
<h1>Powershell - Rename filename by removing the last few characters</h1> <p>I want to remove the last 11 characters of multiple files names. For example I have these file names:</p> <pre><code>ABCDE_2015_10_20 HIJKL_2015_10_20 MNOPQ_2015_10_20 RSTUV_2015_10_20 </code></pre> <p>would like to rename them to </p> <pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,163
bash
# Powershell - Rename filename by removing the last few characters I want to remove the last 11 characters of multiple files names. For example I have these file names: ``` ABCDE_2015_10_20 HIJKL_2015_10_20 MNOPQ_2015_10_20 RSTUV_2015_10_20 ``` would like to rename them to ``` ABCDE HIJKL MNOPQ RSTUV ``` I have tr...
You're almost there, you just need to tell `substring` exactly where to start and end: ``` Get-ChildItem 'E:\Thomson Reuters\Stage' | rename-item -newname { $_.name.substring(0,$_.name.length-11) } ``` By passing two integers to `substring` you give it the StartIndex and Length of the string you want to capture. [See...
29753126
Create environment variable with dot in the current environment
13
2015-04-20 16:17:23
<p>I know that you can create environment variables with the command <code>env</code>.</p> <p>For example:</p> <pre><code>env A.B=D bash </code></pre> <p>The problem is for env a command is required thus creating a new subprocess.</p>
20,274
371,342
2017-03-05 04:28:54
29,753,290
15
2015-04-20 16:25:54
1,566,221
2015-04-20 16:25:54
https://stackoverflow.com/q/29753126
https://stackoverflow.com/a/29753290
<p>Bash does not allow environment variables with non-alphanumeric characters in their names (aside from <kbd>_</kbd>). While the environment may contain a line such as <code>A.B=D</code>, there is no requirement that a shell be able to make use of it, and bash will not. Other shells may be more flexible.</p> <p>Utili...
<p>Bash does not allow environment variables with non-alphanumeric characters in their names (aside from <kbd>_</kbd>). While the environment may contain a line such as <code>A.B=D</code>, there is no requirement that a shell be able to make use of it, and bash will not. Other shells may be more flexible.</p> <p>Utili...
387
bash
<h1>Create environment variable with dot in the current environment</h1> <p>I know that you can create environment variables with the command <code>env</code>.</p> <p>For example:</p> <pre><code>env A.B=D bash </code></pre> <p>The problem is for env a command is required thus creating a new subprocess.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,164
bash
# Create environment variable with dot in the current environment I know that you can create environment variables with the command `env`. For example: ``` env A.B=D bash ``` The problem is for env a command is required thus creating a new subprocess.
Bash does not allow environment variables with non-alphanumeric characters in their names (aside from `_`). While the environment may contain a line such as `A.B=D`, there is no requirement that a shell be able to make use of it, and bash will not. Other shells may be more flexible. Utilities which make use of oddly-n...
29401283
git credential.helper does not store username password
13
2015-04-01 21:35:56
<p>I am writing a deployment script which clones a git repo and then performs other tasks such as fetch etc .I have run this </p> <pre><code>git config --global credential.helper cache </code></pre> <p>The username and password for cloning step are provided by an expect script. But these details are not cached as it ...
18,707
4,381,216
2023-10-03 22:38:23
29,404,057
15
2015-04-02 02:28:40
1,002,260
2021-03-04 17:11:57
https://stackoverflow.com/q/29401283
https://stackoverflow.com/a/29404057
<p>You can create a file <code>~/.netrc</code> like this:</p> <pre><code>machine github.com login &lt;username&gt; password &lt;password&gt; </code></pre> <p>and Git will use it. Another option is <a href="//git-scm.com/docs/git-credential-store" rel="noreferrer">git-credential-store</a>:</p> <pre><code>git config --gl...
<p>You can create a file <code>~/.netrc</code> like this:</p> <pre><code>machine github.com login &lt;username&gt; password &lt;password&gt; </code></pre> <p>and Git will use it. Another option is <a href="//git-scm.com/docs/git-credential-store" rel="noreferrer">git-credential-store</a>:</p> <pre><code>git config --gl...
119, 387, 9048, 116537
azure-devops, bash, expect, git
<h1>git credential.helper does not store username password</h1> <p>I am writing a deployment script which clones a git repo and then performs other tasks such as fetch etc .I have run this </p> <pre><code>git config --global credential.helper cache </code></pre> <p>The username and password for cloning step are provi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,165
bash
# git credential.helper does not store username password I am writing a deployment script which clones a git repo and then performs other tasks such as fetch etc .I have run this ``` git config --global credential.helper cache ``` The username and password for cloning step are provided by an expect script. But these...
You can create a file `~/.netrc` like this: ``` machine github.com login <username> password <password> ``` and Git will use it. Another option is [git-credential-store](//git-scm.com/docs/git-credential-store): ``` git config --global credential.helper store ``` Credentials are saved to `~/.git-credentials`.
28279812
BASH : Difference between '-' and '--' options
13
2015-02-02 14:21:30
<p>I was working my way through a primer on <strong>Shell (Bash) Scripting</strong> and had the following doubt :</p> <blockquote> <ul> <li><p>I came across the <strong><code>ls</code></strong> command</p> </li> <li><p>The <strong><code>man</code></strong> page of <strong><code>ls</code></strong> lists a few use cases ...
10,578
4,382,274
2015-02-04 17:27:08
28,279,911
15
2015-02-02 14:26:19
14,122
2015-02-02 14:34:46
https://stackoverflow.com/q/28279812
https://stackoverflow.com/a/28279911
<p>Long-form (<code>--foo</code>) options are a GNU extension -- something present in GNU <code>ls</code>, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of <code>ls</code> are not obliged to support these options. The entire word (<code>foo</code>) is meaningful in ...
<p>Long-form (<code>--foo</code>) options are a GNU extension -- something present in GNU <code>ls</code>, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of <code>ls</code> are not obliged to support these options. The entire word (<code>foo</code>) is meaningful in ...
58, 387, 390, 3589, 10327
bash, linux, ls, sh, shell
<h1>BASH : Difference between '-' and '--' options</h1> <p>I was working my way through a primer on <strong>Shell (Bash) Scripting</strong> and had the following doubt :</p> <blockquote> <ul> <li><p>I came across the <strong><code>ls</code></strong> command</p> </li> <li><p>The <strong><code>man</code></strong> page of...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,166
bash
# BASH : Difference between '-' and '--' options I was working my way through a primer on **Shell (Bash) Scripting** and had the following doubt : > - I came across the **`ls`** command > - The **`man`** page of **`ls`** lists a few use cases as : > > **`ls -a`** > **`ls --block-size='M'`** ***My Question :*** ...
Long-form (`--foo`) options are a GNU extension -- something present in GNU `ls`, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of `ls` are not obliged to support these options. The entire word (`foo`) is meaningful in this case. This nomenclature was added more rec...
20135054
How do I run many SSH remote commands, on multiple machines, in batch?
13
2013-11-22 01:05:24
<p>I use SSH to run some commands on multiple remote machines in a <code>for</code> loop. It executes the same command(s) for a list of IP addresses. Some of the IP addresses might be unreachable, so I used the <code>ConnectTimeout</code> option.</p> <p>However, my script didn't work the way I wanted. Actually it got ...
35,226
2,103,312
2018-07-10 05:33:07
23,326,958
15
2014-04-27 17:59:12
3,566,933
2014-04-28 05:13:06
https://stackoverflow.com/q/20135054
https://stackoverflow.com/a/23326958
<p>Your use of <code>ConnectTimeout</code> is correct, so it is not obvious why it only times out after 30 or more seconds.</p> <p>Here's how I would change your script to avoid the timeout problem entirely:</p> <ul> <li>Use GNU <code>parallel</code> to connect to more than one destination host at the same time.</li>...
<p>Your use of <code>ConnectTimeout</code> is correct, so it is not obvious why it only times out after 30 or more seconds.</p> <p>Here's how I would change your script to avoid the timeout problem entirely:</p> <ul> <li>Use GNU <code>parallel</code> to connect to more than one destination host at the same time.</li>...
386, 390, 2531, 2702
for-loop, shell, ssh, timeout
<h1>How do I run many SSH remote commands, on multiple machines, in batch?</h1> <p>I use SSH to run some commands on multiple remote machines in a <code>for</code> loop. It executes the same command(s) for a list of IP addresses. Some of the IP addresses might be unreachable, so I used the <code>ConnectTimeout</code> o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,167
bash
# How do I run many SSH remote commands, on multiple machines, in batch? I use SSH to run some commands on multiple remote machines in a `for` loop. It executes the same command(s) for a list of IP addresses. Some of the IP addresses might be unreachable, so I used the `ConnectTimeout` option. However, my script didn...
Your use of `ConnectTimeout` is correct, so it is not obvious why it only times out after 30 or more seconds. Here's how I would change your script to avoid the timeout problem entirely: - Use GNU `parallel` to connect to more than one destination host at the same time. - Use the `-f` option to SSH to process it in t...
22537163
Run curl command on each line of a file and fetch data from result
13
2014-03-20 15:08:29
<p>Suppose I have a file containing a list of links of webpages.</p> <pre><code>www.xyz.com/asdd www.wer.com/asdas www.asdas.com/asd www.asd.com/asdas </code></pre> <p>I know that doing <code>curl www.xyz.com/asdd</code> will fetch me the html of that webpage. I want to fetch some data from that webpage.</p> <p>So t...
21,832
2,542,215
2018-09-10 22:21:23
22,538,035
15
2014-03-20 15:41:35
1,983,854
2016-12-02 10:07:53
https://stackoverflow.com/q/22537163
https://stackoverflow.com/a/22538035
<p>As indicated in the comments, this will loop through <code>your_file</code> and <code>curl</code> each line:</p> <pre><code>while IFS= read -r line do curl "$line" done &lt; your_file </code></pre> <p>To get the <code>&lt;title&gt;</code> of a page, you can <code>grep</code> something like this:</p> <pre><code...
<p>As indicated in the comments, this will loop through <code>your_file</code> and <code>curl</code> each line:</p> <pre><code>while IFS= read -r line do curl "$line" done &lt; your_file </code></pre> <p>To get the <code>&lt;title&gt;</code> of a page, you can <code>grep</code> something like this:</p> <pre><code...
18, 387, 990, 1554
awk, bash, curl, regex
<h1>Run curl command on each line of a file and fetch data from result</h1> <p>Suppose I have a file containing a list of links of webpages.</p> <pre><code>www.xyz.com/asdd www.wer.com/asdas www.asdas.com/asd www.asd.com/asdas </code></pre> <p>I know that doing <code>curl www.xyz.com/asdd</code> will fetch me the htm...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,168
bash
# Run curl command on each line of a file and fetch data from result Suppose I have a file containing a list of links of webpages. ``` www.xyz.com/asdd www.wer.com/asdas www.asdas.com/asd www.asd.com/asdas ``` I know that doing `curl www.xyz.com/asdd` will fetch me the html of that webpage. I want to fetch some data...
As indicated in the comments, this will loop through `your_file` and `curl` each line: ``` while IFS= read -r line do curl "$line" done < your_file ``` To get the `<title>` of a page, you can `grep` something like this: ``` grep -iPo '(?<=<title>).*(?=</title>)' file ``` So all together you could do ``` while I...
21794235
How do I deal with vim's swap file system?
13
2014-02-15 06:31:23
<p>When using <code>vim</code> in ubuntu, I accidentally pressed <code>ctrl-z</code> which suspended my session of <code>vim</code>. I was editing a file (I'll call it <code>test</code>) which was not saved.</p> <p>When I opened the file again in <code>vim</code>, I got the swap file error:</p> <pre><code>E325: ATTEN...
36,179
2,029,568
2015-01-26 11:08:37
21,794,557
15
2014-02-15 07:10:51
3,312,752
2014-02-15 07:10:51
https://stackoverflow.com/q/21794235
https://stackoverflow.com/a/21794557
<p>This is not related to Ubuntu alone, since what happens is a base mechanism of nearly every Unix OS. By pressin ^Z you ave suspended (not ended) the currently running vim session. The vim session is still there and waiting for a signal to put it to foreground again.</p> <p>To reactivate the session: If vim was sta...
<p>This is not related to Ubuntu alone, since what happens is a base mechanism of nearly every Unix OS. By pressin ^Z you ave suspended (not ended) the currently running vim session. The vim session is still there and waiting for a signal to put it to foreground again.</p> <p>To reactivate the session: If vim was sta...
34, 58, 370, 387, 391
bash, linux, terminal, unix, vim
<h1>How do I deal with vim's swap file system?</h1> <p>When using <code>vim</code> in ubuntu, I accidentally pressed <code>ctrl-z</code> which suspended my session of <code>vim</code>. I was editing a file (I'll call it <code>test</code>) which was not saved.</p> <p>When I opened the file again in <code>vim</code>, I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,169
bash
# How do I deal with vim's swap file system? When using `vim` in ubuntu, I accidentally pressed `ctrl-z` which suspended my session of `vim`. I was editing a file (I'll call it `test`) which was not saved. When I opened the file again in `vim`, I got the swap file error: ``` E325: ATTENTION Found a swap file by the ...
This is not related to Ubuntu alone, since what happens is a base mechanism of nearly every Unix OS. By pressin ^Z you ave suspended (not ended) the currently running vim session. The vim session is still there and waiting for a signal to put it to foreground again. To reactivate the session: If vim was started direct...
21590719
Check if user is a member of the local admins group on a remote server
13
2014-02-05 23:17:24
<p>The user is a member of the AD security group "Domain\Sql Admins", and the security group "Domain\Sql Admins" is a member of the local <strong>Administrators</strong> group on a Windows Server.</p> <p>I have tried the following PowerShell script:</p> <pre><code> $u = "Username"; net localgroup administrators | Whe...
56,571
1,645,218
2017-10-12 04:14:54
21,591,740
15
2014-02-06 00:39:50
null
2014-02-06 00:39:50
https://stackoverflow.com/q/21590719
https://stackoverflow.com/a/21591740
<p>Check out this article, by Boe Prox on the Microsoft Hey Scripting Guy blog. He describes how to check if the user is a local administrator or not.</p> <p><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/11/check-for-admin-credentials-in-a-powershell-script.aspx" rel="noreferrer">http://blogs.tec...
<p>Check out this article, by Boe Prox on the Microsoft Hey Scripting Guy blog. He describes how to check if the user is a local administrator or not.</p> <p><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/11/check-for-admin-credentials-in-a-powershell-script.aspx" rel="noreferrer">http://blogs.tec...
526, 10401
active-directory, powershell
<h1>Check if user is a member of the local admins group on a remote server</h1> <p>The user is a member of the AD security group "Domain\Sql Admins", and the security group "Domain\Sql Admins" is a member of the local <strong>Administrators</strong> group on a Windows Server.</p> <p>I have tried the following PowerShe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,170
bash
# Check if user is a member of the local admins group on a remote server The user is a member of the AD security group "Domain\Sql Admins", and the security group "Domain\Sql Admins" is a member of the local **Administrators** group on a Windows Server. I have tried the following PowerShell script: ``` $u = "Userna...
Check out this article, by Boe Prox on the Microsoft Hey Scripting Guy blog. He describes how to check if the user is a local administrator or not. <http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/11/check-for-admin-credentials-in-a-powershell-script.aspx> This article points to a `Test-IsAdmin` function t...
21106465
Restoring stdout and stderr to default value
13
2014-01-14 05:09:50
<p>In shell script, We can change the default input to a File using the exec command as follow :</p> <pre><code> exec 1&gt;outputfile </code></pre> <p>However, if in the same script if I want to restore the stdout descriptor '1' to the default (terminal). How can we achieve that? </p>
8,885
1,773,248
2019-11-20 06:58:50
21,106,592
15
2014-01-14 05:23:09
554,807
2019-11-20 06:58:50
https://stackoverflow.com/q/21106465
https://stackoverflow.com/a/21106592
<p>This example</p> <blockquote> <p>Example 20-2. Redirecting stdout using exec</p> <pre><code>#!/bin/bash # reassign-stdout.sh LOGFILE=logfile.txt exec 6&gt;&amp;1 # Link file descriptor #6 with stdout. # Saves stdout. exec &gt; $LOGFILE # stdout replaced with file "logfile.txt...
<p>This example</p> <blockquote> <p>Example 20-2. Redirecting stdout using exec</p> <pre><code>#!/bin/bash # reassign-stdout.sh LOGFILE=logfile.txt exec 6&gt;&amp;1 # Link file descriptor #6 with stdout. # Saves stdout. exec &gt; $LOGFILE # stdout replaced with file "logfile.txt...
58, 390, 4867, 7932, 31901
exec, http-redirect, linux, shell, stdout
<h1>Restoring stdout and stderr to default value</h1> <p>In shell script, We can change the default input to a File using the exec command as follow :</p> <pre><code> exec 1&gt;outputfile </code></pre> <p>However, if in the same script if I want to restore the stdout descriptor '1' to the default (terminal). How ca...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,171
bash
# Restoring stdout and stderr to default value In shell script, We can change the default input to a File using the exec command as follow : ``` exec 1>outputfile ``` However, if in the same script if I want to restore the stdout descriptor '1' to the default (terminal). How can we achieve that?
This example > Example 20-2. Redirecting stdout using exec > > ``` > #!/bin/bash > # reassign-stdout.sh > > LOGFILE=logfile.txt > > exec 6>&1 # Link file descriptor #6 with stdout. > # Saves stdout. > > exec > $LOGFILE # stdout replaced with file "logfile.txt". > > # -----------------...
18279540
How to kill all background processes in bash when main process exits
13
2013-08-16 18:05:00
<p>I have a bash that runs endless commands as background processes:</p> <pre><code>#!/bin/bash function xyz() { # some awk command } endlesscommand "param 1" | xyz &amp; # async pids=$! endlesscommand "param 2" | xyz &amp; # async pids="$pids "$! endlesscommand "param 3" | xyz # sync so the script doesn't le...
7,514
1,511,914
2023-05-23 15:19:46
18,280,221
15
2013-08-16 18:52:45
580,412
2016-10-24 21:38:04
https://stackoverflow.com/q/18279540
https://stackoverflow.com/a/18280221
<p>Here's a trap that doesn't need you to track <code>pids</code>:</p> <pre><code>trap 'jobs -p | xargs kill' EXIT </code></pre> <p><strong>EDIT</strong>: @Barmar asked if this works within non-sourced scripts, where job control isn't usually available. It does. Consider this script:</p> <pre><code>$ cat no-job-co...
<p>Here's a trap that doesn't need you to track <code>pids</code>:</p> <pre><code>trap 'jobs -p | xargs kill' EXIT </code></pre> <p><strong>EDIT</strong>: @Barmar asked if this works within non-sourced scripts, where job control isn't usually available. It does. Consider this script:</p> <pre><code>$ cat no-job-co...
387, 5910
bash, process
<h1>How to kill all background processes in bash when main process exits</h1> <p>I have a bash that runs endless commands as background processes:</p> <pre><code>#!/bin/bash function xyz() { # some awk command } endlesscommand "param 1" | xyz &amp; # async pids=$! endlesscommand "param 2" | xyz &amp; # async pid...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,172
bash
# How to kill all background processes in bash when main process exits I have a bash that runs endless commands as background processes: ``` #!/bin/bash function xyz() { # some awk command } endlesscommand "param 1" | xyz & # async pids=$! endlesscommand "param 2" | xyz & # async pids="$pids "$! endlesscommand ...
Here's a trap that doesn't need you to track `pids`: ``` trap 'jobs -p | xargs kill' EXIT ``` **EDIT**: @Barmar asked if this works within non-sourced scripts, where job control isn't usually available. It does. Consider this script: ``` $ cat no-job-control #! /bin/bash set -e -o pipefail # Prove job control is o...
16165063
What is the meaning of !#:3?
13
2013-04-23 08:54:38
<pre><code> curl http://beyondgrep.com/ack-2.02-single-file &gt; ~/bin/ack &amp;&amp; chmod 0755 !#:3 </code></pre> <p>What is the meaning of <code>!#:3</code>, from <a href="http://beyondgrep.com/install/">ack installation guide</a>?</p>
591
88,597
2013-04-23 12:08:01
16,165,187
15
2013-04-23 08:59:55
2,195,474
2013-04-23 09:41:25
https://stackoverflow.com/q/16165063
https://stackoverflow.com/a/16165187
<p>In bash or zsh <code>!</code> denotes a history command (not a shebang line which is <code>#!</code>, and has nothing to do with bash or zsh as such).</p> <p><code>!#</code> means the entire command line typed so far, and <code>:3</code> selects the third word, in this case <code>~/bin/ack</code>.</p> <p>So the c...
<p>In bash or zsh <code>!</code> denotes a history command (not a shebang line which is <code>#!</code>, and has nothing to do with bash or zsh as such).</p> <p><code>!#</code> means the entire command line typed so far, and <code>:3</code> selects the third word, in this case <code>~/bin/ack</code>.</p> <p>So the c...
58, 387, 390, 3791, 26784
ack, bash, linux, shell, zsh
<h1>What is the meaning of !#:3?</h1> <pre><code> curl http://beyondgrep.com/ack-2.02-single-file &gt; ~/bin/ack &amp;&amp; chmod 0755 !#:3 </code></pre> <p>What is the meaning of <code>!#:3</code>, from <a href="http://beyondgrep.com/install/">ack installation guide</a>?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,173
bash
# What is the meaning of !#:3? ``` curl http://beyondgrep.com/ack-2.02-single-file > ~/bin/ack && chmod 0755 !#:3 ``` What is the meaning of `!#:3`, from [ack installation guide](http://beyondgrep.com/install/)?
In bash or zsh `!` denotes a history command (not a shebang line which is `#!`, and has nothing to do with bash or zsh as such). `!#` means the entire command line typed so far, and `:3` selects the third word, in this case `~/bin/ack`. So the command is equivalent to: ``` curl http://beyondgrep.com/ack-2.02-single...
15257130
simple tmux bash script not working
13
2013-03-06 20:16:59
<p>I want tmux to open a new window and then cd into a directory, but it doesn't work. It just opens tmux in the directory my script was run from (ie. it doesn't execute the cd command).</p> <p>Can someone tell me what I'm doing wrong? (I'm using tmux 1.6)</p> <pre><code>#!/bin/bash ...
7,939
598,093
2013-03-07 01:05:24
15,261,246
15
2013-03-07 01:05:24
598,093
2013-03-07 01:05:24
https://stackoverflow.com/q/15257130
https://stackoverflow.com/a/15261246
<p>I finally got it to work, using C-m and numbering the windows starting from 0. I added a second command for illustrative purposes.</p> <pre><code>#!/bin/bash tmux start-server tmux new-sessio...
<p>I finally got it to work, using C-m and numbering the windows starting from 0. I added a second command for illustrative purposes.</p> <pre><code>#!/bin/bash tmux start-server tmux new-sessio...
387, 60238
bash, tmux
<h1>simple tmux bash script not working</h1> <p>I want tmux to open a new window and then cd into a directory, but it doesn't work. It just opens tmux in the directory my script was run from (ie. it doesn't execute the cd command).</p> <p>Can someone tell me what I'm doing wrong? (I'm using tmux 1.6)</p> <pre><code>#...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,174
bash
# simple tmux bash script not working I want tmux to open a new window and then cd into a directory, but it doesn't work. It just opens tmux in the directory my script was run from (ie. it doesn't execute the cd command). Can someone tell me what I'm doing wrong? (I'm using tmux 1.6) ``` #!/bin/bash ...
I finally got it to work, using C-m and numbering the windows starting from 0. I added a second command for illustrative purposes. ``` #!/bin/bash tmux start-server tmux new-session -d -s my_ser...
15101343
standard deviation of an arbitrary number of numbers using bc or other standard utilities
13
2013-02-26 23:16:01
<p>Is there some trick that would allow one to use bc (or some other standard utility) to return the standard deviation of an arbitrary number of numbers? For convenience, let's say that the numbers are stored in a Bash variable in the following way:</p> <pre><code>myNumbers="0.556 1.456 45.111 7.812 5.001" </code></p...
10,732
1,556,092
2022-08-01 23:02:36
15,101,429
15
2013-02-26 23:22:24
465,183
2013-02-26 23:57:55
https://stackoverflow.com/q/15101343
https://stackoverflow.com/a/15101429
<p>Using <a href="/questions/tagged/awk" class="post-tag" title="show questions tagged 'awk'" rel="tag">awk</a>:</p> <pre><code>standardDeviation=$( echo "$myNumbers" | awk '{sum+=$1; sumsq+=$1*$1}END{print sqrt(sumsq/NR - (sum/NR)**2)}' ) echo $standardDeviation </code></pre> <p>Using <a href="/questions...
<p>Using <a href="/questions/tagged/awk" class="post-tag" title="show questions tagged 'awk'" rel="tag">awk</a>:</p> <pre><code>standardDeviation=$( echo "$myNumbers" | awk '{sum+=$1; sumsq+=$1*$1}END{print sqrt(sumsq/NR - (sum/NR)**2)}' ) echo $standardDeviation </code></pre> <p>Using <a href="/questions...
276, 387, 49880
bash, standard-deviation, variables
<h1>standard deviation of an arbitrary number of numbers using bc or other standard utilities</h1> <p>Is there some trick that would allow one to use bc (or some other standard utility) to return the standard deviation of an arbitrary number of numbers? For convenience, let's say that the numbers are stored in a Bash v...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,175
bash
# standard deviation of an arbitrary number of numbers using bc or other standard utilities Is there some trick that would allow one to use bc (or some other standard utility) to return the standard deviation of an arbitrary number of numbers? For convenience, let's say that the numbers are stored in a Bash variable i...
Using [awk](/questions/tagged/awk "show questions tagged 'awk'"): ``` standardDeviation=$( echo "$myNumbers" | awk '{sum+=$1; sumsq+=$1*$1}END{print sqrt(sumsq/NR - (sum/NR)**2)}' ) echo $standardDeviation ``` Using [perl](/questions/tagged/perl "show questions tagged 'perl'") : ``` #!/usr/bin/env perl ...
14231232
Why a variable assignment replaces tabs with spaces
13
2013-01-09 08:42:05
<p>Why does a variable assignment replace tabs with spaces in the shell?</p> <pre><code>$ cat tmp a b e c d $ res=$(cat tmp) $ echo $res a b e c d </code></pre>
6,224
878,228
2016-05-13 21:57:35
14,231,342
15
2013-01-09 08:49:20
1,066,031
2016-05-13 21:57:35
https://stackoverflow.com/q/14231232
https://stackoverflow.com/a/14231342
<p>You need to quote your variable <code>$res</code> for whitespace to be preserved. </p> <pre><code>$ cat file a b e c d $ res=$(cat file) $ echo $res a b e c d $ echo "$res" a b e c d </code></pre> <p>From <code>man bash</code> under <code>QUOTING</code>:</p> <blockquote> <p>Qu...
<p>You need to quote your variable <code>$res</code> for whitespace to be preserved. </p> <pre><code>$ cat file a b e c d $ res=$(cat file) $ echo $res a b e c d $ echo "$res" a b e c d </code></pre> <p>From <code>man bash</code> under <code>QUOTING</code>:</p> <blockquote> <p>Qu...
276, 387, 390
bash, shell, variables
<h1>Why a variable assignment replaces tabs with spaces</h1> <p>Why does a variable assignment replace tabs with spaces in the shell?</p> <pre><code>$ cat tmp a b e c d $ res=$(cat tmp) $ echo $res a b e c d </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,176
bash
# Why a variable assignment replaces tabs with spaces Why does a variable assignment replace tabs with spaces in the shell? ``` $ cat tmp a b e c d $ res=$(cat tmp) $ echo $res a b e c d ```
You need to quote your variable `$res` for whitespace to be preserved. ``` $ cat file a b e c d $ res=$(cat file) $ echo $res a b e c d $ echo "$res" a b e c d ``` From `man bash` under `QUOTING`: > Quoting is used to remove the special meaning of certain characters > or words to t...
10821597
How to kill Django runserver sub processes from a bash script?
13
2012-05-30 17:51:35
<p>I'm working on a Django website where I have various compilation programs that need to run (Compass/Sass, coffeescript, hamlpy), so I made this shell script for convenience:</p> <pre><code>#!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using siteroot=$SITE" $SITE/rmx/manage.py runserver &amp; PIDS[0]=$! compass wa...
4,226
179,609
2018-03-02 10:40:46
10,821,880
15
2012-05-30 18:11:28
179,609
2012-05-30 18:11:28
https://stackoverflow.com/q/10821597
https://stackoverflow.com/a/10821880
<p><strong>SOLVED</strong> </p> <p>Thanks to <a href="https://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes">this SO question</a>, I've changed my script to this:</p> <pre><code>#!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using siteroot=$SITE" $SITE/rmx/manage.py runserver &amp; compass ...
<p><strong>SOLVED</strong> </p> <p>Thanks to <a href="https://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes">this SO question</a>, I've changed my script to this:</p> <pre><code>#!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using siteroot=$SITE" $SITE/rmx/manage.py runserver &amp; compass ...
16, 243, 387, 390
bash, django, python, shell
<h1>How to kill Django runserver sub processes from a bash script?</h1> <p>I'm working on a Django website where I have various compilation programs that need to run (Compass/Sass, coffeescript, hamlpy), so I made this shell script for convenience:</p> <pre><code>#!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,177
bash
# How to kill Django runserver sub processes from a bash script? I'm working on a Django website where I have various compilation programs that need to run (Compass/Sass, coffeescript, hamlpy), so I made this shell script for convenience: ``` #!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using siteroot=$SITE" $SITE...
**SOLVED** Thanks to [this SO question](https://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes), I've changed my script to this: ``` #!/bin/bash SITE=/home/dev/sites/rmx echo "RMX using siteroot=$SITE" $SITE/rmx/manage.py runserver & compass watch $SITE/media/compass/ & coffee -o $SITE/media...
10747479
CreateProcess and ShellExecute differences
13
2012-05-25 01:42:41
<p>What are the main differences between the two? I'm willing to run only another EXE from my (C++) application. Are there any differences when inheriting environments, security features etc?</p>
19,700
840,405
2018-02-01 10:02:23
10,751,551
15
2012-05-25 09:08:06
315,935
2016-12-31 13:01:44
https://stackoverflow.com/q/10747479
https://stackoverflow.com/a/10751551
<p>The main difference between <code>CreateProcess</code> and <code>ShellExecute</code> is the following: <code>CreateProcess</code> is more oriented on low level and <code>ShellExec</code> on the high user lever which see the user in explorer.</p> <p>For example using of <code>CreateProcess</code> one can use command...
<p>The main difference between <code>CreateProcess</code> and <code>ShellExecute</code> is the following: <code>CreateProcess</code> is more oriented on low level and <code>ShellExec</code> on the high user lever which see the user in explorer.</p> <p>For example using of <code>CreateProcess</code> one can use command...
10, 64, 889, 6613, 8646
c++, createprocess, shell-exec, winapi, windows
<h1>CreateProcess and ShellExecute differences</h1> <p>What are the main differences between the two? I'm willing to run only another EXE from my (C++) application. Are there any differences when inheriting environments, security features etc?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,178
bash
# CreateProcess and ShellExecute differences What are the main differences between the two? I'm willing to run only another EXE from my (C++) application. Are there any differences when inheriting environments, security features etc?
The main difference between `CreateProcess` and `ShellExecute` is the following: `CreateProcess` is more oriented on low level and `ShellExec` on the high user lever which see the user in explorer. For example using of `CreateProcess` one can use command line which length is more as `MAX_PATH`. It has 32,768 character...
9305714
How to run sh file from another sh file
13
2012-02-16 04:49:30
<p>I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job.</p> <p>I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to include my scripts to master file. How to run those s...
40,225
1,006,944
2019-12-03 11:09:35
9,305,837
15
2012-02-16 05:05:24
1,137,103
2016-06-07 18:05:21
https://stackoverflow.com/q/9305714
https://stackoverflow.com/a/9305837
<p>Take a look at <a href="https://stackoverflow.com/questions/9190151/how-to-run-a-shell-script-in-the-backgroung-and-get-no-output">this</a>. If you want to run a script you can use:</p> <pre><code>./yourscript.sh </code></pre> <p>If your script has a loop, use:</p> <pre><code>./yourscript.sh&amp; </code></pre> <...
<p>Take a look at <a href="https://stackoverflow.com/questions/9190151/how-to-run-a-shell-script-in-the-backgroung-and-get-no-output">this</a>. If you want to run a script you can use:</p> <pre><code>./yourscript.sh </code></pre> <p>If your script has a loop, use:</p> <pre><code>./yourscript.sh&amp; </code></pre> <...
34, 58, 390, 10327
linux, sh, shell, unix
<h1>How to run sh file from another sh file</h1> <p>I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job.</p> <p>I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to incl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,179
bash
# How to run sh file from another sh file I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job. I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to include my scripts to ...
Take a look at [this](https://stackoverflow.com/questions/9190151/how-to-run-a-shell-script-in-the-backgroung-and-get-no-output). If you want to run a script you can use: ``` ./yourscript.sh ``` If your script has a loop, use: ``` ./yourscript.sh& ``` If you want to get the console after starting scripts and you do...
8902004
Powershell fails to return proper exit code
13
2012-01-17 21:32:16
<p>When executing a Powershell script (in 2.0) using the <strong>-File</strong> command line switch, and explicitly defining the input parameters in Param, the exit code is always "0" (never fails) instead of properly returning the defined or expected error code.<br> This does not occur when using the explicit paramete...
6,484
771,831
2013-04-24 14:55:52
8,902,329
15
2012-01-17 21:59:54
251,123
2012-01-17 21:59:54
https://stackoverflow.com/q/8902004
https://stackoverflow.com/a/8902329
<p>Hmm that's odd, I'd expect <code>exit 1</code> to work in both cases. At least you can use this for both:</p> <p><code>[Environment]::Exit(1)</code></p>
<p>Hmm that's odd, I'd expect <code>exit 1</code> to work in both cases. At least you can use this for both:</p> <p><code>[Environment]::Exit(1)</code></p>
360, 526, 10021, 10355, 17564
errorlevel, exit-code, parameter-passing, parameters, powershell
<h1>Powershell fails to return proper exit code</h1> <p>When executing a Powershell script (in 2.0) using the <strong>-File</strong> command line switch, and explicitly defining the input parameters in Param, the exit code is always "0" (never fails) instead of properly returning the defined or expected error code.<br>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,180
bash
# Powershell fails to return proper exit code When executing a Powershell script (in 2.0) using the **-File** command line switch, and explicitly defining the input parameters in Param, the exit code is always "0" (never fails) instead of properly returning the defined or expected error code. This does not occur whe...
Hmm that's odd, I'd expect `exit 1` to work in both cases. At least you can use this for both: `[Environment]::Exit(1)`
218255
Keeping shell configurations in sync across multiple machines
13
2008-10-20 12:30:18
<p>I'm a pretty active command line user and I have shell accounts all over the place. MacBooks, Linux desktop machines, Linux servers, Cygwin on XP, you name it.</p> <p>How can I keep my shell configuration (<code>.bashrc</code>, <code>.vimrc</code> etc.) in sync across all these machines using the limited tools avai...
4,588
20,476
2025-03-12 16:51:31
6,876,048
15
2011-07-29 16:18:08
20,476
2012-11-24 06:46:12
https://stackoverflow.com/q/218255
https://stackoverflow.com/a/6876048
<p>I have folder on Dropbox with global, per OS, and per machine shell configs:</p> <pre><code>$ ls ~/Dropbox/shell/bash bashbootstrap bashrc bashrc-Darwin bashrc-Darwin-laptopname bashrc-Darwin-mininame bashrc-Linux bashrc-Linux-machineone bashrc-Linux-machinetwo </code></pre> <p><code>bashrc</code> is loaded o...
<p>I have folder on Dropbox with global, per OS, and per machine shell configs:</p> <pre><code>$ ls ~/Dropbox/shell/bash bashbootstrap bashrc bashrc-Darwin bashrc-Darwin-laptopname bashrc-Darwin-mininame bashrc-Linux bashrc-Linux-machineone bashrc-Linux-machinetwo </code></pre> <p><code>bashrc</code> is loaded o...
390, 1652, 2533, 54848
development-environment, dotfiles, shell, synchronization
<h1>Keeping shell configurations in sync across multiple machines</h1> <p>I'm a pretty active command line user and I have shell accounts all over the place. MacBooks, Linux desktop machines, Linux servers, Cygwin on XP, you name it.</p> <p>How can I keep my shell configuration (<code>.bashrc</code>, <code>.vimrc</cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,181
bash
# Keeping shell configurations in sync across multiple machines I'm a pretty active command line user and I have shell accounts all over the place. MacBooks, Linux desktop machines, Linux servers, Cygwin on XP, you name it. How can I keep my shell configuration (`.bashrc`, `.vimrc` etc.) in sync across all these mach...
I have folder on Dropbox with global, per OS, and per machine shell configs: ``` $ ls ~/Dropbox/shell/bash bashbootstrap bashrc bashrc-Darwin bashrc-Darwin-laptopname bashrc-Darwin-mininame bashrc-Linux bashrc-Linux-machineone bashrc-Linux-machinetwo ``` `bashrc` is loaded on every machine, `bashrc-Linux`, `bash...
6006759
git bash : how to check if there's a new commit available
13
2011-05-15 05:53:15
<p>I use git with my friend to collaborate on a project. He created a repo in github consisting folders of each of our names, so everytime i update something, I upload it to this folder then push it to github, and so does he. So everytime there's a new commit, we have to pull from github and copy paste the edited files...
18,776
229,424
2022-01-20 10:32:14
6,006,953
15
2011-05-15 06:52:44
223,092
2011-05-15 06:52:44
https://stackoverflow.com/q/6006759
https://stackoverflow.com/a/6006953
<p>Answering your first two questions in turn:</p> <ol> <li>Assuming that <code>origin</code> refers to the GitHub repository in each case, you should just run <code>git fetch origin</code>. Then the "remote-tracking branch" <code>origin/master</code> will be at the version of master on GitHub and you can compare it ...
<p>Answering your first two questions in turn:</p> <ol> <li>Assuming that <code>origin</code> refers to the GitHub repository in each case, you should just run <code>git fetch origin</code>. Then the "remote-tracking branch" <code>origin/master</code> will be at the version of master on GitHub and you can compare it ...
119, 387
bash, git
<h1>git bash : how to check if there's a new commit available</h1> <p>I use git with my friend to collaborate on a project. He created a repo in github consisting folders of each of our names, so everytime i update something, I upload it to this folder then push it to github, and so does he. So everytime there's a new ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,182
bash
# git bash : how to check if there's a new commit available I use git with my friend to collaborate on a project. He created a repo in github consisting folders of each of our names, so everytime i update something, I upload it to this folder then push it to github, and so does he. So everytime there's a new commit, w...
Answering your first two questions in turn: 1. Assuming that `origin` refers to the GitHub repository in each case, you should just run `git fetch origin`. Then the "remote-tracking branch" `origin/master` will be at the version of master on GitHub and you can compare it with your master with `git diff master origin/m...
4146635
custom sorting in powershell
13
2010-11-10 16:28:07
<p>I have filenames in following format: </p> <pre><code>[ignore-prefix]-[important-middle]-[ignore-suffix]-[name-with-digits] </code></pre> <p>I need to sort according to following rules: first by middle part, then by name, in natural order (i.e. foobar10 > foobar2). I don't know prefix value, but I know the separat...
7,886
499,388
2019-07-22 21:26:33
4,146,905
15
2010-11-10 16:58:01
323,582
2010-11-10 17:43:07
https://stackoverflow.com/q/4146635
https://stackoverflow.com/a/4146905
<p>I understand the task in this way: sorting should be performed by 3 expressions: 1) middle part, 2) name part without digits, 3) number represented by trailing digits of the name part.</p> <p>Let’s create these expressions with regular expressions. Here is the answer:</p> <pre><code># gets the middle part $part1 =...
<p>I understand the task in this way: sorting should be performed by 3 expressions: 1) middle part, 2) name part without digits, 3) number represented by trailing digits of the name part.</p> <p>Let’s create these expressions with regular expressions. Here is the answer:</p> <pre><code># gets the middle part $part1 =...
526
powershell
<h1>custom sorting in powershell</h1> <p>I have filenames in following format: </p> <pre><code>[ignore-prefix]-[important-middle]-[ignore-suffix]-[name-with-digits] </code></pre> <p>I need to sort according to following rules: first by middle part, then by name, in natural order (i.e. foobar10 > foobar2). I don't kno...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,183
bash
# custom sorting in powershell I have filenames in following format: ``` [ignore-prefix]-[important-middle]-[ignore-suffix]-[name-with-digits] ``` I need to sort according to following rules: first by middle part, then by name, in natural order (i.e. foobar10 > foobar2). I don't know prefix value, but I know the sep...
I understand the task in this way: sorting should be performed by 3 expressions: 1) middle part, 2) name part without digits, 3) number represented by trailing digits of the name part. Let’s create these expressions with regular expressions. Here is the answer: ``` # gets the middle part $part1 = { if ($_.Name -match...
1251938
Move files to directories based on first part of filename?
13
2009-08-09 18:32:55
<p>I have several thousand ebooks that need to be organized on a headless linux server running bash through SSH. All of the ebooks are thankfully named with one of 2 conventions.</p> <ul> <li>AuthorFirstName AuthorLastName - Book Title.pdf </li> <li>AuthorFirstName AuthorLastName - Book Series #inSeries - Book Title.p...
20,852
153,032
2015-07-27 19:49:04
1,251,953
15
2009-08-09 18:38:44
47,529
2015-05-14 11:44:56
https://stackoverflow.com/q/1251938
https://stackoverflow.com/a/1251953
<pre><code>for f in *.pdf; do name=`echo "$f"|sed 's/ -.*//'` letter=`echo "$name"|cut -c1` dir="DestinationDirectory/$letter/$name" mkdir -p "$dir" mv "$f" "$dir" done </code></pre>
<pre><code>for f in *.pdf; do name=`echo "$f"|sed 's/ -.*//'` letter=`echo "$name"|cut -c1` dir="DestinationDirectory/$letter/$name" mkdir -p "$dir" mv "$f" "$dir" done </code></pre>
387, 1062
bash, filenames
<h1>Move files to directories based on first part of filename?</h1> <p>I have several thousand ebooks that need to be organized on a headless linux server running bash through SSH. All of the ebooks are thankfully named with one of 2 conventions.</p> <ul> <li>AuthorFirstName AuthorLastName - Book Title.pdf </li> <li>A...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,184
bash
# Move files to directories based on first part of filename? I have several thousand ebooks that need to be organized on a headless linux server running bash through SSH. All of the ebooks are thankfully named with one of 2 conventions. - AuthorFirstName AuthorLastName - Book Title.pdf - AuthorFirstName AuthorLastNam...
``` for f in *.pdf; do name=`echo "$f"|sed 's/ -.*//'` letter=`echo "$name"|cut -c1` dir="DestinationDirectory/$letter/$name" mkdir -p "$dir" mv "$f" "$dir" done ```
64584485
What is the purpose of using the exec command?
12
2020-10-29 03:17:09
<p>Here I don't understand what the following piece of code is trying to achieve, I did search online for the use of exec but don't quite get the idea, could anyone please help to explain?</p> <p>Code snippet:</p> <pre><code>exec $(dirname &quot;$0&quot;)/init.sh -l interface.mod -l instrument.mod -a postinit.mod -a as...
14,978
8,824,969
2025-01-09 00:58:43
64,584,819
15
2020-10-29 04:02:48
1,218,985
2020-10-29 04:02:48
https://stackoverflow.com/q/64584485
https://stackoverflow.com/a/64584819
<p>The <code>exec</code> is a builtin command of the Bash shell which allows you to execute a command that completely replaces the current process, i.e., the current shell process is destroyed, and entirely replaced by the command you specify. It is useful when you want to run a command, but you don't want a bash shell...
<p>The <code>exec</code> is a builtin command of the Bash shell which allows you to execute a command that completely replaces the current process, i.e., the current shell process is destroyed, and entirely replaced by the command you specify. It is useful when you want to run a command, but you don't want a bash shell...
387, 390
bash, shell
<h1>What is the purpose of using the exec command?</h1> <p>Here I don't understand what the following piece of code is trying to achieve, I did search online for the use of exec but don't quite get the idea, could anyone please help to explain?</p> <p>Code snippet:</p> <pre><code>exec $(dirname &quot;$0&quot;)/init.sh ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,185
bash
# What is the purpose of using the exec command? Here I don't understand what the following piece of code is trying to achieve, I did search online for the use of exec but don't quite get the idea, could anyone please help to explain? Code snippet: ``` exec $(dirname "$0")/init.sh -l interface.mod -l instrument.mod ...
The `exec` is a builtin command of the Bash shell which allows you to execute a command that completely replaces the current process, i.e., the current shell process is destroyed, and entirely replaced by the command you specify. It is useful when you want to run a command, but you don't want a bash shell to be the par...
51293767
What is the difference between using process substitution vs. a pipe?
12
2018-07-11 20:32:16
<p>I came across an example for the using <code>tee</code> utility in the <code>tee</code> info page:</p> <pre><code>wget -O - http://example.com/dvd.iso | tee &gt;(sha1sum &gt; dvd.sha1) &gt; dvd.iso </code></pre> <p>I looked up the <code>&gt;(...)</code> syntax and found something called "process substitution". Fro...
4,035
7,327,755
2024-10-19 18:41:01
51,293,856
15
2018-07-11 20:39:56
1,899,640
2018-07-11 20:49:56
https://stackoverflow.com/q/51293767
https://stackoverflow.com/a/51293856
<p>There's no benefit here, as the line could equally well have been written like this:</p> <pre><code>wget -O - http://example.com/dvd.iso | tee dvd.iso | sha1sum &gt; dvd.sha1 </code></pre> <p>The differences start to appear when you need to pipe to/from <em>multiple</em> programs, because these can't be expressed ...
<p>There's no benefit here, as the line could equally well have been written like this:</p> <pre><code>wget -O - http://example.com/dvd.iso | tee dvd.iso | sha1sum &gt; dvd.sha1 </code></pre> <p>The differences start to appear when you need to pipe to/from <em>multiple</em> programs, because these can't be expressed ...
387, 5813, 63638
bash, pipe, process-substitution
<h1>What is the difference between using process substitution vs. a pipe?</h1> <p>I came across an example for the using <code>tee</code> utility in the <code>tee</code> info page:</p> <pre><code>wget -O - http://example.com/dvd.iso | tee &gt;(sha1sum &gt; dvd.sha1) &gt; dvd.iso </code></pre> <p>I looked up the <code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,186
bash
# What is the difference between using process substitution vs. a pipe? I came across an example for the using `tee` utility in the `tee` info page: ``` wget -O - http://example.com/dvd.iso | tee >(sha1sum > dvd.sha1) > dvd.iso ``` I looked up the `>(...)` syntax and found something called "process substitution". Fr...
There's no benefit here, as the line could equally well have been written like this: ``` wget -O - http://example.com/dvd.iso | tee dvd.iso | sha1sum > dvd.sha1 ``` The differences start to appear when you need to pipe to/from *multiple* programs, because these can't be expressed purely with `|`. Feel free to try: `...
46565176
Powershell: Checking if Network Drive exists, if not, map it then double check
12
2017-10-04 12:42:08
<p>I am trying to write a simple script to check if a network drive is available, map it if it isn't, then double check the mapping worked (to report any issues like the account mapping it has accidentally expired etc). If it fails at the double check, it will send an email, otherwise it reports all ok. </p> <p>I cann...
38,777
2,920,544
2020-08-17 13:08:10
46,566,209
15
2017-10-04 13:29:44
1,238,413
2020-08-17 13:08:10
https://stackoverflow.com/q/46565176
https://stackoverflow.com/a/46566209
<p>I like James' answer but want to explain why you're having this issue. The reason your double check is failing is that you actually only check for the Path a single time.</p> <p>In the beginning of the code, you check to see if the path exists on these two lines</p> <pre><code>$Networkpath = &quot;X:\Testfolder&quo...
<p>I like James' answer but want to explain why you're having this issue. The reason your double check is failing is that you actually only check for the Path a single time.</p> <p>In the beginning of the code, you check to see if the path exists on these two lines</p> <pre><code>$Networkpath = &quot;X:\Testfolder&quo...
526
powershell
<h1>Powershell: Checking if Network Drive exists, if not, map it then double check</h1> <p>I am trying to write a simple script to check if a network drive is available, map it if it isn't, then double check the mapping worked (to report any issues like the account mapping it has accidentally expired etc). If it fails ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,187
bash
# Powershell: Checking if Network Drive exists, if not, map it then double check I am trying to write a simple script to check if a network drive is available, map it if it isn't, then double check the mapping worked (to report any issues like the account mapping it has accidentally expired etc). If it fails at the do...
I like James' answer but want to explain why you're having this issue. The reason your double check is failing is that you actually only check for the Path a single time. In the beginning of the code, you check to see if the path exists on these two lines ``` $Networkpath = "X:\Testfolder" $pathExists = Test-Path -P...
46366042
How to check if tag exists in if/else
12
2017-09-22 13:31:54
<p>How can I check if a tag exists in my GIT repo. I get as input some tagname and I have to check if it's a valid tag with a <code>if else statement.</code> TAG="tagname"</p> <p>I tried:</p> <pre><code>if [ git rev-parse ${TAG} &gt;/dev/null 2&gt;&amp;1 ]; then echo "tag exists"; else echo "tag does not exist"; ...
17,857
6,077,803
2022-03-18 13:57:14
46,366,360
15
2017-09-22 13:47:19
4,687,135
2017-09-22 13:47:19
https://stackoverflow.com/q/46366042
https://stackoverflow.com/a/46366360
<p>You can use <code>if</code> with a command without <code>test</code> (or it synonym <code>[</code>) and the <code>if</code> command will treat the exit status as the conditional. If it exits with "success" (i.e., <code>0</code>) then it's true, otherwise it's false:</p> <pre><code>if git rev-parse "$TAG" &gt;/dev/...
<p>You can use <code>if</code> with a command without <code>test</code> (or it synonym <code>[</code>) and the <code>if</code> command will treat the exit status as the conditional. If it exits with "success" (i.e., <code>0</code>) then it's true, otherwise it's false:</p> <pre><code>if git rev-parse "$TAG" &gt;/dev/...
119, 387, 2773
bash, git, if-statement
<h1>How to check if tag exists in if/else</h1> <p>How can I check if a tag exists in my GIT repo. I get as input some tagname and I have to check if it's a valid tag with a <code>if else statement.</code> TAG="tagname"</p> <p>I tried:</p> <pre><code>if [ git rev-parse ${TAG} &gt;/dev/null 2&gt;&amp;1 ]; then echo "...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,188
bash
# How to check if tag exists in if/else How can I check if a tag exists in my GIT repo. I get as input some tagname and I have to check if it's a valid tag with a `if else statement.` TAG="tagname" I tried: ``` if [ git rev-parse ${TAG} >/dev/null 2>&1 ]; then echo "tag exists"; else echo "tag does not exist"; `...
You can use `if` with a command without `test` (or it synonym `[`) and the `if` command will treat the exit status as the conditional. If it exits with "success" (i.e., `0`) then it's true, otherwise it's false: ``` if git rev-parse "$TAG" >/dev/null 2>&1; then echo "tag exists"; else echo "tag does not exist" fi ...
44815086
Bitbucket Pipelines run npm fails
12
2017-06-29 01:47:08
<p>I have configured a PHP image for my Bitbucket's Pipelines that runs scripts thru a YML file. I have a laravel repository and want to execute a build command.</p> <p>Though the problem is that on my script, when it runs the <code>npm install</code>, it fails.</p> <p><code>bash: npm: command not found</code></p> <...
9,755
1,781,041
2021-03-30 09:02:33
44,822,491
15
2017-06-29 10:21:42
4,172,960
2017-06-29 10:21:42
https://stackoverflow.com/q/44815086
https://stackoverflow.com/a/44822491
<p>This should help. It'll install Node v8 and NPM v5. Put it before <code>npm install --global gulp-cli</code></p> <pre><code>script: - curl -sL https://deb.nodesource.com/setup_8.x | bash - - apt-get install -y nodejs </code></pre>
<p>This should help. It'll install Node v8 and NPM v5. Put it before <code>npm install --global gulp-cli</code></p> <pre><code>script: - curl -sL https://deb.nodesource.com/setup_8.x | bash - - apt-get install -y nodejs </code></pre>
58, 387, 8337, 46426, 120147
bash, bitbucket, bitbucket-pipelines, linux, node.js
<h1>Bitbucket Pipelines run npm fails</h1> <p>I have configured a PHP image for my Bitbucket's Pipelines that runs scripts thru a YML file. I have a laravel repository and want to execute a build command.</p> <p>Though the problem is that on my script, when it runs the <code>npm install</code>, it fails.</p> <p><code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,189
bash
# Bitbucket Pipelines run npm fails I have configured a PHP image for my Bitbucket's Pipelines that runs scripts thru a YML file. I have a laravel repository and want to execute a build command. Though the problem is that on my script, when it runs the `npm install`, it fails. `bash: npm: command not found` ``` # T...
This should help. It'll install Node v8 and NPM v5. Put it before `npm install --global gulp-cli` ``` script: - curl -sL https://deb.nodesource.com/setup_8.x | bash - - apt-get install -y nodejs ```
44194427
virtualenv activate does not work
12
2017-05-26 05:45:28
<p>I am trying to create a virtual environment to test an api.</p> <p>I can create the environment just fine using <code>virtualenv test</code>, then I can cd into it. When I try to run <code>activate</code>, I get this error:</p> <pre><code>PS C:\Users\Bright Bridge\Desktop\autocomplete_demo\Scripts&gt; activate ac...
82,038
7,864,777
2025-04-24 09:45:17
44,194,501
15
2017-05-26 05:51:39
3,277,713
2017-05-26 05:51:39
https://stackoverflow.com/q/44194427
https://stackoverflow.com/a/44194501
<p>If you press <code>WindowsKey + R</code>, and type <code>cmd</code> when the box comes up, it should bring up the command line interface instead of powershell!</p>
<p>If you press <code>WindowsKey + R</code>, and type <code>cmd</code> when the box comes up, it should bring up the command line interface instead of powershell!</p>
16, 526, 14529
powershell, python, virtualenv
<h1>virtualenv activate does not work</h1> <p>I am trying to create a virtual environment to test an api.</p> <p>I can create the environment just fine using <code>virtualenv test</code>, then I can cd into it. When I try to run <code>activate</code>, I get this error:</p> <pre><code>PS C:\Users\Bright Bridge\Deskto...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,190
bash
# virtualenv activate does not work I am trying to create a virtual environment to test an api. I can create the environment just fine using `virtualenv test`, then I can cd into it. When I try to run `activate`, I get this error: ``` PS C:\Users\Bright Bridge\Desktop\autocomplete_demo\Scripts> activate activate : T...
If you press `WindowsKey + R`, and type `cmd` when the box comes up, it should bring up the command line interface instead of powershell!
43707685
`set -u` (nounset) vs checking whether I have arguments
12
2017-04-30 14:49:31
<p>I'm trying to improve this <a href="https://github.com/SELinuxProject/selinux/blob/5ed45797df92494a137e16eafb64d54490b1d0d5/policycoreutils/scripts/fixfiles" rel="noreferrer">nasty old script</a>. I found an undefined variable error to fix, so I added <code>set -u</code> to catch any similar errors.</p> <p>I get a...
11,499
799,204
2019-06-11 15:08:37
43,707,750
15
2017-04-30 14:54:55
2,302,862
2017-04-30 19:13:55
https://stackoverflow.com/q/43707685
https://stackoverflow.com/a/43707750
<p><code>$#</code> contains the number of arguments, so you can test for <code>$1</code>, <code>$2</code>, etc. to exist before accessing them.</p> <pre><code>if (( $# == 0 )); then # no arguments else # have arguments fi; </code></pre>
<p><code>$#</code> contains the number of arguments, so you can test for <code>$1</code>, <code>$2</code>, etc. to exist before accessing them.</p> <pre><code>if (( $# == 0 )); then # no arguments else # have arguments fi; </code></pre>
387
bash
<h1>`set -u` (nounset) vs checking whether I have arguments</h1> <p>I'm trying to improve this <a href="https://github.com/SELinuxProject/selinux/blob/5ed45797df92494a137e16eafb64d54490b1d0d5/policycoreutils/scripts/fixfiles" rel="noreferrer">nasty old script</a>. I found an undefined variable error to fix, so I added...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,191
bash
# `set -u` (nounset) vs checking whether I have arguments I'm trying to improve this [nasty old script](https://github.com/SELinuxProject/selinux/blob/5ed45797df92494a137e16eafb64d54490b1d0d5/policycoreutils/scripts/fixfiles). I found an undefined variable error to fix, so I added `set -u` to catch any similar errors....
`$#` contains the number of arguments, so you can test for `$1`, `$2`, etc. to exist before accessing them. ``` if (( $# == 0 )); then # no arguments else # have arguments fi; ```
43582494
What is the difference between `sed -i -e` and `sed -ie`?
12
2017-04-24 07:46:41
<p>What is the difference between <code>sed -i -e</code> and <code>sed -ie</code> ? It's not very clear from help <code>sed --help</code></p> <pre><code> -e script, --expression=script add the script to the commands to be executed </code></pre> <p>In second case it creates some backup file?</p> <p>...
31,093
1,179,925
2017-04-24 15:01:32
43,582,772
15
2017-04-24 08:01:55
874,178
2017-04-24 08:01:55
https://stackoverflow.com/q/43582494
https://stackoverflow.com/a/43582772
<p>When you give <code>sed -i -e</code>, <code>sed</code> sees two options.</p> <p>But, When you give <code>sed -ie</code>, <code>sed</code> sees <code>-i</code> option only with <code>suffix</code> as <code>e</code>. That is the reason you got file backup with <code>e</code> suffix.</p> <blockquote> <p>From <code>...
<p>When you give <code>sed -i -e</code>, <code>sed</code> sees two options.</p> <p>But, When you give <code>sed -ie</code>, <code>sed</code> sees <code>-i</code> option only with <code>suffix</code> as <code>e</code>. That is the reason you got file backup with <code>e</code> suffix.</p> <blockquote> <p>From <code>...
34, 387, 5282
bash, sed, unix
<h1>What is the difference between `sed -i -e` and `sed -ie`?</h1> <p>What is the difference between <code>sed -i -e</code> and <code>sed -ie</code> ? It's not very clear from help <code>sed --help</code></p> <pre><code> -e script, --expression=script add the script to the commands to be executed </c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,192
bash
# What is the difference between `sed -i -e` and `sed -ie`? What is the difference between `sed -i -e` and `sed -ie` ? It's not very clear from help `sed --help` ``` -e script, --expression=script add the script to the commands to be executed ``` In second case it creates some backup file? In gen...
When you give `sed -i -e`, `sed` sees two options. But, When you give `sed -ie`, `sed` sees `-i` option only with `suffix` as `e`. That is the reason you got file backup with `e` suffix. > From `man sed`: > > -i[SUFFIX], --in-place[=SUFFIX] > > edit files in place (makes backup if SUFFIX supplied)
34005959
wget: what does this trailing dash represent/do?
12
2015-11-30 19:01:07
<p><code>wget http://ipinfo.io/ip -qO -</code></p> <p>I'm new to <code>bash</code> and can't seem to figure out what that trailing dash character does (or why it is required in this command).</p> <p>Any help is much appreciated.</p>
2,826
1,419,236
2015-11-30 19:23:17
34,005,984
15
2015-11-30 19:02:37
14,122
2015-11-30 19:21:27
https://stackoverflow.com/q/34005959
https://stackoverflow.com/a/34005984
<p>By convention (which not all programs follow), a dash in filename position refers to stdin or stdout, as appropriate. Since this is an argument to <code>-O</code> (output), it refers to stdout.</p> <p>A more verbose way to write this (on Linux or other operating systems where <code>/dev/stdout</code> is usable by p...
<p>By convention (which not all programs follow), a dash in filename position refers to stdin or stdout, as appropriate. Since this is an argument to <code>-O</code> (output), it refers to stdout.</p> <p>A more verbose way to write this (on Linux or other operating systems where <code>/dev/stdout</code> is usable by p...
390, 5583
shell, wget
<h1>wget: what does this trailing dash represent/do?</h1> <p><code>wget http://ipinfo.io/ip -qO -</code></p> <p>I'm new to <code>bash</code> and can't seem to figure out what that trailing dash character does (or why it is required in this command).</p> <p>Any help is much appreciated.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,193
bash
# wget: what does this trailing dash represent/do? `wget http://ipinfo.io/ip -qO -` I'm new to `bash` and can't seem to figure out what that trailing dash character does (or why it is required in this command). Any help is much appreciated.
By convention (which not all programs follow), a dash in filename position refers to stdin or stdout, as appropriate. Since this is an argument to `-O` (output), it refers to stdout. A more verbose way to write this (on Linux or other operating systems where `/dev/stdout` is usable by programs other than just the shel...
33325301
Killing a bash script does not kill child processes
12
2015-10-25 01:45:36
<p>I have written a test script which runs another script to start the server to test. When the tests have completed a <code>SIGKILL</code> message is sent to the server process, however when running the test script again the server throws a <code>EADDRINUSE</code> error (I‘m in a node.js environment) which means the p...
6,618
1,568,890
2019-02-08 11:01:36
33,367,711
15
2015-10-27 12:12:34
155,033
2015-10-28 11:49:45
https://stackoverflow.com/q/33325301
https://stackoverflow.com/a/33367711
<p>To kill a child process and all it's children you may use <a href="https://nodejs.org/api/process.html#process_process_kill_pid_signal"><code>process.kill</code></a> with a negative <code>pid</code> (to kill a process group)</p> <pre><code>var child = child_process.spawn('scripts/start-node.sh', {detached: true}) /...
<p>To kill a child process and all it's children you may use <a href="https://nodejs.org/api/process.html#process_process_kill_pid_signal"><code>process.kill</code></a> with a negative <code>pid</code> (to kill a process group)</p> <pre><code>var child = child_process.spawn('scripts/start-node.sh', {detached: true}) /...
387, 5910, 18570, 26115, 46426
bash, child-process, node.js, process, sigkill
<h1>Killing a bash script does not kill child processes</h1> <p>I have written a test script which runs another script to start the server to test. When the tests have completed a <code>SIGKILL</code> message is sent to the server process, however when running the test script again the server throws a <code>EADDRINUSE<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,194
bash
# Killing a bash script does not kill child processes I have written a test script which runs another script to start the server to test. When the tests have completed a `SIGKILL` message is sent to the server process, however when running the test script again the server throws a `EADDRINUSE` error (I‘m in a node.js ...
To kill a child process and all it's children you may use [`process.kill`](https://nodejs.org/api/process.html#process_process_kill_pid_signal) with a negative `pid` (to kill a process group) ``` var child = child_process.spawn('scripts/start-node.sh', {detached: true}) // Later… process.kill(-child.pid, 'SIGKILL'); `...
27545244
I can't install 'pip' for python
12
2014-12-18 11:14:13
<p>I'm going trough the book Learn Python The Hard Way and i need to install pip.<a href="http://learnpythonthehardway.org/book/ex46.html" rel="noreferrer">(ex46</a>,ex47) So i saved <a href="https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py" rel="noreferrer">get-pip.py</a> on my computer and in pow...
69,535
3,753,471
2021-02-09 12:44:06
27,549,660
15
2014-12-18 15:09:02
393,194
2014-12-18 15:09:02
https://stackoverflow.com/q/27545244
https://stackoverflow.com/a/27549660
<p>Whenever I've installed pip on my Windows machine, it installs to my Python's Scripts folder:</p> <pre><code>c:\Python34\Scripts </code></pre> <p>So to get pip to run on the command line, I had to add that path to my PATH environment variable. You can get to those settings by doing the following (assuming Windows ...
<p>Whenever I've installed pip on my Windows machine, it installs to my Python's Scripts folder:</p> <pre><code>c:\Python34\Scripts </code></pre> <p>So to get pip to run on the command line, I had to add that path to my PATH environment variable. You can get to those settings by doing the following (assuming Windows ...
16, 64, 526, 5119, 59047
pip, powershell, python, python-2.7, windows
<h1>I can't install 'pip' for python</h1> <p>I'm going trough the book Learn Python The Hard Way and i need to install pip.<a href="http://learnpythonthehardway.org/book/ex46.html" rel="noreferrer">(ex46</a>,ex47) So i saved <a href="https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py" rel="noreferrer...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,195
bash
# I can't install 'pip' for python I'm going trough the book Learn Python The Hard Way and i need to install pip.[(ex46](http://learnpythonthehardway.org/book/ex46.html),ex47) So i saved [get-pip.py](https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py) on my computer and in powershell i did : ``` PS ...
Whenever I've installed pip on my Windows machine, it installs to my Python's Scripts folder: ``` c:\Python34\Scripts ``` So to get pip to run on the command line, I had to add that path to my PATH environment variable. You can get to those settings by doing the following (assuming Windows 7 or newer): 1. Right clic...
18685772
How to set Powershell background color programmatically to RGB Value
12
2013-09-08 16:06:27
<p>The current selection of 16 colors from Console Colors is not the right choice for me. I would like to use much darker variants of these for the background.</p> <p>I could definitely set these using the UI and changing the RGB value there.</p> <p><img src="https://i.sstatic.net/pt1Aj.png" alt="Selecting Blue and c...
37,857
2,672,562
2018-12-17 18:42:00
18,686,048
15
2013-09-08 16:35:23
526,535
2013-09-08 16:35:23
https://stackoverflow.com/q/18685772
https://stackoverflow.com/a/18686048
<p>This old post by Lee Holmes explains how you can go about changing the color to any value you want. You have to change the registry - <a href="http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/">http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/</a></p> <pre><code>Push-Location Set-Loca...
<p>This old post by Lee Holmes explains how you can go about changing the color to any value you want. You have to change the registry - <a href="http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/">http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/</a></p> <pre><code>Push-Location Set-Loca...
488, 526
console, powershell
<h1>How to set Powershell background color programmatically to RGB Value</h1> <p>The current selection of 16 colors from Console Colors is not the right choice for me. I would like to use much darker variants of these for the background.</p> <p>I could definitely set these using the UI and changing the RGB value there...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,196
bash
# How to set Powershell background color programmatically to RGB Value The current selection of 16 colors from Console Colors is not the right choice for me. I would like to use much darker variants of these for the background. I could definitely set these using the UI and changing the RGB value there. ![Selecting B...
This old post by Lee Holmes explains how you can go about changing the color to any value you want. You have to change the registry - <http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/> ``` Push-Location Set-Location HKCU:\Console New-Item ".\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe...
17330188
Remove first N lines of a file in place in unix command line
12
2013-06-26 20:49:26
<p>I'm trying to remove the first 37 lines from a very, very large file. I started trying sed and awk, but they seem to require copying the data to a new file. I'm looking for a "remove lines in place" method, that unlike <code>sed -i</code> is not making copies of any kind, but rather is just removing lines from the...
39,975
1,052,117
2023-10-14 06:22:02
17,331,179
15
2013-06-26 21:57:07
1,745,001
2020-09-21 12:40:30
https://stackoverflow.com/q/17330188
https://stackoverflow.com/a/17331179
<p>There's no simple way to do inplace editing using UNIX utilities, but here's one inplace file modification solution that you might be able to modify to work for you (courtesy of Robert Bonomi at <a href="https://groups.google.com/forum/#!topic/comp.unix.shell/5PRRZIP0v64" rel="noreferrer">https://groups.google.com/f...
<p>There's no simple way to do inplace editing using UNIX utilities, but here's one inplace file modification solution that you might be able to modify to work for you (courtesy of Robert Bonomi at <a href="https://groups.google.com/forum/#!topic/comp.unix.shell/5PRRZIP0v64" rel="noreferrer">https://groups.google.com/f...
387, 990, 5282, 11225
awk, bash, command-line-interface, sed
<h1>Remove first N lines of a file in place in unix command line</h1> <p>I'm trying to remove the first 37 lines from a very, very large file. I started trying sed and awk, but they seem to require copying the data to a new file. I'm looking for a "remove lines in place" method, that unlike <code>sed -i</code> is not...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,197
bash
# Remove first N lines of a file in place in unix command line I'm trying to remove the first 37 lines from a very, very large file. I started trying sed and awk, but they seem to require copying the data to a new file. I'm looking for a "remove lines in place" method, that unlike `sed -i` is not making copies of any ...
There's no simple way to do inplace editing using UNIX utilities, but here's one inplace file modification solution that you might be able to modify to work for you (courtesy of Robert Bonomi at <https://groups.google.com/forum/#!topic/comp.unix.shell/5PRRZIP0v64>): ``` bytes=$(head -37 "$file" |wc -c) dd if="$file" b...
17091500
AWK command to print until end of line
12
2013-06-13 15:50:17
<p>I have a quick question regarding the AWK command. I need the command to print until the end of the line on the same line, but then when it gets to the next line I need it to print on another line. The following example will provide better clarity. </p> <p>Say I have a file:</p> <pre><code>0 1 2 3 This is line one...
75,941
1,998,581
2023-11-01 10:19:38
17,091,579
15
2013-06-13 15:53:54
1,983,854
2017-11-16 19:44:12
https://stackoverflow.com/q/17091500
https://stackoverflow.com/a/17091579
<p>It may be more straight-forward to use <code>cut</code>:</p> <pre><code>$ cut -d' ' -f5- file This is line one This is line two This is line three This is line four </code></pre> <p>This says: on space-separated fields, print from the 5th up to the end of the line.</p> <p>If you happen to have multiple spaces i...
<p>It may be more straight-forward to use <code>cut</code>:</p> <pre><code>$ cut -d' ' -f5- file This is line one This is line two This is line three This is line four </code></pre> <p>This says: on space-separated fields, print from the 5th up to the end of the line.</p> <p>If you happen to have multiple spaces i...
34, 390, 990
awk, shell, unix
<h1>AWK command to print until end of line</h1> <p>I have a quick question regarding the AWK command. I need the command to print until the end of the line on the same line, but then when it gets to the next line I need it to print on another line. The following example will provide better clarity. </p> <p>Say I have ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,198
bash
# AWK command to print until end of line I have a quick question regarding the AWK command. I need the command to print until the end of the line on the same line, but then when it gets to the next line I need it to print on another line. The following example will provide better clarity. Say I have a file: ``` 0 1 ...
It may be more straight-forward to use `cut`: ``` $ cut -d' ' -f5- file This is line one This is line two This is line three This is line four ``` This says: on space-separated fields, print from the 5th up to the end of the line. If you happen to have multiple spaces in between fields, you may initially want to s...
16995425
How does cmd > /dev/null 2>&1 work?
12
2013-06-08 02:29:16
<p>I'm reading up on redirecting data to <code>/dev/null</code> and so I tried a simple test:</p> <pre><code>ping a.b.c # which results in an address not found </code></pre> <p>If I try this:</p> <pre><code>ping a.b.c &gt; /dev/null # prints the same error message as the one above </code></pre> <p>However, if I do...
42,798
1,492,471
2017-11-19 02:42:53
16,995,472
15
2013-06-08 02:35:59
2,193,235
2014-10-30 20:15:48
https://stackoverflow.com/q/16995425
https://stackoverflow.com/a/16995472
<p>You are right, <code>2</code> is <code>STDERR</code>, <code>1</code> is <code>STDOUT</code>. When you do <code>2&gt;&amp;1</code> you are saying: "print to <code>STDOUT</code> (<code>1</code>) the things that would go to <code>STDERR</code> (<code>2</code>)". And before that, you said your <code>STDOUT</code> would ...
<p>You are right, <code>2</code> is <code>STDERR</code>, <code>1</code> is <code>STDOUT</code>. When you do <code>2&gt;&amp;1</code> you are saying: "print to <code>STDOUT</code> (<code>1</code>) the things that would go to <code>STDERR</code> (<code>2</code>)". And before that, you said your <code>STDOUT</code> would ...
34, 58, 387, 390
bash, linux, shell, unix
<h1>How does cmd > /dev/null 2>&1 work?</h1> <p>I'm reading up on redirecting data to <code>/dev/null</code> and so I tried a simple test:</p> <pre><code>ping a.b.c # which results in an address not found </code></pre> <p>If I try this:</p> <pre><code>ping a.b.c &gt; /dev/null # prints the same error message as the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,199
bash
# How does cmd > /dev/null 2>&1 work? I'm reading up on redirecting data to `/dev/null` and so I tried a simple test: ``` ping a.b.c # which results in an address not found ``` If I try this: ``` ping a.b.c > /dev/null # prints the same error message as the one above ``` However, if I do this: ``` ping a.b.c > /...
You are right, `2` is `STDERR`, `1` is `STDOUT`. When you do `2>&1` you are saying: "print to `STDOUT` (`1`) the things that would go to `STDERR` (`2`)". And before that, you said your `STDOUT` would go to `/dev/null`. Therefore, nothing is seen. In the examples 1 and 2 you get the output message because it is being pr...
16790666
Reading event log remotely with Get-EventLog in Powershell
12
2013-05-28 11:16:21
<p>I've a powershell script which runs on server(test-server) and reads the log file of his client(DC1).</p> <ul> <li>Both sides can ping to each other.</li> <li>On both sides, firewalls are disabled.</li> <li><p>Remote Desktop and Remote Assistance are enabled on DC1.</p> <pre><code>Get-EventLog System -ComputerName...
56,974
1,816,781
2017-08-24 10:01:40
16,807,919
15
2013-05-29 07:28:07
1,816,781
2016-09-23 14:12:27
https://stackoverflow.com/q/16790666
https://stackoverflow.com/a/16807919
<p>@Lars Truijens's suggestion solved my issue. But other suggestions are also important to check.</p> <p>So, here is the checklist if you get this kind of error when you try to get log files remotely:</p> <ul> <li>Disable or set firewall settings on both sides.</li> <li>Enable Remote Desktop and Remote Assistance on...
<p>@Lars Truijens's suggestion solved my issue. But other suggestions are also important to check.</p> <p>So, here is the checklist if you get this kind of error when you try to get log files remotely:</p> <ul> <li>Disable or set firewall settings on both sides.</li> <li>Enable Remote Desktop and Remote Assistance on...
526, 63177, 153947
powershell, powershell-cmdlet, powershell-remoting
<h1>Reading event log remotely with Get-EventLog in Powershell</h1> <p>I've a powershell script which runs on server(test-server) and reads the log file of his client(DC1).</p> <ul> <li>Both sides can ping to each other.</li> <li>On both sides, firewalls are disabled.</li> <li><p>Remote Desktop and Remote Assistance a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,200
bash
# Reading event log remotely with Get-EventLog in Powershell I've a powershell script which runs on server(test-server) and reads the log file of his client(DC1). - Both sides can ping to each other. - On both sides, firewalls are disabled. - Remote Desktop and Remote Assistance are enabled on DC1. ``` Get-Event...
@Lars Truijens's suggestion solved my issue. But other suggestions are also important to check. So, here is the checklist if you get this kind of error when you try to get log files remotely: - Disable or set firewall settings on both sides. - Enable Remote Desktop and Remote Assistance on client machine. - Can you p...
15932356
Bash script - how to fill array?
12
2013-04-10 17:18:12
<p>Let's say I have this directory structure:</p> <pre><code>DIRECTORY: .........a .........b .........c .........d </code></pre> <p>What I want to do is: I want to store elements of a directory in an array</p> <p>something like : <code>array = ls /home/user/DIRECTORY</code></p> <p>so that <code>array[0]</code...
29,472
1,926,550
2021-12-01 13:12:51
15,932,690
15
2013-04-10 17:37:53
1,155,000
2013-04-10 17:37:53
https://stackoverflow.com/q/15932356
https://stackoverflow.com/a/15932690
<p>You can't simply do <code>array = ls /home/user/DIRECTORY</code>, because - even with proper syntax - it wouldn't give you an array, but a string that you would have to parse, and <a href="http://mywiki.wooledge.org/ParsingLs" rel="noreferrer">Parsing <code>ls</code> is punishable by law</a>. You can, however, use b...
<p>You can't simply do <code>array = ls /home/user/DIRECTORY</code>, because - even with proper syntax - it wouldn't give you an array, but a string that you would have to parse, and <a href="http://mywiki.wooledge.org/ParsingLs" rel="noreferrer">Parsing <code>ls</code> is punishable by law</a>. You can, however, use b...
114, 387, 3589
arrays, bash, ls
<h1>Bash script - how to fill array?</h1> <p>Let's say I have this directory structure:</p> <pre><code>DIRECTORY: .........a .........b .........c .........d </code></pre> <p>What I want to do is: I want to store elements of a directory in an array</p> <p>something like : <code>array = ls /home/user/DIRECTORY</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,201
bash
# Bash script - how to fill array? Let's say I have this directory structure: ``` DIRECTORY: .........a .........b .........c .........d ``` What I want to do is: I want to store elements of a directory in an array something like : `array = ls /home/user/DIRECTORY` so that `array[0]` contains name of first fil...
You can't simply do `array = ls /home/user/DIRECTORY`, because - even with proper syntax - it wouldn't give you an array, but a string that you would have to parse, and [Parsing `ls` is punishable by law](http://mywiki.wooledge.org/ParsingLs). You can, however, use built-in Bash constructs to achieve what you want : `...
15520796
Scripts for listing all the distinct characters in a text file
12
2013-03-20 10:19:27
<p>E.g.</p> <p>Given a file <code>input.txt</code>, which has the following content:</p> <pre><code>He likes cats, really? </code></pre> <p>the output would be like:</p> <pre><code>H e l i k s c a t , r l y ? </code></pre> <p>Note the order of characters in output does not matter.</p>
7,345
1,258,409
2013-03-20 11:15:36
15,520,905
15
2013-03-20 10:24:35
714,501
2013-03-20 10:24:35
https://stackoverflow.com/q/15520796
https://stackoverflow.com/a/15520905
<p>How about:</p> <pre><code>echo "He likes cats, really?" | fold -w1 | sort -u </code></pre>
<p>How about:</p> <pre><code>echo "He likes cats, really?" | fold -w1 | sort -u </code></pre>
387, 990, 5282
awk, bash, sed
<h1>Scripts for listing all the distinct characters in a text file</h1> <p>E.g.</p> <p>Given a file <code>input.txt</code>, which has the following content:</p> <pre><code>He likes cats, really? </code></pre> <p>the output would be like:</p> <pre><code>H e l i k s c a t , r l y ? </code></pre> <p>Note the order o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,202
bash
# Scripts for listing all the distinct characters in a text file E.g. Given a file `input.txt`, which has the following content: ``` He likes cats, really? ``` the output would be like: ``` H e l i k s c a t , r l y ? ``` Note the order of characters in output does not matter.
How about: ``` echo "He likes cats, really?" | fold -w1 | sort -u ```
14103197
How can I tell if I'm in a remote PowerShell session?
12
2012-12-31 15:12:28
<p>I would like to execute code that is specific to remote PSSessions. That is, the code doesn't apply locally, but applies to all remote sessions.</p> <p>Is there any environment variable, function or cmdlet that would effectively return true if I'm in an active PSSession and false if I'm running locally?</p>
3,862
817,630
2022-05-05 13:33:36
14,103,639
15
2012-12-31 16:01:35
9,833
2016-07-04 20:32:06
https://stackoverflow.com/q/14103197
https://stackoverflow.com/a/14103639
<p>Check if the <code>$PSSenderInfo</code> variable exists. From <em>about_Automatic_Variables</em>:</p> <blockquote> <h3><code>$PSSenderInfo</code></h3> <p>Contains information about the user who started the PSSession, including the user identity and the time zone of the originating computer. This variabl...
<p>Check if the <code>$PSSenderInfo</code> variable exists. From <em>about_Automatic_Variables</em>:</p> <blockquote> <h3><code>$PSSenderInfo</code></h3> <p>Contains information about the user who started the PSSession, including the user identity and the time zone of the originating computer. This variabl...
526, 63177
powershell, powershell-remoting
<h1>How can I tell if I'm in a remote PowerShell session?</h1> <p>I would like to execute code that is specific to remote PSSessions. That is, the code doesn't apply locally, but applies to all remote sessions.</p> <p>Is there any environment variable, function or cmdlet that would effectively return true if I'm in an...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,203
bash
# How can I tell if I'm in a remote PowerShell session? I would like to execute code that is specific to remote PSSessions. That is, the code doesn't apply locally, but applies to all remote sessions. Is there any environment variable, function or cmdlet that would effectively return true if I'm in an active PSSessio...
Check if the `$PSSenderInfo` variable exists. From *about_Automatic_Variables*: > ### `$PSSenderInfo` > > Contains information about the user who started the PSSession, > including the user identity and the time zone of the originating > computer. This variable is available only in PSSessions. > > The `$PSSenderInfo` ...
13371407
How do I alias a PowerShell script to be called from prompt?
12
2012-11-14 00:44:51
<p>I have a PowerShell script that opens all files and programs related to my development environment. Rather than typing</p> <pre><code>&gt; &amp;.\mysetup.ps1 </code></pre> <p>is there some way I can alias it to just type</p> <pre><code>&gt; gosetup </code></pre> <p>?</p> <p>Ideally I'll use this functionality f...
16,084
992,954
2017-06-24 20:23:49
13,371,499
15
2012-11-14 00:54:55
790,107
2017-06-24 20:23:49
https://stackoverflow.com/q/13371407
https://stackoverflow.com/a/13371499
<ul> <li>First you need to set up your PowerShell profile, if you haven't done so already.</li> <li>Create a directory where you want to keep your aliased scripts (I use C:\ps).</li> <li><p>In your profile, add the following lines:</p> <pre><code>$ps_script_dir = "C:\path\to\scripts" New-Alias &lt;alias name&gt; $ps_...
<ul> <li>First you need to set up your PowerShell profile, if you haven't done so already.</li> <li>Create a directory where you want to keep your aliased scripts (I use C:\ps).</li> <li><p>In your profile, add the following lines:</p> <pre><code>$ps_script_dir = "C:\path\to\scripts" New-Alias &lt;alias name&gt; $ps_...
526, 2631
cmd, powershell
<h1>How do I alias a PowerShell script to be called from prompt?</h1> <p>I have a PowerShell script that opens all files and programs related to my development environment. Rather than typing</p> <pre><code>&gt; &amp;.\mysetup.ps1 </code></pre> <p>is there some way I can alias it to just type</p> <pre><code>&gt; gos...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,204
bash
# How do I alias a PowerShell script to be called from prompt? I have a PowerShell script that opens all files and programs related to my development environment. Rather than typing ``` > &.\mysetup.ps1 ``` is there some way I can alias it to just type ``` > gosetup ``` ? Ideally I'll use this functionality for o...
- First you need to set up your PowerShell profile, if you haven't done so already. - Create a directory where you want to keep your aliased scripts (I use C:\ps). - In your profile, add the following lines: ``` $ps_script_dir = "C:\path\to\scripts" New-Alias <alias name> $ps_script_dir\<script name> ``` - Op...
13018305
Difference between mkdir and mkdir -p?
12
2012-10-22 19:22:17
<p>I've been following Learn Code the Hard Way's tutorial on learning how to utilize the command line interface in PowerShell. In <a href="http://cli.learncodethehardway.org/book/cli-crash-coursech8.html">this</a> article, it tells me to use the command <code>mkdir -p i\like\icecream</code>. At the bottom, it explains ...
18,362
1,602,525
2018-09-05 12:57:24
13,018,424
15
2012-10-22 19:29:26
1,358
2015-08-20 12:04:33
https://stackoverflow.com/q/13018305
https://stackoverflow.com/a/13018424
<p>PowerShell does its best to determine what parameter you mean even if you don't give it fully. Thus if you use the <code>-p</code> parameter, you are actually using <code>-path</code>.</p> <p>For the mkdir function, the <code>-path</code> parameter tells the function the path to create. <code>-path</code> is also b...
<p>PowerShell does its best to determine what parameter you mean even if you don't give it fully. Thus if you use the <code>-p</code> parameter, you are actually using <code>-path</code>.</p> <p>For the mkdir function, the <code>-path</code> parameter tells the function the path to create. <code>-path</code> is also b...
526, 1231
command-line, powershell
<h1>Difference between mkdir and mkdir -p?</h1> <p>I've been following Learn Code the Hard Way's tutorial on learning how to utilize the command line interface in PowerShell. In <a href="http://cli.learncodethehardway.org/book/cli-crash-coursech8.html">this</a> article, it tells me to use the command <code>mkdir -p i\l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,205
bash
# Difference between mkdir and mkdir -p? I've been following Learn Code the Hard Way's tutorial on learning how to utilize the command line interface in PowerShell. In [this](http://cli.learncodethehardway.org/book/cli-crash-coursech8.html) article, it tells me to use the command `mkdir -p i\like\icecream`. At the bot...
PowerShell does its best to determine what parameter you mean even if you don't give it fully. Thus if you use the `-p` parameter, you are actually using `-path`. For the mkdir function, the `-path` parameter tells the function the path to create. `-path` is also by default the first argument to the function if no exp...
10129747
Conditional trailing space with bash programmable completion
12
2012-04-12 18:40:51
<p>I'm creating a function to provide programmable completion for a command that I use (with much help from <a href="http://www.debian-administration.org/articles/317" rel="noreferrer">http://www.debian-administration.org/articles/317</a>). The shell script usage is as follows:</p> <pre><code>script.sh command [comman...
1,894
920,824
2012-04-12 18:55:24
10,129,950
15
2012-04-12 18:55:24
1,054,459
2012-04-12 18:55:24
https://stackoverflow.com/q/10129747
https://stackoverflow.com/a/10129950
<p>First you need to add = to the COMPREPLY:</p> <pre><code>COMPREPLY=( $(compgen -W "--a_foo= --b_foo=" -- ${cur}) ) </code></pre> <p>next you need to tell completion not to add space after = with</p> <pre><code>compopt -o nospace </code></pre> <p>So, you script lines should be:</p> <pre><code>foo) COMPREPLY=( ...
<p>First you need to add = to the COMPREPLY:</p> <pre><code>COMPREPLY=( $(compgen -W "--a_foo= --b_foo=" -- ${cur}) ) </code></pre> <p>next you need to tell completion not to add space after = with</p> <pre><code>compopt -o nospace </code></pre> <p>So, you script lines should be:</p> <pre><code>foo) COMPREPLY=( ...
387, 59778
bash, bash-completion
<h1>Conditional trailing space with bash programmable completion</h1> <p>I'm creating a function to provide programmable completion for a command that I use (with much help from <a href="http://www.debian-administration.org/articles/317" rel="noreferrer">http://www.debian-administration.org/articles/317</a>). The shell...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,206
bash
# Conditional trailing space with bash programmable completion I'm creating a function to provide programmable completion for a command that I use (with much help from <http://www.debian-administration.org/articles/317>). The shell script usage is as follows: ``` script.sh command [command options] ``` where command...
First you need to add = to the COMPREPLY: ``` COMPREPLY=( $(compgen -W "--a_foo= --b_foo=" -- ${cur}) ) ``` next you need to tell completion not to add space after = with ``` compopt -o nospace ``` So, you script lines should be: ``` foo) COMPREPLY=( $(compgen -W "--a_foo= --b_foo=" -- ${cur}) ); compopt -o nosp...
8849681
Bash join command
12
2012-01-13 11:13:01
<p>Infile1:</p> <pre><code>1 a 3 c 4 d 6 f </code></pre> <p>Infile2:</p> <pre><code>1 a 2 b 5 e 6 f 7 g 8 h </code></pre> <p>How do I join these files with the unix join command to get this output:</p> <pre><code>1 aa 2 b 3 c 4 d 5 e 6 ff 7 g 8 h </code></pre> <p>Dogbanes answer worked but... when I apply dogba...
52,316
1,045,523
2012-01-13 15:49:20
8,849,764
15
2012-01-13 11:20:22
7,412
2012-01-13 11:20:22
https://stackoverflow.com/q/8849681
https://stackoverflow.com/a/8849764
<p>First <code>sort</code> both files. Then use <code>join</code> to join on the first field of both files. You also need to pipe the output through <code>sed</code> if you want to remove the space and thus convert <code>a a</code> into <code>aa</code>. This is shown below:</p> <pre><code>$ join -t " " -1 1 -2 1 -a 1 ...
<p>First <code>sort</code> both files. Then use <code>join</code> to join on the first field of both files. You also need to pipe the output through <code>sed</code> if you want to remove the space and thus convert <code>a a</code> into <code>aa</code>. This is shown below:</p> <pre><code>$ join -t " " -1 1 -2 1 -a 1 ...
34, 58, 387, 3626
bash, join, linux, unix
<h1>Bash join command</h1> <p>Infile1:</p> <pre><code>1 a 3 c 4 d 6 f </code></pre> <p>Infile2:</p> <pre><code>1 a 2 b 5 e 6 f 7 g 8 h </code></pre> <p>How do I join these files with the unix join command to get this output:</p> <pre><code>1 aa 2 b 3 c 4 d 5 e 6 ff 7 g 8 h </code></pre> <p>Dogbanes answer worke...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,207
bash
# Bash join command Infile1: ``` 1 a 3 c 4 d 6 f ``` Infile2: ``` 1 a 2 b 5 e 6 f 7 g 8 h ``` How do I join these files with the unix join command to get this output: ``` 1 aa 2 b 3 c 4 d 5 e 6 ff 7 g 8 h ``` Dogbanes answer worked but... when I apply dogbanes answer on this file: ``` 27 27 28 22 29 37 30 ...
First `sort` both files. Then use `join` to join on the first field of both files. You also need to pipe the output through `sed` if you want to remove the space and thus convert `a a` into `aa`. This is shown below: ``` $ join -t " " -1 1 -2 1 -a 1 -a 2 <(sort file1) <(sort file2) | sed 's/ \([a-z]\) / \1/g' 1 aa 2 ...
8378232
How do I call a local shell script from a web server?
12
2011-12-04 20:06:41
<p>I am running Ubuntu 11 and I would like to setup a simple webserver that responds to an http request by calling a local script with the GET or POST parameters. This script (already written) does some stuff and creates a file. This file should be made available at a URL, and the webserver should then make an http re...
45,067
304,658
2017-06-08 00:00:29
8,378,332
15
2011-12-04 20:23:29
1,074,592
2011-12-04 20:23:29
https://stackoverflow.com/q/8378232
https://stackoverflow.com/a/8378332
<p><a href="http://www.cyberciti.biz/faq/run-shell-script-from-web-page/" rel="noreferrer">This tutorial looks good</a>, but it's a bit brief.</p> <p>I have apache installed. If you don't: <code>sudo apt-get install apache2</code>.</p> <pre><code>cd /usr/lib/cgi-bin # Make a file and let everyone execute it sudo to...
<p><a href="http://www.cyberciti.biz/faq/run-shell-script-from-web-page/" rel="noreferrer">This tutorial looks good</a>, but it's a bit brief.</p> <p>I have apache installed. If you don't: <code>sudo apt-get install apache2</code>.</p> <pre><code>cd /usr/lib/cgi-bin # Make a file and let everyone execute it sudo to...
80, 390, 549, 1074, 6605
apache, nginx, shell, ubuntu, webserver
<h1>How do I call a local shell script from a web server?</h1> <p>I am running Ubuntu 11 and I would like to setup a simple webserver that responds to an http request by calling a local script with the GET or POST parameters. This script (already written) does some stuff and creates a file. This file should be made av...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,208
bash
# How do I call a local shell script from a web server? I am running Ubuntu 11 and I would like to setup a simple webserver that responds to an http request by calling a local script with the GET or POST parameters. This script (already written) does some stuff and creates a file. This file should be made available at...
[This tutorial looks good](http://www.cyberciti.biz/faq/run-shell-script-from-web-page/), but it's a bit brief. I have apache installed. If you don't: `sudo apt-get install apache2`. ``` cd /usr/lib/cgi-bin # Make a file and let everyone execute it sudo touch test.sh && chmod a+x test.sh ``` Then put the some code ...
7799045
Best way to capture output from system command to a text file?
12
2011-10-17 20:17:23
<p>I’m trying to capture output from using Perl’s <code>system</code> function to execute and redirect a system command’s ouptut to a file, but for some reason I’m not getting the whole output.</p> <p>I’m using the following method:</p> <pre><code>system("example.exe &gt;output.txt"); </code></pre> <p>What’s wrong w...
43,804
965,772
2015-12-11 07:43:03
7,801,293
15
2011-10-18 00:48:24
468,327
2011-10-18 11:36:22
https://stackoverflow.com/q/7799045
https://stackoverflow.com/a/7801293
<p>Same as <a href="https://stackoverflow.com/q/7799045#7799174">MVS's answer</a>, but modern and safe.</p> <pre><code>use strict; use warnings; open (my $file, '&gt;', 'output.txt') or die "Could not open file: $!"; my $output = `example.exe`; die "$!" if $?; print $file $output; </code></pre> <p>easier</p> <pre...
<p>Same as <a href="https://stackoverflow.com/q/7799045#7799174">MVS's answer</a>, but modern and safe.</p> <pre><code>use strict; use warnings; open (my $file, '&gt;', 'output.txt') or die "Could not open file: $!"; my $output = `example.exe`; die "$!" if $?; print $file $output; </code></pre> <p>easier</p> <pre...
390, 580, 5163, 7932, 26698
exec, io-redirection, perl, shell, system
<h1>Best way to capture output from system command to a text file?</h1> <p>I’m trying to capture output from using Perl’s <code>system</code> function to execute and redirect a system command’s ouptut to a file, but for some reason I’m not getting the whole output.</p> <p>I’m using the following method:</p> <pre><cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,209
bash
# Best way to capture output from system command to a text file? I’m trying to capture output from using Perl’s `system` function to execute and redirect a system command’s ouptut to a file, but for some reason I’m not getting the whole output. I’m using the following method: ``` system("example.exe >output.txt"); `...
Same as [MVS's answer](https://stackoverflow.com/q/7799045#7799174), but modern and safe. ``` use strict; use warnings; open (my $file, '>', 'output.txt') or die "Could not open file: $!"; my $output = `example.exe`; die "$!" if $?; print $file $output; ``` easier ``` use strict; use warnings; use autodie; open...
6049323
How do I edit XML using Powershell?
12
2011-05-18 18:26:33
<p>I'm trying to edit some xml in Powershell. Here's what I'm doing:</p> <pre><code>$path = 'C:\Projects\NuGetTestPackage\NuGetTestPackage' $projName = 'NuGetTestPackage1.csproj' cd $path $file = gi $projName $pattern = 'TextTemplatingFileGenerator' $xml = [xml](gc $file) $node = [xml] $xml.Project.ItemGroup.None.Gene...
13,320
441,862
2011-05-19 23:50:00
6,050,539
15
2011-05-18 20:19:25
153,982
2011-05-19 23:50:00
https://stackoverflow.com/q/6049323
https://stackoverflow.com/a/6050539
<p>This is happening because you have more than one "ItemGroup" element and more than one "None" element. At that point, ItemGroup is a collection and doesn't have a ".None" property. You'd be better off using XPath IMO e.g.:</p> <pre><code>$ns = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} $patter...
<p>This is happening because you have more than one "ItemGroup" element and more than one "None" element. At that point, ItemGroup is a collection and doesn't have a ".None" property. You'd be better off using XPath IMO e.g.:</p> <pre><code>$ns = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} $patter...
19, 526
powershell, xml
<h1>How do I edit XML using Powershell?</h1> <p>I'm trying to edit some xml in Powershell. Here's what I'm doing:</p> <pre><code>$path = 'C:\Projects\NuGetTestPackage\NuGetTestPackage' $projName = 'NuGetTestPackage1.csproj' cd $path $file = gi $projName $pattern = 'TextTemplatingFileGenerator' $xml = [xml](gc $file) $...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,210
bash
# How do I edit XML using Powershell? I'm trying to edit some xml in Powershell. Here's what I'm doing: ``` $path = 'C:\Projects\NuGetTestPackage\NuGetTestPackage' $projName = 'NuGetTestPackage1.csproj' cd $path $file = gi $projName $pattern = 'TextTemplatingFileGenerator' $xml = [xml](gc $file) $node = [xml] $xml.Pr...
This is happening because you have more than one "ItemGroup" element and more than one "None" element. At that point, ItemGroup is a collection and doesn't have a ".None" property. You'd be better off using XPath IMO e.g.: ``` $ns = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} $pattern = 'TextTemplat...
5954503
Powershell hashtable does not write to file as expected - receive only "System.Collections" rows
12
2011-05-10 18:14:56
<p>Can someone please explain <strong><em>Why</em></strong> my first examples don't work, and why adding in a ForEach-Object solves the problem? Thanks in advance!</p> <hr> <p>I parsed the return from a command into a hashtable (sample at end of post) and want to log the information to a file as part of my processin...
45,760
594,373
2024-04-25 04:54:16
5,956,155
15
2011-05-10 20:36:40
75,224
2011-05-10 20:36:40
https://stackoverflow.com/q/5954503
https://stackoverflow.com/a/5956155
<p>Answering the <strong>why</strong> part, you obviously have a solution :)</p> <p>In your first example</p> <pre><code>$ht | Add-Content log.txt </code></pre> <p>PowerShell takes <code>$ht</code> and tries to somehow convert it to a string so that it can be stored via <code>Add-Content</code>. Because there is no ...
<p>Answering the <strong>why</strong> part, you obviously have a solution :)</p> <p>In your first example</p> <pre><code>$ht | Add-Content log.txt </code></pre> <p>PowerShell takes <code>$ht</code> and tries to somehow convert it to a string so that it can be stored via <code>Add-Content</code>. Because there is no ...
526, 5189
hashtable, powershell
<h1>Powershell hashtable does not write to file as expected - receive only "System.Collections" rows</h1> <p>Can someone please explain <strong><em>Why</em></strong> my first examples don't work, and why adding in a ForEach-Object solves the problem? Thanks in advance!</p> <hr> <p>I parsed the return from a command ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,211
bash
# Powershell hashtable does not write to file as expected - receive only "System.Collections" rows Can someone please explain ***Why*** my first examples don't work, and why adding in a ForEach-Object solves the problem? Thanks in advance! --- I parsed the return from a command into a hashtable (sample at end of pos...
Answering the **why** part, you obviously have a solution :) In your first example ``` $ht | Add-Content log.txt ``` PowerShell takes `$ht` and tries to somehow convert it to a string so that it can be stored via `Add-Content`. Because there is no conversion defined for the hashtable, only the type name is returned ...
5550895
Shell script changing desktop wallpaper
12
2011-04-05 11:13:05
<p>Could you write the easiest possible shell script that will change the desktop wallpaper (in Ubuntu) in regular intervals (e.g. 1 minute).</p> <p>Wallpapers will be saved in particular directory (e.g. $HOME/wallpapers). I need only basic functionality.</p> <p>1) select random wallpaper from <code>$HOME/wallpapers<...
35,350
653,379
2023-05-23 22:20:16
5,551,080
15
2011-04-05 11:29:16
531,222
2011-04-05 12:24:05
https://stackoverflow.com/q/5550895
https://stackoverflow.com/a/5551080
<pre><code>#!/bin/bash wallpaperdir='$HOME/wallpaper' files=($wallpaperdir/*) randompic=`printf "%s\n" "${files[RANDOM % ${#files[@]}]}"` gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$randompic" </code></pre> <p>Save this script and edit your with the command "crontab -e" (it launches an edit...
<pre><code>#!/bin/bash wallpaperdir='$HOME/wallpaper' files=($wallpaperdir/*) randompic=`printf "%s\n" "${files[RANDOM % ${#files[@]}]}"` gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$randompic" </code></pre> <p>Save this script and edit your with the command "crontab -e" (it launches an edit...
387, 390, 3294, 9519
bash, gnome, shell, wallpaper
<h1>Shell script changing desktop wallpaper</h1> <p>Could you write the easiest possible shell script that will change the desktop wallpaper (in Ubuntu) in regular intervals (e.g. 1 minute).</p> <p>Wallpapers will be saved in particular directory (e.g. $HOME/wallpapers). I need only basic functionality.</p> <p>1) sel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,212
bash
# Shell script changing desktop wallpaper Could you write the easiest possible shell script that will change the desktop wallpaper (in Ubuntu) in regular intervals (e.g. 1 minute). Wallpapers will be saved in particular directory (e.g. $HOME/wallpapers). I need only basic functionality. 1) select random wallpaper fr...
``` #!/bin/bash wallpaperdir='$HOME/wallpaper' files=($wallpaperdir/*) randompic=`printf "%s\n" "${files[RANDOM % ${#files[@]}]}"` gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$randompic" ``` Save this script and edit your with the command "crontab -e" (it launches an editor where you put thi...
5101506
How does shell execute piped commands?
12
2011-02-24 07:08:52
<p>I want to understand that how does shell executes piped commands ? e.g. cat | more. I am aware that for executing a normal command shell does a fork, execute it and then child returns. But how does shell internally handle the execution of piped commands ?</p>
3,797
248,132
2011-02-24 07:46:29
5,101,657
15
2011-02-24 07:30:36
265,804
2011-02-24 07:46:29
https://stackoverflow.com/q/5101506
https://stackoverflow.com/a/5101657
<p>Considering for example <code>cat | grep</code>, the shell first forks itself to start <code>cat</code>, and then forks itself once more to start <code>grep</code>.</p> <p>Before calling one of the <code>exec*</code> family of functions in the two newly created processes to start the two programs, the tricky part i...
<p>Considering for example <code>cat | grep</code>, the shell first forks itself to start <code>cat</code>, and then forks itself once more to start <code>grep</code>.</p> <p>Before calling one of the <code>exec*</code> family of functions in the two newly created processes to start the two programs, the tricky part i...
34, 390
shell, unix
<h1>How does shell execute piped commands?</h1> <p>I want to understand that how does shell executes piped commands ? e.g. cat | more. I am aware that for executing a normal command shell does a fork, execute it and then child returns. But how does shell internally handle the execution of piped commands ?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,213
bash
# How does shell execute piped commands? I want to understand that how does shell executes piped commands ? e.g. cat | more. I am aware that for executing a normal command shell does a fork, execute it and then child returns. But how does shell internally handle the execution of piped commands ?
Considering for example `cat | grep`, the shell first forks itself to start `cat`, and then forks itself once more to start `grep`. Before calling one of the `exec*` family of functions in the two newly created processes to start the two programs, the tricky part is setting up the pipe and redirecting the descriptors....
4834353
What is up with [A-Z] meaning [A-Za-z]?
12
2011-01-29 00:43:55
<p>I've noticed for a while now that, on some of the Unix-based systems I use at least, <code>ls [A-Z]*</code> has been giving me the results I would anticipate from <code>ls [A-Za-z]*</code>, leaving me unable to easily get a list of just the goddamned files that start with capital letters. I just now ran into the sa...
5,121
47,529
2011-01-29 01:47:45
4,834,363
15
2011-01-29 00:47:06
20,862
2011-01-29 00:47:06
https://stackoverflow.com/q/4834353
https://stackoverflow.com/a/4834363
<p>It's actually <code>[A-Za-y]</code>, and it has to do with language collation. If you want to override it then set <code>$LC_COLLATE</code> appropriately; either of <code>C</code> or <code>POSIX</code> should do.</p>
<p>It's actually <code>[A-Za-y]</code>, and it has to do with language collation. If you want to override it then set <code>$LC_COLLATE</code> appropriately; either of <code>C</code> or <code>POSIX</code> should do.</p>
18, 34, 58, 390, 1271
grep, linux, regex, shell, unix
<h1>What is up with [A-Z] meaning [A-Za-z]?</h1> <p>I've noticed for a while now that, on some of the Unix-based systems I use at least, <code>ls [A-Z]*</code> has been giving me the results I would anticipate from <code>ls [A-Za-z]*</code>, leaving me unable to easily get a list of just the goddamned files that start ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,214
bash
# What is up with [A-Z] meaning [A-Za-z]? I've noticed for a while now that, on some of the Unix-based systems I use at least, `ls [A-Z]*` has been giving me the results I would anticipate from `ls [A-Za-z]*`, leaving me unable to easily get a list of just the goddamned files that start with capital letters. I just no...
It's actually `[A-Za-y]`, and it has to do with language collation. If you want to override it then set `$LC_COLLATE` appropriately; either of `C` or `POSIX` should do.
4009154
PowerShell ForEach / Piping confusion
12
2010-10-24 16:33:14
<p>I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might be able to explain the problem to me :) )</p> ...
39,286
485,693
2010-10-24 17:26:07
4,009,430
15
2010-10-24 17:26:07
153,982
2010-10-24 17:26:07
https://stackoverflow.com/q/4009154
https://stackoverflow.com/a/4009430
<p>This is indeed confusing. For now a work-around is to grab the items like so:</p> <pre><code>$items = @(Get-TfsItemHistory . -r -Stopafter 25 | Foreach {$_.WorkItems.Count &gt; $null; $_}) </code></pre> <p>This accesses the WorkItems collection which seems to cause this property to be populated (I kno...
<p>This is indeed confusing. For now a work-around is to grab the items like so:</p> <pre><code>$items = @(Get-TfsItemHistory . -r -Stopafter 25 | Foreach {$_.WorkItems.Count &gt; $null; $_}) </code></pre> <p>This accesses the WorkItems collection which seems to cause this property to be populated (I kno...
526, 631, 19486
foreach, piping, powershell
<h1>PowerShell ForEach / Piping confusion</h1> <p>I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,215
bash
# PowerShell ForEach / Piping confusion I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might be able t...
This is indeed confusing. For now a work-around is to grab the items like so: ``` $items = @(Get-TfsItemHistory . -r -Stopafter 25 | Foreach {$_.WorkItems.Count > $null; $_}) ``` This accesses the WorkItems collection which seems to cause this property to be populated (I know - WTF?). I tend to use `@()` ...
3983215
PowerShell CmdLet as Visual Studio External Tool
12
2010-10-20 23:48:11
<p>I am attempting to add a PowerShell cmdlet as an external tool in Visual Studio 2010, but whenever I call the external tool I get:</p> <blockquote> <p>{foo} cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.</p> </blockquote> ...
3,104
143,327
2010-10-21 02:22:04
3,983,376
15
2010-10-21 00:26:15
153,982
2010-10-21 02:22:04
https://stackoverflow.com/q/3983215
https://stackoverflow.com/a/3983376
<p>Are you running on a x64 system? If so, you have to set the execution for both x86 and x64 PowerShell. You can also pass the ExecutionPolicy directly as a parameter to Powershell (2.0) via the command line:</p> <pre><code>powershell.exe -ExecutionPolicy RemoteSigned -Command "&amp;{ foo }" </code></pre>
<p>Are you running on a x64 system? If so, you have to set the execution for both x86 and x64 PowerShell. You can also pass the ExecutionPolicy directly as a parameter to Powershell (2.0) via the command line:</p> <pre><code>powershell.exe -ExecutionPolicy RemoteSigned -Command "&amp;{ foo }" </code></pre>
526, 14456
powershell, visual-studio-2010
<h1>PowerShell CmdLet as Visual Studio External Tool</h1> <p>I am attempting to add a PowerShell cmdlet as an external tool in Visual Studio 2010, but whenever I call the external tool I get:</p> <blockquote> <p>{foo} cannot be loaded because the execution of scripts is disabled on this system. Please see "get-h...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,216
bash
# PowerShell CmdLet as Visual Studio External Tool I am attempting to add a PowerShell cmdlet as an external tool in Visual Studio 2010, but whenever I call the external tool I get: > {foo} cannot be loaded because the > execution of scripts is disabled on > this system. Please see "get-help > about_signing" for more...
Are you running on a x64 system? If so, you have to set the execution for both x86 and x64 PowerShell. You can also pass the ExecutionPolicy directly as a parameter to Powershell (2.0) via the command line: ``` powershell.exe -ExecutionPolicy RemoteSigned -Command "&{ foo }" ```
2721946
Cross-platform getopt for a shell script
12
2010-04-27 14:19:09
<p>I've just found out that <code>getopt</code> is not cross-platform (in particular for FreeBSD and Linux). What is the best workaround for this issue?</p>
12,281
268,224
2015-10-16 17:55:05
2,728,625
15
2010-04-28 10:30:31
26,428
2015-10-16 17:55:05
https://stackoverflow.com/q/2721946
https://stackoverflow.com/a/2728625
<p>Use <code>getopts</code> (with an &quot;s&quot;).</p> <p>According to <a href="http://mywiki.wooledge.org/BashFAQ/035" rel="noreferrer">Bash FAQ 35</a>:</p> <blockquote> <p>Unless it's the version from util-linux, and you use its advanced mode, never use getopt(1). getopt cannot handle empty arguments strings, or ar...
<p>Use <code>getopts</code> (with an &quot;s&quot;).</p> <p>According to <a href="http://mywiki.wooledge.org/BashFAQ/035" rel="noreferrer">Bash FAQ 35</a>:</p> <blockquote> <p>Unless it's the version from util-linux, and you use its advanced mode, never use getopt(1). getopt cannot handle empty arguments strings, or ar...
387, 390, 3285, 10831
bash, cross-platform, getopt, shell
<h1>Cross-platform getopt for a shell script</h1> <p>I've just found out that <code>getopt</code> is not cross-platform (in particular for FreeBSD and Linux). What is the best workaround for this issue?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,217
bash
# Cross-platform getopt for a shell script I've just found out that `getopt` is not cross-platform (in particular for FreeBSD and Linux). What is the best workaround for this issue?
Use `getopts` (with an "s"). According to [Bash FAQ 35](http://mywiki.wooledge.org/BashFAQ/035): > Unless it's the version from util-linux, and you use its advanced mode, never use getopt(1). getopt cannot handle empty arguments strings, or arguments with embedded whitespace. Please forget that it ever existed. > > T...
1973420
Shell Script + Write to File a String
12
2009-12-29 07:41:09
<p>I have a string</p> <p>server.ip=192.168.1.200</p> <p>And I need to write the above statement completely into the file.</p> <p>How can this be done?</p> <p>This is what I'm trying to do...</p> <pre><code>set client_config = xmlrpc_server.properties echo 'serverurl=http://'${IP}':8000' &gt;&gt; %${client_config}...
61,576
185,412
2009-12-29 14:33:23
1,973,492
15
2009-12-29 08:08:28
229,602
2009-12-29 08:08:28
https://stackoverflow.com/q/1973420
https://stackoverflow.com/a/1973492
<p>This worked for me</p> <pre><code>$ FOO="192.168.1.1" $ echo "serverurl=http://$FOO:8000" &gt;&gt; x.conf $ more x.conf serverurl=http://192.168.1.1:8000 </code></pre> <p>I'm using zsh. I verified it with bash as well. What's the problem you get when you do this?</p>
<p>This worked for me</p> <pre><code>$ FOO="192.168.1.1" $ echo "serverurl=http://$FOO:8000" &gt;&gt; x.conf $ more x.conf serverurl=http://192.168.1.1:8000 </code></pre> <p>I'm using zsh. I verified it with bash as well. What's the problem you get when you do this?</p>
390
shell
<h1>Shell Script + Write to File a String</h1> <p>I have a string</p> <p>server.ip=192.168.1.200</p> <p>And I need to write the above statement completely into the file.</p> <p>How can this be done?</p> <p>This is what I'm trying to do...</p> <pre><code>set client_config = xmlrpc_server.properties echo 'serverurl=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,218
bash
# Shell Script + Write to File a String I have a string server.ip=192.168.1.200 And I need to write the above statement completely into the file. How can this be done? This is what I'm trying to do... ``` set client_config = xmlrpc_server.properties echo 'serverurl=http://'${IP}':8000' >> %${client_config}% echo ...
This worked for me ``` $ FOO="192.168.1.1" $ echo "serverurl=http://$FOO:8000" >> x.conf $ more x.conf serverurl=http://192.168.1.1:8000 ``` I'm using zsh. I verified it with bash as well. What's the problem you get when you do this?
1493771
Looking for a PowerShell script to compare two folders recursively
12
2009-09-29 16:56:55
<p>Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs?</p>
11,787
58,463
2009-09-29 17:06:49
1,493,820
15
2009-09-29 17:06:49
67,392
2009-09-29 17:06:49
https://stackoverflow.com/q/1493771
https://stackoverflow.com/a/1493820
<p>Easy enough to do something simple:</p> <pre><code>$d1 = get-childitem -path $dir1 -recurse $d2 = get-childitem -path $dir2 -recurse compare-object $d1 $d2 </code></pre> <p>More sophistication required depending on the definition of difference.</p>
<p>Easy enough to do something simple:</p> <pre><code>$d1 = get-childitem -path $dir1 -recurse $d2 = get-childitem -path $dir2 -recurse compare-object $d1 $d2 </code></pre> <p>More sophistication required depending on the definition of difference.</p>
526
powershell
<h1>Looking for a PowerShell script to compare two folders recursively</h1> <p>Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,219
bash
# Looking for a PowerShell script to compare two folders recursively Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs?
Easy enough to do something simple: ``` $d1 = get-childitem -path $dir1 -recurse $d2 = get-childitem -path $dir2 -recurse compare-object $d1 $d2 ``` More sophistication required depending on the definition of difference.
399734
Input from within shell script
12
2008-12-30 07:45:17
<p>I have a script that calls an application that requires user input, e.g. run app that requires user to type in 'Y' or 'N'.<br> How can I get the shell script not to ask the user for the input but rather use the value from a predefined variable in the script?</p> <p>In my case there will be two questions that requir...
13,035
null
2014-07-29 03:29:08
399,736
15
2008-12-30 07:48:12
27,020
2008-12-30 07:48:12
https://stackoverflow.com/q/399734
https://stackoverflow.com/a/399736
<p>You can pipe in whatever text you'd like on stdin and it will be just the same as having the user type it themselves. For example to simulating typing "Y" just use:</p> <pre><code>echo "Y" | myapp </code></pre> <p>or using a shell variable:</p> <pre><code>echo $ANSWER | myapp </code></pre> <p>There is also a un...
<p>You can pipe in whatever text you'd like on stdin and it will be just the same as having the user type it themselves. For example to simulating typing "Y" just use:</p> <pre><code>echo "Y" | myapp </code></pre> <p>or using a shell variable:</p> <pre><code>echo $ANSWER | myapp </code></pre> <p>There is also a un...
390
shell
<h1>Input from within shell script</h1> <p>I have a script that calls an application that requires user input, e.g. run app that requires user to type in 'Y' or 'N'.<br> How can I get the shell script not to ask the user for the input but rather use the value from a predefined variable in the script?</p> <p>In my case...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,220
bash
# Input from within shell script I have a script that calls an application that requires user input, e.g. run app that requires user to type in 'Y' or 'N'. How can I get the shell script not to ask the user for the input but rather use the value from a predefined variable in the script? In my case there will be two...
You can pipe in whatever text you'd like on stdin and it will be just the same as having the user type it themselves. For example to simulating typing "Y" just use: ``` echo "Y" | myapp ``` or using a shell variable: ``` echo $ANSWER | myapp ``` There is also a unix command called "yes" that outputs a continuous st...
317733
trying to capture javac output in bash shell
12
2008-11-25 15:35:22
<p>I'm trying to redirect the java compiler output to a file. I thought it's supposed to be:</p> <pre><code>javac file.java &gt; log.txt </code></pre> <p>or something. Instead, I see all the output on the terminal and nothing in log.txt!</p> <p>Also, if I want to log errors too, do I do</p> <pre><code>javac file.j...
8,503
31,301
2024-01-10 09:42:12
317,752
15
2008-11-25 15:41:53
40,111
2008-11-25 15:41:53
https://stackoverflow.com/q/317733
https://stackoverflow.com/a/317752
<pre><code>javac file.java 2&gt; log.txt </code></pre> <p>The reason is that you have <em>two</em> output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, ...
<pre><code>javac file.java 2&gt; log.txt </code></pre> <p>The reason is that you have <em>two</em> output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, ...
387, 390, 7427
bash, javac, shell
<h1>trying to capture javac output in bash shell</h1> <p>I'm trying to redirect the java compiler output to a file. I thought it's supposed to be:</p> <pre><code>javac file.java &gt; log.txt </code></pre> <p>or something. Instead, I see all the output on the terminal and nothing in log.txt!</p> <p>Also, if I want t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,221
bash
# trying to capture javac output in bash shell I'm trying to redirect the java compiler output to a file. I thought it's supposed to be: ``` javac file.java > log.txt ``` or something. Instead, I see all the output on the terminal and nothing in log.txt! Also, if I want to log errors too, do I do ``` javac file.ja...
``` javac file.java 2> log.txt ``` The reason is that you have *two* output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, errors, current status etc., t...
53346274
Exactly what cases does the gcc execstack flag allow and how does it enforce it?
11
2018-11-16 22:31:28
<p>I have some example code here which I'm using to understand some C behaviour for a beginner's CTF:</p> <pre><code>// example.c #include &lt;stdio.h&gt; void main() { void (*print)(); print = getenv("EGG"); print(); } </code></pre> <p>Compile: <code>gcc -z execstack -g -m32 -o example ex...
5,682
2,929,228
2022-03-28 00:32:11
53,346,420
15
2018-11-16 22:51:34
224,132
2022-03-28 00:32:11
https://stackoverflow.com/q/53346274
https://stackoverflow.com/a/53346420
<p><strong><code>getenv</code> doesn't <em>store</em> the env var's value on the stack. It's <em>already</em> on the stack from process startup, and <code>getenv</code> obtains a pointer to it.</strong></p> <p>See the i386 System V ABI's description of where argv[] and envp[] are located at process startup: above <cod...
<p><strong><code>getenv</code> doesn't <em>store</em> the env var's value on the stack. It's <em>already</em> on the stack from process startup, and <code>getenv</code> obtains a pointer to it.</strong></p> <p>See the i386 System V ABI's description of where argv[] and envp[] are located at process startup: above <cod...
8, 58, 823, 1477, 78469
c, gcc, linux, shellcode, x86
<h1>Exactly what cases does the gcc execstack flag allow and how does it enforce it?</h1> <p>I have some example code here which I'm using to understand some C behaviour for a beginner's CTF:</p> <pre><code>// example.c #include &lt;stdio.h&gt; void main() { void (*print)(); print = getenv("EGG"); ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,222
bash
# Exactly what cases does the gcc execstack flag allow and how does it enforce it? I have some example code here which I'm using to understand some C behaviour for a beginner's CTF: ``` // example.c #include <stdio.h> void main() { void (*print)(); print = getenv("EGG"); print(); } ``` Co...
**`getenv` doesn't *store* the env var's value on the stack. It's *already* on the stack from process startup, and `getenv` obtains a pointer to it.** See the i386 System V ABI's description of where argv[] and envp[] are located at process startup: above `[esp]`. `_start` doesn't copy them before calling `main`, jus...
49664991
Why am I getting "cat: write error: Broken pipe" rarely and not always
11
2018-04-05 05:47:58
<p>I am running some scripts with commands having <code>cat</code> pipelined with <code>grep</code> like:</p> <pre><code>cat file.txt | grep "pattern" </code></pre> <p>Most of the times there are no problems. But sometimes I get below error:</p> <blockquote> <p>cat: write error: Broken pipe</p> </blockquote> <p>S...
44,930
9,167,609
2020-01-31 06:09:22
49,665,446
15
2018-04-05 06:24:31
5,291,015
2018-04-05 09:24:39
https://stackoverflow.com/q/49664991
https://stackoverflow.com/a/49665446
<p>The reason is because the pipe is closed by <code>grep</code> when it still has some data to be read from <code>cat</code>. The signal <code>SIGPIPE</code> is caught by cat and it exits.</p> <p>What usually happens in a pipeline is the shell runs <code>cat</code> in one process and <code>grep</code> in another. The...
<p>The reason is because the pipe is closed by <code>grep</code> when it still has some data to be read from <code>cat</code>. The signal <code>SIGPIPE</code> is caught by cat and it exits.</p> <p>What usually happens in a pipeline is the shell runs <code>cat</code> in one process and <code>grep</code> in another. The...
58, 387, 1271, 7616, 22820
bash, broken-pipe, cat, grep, linux
<h1>Why am I getting "cat: write error: Broken pipe" rarely and not always</h1> <p>I am running some scripts with commands having <code>cat</code> pipelined with <code>grep</code> like:</p> <pre><code>cat file.txt | grep "pattern" </code></pre> <p>Most of the times there are no problems. But sometimes I get below err...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,223
bash
# Why am I getting "cat: write error: Broken pipe" rarely and not always I am running some scripts with commands having `cat` pipelined with `grep` like: ``` cat file.txt | grep "pattern" ``` Most of the times there are no problems. But sometimes I get below error: > cat: write error: Broken pipe So how do I find ...
The reason is because the pipe is closed by `grep` when it still has some data to be read from `cat`. The signal `SIGPIPE` is caught by cat and it exits. What usually happens in a pipeline is the shell runs `cat` in one process and `grep` in another. The stdout of `cat` is connected to the write-end of the pipe and st...
32062159
How retrieve the creation date of photos with a script
11
2015-08-18 01:26:51
<p>What I want to do is reorganize files in my Camera Roll folder. Using the creation date I want to Put them inside folders according to Year/Month Format using their creation date.</p> <p>In this answer, they explain how to make folders and organize them: <a href="https://stackoverflow.com/a/1314394/4980886">https:/...
18,266
4,980,886
2022-01-07 15:51:38
48,065,212
15
2018-01-02 17:20:48
2,154,510
2019-03-13 16:22:06
https://stackoverflow.com/q/32062159
https://stackoverflow.com/a/48065212
<p>According to exiftool man page '<a href="https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#RENAMING-EXAMPLES" rel="noreferrer">Renaming examples</a>'</p> <p><code>exiftool '-Directory&lt;DateTimeOriginal' -d %Y/%m/%d "$dir" </code></p> <p>and if only copying is required, there is an option:</p> <p><code...
<p>According to exiftool man page '<a href="https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#RENAMING-EXAMPLES" rel="noreferrer">Renaming examples</a>'</p> <p><code>exiftool '-Directory&lt;DateTimeOriginal' -d %Y/%m/%d "$dir" </code></p> <p>and if only copying is required, there is an option:</p> <p><code...
218, 387, 3703, 12067
bash, directory, exif, photos
<h1>How retrieve the creation date of photos with a script</h1> <p>What I want to do is reorganize files in my Camera Roll folder. Using the creation date I want to Put them inside folders according to Year/Month Format using their creation date.</p> <p>In this answer, they explain how to make folders and organize the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,224
bash
# How retrieve the creation date of photos with a script What I want to do is reorganize files in my Camera Roll folder. Using the creation date I want to Put them inside folders according to Year/Month Format using their creation date. In this answer, they explain how to make folders and organize them: <https://stac...
According to exiftool man page '[Renaming examples](https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#RENAMING-EXAMPLES)' `exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d "$dir"` and if only copying is required, there is an option: `exiftool -o . '-Directory<DateTimeOriginal' -d %Y/%m/%d "$dir"` has th...
43686878
Pass multiple arrays as arguments to a Bash script?
11
2017-04-28 18:38:23
<p>I've looked, but have only seen answers to one array being passed in a script. </p> <p>I want to pass multiple arrays to a bash script that assigns them as individual variables as follows: </p> <pre><code>./myScript.sh ${array1[@]} ${array2[@]} ${array3[@]} </code></pre> <p>such that: <code>var1=array1</code> and...
6,918
7,938,150
2022-12-13 07:50:22
43,687,593
15
2017-04-28 19:27:24
14,122
2017-05-01 02:05:36
https://stackoverflow.com/q/43686878
https://stackoverflow.com/a/43687593
<p>The shell passes a single argument vector (that is to say, a simple C array of strings) off to a program being run. This is an OS-level limitation: There <em>exists no method</em> to pass structured data between two programs (any two programs, written in any language!) in an argument list, except by encoding that st...
<p>The shell passes a single argument vector (that is to say, a simple C array of strings) off to a program being run. This is an OS-level limitation: There <em>exists no method</em> to pass structured data between two programs (any two programs, written in any language!) in an argument list, except by encoding that st...
114, 387, 390, 1231
arrays, bash, command-line, shell
<h1>Pass multiple arrays as arguments to a Bash script?</h1> <p>I've looked, but have only seen answers to one array being passed in a script. </p> <p>I want to pass multiple arrays to a bash script that assigns them as individual variables as follows: </p> <pre><code>./myScript.sh ${array1[@]} ${array2[@]} ${array3[...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,225
bash
# Pass multiple arrays as arguments to a Bash script? I've looked, but have only seen answers to one array being passed in a script. I want to pass multiple arrays to a bash script that assigns them as individual variables as follows: ``` ./myScript.sh ${array1[@]} ${array2[@]} ${array3[@]} ``` such that: `var1=arr...
The shell passes a single argument vector (that is to say, a simple C array of strings) off to a program being run. This is an OS-level limitation: There *exists no method* to pass structured data between two programs (any two programs, written in any language!) in an argument list, except by encoding that structure in...
43506421
Create file with content in one line of bash
11
2017-04-19 21:30:44
<p>I wish to create a single file with some contents known to me.</p> <p>How do I do this in couple lines of bash?</p> <p>this command will be used inside of a single script, so it should create file, add text, save, and quit automatically by itself without human intervention.</p> <p>I know that</p> <pre><code>cat ...
22,382
1,017,674
2024-03-06 09:54:00
43,506,474
15
2017-04-19 21:33:58
1,899,640
2017-04-19 21:33:58
https://stackoverflow.com/q/43506421
https://stackoverflow.com/a/43506474
<p>Use a "here document":</p> <pre><code>cat &gt;&gt; some.text &lt;&lt; 'END' some stuff here more stuff END </code></pre> <p>The delimiter (here <code>END</code>) is an arbitrary word. Quoting this delimiter after the <code>&lt;&lt;</code> will ensure that no expansion is performed on the contents.</p>
<p>Use a "here document":</p> <pre><code>cat &gt;&gt; some.text &lt;&lt; 'END' some stuff here more stuff END </code></pre> <p>The delimiter (here <code>END</code>) is an arbitrary word. Quoting this delimiter after the <code>&lt;&lt;</code> will ensure that no expansion is performed on the contents.</p>
387
bash
<h1>Create file with content in one line of bash</h1> <p>I wish to create a single file with some contents known to me.</p> <p>How do I do this in couple lines of bash?</p> <p>this command will be used inside of a single script, so it should create file, add text, save, and quit automatically by itself without human ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,226
bash
# Create file with content in one line of bash I wish to create a single file with some contents known to me. How do I do this in couple lines of bash? this command will be used inside of a single script, so it should create file, add text, save, and quit automatically by itself without human intervention. I know t...
Use a "here document": ``` cat >> some.text << 'END' some stuff here more stuff END ``` The delimiter (here `END`) is an arbitrary word. Quoting this delimiter after the `<<` will ensure that no expansion is performed on the contents.
39549106
Git blame a list of authors in a file
11
2016-09-17 16:27:40
<p>Is there a way to find out a list of authors who edited the class in java file in repo using <code>git blame</code>? The list of authors have to be unique.</p> <p>I have tried using the following command but it did not remove duplicates and there is word "author" in every line of output. There is no need to sort th...
9,793
4,180,707
2021-03-12 07:55:01
39,549,242
15
2016-09-17 16:40:31
2,394,026
2021-03-12 07:55:01
https://stackoverflow.com/q/39549106
https://stackoverflow.com/a/39549242
<p>You can add at the end of the command <code>uniq</code> to make author unique.</p> <pre><code>git blame filename --porcelain | grep &quot;^author &quot; | sort -u </code></pre> <p><a href="http://www.linux-france.org/article/man-fr/man1/sort-1.html" rel="nofollow noreferrer">sort Documentation</a></p>
<p>You can add at the end of the command <code>uniq</code> to make author unique.</p> <pre><code>git blame filename --porcelain | grep &quot;^author &quot; | sort -u </code></pre> <p><a href="http://www.linux-france.org/article/man-fr/man1/sort-1.html" rel="nofollow noreferrer">sort Documentation</a></p>
119, 387
bash, git
<h1>Git blame a list of authors in a file</h1> <p>Is there a way to find out a list of authors who edited the class in java file in repo using <code>git blame</code>? The list of authors have to be unique.</p> <p>I have tried using the following command but it did not remove duplicates and there is word "author" in ev...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,227
bash
# Git blame a list of authors in a file Is there a way to find out a list of authors who edited the class in java file in repo using `git blame`? The list of authors have to be unique. I have tried using the following command but it did not remove duplicates and there is word "author" in every line of output. There i...
You can add at the end of the command `uniq` to make author unique. ``` git blame filename --porcelain | grep "^author " | sort -u ``` [sort Documentation](http://www.linux-france.org/article/man-fr/man1/sort-1.html)
39103264
Rename parts of file names that match a pattern
11
2016-08-23 13:57:02
<p>Say I have a list of file names like this:</p> <pre><code>some-file.ts my-project-service.ts other.ts something-my-project.ts </code></pre> <p>I need to change the file names that have <code>my-project</code> in them to have just that part renamed to <code>$appname$</code>. </p> <p>So <code>my-project-ser...
6,991
16,241
2016-08-23 21:36:18
39,103,500
15
2016-08-23 14:06:49
1,163,423
2016-08-23 21:36:18
https://stackoverflow.com/q/39103264
https://stackoverflow.com/a/39103500
<p>Use the <code>Get-ChildItem</code> cmdlet with the <code>-recurse</code> switch to get all items recursivly from a root directory. Filter all items containing <code>my-project</code> using the <code>Where-Object</code> cmdlet and finally rename them using the <code>Rename-Item</code> cmdlet:</p> <pre><code>Get-Chil...
<p>Use the <code>Get-ChildItem</code> cmdlet with the <code>-recurse</code> switch to get all items recursivly from a root directory. Filter all items containing <code>my-project</code> using the <code>Where-Object</code> cmdlet and finally rename them using the <code>Rename-Item</code> cmdlet:</p> <pre><code>Get-Chil...
526, 24067
powershell, powershell-2.0
<h1>Rename parts of file names that match a pattern</h1> <p>Say I have a list of file names like this:</p> <pre><code>some-file.ts my-project-service.ts other.ts something-my-project.ts </code></pre> <p>I need to change the file names that have <code>my-project</code> in them to have just that part renamed to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,228
bash
# Rename parts of file names that match a pattern Say I have a list of file names like this: ``` some-file.ts my-project-service.ts other.ts something-my-project.ts ``` I need to change the file names that have `my-project` in them to have just that part renamed to `$appname$`. So `my-project-service.ts` woul...
Use the `Get-ChildItem` cmdlet with the `-recurse` switch to get all items recursivly from a root directory. Filter all items containing `my-project` using the `Where-Object` cmdlet and finally rename them using the `Rename-Item` cmdlet: ``` Get-ChildItem "D:\tmp" -Recurse | Where {$_.Name -Match 'my-project'} | ...
34437248
Is there a better way to count occurrence of char in a string?
11
2015-12-23 13:56:02
<p>I felt there must a better way to count occurrence instead of writing a sub in perl, shell in Linux.</p> <pre><code>#/usr/bin/perl -w use strict; return 1 unless $0 eq __FILE__; main() if $0 eq __FILE__; sub main{ my $str = "ru8xysyyyyyyysss6s5s"; my $char = "y"; my $count = count_occurrence($str, $char...
22,575
5,574,689
2015-12-23 22:09:27
34,437,471
15
2015-12-23 14:09:17
197,758
2015-12-23 19:18:41
https://stackoverflow.com/q/34437248
https://stackoverflow.com/a/34437471
<p>Counting the occurences of a character in a string can be performed with one line in Perl (as compared to your 4 lines). There is no need for a sub (although there is nothing wrong with encapsulating functionality in a sub). From <a href="http://perldoc.perl.org/perlfaq4.html" rel="noreferrer">perlfaq4 "How can I ...
<p>Counting the occurences of a character in a string can be performed with one line in Perl (as compared to your 4 lines). There is no need for a sub (although there is nothing wrong with encapsulating functionality in a sub). From <a href="http://perldoc.perl.org/perlfaq4.html" rel="noreferrer">perlfaq4 "How can I ...
580, 10327
perl, sh
<h1>Is there a better way to count occurrence of char in a string?</h1> <p>I felt there must a better way to count occurrence instead of writing a sub in perl, shell in Linux.</p> <pre><code>#/usr/bin/perl -w use strict; return 1 unless $0 eq __FILE__; main() if $0 eq __FILE__; sub main{ my $str = "ru8xysyyyyyyyss...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,229
bash
# Is there a better way to count occurrence of char in a string? I felt there must a better way to count occurrence instead of writing a sub in perl, shell in Linux. ``` #/usr/bin/perl -w use strict; return 1 unless $0 eq __FILE__; main() if $0 eq __FILE__; sub main{ my $str = "ru8xysyyyyyyysss6s5s"; my $char...
Counting the occurences of a character in a string can be performed with one line in Perl (as compared to your 4 lines). There is no need for a sub (although there is nothing wrong with encapsulating functionality in a sub). From [perlfaq4 "How can I count the number of occurrences of a substring within a string?"](htt...
33967294
grep each line in a file
11
2015-11-28 03:18:54
<p>I have two files: one is a fairly long collection of names (names.txt), and another file (grades.csv) which is a huge file of names and the corresponding grades. I would like to iterate over each line in names.txt and extract that name in grades.csv with the entire matching line. </p> <p>This is how a small sample ...
30,217
505,306
2022-05-31 16:18:21
33,967,443
15
2015-11-28 03:48:12
2,883,245
2015-11-28 04:18:53
https://stackoverflow.com/q/33967294
https://stackoverflow.com/a/33967443
<p>I made some changes to your <code>names.txt</code> and <code>grades.csv</code> - some of the names are comma-separated and some aren't. I removed commas within quotes, so here are the new files:</p> <pre><code>22:46 $ cat names.txt "Dumbledore Albus" "Potter Harry" "Riddle Tom" 22:46 $ cat grades.csv "Granger He...
<p>I made some changes to your <code>names.txt</code> and <code>grades.csv</code> - some of the names are comma-separated and some aren't. I removed commas within quotes, so here are the new files:</p> <pre><code>22:46 $ cat names.txt "Dumbledore Albus" "Potter Harry" "Riddle Tom" 22:46 $ cat grades.csv "Granger He...
58, 387, 1271
bash, grep, linux
<h1>grep each line in a file</h1> <p>I have two files: one is a fairly long collection of names (names.txt), and another file (grades.csv) which is a huge file of names and the corresponding grades. I would like to iterate over each line in names.txt and extract that name in grades.csv with the entire matching line. </...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,230
bash
# grep each line in a file I have two files: one is a fairly long collection of names (names.txt), and another file (grades.csv) which is a huge file of names and the corresponding grades. I would like to iterate over each line in names.txt and extract that name in grades.csv with the entire matching line. This is ho...
I made some changes to your `names.txt` and `grades.csv` - some of the names are comma-separated and some aren't. I removed commas within quotes, so here are the new files: ``` 22:46 $ cat names.txt "Dumbledore Albus" "Potter Harry" "Riddle Tom" 22:46 $ cat grades.csv "Granger Hermione", 96.65%, 9,10 "Mcgonagall Mi...
30106758
Difference between braces {} and brackets () in shell scripting
11
2015-05-07 16:27:43
<p>We use braces <code>{}</code> for variable expression like</p> <pre><code>NAME="test" FILE_NAME=${NAME}file </code></pre> <p>But I don't understand in which scenarios we use brackets () Say <code>nslookup $(hostname)</code> works only with <code>()</code> brackets.</p> <p>Can someone explain?</p>
19,760
1,835,315
2017-07-28 20:06:29
30,106,851
15
2015-05-07 16:32:27
1,022,889
2017-07-28 20:06:29
https://stackoverflow.com/q/30106758
https://stackoverflow.com/a/30106851
<p>Minor nitpick first:</p> <ul> <li>Brackets <code>[]</code></li> <li>Parentheses <code>()</code></li> <li>Braces <code>{}</code></li> <li>(Double) Quotation marks <code>""</code></li> <li>(Single) Quotation marks (apostrophes) <code>''</code></li> <li>Backticks <code>``</code> (Same as the tilde ~ key)</li> </ul> <...
<p>Minor nitpick first:</p> <ul> <li>Brackets <code>[]</code></li> <li>Parentheses <code>()</code></li> <li>Braces <code>{}</code></li> <li>(Double) Quotation marks <code>""</code></li> <li>(Single) Quotation marks (apostrophes) <code>''</code></li> <li>Backticks <code>``</code> (Same as the tilde ~ key)</li> </ul> <...
390, 4358, 21252
braces, brackets, shell
<h1>Difference between braces {} and brackets () in shell scripting</h1> <p>We use braces <code>{}</code> for variable expression like</p> <pre><code>NAME="test" FILE_NAME=${NAME}file </code></pre> <p>But I don't understand in which scenarios we use brackets () Say <code>nslookup $(hostname)</code> works only with <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,231
bash
# Difference between braces {} and brackets () in shell scripting We use braces `{}` for variable expression like ``` NAME="test" FILE_NAME=${NAME}file ``` But I don't understand in which scenarios we use brackets () Say `nslookup $(hostname)` works only with `()` brackets. Can someone explain?
Minor nitpick first: - Brackets `[]` - Parentheses `()` - Braces `{}` - (Double) Quotation marks `""` - (Single) Quotation marks (apostrophes) `''` - Backticks ``` `` ``` (Same as the tilde ~ key) Braces are used in BASh scripts for complex variable expansion. Consider string concatenation: ``` STR="hello" STR2=$STR...
28813210
Send message to a Python Script
11
2015-03-02 15:17:22
<p>I'm trying to write a little python program for shutdown or Reboot my Raspberry PI, drived by a button connected to an GPIO. The program can show the current status of the raspberry PI (Booting,Running,Halting,Rebooting) via two leds. The python program is executed as daemon, started by a init.d bash script (written...
11,206
4,623,899
2015-03-04 17:07:19
28,814,296
15
2015-03-02 16:07:53
419,903
2015-03-04 09:39:00
https://stackoverflow.com/q/28813210
https://stackoverflow.com/a/28814296
<p>There are several methods to send a message from one script/app to another:</p> <p>For you application a valid method is to use a named pipe. Create it using <a href="https://docs.python.org/2/library/os.html" rel="noreferrer">os.mkfifo</a>, open it read-only in your python app and then wait for messages on it.</p>...
<p>There are several methods to send a message from one script/app to another:</p> <p>For you application a valid method is to use a named pipe. Create it using <a href="https://docs.python.org/2/library/os.html" rel="noreferrer">os.mkfifo</a>, open it read-only in your python app and then wait for messages on it.</p>...
16, 58, 387, 2510, 77858
bash, daemon, linux, python, raspberry-pi
<h1>Send message to a Python Script</h1> <p>I'm trying to write a little python program for shutdown or Reboot my Raspberry PI, drived by a button connected to an GPIO. The program can show the current status of the raspberry PI (Booting,Running,Halting,Rebooting) via two leds. The python program is executed as daemon,...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,232
bash
# Send message to a Python Script I'm trying to write a little python program for shutdown or Reboot my Raspberry PI, drived by a button connected to an GPIO. The program can show the current status of the raspberry PI (Booting,Running,Halting,Rebooting) via two leds. The python program is executed as daemon, started ...
There are several methods to send a message from one script/app to another: For you application a valid method is to use a named pipe. Create it using [os.mkfifo](https://docs.python.org/2/library/os.html), open it read-only in your python app and then wait for messages on it. If you want your app to do another thing...
28749439
Changing Windows Time and Date Format
11
2015-02-26 17:54:50
<p>I'd like to automate preferences on a Windows machine for the date and time formats used throughout the OS.</p> <p>What PowerShell commands can I use to automate this task of changing values?</p> <ul> <li>short date format</li> <li>short and long time format</li> </ul> <p>These <a href="https://i.sstatic.net/IL4o...
11,023
23,199
2021-07-29 12:52:11
28,749,587
15
2015-02-26 18:02:12
4,375,845
2015-02-26 18:06:56
https://stackoverflow.com/q/28749439
https://stackoverflow.com/a/28749587
<p>I believe the settings you are looking for are located in:</p> <pre><code>HKEY_CURRENT_USER\Control Panel\International\sLongDate HKEY_CURRENT_USER\Control Panel\International\sShortDate HKEY_CURRENT_USER\Control Panel\International\sTimeFormat HKEY_CURRENT_USER\Control Panel\International\sYearMonth </code></pre> ...
<p>I believe the settings you are looking for are located in:</p> <pre><code>HKEY_CURRENT_USER\Control Panel\International\sLongDate HKEY_CURRENT_USER\Control Panel\International\sShortDate HKEY_CURRENT_USER\Control Panel\International\sTimeFormat HKEY_CURRENT_USER\Control Panel\International\sYearMonth </code></pre> ...
526
powershell
<h1>Changing Windows Time and Date Format</h1> <p>I'd like to automate preferences on a Windows machine for the date and time formats used throughout the OS.</p> <p>What PowerShell commands can I use to automate this task of changing values?</p> <ul> <li>short date format</li> <li>short and long time format</li> </ul...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,233
bash
# Changing Windows Time and Date Format I'd like to automate preferences on a Windows machine for the date and time formats used throughout the OS. What PowerShell commands can I use to automate this task of changing values? - short date format - short and long time format These [options are buried deep in Control ...
I believe the settings you are looking for are located in: ``` HKEY_CURRENT_USER\Control Panel\International\sLongDate HKEY_CURRENT_USER\Control Panel\International\sShortDate HKEY_CURRENT_USER\Control Panel\International\sTimeFormat HKEY_CURRENT_USER\Control Panel\International\sYearMonth ``` So, ``` Set-ItemProper...
28570535
How to check if a blob already exists in Azure blob container using PowerShell
11
2015-02-17 20:28:49
<p>I have a Windows PowerShell script that uploads a file to my Azure Blob Storage. I want the file only to upload if it doesn't already exists in the container.</p> <p>How do I check if the blob already exists ?</p> <p>I tired to use <a href="https://msdn.microsoft.com/en-us/library/dn806392.aspx" rel="noreferrer">G...
20,006
1,720,615
2024-10-09 14:58:10
28,590,164
15
2015-02-18 17:38:22
1,720,615
2015-02-18 17:43:22
https://stackoverflow.com/q/28570535
https://stackoverflow.com/a/28590164
<p>A solution is to wrap the call to <strong>Get-AzureStorageBlob</strong> in a try/catch and catch <strong><em>ResourceNotFoundException</em></strong> to determine that the blob doesn't exist.</p> <p>And don't forget the <code>-ErrorAction Stop</code> at the end.</p> <pre><code>try { $blob = Get-AzureStorageB...
<p>A solution is to wrap the call to <strong>Get-AzureStorageBlob</strong> in a try/catch and catch <strong><em>ResourceNotFoundException</em></strong> to determine that the blob doesn't exist.</p> <p>And don't forget the <code>-ErrorAction Stop</code> at the end.</p> <pre><code>try { $blob = Get-AzureStorageB...
526, 81879
azure-powershell, powershell
<h1>How to check if a blob already exists in Azure blob container using PowerShell</h1> <p>I have a Windows PowerShell script that uploads a file to my Azure Blob Storage. I want the file only to upload if it doesn't already exists in the container.</p> <p>How do I check if the blob already exists ?</p> <p>I tired to...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,234
bash
# How to check if a blob already exists in Azure blob container using PowerShell I have a Windows PowerShell script that uploads a file to my Azure Blob Storage. I want the file only to upload if it doesn't already exists in the container. How do I check if the blob already exists ? I tired to use [Get-AzureStorageB...
A solution is to wrap the call to **Get-AzureStorageBlob** in a try/catch and catch ***ResourceNotFoundException*** to determine that the blob doesn't exist. And don't forget the `-ErrorAction Stop` at the end. ``` try { $blob = Get-AzureStorageBlob -Blob $azureBlobName -Container $azureStorageContainer -Conte...
28185012
How to create tar for files older than 7 days using linux shell scripting
11
2015-01-28 05:06:58
<p>I'm writing shell script to backup files older than 7 days. Here is my code. But i'm not getting expected result. Can anyone correct me?</p> <pre><code>#!/bin/bash # Backup files files=($(find /var/log/ -mtime +"7")) for files in ${files[*]} do echo $files tar cvfz backup.tar.gz $files done </...
26,513
1,383,987
2021-08-18 10:35:57
28,185,124
15
2015-01-28 05:16:33
3,030,305
2018-09-23 05:22:03
https://stackoverflow.com/q/28185012
https://stackoverflow.com/a/28185124
<p>This will work:</p> <pre><code>#!/bin/bash files=() while IFS= read -r -d $'\0'; do files+=("$REPLY") done &lt; &lt;(find /var/log/ -mtime +7 -print0) tar cvfz backup.tar.gz "${files[@]}" </code></pre> <p>Note the use of <code>"${files[@]}"</code> as opposed to <code>${files[*]}</code>. <code>"${files[@]}"</...
<p>This will work:</p> <pre><code>#!/bin/bash files=() while IFS= read -r -d $'\0'; do files+=("$REPLY") done &lt; &lt;(find /var/log/ -mtime +7 -print0) tar cvfz backup.tar.gz "${files[@]}" </code></pre> <p>Note the use of <code>"${files[@]}"</code> as opposed to <code>${files[*]}</code>. <code>"${files[@]}"</...
58, 390
linux, shell
<h1>How to create tar for files older than 7 days using linux shell scripting</h1> <p>I'm writing shell script to backup files older than 7 days. Here is my code. But i'm not getting expected result. Can anyone correct me?</p> <pre><code>#!/bin/bash # Backup files files=($(find /var/log/ -mtime +"7")) for files in $...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,235
bash
# How to create tar for files older than 7 days using linux shell scripting I'm writing shell script to backup files older than 7 days. Here is my code. But i'm not getting expected result. Can anyone correct me? ``` #!/bin/bash # Backup files files=($(find /var/log/ -mtime +"7")) for files in ${files[*]} do ...
This will work: ``` #!/bin/bash files=() while IFS= read -r -d $'\0'; do files+=("$REPLY") done < <(find /var/log/ -mtime +7 -print0) tar cvfz backup.tar.gz "${files[@]}" ``` Note the use of `"${files[@]}"` as opposed to `${files[*]}`. `"${files[@]}"` will expand to provide `tar` with one argument per file name ...
22549489
Mount an SD card manually from adb shell in android
11
2014-03-21 03:17:07
<p>I have an android 4.1 phone (Lenovo 820). After some changes aimed at partitioning the internal SD ram (which changed , the phone will no longer mount the <em>external</em> SD card. I am good-ish at Linux, but I have never seen the Android shell before today.</p> <p>I would love to know the steps to:</p> <ul> <li>...
48,068
829,771
2014-06-04 11:41:06
24,036,449
15
2014-06-04 11:41:06
3,706,809
2014-06-04 11:41:06
https://stackoverflow.com/q/22549489
https://stackoverflow.com/a/24036449
<p>I can't believe no one has responded to you in 2 months? Wow...how slack!</p> <p>Well anyway I spose I should fill you in on some info as well as ask some questions. 1). Have you got root access or did you pull the system vold from a release image/firmware? Like Linux SuperUser rights? 2). If you have root access/s...
<p>I can't believe no one has responded to you in 2 months? Wow...how slack!</p> <p>Well anyway I spose I should fill you in on some info as well as ask some questions. 1). Have you got root access or did you pull the system vold from a release image/firmware? Like Linux SuperUser rights? 2). If you have root access/s...
390, 1386, 1678
android, mount, shell
<h1>Mount an SD card manually from adb shell in android</h1> <p>I have an android 4.1 phone (Lenovo 820). After some changes aimed at partitioning the internal SD ram (which changed , the phone will no longer mount the <em>external</em> SD card. I am good-ish at Linux, but I have never seen the Android shell before tod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,236
bash
# Mount an SD card manually from adb shell in android I have an android 4.1 phone (Lenovo 820). After some changes aimed at partitioning the internal SD ram (which changed , the phone will no longer mount the *external* SD card. I am good-ish at Linux, but I have never seen the Android shell before today. I would lov...
I can't believe no one has responded to you in 2 months? Wow...how slack! Well anyway I spose I should fill you in on some info as well as ask some questions. 1). Have you got root access or did you pull the system vold from a release image/firmware? Like Linux SuperUser rights? 2). If you have root access/super user ...
21345314
Run ScriptBlock with different credentials
11
2014-01-25 01:16:31
<p>I have a script, that determines a userid; once I have that userid, I want to run a script block against that userid using different credentials. Is this possible? Can anyone show me examples of this? </p>
35,994
2,917,511
2024-10-21 19:37:23
21,439,734
15
2014-01-29 18:38:55
2,917,511
2014-01-29 18:38:55
https://stackoverflow.com/q/21345314
https://stackoverflow.com/a/21439734
<p>I got it, thanks to Trevor Sullivan for pointing me in the right direction. I ended up just putting my second ps1 file into a scriptblock, and running it as a job, and passing it the arguments from the main script, like this</p> <pre><code>$job = Start-Job -scriptblock { param ($username) some code to run against t...
<p>I got it, thanks to Trevor Sullivan for pointing me in the right direction. I ended up just putting my second ps1 file into a scriptblock, and running it as a job, and passing it the arguments from the main script, like this</p> <pre><code>$job = Start-Job -scriptblock { param ($username) some code to run against t...
526, 5357
credentials, powershell
<h1>Run ScriptBlock with different credentials</h1> <p>I have a script, that determines a userid; once I have that userid, I want to run a script block against that userid using different credentials. Is this possible? Can anyone show me examples of this? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,237
bash
# Run ScriptBlock with different credentials I have a script, that determines a userid; once I have that userid, I want to run a script block against that userid using different credentials. Is this possible? Can anyone show me examples of this?
I got it, thanks to Trevor Sullivan for pointing me in the right direction. I ended up just putting my second ps1 file into a scriptblock, and running it as a job, and passing it the arguments from the main script, like this ``` $job = Start-Job -scriptblock { param ($username) some code to run against the variable th...
21041543
How to rename a column heading in a CSV file?
11
2014-01-10 10:14:20
<p>I cannot work out how to rename a column heading in a CSV file with Windows PowerShell. I can add new rows, delete rows, fill, and export, but cannot find out how to change a header value.</p> <p>I thought I could import the CSV &amp; export with headers specified, but taht doesn't work:</p> <pre><code>import-csv c:...
55,267
1,235,462
2021-12-21 16:42:07
21,042,554
15
2014-01-10 10:57:30
260,545
2021-12-21 16:41:48
https://stackoverflow.com/q/21041543
https://stackoverflow.com/a/21042554
<p>You may use <code>Select-Object</code> with a <a href="http://technet.microsoft.com/en-us/library/ff730948.aspx" rel="nofollow noreferrer">calculated property</a> to do this:</p> <pre><code>Import-Csv test.csv | Select-Object @{ expression={$_.first_name}; label='test' } | Export-Csv -NoTypeInformation t...
<p>You may use <code>Select-Object</code> with a <a href="http://technet.microsoft.com/en-us/library/ff730948.aspx" rel="nofollow noreferrer">calculated property</a> to do this:</p> <pre><code>Import-Csv test.csv | Select-Object @{ expression={$_.first_name}; label='test' } | Export-Csv -NoTypeInformation t...
73, 526
csv, powershell
<h1>How to rename a column heading in a CSV file?</h1> <p>I cannot work out how to rename a column heading in a CSV file with Windows PowerShell. I can add new rows, delete rows, fill, and export, but cannot find out how to change a header value.</p> <p>I thought I could import the CSV &amp; export with headers specifi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,238
bash
# How to rename a column heading in a CSV file? I cannot work out how to rename a column heading in a CSV file with Windows PowerShell. I can add new rows, delete rows, fill, and export, but cannot find out how to change a header value. I thought I could import the CSV & export with headers specified, but taht doesn'...
You may use `Select-Object` with a [calculated property](http://technet.microsoft.com/en-us/library/ff730948.aspx) to do this: ``` Import-Csv test.csv | Select-Object @{ expression={$_.first_name}; label='test' } | Export-Csv -NoTypeInformation test1.csv ```
17324392
How does the PowerShell Pipeline Concept work?
11
2013-06-26 15:33:30
<p>I understand that PowerShell piping works by taking the output of one cmdlet and passing it to another cmdlet as input. But how does it go about doing this? </p> <p>Does the first cmdlet finish and then pass all the output variables across at once, which are then processed by the next cmdlet?</p> <p>Or is each out...
3,617
2,215,029
2015-11-07 00:55:39
17,329,863
15
2013-06-26 20:29:47
153,982
2013-06-26 20:29:47
https://stackoverflow.com/q/17324392
https://stackoverflow.com/a/17329863
<p>You can see how pipeline order works with a simple bit of script:</p> <pre><code>function a {begin {Write-Host 'begin a'} process {Write-Host "process a: $_"; $_} end {Write-Host 'end a'}} function b {begin {Write-Host 'begin b'} process {Write-Host "process b: $_"; $_} end {Write-Host 'end b'}} function c { Write-...
<p>You can see how pipeline order works with a simple bit of script:</p> <pre><code>function a {begin {Write-Host 'begin a'} process {Write-Host "process a: $_"; $_} end {Write-Host 'end a'}} function b {begin {Write-Host 'begin b'} process {Write-Host "process b: $_"; $_} end {Write-Host 'end b'}} function c { Write-...
526, 2844, 12103
conceptual, pipeline, powershell
<h1>How does the PowerShell Pipeline Concept work?</h1> <p>I understand that PowerShell piping works by taking the output of one cmdlet and passing it to another cmdlet as input. But how does it go about doing this? </p> <p>Does the first cmdlet finish and then pass all the output variables across at once, which are t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,239
bash
# How does the PowerShell Pipeline Concept work? I understand that PowerShell piping works by taking the output of one cmdlet and passing it to another cmdlet as input. But how does it go about doing this? Does the first cmdlet finish and then pass all the output variables across at once, which are then processed by ...
You can see how pipeline order works with a simple bit of script: ``` function a {begin {Write-Host 'begin a'} process {Write-Host "process a: $_"; $_} end {Write-Host 'end a'}} function b {begin {Write-Host 'begin b'} process {Write-Host "process b: $_"; $_} end {Write-Host 'end b'}} function c { Write-Host 'c' } 1....
17242773
Pass in variable from shell script to applescript
11
2013-06-21 19:19:40
<p>I've got a shell script that I call that uses <code>osascript</code>, and that <code>osascript</code> calls a shell script and passes in a variable that I've set in the original shell script. I don't know how to pass that variable in from the applescript to shell script.</p> <p>How can I pass in a variable from sh...
16,809
996,110
2023-10-27 20:41:36
17,243,326
15
2013-06-21 19:57:14
632,407
2021-12-17 22:18:00
https://stackoverflow.com/q/17242773
https://stackoverflow.com/a/17243326
<p>Shell variables don't expand inside single quotes. When you to want pass a shell variable to <code>osascript</code> you need to use double <code>&quot;&quot;</code> quotes. The problem is, than you must escape double quotes needed inside the osascript, like:</p> <p>the script</p> <pre><code>say &quot;Hello&quot; usi...
<p>Shell variables don't expand inside single quotes. When you to want pass a shell variable to <code>osascript</code> you need to use double <code>&quot;&quot;</code> quotes. The problem is, than you must escape double quotes needed inside the osascript, like:</p> <p>the script</p> <pre><code>say &quot;Hello&quot; usi...
387, 390, 1243, 15718
applescript, bash, osascript, shell
<h1>Pass in variable from shell script to applescript</h1> <p>I've got a shell script that I call that uses <code>osascript</code>, and that <code>osascript</code> calls a shell script and passes in a variable that I've set in the original shell script. I don't know how to pass that variable in from the applescript to...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,240
bash
# Pass in variable from shell script to applescript I've got a shell script that I call that uses `osascript`, and that `osascript` calls a shell script and passes in a variable that I've set in the original shell script. I don't know how to pass that variable in from the applescript to shell script. How can I pass i...
Shell variables don't expand inside single quotes. When you to want pass a shell variable to `osascript` you need to use double `""` quotes. The problem is, than you must escape double quotes needed inside the osascript, like: the script ``` say "Hello" using "Alex" ``` you need escape quotes ``` text="Hello" osasc...
15557857
How to kill all processes that were opened by a shell script upon ctrl + C?
11
2013-03-21 20:53:10
<p>I've got a couple python scripts which I start collectively from a shell script as follows:</p> <pre><code>#!/bin/bash python prog1.py &amp; python prog2.py &amp; python prog3.py </code></pre> <p>Since I am developing I often want to stop these processes. I normally do so by hitting ctrl+C, but unfortuntaly a cou...
3,474
1,650,012
2013-03-21 21:02:37
15,557,994
15
2013-03-21 20:59:58
1,204,143
2013-03-21 20:59:58
https://stackoverflow.com/q/15557857
https://stackoverflow.com/a/15557994
<p>Let the bash script catch SIGINT, and have it kill everything in the current process group:</p> <pre><code>intexit() { # Kill all subprocesses (all processes in the current process group) kill -HUP -$$ } hupexit() { # HUP'd (probably by intexit) echo echo "Interrupted" exit } trap hupexit ...
<p>Let the bash script catch SIGINT, and have it kill everything in the current process group:</p> <pre><code>intexit() { # Kill all subprocesses (all processes in the current process group) kill -HUP -$$ } hupexit() { # HUP'd (probably by intexit) echo echo "Interrupted" exit } trap hupexit ...
387
bash
<h1>How to kill all processes that were opened by a shell script upon ctrl + C?</h1> <p>I've got a couple python scripts which I start collectively from a shell script as follows:</p> <pre><code>#!/bin/bash python prog1.py &amp; python prog2.py &amp; python prog3.py </code></pre> <p>Since I am developing I often wan...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,241
bash
# How to kill all processes that were opened by a shell script upon ctrl + C? I've got a couple python scripts which I start collectively from a shell script as follows: ``` #!/bin/bash python prog1.py & python prog2.py & python prog3.py ``` Since I am developing I often want to stop these processes. I normally do s...
Let the bash script catch SIGINT, and have it kill everything in the current process group: ``` intexit() { # Kill all subprocesses (all processes in the current process group) kill -HUP -$$ } hupexit() { # HUP'd (probably by intexit) echo echo "Interrupted" exit } trap hupexit HUP trap intex...
13968004
How do I use Json.NET to parse json in PowerShell?
11
2012-12-20 08:29:26
<p>I want to parse JSON in PowerShell but I can't use the new v3 functions that are available in PowerShell. My first thought was to load the JSON.Net assembly and use that to parse the JSON string but it doesn't work as I expect it to.</p> <p>I have this JSON:</p> <pre><code>$json = "{""Name"": ""Apple"", ...
25,994
280,693
2022-11-07 22:53:14
13,989,994
15
2012-12-21 12:13:38
280,693
2017-10-20 11:00:59
https://stackoverflow.com/q/13968004
https://stackoverflow.com/a/13989994
<p>Ok, so here is how I did it so it works down to at least PowerShell v2 on Windows 2008.</p> <p>First, load the Json.NET assembly for the version you would like to use, I took the .NET 3.5 version:</p> <pre><code>[Reflection.Assembly]::LoadFile("Newtonsoft.Json.dll") </code></pre> <p>I had the JSON in a file since...
<p>Ok, so here is how I did it so it works down to at least PowerShell v2 on Windows 2008.</p> <p>First, load the Json.NET assembly for the version you would like to use, I took the .NET 3.5 version:</p> <pre><code>[Reflection.Assembly]::LoadFile("Newtonsoft.Json.dll") </code></pre> <p>I had the JSON in a file since...
526, 1508, 16268
json, json.net, powershell
<h1>How do I use Json.NET to parse json in PowerShell?</h1> <p>I want to parse JSON in PowerShell but I can't use the new v3 functions that are available in PowerShell. My first thought was to load the JSON.Net assembly and use that to parse the JSON string but it doesn't work as I expect it to.</p> <p>I have this JSO...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,242
bash
# How do I use Json.NET to parse json in PowerShell? I want to parse JSON in PowerShell but I can't use the new v3 functions that are available in PowerShell. My first thought was to load the JSON.Net assembly and use that to parse the JSON string but it doesn't work as I expect it to. I have this JSON: ``` $json = ...
Ok, so here is how I did it so it works down to at least PowerShell v2 on Windows 2008. First, load the Json.NET assembly for the version you would like to use, I took the .NET 3.5 version: ``` [Reflection.Assembly]::LoadFile("Newtonsoft.Json.dll") ``` I had the JSON in a file since it was used in a deployment confi...
12600177
Length of shortest line?
11
2012-09-26 10:58:06
<p>In Linux command using <code>wc -L</code> it's possible to get the length of longest line of a text file.</p> <p>How do I find the length of the <em>shortest</em> line of a text file?</p>
9,743
1,459,344
2015-12-15 00:41:01
12,600,382
15
2012-09-26 11:09:57
1,690,777
2012-09-26 11:09:57
https://stackoverflow.com/q/12600177
https://stackoverflow.com/a/12600382
<p>Try this:</p> <pre><code>awk '{print length}' &lt;your_file&gt; | sort -n | head -n1 </code></pre> <p>This command gets lengths of all files, sorts them (correctly, as numbers) and, fianlly, prints the smallest number to console.</p>
<p>Try this:</p> <pre><code>awk '{print length}' &lt;your_file&gt; | sort -n | head -n1 </code></pre> <p>This command gets lengths of all files, sorts them (correctly, as numbers) and, fianlly, prints the smallest number to console.</p>
58, 390
linux, shell
<h1>Length of shortest line?</h1> <p>In Linux command using <code>wc -L</code> it's possible to get the length of longest line of a text file.</p> <p>How do I find the length of the <em>shortest</em> line of a text file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,243
bash
# Length of shortest line? In Linux command using `wc -L` it's possible to get the length of longest line of a text file. How do I find the length of the *shortest* line of a text file?
Try this: ``` awk '{print length}' <your_file> | sort -n | head -n1 ``` This command gets lengths of all files, sorts them (correctly, as numbers) and, fianlly, prints the smallest number to console.
12320275
How to pipe output of Invoke-Expression to string?
11
2012-09-07 14:39:57
<p>In a Powershell script, I something like this:</p> <pre><code>Invoke-Expression "&amp; `"C:\Scripts\psftp.exe`" ftp.blah.com" </code></pre> <p>I want to pipe all output, errors etc of this to the string <code>$output</code></p> <p>How can I do this? I've tried <code>&gt;</code> at the end as well as <code>$output...
29,277
1,128,875
2012-09-07 14:52:36
12,320,512
15
2012-09-07 14:52:36
153,982
2012-09-07 14:52:36
https://stackoverflow.com/q/12320275
https://stackoverflow.com/a/12320512
<p>Try this:</p> <pre><code>$output = Invoke-Expression "C:\Scripts\psftp.exe ftp.blah.com 2&gt;&amp;1" </code></pre> <p>The use of the call operator <code>&amp;</code> is unnecessary as is quoting the exe path in this case since the path doesn't contain spaces. If the path contained spaces, then it would need to be...
<p>Try this:</p> <pre><code>$output = Invoke-Expression "C:\Scripts\psftp.exe ftp.blah.com 2&gt;&amp;1" </code></pre> <p>The use of the call operator <code>&amp;</code> is unnecessary as is quoting the exe path in this case since the path doesn't contain spaces. If the path contained spaces, then it would need to be...
526
powershell
<h1>How to pipe output of Invoke-Expression to string?</h1> <p>In a Powershell script, I something like this:</p> <pre><code>Invoke-Expression "&amp; `"C:\Scripts\psftp.exe`" ftp.blah.com" </code></pre> <p>I want to pipe all output, errors etc of this to the string <code>$output</code></p> <p>How can I do this? I've...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,244
bash
# How to pipe output of Invoke-Expression to string? In a Powershell script, I something like this: ``` Invoke-Expression "& `"C:\Scripts\psftp.exe`" ftp.blah.com" ``` I want to pipe all output, errors etc of this to the string `$output` How can I do this? I've tried `>` at the end as well as `$output = ...` but ne...
Try this: ``` $output = Invoke-Expression "C:\Scripts\psftp.exe ftp.blah.com 2>&1" ``` The use of the call operator `&` is unnecessary as is quoting the exe path in this case since the path doesn't contain spaces. If the path contained spaces, then it would need to be quoted and then you would have to use the call op...
10316888
Bash ${!variable}
11
2012-04-25 13:38:02
<p>I am scratching my head on this one, can't find the bash reference talking about it. </p> <p>In the code below</p> <pre><code>host_color=${uphost}_host_color host_color=${!host_color} </code></pre> <p>What is the second line doing ? what does the !operator do in this case ?</p>
11,978
258,689
2012-04-25 14:04:47
10,317,069
15
2012-04-25 13:47:32
34,148
2012-04-25 14:04:47
https://stackoverflow.com/q/10316888
https://stackoverflow.com/a/10317069
<p>That is a short form for <a href="http://tldp.org/LDP/abs/html/ivr.html" rel="noreferrer">indirect references</a>.</p> <pre><code>$ foo=bar $ bar=bas $ echo ${!foo} bas </code></pre> <p>The seemingly similar construction <a href="http://tldp.org/LDP/abs/html/parameter-substitution.html#VARPREFIXM" rel="noreferrer"...
<p>That is a short form for <a href="http://tldp.org/LDP/abs/html/ivr.html" rel="noreferrer">indirect references</a>.</p> <pre><code>$ foo=bar $ bar=bas $ echo ${!foo} bas </code></pre> <p>The seemingly similar construction <a href="http://tldp.org/LDP/abs/html/parameter-substitution.html#VARPREFIXM" rel="noreferrer"...
387
bash
<h1>Bash ${!variable}</h1> <p>I am scratching my head on this one, can't find the bash reference talking about it. </p> <p>In the code below</p> <pre><code>host_color=${uphost}_host_color host_color=${!host_color} </code></pre> <p>What is the second line doing ? what does the !operator do in this case ?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,245
bash
# Bash ${!variable} I am scratching my head on this one, can't find the bash reference talking about it. In the code below ``` host_color=${uphost}_host_color host_color=${!host_color} ``` What is the second line doing ? what does the !operator do in this case ?
That is a short form for [indirect references](http://tldp.org/LDP/abs/html/ivr.html). ``` $ foo=bar $ bar=bas $ echo ${!foo} bas ``` The seemingly similar construction [${!foo*}](http://tldp.org/LDP/abs/html/parameter-substitution.html#VARPREFIXM) expands to *the names of all variables whose name begin with foo*: `...
8186079
generate php classes in bash
11
2011-11-18 17:01:49
<p>i have this script:</p> <pre><code> #!/bin/bash if [[ -z "$1" ]] ; then echo "Class is required" exit 1; fi if [[ -z "$2" ]] ; then package="Default" else package=$2; fi echo "&lt;?php /** * $1.class.php * * Vcard class file. * @name Project * @author...
210
1,034,727
2011-11-18 17:48:51
8,186,365
15
2011-11-18 17:24:08
378,193
2011-11-18 17:48:51
https://stackoverflow.com/q/8186079
https://stackoverflow.com/a/8186365
<p>If you want to ensure it's called MyClass you can add this somewhere after the validations:</p> <pre><code>fname=$( IFS='_'; for i in ${1,,}; do echo -n ${i^}; done ) </code></pre> <p>And use <code>$fname.class.php</code></p>
<p>If you want to ensure it's called MyClass you can add this somewhere after the validations:</p> <pre><code>fname=$( IFS='_'; for i in ${1,,}; do echo -n ${i^}; done ) </code></pre> <p>And use <code>$fname.class.php</code></p>
5, 387
bash, php
<h1>generate php classes in bash</h1> <p>i have this script:</p> <pre><code> #!/bin/bash if [[ -z "$1" ]] ; then echo "Class is required" exit 1; fi if [[ -z "$2" ]] ; then package="Default" else package=$2; fi echo "&lt;?php /** * $1.class.php * * Vcard class file. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,246
bash
# generate php classes in bash i have this script: ``` #!/bin/bash if [[ -z "$1" ]] ; then echo "Class is required" exit 1; fi if [[ -z "$2" ]] ; then package="Default" else package=$2; fi echo "<?php /** * $1.class.php * * Vcard class file. * @name Proje...
If you want to ensure it's called MyClass you can add this somewhere after the validations: ``` fname=$( IFS='_'; for i in ${1,,}; do echo -n ${i^}; done ) ``` And use `$fname.class.php`
5615570
$$ in a script vs $$ in a subshell
11
2011-04-11 00:00:12
<p><code>$$</code> gives process id of the script process when used in a script, like this:</p> <p>Example 1</p> <pre><code>#!/bin/bash # processid.sh # print process ids ps -o cmd,pid,ppid echo "The value of \$\$ is $$" $ ./processid.sh CMD PID PPID bash 15073 46...
8,854
494,074
2017-02-01 02:28:49
5,630,894
15
2011-04-12 05:45:48
36,472
2011-04-12 05:45:48
https://stackoverflow.com/q/5615570
https://stackoverflow.com/a/5630894
<p>I tried and escaping (to pass the $$ to the subshell) does not work as the subshell inherits the $$ value from the parent bash. The solution to this is to use $BASHPID.</p> <pre><code>(echo $$; echo $BASHPID) </code></pre> <p>prints the PID from the parent shell and from the subshell.</p>
<p>I tried and escaping (to pass the $$ to the subshell) does not work as the subshell inherits the $$ value from the parent bash. The solution to this is to use $BASHPID.</p> <pre><code>(echo $$; echo $BASHPID) </code></pre> <p>prints the PID from the parent shell and from the subshell.</p>
387, 390, 531
bash, scripting, shell
<h1>$$ in a script vs $$ in a subshell</h1> <p><code>$$</code> gives process id of the script process when used in a script, like this:</p> <p>Example 1</p> <pre><code>#!/bin/bash # processid.sh # print process ids ps -o cmd,pid,ppid echo "The value of \$\$ is $$" $ ./processid.sh CMD PID...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,247
bash
# $$ in a script vs $$ in a subshell `$$` gives process id of the script process when used in a script, like this: Example 1 ``` #!/bin/bash # processid.sh # print process ids ps -o cmd,pid,ppid echo "The value of \$\$ is $$" $ ./processid.sh CMD PID PPID bash 150...
I tried and escaping (to pass the $$ to the subshell) does not work as the subshell inherits the $$ value from the parent bash. The solution to this is to use $BASHPID. ``` (echo $$; echo $BASHPID) ``` prints the PID from the parent shell and from the subshell.
5571579
Escaping splatted variables in Powershell Invoke-Expression
11
2011-04-06 19:02:35
<p>I'm trying to invoke another application (Beyond Compare) from Powershell which requires an @ in the typical command-line:</p> <pre><code>C:\deploy&gt;bcompare @static.diff </code></pre> <p>I've found Powershell's Invoke-Expression, but when I try the following it gives me an error:</p> <pre><code>PS C:\deploy&gt...
14,880
2,787
2019-03-15 13:36:08
5,571,703
15
2011-04-06 19:12:56
73,070
2011-04-06 19:12:56
https://stackoverflow.com/q/5571579
https://stackoverflow.com/a/5571703
<pre><code>bcompare '@static.diff' </code></pre> <p>If in doubt, put it into a string :-)</p> <pre><code>PS Home:\&gt; args '@static.diff' argv[0] = "C:\Users\Joey\Batches\args.cmd" argv[1] = @static.diff </code></pre>
<pre><code>bcompare '@static.diff' </code></pre> <p>If in doubt, put it into a string :-)</p> <pre><code>PS Home:\&gt; args '@static.diff' argv[0] = "C:\Users\Joey\Batches\args.cmd" argv[1] = @static.diff </code></pre>
526, 4804
escaping, powershell
<h1>Escaping splatted variables in Powershell Invoke-Expression</h1> <p>I'm trying to invoke another application (Beyond Compare) from Powershell which requires an @ in the typical command-line:</p> <pre><code>C:\deploy&gt;bcompare @static.diff </code></pre> <p>I've found Powershell's Invoke-Expression, but when I tr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,248
bash
# Escaping splatted variables in Powershell Invoke-Expression I'm trying to invoke another application (Beyond Compare) from Powershell which requires an @ in the typical command-line: ``` C:\deploy>bcompare @static.diff ``` I've found Powershell's Invoke-Expression, but when I try the following it gives me an error...
``` bcompare '@static.diff' ``` If in doubt, put it into a string :-) ``` PS Home:\> args '@static.diff' argv[0] = "C:\Users\Joey\Batches\args.cmd" argv[1] = @static.diff ```
4753051
How do i check if a particular MSI is installed?
11
2011-01-20 21:51:39
<p>I'm writing a powershell script that will install some dependencies for my webapp. In my script, I'm running into a recurring problem of checking if a particular application is installed. it seems there's a unique way of checking if an application exists for each application (ie: by checking the existing of this fol...
50,888
89,605
2023-07-25 16:40:33
4,753,203
15
2011-01-20 22:08:04
323,582
2014-08-18 22:04:55
https://stackoverflow.com/q/4753051
https://stackoverflow.com/a/4753203
<p>Here is the code I use sometimes (not too often, so...). See the help comments for details.</p> <pre class="lang-none prettyprint-override"><code>&lt;# .SYNOPSIS Gets uninstall records from the registry. .DESCRIPTION This function returns information similar to the "Add or remove programs" Windows tool...
<p>Here is the code I use sometimes (not too often, so...). See the help comments for details.</p> <pre class="lang-none prettyprint-override"><code>&lt;# .SYNOPSIS Gets uninstall records from the registry. .DESCRIPTION This function returns information similar to the "Add or remove programs" Windows tool...
526
powershell
<h1>How do i check if a particular MSI is installed?</h1> <p>I'm writing a powershell script that will install some dependencies for my webapp. In my script, I'm running into a recurring problem of checking if a particular application is installed. it seems there's a unique way of checking if an application exists for ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,249
bash
# How do i check if a particular MSI is installed? I'm writing a powershell script that will install some dependencies for my webapp. In my script, I'm running into a recurring problem of checking if a particular application is installed. it seems there's a unique way of checking if an application exists for each appl...
Here is the code I use sometimes (not too often, so...). See the help comments for details. ``` <# .SYNOPSIS Gets uninstall records from the registry. .DESCRIPTION This function returns information similar to the "Add or remove programs" Windows tool. The function normally works much faster and gets some ...
4250280
Shell script detecting running in Cygwin
11
2010-11-22 21:13:12
<p>Is there a simple way to check if a script is running in Cygwin. We have a script that calls a utility that expects the paths passed to be windows so if we're in Cygwin we have to convert the paths to windows paths.</p>
3,964
98,050
2014-07-21 17:31:13
4,251,218
15
2010-11-22 23:17:52
430,775
2010-11-22 23:17:52
https://stackoverflow.com/q/4250280
https://stackoverflow.com/a/4251218
<p>You can use the <code>uname</code> utility. From <a href="http://linux.die.net/man/1/uname" rel="noreferrer">uname(1)</a>:</p> <blockquote>-o, --operating-system<br> print the operating system </blockquote> <p>Example code:</p> <pre><code>if [ `uname -o` = "Cygwin" ] then # Cygwin specific stuff else ...
<p>You can use the <code>uname</code> utility. From <a href="http://linux.die.net/man/1/uname" rel="noreferrer">uname(1)</a>:</p> <blockquote>-o, --operating-system<br> print the operating system </blockquote> <p>Example code:</p> <pre><code>if [ `uname -o` = "Cygwin" ] then # Cygwin specific stuff else ...
34, 64, 387, 390, 1731
bash, cygwin, shell, unix, windows
<h1>Shell script detecting running in Cygwin</h1> <p>Is there a simple way to check if a script is running in Cygwin. We have a script that calls a utility that expects the paths passed to be windows so if we're in Cygwin we have to convert the paths to windows paths.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,250
bash
# Shell script detecting running in Cygwin Is there a simple way to check if a script is running in Cygwin. We have a script that calls a utility that expects the paths passed to be windows so if we're in Cygwin we have to convert the paths to windows paths.
You can use the `uname` utility. From [uname(1)](http://linux.die.net/man/1/uname): > -o, --operating-system > print the operating system Example code: ``` if [ `uname -o` = "Cygwin" ] then # Cygwin specific stuff else # Other UNIX (Linux, etc.) specific stuff fi ```
2572495
read from file and add numbers
11
2010-04-03 20:01:53
<p>I have text file with entries like 123 112 3333 44 2</p> <p>How to add these numbers and get the sum of these.</p>
24,163
308,445
2018-10-11 16:16:09
2,572,514
15
2010-04-03 20:07:50
89,391
2018-10-11 16:16:09
https://stackoverflow.com/q/2572495
https://stackoverflow.com/a/2572514
<p>Example:</p> <pre><code>$ cat numbers.txt 123 112 3333 44 2 $ SUM=0; for i in `cat numbers.txt`; do SUM=$(($SUM + $i)); done; echo $SUM 3614 </code></pre> <p>See also: <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-10.html#ss10.2" rel="noreferrer">Bash Programming Introduction, section on arithmetic evaluat...
<p>Example:</p> <pre><code>$ cat numbers.txt 123 112 3333 44 2 $ SUM=0; for i in `cat numbers.txt`; do SUM=$(($SUM + $i)); done; echo $SUM 3614 </code></pre> <p>See also: <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-10.html#ss10.2" rel="noreferrer">Bash Programming Introduction, section on arithmetic evaluat...
387, 14215
addition, bash
<h1>read from file and add numbers</h1> <p>I have text file with entries like 123 112 3333 44 2</p> <p>How to add these numbers and get the sum of these.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,251
bash
# read from file and add numbers I have text file with entries like 123 112 3333 44 2 How to add these numbers and get the sum of these.
Example: ``` $ cat numbers.txt 123 112 3333 44 2 $ SUM=0; for i in `cat numbers.txt`; do SUM=$(($SUM + $i)); done; echo $SUM 3614 ``` See also: [Bash Programming Introduction, section on arithmetic evaluation](http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-10.html#ss10.2) Another way would be to use `bc`, an arbitrary...
2164986
powershell xml xpath
11
2010-01-29 20:37:10
<p>In Powershell, suppose I have the following xml:</p> <pre><code> &lt;Users&gt; &lt;User Name="Foo"&gt; &lt;Friends&gt; &lt;Friend Name="Bar"/&gt; &lt;/Friends&gt; &lt;/User&gt; &lt;User Name="Foo2" /&gt; &lt;User Name="Foo3"&gt; &lt;Friends&gt; &lt;Friend Name="Bar...
18,655
20,257
2019-09-04 15:21:55
2,165,192
15
2010-01-29 21:12:09
153,982
2010-01-29 21:12:09
https://stackoverflow.com/q/2164986
https://stackoverflow.com/a/2165192
<p>I have a preference for using XPath these days. I've run into issues using PowerShell's xml adapter that are annoying like the name collision on <code>item</code>:</p> <pre><code>$xml = [xml]@' &lt;Users&gt; &lt;User Name="Foo"&gt; &lt;Friends&gt; &lt;Friend Name="Bar"/&gt; &lt;/Friend...
<p>I have a preference for using XPath these days. I've run into issues using PowerShell's xml adapter that are annoying like the name collision on <code>item</code>:</p> <pre><code>$xml = [xml]@' &lt;Users&gt; &lt;User Name="Foo"&gt; &lt;Friends&gt; &lt;Friend Name="Bar"/&gt; &lt;/Friend...
19, 526, 1227
powershell, xml, xpath
<h1>powershell xml xpath</h1> <p>In Powershell, suppose I have the following xml:</p> <pre><code> &lt;Users&gt; &lt;User Name="Foo"&gt; &lt;Friends&gt; &lt;Friend Name="Bar"/&gt; &lt;/Friends&gt; &lt;/User&gt; &lt;User Name="Foo2" /&gt; &lt;User Name="Foo3"&gt; &lt;Friends&gt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,252
bash
# powershell xml xpath In Powershell, suppose I have the following xml: ``` <Users> <User Name="Foo"> <Friends> <Friend Name="Bar"/> </Friends> </User> <User Name="Foo2" /> <User Name="Foo3"> <Friends> <Friend Name="Bar"/> </Friends> </User> </Users> ```...
I have a preference for using XPath these days. I've run into issues using PowerShell's xml adapter that are annoying like the name collision on `item`: ``` $xml = [xml]@' <Users> <User Name="Foo"> <Friends> <Friend Name="Bar"/> </Friends> </User> <User Name="Foo2" /> <User...
1644532
How to split file on first empty line in a portable way in shell (e.g. using sed)?
11
2009-10-29 15:27:04
<p>I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first line containing only CR = '<code>\r</code>' character) using a <strong>shell script</strong...
8,836
46,058
2023-02-16 10:42:10
1,644,576
15
2009-10-29 15:34:02
68,587
2009-10-29 15:34:02
https://stackoverflow.com/q/1644532
https://stackoverflow.com/a/1644576
<pre><code>$ cat test.txt a b c d e f $ sed '/^$/q' test.txt a b c $ sed '1,/^$/d' test.txt d e f </code></pre> <p>Change the <code>/^$/</code> to <code>/^\s*$/</code> if you expect there may be whitespace on the blank line.</p>
<pre><code>$ cat test.txt a b c d e f $ sed '/^$/q' test.txt a b c $ sed '1,/^$/d' test.txt d e f </code></pre> <p>Change the <code>/^$/</code> to <code>/^\s*$/</code> if you expect there may be whitespace on the blank line.</p>
390, 1407, 5050, 5282, 30640
filesplitting, portability, sed, shell, text-manipulation
<h1>How to split file on first empty line in a portable way in shell (e.g. using sed)?</h1> <p>I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,253
bash
# How to split file on first empty line in a portable way in shell (e.g. using sed)? I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first line cont...
``` $ cat test.txt a b c d e f $ sed '/^$/q' test.txt a b c $ sed '1,/^$/d' test.txt d e f ``` Change the `/^$/` to `/^\s*$/` if you expect there may be whitespace on the blank line.
1390782
Jagged PowerShell array is losing a dimension when only one element exists
11
2009-09-07 19:59:10
<p>I have the following PowerShell function that works well for any input except for <code>1</code>. If I pass it an input of <code>1</code> it will return an array with two elements <code>1,1</code> instead of a single element which is itself an array of two elements <code>(1,1)</code>.</p> <p><strong>Any ideas how ...
2,131
3,957
2023-02-21 11:19:42
1,391,042
15
2009-09-07 21:39:05
5,460
2012-08-17 18:10:09
https://stackoverflow.com/q/1390782
https://stackoverflow.com/a/1391042
<p>I tested this on the PowerShell V2 CTP on Windows XP, and saw the same results as the OP.</p> <p>The problem appears to be PowerShell's habit of "flattening" collections as they're passed along the pipeline. A simple solution is to wrap the return value in an collection by prefacing the expression to be returned wi...
<p>I tested this on the PowerShell V2 CTP on Windows XP, and saw the same results as the OP.</p> <p>The problem appears to be PowerShell's habit of "flattening" collections as they're passed along the pipeline. A simple solution is to wrap the return value in an collection by prefacing the expression to be returned wi...
114, 526
arrays, powershell
<h1>Jagged PowerShell array is losing a dimension when only one element exists</h1> <p>I have the following PowerShell function that works well for any input except for <code>1</code>. If I pass it an input of <code>1</code> it will return an array with two elements <code>1,1</code> instead of a single element which i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,254
bash
# Jagged PowerShell array is losing a dimension when only one element exists I have the following PowerShell function that works well for any input except for `1`. If I pass it an input of `1` it will return an array with two elements `1,1` instead of a single element which is itself an array of two elements `(1,1)`. ...
I tested this on the PowerShell V2 CTP on Windows XP, and saw the same results as the OP. The problem appears to be PowerShell's habit of "flattening" collections as they're passed along the pipeline. A simple solution is to wrap the return value in an collection by prefacing the expression to be returned with the com...
1070050
Powershell in SSIS
11
2009-07-01 16:18:28
<p>What would I need to do in order to run a PowerShell script in an SSIS package? </p> <p>Does PowerShell need to be installed on the SQL server? How do I actually call the script in SSIS?</p> <p>Thanks</p>
5,754
33,470
2018-07-27 06:45:48
1,070,088
15
2009-07-01 16:24:52
95,589
2009-07-01 16:24:52
https://stackoverflow.com/q/1070050
https://stackoverflow.com/a/1070088
<p>Yes, PowerShell needs to be installed. Then, you can use an <a href="http://msdn.microsoft.com/en-us/library/ms141166.aspx" rel="noreferrer">Execute Process Task</a> to point to the PowerShell executable and give the script as an argument.</p> <p>Like so:</p> <pre><code>Executable: %windir%\system32\WindowsPowerSh...
<p>Yes, PowerShell needs to be installed. Then, you can use an <a href="http://msdn.microsoft.com/en-us/library/ms141166.aspx" rel="noreferrer">Execute Process Task</a> to point to the PowerShell executable and give the script as an argument.</p> <p>Like so:</p> <pre><code>Executable: %windir%\system32\WindowsPowerSh...
526, 2175
powershell, ssis
<h1>Powershell in SSIS</h1> <p>What would I need to do in order to run a PowerShell script in an SSIS package? </p> <p>Does PowerShell need to be installed on the SQL server? How do I actually call the script in SSIS?</p> <p>Thanks</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,255
bash
# Powershell in SSIS What would I need to do in order to run a PowerShell script in an SSIS package? Does PowerShell need to be installed on the SQL server? How do I actually call the script in SSIS? Thanks
Yes, PowerShell needs to be installed. Then, you can use an [Execute Process Task](http://msdn.microsoft.com/en-us/library/ms141166.aspx) to point to the PowerShell executable and give the script as an argument. Like so: ``` Executable: %windir%\system32\WindowsPowerShell\v1.0\powershell.exe Arguments: C:\path\to\sc...
68561415
cant suppress or use an AWS-CLI error in bash
10
2021-07-28 13:33:42
<p>i have a simple script that i want to display specific information from AWS using AWS CLI.</p> <p>for example:</p> <pre><code>get_cluster_name() { EKS_NAME=$(aws eks describe-cluster --name ${CUSTOMER_NAME}) &amp;&amp; \ echo $EKS_NAME | jq -r .cluster.name} </code></pre> <p>the output when the cluster exist is ok, ...
12,436
9,658,396
2021-07-28 14:10:31
68,561,991
15
2021-07-28 14:10:31
2,221,001
2021-07-28 14:10:31
https://stackoverflow.com/q/68561415
https://stackoverflow.com/a/68561991
<p>Here's a consideration, and expansion on my comments. Again you're getting a <code>stderr</code> response when no cluster is found, so this makes this pretty straightforward.</p> <p>Using <code>&gt;2 /dev/null</code> to suppress that return message in stderr. Then using <code>ret=$?</code> to capture the return code...
<p>Here's a consideration, and expansion on my comments. Again you're getting a <code>stderr</code> response when no cluster is found, so this makes this pretty straightforward.</p> <p>Using <code>&gt;2 /dev/null</code> to suppress that return message in stderr. Then using <code>ret=$?</code> to capture the return code...
387, 4867, 19156, 99166
aws-cli, bash, stderr, stdout
<h1>cant suppress or use an AWS-CLI error in bash</h1> <p>i have a simple script that i want to display specific information from AWS using AWS CLI.</p> <p>for example:</p> <pre><code>get_cluster_name() { EKS_NAME=$(aws eks describe-cluster --name ${CUSTOMER_NAME}) &amp;&amp; \ echo $EKS_NAME | jq -r .cluster.name} </c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,256
bash
# cant suppress or use an AWS-CLI error in bash i have a simple script that i want to display specific information from AWS using AWS CLI. for example: ``` get_cluster_name() { EKS_NAME=$(aws eks describe-cluster --name ${CUSTOMER_NAME}) && \ echo $EKS_NAME | jq -r .cluster.name} ``` the output when the cluster exi...
Here's a consideration, and expansion on my comments. Again you're getting a `stderr` response when no cluster is found, so this makes this pretty straightforward. Using `>2 /dev/null` to suppress that return message in stderr. Then using `ret=$?` to capture the return code. ``` get_cluster_name() { EKS_NAME=$(aws ...
58449069
How to enable "Allow Azure services and resources to access this server" through PowerShell (Azure CLI)?
10
2019-10-18 10:33:46
<p>After creating a new Azure SQL server using <code>az sql server create</code>, how can I enable the following options through PowerShell(Azure CLI)?</p> <p><a href="https://i.sstatic.net/gXOpx.png" rel="noreferrer"><img src="https://i.sstatic.net/gXOpx.png" alt="enter image description here"></a></p>
7,956
3,037,607
2024-03-15 19:32:48
58,449,999
15
2019-10-18 11:30:36
8,734,587
2019-10-18 11:30:36
https://stackoverflow.com/q/58449069
https://stackoverflow.com/a/58449999
<p>It's in the documentation for Azure SQL somewhere, if you search for "azure sql firewall allow azure services", but here's what you need to do - create a rule with a start and end address of 0.0.0.0, like this:</p> <pre><code>az sql server firewall-rule create --resource-group &lt;resource group name&gt; --server &...
<p>It's in the documentation for Azure SQL somewhere, if you search for "azure sql firewall allow azure services", but here's what you need to do - create a rule with a start and end address of 0.0.0.0, like this:</p> <pre><code>az sql server firewall-rule create --resource-group &lt;resource group name&gt; --server &...
72, 526, 2045, 14158, 108105
azure, azure-cli, firewall, powershell, sql-server
<h1>How to enable "Allow Azure services and resources to access this server" through PowerShell (Azure CLI)?</h1> <p>After creating a new Azure SQL server using <code>az sql server create</code>, how can I enable the following options through PowerShell(Azure CLI)?</p> <p><a href="https://i.sstatic.net/gXOpx.png" rel=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,258
bash
# How to enable "Allow Azure services and resources to access this server" through PowerShell (Azure CLI)? After creating a new Azure SQL server using `az sql server create`, how can I enable the following options through PowerShell(Azure CLI)? [![enter image description here](https://i.sstatic.net/gXOpx.png)](https:...
It's in the documentation for Azure SQL somewhere, if you search for "azure sql firewall allow azure services", but here's what you need to do - create a rule with a start and end address of 0.0.0.0, like this: ``` az sql server firewall-rule create --resource-group <resource group name> --server <azure sql name> -n <...
58431906
Can a PowerShell function handle multiple input types?
10
2019-10-17 11:47:14
<p>I'm working on a function that compares two objects so it detects them if they are identical. However I would like it to also work with other types like strings or integers.</p> <p>C++ lets you declare different functions with the same name to handle function calls with different input types in a different way. I'm ...
6,334
6,068,574
2022-06-15 07:46:42
58,433,717
15
2019-10-17 13:22:06
45,375
2022-06-15 07:46:42
https://stackoverflow.com/q/58431906
https://stackoverflow.com/a/58433717
<p>As <a href="https://stackoverflow.com/users/6083222/jeff-zeitlin">Jeff Zeitlin</a> states in his comment:</p> <p><strong>Users do NOT have to specify a parameter set explicitly - PowerShell <em>infers</em> the applicable parameter set</strong> from the specific combination of arguments (or absence thereof) passed on...
<p>As <a href="https://stackoverflow.com/users/6083222/jeff-zeitlin">Jeff Zeitlin</a> states in his comment:</p> <p><strong>Users do NOT have to specify a parameter set explicitly - PowerShell <em>infers</em> the applicable parameter set</strong> from the specific combination of arguments (or absence thereof) passed on...
526, 5569, 119568
function, parameter-sets, powershell
<h1>Can a PowerShell function handle multiple input types?</h1> <p>I'm working on a function that compares two objects so it detects them if they are identical. However I would like it to also work with other types like strings or integers.</p> <p>C++ lets you declare different functions with the same name to handle fu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,259
bash
# Can a PowerShell function handle multiple input types? I'm working on a function that compares two objects so it detects them if they are identical. However I would like it to also work with other types like strings or integers. C++ lets you declare different functions with the same name to handle function calls wi...
As [Jeff Zeitlin](https://stackoverflow.com/users/6083222/jeff-zeitlin) states in his comment: **Users do NOT have to specify a parameter set explicitly - PowerShell *infers* the applicable parameter set** from the specific combination of arguments (or absence thereof) passed on invocation. The inference is based on ...
57594415
PowerShell Hashtable show first key
10
2019-08-21 15:00:25
<p>I am playing around with hashtables in powershell and try to figure out, if there is a way, to show the content of Key1 (not the value).</p> <p>I tried several ways to have as an result "Monday" but either I get all the names of the table, a blank return or an error message.</p> <p><strong>here's my table</strong>...
10,682
10,733,432
2021-08-11 06:43:26
57,595,340
15
2019-08-21 15:53:15
28,828
2019-08-21 15:53:15
https://stackoverflow.com/q/57594415
https://stackoverflow.com/a/57595340
<p>You can access the Key/ValueCollection inside the hashtable:</p> <pre><code>$Weekdays = @{Monday = 'Montag';Tuesday = 'Dienstag'} echo $($Weekdays.Keys)[0] echo $($Weekdays.Values)[1] </code></pre> <p>will return</p> <pre><code>Monday Dienstag </code></pre> <p>enclosing the call to "Keys" in $() will result ...
<p>You can access the Key/ValueCollection inside the hashtable:</p> <pre><code>$Weekdays = @{Monday = 'Montag';Tuesday = 'Dienstag'} echo $($Weekdays.Keys)[0] echo $($Weekdays.Values)[1] </code></pre> <p>will return</p> <pre><code>Monday Dienstag </code></pre> <p>enclosing the call to "Keys" in $() will result ...
526, 5189
hashtable, powershell
<h1>PowerShell Hashtable show first key</h1> <p>I am playing around with hashtables in powershell and try to figure out, if there is a way, to show the content of Key1 (not the value).</p> <p>I tried several ways to have as an result "Monday" but either I get all the names of the table, a blank return or an error mess...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,260
bash
# PowerShell Hashtable show first key I am playing around with hashtables in powershell and try to figure out, if there is a way, to show the content of Key1 (not the value). I tried several ways to have as an result "Monday" but either I get all the names of the table, a blank return or an error message. **here's m...
You can access the Key/ValueCollection inside the hashtable: ``` $Weekdays = @{Monday = 'Montag';Tuesday = 'Dienstag'} echo $($Weekdays.Keys)[0] echo $($Weekdays.Values)[1] ``` will return ``` Monday Dienstag ``` enclosing the call to "Keys" in $() will result in the Collection being converted to an Object Arra...
50281853
git credential helper not working
10
2018-05-10 21:35:51
<p>I'm trying to save my git password to avoid typing every time.</p> <p>I am using git bash on windows 10. </p> <p>git continues to demand a password everytime I hit remote.</p> <p>(Is git bash why its not working?)</p> <p>I have tried:</p> <pre><code>git config --global credential.helper 'cache --timeout 28800'...
20,728
467,240
2024-10-07 19:44:37
50,285,265
15
2018-05-11 04:59:42
6,309
2024-10-07 19:44:37
https://stackoverflow.com/q/50281853
https://stackoverflow.com/a/50285265
<p>First, for Windows, the credential helper to use is <code>manager</code><br /> (see more at &quot;<a href="https://stackoverflow.com/a/65468187/6309">How to remove github login popup asking for credentials?</a>&quot;):</p> <pre><code>git config --global credential.helper manager </code></pre> <p>Second, this only wo...
<p>First, for Windows, the credential helper to use is <code>manager</code><br /> (see more at &quot;<a href="https://stackoverflow.com/a/65468187/6309">How to remove github login popup asking for credentials?</a>&quot;):</p> <pre><code>git config --global credential.helper manager </code></pre> <p>Second, this only wo...
119, 5357, 61874
credentials, git, git-bash
<h1>git credential helper not working</h1> <p>I'm trying to save my git password to avoid typing every time.</p> <p>I am using git bash on windows 10. </p> <p>git continues to demand a password everytime I hit remote.</p> <p>(Is git bash why its not working?)</p> <p>I have tried:</p> <pre><code>git config --globa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,261
bash
# git credential helper not working I'm trying to save my git password to avoid typing every time. I am using git bash on windows 10. git continues to demand a password everytime I hit remote. (Is git bash why its not working?) I have tried: ``` git config --global credential.helper 'cache --timeout 28800' ``` A...
First, for Windows, the credential helper to use is `manager` (see more at "[How to remove github login popup asking for credentials?](https://stackoverflow.com/a/65468187/6309)"): ``` git config --global credential.helper manager ``` Second, this only works for HTTPS URLs, not SSH ones (`user@server.com`) For SSH...
48627989
Open a terminal via gnome-terminal then execute command, error : "failed to execute child process""
10
2018-02-05 17:16:59
<p>Via a bash command, I want open a terminal and, from the new terminal, execute a simple bash command. </p> <p>I tried: </p> <pre><code>gnome-terminal -- "/bin/bash -c ls" </code></pre> <p>But I got this error: </p> <p><a href="https://i.sstatic.net/xvggS.png" rel="noreferrer"><img src="https://i.sstatic.net/xvgg...
22,228
2,137,454
2019-09-28 12:12:00
48,628,070
15
2018-02-05 17:22:02
14,122
2018-02-05 17:22:02
https://stackoverflow.com/q/48627989
https://stackoverflow.com/a/48628070
<p>The quotes are telling the terminal to run an executable in <code>/bin</code> called <code>bash -c ls</code> (with the spaces as part of its name!). There exists no such executable.</p> <p>Take them out:</p> <pre><code>gnome-terminal -- /bin/bash -c ls </code></pre> <p>...or, to actually make something stay open ...
<p>The quotes are telling the terminal to run an executable in <code>/bin</code> called <code>bash -c ls</code> (with the spaces as part of its name!). There exists no such executable.</p> <p>Take them out:</p> <pre><code>gnome-terminal -- /bin/bash -c ls </code></pre> <p>...or, to actually make something stay open ...
387, 32965
bash, gnome-terminal
<h1>Open a terminal via gnome-terminal then execute command, error : "failed to execute child process""</h1> <p>Via a bash command, I want open a terminal and, from the new terminal, execute a simple bash command. </p> <p>I tried: </p> <pre><code>gnome-terminal -- "/bin/bash -c ls" </code></pre> <p>But I got this er...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,262
bash
# Open a terminal via gnome-terminal then execute command, error : "failed to execute child process"" Via a bash command, I want open a terminal and, from the new terminal, execute a simple bash command. I tried: ``` gnome-terminal -- "/bin/bash -c ls" ``` But I got this error: [![enter image description here](htt...
The quotes are telling the terminal to run an executable in `/bin` called `bash -c ls` (with the spaces as part of its name!). There exists no such executable. Take them out: ``` gnome-terminal -- /bin/bash -c ls ``` ...or, to actually make something stay open until the user provides input... ``` gnome-terminal -- ...