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
17975232
Shell redirection i/o order
25
2013-07-31 15:58:39
<p>I'm playing with i/o shell redirection. The commands I've tried (in bash):</p> <pre><code>ls -al *.xyz 2&gt;&amp;1 1&gt; files.lst </code></pre> <p>and</p> <pre><code>ls -al *.xyz 1&gt; files.lst 2&gt;&amp;1 </code></pre> <p>There is no any <code>*.xyz</code> file in current folder.</p> <p>These commands gives ...
8,887
689,990
2022-08-25 08:04:42
17,975,577
15
2013-07-31 16:13:57
548,225
2013-07-31 16:13:57
https://stackoverflow.com/q/17975232
https://stackoverflow.com/a/17975577
<p>This error:</p> <pre><code>ls: *.xyz: No such file or directory </code></pre> <p>is being written on <code>stderr</code> by <code>ls</code> binary.</p> <p>However in this command:</p> <pre><code>ls -al *.xyz 2&gt;&amp;1 1&gt; files.lst </code></pre> <p><strong>You're first redirecting</strong> <code>stderr</cod...
<p>This error:</p> <pre><code>ls: *.xyz: No such file or directory </code></pre> <p>is being written on <code>stderr</code> by <code>ls</code> binary.</p> <p>However in this command:</p> <pre><code>ls -al *.xyz 2&gt;&amp;1 1&gt; files.lst </code></pre> <p><strong>You're first redirecting</strong> <code>stderr</cod...
387, 390, 4867, 19156, 26698
bash, io-redirection, shell, stderr, stdout
<h1>Shell redirection i/o order</h1> <p>I'm playing with i/o shell redirection. The commands I've tried (in bash):</p> <pre><code>ls -al *.xyz 2&gt;&amp;1 1&gt; files.lst </code></pre> <p>and</p> <pre><code>ls -al *.xyz 1&gt; files.lst 2&gt;&amp;1 </code></pre> <p>There is no any <code>*.xyz</code> file in current ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,062
bash
# Shell redirection i/o order I'm playing with i/o shell redirection. The commands I've tried (in bash): ``` ls -al *.xyz 2>&1 1> files.lst ``` and ``` ls -al *.xyz 1> files.lst 2>&1 ``` There is no any `*.xyz` file in current folder. These commands gives me the different results. The first command shows an error...
This error: ``` ls: *.xyz: No such file or directory ``` is being written on `stderr` by `ls` binary. However in this command: ``` ls -al *.xyz 2>&1 1> files.lst ``` **You're first redirecting** `stderr` to `stdout` which by default goes to `tty` (terminal) And then you're redirecting `stdout` to a file `files.ls...
12561654
BASH: difference between "export k=1" vs. "k=1"
25
2012-09-24 08:52:25
<p>I am going to write an script and It looks there is no difference between:</p> <pre><code>export k=1 </code></pre> <p>and</p> <pre><code>k=1 </code></pre> <p>Am I right?</p>
7,733
1,501,388
2012-09-24 10:04:58
12,562,787
15
2012-09-24 10:04:58
736,308
2012-09-24 10:04:58
https://stackoverflow.com/q/12561654
https://stackoverflow.com/a/12562787
<p>Every process, even on Windows, has a block of memory known as the <em>environment block</em>, this contains <em>environment variables</em>. When a new process is created, by default, the environment block of the parent process is copied to the child, so environment variables are a simple way of passing text data ...
<p>Every process, even on Windows, has a block of memory known as the <em>environment block</em>, this contains <em>environment variables</em>. When a new process is created, by default, the environment block of the parent process is copied to the child, so environment variables are a simple way of passing text data ...
58, 387, 390
bash, linux, shell
<h1>BASH: difference between "export k=1" vs. "k=1"</h1> <p>I am going to write an script and It looks there is no difference between:</p> <pre><code>export k=1 </code></pre> <p>and</p> <pre><code>k=1 </code></pre> <p>Am I right?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,063
bash
# BASH: difference between "export k=1" vs. "k=1" I am going to write an script and It looks there is no difference between: ``` export k=1 ``` and ``` k=1 ``` Am I right?
Every process, even on Windows, has a block of memory known as the *environment block*, this contains *environment variables*. When a new process is created, by default, the environment block of the parent process is copied to the child, so environment variables are a simple way of passing text data to a child process....
5917439
Bash bad substitution with subshell and substring
25
2011-05-06 21:59:10
<p>A contrived example... given </p> <pre><code>FOO="/foo/bar/baz" </code></pre> <p>this works (in bash)</p> <pre><code>BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" </code></pre> <p>this doesn't</p> <pre><code>BAZ=${$(basename $FOO):0:1} # result is bad substitution </code><...
42,898
123,054
2019-09-03 15:02:07
5,917,742
15
2011-05-06 22:39:40
107,331
2011-05-06 22:39:40
https://stackoverflow.com/q/5917439
https://stackoverflow.com/a/5917742
<p>First off, note that when you say this:</p> <pre><code>BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" </code></pre> <p>the first bit in the construct for <code>BAZ</code> is <code>BAR</code> and not the <em>value</em> that you want to take the first character of. So even if bas...
<p>First off, note that when you say this:</p> <pre><code>BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" </code></pre> <p>the first bit in the construct for <code>BAZ</code> is <code>BAR</code> and not the <em>value</em> that you want to take the first character of. So even if bas...
139, 387, 16107, 57788
bash, string, subshell, substitution
<h1>Bash bad substitution with subshell and substring</h1> <p>A contrived example... given </p> <pre><code>FOO="/foo/bar/baz" </code></pre> <p>this works (in bash)</p> <pre><code>BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" </code></pre> <p>this doesn't</p> <pre><code>BAZ=${...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,064
bash
# Bash bad substitution with subshell and substring A contrived example... given ``` FOO="/foo/bar/baz" ``` this works (in bash) ``` BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" ``` this doesn't ``` BAZ=${$(basename $FOO):0:1} # result is bad substitution ``` My question is...
First off, note that when you say this: ``` BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" ``` the first bit in the construct for `BAZ` is `BAR` and not the *value* that you want to take the first character of. So even if bash allowed variable names to contain arbitrary characters...
54372601
Running "Git-Clone" from Powershell giving errors even when it seems to work
24
2019-01-25 20:52:22
<p>How do I interpret the errors coming out of this PowerShell script that calls &quot;Git Clone&quot; (actually using GitLab). And can I clone an empty directory and cause it to work without getting errors?</p> <pre><code>$path1 = &quot;d:\GitPath&quot; $path2 = &quot;${path1}\mycompany-mygroup-nealtestautomation01-...
19,172
160,245
2025-03-25 18:09:23
54,624,579
15
2019-02-11 05:45:49
6,309
2025-03-25 18:09:23
https://stackoverflow.com/q/54372601
https://stackoverflow.com/a/54624579
<p>As I mention in &quot;<a href="https://stackoverflow.com/a/47367768/6309">PowerShell Capture Git Output</a>&quot;, since a Git command can output information message on stderr (<a href="https://stackoverflow.com/a/37561629/6309">instead of stdout</a>), (for Git 2.16+) try this in the command prompt</p> <pre><code>se...
<p>As I mention in &quot;<a href="https://stackoverflow.com/a/47367768/6309">PowerShell Capture Git Output</a>&quot;, since a Git command can output information message on stderr (<a href="https://stackoverflow.com/a/37561629/6309">instead of stdout</a>), (for Git 2.16+) try this in the command prompt</p> <pre><code>se...
119, 95686
git, powershell-4.0
<h1>Running "Git-Clone" from Powershell giving errors even when it seems to work</h1> <p>How do I interpret the errors coming out of this PowerShell script that calls &quot;Git Clone&quot; (actually using GitLab). And can I clone an empty directory and cause it to work without getting errors?</p> <pre><code>$path1 = &...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,065
bash
# Running "Git-Clone" from Powershell giving errors even when it seems to work How do I interpret the errors coming out of this PowerShell script that calls "Git Clone" (actually using GitLab). And can I clone an empty directory and cause it to work without getting errors? ``` $path1 = "d:\GitPath" $path2 = "${path1...
As I mention in "[PowerShell Capture Git Output](https://stackoverflow.com/a/47367768/6309)", since a Git command can output information message on stderr ([instead of stdout](https://stackoverflow.com/a/37561629/6309)), (for Git 2.16+) try this in the command prompt ``` set GIT_REDIRECT_STDERR=2>&1 ``` or this comma...
22996645
Brace expansion in python glob
24
2014-04-10 18:55:04
<p>I have python 2.7 and am trying to issue:</p> <pre><code>glob('{faint,bright*}/{science,calib}/chip?/') </code></pre> <p>I obtain no matches, however from the shell <code>echo {faint,bright*}/{science,calib}/chip?</code> gives:</p> <pre><code>faint/science/chip1 faint/science/chip2 faint/calib/chip1 faint/calib/c...
12,469
1,040,266
2024-05-06 03:46:07
38,485,954
15
2016-07-20 16:27:20
912,236
2022-05-01 15:12:08
https://stackoverflow.com/q/22996645
https://stackoverflow.com/a/38485954
<p>Combining globbing with brace expansion.</p> <pre><code>pip install braceexpand </code></pre> <p>Sample:</p> <pre class="lang-py prettyprint-override"><code>from glob import glob from braceexpand import braceexpand def braced_glob(path): l = [] for x in braceexpand(path): l.extend(glob(x)) ...
<p>Combining globbing with brace expansion.</p> <pre><code>pip install braceexpand </code></pre> <p>Sample:</p> <pre class="lang-py prettyprint-override"><code>from glob import glob from braceexpand import braceexpand def braced_glob(path): l = [] for x in braceexpand(path): l.extend(glob(x)) ...
16, 387, 390, 3889, 19863
bash, expansion, glob, python, shell
<h1>Brace expansion in python glob</h1> <p>I have python 2.7 and am trying to issue:</p> <pre><code>glob('{faint,bright*}/{science,calib}/chip?/') </code></pre> <p>I obtain no matches, however from the shell <code>echo {faint,bright*}/{science,calib}/chip?</code> gives:</p> <pre><code>faint/science/chip1 faint/scien...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,066
bash
# Brace expansion in python glob I have python 2.7 and am trying to issue: ``` glob('{faint,bright*}/{science,calib}/chip?/') ``` I obtain no matches, however from the shell `echo {faint,bright*}/{science,calib}/chip?` gives: ``` faint/science/chip1 faint/science/chip2 faint/calib/chip1 faint/calib/chip2 bright1/sc...
Combining globbing with brace expansion. ``` pip install braceexpand ``` Sample: ``` from glob import glob from braceexpand import braceexpand def braced_glob(path): l = [] for x in braceexpand(path): l.extend(glob(x)) return l ``` ``` >>> braced_glob('/usr/bin/{x,z}*k') ['/usr/b...
17945514
Find files which does not contains selected string
24
2013-07-30 11:14:54
<p>I am trying to find all files, which does not contains a selected string. Find files which contains is easy:</p> <pre><code>gci | select-string "something" </code></pre> <p>but I do not have an idea how to negate this statement.</p>
26,180
1,749,895
2024-06-27 14:24:19
17,945,858
15
2013-07-30 11:30:23
1,324,345
2013-07-30 11:30:23
https://stackoverflow.com/q/17945514
https://stackoverflow.com/a/17945858
<p>I'm not sure if it can be done without the <code>foreach-object</code> but this works:</p> <pre><code>gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}} </code></pre>
<p>I'm not sure if it can be done without the <code>foreach-object</code> but this works:</p> <pre><code>gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}} </code></pre>
526
powershell
<h1>Find files which does not contains selected string</h1> <p>I am trying to find all files, which does not contains a selected string. Find files which contains is easy:</p> <pre><code>gci | select-string "something" </code></pre> <p>but I do not have an idea how to negate this statement.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,067
bash
# Find files which does not contains selected string I am trying to find all files, which does not contains a selected string. Find files which contains is easy: ``` gci | select-string "something" ``` but I do not have an idea how to negate this statement.
I'm not sure if it can be done without the `foreach-object` but this works: ``` gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}} ```
10481685
Setting colors for prompt in Git Bash on Windows
24
2012-05-07 11:59:51
<p>I've successfully played around with some of the color settings in the Git Bash on Windows - I'm able to set a few things, like the colors of the local, the current and remote branches in my <code>.gitconfig</code> file:</p> <pre><code>[color "branch"] current = cyan bold local = cyan remote = red </code></pre> <...
22,973
13,302
2023-09-14 11:16:59
10,483,234
15
2012-05-07 13:46:28
26,428
2012-05-07 13:46:28
https://stackoverflow.com/q/10481685
https://stackoverflow.com/a/10483234
<p>In your <code>.bashrc</code> you can set your prompt using the <code>PS1</code> variable (which is likely set to a global value in <code>/etc/profile</code> or another file in <code>/etc</code> which may be distribution dependent).</p> <p>Here's an example:</p> <pre><code>PS1='\[\033[1;36m\]\u@\h:\[\033[0m\]\[\033...
<p>In your <code>.bashrc</code> you can set your prompt using the <code>PS1</code> variable (which is likely set to a global value in <code>/etc/profile</code> or another file in <code>/etc</code> which may be distribution dependent).</p> <p>Here's an example:</p> <pre><code>PS1='\[\033[1;36m\]\u@\h:\[\033[0m\]\[\033...
119, 387, 21628
bash, git, msysgit
<h1>Setting colors for prompt in Git Bash on Windows</h1> <p>I've successfully played around with some of the color settings in the Git Bash on Windows - I'm able to set a few things, like the colors of the local, the current and remote branches in my <code>.gitconfig</code> file:</p> <pre><code>[color "branch"] curre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,068
bash
# Setting colors for prompt in Git Bash on Windows I've successfully played around with some of the color settings in the Git Bash on Windows - I'm able to set a few things, like the colors of the local, the current and remote branches in my `.gitconfig` file: ``` [color "branch"] current = cyan bold local = cyan re...
In your `.bashrc` you can set your prompt using the `PS1` variable (which is likely set to a global value in `/etc/profile` or another file in `/etc` which may be distribution dependent). Here's an example: ``` PS1='\[\033[1;36m\]\u@\h:\[\033[0m\]\[\033[1;34m\]\w\[\033[0m\] \[\033[1;32m\]$(__git_ps1)\[\033[0m\]\$ ' `...
37035300
How to determine the default location for openssl.cnf?
23
2016-05-04 18:27:43
<h1>Background</h1> <p>I'm writing a bash script that will use openssl to generate a certificate signing request with <em>X509v3 extension compliant</em> subject alternative names.</p> <p>Since there's no command line option for this, <a href="http://blog.endpoint.com/2014/10/openssl-csr-with-alternative-names-one.ht...
69,960
4,233,593
2019-01-21 00:52:58
37,042,289
15
2016-05-05 04:20:33
608,639
2016-05-05 05:09:34
https://stackoverflow.com/q/37035300
https://stackoverflow.com/a/37042289
<blockquote> <p>How do I programmatically determine the full path to the openssl default configuration file?</p> </blockquote> <p>Programmatically, its as easy as using the <code>OPENSSLDIR</code> macro from <code>opensslconf.h</code>:</p> <pre class="lang-none prettyprint-override"><code>$ cat /usr/local/ssl/darwi...
<blockquote> <p>How do I programmatically determine the full path to the openssl default configuration file?</p> </blockquote> <p>Programmatically, its as easy as using the <code>OPENSSLDIR</code> macro from <code>opensslconf.h</code>:</p> <pre class="lang-none prettyprint-override"><code>$ cat /usr/local/ssl/darwi...
387, 1999
bash, openssl
<h1>How to determine the default location for openssl.cnf?</h1> <h1>Background</h1> <p>I'm writing a bash script that will use openssl to generate a certificate signing request with <em>X509v3 extension compliant</em> subject alternative names.</p> <p>Since there's no command line option for this, <a href="http://blo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,069
bash
# How to determine the default location for openssl.cnf? # Background I'm writing a bash script that will use openssl to generate a certificate signing request with *X509v3 extension compliant* subject alternative names. Since there's no command line option for this, [a solution](http://blog.endpoint.com/2014/10/ope...
> How do I programmatically determine the full path to the openssl default configuration file? Programmatically, its as easy as using the `OPENSSLDIR` macro from `opensslconf.h`: ``` $ cat /usr/local/ssl/darwin/include/openssl/opensslconf.h | grep OPENSSLDIR #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR) #def...
27641139
How can I identify partitions of an Android device from the shell?
23
2014-12-24 18:52:43
<p>I'm trying to find which partition is used for what, e.g. <code>/boot</code>, <code>/recovery</code>, <code>/system</code>, from <code>adb shell</code>. While this is trivial for partitions currently mounted (using the <code>mount</code> or <code>df</code> commands, see e.g. <a href="https://stackoverflow.com/q/2021...
68,351
2,533,433
2015-10-27 11:44:38
30,537,731
15
2015-05-29 19:35:29
2,533,433
2015-05-29 19:35:29
https://stackoverflow.com/q/27641139
https://stackoverflow.com/a/30537731
<p>As there seems to be no "unique way" to achieve that, I started combining ideas from allover, joining them into a script (or rather a "script library") to have them checked sequentially (until a good hit was made), and integrated that into my "Device Documentation Tool" named <strong><a href="https://github.com/Izzy...
<p>As there seems to be no "unique way" to achieve that, I started combining ideas from allover, joining them into a script (or rather a "script library") to have them checked sequentially (until a good hit was made), and integrated that into my "Device Documentation Tool" named <strong><a href="https://github.com/Izzy...
390, 1386, 94487
android, partition, shell
<h1>How can I identify partitions of an Android device from the shell?</h1> <p>I'm trying to find which partition is used for what, e.g. <code>/boot</code>, <code>/recovery</code>, <code>/system</code>, from <code>adb shell</code>. While this is trivial for partitions currently mounted (using the <code>mount</code> or ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,070
bash
# How can I identify partitions of an Android device from the shell? I'm trying to find which partition is used for what, e.g. `/boot`, `/recovery`, `/system`, from `adb shell`. While this is trivial for partitions currently mounted (using the `mount` or `df` commands, see e.g. [how to identify names of the partitions...
As there seems to be no "unique way" to achieve that, I started combining ideas from allover, joining them into a script (or rather a "script library") to have them checked sequentially (until a good hit was made), and integrated that into my "Device Documentation Tool" named **[Adebar](https://github.com/IzzySoft/Adeb...
27175137
Powershellv2 - remove last x characters from a string
23
2014-11-27 16:27:44
<p>I have a file containing a few thousand lines of text. I need to extract some data from it, but the data I need is always 57 characters from the left, and 37 characters from the end. The bit I need (in the middle) is of varying length.</p> <p>e.g. <code>20141126_this_piece_of_text_needs_to_be_removed&lt;b&gt;thi...
106,182
1,532,210
2015-09-16 13:05:07
27,175,389
15
2014-11-27 16:40:16
3,115,685
2014-11-27 16:40:16
https://stackoverflow.com/q/27175137
https://stackoverflow.com/a/27175389
<p>If I understand you correctly, you need this:</p> <pre><code>$_.substring(57,$_.length-57-37) </code></pre> <p>Though this doesn't seem to work precisely with the example you gave but it will give you the varying middle section i.e. starting at 57 chars from the start and ending 37 chars from the end</p>
<p>If I understand you correctly, you need this:</p> <pre><code>$_.substring(57,$_.length-57-37) </code></pre> <p>Though this doesn't seem to work precisely with the example you gave but it will give you the varying middle section i.e. starting at 57 chars from the start and ending 37 chars from the end</p>
526, 4371, 24067
powershell, powershell-2.0, substring
<h1>Powershellv2 - remove last x characters from a string</h1> <p>I have a file containing a few thousand lines of text. I need to extract some data from it, but the data I need is always 57 characters from the left, and 37 characters from the end. The bit I need (in the middle) is of varying length.</p> <p>e.g. <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,071
bash
# Powershellv2 - remove last x characters from a string I have a file containing a few thousand lines of text. I need to extract some data from it, but the data I need is always 57 characters from the left, and 37 characters from the end. The bit I need (in the middle) is of varying length. e.g. `20141126_this_piece_...
If I understand you correctly, you need this: ``` $_.substring(57,$_.length-57-37) ``` Though this doesn't seem to work precisely with the example you gave but it will give you the varying middle section i.e. starting at 57 chars from the start and ending 37 chars from the end
8965887
Why does `if $(true) ; then ... fi` succeed?
23
2012-01-22 23:59:46
<p>Inspired by <a href="https://stackoverflow.com/questions/8965509/why-if-ps-aux-grep-always-succeeds-in-bash">this question</a>:</p> <p>What should an if statement do when the condition is a command substitution where the command produces no output?</p> <p><strong>NOTE:</strong> The example is <code>if $(true); the...
6,757
827,263
2023-03-16 14:09:13
8,973,170
15
2012-01-23 14:30:01
140,750
2012-01-27 21:25:06
https://stackoverflow.com/q/8965887
https://stackoverflow.com/a/8973170
<p>See section 2.9.1 of the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18" rel="noreferrer"> language spec</a>. The last sentence of the first section reads:</p> <blockquote> <p>If there is a command name, execution shall continue as described in Command Search and Executi...
<p>See section 2.9.1 of the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18" rel="noreferrer"> language spec</a>. The last sentence of the first section reads:</p> <blockquote> <p>If there is a command name, execution shall continue as described in Command Search and Executi...
387, 1964, 3791, 10327
bash, ksh, sh, zsh
<h1>Why does `if $(true) ; then ... fi` succeed?</h1> <p>Inspired by <a href="https://stackoverflow.com/questions/8965509/why-if-ps-aux-grep-always-succeeds-in-bash">this question</a>:</p> <p>What should an if statement do when the condition is a command substitution where the command produces no output?</p> <p><stro...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,072
bash
# Why does `if $(true) ; then ... fi` succeed? Inspired by [this question](https://stackoverflow.com/questions/8965509/why-if-ps-aux-grep-always-succeeds-in-bash): What should an if statement do when the condition is a command substitution where the command produces no output? **NOTE:** The example is `if $(true); t...
See section 2.9.1 of the [language spec](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18). The last sentence of the first section reads: > If there is a command name, execution shall continue as described in Command Search and Execution . If there is no command name, but the command co...
8670001
How to launch PowerShell (not a script) from the command line
23
2011-12-29 15:53:02
<p>I am new to PowerShell and am struggling with what I assume should be a simple operation&mdash;I am trying to launch a PowesShell window from the command line. </p> <p>If I launch a command line instance and type either <code>powershell</code> or <code>start powershell</code>, I am getting a PowerShell instance wi...
187,654
306,894
2017-06-16 22:34:12
8,671,671
15
2011-12-29 18:18:36
9,833
2011-12-29 18:18:36
https://stackoverflow.com/q/8670001
https://stackoverflow.com/a/8671671
<p>Set the default console colors and fonts:</p> <p><a href="http://poshcode.org/2220">http://poshcode.org/2220</a><br> From Windows PowerShell Cookbook (O'Reilly)<br> by Lee Holmes (http://www.leeholmes.com/guide) </p> <pre><code>Set-StrictMode -Version Latest Push-Location Set-Location HKCU:\Console New-Item '.\%...
<p>Set the default console colors and fonts:</p> <p><a href="http://poshcode.org/2220">http://poshcode.org/2220</a><br> From Windows PowerShell Cookbook (O'Reilly)<br> by Lee Holmes (http://www.leeholmes.com/guide) </p> <pre><code>Set-StrictMode -Version Latest Push-Location Set-Location HKCU:\Console New-Item '.\%...
526, 24067
powershell, powershell-2.0
<h1>How to launch PowerShell (not a script) from the command line</h1> <p>I am new to PowerShell and am struggling with what I assume should be a simple operation&mdash;I am trying to launch a PowesShell window from the command line. </p> <p>If I launch a command line instance and type either <code>powershell</code> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,073
bash
# How to launch PowerShell (not a script) from the command line I am new to PowerShell and am struggling with what I assume should be a simple operation—I am trying to launch a PowesShell window from the command line. If I launch a command line instance and type either `powershell` or `start powershell`, I am getting...
Set the default console colors and fonts: <http://poshcode.org/2220> From Windows PowerShell Cookbook (O'Reilly) by Lee Holmes (http://www.leeholmes.com/guide) ``` Set-StrictMode -Version Latest Push-Location Set-Location HKCU:\Console New-Item '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe' Set-...
1574403
List all leaf subdirectories in linux
23
2009-10-15 19:09:09
<p>Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do:</p> <pre><code>find mydir -type d </code></pre> <p>which gives:</p> <pre><code>mydir/src mydir/src/main mydir/bin mydir/bin/classes </code></pre> <p>What I want instead is:</p> <pre><code>mydir/src/main ...
22,490
152,833
2022-09-18 09:35:01
1,574,711
15
2009-10-15 20:03:47
161,126
2012-08-22 03:44:29
https://stackoverflow.com/q/1574403
https://stackoverflow.com/a/1574711
<pre><code>find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}' </code></pre>
<pre><code>find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}' </code></pre>
387
bash
<h1>List all leaf subdirectories in linux</h1> <p>Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do:</p> <pre><code>find mydir -type d </code></pre> <p>which gives:</p> <pre><code>mydir/src mydir/src/main mydir/bin mydir/bin/classes </code></pre> <p>What I w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,074
bash
# List all leaf subdirectories in linux Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do: ``` find mydir -type d ``` which gives: ``` mydir/src mydir/src/main mydir/bin mydir/bin/classes ``` What I want instead is: ``` mydir/src/main mydir/bin/classes ```...
``` find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}' ```
56108617
How to pass arguments in command line using dotnet?
22
2019-05-13 08:40:46
<p>the command <code>dotnet myapp.dll -- [4, 3, 2]</code> throws the exception <code>System.FormatException: Input string was not in a correct format</code>. I do not know the syntax. How should I pass arguments correctly? I use powershell.</p>
39,889
9,046,018
2023-08-24 13:46:07
56,109,119
15
2019-05-13 09:10:47
6,270,170
2022-04-27 11:12:17
https://stackoverflow.com/q/56108617
https://stackoverflow.com/a/56109119
<pre><code>using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { Console.WriteLine(string.Join('-', args)); } } } </code></pre> <p>Call it via Powershell 6:</p> <pre><code>dotnet .\ConsoleApp3.dll &quot;[1,2,3]&quot; </code></pre> <p>Out...
<pre><code>using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { Console.WriteLine(string.Join('-', args)); } } } </code></pre> <p>Call it via Powershell 6:</p> <pre><code>dotnet .\ConsoleApp3.dll &quot;[1,2,3]&quot; </code></pre> <p>Out...
1, 9, 526
.net, c#, powershell
<h1>How to pass arguments in command line using dotnet?</h1> <p>the command <code>dotnet myapp.dll -- [4, 3, 2]</code> throws the exception <code>System.FormatException: Input string was not in a correct format</code>. I do not know the syntax. How should I pass arguments correctly? I use powershell.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,075
bash
# How to pass arguments in command line using dotnet? the command `dotnet myapp.dll -- [4, 3, 2]` throws the exception `System.FormatException: Input string was not in a correct format`. I do not know the syntax. How should I pass arguments correctly? I use powershell.
``` using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { Console.WriteLine(string.Join('-', args)); } } } ``` Call it via Powershell 6: ``` dotnet .\ConsoleApp3.dll "[1,2,3]" ``` Output: ``` [1,2,3] ``` In the above call, your `Mai...
53307844
[System.Web.Security.Membership]::GeneratePassword() - Type Not found
22
2018-11-14 19:54:46
<p>Why do I get Type Not Found when trying to use this class/method in PowerShell?</p> <pre><code> [System.Web.Security.Membership]::GeneratePassword() </code></pre> <p>Do I need to install a module or something to make use of it?</p>
23,501
7,228,003
2022-10-21 14:43:24
53,308,091
15
2018-11-14 20:14:32
7,228,003
2018-11-14 20:14:32
https://stackoverflow.com/q/53307844
https://stackoverflow.com/a/53308091
<p>Load the assembly first:</p> <pre><code>add-type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(10,0) </code></pre>
<p>Load the assembly first:</p> <pre><code>add-type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(10,0) </code></pre>
220, 526, 5187
class, passwords, powershell
<h1>[System.Web.Security.Membership]::GeneratePassword() - Type Not found</h1> <p>Why do I get Type Not Found when trying to use this class/method in PowerShell?</p> <pre><code> [System.Web.Security.Membership]::GeneratePassword() </code></pre> <p>Do I need to install a module or something to make use of it?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,076
bash
# [System.Web.Security.Membership]::GeneratePassword() - Type Not found Why do I get Type Not Found when trying to use this class/method in PowerShell? ``` [System.Web.Security.Membership]::GeneratePassword() ``` Do I need to install a module or something to make use of it?
Load the assembly first: ``` add-type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(10,0) ```
33911332
Powershell how to get the ParentProcessID by the ProcessID
22
2015-11-25 08:09:50
<p>I've problems to get the ParentProcessID from a Process where I have the ProcessID. I tried it like this, this is how it works with the ProcessID:</p> <pre><code>$p = Get-Process firefox $p.Id </code></pre> <p>But if I try it with the ParentProcessID, it doesn't work:</p> <pre><code>$p.ParentProcessId </code></pr...
37,442
4,306,615
2025-02-27 18:08:08
33,912,278
15
2015-11-25 09:05:08
4,306,615
2015-11-25 09:05:08
https://stackoverflow.com/q/33911332
https://stackoverflow.com/a/33912278
<p>This worked for me:</p> <pre><code>$p = Get-Process firefox $parent = (gwmi win32_process | ? processid -eq $p.Id).parentprocessid $parent </code></pre> <p>The output is the following:</p> <pre><code>1596 </code></pre> <p>And <code>1596</code> is the matching ParentProcessID I've checked it with the ProcessExpl...
<p>This worked for me:</p> <pre><code>$p = Get-Process firefox $parent = (gwmi win32_process | ? processid -eq $p.Id).parentprocessid $parent </code></pre> <p>The output is the following:</p> <pre><code>1596 </code></pre> <p>And <code>1596</code> is the matching ParentProcessID I've checked it with the ProcessExpl...
526
powershell
<h1>Powershell how to get the ParentProcessID by the ProcessID</h1> <p>I've problems to get the ParentProcessID from a Process where I have the ProcessID. I tried it like this, this is how it works with the ProcessID:</p> <pre><code>$p = Get-Process firefox $p.Id </code></pre> <p>But if I try it with the ParentProces...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,077
bash
# Powershell how to get the ParentProcessID by the ProcessID I've problems to get the ParentProcessID from a Process where I have the ProcessID. I tried it like this, this is how it works with the ProcessID: ``` $p = Get-Process firefox $p.Id ``` But if I try it with the ParentProcessID, it doesn't work: ``` $p.Par...
This worked for me: ``` $p = Get-Process firefox $parent = (gwmi win32_process | ? processid -eq $p.Id).parentprocessid $parent ``` The output is the following: ``` 1596 ``` And `1596` is the matching ParentProcessID I've checked it with the ProcessExplorer.
22491129
How to send multipart/form-data with PowerShell Invoke-RestMethod
22
2014-03-18 21:10:00
<p>I'm trying to send a file via Invoke-RestMethod in a similar context as curl with the -F switch. </p> <p>Curl Example</p> <pre><code>curl -F FileName=@"/path-to-file.name" "https://uri-to-post" </code></pre> <p>In powershell, I've tried something like this:</p> <pre><code>$uri = "https://uri-to-post" $contentTy...
49,120
1,104,690
2024-03-14 14:55:53
22,563,552
15
2014-03-21 15:57:54
1,104,690
2014-03-21 15:57:54
https://stackoverflow.com/q/22491129
https://stackoverflow.com/a/22563552
<p>The problem here was what the API required some additional parameters. Initial request required some parameters to accept raw content and specify filename/size. After setting that and getting back proper link to submit, I was able to use:</p> <pre><code>Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -...
<p>The problem here was what the API required some additional parameters. Initial request required some parameters to accept raw content and specify filename/size. After setting that and getting back proper link to submit, I was able to use:</p> <pre><code>Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -...
526, 1554
curl, powershell
<h1>How to send multipart/form-data with PowerShell Invoke-RestMethod</h1> <p>I'm trying to send a file via Invoke-RestMethod in a similar context as curl with the -F switch. </p> <p>Curl Example</p> <pre><code>curl -F FileName=@"/path-to-file.name" "https://uri-to-post" </code></pre> <p>In powershell, I've tried s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,078
bash
# How to send multipart/form-data with PowerShell Invoke-RestMethod I'm trying to send a file via Invoke-RestMethod in a similar context as curl with the -F switch. Curl Example ``` curl -F FileName=@"/path-to-file.name" "https://uri-to-post" ``` In powershell, I've tried something like this: ``` $uri = "https://u...
The problem here was what the API required some additional parameters. Initial request required some parameters to accept raw content and specify filename/size. After setting that and getting back proper link to submit, I was able to use: ``` Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "mul...
10466749
Bash: Colored Output with a Variable
22
2012-05-05 23:16:03
<p>I have the following function:</p> <pre><code>function pause #for prompted pause until ENTER { prompt="$3" echo -e -n "\E[36m$3" #color output text cyan echo -e -n '\E[0m' #ends colored output read -p "$*" #read keys from user until ENTER. clear } pause "Press enter to continue..." </code></pre...
32,435
1,186,723
2019-07-21 19:50:42
10,466,944
15
2012-05-05 23:56:14
727,142
2012-05-05 23:56:14
https://stackoverflow.com/q/10466749
https://stackoverflow.com/a/10466944
<p>I've slightly changed your code:</p> <pre><code>#!/bin/bash function pause() { prompt="$1" echo -e -n "\033[1;36m$prompt" echo -e -n '\033[0m' read clear } pause "Press enter to continue..." </code></pre> <p>What I've changed:</p> <ol> <li>You were initializing prompt to $3, when the correct...
<p>I've slightly changed your code:</p> <pre><code>#!/bin/bash function pause() { prompt="$1" echo -e -n "\033[1;36m$prompt" echo -e -n '\033[0m' read clear } pause "Press enter to continue..." </code></pre> <p>What I've changed:</p> <ol> <li>You were initializing prompt to $3, when the correct...
276, 387
bash, variables
<h1>Bash: Colored Output with a Variable</h1> <p>I have the following function:</p> <pre><code>function pause #for prompted pause until ENTER { prompt="$3" echo -e -n "\E[36m$3" #color output text cyan echo -e -n '\E[0m' #ends colored output read -p "$*" #read keys from user until ENTER. clear } p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,079
bash
# Bash: Colored Output with a Variable I have the following function: ``` function pause #for prompted pause until ENTER { prompt="$3" echo -e -n "\E[36m$3" #color output text cyan echo -e -n '\E[0m' #ends colored output read -p "$*" #read keys from user until ENTER. clear } pause "Press enter to...
I've slightly changed your code: ``` #!/bin/bash function pause() { prompt="$1" echo -e -n "\033[1;36m$prompt" echo -e -n '\033[0m' read clear } pause "Press enter to continue..." ``` What I've changed: 1. You were initializing prompt to $3, when the correct argument was $1 2. The ANSI sequence...
880467
Renaming a set of files to 001, 002,
22
2009-05-19 00:38:29
<p>I originally had a set of images of the form image_001.jpg, image_002.jpg, ...</p> <p>I went through them and removed several. Now I'd like to rename the leftover files back to image_001.jpg, image_002.jpg, ...</p> <p>Is there a Linux command that will do this neatly? I'm familiar with rename but can't see anythin...
29,449
37,947
2022-03-17 13:48:34
880,488
15
2009-05-19 00:47:32
47,773
2009-05-19 01:03:24
https://stackoverflow.com/q/880467
https://stackoverflow.com/a/880488
<p>If I understand right, you have e.g. image_001.jpg, image_003.jpg, image_005.jpg, and you want to rename to image_001.jpg, image_002.jpg, image_003.jpg.</p> <p>EDIT: This is modified to put the temp file in the current directory. As Stephan202 noted, this can make a significant difference if temp is on a different...
<p>If I understand right, you have e.g. image_001.jpg, image_003.jpg, image_005.jpg, and you want to rename to image_001.jpg, image_002.jpg, image_003.jpg.</p> <p>EDIT: This is modified to put the temp file in the current directory. As Stephan202 noted, this can make a significant difference if temp is on a different...
58, 387, 390, 4510, 5310
bash, file, linux, rename, shell
<h1>Renaming a set of files to 001, 002,</h1> <p>I originally had a set of images of the form image_001.jpg, image_002.jpg, ...</p> <p>I went through them and removed several. Now I'd like to rename the leftover files back to image_001.jpg, image_002.jpg, ...</p> <p>Is there a Linux command that will do this neatly? ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,080
bash
# Renaming a set of files to 001, 002, I originally had a set of images of the form image_001.jpg, image_002.jpg, ... I went through them and removed several. Now I'd like to rename the leftover files back to image_001.jpg, image_002.jpg, ... Is there a Linux command that will do this neatly? I'm familiar with renam...
If I understand right, you have e.g. image_001.jpg, image_003.jpg, image_005.jpg, and you want to rename to image_001.jpg, image_002.jpg, image_003.jpg. EDIT: This is modified to put the temp file in the current directory. As Stephan202 noted, this can make a significant difference if temp is on a different filesystem...
6018586
How to handle shell getopts with parameter containing blank spaces
21
2011-05-16 14:03:32
<p>I'm looking for a way to handle arguments containing blank spaces that has to be parsed by shell getopts command.</p> <pre><code>while getopts ":a:i:o:e:v:u:" arg do echo "ARG is: $arg" &gt;&gt; /tmp/submit.log case "$arg" in a) arg1="$OPTARG" ;; i) arg2="$OPTARG" ;; o) arg3="$OPTARG" ;; ... u) arg...
29,743
71,333
2023-09-30 11:50:18
6,022,923
15
2011-05-16 20:23:48
387,076
2011-05-16 20:23:48
https://stackoverflow.com/q/6018586
https://stackoverflow.com/a/6022923
<p>As <a href="https://stackoverflow.com/users/635608/mat">Mat</a> notes, your script fragment is already correct. If you're invoking your script from a shell, you need to quote arguments properly, e.g.</p> <pre><code>myscript -u "string with white space" myscript -u 'string with white space' myscript -u string\ with\...
<p>As <a href="https://stackoverflow.com/users/635608/mat">Mat</a> notes, your script fragment is already correct. If you're invoking your script from a shell, you need to quote arguments properly, e.g.</p> <pre><code>myscript -u "string with white space" myscript -u 'string with white space' myscript -u string\ with\...
390, 19020
getopts, shell
<h1>How to handle shell getopts with parameter containing blank spaces</h1> <p>I'm looking for a way to handle arguments containing blank spaces that has to be parsed by shell getopts command.</p> <pre><code>while getopts ":a:i:o:e:v:u:" arg do echo "ARG is: $arg" &gt;&gt; /tmp/submit.log case "$arg" in a) ar...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,081
bash
# How to handle shell getopts with parameter containing blank spaces I'm looking for a way to handle arguments containing blank spaces that has to be parsed by shell getopts command. ``` while getopts ":a:i:o:e:v:u:" arg do echo "ARG is: $arg" >> /tmp/submit.log case "$arg" in a) arg1="$OPTARG" ;; i) arg2="...
As [Mat](https://stackoverflow.com/users/635608/mat) notes, your script fragment is already correct. If you're invoking your script from a shell, you need to quote arguments properly, e.g. ``` myscript -u "string with white space" myscript -u 'string with white space' myscript -u string\ with\ white\ space myscript -u...
26167803
How does /bin/bash -c differ from executing a command directly?
20
2014-10-02 19:06:14
<p>I'm curious why the commmand:</p> <pre><code>for f in `/bin/ls /mydir | sort | tail -n 10`; do echo $f; done; </code></pre> <p>Outputs the last ten files in /mydir, but</p> <pre><code>/bin/bash -c "for f in `/bin/ls /mydir | sort | tail -n 10`; do echo $f; done;" </code></pre> <p>Outputs "syntax error near unexp...
28,568
384,164
2014-10-02 19:13:59
26,167,919
15
2014-10-02 19:13:59
1,204,143
2014-10-02 19:13:59
https://stackoverflow.com/q/26167803
https://stackoverflow.com/a/26167919
<p>You are using double-quotes, so the parent shell is interpolating backticks and variables before passing the argument to <code>/bin/bash</code>.</p> <p>Thus, your <code>/bin/bash</code> is receiving the following arguments:</p> <pre><code>-c "for f in x y z ... ; do echo ; done;" </code></pre> <p>which is a synta...
<p>You are using double-quotes, so the parent shell is interpolating backticks and variables before passing the argument to <code>/bin/bash</code>.</p> <p>Thus, your <code>/bin/bash</code> is receiving the following arguments:</p> <pre><code>-c "for f in x y z ... ; do echo ; done;" </code></pre> <p>which is a synta...
387
bash
<h1>How does /bin/bash -c differ from executing a command directly?</h1> <p>I'm curious why the commmand:</p> <pre><code>for f in `/bin/ls /mydir | sort | tail -n 10`; do echo $f; done; </code></pre> <p>Outputs the last ten files in /mydir, but</p> <pre><code>/bin/bash -c "for f in `/bin/ls /mydir | sort | tail -n 1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,082
bash
# How does /bin/bash -c differ from executing a command directly? I'm curious why the commmand: ``` for f in `/bin/ls /mydir | sort | tail -n 10`; do echo $f; done; ``` Outputs the last ten files in /mydir, but ``` /bin/bash -c "for f in `/bin/ls /mydir | sort | tail -n 10`; do echo $f; done;" ``` Outputs "syntax ...
You are using double-quotes, so the parent shell is interpolating backticks and variables before passing the argument to `/bin/bash`. Thus, your `/bin/bash` is receiving the following arguments: ``` -c "for f in x y z ... ; do echo ; done;" ``` which is a syntax error. To avoid this, use single quotes to pass your ...
25467090
How to run SWI-Prolog from the command line?
20
2014-08-23 22:53:21
<p>Is there a way to just create a prolog script called <code>hello.pl</code> like this:</p> <pre><code>#!/usr/local/bin/swipl -q -s -t main main:- write('Hello World\n'). </code></pre> <p>And be able to run it from the terminal like this?</p> <pre><code>$ hello.pl Hello World $ </code></pre> <p>When I do that i...
25,834
169,992
2019-07-06 02:19:18
25,467,219
15
2014-08-23 23:16:46
874,024
2014-08-24 07:27:57
https://stackoverflow.com/q/25467090
https://stackoverflow.com/a/25467219
<p>ISO directive: <a href="http://www.swi-prolog.org/pldoc/doc_for?object=%28initialization%29/1">initialization</a>. This should work.</p> <pre><code>:- initialization main. main :- write('Hello World\n'). </code></pre> <p><em>edit</em> sorry, I skipped over most interesting details. Here is a sample script, let'...
<p>ISO directive: <a href="http://www.swi-prolog.org/pldoc/doc_for?object=%28initialization%29/1">initialization</a>. This should work.</p> <pre><code>:- initialization main. main :- write('Hello World\n'). </code></pre> <p><em>edit</em> sorry, I skipped over most interesting details. Here is a sample script, let'...
390, 1135, 1231, 8746, 31102
command-line, executable, prolog, shell, swi-prolog
<h1>How to run SWI-Prolog from the command line?</h1> <p>Is there a way to just create a prolog script called <code>hello.pl</code> like this:</p> <pre><code>#!/usr/local/bin/swipl -q -s -t main main:- write('Hello World\n'). </code></pre> <p>And be able to run it from the terminal like this?</p> <pre><code>$ hel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,083
bash
# How to run SWI-Prolog from the command line? Is there a way to just create a prolog script called `hello.pl` like this: ``` #!/usr/local/bin/swipl -q -s -t main main:- write('Hello World\n'). ``` And be able to run it from the terminal like this? ``` $ hello.pl Hello World $ ``` When I do that it gives me thi...
ISO directive: [initialization](http://www.swi-prolog.org/pldoc/doc_for?object=%28initialization%29/1). This should work. ``` :- initialization main. main :- write('Hello World\n'). ``` *edit* sorry, I skipped over most interesting details. Here is a sample script, let's say saved in ~/test/main.pl ``` #!/home/ca...
15201763
IntelliJ does not recognize PATH variable
20
2013-03-04 12:36:46
<p>I recently tried to import an existing Gradle project, using the option "Open Project" in the startup window and the existing build.gradle file to automatically set-up the project. </p> <p>Right after I did this, an error message appeared in IntelliJ, saying: </p> <blockquote> <p>Could not fetch model of type 'B...
23,031
2,104,921
2023-11-30 05:20:14
15,201,881
15
2013-03-04 12:43:20
575,421
2023-11-30 05:20:14
https://stackoverflow.com/q/15201763
https://stackoverflow.com/a/15201881
<p>Check this post: <a href="https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/" rel="nofollow noreferrer">https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/</a> The problem is that IDEA doesn't read your <code>.zshrc</code> file and doesn't know about path to pla...
<p>Check this post: <a href="https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/" rel="nofollow noreferrer">https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/</a> The problem is that IDEA doesn't read your <code>.zshrc</code> file and doesn't know about path to pla...
17, 390, 6268, 8945, 9013
environment-variables, intellij-idea, java, path, shell
<h1>IntelliJ does not recognize PATH variable</h1> <p>I recently tried to import an existing Gradle project, using the option "Open Project" in the startup window and the existing build.gradle file to automatically set-up the project. </p> <p>Right after I did this, an error message appeared in IntelliJ, saying: </p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,084
bash
# IntelliJ does not recognize PATH variable I recently tried to import an existing Gradle project, using the option "Open Project" in the startup window and the existing build.gradle file to automatically set-up the project. Right after I did this, an error message appeared in IntelliJ, saying: > Could not fetch mod...
Check this post: <https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/> The problem is that IDEA doesn't read your `.zshrc` file and doesn't know about path to play. Try to set PATH variable manually in IDEA settings.
11935480
How do I maintain the version number of my bash script which is git source controlled?
20
2012-08-13 13:40:02
<p>I've just finished the first working version of a more complex bash script, and I'm wrapping my head around on how to maintain the scripts version.</p> <p>Why do I need this? Following <a href="http://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html" rel="noreferrer">GNU Coding Standards For Co...
9,028
1,178,669
2018-09-05 13:26:27
11,936,605
15
2012-08-13 14:41:49
233,485
2012-08-13 14:41:49
https://stackoverflow.com/q/11935480
https://stackoverflow.com/a/11936605
<p>As far as I can tell, what you want is impossible. In order to have the version number be committed into the version control software, you'd have to edit the version number, commit, then tag; not the other way around. You can however have the process a little more streamlined.</p> <p>We can do this by writing a pos...
<p>As far as I can tell, what you want is impossible. In order to have the version number be committed into the version control software, you'd have to edit the version number, commit, then tag; not the other way around. You can however have the process a little more streamlined.</p> <p>We can do this by writing a pos...
119, 387, 5792
bash, git, version
<h1>How do I maintain the version number of my bash script which is git source controlled?</h1> <p>I've just finished the first working version of a more complex bash script, and I'm wrapping my head around on how to maintain the scripts version.</p> <p>Why do I need this? Following <a href="http://www.gnu.org/prep/st...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,085
bash
# How do I maintain the version number of my bash script which is git source controlled? I've just finished the first working version of a more complex bash script, and I'm wrapping my head around on how to maintain the scripts version. Why do I need this? Following [GNU Coding Standards For Commandline Interfaces](h...
As far as I can tell, what you want is impossible. In order to have the version number be committed into the version control software, you'd have to edit the version number, commit, then tag; not the other way around. You can however have the process a little more streamlined. We can do this by writing a post-commit h...
9673730
Interacting with bash from python
20
2012-03-12 19:43:25
<p>I've been playing around with Python's <code>subprocess</code> module and I wanted to do an "interactive session" with bash from python. I want to be able to read bash output/write commands from Python just like I do on a terminal emulator. I guess a code example explains it better:</p> <pre><code>&gt;&gt;&gt; proc...
45,408
1,264,974
2024-09-03 08:10:52
9,674,162
15
2012-03-12 20:17:21
170,614
2024-09-03 08:10:52
https://stackoverflow.com/q/9673730
https://stackoverflow.com/a/9674162
<p>Try with this example:</p> <pre class="lang-py prettyprint-override"><code>import subprocess proc = subprocess.Popen(['/bin/bash'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout = proc.communicate('ls -lash') print(stdout) </code></pre> <p>You have to read more about stdin, stdout and stderr. This looks lik...
<p>Try with this example:</p> <pre class="lang-py prettyprint-override"><code>import subprocess proc = subprocess.Popen(['/bin/bash'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout = proc.communicate('ls -lash') print(stdout) </code></pre> <p>You have to read more about stdin, stdout and stderr. This looks lik...
16, 387, 2348
bash, python, subprocess
<h1>Interacting with bash from python</h1> <p>I've been playing around with Python's <code>subprocess</code> module and I wanted to do an "interactive session" with bash from python. I want to be able to read bash output/write commands from Python just like I do on a terminal emulator. I guess a code example explains i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,086
bash
# Interacting with bash from python I've been playing around with Python's `subprocess` module and I wanted to do an "interactive session" with bash from python. I want to be able to read bash output/write commands from Python just like I do on a terminal emulator. I guess a code example explains it better: ``` >>> p...
Try with this example: ``` import subprocess proc = subprocess.Popen(['/bin/bash'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout = proc.communicate('ls -lash') print(stdout) ``` You have to read more about stdin, stdout and stderr. This looks like good lecture: <http://www.doughellmann.com/PyMOTW/subprocess...
6713391
Can bash completion be invoked programmatically?
20
2011-07-15 21:34:46
<p>What I want is a function I can call from a program so it completes the way bash would given a commandline and a location where TAB was pressed.</p> <pre><code>. /etc/bash_completion generate_completions "command arg1 arg2" 17 </code></pre> <p>would return the same thing as </p> <pre><code>command arg1 arg2[TAB] ...
2,136
245,173
2014-09-05 21:00:24
6,741,838
15
2011-07-19 02:56:42
590,042
2011-07-19 02:56:42
https://stackoverflow.com/q/6713391
https://stackoverflow.com/a/6741838
<p>I actually had to do this to figure out how apt-get autocomplete works on ubuntu (built my own pseudo-repository tool :)</p> <p>This is a multistep process:</p> <p>First, <code>complete -p</code> will give you a listing of all completions in the form of a set of commands you can run to replicate the configuration....
<p>I actually had to do this to figure out how apt-get autocomplete works on ubuntu (built my own pseudo-repository tool :)</p> <p>This is a multistep process:</p> <p>First, <code>complete -p</code> will give you a listing of all completions in the form of a set of commands you can run to replicate the configuration....
387, 59778
bash, bash-completion
<h1>Can bash completion be invoked programmatically?</h1> <p>What I want is a function I can call from a program so it completes the way bash would given a commandline and a location where TAB was pressed.</p> <pre><code>. /etc/bash_completion generate_completions "command arg1 arg2" 17 </code></pre> <p>would return ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,087
bash
# Can bash completion be invoked programmatically? What I want is a function I can call from a program so it completes the way bash would given a commandline and a location where TAB was pressed. ``` . /etc/bash_completion generate_completions "command arg1 arg2" 17 ``` would return the same thing as ``` command ar...
I actually had to do this to figure out how apt-get autocomplete works on ubuntu (built my own pseudo-repository tool :) This is a multistep process: First, `complete -p` will give you a listing of all completions in the form of a set of commands you can run to replicate the configuration. For example, lets say you w...
3524978
Logging functions in bash and stdout
20
2010-08-19 18:26:09
<p>I'd like to be able to put log messages in the middle of bash functions, without affecting the output of those very functions. For example, consider the following functions <code>log()</code> and <code>get_animals()</code>:</p> <pre><code># print a log a message log () { echo "Log message: $1" } get_animals()...
37,416
393,583
2023-04-24 07:45:24
3,525,054
15
2010-08-19 18:36:08
350,890
2010-08-19 22:54:24
https://stackoverflow.com/q/3524978
https://stackoverflow.com/a/3525054
<p>You can redirect the output to the sdterr error file on file handle 2 using >&amp;2 </p> <p>example :</p> <pre><code># print a log a message log () { echo "Log message: $1" &gt;&amp;2 } get_animals() { log "Fetching animals" echo "cat dog mouse" } values=`get_animals` echo $values </code></pre> <p>the `` only t...
<p>You can redirect the output to the sdterr error file on file handle 2 using >&amp;2 </p> <p>example :</p> <pre><code># print a log a message log () { echo "Log message: $1" &gt;&amp;2 } get_animals() { log "Fetching animals" echo "cat dog mouse" } values=`get_animals` echo $values </code></pre> <p>the `` only t...
387, 942, 4867
bash, logging, stdout
<h1>Logging functions in bash and stdout</h1> <p>I'd like to be able to put log messages in the middle of bash functions, without affecting the output of those very functions. For example, consider the following functions <code>log()</code> and <code>get_animals()</code>:</p> <pre><code># print a log a message log ()...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,088
bash
# Logging functions in bash and stdout I'd like to be able to put log messages in the middle of bash functions, without affecting the output of those very functions. For example, consider the following functions `log()` and `get_animals()`: ``` # print a log a message log () { echo "Log message: $1" } get_animal...
You can redirect the output to the sdterr error file on file handle 2 using >&2 example : ``` # print a log a message log () { echo "Log message: $1" >&2 } get_animals() { log "Fetching animals" echo "cat dog mouse" } values=`get_animals` echo $values ``` the `` only take the output on stdout, not on stderr. The c...
43213624
How can I automatically syntax check a powershell script file?
19
2017-04-04 17:13:18
<p>I want to write a unit-test for some code which generates a powershell script and then check that the script has valid syntax.</p> <p>What's a good way to do this without actually executing the script?</p> <p>A .NET code solution is ideal, but a command line solution that I could use by launching an external proce...
30,073
234,288
2021-12-10 14:58:56
43,214,144
15
2017-04-04 17:44:49
712,649
2019-04-29 15:27:05
https://stackoverflow.com/q/43213624
https://stackoverflow.com/a/43214144
<p>You could run your code through the <a href="https://msdn.microsoft.com/en-us/library/system.management.automation.language.parser(v=vs.85).aspx" rel="noreferrer"><code>Parser</code></a> and observe if it raises any errors:</p> <pre><code># Empty collection for errors $Errors = @() # Define input script $inputScri...
<p>You could run your code through the <a href="https://msdn.microsoft.com/en-us/library/system.management.automation.language.parser(v=vs.85).aspx" rel="noreferrer"><code>Parser</code></a> and observe if it raises any errors:</p> <pre><code># Empty collection for errors $Errors = @() # Define input script $inputScri...
355, 526
powershell, validation
<h1>How can I automatically syntax check a powershell script file?</h1> <p>I want to write a unit-test for some code which generates a powershell script and then check that the script has valid syntax.</p> <p>What's a good way to do this without actually executing the script?</p> <p>A .NET code solution is ideal, but...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,089
bash
# How can I automatically syntax check a powershell script file? I want to write a unit-test for some code which generates a powershell script and then check that the script has valid syntax. What's a good way to do this without actually executing the script? A .NET code solution is ideal, but a command line solutio...
You could run your code through the [`Parser`](https://msdn.microsoft.com/en-us/library/system.management.automation.language.parser(v=vs.85).aspx) and observe if it raises any errors: ``` # Empty collection for errors $Errors = @() # Define input script $inputScript = 'Do-Something -Param 1,2,3,' [void][System.Mana...
20330385
Cannot find the file specified when using subprocess.call('dir', shell=True) in Python
19
2013-12-02 14:14:57
<p>In a 64-bit system with 32 bit python 2.7 installed I am trying to do the following:</p> <pre><code>import subprocess p = subprocess.call('dir', shell=True) print p </code></pre> <p>But this gives me:</p> <pre><code>Traceback (most recent call last): File "test.py", line 2, in &lt;module&gt; p = subprocess....
42,045
2,996,272
2019-07-21 11:15:16
20,335,954
15
2013-12-02 19:10:29
722,332
2013-12-02 19:10:29
https://stackoverflow.com/q/20330385
https://stackoverflow.com/a/20335954
<p>I think you may have a problem with your <code>COMSPEC</code> environment variable:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.environ['COMSPEC'] 'C:\\Windows\\system32\\cmd.exe' &gt;&gt;&gt; import subprocess &gt;&gt;&gt; subprocess.call('dir', shell=True) (normal output here) &gt;&gt;&gt; os.envi...
<p>I think you may have a problem with your <code>COMSPEC</code> environment variable:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.environ['COMSPEC'] 'C:\\Windows\\system32\\cmd.exe' &gt;&gt;&gt; import subprocess &gt;&gt;&gt; subprocess.call('dir', shell=True) (normal output here) &gt;&gt;&gt; os.envi...
16, 390, 2348, 6268, 59047
path, python, python-2.7, shell, subprocess
<h1>Cannot find the file specified when using subprocess.call('dir', shell=True) in Python</h1> <p>In a 64-bit system with 32 bit python 2.7 installed I am trying to do the following:</p> <pre><code>import subprocess p = subprocess.call('dir', shell=True) print p </code></pre> <p>But this gives me:</p> <pre><code>Tr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,090
bash
# Cannot find the file specified when using subprocess.call('dir', shell=True) in Python In a 64-bit system with 32 bit python 2.7 installed I am trying to do the following: ``` import subprocess p = subprocess.call('dir', shell=True) print p ``` But this gives me: ``` Traceback (most recent call last): File "tes...
I think you may have a problem with your `COMSPEC` environment variable: ``` >>> import os >>> os.environ['COMSPEC'] 'C:\\Windows\\system32\\cmd.exe' >>> import subprocess >>> subprocess.call('dir', shell=True) (normal output here) >>> os.environ['COMSPEC'] = 'C:\\nonexistent.exe' >>> subprocess.call('dir', shel...
19943482
Configure shell to always print prompt on new line, like zsh
19
2013-11-13 01:23:34
<p>If a command's output does not end with a <code>\n</code>, the next prompt appears, awkwardly, immediately afterwards:</p> <pre><code>$ echo -n hai hai$ </code></pre> <p>I just noticed a colleague whose shell (zsh, for what it's worth) is configured to print a <code>%</code> (with background and foreground colours...
6,673
312,785
2013-11-24 09:03:29
20,156,527
15
2013-11-22 23:42:22
1,815,797
2013-11-24 09:03:29
https://stackoverflow.com/q/19943482
https://stackoverflow.com/a/20156527
<p>A little trick using <a href="http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt" rel="noreferrer"><code>PROMPT_COMMAND</code></a>:</p> <blockquote> <p>The value of the variable <code>PROMPT_COMMAND</code> is examined just before Bash prints each primary prompt. If <code>PROMPT_COMMAND</code> ...
<p>A little trick using <a href="http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt" rel="noreferrer"><code>PROMPT_COMMAND</code></a>:</p> <blockquote> <p>The value of the variable <code>PROMPT_COMMAND</code> is examined just before Bash prints each primary prompt. If <code>PROMPT_COMMAND</code> ...
387, 390, 5003
bash, prompt, shell
<h1>Configure shell to always print prompt on new line, like zsh</h1> <p>If a command's output does not end with a <code>\n</code>, the next prompt appears, awkwardly, immediately afterwards:</p> <pre><code>$ echo -n hai hai$ </code></pre> <p>I just noticed a colleague whose shell (zsh, for what it's worth) is config...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,091
bash
# Configure shell to always print prompt on new line, like zsh If a command's output does not end with a `\n`, the next prompt appears, awkwardly, immediately afterwards: ``` $ echo -n hai hai$ ``` I just noticed a colleague whose shell (zsh, for what it's worth) is configured to print a `%` (with background and for...
A little trick using [`PROMPT_COMMAND`](http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt): > The value of the variable `PROMPT_COMMAND` is examined just before Bash prints each primary prompt. If `PROMPT_COMMAND` is set and has a non-null value, then the value is executed just as if it had been t...
19530429
Rename file by removing last n characters
19
2013-10-23 00:01:33
<p>I want to rename files by removing the last N characters</p> <p>For example I want to rename these files by removing the last 7 characters</p> <p>From:</p> <pre><code>file.txt.123456 </code></pre> <p>To:</p> <pre><code>file.txt </code></pre> <p>Is this doable in a single command?</p>
47,866
2,771,455
2022-06-07 09:17:59
19,531,512
15
2013-10-23 02:05:03
1,126,841
2013-10-23 20:16:25
https://stackoverflow.com/q/19530429
https://stackoverflow.com/a/19531512
<p>You can remove a fixed number of characters using</p> <pre><code>mv "$file" "${file%???????}" # 7 question marks to match 7 characters </code></pre> <p>This will work in any POSIX-compliant shell.</p> <p>To remove the last extension (which may be more or less than 7 characters), use</p> <pre><code>mv "$file" "$...
<p>You can remove a fixed number of characters using</p> <pre><code>mv "$file" "${file%???????}" # 7 question marks to match 7 characters </code></pre> <p>This will work in any POSIX-compliant shell.</p> <p>To remove the last extension (which may be more or less than 7 characters), use</p> <pre><code>mv "$file" "$...
34, 390
shell, unix
<h1>Rename file by removing last n characters</h1> <p>I want to rename files by removing the last N characters</p> <p>For example I want to rename these files by removing the last 7 characters</p> <p>From:</p> <pre><code>file.txt.123456 </code></pre> <p>To:</p> <pre><code>file.txt </code></pre> <p>Is this doable ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,092
bash
# Rename file by removing last n characters I want to rename files by removing the last N characters For example I want to rename these files by removing the last 7 characters From: ``` file.txt.123456 ``` To: ``` file.txt ``` Is this doable in a single command?
You can remove a fixed number of characters using ``` mv "$file" "${file%???????}" # 7 question marks to match 7 characters ``` This will work in any POSIX-compliant shell. To remove the last extension (which may be more or less than 7 characters), use ``` mv "$file" "${file%.*}" ``` To trim everything after a gi...
12474172
How to find network interface name
19
2012-09-18 09:31:04
<p>I have a bash script that runs on a variety of different Ubuntu Linux machines. Its job is to find out the LAN IPv4 address of the localhost.</p> <p>The script is using </p> <pre><code>ip addr show eth0 | sed -n '/inet /{s/^.*inet \([0-9.]\+\).*$/\1/;p}' </code></pre> <p>which is fine, but some machines for some ...
68,437
623,519
2024-03-24 09:55:37
16,469,143
15
2013-05-09 18:59:32
81,636
2013-05-09 18:59:32
https://stackoverflow.com/q/12474172
https://stackoverflow.com/a/16469143
<p>Not sure if this helps, but it seems that <code>ip route get</code> will show which interface it uses to connect to a remote host.</p> <pre><code>ubuntu@ip-10-40-24-21:/nail/srv/elasticsearch$ ip route get 8.8.8.8 8.8.8.8 via &lt;gateway address&gt; dev eth0 src &lt;eth0 IP Address&gt; </code></pre> <p>of course ...
<p>Not sure if this helps, but it seems that <code>ip route get</code> will show which interface it uses to connect to a remote host.</p> <pre><code>ubuntu@ip-10-40-24-21:/nail/srv/elasticsearch$ ip route get 8.8.8.8 8.8.8.8 via &lt;gateway address&gt; dev eth0 src &lt;eth0 IP Address&gt; </code></pre> <p>of course ...
58, 294, 387, 5282
bash, ip, linux, sed
<h1>How to find network interface name</h1> <p>I have a bash script that runs on a variety of different Ubuntu Linux machines. Its job is to find out the LAN IPv4 address of the localhost.</p> <p>The script is using </p> <pre><code>ip addr show eth0 | sed -n '/inet /{s/^.*inet \([0-9.]\+\).*$/\1/;p}' </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,093
bash
# How to find network interface name I have a bash script that runs on a variety of different Ubuntu Linux machines. Its job is to find out the LAN IPv4 address of the localhost. The script is using ``` ip addr show eth0 | sed -n '/inet /{s/^.*inet \([0-9.]\+\).*$/\1/;p}' ``` which is fine, but some machines for so...
Not sure if this helps, but it seems that `ip route get` will show which interface it uses to connect to a remote host. ``` ubuntu@ip-10-40-24-21:/nail/srv/elasticsearch$ ip route get 8.8.8.8 8.8.8.8 via <gateway address> dev eth0 src <eth0 IP Address> ``` of course you could automate that in shell script with somet...
15807496
Adding and removing extensionattribute to AD object
19
2013-04-04 09:32:13
<p>I'm using powershell to modify some AD extensionattribute.</p> <p>This is my code to add an extensionattribute</p> <pre><code>Set-ADUser -Identity "anyUser" -Add @{extensionAttribute4="myString"} </code></pre> <p>It works, but how can I remove the same extensionattribute? I can't find anything similar to <code>-r...
292,970
1,303,090
2016-06-19 10:42:12
15,808,034
15
2013-04-04 09:57:22
2,215,029
2013-04-04 09:57:22
https://stackoverflow.com/q/15807496
https://stackoverflow.com/a/15808034
<p>You could try using the <code>-Clear</code> parameter </p> <p>Example:<code>-Clear Attribute1LDAPDisplayName, Attribute2LDAPDisplayName</code></p> <p><a href="http://technet.microsoft.com/en-us/library/ee617215.aspx">http://technet.microsoft.com/en-us/library/ee617215.aspx</a></p>
<p>You could try using the <code>-Clear</code> parameter </p> <p>Example:<code>-Clear Attribute1LDAPDisplayName, Attribute2LDAPDisplayName</code></p> <p><a href="http://technet.microsoft.com/en-us/library/ee617215.aspx">http://technet.microsoft.com/en-us/library/ee617215.aspx</a></p>
526, 10401
active-directory, powershell
<h1>Adding and removing extensionattribute to AD object</h1> <p>I'm using powershell to modify some AD extensionattribute.</p> <p>This is my code to add an extensionattribute</p> <pre><code>Set-ADUser -Identity "anyUser" -Add @{extensionAttribute4="myString"} </code></pre> <p>It works, but how can I remove the same ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,094
bash
# Adding and removing extensionattribute to AD object I'm using powershell to modify some AD extensionattribute. This is my code to add an extensionattribute ``` Set-ADUser -Identity "anyUser" -Add @{extensionAttribute4="myString"} ``` It works, but how can I remove the same extensionattribute? I can't find anythin...
You could try using the `-Clear` parameter Example:`-Clear Attribute1LDAPDisplayName, Attribute2LDAPDisplayName` <http://technet.microsoft.com/en-us/library/ee617215.aspx>
11542243
Finding number of child processes
19
2012-07-18 13:12:47
<p>How do find the number of child processes of a bash script, from within the script itself?</p>
20,204
51,197
2019-09-20 18:59:14
11,542,363
15
2012-07-18 13:18:29
1,135,819
2012-07-18 14:23:46
https://stackoverflow.com/q/11542243
https://stackoverflow.com/a/11542363
<p>To obtain the PID of the bash script you can use variable <code>$$</code>.</p> <p>Then, to obtain its children, you can run:</p> <pre><code>bash_pid=$$ children=`ps -eo ppid | grep -w $bash_pid` </code></pre> <p><code>ps</code> will return the list of parent PIDs. Then <code>grep</code> filters all the processes ...
<p>To obtain the PID of the bash script you can use variable <code>$$</code>.</p> <p>Then, to obtain its children, you can run:</p> <pre><code>bash_pid=$$ children=`ps -eo ppid | grep -w $bash_pid` </code></pre> <p><code>ps</code> will return the list of parent PIDs. Then <code>grep</code> filters all the processes ...
387, 3300, 5910
bash, pid, process
<h1>Finding number of child processes</h1> <p>How do find the number of child processes of a bash script, from within the script itself?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,095
bash
# Finding number of child processes How do find the number of child processes of a bash script, from within the script itself?
To obtain the PID of the bash script you can use variable `$$`. Then, to obtain its children, you can run: ``` bash_pid=$$ children=`ps -eo ppid | grep -w $bash_pid` ``` `ps` will return the list of parent PIDs. Then `grep` filters all the processes not related to the bash script's children. In order to get the numb...
9050331
What does it mean in linux scripts? #!/usr/bin/python -tt
19
2012-01-29 02:08:23
<p>I know that in the begining of .sh bash scripts is</p> <pre><code>#!/bin/bash </code></pre> <p>which points to the command interpeter executable.</p> <p>But during watching Google Python Class <a href="http://www.youtube.com/watch?v=tKTZoB2Vjuk" rel="noreferrer">http://www.youtube.com/watch?v=tKTZoB2Vjuk</a> I no...
17,668
965,187
2012-01-29 02:33:14
9,050,352
15
2012-01-29 02:13:49
118,068
2012-01-29 02:19:51
https://stackoverflow.com/q/9050331
https://stackoverflow.com/a/9050352
<p>Question #1) The line is called a shebang, and there's no right form that works universally. e.g.</p> <pre><code>#!python #!/usr/bin/python #!/usr/local/bin/python #!/usr/bin/python -t </code></pre> <p>are all valid/acceptable forms, but may not work on all systems:</p> <p><code>#!python</code> will work only if ...
<p>Question #1) The line is called a shebang, and there's no right form that works universally. e.g.</p> <pre><code>#!python #!/usr/bin/python #!/usr/local/bin/python #!/usr/bin/python -t </code></pre> <p>are all valid/acceptable forms, but may not work on all systems:</p> <p><code>#!python</code> will work only if ...
16, 58, 387, 1687
bash, interpreter, linux, python
<h1>What does it mean in linux scripts? #!/usr/bin/python -tt</h1> <p>I know that in the begining of .sh bash scripts is</p> <pre><code>#!/bin/bash </code></pre> <p>which points to the command interpeter executable.</p> <p>But during watching Google Python Class <a href="http://www.youtube.com/watch?v=tKTZoB2Vjuk" r...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,096
bash
# What does it mean in linux scripts? #!/usr/bin/python -tt I know that in the begining of .sh bash scripts is ``` #!/bin/bash ``` which points to the command interpeter executable. But during watching Google Python Class <http://www.youtube.com/watch?v=tKTZoB2Vjuk> I noticed that for python they use ``` #!/usr/bi...
Question #1) The line is called a shebang, and there's no right form that works universally. e.g. ``` #!python #!/usr/bin/python #!/usr/local/bin/python #!/usr/bin/python -t ``` are all valid/acceptable forms, but may not work on all systems: `#!python` will work only if the python executable is somewhere in your sh...
6115225
Escaping Shell Commands In java?
19
2011-05-24 18:40:57
<p>I have a webservice that will take some input from authenticated machines as XML (this is for a network management system that I am integrating with some other software) and execute a shell script with some of the XML data as arguments.</p> <p>In Java(/Linux), what is the best way to escape shell commands to ensure...
9,279
416,665
2017-10-12 14:36:58
6,116,076
15
2011-05-24 19:54:36
null
2011-05-24 20:04:05
https://stackoverflow.com/q/6115225
https://stackoverflow.com/a/6116076
<p>I would suggest <strong>using ProcessBuilder or one of the Runtime.exec methods <em>which does not</em> run through the shell</strong> and thus <em>does not require shell escaping</em> to avoid injection attacks (here).</p> <ul> <li><p><a href="http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.h...
<p>I would suggest <strong>using ProcessBuilder or one of the Runtime.exec methods <em>which does not</em> run through the shell</strong> and thus <em>does not require shell escaping</em> to avoid injection attacks (here).</p> <ul> <li><p><a href="http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.h...
17, 390, 4804
escaping, java, shell
<h1>Escaping Shell Commands In java?</h1> <p>I have a webservice that will take some input from authenticated machines as XML (this is for a network management system that I am integrating with some other software) and execute a shell script with some of the XML data as arguments.</p> <p>In Java(/Linux), what is the b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,097
bash
# Escaping Shell Commands In java? I have a webservice that will take some input from authenticated machines as XML (this is for a network management system that I am integrating with some other software) and execute a shell script with some of the XML data as arguments. In Java(/Linux), what is the best way to escap...
I would suggest **using ProcessBuilder or one of the Runtime.exec methods *which does not* run through the shell** and thus *does not require shell escaping* to avoid injection attacks (here). - [ProcessBuilder](http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html) -- more flexible than `Runtime....
4581203
Shell command to find files in a directory pattern
19
2011-01-02 23:58:36
<p>With a shell command i need to list all files on my server in the following directory pattern:</p> <blockquote> <p>/home/*/public_html/images/*.php</p> </blockquote> <p>Theres a few an its taking a long time to do this manually. I really have no idea when it comes to these commands.</p>
52,940
560,702
2014-02-05 04:00:53
4,581,234
15
2011-01-03 00:10:05
552,792
2011-01-03 00:10:05
https://stackoverflow.com/q/4581203
https://stackoverflow.com/a/4581234
<p>Shell Script:</p> <pre><code>find /home/*/public_html/images -iname "*php" -exec echo {} \; </code></pre> <p>You can then change the -exec command to do whatever actions you want to the returned files. In this case, we echo them, but you could easily perform other actions as well.</p>
<p>Shell Script:</p> <pre><code>find /home/*/public_html/images -iname "*php" -exec echo {} \; </code></pre> <p>You can then change the -exec command to do whatever actions you want to the returned files. In this case, we echo them, but you could easily perform other actions as well.</p>
58, 387, 390, 488
bash, console, linux, shell
<h1>Shell command to find files in a directory pattern</h1> <p>With a shell command i need to list all files on my server in the following directory pattern:</p> <blockquote> <p>/home/*/public_html/images/*.php</p> </blockquote> <p>Theres a few an its taking a long time to do this manually. I really have no idea wh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,098
bash
# Shell command to find files in a directory pattern With a shell command i need to list all files on my server in the following directory pattern: > /home/*/public_html/images/*.php Theres a few an its taking a long time to do this manually. I really have no idea when it comes to these commands.
Shell Script: ``` find /home/*/public_html/images -iname "*php" -exec echo {} \; ``` You can then change the -exec command to do whatever actions you want to the returned files. In this case, we echo them, but you could easily perform other actions as well.
2224321
Problems installing Java EE SDK on Linux
19
2010-02-08 19:38:23
<p>I installed the Java 6 JRE on my VPS just fine, but I can't get the EE SDK installation to even run.</p> <pre><code>root@vps [/usr/java]# java -version java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode) </code></pre> <p>However, when...
41,948
243,613
2014-07-28 10:35:37
2,224,461
15
2010-02-08 19:58:31
4,249
2010-02-08 19:58:31
https://stackoverflow.com/q/2224321
https://stackoverflow.com/a/2224461
<p>Do you have a JDK installed? You likely want to put <code>$JDK_HOME/bin</code> on your PATH, not the <code>/bin</code> of a JRE, as <code>jar</code> comes with JDK, not JRE.</p>
<p>Do you have a JDK installed? You likely want to put <code>$JDK_HOME/bin</code> on your PATH, not the <code>/bin</code> of a JRE, as <code>jar</code> comes with JDK, not JRE.</p>
17, 58, 529, 10327
installation, java, linux, sh
<h1>Problems installing Java EE SDK on Linux</h1> <p>I installed the Java 6 JRE on my VPS just fine, but I can't get the EE SDK installation to even run.</p> <pre><code>root@vps [/usr/java]# java -version java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) Client VM (build 16....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,099
bash
# Problems installing Java EE SDK on Linux I installed the Java 6 JRE on my VPS just fine, but I can't get the EE SDK installation to even run. ``` root@vps [/usr/java]# java -version java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode) `...
Do you have a JDK installed? You likely want to put `$JDK_HOME/bin` on your PATH, not the `/bin` of a JRE, as `jar` comes with JDK, not JRE.
1803701
cygwin file path tab completion not working
19
2009-11-26 13:35:11
<p>How can I set up Cygwin to have tab completion?</p> <p>Actually, I do have it automatically, but it does not seem to complete paths. How do I set it up to complete paths?</p>
19,978
216,275
2021-07-12 14:36:48
1,803,891
15
2009-11-26 14:13:17
33,837
2009-12-28 17:06:17
https://stackoverflow.com/q/1803701
https://stackoverflow.com/a/1803891
<p>Cygwin paths typically start with <code>/cygdrive/c</code> (substitute whatever drive letter you happen to be using, of course). So to complete <code>c:\Program Files</code>, you must type (for instance) <kbd>/cygdrive/c/Prog</kbd> and then press <kbd>TAB</kbd>.</p> <p>Also, note that Cygwin is case-sensitive, so ...
<p>Cygwin paths typically start with <code>/cygdrive/c</code> (substitute whatever drive letter you happen to be using, of course). So to complete <code>c:\Program Files</code>, you must type (for instance) <kbd>/cygdrive/c/Prog</kbd> and then press <kbd>TAB</kbd>.</p> <p>Also, note that Cygwin is case-sensitive, so ...
387, 1731
bash, cygwin
<h1>cygwin file path tab completion not working</h1> <p>How can I set up Cygwin to have tab completion?</p> <p>Actually, I do have it automatically, but it does not seem to complete paths. How do I set it up to complete 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,100
bash
# cygwin file path tab completion not working How can I set up Cygwin to have tab completion? Actually, I do have it automatically, but it does not seem to complete paths. How do I set it up to complete paths?
Cygwin paths typically start with `/cygdrive/c` (substitute whatever drive letter you happen to be using, of course). So to complete `c:\Program Files`, you must type (for instance) `/cygdrive/c/Prog` and then press `TAB`. Also, note that Cygwin is case-sensitive, so `/cygdrive/c/prog` would not complete to `c:\Progra...
31814663
Git remote two branches same name different case
18
2015-08-04 16:33:27
<pre><code>origin/joetest origin/JoeTest </code></pre> <p>I have a problem I have two remote branches in git which are the same name with different case.</p> <p>I can't work out what todo in visual studio online I can see the differences but it can't merge them because of conflicts.</p> <p>The git tools in visual st...
12,506
3,173,834
2024-01-07 22:07:01
31,814,760
15
2015-08-04 16:38:40
216,074
2015-08-04 16:38:40
https://stackoverflow.com/q/31814663
https://stackoverflow.com/a/31814760
<p>Clone the repository on an operating system with a case-sensitive file system, e.g. Linux, then rename one of the branches, push it, and delete the old branch:</p> <pre><code>git clone &lt;url&gt; repo cd repo git checkout -b joetest2 origin/JoeTest git push origin joetest2:joetest2 git push origin :JoeTest </code>...
<p>Clone the repository on an operating system with a case-sensitive file system, e.g. Linux, then rename one of the branches, push it, and delete the old branch:</p> <pre><code>git clone &lt;url&gt; repo cd repo git checkout -b joetest2 origin/JoeTest git push origin joetest2:joetest2 git push origin :JoeTest </code>...
119, 387
bash, git
<h1>Git remote two branches same name different case</h1> <pre><code>origin/joetest origin/JoeTest </code></pre> <p>I have a problem I have two remote branches in git which are the same name with different case.</p> <p>I can't work out what todo in visual studio online I can see the differences but it can't merge the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,101
bash
# Git remote two branches same name different case ``` origin/joetest origin/JoeTest ``` I have a problem I have two remote branches in git which are the same name with different case. I can't work out what todo in visual studio online I can see the differences but it can't merge them because of conflicts. The git ...
Clone the repository on an operating system with a case-sensitive file system, e.g. Linux, then rename one of the branches, push it, and delete the old branch: ``` git clone <url> repo cd repo git checkout -b joetest2 origin/JoeTest git push origin joetest2:joetest2 git push origin :JoeTest ``` As for why Git is havi...
19007884
Import XML files to PostgreSQL
18
2013-09-25 14:36:51
<p>I do have a lot of XML files I would like to import in the table <code>xml_data</code>:</p> <pre><code>create table xml_data(result xml); </code></pre> <p>To do this I have a simple bash script with loop:</p> <pre><code>#!/bin/sh FILES=/folder/with/xml/files/*.xml for f in $FILES do psql psql -d mydb -h myhost ...
65,767
1,442,374
2019-11-28 10:58:46
19,013,822
15
2013-09-25 19:42:18
939,860
2019-04-26 22:00:36
https://stackoverflow.com/q/19007884
https://stackoverflow.com/a/19013822
<p>I would try a different approach: read the XML file directly into variable inside a plpgsql function and proceed from there. Should be <strong>a lot faster</strong> and a lot more robust.</p> <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION f_sync_from_xml() RETURNS boolean AS $BODY$ ...
<p>I would try a different approach: read the XML file directly into variable inside a plpgsql function and proceed from there. Should be <strong>a lot faster</strong> and a lot more robust.</p> <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION f_sync_from_xml() RETURNS boolean AS $BODY$ ...
19, 256, 387
bash, postgresql, xml
<h1>Import XML files to PostgreSQL</h1> <p>I do have a lot of XML files I would like to import in the table <code>xml_data</code>:</p> <pre><code>create table xml_data(result xml); </code></pre> <p>To do this I have a simple bash script with loop:</p> <pre><code>#!/bin/sh FILES=/folder/with/xml/files/*.xml for f in ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,102
bash
# Import XML files to PostgreSQL I do have a lot of XML files I would like to import in the table `xml_data`: ``` create table xml_data(result xml); ``` To do this I have a simple bash script with loop: ``` #!/bin/sh FILES=/folder/with/xml/files/*.xml for f in $FILES do psql psql -d mydb -h myhost -U usr -c \'\co...
I would try a different approach: read the XML file directly into variable inside a plpgsql function and proceed from there. Should be **a lot faster** and a lot more robust. ``` CREATE OR REPLACE FUNCTION f_sync_from_xml() RETURNS boolean AS $BODY$ DECLARE myxml xml; datafile text := 'path/to/my_file.xml...
17189010
How to copy/cut a file (not the contents) to the clipboard in Windows on the command line?
18
2013-06-19 10:34:30
<p>Is there a way to copy (or cut) a file to the Windows clipboard from the command line?</p> <p>In particular with a batch script. I know how to copy the contents to the clipboard (<code>type file | clip</code>), but this is not the case. I want to have the whole file as I would press <kbd>Ctrl</kbd> + <kbd>C</kbd> i...
15,419
2,451,546
2021-08-29 15:18:41
17,354,470
15
2013-06-27 22:44:49
2,451,546
2017-04-24 15:18:56
https://stackoverflow.com/q/17189010
https://stackoverflow.com/a/17354470
<p>OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard:</p> <pre><code>using System; using System.Windows.Forms; using System.Collections.Generic; using System.Collections.Specialized; namespace File2Clip { public class App { [STAThread] ...
<p>OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard:</p> <pre><code>using System; using System.Windows.Forms; using System.Collections.Generic; using System.Collections.Specialized; namespace File2Clip { public class App { [STAThread] ...
64, 390, 524, 1231, 7002
batch-file, clipboard, command-line, shell, windows
<h1>How to copy/cut a file (not the contents) to the clipboard in Windows on the command line?</h1> <p>Is there a way to copy (or cut) a file to the Windows clipboard from the command line?</p> <p>In particular with a batch script. I know how to copy the contents to the clipboard (<code>type file | clip</code>), but t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,103
bash
# How to copy/cut a file (not the contents) to the clipboard in Windows on the command line? Is there a way to copy (or cut) a file to the Windows clipboard from the command line? In particular with a batch script. I know how to copy the contents to the clipboard (`type file | clip`), but this is not the case. I want...
OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard: ``` using System; using System.Windows.Forms; using System.Collections.Generic; using System.Collections.Specialized; namespace File2Clip { public class App { [STAThread] static vo...
17114807
sed replace last line matching pattern
18
2013-06-14 18:14:10
<p>Given a file like this:</p> <pre><code>a b a b </code></pre> <p>I'd like to be able to use <code>sed</code> to replace just the last line that contains an instance of "a" in the file. So if I wanted to replace it with "c", then the output should look like: </p> <pre><code>a b c b </code></pre> <p>Note that I n...
22,138
1,789,543
2024-07-20 20:10:16
17,115,550
15
2013-06-14 19:02:55
7,552
2017-01-25 05:00:51
https://stackoverflow.com/q/17114807
https://stackoverflow.com/a/17115550
<p>Not quite sed only:</p> <pre><code>tac file | sed '/a/ {s//c/; :loop; n; b loop}' | tac </code></pre> <p>testing</p> <pre><code>% printf "%s\n" a b a b a b | tac | sed '/a/ {s//c/; :loop; n; b loop}' | tac a b a b c b </code></pre> <p>Reverse the file, then for the <strong>first</strong> match, make the substitu...
<p>Not quite sed only:</p> <pre><code>tac file | sed '/a/ {s//c/; :loop; n; b loop}' | tac </code></pre> <p>testing</p> <pre><code>% printf "%s\n" a b a b a b | tac | sed '/a/ {s//c/; :loop; n; b loop}' | tac a b a b c b </code></pre> <p>Reverse the file, then for the <strong>first</strong> match, make the substitu...
18, 387, 5282
bash, regex, sed
<h1>sed replace last line matching pattern</h1> <p>Given a file like this:</p> <pre><code>a b a b </code></pre> <p>I'd like to be able to use <code>sed</code> to replace just the last line that contains an instance of "a" in the file. So if I wanted to replace it with "c", then the output should look like: </p> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,104
bash
# sed replace last line matching pattern Given a file like this: ``` a b a b ``` I'd like to be able to use `sed` to replace just the last line that contains an instance of "a" in the file. So if I wanted to replace it with "c", then the output should look like: ``` a b c b ``` Note that I need this to work irresp...
Not quite sed only: ``` tac file | sed '/a/ {s//c/; :loop; n; b loop}' | tac ``` testing ``` % printf "%s\n" a b a b a b | tac | sed '/a/ {s//c/; :loop; n; b loop}' | tac a b a b c b ``` Reverse the file, then for the **first** match, make the substitution and then unconditionally slurp up the rest of the file. The...
14513571
How to enable default file completion in bash
18
2013-01-25 00:49:18
<p>Say I have a command named "foo" that takes one argument (either "encrypt" or "decrypt") and then a list of files. I want to write a bash completion script that helps with the first argument and then enables standard file completion for the others. The closest I've been able to come is this:</p> <pre><code>comple...
5,743
1,988,504
2019-03-13 21:28:10
14,524,311
15
2013-01-25 14:55:07
1,955,371
2019-03-13 21:28:10
https://stackoverflow.com/q/14513571
https://stackoverflow.com/a/14524311
<p>The bash documentation can be a little enigmatic. The simplest solution is to alter the completion function binding:</p> <pre><code>complete -o filenames -F _foo foo </code></pre> <p>This means the function returns filenames (including directories), and special handling of the results is enabled.</p> <p>(IMHO the...
<p>The bash documentation can be a little enigmatic. The simplest solution is to alter the completion function binding:</p> <pre><code>complete -o filenames -F _foo foo </code></pre> <p>This means the function returns filenames (including directories), and special handling of the results is enabled.</p> <p>(IMHO the...
387
bash
<h1>How to enable default file completion in bash</h1> <p>Say I have a command named "foo" that takes one argument (either "encrypt" or "decrypt") and then a list of files. I want to write a bash completion script that helps with the first argument and then enables standard file completion for the others. The closest...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,105
bash
# How to enable default file completion in bash Say I have a command named "foo" that takes one argument (either "encrypt" or "decrypt") and then a list of files. I want to write a bash completion script that helps with the first argument and then enables standard file completion for the others. The closest I've been ...
The bash documentation can be a little enigmatic. The simplest solution is to alter the completion function binding: ``` complete -o filenames -F _foo foo ``` This means the function returns filenames (including directories), and special handling of the results is enabled. (IMHO the documentation doesn't make it cle...
7935512
Why doesn't "sort file1 > file1" work?
18
2011-10-28 22:26:41
<p>When I am trying to sort a file and save the sorted output in itself, like this</p> <pre><code>sort file1 &gt; file1; </code></pre> <p>the contents of the file1 is getting erased altogether, whereas when i am trying to do the same with 'tee' command like this</p> <pre><code>sort file1 | tee file1; </code></pre> ...
8,887
540,665
2017-08-16 23:39:27
7,935,539
15
2011-10-28 22:30:06
null
2011-10-28 22:30:06
https://stackoverflow.com/q/7935512
https://stackoverflow.com/a/7935539
<p>It doesn't work because '>' redirection implies truncation, and to avoid keeping the whole output of <code>sort</code> in the memory before re-directing to the file, bash truncates and redirects output before running <code>sort</code>. Thus, contents of the <code>file1</code> file will be truncated before <code>sort...
<p>It doesn't work because '>' redirection implies truncation, and to avoid keeping the whole output of <code>sort</code> in the memory before re-directing to the file, bash truncates and redirects output before running <code>sort</code>. Thus, contents of the <code>file1</code> file will be truncated before <code>sort...
34, 58, 390, 5813, 31901
http-redirect, linux, pipe, shell, unix
<h1>Why doesn't "sort file1 > file1" work?</h1> <p>When I am trying to sort a file and save the sorted output in itself, like this</p> <pre><code>sort file1 &gt; file1; </code></pre> <p>the contents of the file1 is getting erased altogether, whereas when i am trying to do the same with 'tee' command like this</p> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,106
bash
# Why doesn't "sort file1 > file1" work? When I am trying to sort a file and save the sorted output in itself, like this ``` sort file1 > file1; ``` the contents of the file1 is getting erased altogether, whereas when i am trying to do the same with 'tee' command like this ``` sort file1 | tee file1; ``` it works ...
It doesn't work because '>' redirection implies truncation, and to avoid keeping the whole output of `sort` in the memory before re-directing to the file, bash truncates and redirects output before running `sort`. Thus, contents of the `file1` file will be truncated before `sort` will have a chance to read it.
7652911
equivalent of su in powershell
18
2011-10-04 19:13:19
<p>Let's say I'm an administrator on a Windows7 box. I'd like to be able to run commands as other users without knowing their passwords. This is what happens on linux. If I'm root, I can 'su' to other accounts without providing any password and run commands in their own name.</p>
38,713
140,732
2018-01-25 00:14:03
7,656,592
15
2011-10-05 04:02:27
608,772
2011-10-05 04:02:27
https://stackoverflow.com/q/7652911
https://stackoverflow.com/a/7656592
<p><strong>su</strong> (substitute user or switch user) allows changing the account associated with the current terminal. Where <em>Normal user</em> have to give password of the account he wants to change to, super user (root) can change to any ID he wants without giving password.</p> <p><strong>sudo</strong> executes...
<p><strong>su</strong> (substitute user or switch user) allows changing the account associated with the current terminal. Where <em>Normal user</em> have to give password of the account he wants to change to, super user (root) can change to any ID he wants without giving password.</p> <p><strong>sudo</strong> executes...
526
powershell
<h1>equivalent of su in powershell</h1> <p>Let's say I'm an administrator on a Windows7 box. I'd like to be able to run commands as other users without knowing their passwords. This is what happens on linux. If I'm root, I can 'su' to other accounts without providing any password and run commands in their own name.</p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,107
bash
# equivalent of su in powershell Let's say I'm an administrator on a Windows7 box. I'd like to be able to run commands as other users without knowing their passwords. This is what happens on linux. If I'm root, I can 'su' to other accounts without providing any password and run commands in their own name.
**su** (substitute user or switch user) allows changing the account associated with the current terminal. Where *Normal user* have to give password of the account he wants to change to, super user (root) can change to any ID he wants without giving password. **sudo** executes a command as another user but observes a s...
3605146
Creating & Editing performance counters in a powershell script or command line
18
2010-08-31 00:10:38
<p>I'm trying to move the verification &amp; creation of my performance counter groups, and the counters themselves, out of my web service and into a powershell script that's run during deployment.</p> <p>Can this be done? Or am I stuck using a simple app to build the groups &amp; counters?</p> <p>Thanks much :)</p>
7,401
226,500
2017-11-20 20:50:20
4,394,377
15
2010-12-09 02:43:59
226,500
2010-12-09 02:43:59
https://stackoverflow.com/q/3605146
https://stackoverflow.com/a/4394377
<p>Figured this out a while ago, but never posted.<br> Here's my solution: </p> <pre><code>//save out the type name for sanity's sake $ccdTypeName = 'System.Diagnostics.CounterCreationData' $CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection //create as many counters as we'd like, and ad...
<p>Figured this out a while ago, but never posted.<br> Here's my solution: </p> <pre><code>//save out the type name for sanity's sake $ccdTypeName = 'System.Diagnostics.CounterCreationData' $CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection //create as many counters as we'd like, and ad...
526, 598, 2631, 7466
cmd, performance, performancecounter, powershell
<h1>Creating & Editing performance counters in a powershell script or command line</h1> <p>I'm trying to move the verification &amp; creation of my performance counter groups, and the counters themselves, out of my web service and into a powershell script that's run during deployment.</p> <p>Can this be done? Or am I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,108
bash
# Creating & Editing performance counters in a powershell script or command line I'm trying to move the verification & creation of my performance counter groups, and the counters themselves, out of my web service and into a powershell script that's run during deployment. Can this be done? Or am I stuck using a simple...
Figured this out a while ago, but never posted. Here's my solution: ``` //save out the type name for sanity's sake $ccdTypeName = 'System.Diagnostics.CounterCreationData' $CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection //create as many counters as we'd like, and add them to the coll...
1644856
Terminate running commands when shell script is killed
18
2009-10-29 16:15:10
<p>For testing purposes I have this shell script</p> <pre><code>#!/bin/bash echo $$ find / &gt;/dev/null 2&gt;&amp;1 </code></pre> <p>Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.</p> <pre><code>$ ./test-k.sh 13227 &lt;Ctrl+C&gt; $ ps -ef |grep find $ </code></pre> <p>...
18,847
126,769
2015-11-05 16:40:13
1,645,157
15
2009-10-29 17:00:26
116,908
2009-10-29 17:31:36
https://stackoverflow.com/q/1644856
https://stackoverflow.com/a/1645157
<p>I would do something like this:</p> <pre><code>#!/bin/bash trap : SIGTERM SIGINT echo $$ find / &gt;/dev/null 2&gt;&amp;1 &amp; FIND_PID=$! wait $FIND_PID if [[ $? -gt 128 ]] then kill $FIND_PID fi </code></pre> <p>Some explanation is in order, I guess. Out the gate, we need to change some of the default ...
<p>I would do something like this:</p> <pre><code>#!/bin/bash trap : SIGTERM SIGINT echo $$ find / &gt;/dev/null 2&gt;&amp;1 &amp; FIND_PID=$! wait $FIND_PID if [[ $? -gt 128 ]] then kill $FIND_PID fi </code></pre> <p>Some explanation is in order, I guess. Out the gate, we need to change some of the default ...
387
bash
<h1>Terminate running commands when shell script is killed</h1> <p>For testing purposes I have this shell script</p> <pre><code>#!/bin/bash echo $$ find / &gt;/dev/null 2&gt;&amp;1 </code></pre> <p>Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.</p> <pre><code>$ ./test-k....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,109
bash
# Terminate running commands when shell script is killed For testing purposes I have this shell script ``` #!/bin/bash echo $$ find / >/dev/null 2>&1 ``` Running this from an interactive terminal, ctrl+c will terminate bash, and the find command. ``` $ ./test-k.sh 13227 <Ctrl+C> $ ps -ef |grep find $ ``` Running i...
I would do something like this: ``` #!/bin/bash trap : SIGTERM SIGINT echo $$ find / >/dev/null 2>&1 & FIND_PID=$! wait $FIND_PID if [[ $? -gt 128 ]] then kill $FIND_PID fi ``` Some explanation is in order, I guess. Out the gate, we need to change some of the default signal handling. `:` is a no-op command, s...
1010924
Is there a shorter way to pull groups out of a Powershell regex?
18
2009-06-18 05:37:01
<p>In PowerShell I find myself doing this kind of thing over and over again for matches:</p> <pre><code>some-command | select-string '^(//[^#]*)' | %{some-other-command $_.matches[0].groups[1].value} </code></pre> <p>So basically - run a command that generates lines of text, and for each line I want to run a com...
14,071
14,582
2012-03-07 19:22:25
1,011,163
15
2009-06-18 06:58:56
74,198
2009-06-19 13:13:55
https://stackoverflow.com/q/1010924
https://stackoverflow.com/a/1011163
<p>You can use the <code>-match</code> operator to reformulate your command as:</p> <pre><code>some-command | Foreach-Object { if($_ -match '^(//[^#]*)') { some-other-command $($matches[1])}} </code></pre>
<p>You can use the <code>-match</code> operator to reformulate your command as:</p> <pre><code>some-command | Foreach-Object { if($_ -match '^(//[^#]*)') { some-other-command $($matches[1])}} </code></pre>
18, 526
powershell, regex
<h1>Is there a shorter way to pull groups out of a Powershell regex?</h1> <p>In PowerShell I find myself doing this kind of thing over and over again for matches:</p> <pre><code>some-command | select-string '^(//[^#]*)' | %{some-other-command $_.matches[0].groups[1].value} </code></pre> <p>So basically - run a c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,110
bash
# Is there a shorter way to pull groups out of a Powershell regex? In PowerShell I find myself doing this kind of thing over and over again for matches: ``` some-command | select-string '^(//[^#]*)' | %{some-other-command $_.matches[0].groups[1].value} ``` So basically - run a command that generates lines of te...
You can use the `-match` operator to reformulate your command as: ``` some-command | Foreach-Object { if($_ -match '^(//[^#]*)') { some-other-command $($matches[1])}} ```
65004930
Win 10 WSL won't set default 2
17
2020-11-25 12:41:32
<p>Completely new to developing on windows (as my mac is in for repair) and I'm trying to follow these instructions <a href="https://learn.microsoft.com/en-us/windows/wsl/install-win10" rel="noreferrer">https://learn.microsoft.com/en-us/windows/wsl/install-win10</a></p> <p>But while I seem to have an adequate version, ...
62,241
1,923,190
2023-03-18 21:33:47
65,005,633
15
2020-11-25 13:27:23
13,510,728
2020-11-25 13:27:23
https://stackoverflow.com/q/65004930
https://stackoverflow.com/a/65005633
<p>Make sure virtualisation is enabled in your BIOS by going to Task Manager -&gt; More Details -&gt; Performace -&gt; CPU and an option called Virtualisation should be set to enabled. If it isn't enabled then go to your BIOS and enable <strong>SVM Mode</strong> on AMD CPUs or <strong>Intel Virtualisation Technology</s...
<p>Make sure virtualisation is enabled in your BIOS by going to Task Manager -&gt; More Details -&gt; Performace -&gt; CPU and an option called Virtualisation should be set to enabled. If it isn't enabled then go to your BIOS and enable <strong>SVM Mode</strong> on AMD CPUs or <strong>Intel Virtualisation Technology</s...
64, 526
powershell, windows
<h1>Win 10 WSL won't set default 2</h1> <p>Completely new to developing on windows (as my mac is in for repair) and I'm trying to follow these instructions <a href="https://learn.microsoft.com/en-us/windows/wsl/install-win10" rel="noreferrer">https://learn.microsoft.com/en-us/windows/wsl/install-win10</a></p> <p>But wh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,111
bash
# Win 10 WSL won't set default 2 Completely new to developing on windows (as my mac is in for repair) and I'm trying to follow these instructions <https://learn.microsoft.com/en-us/windows/wsl/install-win10> But while I seem to have an adequate version, my wsl does not seem to have the right option. I have installed ...
Make sure virtualisation is enabled in your BIOS by going to Task Manager -> More Details -> Performace -> CPU and an option called Virtualisation should be set to enabled. If it isn't enabled then go to your BIOS and enable **SVM Mode** on AMD CPUs or **Intel Virtualisation Technology** on Intel CPUs. next, make sure...
29699026
PowerShell copy an array completely
17
2015-04-17 12:18:46
<p>I'm trying to create a complete copy of an existing array. Every time I try this it doesn't seem to work. The thing is that I'm modifying the object names inside the new copied array, but they're also changed in the original array..</p> <h4>Simplified example</h4> <pre><code>Function Get-Fruits { Param ( ...
28,055
2,304,170
2025-01-13 08:25:04
29,699,129
15
2015-04-17 12:24:03
4,640,209
2015-04-17 12:24:03
https://stackoverflow.com/q/29699026
https://stackoverflow.com/a/29699129
<p>You can use serialisation to deep clone your array:</p> <pre><code>#Original data $FruitsOriginal = Get-Fruits # Serialize and Deserialize data using BinaryFormatter $ms = New-Object System.IO.MemoryStream $bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter $bf.Serialize($ms, $FruitsOri...
<p>You can use serialisation to deep clone your array:</p> <pre><code>#Original data $FruitsOriginal = Get-Fruits # Serialize and Deserialize data using BinaryFormatter $ms = New-Object System.IO.MemoryStream $bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter $bf.Serialize($ms, $FruitsOri...
114, 526
arrays, powershell
<h1>PowerShell copy an array completely</h1> <p>I'm trying to create a complete copy of an existing array. Every time I try this it doesn't seem to work. The thing is that I'm modifying the object names inside the new copied array, but they're also changed in the original array..</p> <h4>Simplified example</h4> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,112
bash
# PowerShell copy an array completely I'm trying to create a complete copy of an existing array. Every time I try this it doesn't seem to work. The thing is that I'm modifying the object names inside the new copied array, but they're also changed in the original array.. #### Simplified example ``` Function Get-Fruit...
You can use serialisation to deep clone your array: ``` #Original data $FruitsOriginal = Get-Fruits # Serialize and Deserialize data using BinaryFormatter $ms = New-Object System.IO.MemoryStream $bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter $bf.Serialize($ms, $FruitsOriginal) $ms.Pos...
28110536
How to split an mbox file into n-MB big chunks using the terminal?
17
2015-01-23 13:00:58
<p>So I've <a href="https://stackoverflow.com/questions/11281893/how-to-split-mailbox-into-single-file-per-message">read through this question</a> on SO but it does not quite help me any. I want to import a Gmail generated mbox file into another webmail service, but the problem is it only allows 40 MB huge files per im...
13,515
1,449,710
2024-08-16 22:28:06
28,111,716
15
2015-01-23 14:07:41
2,836,621
2015-01-23 16:58:47
https://stackoverflow.com/q/28110536
https://stackoverflow.com/a/28111716
<p>If your <code>mbox</code> is in standard format, each message will begin with <code>From</code> and a space:</p> <pre><code>From someone@somewhere.com </code></pre> <p>So, you could <code>COPY YOUR MBOX TO A TEMPORARY DIRECTORY</code> and try using <code>awk</code> to process it, on a message-by-message basis, onl...
<p>If your <code>mbox</code> is in standard format, each message will begin with <code>From</code> and a space:</p> <pre><code>From someone@somewhere.com </code></pre> <p>So, you could <code>COPY YOUR MBOX TO A TEMPORARY DIRECTORY</code> and try using <code>awk</code> to process it, on a message-by-message basis, onl...
387, 391, 19228
bash, mbox, terminal
<h1>How to split an mbox file into n-MB big chunks using the terminal?</h1> <p>So I've <a href="https://stackoverflow.com/questions/11281893/how-to-split-mailbox-into-single-file-per-message">read through this question</a> on SO but it does not quite help me any. I want to import a Gmail generated mbox file into anothe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,113
bash
# How to split an mbox file into n-MB big chunks using the terminal? So I've [read through this question](https://stackoverflow.com/questions/11281893/how-to-split-mailbox-into-single-file-per-message) on SO but it does not quite help me any. I want to import a Gmail generated mbox file into another webmail service, b...
If your `mbox` is in standard format, each message will begin with `From` and a space: ``` From someone@somewhere.com ``` So, you could `COPY YOUR MBOX TO A TEMPORARY DIRECTORY` and try using `awk` to process it, on a message-by-message basis, only splitting at the start of any message. Let's say we went for 1,000 me...
21245579
PowerShell - Setting $ErrorActionPreference for the entire script
17
2014-01-20 22:35:51
<p>I've been giving PowerShell (v3.0) a shot for the first time today, and became enormously frustrated with the strange way some of its error-handling concepts are implemented.</p> <p>I wrote the following piece of code (using the Remote Registry PowerShell Module)</p> <pre><code>try { New-RegKey -ComputerName $...
25,185
1,832,740
2014-01-22 04:40:39
21,260,623
15
2014-01-21 14:16:38
574,168
2014-01-22 04:40:39
https://stackoverflow.com/q/21245579
https://stackoverflow.com/a/21260623
<p>Since you're running V3, you also have the option of using $PSDefaultParameterValues:</p> <pre><code>$PSDefaultParameterValues += @{'New-RegKey:ErrorAction' = 'Stop'} </code></pre> <p>Normally that will change it in the global scope. If you want to isolate it to just the local or script scope, you can initialize ...
<p>Since you're running V3, you also have the option of using $PSDefaultParameterValues:</p> <pre><code>$PSDefaultParameterValues += @{'New-RegKey:ErrorAction' = 'Stop'} </code></pre> <p>Normally that will change it in the global scope. If you want to isolate it to just the local or script scope, you can initialize ...
379, 526, 22864, 73157
error-handling, powershell, powershell-3.0, powershell-ise
<h1>PowerShell - Setting $ErrorActionPreference for the entire script</h1> <p>I've been giving PowerShell (v3.0) a shot for the first time today, and became enormously frustrated with the strange way some of its error-handling concepts are implemented.</p> <p>I wrote the following piece of code (using the Remote Regis...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,114
bash
# PowerShell - Setting $ErrorActionPreference for the entire script I've been giving PowerShell (v3.0) a shot for the first time today, and became enormously frustrated with the strange way some of its error-handling concepts are implemented. I wrote the following piece of code (using the Remote Registry PowerShell M...
Since you're running V3, you also have the option of using $PSDefaultParameterValues: ``` $PSDefaultParameterValues += @{'New-RegKey:ErrorAction' = 'Stop'} ``` Normally that will change it in the global scope. If you want to isolate it to just the local or script scope, you can initialize a new one in the local scope...
17846417
Getting all open PS Sessions on a remote server (from new console window)
17
2013-07-24 23:15:13
<p>I can start 5 new PS sessions on a remote server and see them all by running Get-PSSession</p> <pre><code>PS C:\&gt; New-PSSession -ComputerName MyServerName Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- --------------...
67,401
2,009,405
2015-02-11 21:47:53
17,849,744
15
2013-07-25 05:31:15
235
2013-07-25 05:31:15
https://stackoverflow.com/q/17846417
https://stackoverflow.com/a/17849744
<p>From what I can tell...</p> <p>The PSSessions you created live on "MyServerName" and, for the duration of the session you first created them, will also be returned by Get-PSSession (with no arguments, in the PowerShell window on the box you're remoting FROM). When you close the session they are created in, the sess...
<p>From what I can tell...</p> <p>The PSSessions you created live on "MyServerName" and, for the duration of the session you first created them, will also be returned by Get-PSSession (with no arguments, in the PowerShell window on the box you're remoting FROM). When you close the session they are created in, the sess...
526, 8192, 73157
powershell, powershell-3.0, remote-access
<h1>Getting all open PS Sessions on a remote server (from new console window)</h1> <p>I can start 5 new PS sessions on a remote server and see them all by running Get-PSSession</p> <pre><code>PS C:\&gt; New-PSSession -ComputerName MyServerName Id Name ComputerName State ConfigurationName ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,115
bash
# Getting all open PS Sessions on a remote server (from new console window) I can start 5 new PS sessions on a remote server and see them all by running Get-PSSession ``` PS C:\> New-PSSession -ComputerName MyServerName Id Name ComputerName State ConfigurationName Availability -- ...
From what I can tell... The PSSessions you created live on "MyServerName" and, for the duration of the session you first created them, will also be returned by Get-PSSession (with no arguments, in the PowerShell window on the box you're remoting FROM). When you close the session they are created in, the sessions are n...
10942919
Customize tab completion in shell
17
2012-06-08 04:02:49
<p>This may be have a better name than "custom tab completion", but here's the scenario:</p> <p>Typically when I'm at the command line and I enter a command, followed with {TAB} twice, I get a list of all files and subdirectories in the current directory. For example:</p> <pre><code>[user@host tmp]$ cat &lt;TAB&gt;&...
12,281
736,937
2014-01-31 09:30:18
10,947,749
15
2012-06-08 11:12:55
26,428
2012-06-08 11:12:55
https://stackoverflow.com/q/10942919
https://stackoverflow.com/a/10947749
<p>You will likely find a file on your system called <code>/etc/bash_completion</code> which is full of functions and <code>complete</code> commands that set up this behavior. The file will be sourced by one of your shell startup files such as <code>~/.bashrc</code>.</p> <p>There may also be a directory called <code>/...
<p>You will likely find a file on your system called <code>/etc/bash_completion</code> which is full of functions and <code>complete</code> commands that set up this behavior. The file will be sourced by one of your shell startup files such as <code>~/.bashrc</code>.</p> <p>There may also be a directory called <code>/...
58, 387, 390, 12891, 59778
bash, bash-completion, linux, shell, tab-completion
<h1>Customize tab completion in shell</h1> <p>This may be have a better name than "custom tab completion", but here's the scenario:</p> <p>Typically when I'm at the command line and I enter a command, followed with {TAB} twice, I get a list of all files and subdirectories in the current directory. For example:</p> <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,116
bash
# Customize tab completion in shell This may be have a better name than "custom tab completion", but here's the scenario: Typically when I'm at the command line and I enter a command, followed with {TAB} twice, I get a list of all files and subdirectories in the current directory. For example: ``` [user@host tmp]$ c...
You will likely find a file on your system called `/etc/bash_completion` which is full of functions and `complete` commands that set up this behavior. The file will be sourced by one of your shell startup files such as `~/.bashrc`. There may also be a directory called `/etc/bash_completion.d` which contains individual...
7196937
How to speed up Powershell Get-Childitem over UNC
17
2011-08-25 20:43:41
<p><code>DIR</code> or <code>GCI</code> is slow in Powershell, but fast in CMD. Is there any way to speed this up?</p> <p>In CMD.exe, after a sub-second delay, this responds as fast as the CMD window can keep up</p> <pre><code>dir \\remote-server.domain.com\share\folder\file*.* </code></pre> <p>In Powershell (v2), a...
45,242
4,126
2020-04-14 22:50:15
7,208,713
15
2011-08-26 17:55:46
null
2012-09-13 15:49:02
https://stackoverflow.com/q/7196937
https://stackoverflow.com/a/7208713
<p><a href="http://blogs.msdn.com/b/powershell/archive/2009/11/04/why-is-get-childitem-so-slow.aspx" rel="noreferrer">Here</a> is a good explanation on why Get-ChildItem is slow by Lee Holmes. If you take note of the comment from "Anon 11 Mar 2010 11:11 AM" at the bottom of the page his solution might work for you.</p>...
<p><a href="http://blogs.msdn.com/b/powershell/archive/2009/11/04/why-is-get-childitem-so-slow.aspx" rel="noreferrer">Here</a> is a good explanation on why Get-ChildItem is slow by Lee Holmes. If you take note of the comment from "Anon 11 Mar 2010 11:11 AM" at the bottom of the page his solution might work for you.</p>...
526, 24067
powershell, powershell-2.0
<h1>How to speed up Powershell Get-Childitem over UNC</h1> <p><code>DIR</code> or <code>GCI</code> is slow in Powershell, but fast in CMD. Is there any way to speed this up?</p> <p>In CMD.exe, after a sub-second delay, this responds as fast as the CMD window can keep up</p> <pre><code>dir \\remote-server.domain.com\s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,117
bash
# How to speed up Powershell Get-Childitem over UNC `DIR` or `GCI` is slow in Powershell, but fast in CMD. Is there any way to speed this up? In CMD.exe, after a sub-second delay, this responds as fast as the CMD window can keep up ``` dir \\remote-server.domain.com\share\folder\file*.* ``` In Powershell (v2), afte...
[Here](http://blogs.msdn.com/b/powershell/archive/2009/11/04/why-is-get-childitem-so-slow.aspx) is a good explanation on why Get-ChildItem is slow by Lee Holmes. If you take note of the comment from "Anon 11 Mar 2010 11:11 AM" at the bottom of the page his solution might work for you. Anon's Code: ``` # SCOPE: SEARCH...
5809736
how to use "if" statements inside pipeline
17
2011-04-27 19:51:37
<p>I'm trying to use <code>if</code> inside a pipeline.</p> <p>I know that there is <code>where</code> (alias <code>?</code>) filter, but what if I want to activate a filter only if a certain condition is satisfied?</p> <p>I mean, for example:</p> <pre class="lang-bash prettyprint-override"><code>get-something | ? {$_....
39,968
253,811
2025-12-02 14:27:46
5,810,593
15
2011-04-27 21:06:54
686,969
2011-04-27 21:06:54
https://stackoverflow.com/q/5809736
https://stackoverflow.com/a/5810593
<p>When using where-object, the condition doesn't have to strictly be related to the objects that are passing through the pipeline. So consider a case where sometimes we wanted to filter for odd objects, but only if some other condition was met: </p> <pre><code>$filter = $true 1..10 | ? { (-not $filter) -or ($_ % 2) }...
<p>When using where-object, the condition doesn't have to strictly be related to the objects that are passing through the pipeline. So consider a case where sometimes we wanted to filter for odd objects, but only if some other condition was met: </p> <pre><code>$filter = $true 1..10 | ? { (-not $filter) -or ($_ % 2) }...
526, 2844, 35241, 39271
conditional-statements, pipeline, powershell, statements
<h1>how to use "if" statements inside pipeline</h1> <p>I'm trying to use <code>if</code> inside a pipeline.</p> <p>I know that there is <code>where</code> (alias <code>?</code>) filter, but what if I want to activate a filter only if a certain condition is satisfied?</p> <p>I mean, for example:</p> <pre class="lang-bas...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,118
bash
# how to use "if" statements inside pipeline I'm trying to use `if` inside a pipeline. I know that there is `where` (alias `?`) filter, but what if I want to activate a filter only if a certain condition is satisfied? I mean, for example: ``` get-something | ? {$_.someone -eq 'somespecific'} | format-table ``` How...
When using where-object, the condition doesn't have to strictly be related to the objects that are passing through the pipeline. So consider a case where sometimes we wanted to filter for odd objects, but only if some other condition was met: ``` $filter = $true 1..10 | ? { (-not $filter) -or ($_ % 2) } $filter = $fa...
36802996
bash: nano: command not found at Windows git bash
16
2016-04-22 20:41:54
<p>I am using git version 2.7.0.windows.1 on a windows pc, I used the following command:</p> <pre><code>$ nano README </code></pre> <p>which results me:</p> <pre><code>bash: nano: command not found </code></pre> <p>Now how can I install nano text editor to git bash?</p>
43,349
6,193,267
2023-12-04 03:24:09
45,717,046
15
2017-08-16 15:00:36
2,750,420
2017-08-16 15:00:36
https://stackoverflow.com/q/36802996
https://stackoverflow.com/a/45717046
<p>Little modification of the previous solution (@Simopaa) is worked for me on Windows 10 (without Chocolatey):</p> <ol> <li>Download <a href="https://www.nano-editor.org/dist/win32-support/" rel="noreferrer">nano-git</a></li> <li><p>Move the <code>nano-git-xxx.exe</code> to (for example) <code>C:\Program Files\Git\bi...
<p>Little modification of the previous solution (@Simopaa) is worked for me on Windows 10 (without Chocolatey):</p> <ol> <li>Download <a href="https://www.nano-editor.org/dist/win32-support/" rel="noreferrer">nano-git</a></li> <li><p>Move the <code>nano-git-xxx.exe</code> to (for example) <code>C:\Program Files\Git\bi...
64, 119, 18209, 61874
git, git-bash, nano, windows
<h1>bash: nano: command not found at Windows git bash</h1> <p>I am using git version 2.7.0.windows.1 on a windows pc, I used the following command:</p> <pre><code>$ nano README </code></pre> <p>which results me:</p> <pre><code>bash: nano: command not found </code></pre> <p>Now how can I install nano text editor to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,119
bash
# bash: nano: command not found at Windows git bash I am using git version 2.7.0.windows.1 on a windows pc, I used the following command: ``` $ nano README ``` which results me: ``` bash: nano: command not found ``` Now how can I install nano text editor to git bash?
Little modification of the previous solution (@Simopaa) is worked for me on Windows 10 (without Chocolatey): 1. Download [nano-git](https://www.nano-editor.org/dist/win32-support/) 2. Move the `nano-git-xxx.exe` to (for example) `C:\Program Files\Git\bin`. 3. Modify the `.gitconfig` file with the following (**single**...
40798249
Get parent directory of shell script's directory
16
2016-11-25 05:25:53
<p>I have a shell script here:</p> <pre><code>/node_modules/.bin/exec.sh </code></pre> <p>in the exec.sh script, I want to obtain the path of the directory's parent directory that the script is contained in (not pwd/cwd!). I can obtain the containing directory like so:</p> <pre><code>`dirname $0` </code></pre> <p>w...
17,531
1,223,975
2016-11-25 09:22:51
40,798,290
15
2016-11-25 05:29:30
5,699,852
2016-11-25 05:29:30
https://stackoverflow.com/q/40798249
https://stackoverflow.com/a/40798290
<p>Run dirname twice (nested).</p> <pre><code>~$ dirname $PWD /home ~$ dirname `dirname $PWD` / ~$ </code></pre>
<p>Run dirname twice (nested).</p> <pre><code>~$ dirname $PWD /home ~$ dirname `dirname $PWD` / ~$ </code></pre>
387, 390
bash, shell
<h1>Get parent directory of shell script's directory</h1> <p>I have a shell script here:</p> <pre><code>/node_modules/.bin/exec.sh </code></pre> <p>in the exec.sh script, I want to obtain the path of the directory's parent directory that the script is contained in (not pwd/cwd!). I can obtain the containing directory...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,120
bash
# Get parent directory of shell script's directory I have a shell script here: ``` /node_modules/.bin/exec.sh ``` in the exec.sh script, I want to obtain the path of the directory's parent directory that the script is contained in (not pwd/cwd!). I can obtain the containing directory like so: ``` `dirname $0` ``` ...
Run dirname twice (nested). ``` ~$ dirname $PWD /home ~$ dirname `dirname $PWD` / ~$ ```
38796224
POSIX shell equivalent to <()
16
2016-08-05 19:06:35
<p><code>&lt;(commands ...)</code> in bash/zsh makes the output behavior as a file. Does a POSIX equivalent exist?</p>
2,762
6,338,087
2016-08-05 21:11:24
38,796,342
15
2016-08-05 19:14:41
14,122
2016-08-05 21:11:24
https://stackoverflow.com/q/38796224
https://stackoverflow.com/a/38796342
<pre><code>mkfifo foo.fifo ## if your "commands" is multiple commands # { commands ...; } &gt;foo.fifo &amp; # otherwise, if it's just one commands ... &gt;foo.fifo &amp; something_else foo.fifo </code></pre> <p>is the closest available equivalent to</p> <pre><code>something_else &lt;( commands ... ) </code></pre>...
<pre><code>mkfifo foo.fifo ## if your "commands" is multiple commands # { commands ...; } &gt;foo.fifo &amp; # otherwise, if it's just one commands ... &gt;foo.fifo &amp; something_else foo.fifo </code></pre> <p>is the closest available equivalent to</p> <pre><code>something_else &lt;( commands ... ) </code></pre>...
387, 1993, 3791, 10327, 63638
bash, posix, process-substitution, sh, zsh
<h1>POSIX shell equivalent to <()</h1> <p><code>&lt;(commands ...)</code> in bash/zsh makes the output behavior as a file. Does a POSIX equivalent exist?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,121
bash
# POSIX shell equivalent to <() `<(commands ...)` in bash/zsh makes the output behavior as a file. Does a POSIX equivalent exist?
``` mkfifo foo.fifo ## if your "commands" is multiple commands # { commands ...; } >foo.fifo & # otherwise, if it's just one commands ... >foo.fifo & something_else foo.fifo ``` is the closest available equivalent to ``` something_else <( commands ... ) ```
33381650
How to list Azure Storage Containers and Blobs
16
2015-10-28 01:58:13
<p>I'm new to Azure Storage and I think I may be misunderstanding a few of the concepts.</p> <p>I'd like to list all my Storage Containers and Blobs using PowerShell.</p> <p>I can list all my Storage Accounts using the following code:</p> <pre><code>Get-AzureStorageAccount | Select StorageAccountName, GeoPrimaryLoca...
71,428
1,853,167
2023-03-03 00:39:31
33,381,826
15
2015-10-28 02:19:04
1,567,352
2015-10-28 02:19:04
https://stackoverflow.com/q/33381650
https://stackoverflow.com/a/33381826
<p>Not sure if this is what you want, but I am able to list containers using <code>New-AzureStorageContext</code> and <code>Get-AzureStorageContainers</code>.</p> <pre><code>$ctx = New-AzureStorageContext -StorageAccountName &lt;name&gt; -StorageAccountKey &lt;key&gt; Get-AzureStorageContainer -Context $ctx </code></...
<p>Not sure if this is what you want, but I am able to list containers using <code>New-AzureStorageContext</code> and <code>Get-AzureStorageContainers</code>.</p> <pre><code>$ctx = New-AzureStorageContext -StorageAccountName &lt;name&gt; -StorageAccountKey &lt;key&gt; Get-AzureStorageContainer -Context $ctx </code></...
526, 14158, 35808
azure, azure-storage, powershell
<h1>How to list Azure Storage Containers and Blobs</h1> <p>I'm new to Azure Storage and I think I may be misunderstanding a few of the concepts.</p> <p>I'd like to list all my Storage Containers and Blobs using PowerShell.</p> <p>I can list all my Storage Accounts using the following code:</p> <pre><code>Get-AzureSt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,122
bash
# How to list Azure Storage Containers and Blobs I'm new to Azure Storage and I think I may be misunderstanding a few of the concepts. I'd like to list all my Storage Containers and Blobs using PowerShell. I can list all my Storage Accounts using the following code: ``` Get-AzureStorageAccount | Select StorageAccou...
Not sure if this is what you want, but I am able to list containers using `New-AzureStorageContext` and `Get-AzureStorageContainers`. ``` $ctx = New-AzureStorageContext -StorageAccountName <name> -StorageAccountKey <key> Get-AzureStorageContainer -Context $ctx ```
15857027
Bash doesn't parse quotes when converting a string to arguments
16
2013-04-06 23:05:18
<p>This is my problem. In bash 3:</p> <pre><code>$ test='One "This is two" Three' $ set -- $test $ echo $2 "This </code></pre> <p>How to get bash to understand the quotes and return $2 as <code>This is two</code> and not <code>"This</code>? Unfortunately I cannot alter the construction of the variable called <code>te...
7,679
1,568,545
2020-04-28 07:18:13
15,857,262
15
2013-04-06 23:44:56
89,817
2013-04-06 23:44:56
https://stackoverflow.com/q/15857027
https://stackoverflow.com/a/15857262
<p>The reason this happens is because of the order in which the shell parses the command line: it parses (and removes) quotes and escapes, then replaces variable values. By the time <code>$test</code> gets replaced with <code>One "This is two" Three</code>, it's too late for the quotes to have their intended effect.</p...
<p>The reason this happens is because of the order in which the shell parses the command line: it parses (and removes) quotes and escapes, then replaces variable values. By the time <code>$test</code> gets replaced with <code>One "This is two" Three</code>, it's too late for the quotes to have their intended effect.</p...
139, 387, 2313, 5162, 10804
arguments, bash, quoting, spaces, string
<h1>Bash doesn't parse quotes when converting a string to arguments</h1> <p>This is my problem. In bash 3:</p> <pre><code>$ test='One "This is two" Three' $ set -- $test $ echo $2 "This </code></pre> <p>How to get bash to understand the quotes and return $2 as <code>This is two</code> and not <code>"This</code>? Unfo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,123
bash
# Bash doesn't parse quotes when converting a string to arguments This is my problem. In bash 3: ``` $ test='One "This is two" Three' $ set -- $test $ echo $2 "This ``` How to get bash to understand the quotes and return $2 as `This is two` and not `"This`? Unfortunately I cannot alter the construction of the variab...
The reason this happens is because of the order in which the shell parses the command line: it parses (and removes) quotes and escapes, then replaces variable values. By the time `$test` gets replaced with `One "This is two" Three`, it's too late for the quotes to have their intended effect. The simple (but dangerous)...
5773844
Piping find to find
16
2011-04-24 23:10:17
<p>I want to pipe a find result to a new find. What I have is:</p> <pre><code>find . -iname "2010-06*" -maxdepth 1 -type d | xargs -0 find '{}' -iname "*.jpg" </code></pre> <p>Expected result: Second find receives a list of folders starting with 2010-06, second find returns a list of jpg's contained within those fold...
11,916
496,999
2011-04-25 01:57:32
5,773,863
15
2011-04-24 23:15:04
576,139
2011-04-24 23:15:04
https://stackoverflow.com/q/5773844
https://stackoverflow.com/a/5773863
<p>You need 2 things. <code>-print0</code>, and more importantly <code>-I{}</code> on xargs, otherwise the <code>{}</code> doesn't do anything.</p> <pre><code>find . -iname "2010-06*" -maxdepth 1 -type d -print0 | xargs -0 -I{} find '{}' -iname '*.jpg' </code></pre>
<p>You need 2 things. <code>-print0</code>, and more importantly <code>-I{}</code> on xargs, otherwise the <code>{}</code> doesn't do anything.</p> <pre><code>find . -iname "2010-06*" -maxdepth 1 -type d -print0 | xargs -0 -I{} find '{}' -iname '*.jpg' </code></pre>
387, 5813
bash, pipe
<h1>Piping find to find</h1> <p>I want to pipe a find result to a new find. What I have is:</p> <pre><code>find . -iname "2010-06*" -maxdepth 1 -type d | xargs -0 find '{}' -iname "*.jpg" </code></pre> <p>Expected result: Second find receives a list of folders starting with 2010-06, second find returns a list of jpg'...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,124
bash
# Piping find to find I want to pipe a find result to a new find. What I have is: ``` find . -iname "2010-06*" -maxdepth 1 -type d | xargs -0 find '{}' -iname "*.jpg" ``` Expected result: Second find receives a list of folders starting with 2010-06, second find returns a list of jpg's contained within those folders....
You need 2 things. `-print0`, and more importantly `-I{}` on xargs, otherwise the `{}` doesn't do anything. ``` find . -iname "2010-06*" -maxdepth 1 -type d -print0 | xargs -0 -I{} find '{}' -iname '*.jpg' ```
5643132
Unable to trap SIGINT signal in a background shell
16
2011-04-13 00:26:33
<p>I am unable to trap a signal when running in a child / background process.</p> <p>Here is my simple bash script:</p> <pre><code>#!/bin/bash echo &quot;in child&quot; trap &quot;got_signal&quot; SIGINT function got_signal { echo &quot;trapped&quot; exit 0 } while [ true ]; do sleep 2 done </code></pre> <p...
9,853
347,565
2020-11-25 21:15:30
5,643,222
15
2011-04-13 00:42:10
643,977
2011-04-13 00:42:10
https://stackoverflow.com/q/5643132
https://stackoverflow.com/a/5643222
<p>The <code>bash</code> manpage on OSX (but it should be the same in other versions) has this to say about signal handling:</p> <blockquote> <p>Non-builtin commands run by <code>bash</code> have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchr...
<p>The <code>bash</code> manpage on OSX (but it should be the same in other versions) has this to say about signal handling:</p> <blockquote> <p>Non-builtin commands run by <code>bash</code> have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchr...
387, 2481, 25657, 26115, 124485
bash, bash-trap, child-process, sigint, signals
<h1>Unable to trap SIGINT signal in a background shell</h1> <p>I am unable to trap a signal when running in a child / background process.</p> <p>Here is my simple bash script:</p> <pre><code>#!/bin/bash echo &quot;in child&quot; trap &quot;got_signal&quot; SIGINT function got_signal { echo &quot;trapped&quot; ex...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,125
bash
# Unable to trap SIGINT signal in a background shell I am unable to trap a signal when running in a child / background process. Here is my simple bash script: ``` #!/bin/bash echo "in child" trap "got_signal" SIGINT function got_signal { echo "trapped" exit 0 } while [ true ]; do sleep 2 done ``` When r...
The `bash` manpage on OSX (but it should be the same in other versions) has this to say about signal handling: > Non-builtin commands run by `bash` have signal handlers set to the values > inherited by the shell from its parent. When job control is not in > effect, asynchronous commands ignore `SIGINT` and `SIGQUIT` i...
3984001
Mercurial color extension in Windows Powershell
16
2010-10-21 03:08:04
<p>Is there a way to enable color support for Mercurial in Powershell on Windows 7? The <a href="https://www.mercurial-scm.org/wiki/ColorExtension" rel="nofollow noreferrer">ColorExtension</a> page says to add</p> <pre><code>[color] mode = win32 </code></pre> <p>to your <code>.hgrc</code> file, but it doesn't seem t...
1,893
247,763
2018-02-22 12:10:52
4,015,784
15
2010-10-25 14:53:49
8,718
2010-10-25 14:53:49
https://stackoverflow.com/q/3984001
https://stackoverflow.com/a/4015784
<p>You probably need to update to the latest mercurial (1.6.4). Version 1.5.4 in particular didn't do win32 color properly (and there have been quite a few color-related and win32-related bugs fixed in recent builds).</p> <p>You also need to make sure you're not specifying ANSI color mode. You can force win32:</p> <...
<p>You probably need to update to the latest mercurial (1.6.4). Version 1.5.4 in particular didn't do win32 color properly (and there have been quite a few color-related and win32-related bugs fixed in recent builds).</p> <p>You also need to make sure you're not specifying ANSI color mode. You can force win32:</p> <...
64, 526, 802, 3346
dvcs, mercurial, powershell, windows
<h1>Mercurial color extension in Windows Powershell</h1> <p>Is there a way to enable color support for Mercurial in Powershell on Windows 7? The <a href="https://www.mercurial-scm.org/wiki/ColorExtension" rel="nofollow noreferrer">ColorExtension</a> page says to add</p> <pre><code>[color] mode = win32 </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,126
bash
# Mercurial color extension in Windows Powershell Is there a way to enable color support for Mercurial in Powershell on Windows 7? The [ColorExtension](https://www.mercurial-scm.org/wiki/ColorExtension) page says to add ``` [color] mode = win32 ``` to your `.hgrc` file, but it doesn't seem to make a difference. Run...
You probably need to update to the latest mercurial (1.6.4). Version 1.5.4 in particular didn't do win32 color properly (and there have been quite a few color-related and win32-related bugs fixed in recent builds). You also need to make sure you're not specifying ANSI color mode. You can force win32: ``` [color] mode...
2193231
Display function definition in interactive shell
16
2010-02-03 15:55:06
<p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. ...
25,177
245,029
2022-06-30 08:24:56
2,193,342
15
2010-02-03 16:07:04
95,810
2010-02-03 16:07:04
https://stackoverflow.com/q/2193231
https://stackoverflow.com/a/2193342
<p>No, <code>__code__</code> and <code>func_code</code> are references to the compiled bytecode -- you can disassemble them (see <code>dis.dis</code>) but not get back to the Python source code.</p> <p>Alas, the source code is simply gone, not remembered anywhere...:</p> <pre><code>&gt;&gt;&gt; import inspect &gt;&gt...
<p>No, <code>__code__</code> and <code>func_code</code> are references to the compiled bytecode -- you can disassemble them (see <code>dis.dis</code>) but not get back to the Python source code.</p> <p>Alas, the source code is simply gone, not remembered anywhere...:</p> <pre><code>&gt;&gt;&gt; import inspect &gt;&gt...
16, 390
python, shell
<h1>Display function definition in interactive shell</h1> <p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline functio...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,127
bash
# Display function definition in interactive shell I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the ...
No, `__code__` and `func_code` are references to the compiled bytecode -- you can disassemble them (see `dis.dis`) but not get back to the Python source code. Alas, the source code is simply gone, not remembered anywhere...: ``` >>> import inspect >>> def f(): ... print 'ciao' ... >>> inspect.getsource(f) Tracebac...
1199931
How to expand a CMD shell variable twice (recursively)
16
2009-07-29 12:33:53
<p>Using the Windows XP CMD command-line I can expand a variable twice as follows:</p> <pre><code>set AAA=BBB set BBB=CCC for /F "usebackq tokens=*" %i in (`echo %%AAA%%`) do echo %i </code></pre> <p>will echo <code>CCC</code>. I.e. <code>AAA</code> has been expanded to the string <code>BBB</code>, and then the varia...
16,117
84,538
2019-03-06 00:22:26
1,200,871
15
2009-07-29 14:54:12
103,043
2009-07-30 13:06:12
https://stackoverflow.com/q/1199931
https://stackoverflow.com/a/1200871
<p>Thinking in terms of a less tortuous solution, this, too, produces the <code>CCC</code> you desire.</p> <pre><code>setlocal enabledelayedexpansion set AAA=BBB set BBB=CCC for /F %%a in ('echo %AAA%') do echo !%%a! </code></pre> <p><strong>edit:</strong></p> <p>to dissect this answer:</p> <p><code>setlocal enab...
<p>Thinking in terms of a less tortuous solution, this, too, produces the <code>CCC</code> you desire.</p> <pre><code>setlocal enabledelayedexpansion set AAA=BBB set BBB=CCC for /F %%a in ('echo %AAA%') do echo !%%a! </code></pre> <p><strong>edit:</strong></p> <p>to dissect this answer:</p> <p><code>setlocal enab...
64, 390, 531, 2631, 7002
batch-file, cmd, scripting, shell, windows
<h1>How to expand a CMD shell variable twice (recursively)</h1> <p>Using the Windows XP CMD command-line I can expand a variable twice as follows:</p> <pre><code>set AAA=BBB set BBB=CCC for /F "usebackq tokens=*" %i in (`echo %%AAA%%`) do echo %i </code></pre> <p>will echo <code>CCC</code>. I.e. <code>AAA</code> has ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,128
bash
# How to expand a CMD shell variable twice (recursively) Using the Windows XP CMD command-line I can expand a variable twice as follows: ``` set AAA=BBB set BBB=CCC for /F "usebackq tokens=*" %i in (`echo %%AAA%%`) do echo %i ``` will echo `CCC`. I.e. `AAA` has been expanded to the string `BBB`, and then the variabl...
Thinking in terms of a less tortuous solution, this, too, produces the `CCC` you desire. ``` setlocal enabledelayedexpansion set AAA=BBB set BBB=CCC for /F %%a in ('echo %AAA%') do echo !%%a! ``` **edit:** to dissect this answer: `setlocal enabledelayedexpansion` - this will allow for any environment variable set...
46061694
bash: Why can't I set a trap for SIGINT in a background shell?
15
2017-09-05 19:01:24
<p>Here's a simple program that registers two <code>trap</code> handlers and then displays them with <code>trap -p</code>. Then it does the same thing, but in a child background process.</p> <p>Why does the background process ignore the <code>SIGINT</code> trap?</p> <pre class="lang-bash prettyprint-override"><code>...
1,557
162,094
2022-05-26 21:58:47
46,061,734
15
2017-09-05 19:04:21
1,084,774
2022-05-26 21:58:47
https://stackoverflow.com/q/46061694
https://stackoverflow.com/a/46061734
<p><code>SIGINT</code> and <code>SIGQUIT</code> are ignored in backgrounded processes (unless they're backgrounded with <code>set -m</code> on). It's a (weird) POSIX requirement (see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html" rel="nofollow noreferrer"> 2. Shell Command Language</...
<p><code>SIGINT</code> and <code>SIGQUIT</code> are ignored in backgrounded processes (unless they're backgrounded with <code>set -m</code> on). It's a (weird) POSIX requirement (see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html" rel="nofollow noreferrer"> 2. Shell Command Language</...
387, 2481, 25657, 26115, 124485
bash, bash-trap, child-process, sigint, signals
<h1>bash: Why can't I set a trap for SIGINT in a background shell?</h1> <p>Here's a simple program that registers two <code>trap</code> handlers and then displays them with <code>trap -p</code>. Then it does the same thing, but in a child background process.</p> <p>Why does the background process ignore the <code>SIG...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,129
bash
# bash: Why can't I set a trap for SIGINT in a background shell? Here's a simple program that registers two `trap` handlers and then displays them with `trap -p`. Then it does the same thing, but in a child background process. Why does the background process ignore the `SIGINT` trap? ``` #!/bin/bash echo "Traps on ...
`SIGINT` and `SIGQUIT` are ignored in backgrounded processes (unless they're backgrounded with `set -m` on). It's a (weird) POSIX requirement (see [2. Shell Command Language](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) or my SO question [Why do shells ignore SIGINT and SIGQUIT in backgroun...
45999187
Creating filename_$(date %Y-%m-%d) from systemd bash inline script
15
2017-09-01 11:21:25
<p>I am trying to execute a <code>systemd</code> timer and would like to keep the output from the executed script in a file per date. Here is my <code>ExecStart</code> script in the <code>.service</code> file:</p> <pre><code>ExecStart=/bin/bash -c 'echo $(date +%Y-%m-%d) &gt;&gt; /home/username/test_output_$(date +%Y-...
14,215
5,211,086
2017-09-01 14:01:48
46,001,754
15
2017-09-01 13:53:56
1,312,096
2017-09-01 14:01:48
https://stackoverflow.com/q/45999187
https://stackoverflow.com/a/46001754
<p>You'll need to escape the <strong>$</strong> and <strong>%</strong> signs, by doubling them both in order to make this work.</p> <p>As described here:</p> <ul> <li><a href="https://github.com/systemd/systemd/issues/2146" rel="noreferrer">https://github.com/systemd/systemd/issues/2146</a></li> <li><a href="https://...
<p>You'll need to escape the <strong>$</strong> and <strong>%</strong> signs, by doubling them both in order to make this work.</p> <p>As described here:</p> <ul> <li><a href="https://github.com/systemd/systemd/issues/2146" rel="noreferrer">https://github.com/systemd/systemd/issues/2146</a></li> <li><a href="https://...
58, 387, 4847, 5002, 81442
bash, date, inline, linux, systemd
<h1>Creating filename_$(date %Y-%m-%d) from systemd bash inline script</h1> <p>I am trying to execute a <code>systemd</code> timer and would like to keep the output from the executed script in a file per date. Here is my <code>ExecStart</code> script in the <code>.service</code> file:</p> <pre><code>ExecStart=/bin/bas...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,130
bash
# Creating filename_$(date %Y-%m-%d) from systemd bash inline script I am trying to execute a `systemd` timer and would like to keep the output from the executed script in a file per date. Here is my `ExecStart` script in the `.service` file: ``` ExecStart=/bin/bash -c 'echo $(date +%Y-%m-%d) >> /home/username/test_o...
You'll need to escape the **$** and **%** signs, by doubling them both in order to make this work. As described here: - <https://github.com/systemd/systemd/issues/2146> - <https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines> > To pass a literal dollar sign, use "$$" ``` ExecStart=/...
44343562
What is the difference between Shell and ShellEx in Windows Registry?
15
2017-06-03 11:45:35
<p>I'm trying to add a custom context menu in windows registry, I found a shell key and shellex key that seems to both work the same thing? Why is there 2 and what are they for?</p>
13,507
245,904
2017-06-03 13:18:50
44,344,378
15
2017-06-03 13:18:50
3,501
2017-06-03 13:18:50
https://stackoverflow.com/q/44343562
https://stackoverflow.com/a/44344378
<p>The <code>Shell</code> key is for <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc144175(v=vs.85).aspx" rel="noreferrer">static verbs</a> used by <code>ShellExecute</code> and file-type context menus. They are simple to implement because they are just a string that specifies the command. They can...
<p>The <code>Shell</code> key is for <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc144175(v=vs.85).aspx" rel="noreferrer">static verbs</a> used by <code>ShellExecute</code> and file-type context menus. They are simple to implement because they are just a string that specifies the command. They can...
64, 263, 7839
registry, shellexecute, windows
<h1>What is the difference between Shell and ShellEx in Windows Registry?</h1> <p>I'm trying to add a custom context menu in windows registry, I found a shell key and shellex key that seems to both work the same thing? Why is there 2 and what are they for?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,131
bash
# What is the difference between Shell and ShellEx in Windows Registry? I'm trying to add a custom context menu in windows registry, I found a shell key and shellex key that seems to both work the same thing? Why is there 2 and what are they for?
The `Shell` key is for [static verbs](https://msdn.microsoft.com/en-us/library/windows/desktop/cc144175(v=vs.85).aspx) used by `ShellExecute` and file-type context menus. They are simple to implement because they are just a string that specifies the command. They can be extended with optional COM objects (DropTarget et...
39497196
missing end to balance this if statement
15
2016-09-14 18:23:44
<p>i try to add this lines to my .bash-profile </p> <pre><code>if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ];then source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" fi </code></pre> <p>but I get this error</p> <pre><code>Missing end to balance this if statement .bash_profile (lin...
17,464
5,550,399
2016-09-14 18:37:26
39,497,441
15
2016-09-14 18:37:26
1,126,841
2016-09-14 18:37:26
https://stackoverflow.com/q/39497196
https://stackoverflow.com/a/39497441
<p>Although the linked repository contains a script for <code>fish</code>, the README does not provide any directions for how to <em>use</em> that script. Not having used <code>fish</code> in several years, I <em>think</em> what you want to do is add</p> <pre><code>if status --is-login source (brew --prefix)"/opt/ba...
<p>Although the linked repository contains a script for <code>fish</code>, the README does not provide any directions for how to <em>use</em> that script. Not having used <code>fish</code> in several years, I <em>think</em> what you want to do is add</p> <pre><code>if status --is-login source (brew --prefix)"/opt/ba...
34, 119, 387, 390, 55824
bash, fish, git, shell, unix
<h1>missing end to balance this if statement</h1> <p>i try to add this lines to my .bash-profile </p> <pre><code>if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ];then source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" fi </code></pre> <p>but I get this error</p> <pre><code>Missing e...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,132
bash
# missing end to balance this if statement i try to add this lines to my .bash-profile ``` if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ];then source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" fi ``` but I get this error ``` Missing end to balance this if statement .bash_profile...
Although the linked repository contains a script for `fish`, the README does not provide any directions for how to *use* that script. Not having used `fish` in several years, I *think* what you want to do is add ``` if status --is-login source (brew --prefix)"/opt/bash-git-prompt/share/gitprompt.fish" end ``` to `~...
33038848
How to exclude non-valued object properties when converting to JSON in Powershell
15
2015-10-09 12:55:04
<p>I have a piece of code that works but I want to know if there is a better way to do it. I could not find anything related so far. Here are the facts:</p> <ul> <li>I have an object with n properties.</li> <li>I want to convert this object to JSON using (ConvertTo-Json).</li> <li>I don't want to include in the JSON t...
14,950
2,878,438
2023-10-14 19:30:41
33,039,561
15
2015-10-09 13:28:41
4,424,236
2015-10-09 13:28:41
https://stackoverflow.com/q/33038848
https://stackoverflow.com/a/33039561
<p>Something like this?</p> <pre><code>$object = New-Object PSObject Add-Member -InputObject $object -MemberType NoteProperty -Name TableName -Value "MyTable" Add-Member -InputObject $object -MemberType NoteProperty -Name Description -Value "Lorem ipsum dolor.." Add-Member -InputObject $object -MemberType NotePropert...
<p>Something like this?</p> <pre><code>$object = New-Object PSObject Add-Member -InputObject $object -MemberType NoteProperty -Name TableName -Value "MyTable" Add-Member -InputObject $object -MemberType NoteProperty -Name Description -Value "Lorem ipsum dolor.." Add-Member -InputObject $object -MemberType NotePropert...
526, 1508, 95686
json, powershell, powershell-4.0
<h1>How to exclude non-valued object properties when converting to JSON in Powershell</h1> <p>I have a piece of code that works but I want to know if there is a better way to do it. I could not find anything related so far. Here are the facts:</p> <ul> <li>I have an object with n properties.</li> <li>I want to convert...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,133
bash
# How to exclude non-valued object properties when converting to JSON in Powershell I have a piece of code that works but I want to know if there is a better way to do it. I could not find anything related so far. Here are the facts: - I have an object with n properties. - I want to convert this object to JSON using ...
Something like this? ``` $object = New-Object PSObject Add-Member -InputObject $object -MemberType NoteProperty -Name TableName -Value "MyTable" Add-Member -InputObject $object -MemberType NoteProperty -Name Description -Value "Lorem ipsum dolor.." Add-Member -InputObject $object -MemberType NoteProperty -Name AppAre...
32761627
Bash: How can I grep a line for multiple instances of the same string?
15
2015-09-24 12:42:03
<p>I've got several lines that look like this:</p> <pre><code>aaaaaaaaxzaaaaaaaaaaaaaa bbbbbbbbbbbbxzbbbbbbxzbb ccxzcccccccccccccccccxzc dddddddxzddddddddddddddd </code></pre> <p>Inside two of those lines, there are <strong>two</strong> instances of <code>xz</code> characters. I want grep to look for <code>xz</code> ...
22,360
2,541,806
2015-09-24 13:05:16
32,761,714
15
2015-09-24 12:46:09
3,832,970
2015-09-24 13:05:16
https://stackoverflow.com/q/32761627
https://stackoverflow.com/a/32761714
<p>You can use </p> <pre><code>cat lines | grep 'xz.*xz' </code></pre> <p>Or just </p> <pre><code>grep 'xz.*xz' lines </code></pre> <p>The <code>.*</code> will match optional characters (any but a newline) between 2 <code>xz</code>.</p> <p>In case you need to use look-arounds, you will need <code>-P</code> switch...
<p>You can use </p> <pre><code>cat lines | grep 'xz.*xz' </code></pre> <p>Or just </p> <pre><code>grep 'xz.*xz' lines </code></pre> <p>The <code>.*</code> will match optional characters (any but a newline) between 2 <code>xz</code>.</p> <p>In case you need to use look-arounds, you will need <code>-P</code> switch...
18, 387, 1271
bash, grep, regex
<h1>Bash: How can I grep a line for multiple instances of the same string?</h1> <p>I've got several lines that look like this:</p> <pre><code>aaaaaaaaxzaaaaaaaaaaaaaa bbbbbbbbbbbbxzbbbbbbxzbb ccxzcccccccccccccccccxzc dddddddxzddddddddddddddd </code></pre> <p>Inside two of those lines, there are <strong>two</strong> i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,134
bash
# Bash: How can I grep a line for multiple instances of the same string? I've got several lines that look like this: ``` aaaaaaaaxzaaaaaaaaaaaaaa bbbbbbbbbbbbxzbbbbbbxzbb ccxzcccccccccccccccccxzc dddddddxzddddddddddddddd ``` Inside two of those lines, there are **two** instances of `xz` characters. I want grep to lo...
You can use ``` cat lines | grep 'xz.*xz' ``` Or just ``` grep 'xz.*xz' lines ``` The `.*` will match optional characters (any but a newline) between 2 `xz`. In case you need to use look-arounds, you will need `-P` switch to enable Perl-like regexps.
29986413
GPG key exists in the list?
15
2015-05-01 11:57:12
<p>I want to create a shell script and I haven't worked with it before. There is a command for gpg:</p> <pre><code>gpg --keyserver SERVER --recv-keys KEY </code></pre> <p>The problem is that I don't want to run this command if key has been already added. Is there any method to check that key exists in keys list? Th...
12,241
1,236,038
2022-02-27 23:20:04
29,986,943
15
2015-05-01 12:35:28
695,343
2015-05-01 12:35:28
https://stackoverflow.com/q/29986413
https://stackoverflow.com/a/29986943
<p>Run <code>gpg --list-keys [key-id]</code> (or the abbreviated command <code>-k</code>), which will have a return code of 0 (success) if a matching key exists, or something else (failure) otherwise. Don't list all keys and <code>grep</code> afterwards as proposed by others in the comments, this will get <em>horribly<...
<p>Run <code>gpg --list-keys [key-id]</code> (or the abbreviated command <code>-k</code>), which will have a return code of 0 (success) if a matching key exists, or something else (failure) otherwise. Don't list all keys and <code>grep</code> afterwards as proposed by others in the comments, this will get <em>horribly<...
387, 390, 6735
bash, gnupg, shell
<h1>GPG key exists in the list?</h1> <p>I want to create a shell script and I haven't worked with it before. There is a command for gpg:</p> <pre><code>gpg --keyserver SERVER --recv-keys KEY </code></pre> <p>The problem is that I don't want to run this command if key has been already added. Is there any method to c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,135
bash
# GPG key exists in the list? I want to create a shell script and I haven't worked with it before. There is a command for gpg: ``` gpg --keyserver SERVER --recv-keys KEY ``` The problem is that I don't want to run this command if key has been already added. Is there any method to check that key exists in keys list?...
Run `gpg --list-keys [key-id]` (or the abbreviated command `-k`), which will have a return code of 0 (success) if a matching key exists, or something else (failure) otherwise. Don't list all keys and `grep` afterwards as proposed by others in the comments, this will get *horribly* slow for larger numbers of keys in the...
20528282
how to update homebrew with Cron on Mac os
15
2013-12-11 19:31:09
<p>I've been discvering some long lasting linux techs to help automate my daily work. I found <code>cron</code> to be very powerful if I can use it to check the updates of some packages I have on my system. </p> <p>For example, I want to update my <code>Homebrew</code> everyday at 11pm. What I did is, with <code>sudo ...
10,040
1,610,143
2020-03-17 18:04:40
25,639,070
15
2014-09-03 07:52:54
517,914
2020-03-17 18:04:40
https://stackoverflow.com/q/20528282
https://stackoverflow.com/a/25639070
<p>A cronjob is a good option, but I didn't want it to happen automatically. I found a <a href="http://chrisstreeter.com/archive/2012/08/homebrew-package-update-notifications-on-mountain-lion.html" rel="noreferrer">script</a> that will notify you if a new version of a formula installed on your Mac is available. </p> <...
<p>A cronjob is a good option, but I didn't want it to happen automatically. I found a <a href="http://chrisstreeter.com/archive/2012/08/homebrew-package-update-notifications-on-mountain-lion.html" rel="noreferrer">script</a> that will notify you if a new version of a formula installed on your Mac is available. </p> <...
58, 369, 387, 601
bash, cron, linux, macos
<h1>how to update homebrew with Cron on Mac os</h1> <p>I've been discvering some long lasting linux techs to help automate my daily work. I found <code>cron</code> to be very powerful if I can use it to check the updates of some packages I have on my system. </p> <p>For example, I want to update my <code>Homebrew</cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,136
bash
# how to update homebrew with Cron on Mac os I've been discvering some long lasting linux techs to help automate my daily work. I found `cron` to be very powerful if I can use it to check the updates of some packages I have on my system. For example, I want to update my `Homebrew` everyday at 11pm. What I did is, wit...
A cronjob is a good option, but I didn't want it to happen automatically. I found a [script](http://chrisstreeter.com/archive/2012/08/homebrew-package-update-notifications-on-mountain-lion.html) that will notify you if a new version of a formula installed on your Mac is available. I extended the [script](https://gist....
20850289
Comparing two json files : shell scripting
15
2013-12-31 01:22:30
<p>I'm comparing two json files which look like:</p> <pre><code>[ { &quot;type&quot; : 1, &quot;children&quot; : { &quot;nsubj&quot; : { &quot;role&quot; : &quot;topic&quot;, &quot;POS&quot; : [ &quot;noun&quot; ] } }, &quot...
28,668
2,626,221
2025-09-03 13:22:30
20,850,306
15
2013-12-31 01:24:28
220,700
2013-12-31 01:24:28
https://stackoverflow.com/q/20850289
https://stackoverflow.com/a/20850306
<p>Just use diff. Like in</p> <pre><code>diff --unified file1.json file2.json </code></pre>
<p>Just use diff. Like in</p> <pre><code>diff --unified file1.json file2.json </code></pre>
390, 606, 1508, 105170
diff, jq, json, shell
<h1>Comparing two json files : shell scripting</h1> <p>I'm comparing two json files which look like:</p> <pre><code>[ { &quot;type&quot; : 1, &quot;children&quot; : { &quot;nsubj&quot; : { &quot;role&quot; : &quot;topic&quot;, &quot;POS&quot; : [ &quot;noun...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,137
bash
# Comparing two json files : shell scripting I'm comparing two json files which look like: ``` [ { "type" : 1, "children" : { "nsubj" : { "role" : "topic", "POS" : [ "noun" ] } }, "role" : "vehicle", "POS" : [ ...
Just use diff. Like in ``` diff --unified file1.json file2.json ```
18607788
How to distinguish between empty argument and zero-value argument in Powershell?
15
2013-09-04 07:23:42
<p>I want to be able to pass a single int through to a powershell script, and be able to tell when no variable is passed. My understanding was that the following should identify whether an argument is null or not:</p> <pre><code>if (!$args[0]) { Write-Host "Null" } else { Write-Host "Not null" } </code></pre> <p>Thi...
30,992
758,231
2024-10-07 04:24:39
18,607,991
15
2013-09-04 07:35:37
608,772
2024-10-07 04:24:39
https://stackoverflow.com/q/18607788
https://stackoverflow.com/a/18607991
<p>You can just test <code>$args</code> variable or <code>$args.count</code> to see how many vars are passed to the script.</p> <p>Another thing : <code>$args[0] -eq $null</code> is different from <code>$args[0] -eq 0</code> and from <code>!$args[0]</code>.</p> <ol> <li><strong>$args[0] -eq $null</strong> : This chec...
<p>You can just test <code>$args</code> variable or <code>$args.count</code> to see how many vars are passed to the script.</p> <p>Another thing : <code>$args[0] -eq $null</code> is different from <code>$args[0] -eq 0</code> and from <code>!$args[0]</code>.</p> <ol> <li><strong>$args[0] -eq $null</strong> : This chec...
526, 694, 2773, 15517
if-statement, null, powershell, zero
<h1>How to distinguish between empty argument and zero-value argument in Powershell?</h1> <p>I want to be able to pass a single int through to a powershell script, and be able to tell when no variable is passed. My understanding was that the following should identify whether an argument is null or not:</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,138
bash
# How to distinguish between empty argument and zero-value argument in Powershell? I want to be able to pass a single int through to a powershell script, and be able to tell when no variable is passed. My understanding was that the following should identify whether an argument is null or not: ``` if (!$args[0]) { Wri...
You can just test `$args` variable or `$args.count` to see how many vars are passed to the script. Another thing : `$args[0] -eq $null` is different from `$args[0] -eq 0` and from `!$args[0]`. 1. **$args[0] -eq $null** : This checks if the first argument in the $args array is equal to $null. If $args[0] is $null, it ...
18344551
Move file as root preserving ownership linux
15
2013-08-20 20:39:30
<p>OS: Debian. I want to be able to move files and folders around as root and from the command line without changing it's owner and group. Is this possible? </p>
45,354
1,955,740
2013-08-20 20:49:42
18,344,595
15
2013-08-20 20:42:09
986,485
2013-08-20 20:42:09
https://stackoverflow.com/q/18344551
https://stackoverflow.com/a/18344595
<p>rsync :</p> <pre><code> -A, --acls preserve ACLs (implies --perms) -X, --xattrs preserve extended attributes -o, --owner preserve owner (super-user only) -g, --group preserve group --devices preserve device files (super-user only)...
<p>rsync :</p> <pre><code> -A, --acls preserve ACLs (implies --perms) -X, --xattrs preserve extended attributes -o, --owner preserve owner (super-user only) -g, --group preserve group --devices preserve device files (super-user only)...
58, 390, 391, 1231, 1796
command, command-line, linux, shell, terminal
<h1>Move file as root preserving ownership linux</h1> <p>OS: Debian. I want to be able to move files and folders around as root and from the command line without changing it's owner and group. Is this possible? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,139
bash
# Move file as root preserving ownership linux OS: Debian. I want to be able to move files and folders around as root and from the command line without changing it's owner and group. Is this possible?
rsync : ``` -A, --acls preserve ACLs (implies --perms) -X, --xattrs preserve extended attributes -o, --owner preserve owner (super-user only) -g, --group preserve group --devices preserve device files (super-user only) --specia...
17548854
Difference between Mac `find` and Linux `find`
15
2013-07-09 13:01:55
<p>I have inherited a script as part of a build process for an application, and when I run it on the build server (Ubuntu Precise) it runs fine, but when I run it on my mac I get "illegal option -- t". The command that has problems is simple, it's just a call to <code>find</code>:</p> <pre><code>find -type f -not -pat...
8,794
907,981
2013-07-09 13:08:02
17,548,983
15
2013-07-09 13:08:02
2,235,132
2013-07-09 13:08:02
https://stackoverflow.com/q/17548854
https://stackoverflow.com/a/17548983
<p>The <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html" rel="noreferrer">standard</a> mandates the path (<code>./</code> in your example) to be mandatory. <code>find</code> on MacOS follows the standard.</p> <p><code>GNU find</code> (the one available on Linux) allows the path to be optio...
<p>The <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html" rel="noreferrer">standard</a> mandates the path (<code>./</code> in your example) to be mandatory. <code>find</code> on MacOS follows the standard.</p> <p><code>GNU find</code> (the one available on Linux) allows the path to be optio...
34, 369, 390, 10193
find, macos, shell, unix
<h1>Difference between Mac `find` and Linux `find`</h1> <p>I have inherited a script as part of a build process for an application, and when I run it on the build server (Ubuntu Precise) it runs fine, but when I run it on my mac I get "illegal option -- t". The command that has problems is simple, it's just a call to <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,140
bash
# Difference between Mac `find` and Linux `find` I have inherited a script as part of a build process for an application, and when I run it on the build server (Ubuntu Precise) it runs fine, but when I run it on my mac I get "illegal option -- t". The command that has problems is simple, it's just a call to `find`: `...
The [standard](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html) mandates the path (`./` in your example) to be mandatory. `find` on MacOS follows the standard. `GNU find` (the one available on Linux) allows the path to be optional. If not specified, the current directory is assumed to be the path. ...
8794645
MongoDB remove GridFS objects from shell
15
2012-01-09 20:20:34
<p>I have files stored in a MongoDB using GridFS. I need to remove some of those files by ID, from the JavaScript shell. I need to remove a single file using it's ID. I figured I could just do this:</p> <pre><code>db.fs.files.remove({_id: my_id}); </code></pre> <p>This works to some extent; it removes the file from t...
20,082
104,999
2019-03-04 16:40:39
8,794,871
15
2012-01-09 20:37:47
683,201
2012-01-09 21:40:39
https://stackoverflow.com/q/8794645
https://stackoverflow.com/a/8794871
<p>You want to use <code>db.fs.delete(_id);</code> instead.</p> <p><strong>Update</strong> Sorry, that apparently doesn't work from the shell, only through the driver. GridFS is a specification for storage implemented by the drivers. Looks like it doesn't have much built-in functionality from the shell, as such.</p> ...
<p>You want to use <code>db.fs.delete(_id);</code> instead.</p> <p><strong>Update</strong> Sorry, that apparently doesn't work from the shell, only through the driver. GridFS is a specification for storage implemented by the drivers. Looks like it doesn't have much built-in functionality from the shell, as such.</p> ...
3, 390, 30073, 51700
gridfs, javascript, mongodb, shell
<h1>MongoDB remove GridFS objects from shell</h1> <p>I have files stored in a MongoDB using GridFS. I need to remove some of those files by ID, from the JavaScript shell. I need to remove a single file using it's ID. I figured I could just do this:</p> <pre><code>db.fs.files.remove({_id: my_id}); </code></pre> <p>Thi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,141
bash
# MongoDB remove GridFS objects from shell I have files stored in a MongoDB using GridFS. I need to remove some of those files by ID, from the JavaScript shell. I need to remove a single file using it's ID. I figured I could just do this: ``` db.fs.files.remove({_id: my_id}); ``` This works to some extent; it remove...
You want to use `db.fs.delete(_id);` instead. **Update** Sorry, that apparently doesn't work from the shell, only through the driver. GridFS is a specification for storage implemented by the drivers. Looks like it doesn't have much built-in functionality from the shell, as such. **Update 2** There is also a command l...
7728444
Programmatically change the Windows Shell
15
2011-10-11 15:22:33
<p>I'm working on a project that will be "embedded" into a Windows 7 system, this is going to be achieved by disabling task manager and changing the windows shell to the application, as well as other things.</p> <p>What I'm looking to do here is programmatically change the Windows shell between the application and exp...
4,473
989,766
2014-04-28 01:13:57
7,741,917
15
2011-10-12 14:44:36
989,766
2011-10-12 15:46:02
https://stackoverflow.com/q/7728444
https://stackoverflow.com/a/7741917
<p>After much searching of other locations on the net, I have finally got the Shell to change to the executable file of the application that is being built.</p> <p>The "Embedding" process is a three step process, in the case of the software I'm working on, we start by disabling Task Manager, We then set the shell exec...
<p>After much searching of other locations on the net, I have finally got the Shell to change to the executable file of the application that is being built.</p> <p>The "Embedding" process is a three step process, in the case of the software I'm working on, we start by disabling Task Manager, We then set the shell exec...
9, 64, 263, 390
c#, registry, shell, windows
<h1>Programmatically change the Windows Shell</h1> <p>I'm working on a project that will be "embedded" into a Windows 7 system, this is going to be achieved by disabling task manager and changing the windows shell to the application, as well as other things.</p> <p>What I'm looking to do here is programmatically chang...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,142
bash
# Programmatically change the Windows Shell I'm working on a project that will be "embedded" into a Windows 7 system, this is going to be achieved by disabling task manager and changing the windows shell to the application, as well as other things. What I'm looking to do here is programmatically change the Windows sh...
After much searching of other locations on the net, I have finally got the Shell to change to the executable file of the application that is being built. The "Embedding" process is a three step process, in the case of the software I'm working on, we start by disabling Task Manager, We then set the shell executable in ...
3997303
How to attach a file to an email with PowerShell
15
2010-10-22 13:35:29
<p>I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong?</p> <pre><code>$ol = New-Object -comObject Outlook.Application $message = $ol.CreateItem(0) $message.Recipients.Add("Deploy...
146,977
409,119
2024-06-13 14:37:23
4,067,730
15
2010-11-01 09:24:35
409,119
2010-11-01 09:55:27
https://stackoverflow.com/q/3997303
https://stackoverflow.com/a/4067730
<p>I got the above to work by removing the line</p> <pre><code>$attachment = new-object System.Net.Mail.Attachment $file </code></pre> <p>and changing </p> <pre><code>$message.Attachments.Add($attachment) </code></pre> <p>to </p> <pre><code>$message.Attachments.Add($file) </code></pre> <p>While the solution provi...
<p>I got the above to work by removing the line</p> <pre><code>$attachment = new-object System.Net.Mail.Attachment $file </code></pre> <p>and changing </p> <pre><code>$message.Attachments.Add($attachment) </code></pre> <p>to </p> <pre><code>$message.Attachments.Add($file) </code></pre> <p>While the solution provi...
146, 526, 6166, 24067
attachment, email, powershell, powershell-2.0
<h1>How to attach a file to an email with PowerShell</h1> <p>I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong?</p> <pre><code>$ol = New-Object -comObject Outlook.Application $m...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,143
bash
# How to attach a file to an email with PowerShell I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong? ``` $ol = New-Object -comObject Outlook.Application $message = $ol.CreateI...
I got the above to work by removing the line ``` $attachment = new-object System.Net.Mail.Attachment $file ``` and changing ``` $message.Attachments.Add($attachment) ``` to ``` $message.Attachments.Add($file) ``` While the solution provided by @Keith Hill would be better, even with a lot of goggling I couldn't ge...
2524937
How to send a signal SIGINT from script to script?
15
2010-03-26 16:32:57
<p>I want to trap a signal send from Script-A.sh to Script-B.sh so in Script-A.sh i use the command:</p> <blockquote> <p>(Send SIGINT to Script-B.sh)<br> kill -2 $PID_Script-B.sh </p> </blockquote> <p>And in Script-B.sh i catch the signal and call function Clean</p> <blockquote> <p>trap 'Clean' 2 </p> </bloc...
18,747
276,285
2019-08-09 01:38:21
2,527,268
15
2010-03-26 22:47:44
26,428
2016-07-19 21:48:51
https://stackoverflow.com/q/2524937
https://stackoverflow.com/a/2527268
<p>I was able to reproduce the behavior you report. My hypothesis is that since the script is running <strong><em>from</em></strong> a non-interactive shell (as a child of a script) that <code>SIGINT</code>, which is a keyboard signal, is ignored.</p> <p>From <code>info bash</code>:</p> <blockquote> <p>Background p...
<p>I was able to reproduce the behavior you report. My hypothesis is that since the script is running <strong><em>from</em></strong> a non-interactive shell (as a child of a script) that <code>SIGINT</code>, which is a keyboard signal, is ignored.</p> <p>From <code>info bash</code>:</p> <blockquote> <p>Background p...
387, 2481, 5779, 124485
bash, bash-trap, kill, signals
<h1>How to send a signal SIGINT from script to script?</h1> <p>I want to trap a signal send from Script-A.sh to Script-B.sh so in Script-A.sh i use the command:</p> <blockquote> <p>(Send SIGINT to Script-B.sh)<br> kill -2 $PID_Script-B.sh </p> </blockquote> <p>And in Script-B.sh i catch the signal and call funct...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,144
bash
# How to send a signal SIGINT from script to script? I want to trap a signal send from Script-A.sh to Script-B.sh so in Script-A.sh i use the command: > (Send SIGINT to Script-B.sh) > kill -2 $PID_Script-B.sh And in Script-B.sh i catch the signal and call function Clean > trap 'Clean' 2 It does not work, instead...
I was able to reproduce the behavior you report. My hypothesis is that since the script is running ***from*** a non-interactive shell (as a child of a script) that `SIGINT`, which is a keyboard signal, is ignored. From `info bash`: > Background processes are those whose process group ID differs from the > terminal's;...
1506902
Why do processes spawned by cron end up defunct?
15
2009-10-01 22:45:18
<p>I have some processes showing up as <code>&lt;defunct&gt;</code> in <code>top</code> (and <code>ps</code>). I've boiled things down from the real scripts and programs.</p> <p>In my <code>crontab</code>:</p> <pre><code>* * * * * /tmp/launcher.sh /tmp/tester.sh </code></pre> <p>The contents of <code>launcher.sh</c...
32,512
4,323
2021-02-23 20:49:51
1,506,914
15
2009-10-01 22:48:58
140,740
2009-10-02 21:48:22
https://stackoverflow.com/q/1506902
https://stackoverflow.com/a/1506914
<p>Because they haven't been the subject of a <code>wait(2)</code> system call.</p> <p>Since someone may wait for these processes in the future, the kernel can't completely get rid of them or it won't be able to execute the <code>wait</code> system call because it won't have the exit status or evidence of its existenc...
<p>Because they haven't been the subject of a <code>wait(2)</code> system call.</p> <p>Since someone may wait for these processes in the future, the kernel can't completely get rid of them or it won't be able to execute the <code>wait</code> system call because it won't have the exit status or evidence of its existenc...
387, 601, 2827, 17776, 40425
background, bash, cron, defunct, zombie-process
<h1>Why do processes spawned by cron end up defunct?</h1> <p>I have some processes showing up as <code>&lt;defunct&gt;</code> in <code>top</code> (and <code>ps</code>). I've boiled things down from the real scripts and programs.</p> <p>In my <code>crontab</code>:</p> <pre><code>* * * * * /tmp/launcher.sh /tmp/tester...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,145
bash
# Why do processes spawned by cron end up defunct? I have some processes showing up as `<defunct>` in `top` (and `ps`). I've boiled things down from the real scripts and programs. In my `crontab`: ``` * * * * * /tmp/launcher.sh /tmp/tester.sh ``` The contents of `launcher.sh` (which is of course marked executable):...
Because they haven't been the subject of a `wait(2)` system call. Since someone may wait for these processes in the future, the kernel can't completely get rid of them or it won't be able to execute the `wait` system call because it won't have the exit status or evidence of its existence any more. When you start one ...
49818161
Can't Install ARCore Emulator for Android Studio
14
2018-04-13 13:26:48
<p>I don't know if I'm allowed to ask this question but I really can't figure out how to use ARCore on Android Emulated Device. According to the official guide I'm supposed to use API 8.1 on pixel/pixel 2 device in order to run any app which uses ARCore. Sadly those emulator don't come with the support for Play Store, ...
9,644
7,362,273
2023-05-11 08:12:41
55,567,156
15
2019-04-08 06:08:29
6,599,590
2023-05-11 08:12:41
https://stackoverflow.com/q/49818161
https://stackoverflow.com/a/55567156
<p>Updated: <strong>May 11, 2023</strong>.</p> <p>For using ARCore Emulator, at first, you have to create a virtual device with support for AR. I'm running Android Studio Flamingo on macOS Ventura 13.4.</p> <p>I created Pixel 6 Pro virtual device:</p> <p><a href="https://i.sstatic.net/9e9SJ.png" rel="nofollow noreferre...
<p>Updated: <strong>May 11, 2023</strong>.</p> <p>For using ARCore Emulator, at first, you have to create a virtual device with support for AR. I'm running Android Studio Flamingo on macOS Ventura 13.4.</p> <p>I created Pixel 6 Pro virtual device:</p> <p><a href="https://i.sstatic.net/9e9SJ.png" rel="nofollow noreferre...
387, 30868, 91905, 128295
android-studio, arcore, augmented-reality, bash
<h1>Can't Install ARCore Emulator for Android Studio</h1> <p>I don't know if I'm allowed to ask this question but I really can't figure out how to use ARCore on Android Emulated Device. According to the official guide I'm supposed to use API 8.1 on pixel/pixel 2 device in order to run any app which uses ARCore. Sadly t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,146
bash
# Can't Install ARCore Emulator for Android Studio I don't know if I'm allowed to ask this question but I really can't figure out how to use ARCore on Android Emulated Device. According to the official guide I'm supposed to use API 8.1 on pixel/pixel 2 device in order to run any app which uses ARCore. Sadly those emul...
Updated: **May 11, 2023**. For using ARCore Emulator, at first, you have to create a virtual device with support for AR. I'm running Android Studio Flamingo on macOS Ventura 13.4. I created Pixel 6 Pro virtual device: [![enter image description here](https://i.sstatic.net/9e9SJ.png)](https://i.sstatic.net/9e9SJ.png)...
2718744
PowerShell Advanced Function get current ParameterSetName
14
2010-04-27 04:30:48
<p>In C# you can get the current <code>ParameterSetName</code> in the <code>ProcessRecord</code> override of a PowerShell <code>Cmdlet</code> with code like this:</p> <pre><code> switch (ParameterSetName) { case FromUriParamSetName: loadFromUri(); break; case FromFileParamSetName: ...
10,673
3,957
2017-10-28 05:00:16
46,940,090
15
2017-10-25 18:56:44
3,625,630
2017-10-28 05:00:16
https://stackoverflow.com/q/2718744
https://stackoverflow.com/a/46940090
<p>As a way to expand this awesome answer:</p> <pre><code>switch ($PsCmdlet.ParameterSetName) { "FromFile_ParamSet" { } "FromUri_ParamSet" { } "__AllParameterSets" { } } </code></pre> <p>The <code>__AllparameterSets</code> is the default option in PS</p>
<p>As a way to expand this awesome answer:</p> <pre><code>switch ($PsCmdlet.ParameterSetName) { "FromFile_ParamSet" { } "FromUri_ParamSet" { } "__AllParameterSets" { } } </code></pre> <p>The <code>__AllparameterSets</code> is the default option in PS</p>
526, 153947
powershell, powershell-cmdlet
<h1>PowerShell Advanced Function get current ParameterSetName</h1> <p>In C# you can get the current <code>ParameterSetName</code> in the <code>ProcessRecord</code> override of a PowerShell <code>Cmdlet</code> with code like this:</p> <pre><code> switch (ParameterSetName) { case FromUriParamSetName: l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,147
bash
# PowerShell Advanced Function get current ParameterSetName In C# you can get the current `ParameterSetName` in the `ProcessRecord` override of a PowerShell `Cmdlet` with code like this: ``` switch (ParameterSetName) { case FromUriParamSetName: loadFromUri(); break; case FromFileP...
As a way to expand this awesome answer: ``` switch ($PsCmdlet.ParameterSetName) { "FromFile_ParamSet" { } "FromUri_ParamSet" { } "__AllParameterSets" { } } ``` The `__AllparameterSets` is the default option in PS
43731839
PowerShell Split after Pipe
14
2017-05-02 06:53:24
<p>I use the following line in my script to return all the paths of all folders at the <code>$folder</code> location.</p> <pre><code>dir -recurse $folder|?{$_.PSIsContainer}|select -ExpandProperty FullName </code></pre> <p>This works. But: I only need the fourth element of each path.</p> <p>I've tried adding <code>|...
23,538
2,146,626
2017-05-02 06:59:55
43,731,879
15
2017-05-02 06:55:56
1,163,423
2017-05-02 06:55:56
https://stackoverflow.com/q/43731839
https://stackoverflow.com/a/43731879
<p>You are almost there. You need to put your code within the <code>Foreach-Object</code> cmdlet:</p> <pre><code>Get-ChildItem -recurse $folder| Where-Object {$_.PSIsContainer}| Select-Object -ExpandProperty FullName | ForEach-Object { $_.Split("\")[3] } </code></pre>
<p>You are almost there. You need to put your code within the <code>Foreach-Object</code> cmdlet:</p> <pre><code>Get-ChildItem -recurse $folder| Where-Object {$_.PSIsContainer}| Select-Object -ExpandProperty FullName | ForEach-Object { $_.Split("\")[3] } </code></pre>
526, 2193, 6268
path, powershell, split
<h1>PowerShell Split after Pipe</h1> <p>I use the following line in my script to return all the paths of all folders at the <code>$folder</code> location.</p> <pre><code>dir -recurse $folder|?{$_.PSIsContainer}|select -ExpandProperty FullName </code></pre> <p>This works. But: I only need the fourth element of each pa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,148
bash
# PowerShell Split after Pipe I use the following line in my script to return all the paths of all folders at the `$folder` location. ``` dir -recurse $folder|?{$_.PSIsContainer}|select -ExpandProperty FullName ``` This works. But: I only need the fourth element of each path. I've tried adding `|{$_.Split("\")}[3]}...
You are almost there. You need to put your code within the `Foreach-Object` cmdlet: ``` Get-ChildItem -recurse $folder| Where-Object {$_.PSIsContainer}| Select-Object -ExpandProperty FullName | ForEach-Object { $_.Split("\")[3] } ```
38354773
How to pass an ssh key passphrase via environment variable
14
2016-07-13 14:39:03
<p>I run shell script with <code>ssh</code> command inside my application. Used private key is encrypted by passphrase and the problem is - I cannot interactively pass it when asked.Key is not added in <code>ssh-agent</code>. I cannot execute <code>ssh-add my_key</code> because the passphrase is suppose to be passed in...
27,406
4,261,472
2022-02-12 16:20:53
38,356,798
15
2016-07-13 16:11:24
1,598,080
2016-07-14 08:31:03
https://stackoverflow.com/q/38354773
https://stackoverflow.com/a/38356798
<p>So there are actually a few things that is important for what you are trying to do:</p> <ol> <li>DISPLAY must be set</li> <li>it must not have a terminal associated with it</li> <li>on some machines it may be necessary to redirect the input from /dev/null (mine is one of them).</li> <li>SSH_ASKPASS must contain an ...
<p>So there are actually a few things that is important for what you are trying to do:</p> <ol> <li>DISPLAY must be set</li> <li>it must not have a terminal associated with it</li> <li>on some machines it may be necessary to redirect the input from /dev/null (mine is one of them).</li> <li>SSH_ASKPASS must contain an ...
58, 386, 390, 25308, 58114
linux, shell, ssh, ssh-agent, ssh-keys
<h1>How to pass an ssh key passphrase via environment variable</h1> <p>I run shell script with <code>ssh</code> command inside my application. Used private key is encrypted by passphrase and the problem is - I cannot interactively pass it when asked.Key is not added in <code>ssh-agent</code>. I cannot execute <code>ssh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,149
bash
# How to pass an ssh key passphrase via environment variable I run shell script with `ssh` command inside my application. Used private key is encrypted by passphrase and the problem is - I cannot interactively pass it when asked.Key is not added in `ssh-agent`. I cannot execute `ssh-add my_key` because the passphrase ...
So there are actually a few things that is important for what you are trying to do: 1. DISPLAY must be set 2. it must not have a terminal associated with it 3. on some machines it may be necessary to redirect the input from /dev/null (mine is one of them). 4. SSH_ASKPASS must contain an executable which outputs the pa...
23096884
How to enumerate a list of files
14
2014-04-16 00:28:27
<p>I want to get a numbered list of files, e.g. if I have these files:</p> <pre><code>a.pdf b.pdf c </code></pre> <p>then it should be listed as:</p> <pre><code>1 a.pdf 2 b.pdf 3 c </code></pre>
18,236
null
2018-03-15 05:23:07
23,096,914
15
2014-04-16 00:31:27
3,164,492
2014-04-16 07:40:04
https://stackoverflow.com/q/23096884
https://stackoverflow.com/a/23096914
<p>You can do it two ways:-<br> 1st one :-<br> <code>ls -1 | awk '{print NR,$0}'</code></p> <p>2nd one:-<br> <code>ls -1 | cat -n</code><br> You must prefer 2nd one but choose whatever you like. :-)</p>
<p>You can do it two ways:-<br> 1st one :-<br> <code>ls -1 | awk '{print NR,$0}'</code></p> <p>2nd one:-<br> <code>ls -1 | cat -n</code><br> You must prefer 2nd one but choose whatever you like. :-)</p>
387, 990, 10327
awk, bash, sh
<h1>How to enumerate a list of files</h1> <p>I want to get a numbered list of files, e.g. if I have these files:</p> <pre><code>a.pdf b.pdf c </code></pre> <p>then it should be listed as:</p> <pre><code>1 a.pdf 2 b.pdf 3 c </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,150
bash
# How to enumerate a list of files I want to get a numbered list of files, e.g. if I have these files: ``` a.pdf b.pdf c ``` then it should be listed as: ``` 1 a.pdf 2 b.pdf 3 c ```
You can do it two ways:- 1st one :- `ls -1 | awk '{print NR,$0}'` 2nd one:- `ls -1 | cat -n` You must prefer 2nd one but choose whatever you like. :-)
19352820
Bash shell...find command...names with wildcards...alias or function
14
2013-10-14 02:50:24
<p>I've long used the find command for finding files and directories in the current directory and all subdirectories that match a pattern:</p> <pre><code>find . -name "*.txt" -print find . -name "Bill*" -print </code></pre> <p>But what I'd really like is an alias or function that will properly pass the wildcard. (I ...
35,031
2,877,454
2025-08-29 08:47:54
19,352,839
15
2013-10-14 02:52:18
20,862
2013-10-14 02:52:18
https://stackoverflow.com/q/19352820
https://stackoverflow.com/a/19352839
<p>Unfortunately the wildcards must be quoted or the shell will expand them if possible.</p> <p>Fortunately there are multiple ways of quoting them.</p> <pre><code>fn '*.txt' fn Bill\* </code></pre>
<p>Unfortunately the wildcards must be quoted or the shell will expand them if possible.</p> <p>Fortunately there are multiple ways of quoting them.</p> <pre><code>fn '*.txt' fn Bill\* </code></pre>
387, 1448, 5569, 5997
alias, bash, function, wildcard
<h1>Bash shell...find command...names with wildcards...alias or function</h1> <p>I've long used the find command for finding files and directories in the current directory and all subdirectories that match a pattern:</p> <pre><code>find . -name "*.txt" -print find . -name "Bill*" -print </code></pre> <p>But what I'd ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,151
bash
# Bash shell...find command...names with wildcards...alias or function I've long used the find command for finding files and directories in the current directory and all subdirectories that match a pattern: ``` find . -name "*.txt" -print find . -name "Bill*" -print ``` But what I'd really like is an alias or functi...
Unfortunately the wildcards must be quoted or the shell will expand them if possible. Fortunately there are multiple ways of quoting them. ``` fn '*.txt' fn Bill\* ```
5833086
Shell script variable replacing characters
14
2011-04-29 14:02:59
<p>I have a variable var="abcde$$$$$$$$fff$$gg". I want to replace all $ with space ' ' but the following puts just one space</p> <pre><code>var=$( echo "$var" | tr '$' ' ') </code></pre> <p>How can i replace them all?</p>
59,810
663,229
2016-09-27 09:48:25
5,833,204
15
2011-04-29 14:12:44
96,588
2011-04-29 14:12:44
https://stackoverflow.com/q/5833086
https://stackoverflow.com/a/5833204
<p>Works for me. You'll need to use single quotes or escape the dollar signs, otherwise they are removed from the double-quoted string:</p> <pre><code>echo 'abcde$$$$$$$$fff$$gg' | tr '$' ' ' abcde fff gg echo "abcde\$\$\$\$\$\$\$\$fff\$\$gg" | tr '$' ' ' abcde fff gg echo abcde\$\$\$\$\$\$\$\$fff\$\...
<p>Works for me. You'll need to use single quotes or escape the dollar signs, otherwise they are removed from the double-quoted string:</p> <pre><code>echo 'abcde$$$$$$$$fff$$gg' | tr '$' ' ' abcde fff gg echo "abcde\$\$\$\$\$\$\$\$fff\$\$gg" | tr '$' ' ' abcde fff gg echo abcde\$\$\$\$\$\$\$\$fff\$\...
139, 276, 390
shell, string, variables
<h1>Shell script variable replacing characters</h1> <p>I have a variable var="abcde$$$$$$$$fff$$gg". I want to replace all $ with space ' ' but the following puts just one space</p> <pre><code>var=$( echo "$var" | tr '$' ' ') </code></pre> <p>How can i replace them all?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,152
bash
# Shell script variable replacing characters I have a variable var="abcde$$$$$$$$fff$$gg". I want to replace all $ with space ' ' but the following puts just one space ``` var=$( echo "$var" | tr '$' ' ') ``` How can i replace them all?
Works for me. You'll need to use single quotes or escape the dollar signs, otherwise they are removed from the double-quoted string: ``` echo 'abcde$$$$$$$$fff$$gg' | tr '$' ' ' abcde fff gg echo "abcde\$\$\$\$\$\$\$\$fff\$\$gg" | tr '$' ' ' abcde fff gg echo abcde\$\$\$\$\$\$\$\$fff\$\$gg | tr '$' '...
5790767
Remove folder & files from project using NuGet/Powershell
14
2011-04-26 13:03:15
<p>I am trying to remove the App_Start folder from my project during my NuGet package install. The documentation for NuGet here:</p> <p><a href="http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package">http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package</a></p> <p>Says:</p> <blockquote> <p>$pro...
4,596
364,683
2013-03-15 06:28:54
5,808,163
15
2011-04-27 17:33:24
25,124
2011-04-28 09:05:18
https://stackoverflow.com/q/5790767
https://stackoverflow.com/a/5808163
<p>Ok, I'm absolutely sure there's a better way than this, but I've never used NuGet or Powershell until today... :/</p> <p>I just ran this in my Package Manager Console:</p> <pre><code>$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } } </code></pre> <p>...
<p>Ok, I'm absolutely sure there's a better way than this, but I've never used NuGet or Powershell until today... :/</p> <p>I just ran this in my Package Manager Console:</p> <pre><code>$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } } </code></pre> <p>...
526, 62770, 62984
nuget, nuget-package, powershell
<h1>Remove folder & files from project using NuGet/Powershell</h1> <p>I am trying to remove the App_Start folder from my project during my NuGet package install. The documentation for NuGet here:</p> <p><a href="http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package">http://nuget.codeplex.com/wikipage?title=C...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,153
bash
# Remove folder & files from project using NuGet/Powershell I am trying to remove the App_Start folder from my project during my NuGet package install. The documentation for NuGet here: <http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package> Says: > $project.Object is the equivalent of <http://msdn.micros...
Ok, I'm absolutely sure there's a better way than this, but I've never used NuGet or Powershell until today... :/ I just ran this in my Package Manager Console: ``` $DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } } ``` It looped through all projects ite...
5584470
How to increment a zero padded int in Bash
14
2011-04-07 16:34:41
<p>I have a set of records to loop. The numbers range from 0000001 to 0089543 that ill call UIDX.</p> <p>if i try something like:</p> <pre><code>for ((i=0; i&lt; 0089543; i++)); do ((UIDX++)) done </code></pre> <p>counter increments 1, 2, 3, 4 as opposed to the 0000001, 0000002... that i need.</p> <p>what is th...
10,123
697,208
2014-03-25 15:53:05
5,584,523
15
2011-04-07 16:38:48
182,693
2014-03-25 15:53:05
https://stackoverflow.com/q/5584470
https://stackoverflow.com/a/5584523
<p>Use the <code>printf</code> command to format the numbers with leading zeroes, eg:</p> <pre><code>for ((i = 0; i &lt; 99; ++i)); do printf -v num '%07d' $i; echo $num; done </code></pre> <p>From <code>man bash</code>:</p> <blockquote> <p>printf [-v var] format [arguments]<br> Write the formatted arguments to ...
<p>Use the <code>printf</code> command to format the numbers with leading zeroes, eg:</p> <pre><code>for ((i = 0; i &lt; 99; ++i)); do printf -v num '%07d' $i; echo $num; done </code></pre> <p>From <code>man bash</code>:</p> <blockquote> <p>printf [-v var] format [arguments]<br> Write the formatted arguments to ...
387
bash
<h1>How to increment a zero padded int in Bash</h1> <p>I have a set of records to loop. The numbers range from 0000001 to 0089543 that ill call UIDX.</p> <p>if i try something like:</p> <pre><code>for ((i=0; i&lt; 0089543; i++)); do ((UIDX++)) done </code></pre> <p>counter increments 1, 2, 3, 4 as opposed to the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,154
bash
# How to increment a zero padded int in Bash I have a set of records to loop. The numbers range from 0000001 to 0089543 that ill call UIDX. if i try something like: ``` for ((i=0; i< 0089543; i++)); do ((UIDX++)) done ``` counter increments 1, 2, 3, 4 as opposed to the 0000001, 0000002... that i need. what is ...
Use the `printf` command to format the numbers with leading zeroes, eg: ``` for ((i = 0; i < 99; ++i)); do printf -v num '%07d' $i; echo $num; done ``` From `man bash`: > printf [-v var] format [arguments] > Write the formatted arguments to the standard output under the control of the format. The -v option causes ...
5436899
how do i start commands in new terminals in BASH script
14
2011-03-25 18:58:51
<p>my bash script reads in a few variables and then runs airodump on my home network. I would like to keep the window with airodump running and open some new terminals to run other commands for network discovery while the airodump screen is open (so i can see the results).<br> right now what i have looks like this (ed...
29,390
585,971
2011-08-28 14:48:19
5,436,995
15
2011-03-25 19:08:45
388,520
2011-03-25 19:08:45
https://stackoverflow.com/q/5436899
https://stackoverflow.com/a/5436995
<p>The terminal window is generated by a separate program from the command running inside. Try one of these variations:</p> <pre><code>xterm -e airomon-start wlan0 "$channel","$channel" &amp; gnome-terminal -x airomon-start wlan0 "$channel","$channel" &amp; konsole -e airomon-start wlan0 "$channel","$channel" &amp;...
<p>The terminal window is generated by a separate program from the command running inside. Try one of these variations:</p> <pre><code>xterm -e airomon-start wlan0 "$channel","$channel" &amp; gnome-terminal -x airomon-start wlan0 "$channel","$channel" &amp; konsole -e airomon-start wlan0 "$channel","$channel" &amp;...
387
bash
<h1>how do i start commands in new terminals in BASH script</h1> <p>my bash script reads in a few variables and then runs airodump on my home network. I would like to keep the window with airodump running and open some new terminals to run other commands for network discovery while the airodump screen is open (so i ca...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,155
bash
# how do i start commands in new terminals in BASH script my bash script reads in a few variables and then runs airodump on my home network. I would like to keep the window with airodump running and open some new terminals to run other commands for network discovery while the airodump screen is open (so i can see the ...
The terminal window is generated by a separate program from the command running inside. Try one of these variations: ``` xterm -e airomon-start wlan0 "$channel","$channel" & gnome-terminal -x airomon-start wlan0 "$channel","$channel" & konsole -e airomon-start wlan0 "$channel","$channel" & ``` Pick the command that...
61840544
What is the "done" function/meaning in the bash while loop?
13
2020-05-16 17:04:13
<p>I am a new guy for bash shell. I am confused by the below script. </p> <pre><code>#!/bin/bash input=name.csv while IFS=',' read -r Family_name First_name do echo $Family_name echo $First_name done &lt; $input </code></pre> <p>Intuitively, I thought the <code>done</code> is some kind of boundary marker that ...
41,712
11,203,583
2020-12-15 18:16:54
61,840,595
15
2020-05-16 17:08:04
978,917
2020-05-16 17:08:04
https://stackoverflow.com/q/61840544
https://stackoverflow.com/a/61840595
<blockquote> <p>Intuitively, I thought the done is some kind of boundary maker that told you the while field is over.</p> </blockquote> <p>Correct; <code>done</code> ends a while-loop (or for-loop or similar).</p> <blockquote> <p>Here it show that done can take the data from a variable.</p> </blockquote> <p>No; ...
<blockquote> <p>Intuitively, I thought the done is some kind of boundary maker that told you the while field is over.</p> </blockquote> <p>Correct; <code>done</code> ends a while-loop (or for-loop or similar).</p> <blockquote> <p>Here it show that done can take the data from a variable.</p> </blockquote> <p>No; ...
58, 387
bash, linux
<h1>What is the "done" function/meaning in the bash while loop?</h1> <p>I am a new guy for bash shell. I am confused by the below script. </p> <pre><code>#!/bin/bash input=name.csv while IFS=',' read -r Family_name First_name do echo $Family_name echo $First_name done &lt; $input </code></pre> <p>Intuitively, ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,156
bash
# What is the "done" function/meaning in the bash while loop? I am a new guy for bash shell. I am confused by the below script. ``` #!/bin/bash input=name.csv while IFS=',' read -r Family_name First_name do echo $Family_name echo $First_name done < $input ``` Intuitively, I thought the `done` is some kind of ...
> Intuitively, I thought the done is some kind of boundary maker that told you the while field is over. Correct; `done` ends a while-loop (or for-loop or similar). > Here it show that done can take the data from a variable. No; the `< $input` (meaning `< name.csv`) is a [redirection](https://www.gnu.org/software/bas...
59897745
checking if a string exists in an array of strings in bash
13
2020-01-24 13:47:49
<p>I know how to compare two string in bash:</p> <pre><code>if [ "$build_type" = "devite" ]; then echo "building'" fi </code></pre> <p>But what I need is to check if "$build_type" is in ["devite", "relite"]</p> <p>so something similar to this:</p> <pre><code>if [ "$build_type" in ["devite", "relite"] ]; then ec...
23,924
12,043,259
2020-01-24 14:25:11
59,897,856
15
2020-01-24 13:54:17
1,126,841
2020-01-24 13:54:17
https://stackoverflow.com/q/59897745
https://stackoverflow.com/a/59897856
<p>Join two <code>test</code>/<code>[</code> commands with <code>||</code>:</p> <pre><code>if [ "$build_type" = devite ] || [ "$build_type" = relite ]; then echo "building" fi </code></pre> <p>or use a <code>case</code> statement.</p> <pre><code>case $build_type in devite|relite) echo "building" ;; esac </code><...
<p>Join two <code>test</code>/<code>[</code> commands with <code>||</code>:</p> <pre><code>if [ "$build_type" = devite ] || [ "$build_type" = relite ]; then echo "building" fi </code></pre> <p>or use a <code>case</code> statement.</p> <pre><code>case $build_type in devite|relite) echo "building" ;; esac </code><...
387
bash
<h1>checking if a string exists in an array of strings in bash</h1> <p>I know how to compare two string in bash:</p> <pre><code>if [ "$build_type" = "devite" ]; then echo "building'" fi </code></pre> <p>But what I need is to check if "$build_type" is in ["devite", "relite"]</p> <p>so something similar to 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,157
bash
# checking if a string exists in an array of strings in bash I know how to compare two string in bash: ``` if [ "$build_type" = "devite" ]; then echo "building'" fi ``` But what I need is to check if "$build_type" is in ["devite", "relite"] so something similar to this: ``` if [ "$build_type" in ["devite", "reli...
Join two `test`/`[` commands with `||`: ``` if [ "$build_type" = devite ] || [ "$build_type" = relite ]; then echo "building" fi ``` or use a `case` statement. ``` case $build_type in devite|relite) echo "building" ;; esac ``` If the targets are in an associative array, you can check for the existence of a key....
56257442
Trusting self-signed certificate in Invoke-WebRequest call
13
2019-05-22 13:02:05
<h2>Question</h2> <p>Is there a way I can call <code>Invoke-WebRequest</code> and for example expect a given public key of the certificate to validate that I trust the connection?</p> <p>If not, is there another way to invoke the webrequest and only trust the webpage without trusting the issuer or ignoring the certif...
32,134
6,404,133
2019-10-21 22:07:49
56,260,067
15
2019-05-22 15:15:55
2,150,063
2019-05-22 15:15:55
https://stackoverflow.com/q/56257442
https://stackoverflow.com/a/56260067
<p>Short answer, No you can't get around it, and when it comes to certificates, don't even try. The client will first look at the certificate, and the whole certificate chain to see if it is trusted. If any part of that chain (e.g. issuer) is not trusted, then it is not trusted. If this fundamental fact didn't happen, ...
<p>Short answer, No you can't get around it, and when it comes to certificates, don't even try. The client will first look at the certificate, and the whole certificate chain to see if it is trusted. If any part of that chain (e.g. issuer) is not trusted, then it is not trusted. If this fundamental fact didn't happen, ...
526, 642, 14423, 130616
https, powershell, powershell-core, ssl-certificate
<h1>Trusting self-signed certificate in Invoke-WebRequest call</h1> <h2>Question</h2> <p>Is there a way I can call <code>Invoke-WebRequest</code> and for example expect a given public key of the certificate to validate that I trust the connection?</p> <p>If not, is there another way to invoke the webrequest and only ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,158
bash
# Trusting self-signed certificate in Invoke-WebRequest call ## Question Is there a way I can call `Invoke-WebRequest` and for example expect a given public key of the certificate to validate that I trust the connection? If not, is there another way to invoke the webrequest and only trust the webpage without trustin...
Short answer, No you can't get around it, and when it comes to certificates, don't even try. The client will first look at the certificate, and the whole certificate chain to see if it is trusted. If any part of that chain (e.g. issuer) is not trusted, then it is not trusted. If this fundamental fact didn't happen, the...
53126950
Permission denied to Docker daemon socket at unix:///var/run/docker.sock
13
2018-11-02 23:28:22
<p>I have this <code>Dockerfile</code>:</p> <pre><code>FROM chekote/gulp:latest USER root RUN apt-get update \ &amp;&amp; apt-get upgrade -y \ &amp;&amp; apt-get install -y sudo libltdl-dev ARG dockerUser='my-user-name'; ARG group='docker'; # crate group if not exists RUN if ! grep -q -E "^$group:" /e...
28,522
1,174,405
2022-07-11 23:25:12
53,129,447
15
2018-11-03 07:47:09
10,008,173
2021-07-28 11:34:28
https://stackoverflow.com/q/53126950
https://stackoverflow.com/a/53129447
<p>The permission matching happens only on <em>numeric</em> user ID and group ID. If the socket file is mode 0660 and owned by user ID 0 and group ID 32, and you're calling it as a user with user ID 1000 and group IDs 1000 and 16, it doesn't matter if one <code>/etc/group</code> file names gid 32 as <code>docker</code...
<p>The permission matching happens only on <em>numeric</em> user ID and group ID. If the socket file is mode 0660 and owned by user ID 0 and group ID 32, and you're calling it as a user with user ID 1000 and group IDs 1000 and 16, it doesn't matter if one <code>/etc/group</code> file names gid 32 as <code>docker</code...
387, 90304, 99715, 108477, 133383
bash, docker, dockerfile, docker-run, gulp
<h1>Permission denied to Docker daemon socket at unix:///var/run/docker.sock</h1> <p>I have this <code>Dockerfile</code>:</p> <pre><code>FROM chekote/gulp:latest USER root RUN apt-get update \ &amp;&amp; apt-get upgrade -y \ &amp;&amp; apt-get install -y sudo libltdl-dev ARG dockerUser='my-user-name'; A...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,159
bash
# Permission denied to Docker daemon socket at unix:///var/run/docker.sock I have this `Dockerfile`: ``` FROM chekote/gulp:latest USER root RUN apt-get update \ && apt-get upgrade -y \ && apt-get install -y sudo libltdl-dev ARG dockerUser='my-user-name'; ARG group='docker'; # crate group if not exists...
The permission matching happens only on *numeric* user ID and group ID. If the socket file is mode 0660 and owned by user ID 0 and group ID 32, and you're calling it as a user with user ID 1000 and group IDs 1000 and 16, it doesn't matter if one `/etc/group` file names gid 32 as `docker` and the other one names gid 16 ...
51440450
Bash operators: "!" vs "-z"
13
2018-07-20 10:25:03
<p>What is the difference between the operator "!" and "-z" applied to a string?</p> <pre><code>#Example 1 if [ ! STRING ]; then ... #Example 2 if [ -z STRING ]; then ... </code></pre> <p>Thanks</p>
11,262
8,018,439
2019-03-29 11:16:55
51,440,747
15
2018-07-20 10:41:30
8,344,060
2019-03-29 11:16:55
https://stackoverflow.com/q/51440450
https://stackoverflow.com/a/51440747
<p>First of all you make use of single brackets. This implies that you are using the <code>test</code> command and not the Bash-builtin function. From the manual :</p> <blockquote> <p><strong><code>test EXPRESSION</code></strong> or <strong><code>[ EXPRESSION ]</code>:</strong> this exits with the status returned by <c...
<p>First of all you make use of single brackets. This implies that you are using the <code>test</code> command and not the Bash-builtin function. From the manual :</p> <blockquote> <p><strong><code>test EXPRESSION</code></strong> or <strong><code>[ EXPRESSION ]</code>:</strong> this exits with the status returned by <c...
387, 7992
bash, operators
<h1>Bash operators: "!" vs "-z"</h1> <p>What is the difference between the operator "!" and "-z" applied to a string?</p> <pre><code>#Example 1 if [ ! STRING ]; then ... #Example 2 if [ -z STRING ]; then ... </code></pre> <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,160
bash
# Bash operators: "!" vs "-z" What is the difference between the operator "!" and "-z" applied to a string? ``` #Example 1 if [ ! STRING ]; then ... #Example 2 if [ -z STRING ]; then ... ``` Thanks
First of all you make use of single brackets. This implies that you are using the `test` command and not the Bash-builtin function. From the manual : > **`test EXPRESSION`** or **`[ EXPRESSION ]`:** this exits with the status returned by `EXPRESSION` > > **`! EXPRESSION`:** `test` returns **true** of `EXPRESSION` is *...
34591729
How to execute code in the Django shell by an external python script?
13
2016-01-04 12:58:13
<p><strong>What I want to achieve:</strong></p> <p>I would like to create a python script to deactivate Django users in the database from the CLI. I came up with this:</p> <pre><code>$ sudo python manage.py shell &gt;&gt;&gt; user = User.objects.get(username=FooBar) &gt;&gt;&gt; user.is_active = False &gt;&gt;&gt; us...
18,250
1,949,628
2022-09-01 13:37:14
34,591,919
15
2016-01-04 13:08:16
104,349
2022-09-01 11:38:44
https://stackoverflow.com/q/34591729
https://stackoverflow.com/a/34591919
<p>Firstly, you should not be accessing your Python shell with <code>sudo</code>. There's no need to be running as root.</p> <p>Secondly, the way to create a script that runs from the command prompt is to write a custom manage.py script, so you can run <code>./manage.py deactivate_users</code>. Full instructions for do...
<p>Firstly, you should not be accessing your Python shell with <code>sudo</code>. There's no need to be running as root.</p> <p>Secondly, the way to create a script that runs from the command prompt is to write a custom manage.py script, so you can run <code>./manage.py deactivate_users</code>. Full instructions for do...
16, 58, 243, 390, 50079
django, linux, manage.py, python, shell
<h1>How to execute code in the Django shell by an external python script?</h1> <p><strong>What I want to achieve:</strong></p> <p>I would like to create a python script to deactivate Django users in the database from the CLI. I came up with this:</p> <pre><code>$ sudo python manage.py shell &gt;&gt;&gt; user = User.o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,161
bash
# How to execute code in the Django shell by an external python script? **What I want to achieve:** I would like to create a python script to deactivate Django users in the database from the CLI. I came up with this: ``` $ sudo python manage.py shell >>> user = User.objects.get(username=FooBar) >>> user.is_active = ...
Firstly, you should not be accessing your Python shell with `sudo`. There's no need to be running as root. Secondly, the way to create a script that runs from the command prompt is to write a custom manage.py script, so you can run `./manage.py deactivate_users`. Full instructions for doing that are in [the documentat...