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
16676750
Windows, Emacs, Git Bash, and shell-command
6
2013-05-21 18:14:12
<p>Windows 7. Emacs 24.3.1. Git 1.8.1.msysgit.1. I have the following in my equivalent .emacs file:</p> <pre><code>(if (equal system-type 'windows-nt) (progn (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/sh.exe") (setq shell-file-name "bash") (setq explicit-s...
10,746
500,207
2018-04-19 09:28:41
16,677,257
13
2013-05-21 18:43:15
973,603
2013-05-21 18:43:15
https://stackoverflow.com/q/16676750
https://stackoverflow.com/a/16677257
<p>Try setting both variables to point to the same executable and make sure the path is in <code>exec-path</code>:</p> <pre><code>(setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/bash.exe") (setq shell-file-name explicit-shell-file-name) (add-to-list 'exec-path "C:/Program Files (x86)/Git/bin") </c...
<p>Try setting both variables to point to the same executable and make sure the path is in <code>exec-path</code>:</p> <pre><code>(setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/bash.exe") (setq shell-file-name explicit-shell-file-name) (add-to-list 'exec-path "C:/Program Files (x86)/Git/bin") </c...
64, 371, 390
emacs, shell, windows
<h1>Windows, Emacs, Git Bash, and shell-command</h1> <p>Windows 7. Emacs 24.3.1. Git 1.8.1.msysgit.1. I have the following in my equivalent .emacs file:</p> <pre><code>(if (equal system-type 'windows-nt) (progn (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/sh.exe") (set...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,571
bash
# Windows, Emacs, Git Bash, and shell-command Windows 7. Emacs 24.3.1. Git 1.8.1.msysgit.1. I have the following in my equivalent .emacs file: ``` (if (equal system-type 'windows-nt) (progn (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/sh.exe") (setq shell-file-name "b...
Try setting both variables to point to the same executable and make sure the path is in `exec-path`: ``` (setq explicit-shell-file-name "C:/Program Files (x86)/Git/bin/bash.exe") (setq shell-file-name explicit-shell-file-name) (add-to-list 'exec-path "C:/Program Files (x86)/Git/bin") ```
16626218
Composer.phar don't want to run by shell_exec from PHP script. Why?
6
2013-05-18 15:58:44
<p>Trying to execute it with all possible params, such as -d and full path etc.. No errors. When running another commands, all is ok, when running composer from CMD, all is ok too. Have tried exec, system, shell_exec etc.. What it could be?</p> <blockquote> <p>echo system('php composer.phar install');</p> </blockquo...
5,227
217,128
2020-08-06 07:09:03
16,626,248
13
2013-05-18 16:01:52
2,396,993
2013-10-27 08:09:43
https://stackoverflow.com/q/16626218
https://stackoverflow.com/a/16626248
<p>Try outputting the error stream as well:</p> <pre><code>system('php composer.phar install 2&gt;&amp;1'); </code></pre> <p>It might give you more of a hint as to what is going wrong.</p>
<p>Try outputting the error stream as well:</p> <pre><code>system('php composer.phar install 2&gt;&amp;1'); </code></pre> <p>It might give you more of a hint as to what is going wrong.</p>
5, 5163, 7932, 8646, 78546
composer-php, exec, php, shell-exec, system
<h1>Composer.phar don't want to run by shell_exec from PHP script. Why?</h1> <p>Trying to execute it with all possible params, such as -d and full path etc.. No errors. When running another commands, all is ok, when running composer from CMD, all is ok too. Have tried exec, system, shell_exec etc.. What it could be?</p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,572
bash
# Composer.phar don't want to run by shell_exec from PHP script. Why? Trying to execute it with all possible params, such as -d and full path etc.. No errors. When running another commands, all is ok, when running composer from CMD, all is ok too. Have tried exec, system, shell_exec etc.. What it could be? > echo sys...
Try outputting the error stream as well: ``` system('php composer.phar install 2>&1'); ``` It might give you more of a hint as to what is going wrong.
16325452
IF Statement not working in Powershell
6
2013-05-01 19:56:37
<p>I've been trying to get an IF-ELSE clause to work within my little powershell v2 script, and I think I'm having some problems with my parsing. Here's the code I have currently:</p> <pre><code>$dir = test-path C:\Perflogs\TestFolder IF($dir -eq "False") { New-Item C:\Perflogs\TestFolder -type directory get-counte...
12,622
2,133,338
2021-05-21 07:17:53
16,325,604
13
2013-05-01 20:05:56
6,920
2013-05-01 20:05:56
https://stackoverflow.com/q/16325452
https://stackoverflow.com/a/16325604
<p>You should have:</p> <pre><code>if ($dir -eq $false) </code></pre> <p>because the string <code>"False"</code> is not equal to the boolean value <code>$false</code>.</p>
<p>You should have:</p> <pre><code>if ($dir -eq $false) </code></pre> <p>because the string <code>"False"</code> is not equal to the boolean value <code>$false</code>.</p>
526, 2773, 24067
if-statement, powershell, powershell-2.0
<h1>IF Statement not working in Powershell</h1> <p>I've been trying to get an IF-ELSE clause to work within my little powershell v2 script, and I think I'm having some problems with my parsing. Here's the code I have currently:</p> <pre><code>$dir = test-path C:\Perflogs\TestFolder IF($dir -eq "False") { New-Item C...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,573
bash
# IF Statement not working in Powershell I've been trying to get an IF-ELSE clause to work within my little powershell v2 script, and I think I'm having some problems with my parsing. Here's the code I have currently: ``` $dir = test-path C:\Perflogs\TestFolder IF($dir -eq "False") { New-Item C:\Perflogs\TestFolde...
You should have: ``` if ($dir -eq $false) ``` because the string `"False"` is not equal to the boolean value `$false`.
15707219
Can I use the environment variable %PROGRAMDATA%?
6
2013-03-29 16:25:02
<p>I type:</p> <p><code>echo $USERPROFILE</code> and get <code>C:\Users\rob</code></p> <p><code>echo $PROGRAMFILES</code> and get <code>C:\Program Files (x86)</code></p> <p><code>echo $PROGRAMDATA</code> and get nothing.</p> <p>Under windows <code>%PROGRAMDATA%</code> evaluates to <code>C:\ProgramData</code></p> <...
12,955
221,801
2013-04-18 06:22:23
16,075,834
13
2013-04-18 06:20:03
1,002,260
2013-04-18 06:20:03
https://stackoverflow.com/q/15707219
https://stackoverflow.com/a/16075834
<p>It is mixed case</p> <pre class="lang-sh prettyprint-override"><code>$ set | grep -i programdata ALLUSERSPROFILE='C:\ProgramData' ProgramData='C:\ProgramData' $ echo $ProgramData C:\ProgramData </code></pre>
<p>It is mixed case</p> <pre class="lang-sh prettyprint-override"><code>$ set | grep -i programdata ALLUSERSPROFILE='C:\ProgramData' ProgramData='C:\ProgramData' $ echo $ProgramData C:\ProgramData </code></pre>
387, 390, 1731, 69665
bash, cygwin, shell, windows-8
<h1>Can I use the environment variable %PROGRAMDATA%?</h1> <p>I type:</p> <p><code>echo $USERPROFILE</code> and get <code>C:\Users\rob</code></p> <p><code>echo $PROGRAMFILES</code> and get <code>C:\Program Files (x86)</code></p> <p><code>echo $PROGRAMDATA</code> and get nothing.</p> <p>Under windows <code>%PROGRAMD...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,574
bash
# Can I use the environment variable %PROGRAMDATA%? I type: `echo $USERPROFILE` and get `C:\Users\rob` `echo $PROGRAMFILES` and get `C:\Program Files (x86)` `echo $PROGRAMDATA` and get nothing. Under windows `%PROGRAMDATA%` evaluates to `C:\ProgramData` Why are some windows environment variables supported and not...
It is mixed case ``` $ set | grep -i programdata ALLUSERSPROFILE='C:\ProgramData' ProgramData='C:\ProgramData' $ echo $ProgramData C:\ProgramData ```
15914109
using powershell to change registry binary data
6
2013-04-09 23:05:04
<p>I understand that with powershell it's possible to change registry values.</p> <p>for example, here: <a href="http://poshcode.org/3504" rel="noreferrer">http://poshcode.org/3504</a></p> <p>we can set the properties like this:</p> <pre><code>Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\Shell\Associations\Url...
12,136
117,700
2015-06-09 01:02:13
15,914,470
13
2013-04-09 23:41:15
251,123
2013-04-09 23:41:15
https://stackoverflow.com/q/15914109
https://stackoverflow.com/a/15914470
<ol> <li>Read the value (a byte array)</li> <li>Modify the array element</li> <li>Write the byte array back to the registry key.</li> </ol> <p>Here's an example:</p> <pre><code>$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' $data = (Get-ItemProperty -Path $key -Name DefaultCon...
<ol> <li>Read the value (a byte array)</li> <li>Modify the array element</li> <li>Write the byte array back to the registry key.</li> </ol> <p>Here's an example:</p> <pre><code>$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' $data = (Get-ItemProperty -Path $key -Name DefaultCon...
64, 368, 526, 1189
binary, internet-explorer, powershell, windows
<h1>using powershell to change registry binary data</h1> <p>I understand that with powershell it's possible to change registry values.</p> <p>for example, here: <a href="http://poshcode.org/3504" rel="noreferrer">http://poshcode.org/3504</a></p> <p>we can set the properties like this:</p> <pre><code>Set-ItemProperty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,575
bash
# using powershell to change registry binary data I understand that with powershell it's possible to change registry values. for example, here: <http://poshcode.org/3504> we can set the properties like this: ``` Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice' -n...
1. Read the value (a byte array) 2. Modify the array element 3. Write the byte array back to the registry key. Here's an example: ``` $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' $data = (Get-ItemProperty -Path $key -Name DefaultConnectionSettings).DefaultConnectionSettings ...
15596826
What is the difference between $@ and $* in shell script?
6
2013-03-24 09:19:44
<p>in my <code>script.sh</code>:</p> <pre><code>aa=$@ bb=$* echo $aa echo $bb </code></pre> <p>when running it:</p> <pre><code> source script.sh a b c d e f g </code></pre> <p>I get:</p> <pre><code>a b c d e f g a b c d e f g </code></pre> <p>What is the difference between <code>$@</code> and <code>$*</code> ?</p...
19,356
1,031,417
2013-03-24 09:31:07
15,596,832
13
2013-03-24 09:20:29
1,458,569
2013-03-24 09:31:07
https://stackoverflow.com/q/15596826
https://stackoverflow.com/a/15596832
<p>There are no difference between <code>$*</code> and <code>$@</code>, but there is a difference between <code>"$@"</code> and <code>"$*"</code>. </p> <pre><code>$ cat 1.sh mkdir "$*" $ cat 2.sh mkdir "$@" $ sh 1.sh a "b c" d $ ls -l total 12 -rw-r--r-- 1 igor igor 11 mar 24 10:20 1.sh -rw-r--r-- 1 igor igor 1...
<p>There are no difference between <code>$*</code> and <code>$@</code>, but there is a difference between <code>"$@"</code> and <code>"$*"</code>. </p> <pre><code>$ cat 1.sh mkdir "$*" $ cat 2.sh mkdir "$@" $ sh 1.sh a "b c" d $ ls -l total 12 -rw-r--r-- 1 igor igor 11 mar 24 10:20 1.sh -rw-r--r-- 1 igor igor 1...
58, 387, 390
bash, linux, shell
<h1>What is the difference between $@ and $* in shell script?</h1> <p>in my <code>script.sh</code>:</p> <pre><code>aa=$@ bb=$* echo $aa echo $bb </code></pre> <p>when running it:</p> <pre><code> source script.sh a b c d e f g </code></pre> <p>I get:</p> <pre><code>a b c d e f g a b c d e f g </code></pre> <p>What...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,576
bash
# What is the difference between $@ and $* in shell script? in my `script.sh`: ``` aa=$@ bb=$* echo $aa echo $bb ``` when running it: ``` source script.sh a b c d e f g ``` I get: ``` a b c d e f g a b c d e f g ``` What is the difference between `$@` and `$*` ?
There are no difference between `$*` and `$@`, but there is a difference between `"$@"` and `"$*"`. ``` $ cat 1.sh mkdir "$*" $ cat 2.sh mkdir "$@" $ sh 1.sh a "b c" d $ ls -l total 12 -rw-r--r-- 1 igor igor 11 mar 24 10:20 1.sh -rw-r--r-- 1 igor igor 11 mar 24 10:20 2.sh drwxr-xr-x 2 igor igor 4096 mar 24 10:2...
13502776
Import-Pssession is not importing cmdlets when used in a custom module
6
2012-11-21 22:03:31
<p>I have a PowerShell script/function that works great when I use it in my PowerShell profile or manually copy/paste the function in the PowerShell window.</p> <p>I'm trying to make the function accessible to other members of my team as a module. I want to have the module stored in a central place so we can all add ...
6,401
1,768,335
2018-10-25 17:32:53
13,972,622
13
2012-12-20 12:50:47
1,768,335
2015-03-31 07:44:06
https://stackoverflow.com/q/13502776
https://stackoverflow.com/a/13972622
<p>With some assistance from TechNet I was able to modify the script module so it worked the way I expected.</p> <pre><code>function Connect-O365 { $o365cred = Get-Credential username@domain.onmicrosoft.com $session365 = New-PSSession ` -ConfigurationName Microsoft.Exchange ` ...
<p>With some assistance from TechNet I was able to modify the script module so it worked the way I expected.</p> <pre><code>function Connect-O365 { $o365cred = Get-Credential username@domain.onmicrosoft.com $session365 = New-PSSession ` -ConfigurationName Microsoft.Exchange ` ...
526, 73157
powershell, powershell-3.0
<h1>Import-Pssession is not importing cmdlets when used in a custom module</h1> <p>I have a PowerShell script/function that works great when I use it in my PowerShell profile or manually copy/paste the function in the PowerShell window.</p> <p>I'm trying to make the function accessible to other members of my team as a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,577
bash
# Import-Pssession is not importing cmdlets when used in a custom module I have a PowerShell script/function that works great when I use it in my PowerShell profile or manually copy/paste the function in the PowerShell window. I'm trying to make the function accessible to other members of my team as a module. I want ...
With some assistance from TechNet I was able to modify the script module so it worked the way I expected. ``` function Connect-O365 { $o365cred = Get-Credential username@domain.onmicrosoft.com $session365 = New-PSSession ` -ConfigurationName Microsoft.Exchange ` -Connect...
13790956
MYSQL differs in Output from script
6
2012-12-09 19:33:08
<p>I have a problem with the MySQL output formatting while executing the commands from a bash script.</p> <p>If I execute a command on the command line then, I am able to get the output in formatted as expected.</p> <pre><code>$ mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" +---...
2,256
1,005,707
2019-10-15 13:04:20
13,790,972
13
2012-12-09 19:34:50
541,091
2017-04-25 13:24:04
https://stackoverflow.com/q/13790956
https://stackoverflow.com/a/13790972
<p>Pass the <code>-t</code> or <code>--table</code> option to force table output.</p> <pre><code>mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" </code></pre> <p>From <code>mysql --help</code>:</p> <pre><code> -t, --table Output in table format. </code></pre>
<p>Pass the <code>-t</code> or <code>--table</code> option to force table output.</p> <pre><code>mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" </code></pre> <p>From <code>mysql --help</code>:</p> <pre><code> -t, --table Output in table format. </code></pre>
21, 58, 387
bash, linux, mysql
<h1>MYSQL differs in Output from script</h1> <p>I have a problem with the MySQL output formatting while executing the commands from a bash script.</p> <p>If I execute a command on the command line then, I am able to get the output in formatted as expected.</p> <pre><code>$ mysql -u dbclient -pxxxx GEKONYLOGDB -e "se...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,578
bash
# MYSQL differs in Output from script I have a problem with the MySQL output formatting while executing the commands from a bash script. If I execute a command on the command line then, I am able to get the output in formatted as expected. ``` $ mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) f...
Pass the `-t` or `--table` option to force table output. ``` mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" ``` From `mysql --help`: ``` -t, --table Output in table format. ```
13709315
sh script not finding variables
6
2012-12-04 18:16:47
<p>I am following a tutorial on how to run a reverse ssh tunnel which is found at <a href="http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling" rel="noreferrer">http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling</a> Issue I am having is when I run the tunneling.sh script:</p> ...
27,860
323,332
2012-12-06 04:01:29
13,709,746
13
2012-12-04 18:43:40
3,333
2012-12-04 18:43:40
https://stackoverflow.com/q/13709315
https://stackoverflow.com/a/13709746
<p>Don't specify <code>#!/bin/sh</code> in your "shebang" line if you're going to use bash features. If you want bash, ask for bash.</p>
<p>Don't specify <code>#!/bin/sh</code> in your "shebang" line if you're going to use bash features. If you want bash, ask for bash.</p>
58, 10327
linux, sh
<h1>sh script not finding variables</h1> <p>I am following a tutorial on how to run a reverse ssh tunnel which is found at <a href="http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling" rel="noreferrer">http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling</a> Issue I am having is...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,579
bash
# sh script not finding variables I am following a tutorial on how to run a reverse ssh tunnel which is found at <http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling> Issue I am having is when I run the tunneling.sh script: ``` #!/bin/sh a=`ps -ef | grep 19999 | grep -v grep` if [ ! "$a" ]; then ...
Don't specify `#!/bin/sh` in your "shebang" line if you're going to use bash features. If you want bash, ask for bash.
13571566
Bash alphanumeric list generating
6
2012-11-26 19:18:07
<p>I need print something like this:</p> <pre><code>a b c . . . z A B C . . . Z 0 1 2 . . . 9 </code></pre> <p>with this is can be done for separately but.</p> <pre><code> for f in {a..z}; do echo $f; done for f in {A..Z}; do echo $f; done for f in {0..9}; do ech...
5,193
1,765,681
2021-01-13 07:21:38
13,571,603
13
2012-11-26 19:20:48
1,848,654
2012-11-26 19:20:48
https://stackoverflow.com/q/13571566
https://stackoverflow.com/a/13571603
<pre><code>for f in {a..z} {A..Z} {0..9}; do echo "$f" done </code></pre>
<pre><code>for f in {a..z} {A..Z} {0..9}; do echo "$f" done </code></pre>
58, 387, 2531, 10327
bash, for-loop, linux, sh
<h1>Bash alphanumeric list generating</h1> <p>I need print something like this:</p> <pre><code>a b c . . . z A B C . . . Z 0 1 2 . . . 9 </code></pre> <p>with this is can be done for separately but.</p> <pre><code> for f in {a..z}; do echo $f; done for f in {A..Z}; do echo $f; do...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,580
bash
# Bash alphanumeric list generating I need print something like this: ``` a b c . . . z A B C . . . Z 0 1 2 . . . 9 ``` with this is can be done for separately but. ``` for f in {a..z}; do echo $f; done for f in {A..Z}; do echo $f; done for f in {0..9}; do echo...
``` for f in {a..z} {A..Z} {0..9}; do echo "$f" done ```
12343227
Escaping bash function arguments for use by su -c
6
2012-09-09 21:40:11
<p>I'd like to be able to write a function <code>su_mt_user</code> that (currently) looks like this:</p> <pre><code>su_mt_user() { su someuser -c "$*" } </code></pre> <p>The objective is to be able to use it like this:</p> <pre><code>su_mt_user mt-auth --stuff etc </code></pre> <p>Which would run the command <c...
4,247
109,696
2012-09-09 23:03:28
12,343,661
13
2012-09-09 22:56:17
387,076
2012-09-09 23:03:28
https://stackoverflow.com/q/12343227
https://stackoverflow.com/a/12343661
<p>To pass multiple arguments through a function to a command, you need <code>"$@"</code>. <code>"$@"</code> is special in that even though it's between double quotes, the separate arguments end up in different words, so they're passed down exactly as is. This is different from <code>$@</code> or <code>$*</code> withou...
<p>To pass multiple arguments through a function to a command, you need <code>"$@"</code>. <code>"$@"</code> is special in that even though it's between double quotes, the separate arguments end up in different words, so they're passed down exactly as is. This is different from <code>$@</code> or <code>$*</code> withou...
387, 2313, 4804, 5569, 13784
arguments, bash, escaping, function, su
<h1>Escaping bash function arguments for use by su -c</h1> <p>I'd like to be able to write a function <code>su_mt_user</code> that (currently) looks like this:</p> <pre><code>su_mt_user() { su someuser -c "$*" } </code></pre> <p>The objective is to be able to use it like this:</p> <pre><code>su_mt_user mt-auth -...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,581
bash
# Escaping bash function arguments for use by su -c I'd like to be able to write a function `su_mt_user` that (currently) looks like this: ``` su_mt_user() { su someuser -c "$*" } ``` The objective is to be able to use it like this: ``` su_mt_user mt-auth --stuff etc ``` Which would run the command `mt-auth --...
To pass multiple arguments through a function to a command, you need `"$@"`. `"$@"` is special in that even though it's between double quotes, the separate arguments end up in different words, so they're passed down exactly as is. This is different from `$@` or `$*` without quotes, which would additionally split each a...
11267015
how to ignore blank lines and comment lines using awk
6
2012-06-29 18:23:17
<p>i am writing this code:</p> <pre><code>awk -F'=' '!/^$/{arr[$1]=$2}END{for (x in arr) {print x"="arr[x]}}' 1.txt 2.txt </code></pre> <p>this code ignore blank lines, but i also want to ignore line starting with # (comments).</p> <p>Any idea how to add multiple patterns?</p>
21,520
1,486,386
2014-03-16 21:36:33
11,267,059
13
2012-06-29 18:26:22
47,529
2012-06-29 20:55:57
https://stackoverflow.com/q/11267015
https://stackoverflow.com/a/11267059
<p>Change <code>!/^$/</code> to</p> <pre><code>!/^($|#)/ </code></pre> <p>or</p> <pre><code>!/^($|[:space:]*#)/ </code></pre> <p>if you want to disregard whitespace before the <code>#</code>.</p>
<p>Change <code>!/^$/</code> to</p> <pre><code>!/^($|#)/ </code></pre> <p>or</p> <pre><code>!/^($|[:space:]*#)/ </code></pre> <p>if you want to disregard whitespace before the <code>#</code>.</p>
18, 58, 387, 990
awk, bash, linux, regex
<h1>how to ignore blank lines and comment lines using awk</h1> <p>i am writing this code:</p> <pre><code>awk -F'=' '!/^$/{arr[$1]=$2}END{for (x in arr) {print x"="arr[x]}}' 1.txt 2.txt </code></pre> <p>this code ignore blank lines, but i also want to ignore line starting with # (comments).</p> <p>Any idea how to add...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,582
bash
# how to ignore blank lines and comment lines using awk i am writing this code: ``` awk -F'=' '!/^$/{arr[$1]=$2}END{for (x in arr) {print x"="arr[x]}}' 1.txt 2.txt ``` this code ignore blank lines, but i also want to ignore line starting with # (comments). Any idea how to add multiple patterns?
Change `!/^$/` to ``` !/^($|#)/ ``` or ``` !/^($|[:space:]*#)/ ``` if you want to disregard whitespace before the `#`.
10658924
How to find the Set - Subset of two files from the command line?
6
2012-05-18 19:56:08
<p>I have two files with sorted lines. One file (B) is a subset of the other file (A). I would like to find all lines in A that ARE NOT in B. Ideally, I would like to create a file (C) that contains these lines. Is this possible in Unix? I'm looking for a one line command to do this instead of writing a script. I looke...
2,888
636,493
2012-06-13 12:56:38
10,659,032
13
2012-05-18 20:05:16
1,231,364
2012-06-13 12:56:38
https://stackoverflow.com/q/10658924
https://stackoverflow.com/a/10659032
<p>This will suppress common lines:</p> <pre><code>comm -3 a b </code></pre>
<p>This will suppress common lines:</p> <pre><code>comm -3 a b </code></pre>
34, 58, 387, 3791, 8470
bash, linux, set, unix, zsh
<h1>How to find the Set - Subset of two files from the command line?</h1> <p>I have two files with sorted lines. One file (B) is a subset of the other file (A). I would like to find all lines in A that ARE NOT in B. Ideally, I would like to create a file (C) that contains these lines. Is this possible in Unix? I'm look...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,583
bash
# How to find the Set - Subset of two files from the command line? I have two files with sorted lines. One file (B) is a subset of the other file (A). I would like to find all lines in A that ARE NOT in B. Ideally, I would like to create a file (C) that contains these lines. Is this possible in Unix? I'm looking for a...
This will suppress common lines: ``` comm -3 a b ```
10558439
Ruby cannot see NLS_LANG environmental variable
6
2012-05-11 20:50:32
<p>I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).</p> <p>I've set the NLS_LANG variable in .bash_profile.</p> <pre><code>[app@box stasis]$ echo $NLS_LANG en_US.UTF-8 [app@box stasis]$ which ruby ~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby </code></pre> <p>However when trying to access it via rub...
11,483
104,588
2012-05-13 22:57:40
10,559,031
13
2012-05-11 21:43:30
497,756
2012-05-11 21:43:30
https://stackoverflow.com/q/10558439
https://stackoverflow.com/a/10559031
<p>You need to export your variables to be available in any applications run (unless they are functions):</p> <pre><code>export NLS_LANG </code></pre> <p>or together with setting:</p> <pre><code>export NLS_LANG=en_US.UTF-8 </code></pre> <p>or as on most systems <code>LANG</code> should be available:</p> <pre><code...
<p>You need to export your variables to be available in any applications run (unless they are functions):</p> <pre><code>export NLS_LANG </code></pre> <p>or together with setting:</p> <pre><code>export NLS_LANG=en_US.UTF-8 </code></pre> <p>or as on most systems <code>LANG</code> should be available:</p> <pre><code...
12, 387, 8409
bash, oci8, ruby
<h1>Ruby cannot see NLS_LANG environmental variable</h1> <p>I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).</p> <p>I've set the NLS_LANG variable in .bash_profile.</p> <pre><code>[app@box stasis]$ echo $NLS_LANG en_US.UTF-8 [app@box stasis]$ which ruby ~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,584
bash
# Ruby cannot see NLS_LANG environmental variable I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3). I've set the NLS_LANG variable in .bash_profile. ``` [app@box stasis]$ echo $NLS_LANG en_US.UTF-8 [app@box stasis]$ which ruby ~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby ``` However when trying to ...
You need to export your variables to be available in any applications run (unless they are functions): ``` export NLS_LANG ``` or together with setting: ``` export NLS_LANG=en_US.UTF-8 ``` or as on most systems `LANG` should be available: ``` export NLS_LANG=$LANG ```
10447709
Pass action as Parameter on Command Prompt (Linux)
6
2012-05-04 11:13:29
<p>I have written a program in linux bash and following are ways to start/stop that program:</p> <pre><code>start_program stop_program restart_program. </code></pre> <p>I have copied above scripts in /usr/bin so these scripts are working as command. but I want that instead of above commands I just type program name t...
3,721
1,287,633
2018-02-20 04:40:24
10,447,808
13
2012-05-04 11:20:26
111,644
2012-05-04 12:21:00
https://stackoverflow.com/q/10447709
https://stackoverflow.com/a/10447808
<p>A common approach is to use a case statement:</p> <pre><code>case "$1" in start) # Your Start Code ;; stop) # Your Stop Code ;; restart) # Your Restart Code ;; *) echo "Usage: $0 {start|stop|restart}" &gt;&amp;2 exit 1 ;; esac </code></pre> <p>If your <code>restart</code...
<p>A common approach is to use a case statement:</p> <pre><code>case "$1" in start) # Your Start Code ;; stop) # Your Stop Code ;; restart) # Your Restart Code ;; *) echo "Usage: $0 {start|stop|restart}" &gt;&amp;2 exit 1 ;; esac </code></pre> <p>If your <code>restart</code...
58, 387, 390
bash, linux, shell
<h1>Pass action as Parameter on Command Prompt (Linux)</h1> <p>I have written a program in linux bash and following are ways to start/stop that program:</p> <pre><code>start_program stop_program restart_program. </code></pre> <p>I have copied above scripts in /usr/bin so these scripts are working as command. but I wa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,585
bash
# Pass action as Parameter on Command Prompt (Linux) I have written a program in linux bash and following are ways to start/stop that program: ``` start_program stop_program restart_program. ``` I have copied above scripts in /usr/bin so these scripts are working as command. but I want that instead of above commands...
A common approach is to use a case statement: ``` case "$1" in start) # Your Start Code ;; stop) # Your Stop Code ;; restart) # Your Restart Code ;; *) echo "Usage: $0 {start|stop|restart}" >&2 exit 1 ;; esac ``` If your `restart` is just `stop` then `start`, you can do: `...
9559582
echo from lines of a file
6
2012-03-04 22:48:50
<p>i have a file "myfile.txt" that have the next content:</p> <pre><code>hola mundo hello word </code></pre> <p>and i want work with every line </p> <pre><code>for i in `cat myfile.txt`; do echo $i; done </code></pre> <p>i hope this give me </p> <pre><code>hola mundo hello word </code></pre> <p>firts one line, th...
27,911
614,662
2012-03-04 22:54:37
9,559,595
13
2012-03-04 22:51:36
55,925
2012-03-04 22:51:36
https://stackoverflow.com/q/9559582
https://stackoverflow.com/a/9559595
<p>That's better</p> <pre><code>cat myfile.txt | while read line; do echo "$line" done </code></pre> <p>or even better (doesn't launch other processes such as a subshell and <code>cat</code>):</p> <pre><code>while read line; do echo "$line" done &lt; myfile.txt </code></pre> <p>If you prefer oneliners, it's...
<p>That's better</p> <pre><code>cat myfile.txt | while read line; do echo "$line" done </code></pre> <p>or even better (doesn't launch other processes such as a subshell and <code>cat</code>):</p> <pre><code>while read line; do echo "$line" done &lt; myfile.txt </code></pre> <p>If you prefer oneliners, it's...
387, 13824, 22820
bash, cat, echo
<h1>echo from lines of a file</h1> <p>i have a file "myfile.txt" that have the next content:</p> <pre><code>hola mundo hello word </code></pre> <p>and i want work with every line </p> <pre><code>for i in `cat myfile.txt`; do echo $i; done </code></pre> <p>i hope this give me </p> <pre><code>hola mundo hello word <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,586
bash
# echo from lines of a file i have a file "myfile.txt" that have the next content: ``` hola mundo hello word ``` and i want work with every line ``` for i in `cat myfile.txt`; do echo $i; done ``` i hope this give me ``` hola mundo hello word ``` firts one line, then the other, but get ``` hola mundo hello word...
That's better ``` cat myfile.txt | while read line; do echo "$line" done ``` or even better (doesn't launch other processes such as a subshell and `cat`): ``` while read line; do echo "$line" done < myfile.txt ``` If you prefer oneliners, it's obviously ``` while read line; do echo "$line"; done < myfile.t...
9265607
mkdir command for a list of filenames paths
6
2012-02-13 18:09:45
<p>I have txt file with content like this</p> <pre><code>/home/username/Desktop/folder/folder3333/IMAGw488.jpg /home/username/Desktop/folder/folder3333/IMAG04f88.jpg /home/username/Desktop/folder/folder3333/IMAGe0488.jpg /home/username/Desktop/folder/folder3333/IMAG0r88.jpg /home/username/Desktop/folder/folder3333/ /h...
15,806
706,780
2014-07-10 20:04:34
9,265,932
13
2012-02-13 18:35:24
207,248
2012-02-13 18:40:45
https://stackoverflow.com/q/9265607
https://stackoverflow.com/a/9265932
<p>This can be done in native <code>bash</code> syntax without any calls to external binaries:</p> <pre><code>while read line; do mkdir -p "${line%/*}"; done &lt; infile </code></pre> <p>Or perhaps with a just a single call to <code>mkdir</code> if you have <code>bash 4.x</code></p> <pre><code>mapfile -t arr &lt; in...
<p>This can be done in native <code>bash</code> syntax without any calls to external binaries:</p> <pre><code>while read line; do mkdir -p "${line%/*}"; done &lt; infile </code></pre> <p>Or perhaps with a just a single call to <code>mkdir</code> if you have <code>bash 4.x</code></p> <pre><code>mapfile -t arr &lt; in...
58, 387, 390, 549
bash, linux, shell, ubuntu
<h1>mkdir command for a list of filenames paths</h1> <p>I have txt file with content like this</p> <pre><code>/home/username/Desktop/folder/folder3333/IMAGw488.jpg /home/username/Desktop/folder/folder3333/IMAG04f88.jpg /home/username/Desktop/folder/folder3333/IMAGe0488.jpg /home/username/Desktop/folder/folder3333/IMAG...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,587
bash
# mkdir command for a list of filenames paths I have txt file with content like this ``` /home/username/Desktop/folder/folder3333/IMAGw488.jpg /home/username/Desktop/folder/folder3333/IMAG04f88.jpg /home/username/Desktop/folder/folder3333/IMAGe0488.jpg /home/username/Desktop/folder/folder3333/IMAG0r88.jpg /home/usern...
This can be done in native `bash` syntax without any calls to external binaries: ``` while read line; do mkdir -p "${line%/*}"; done < infile ``` Or perhaps with a just a single call to `mkdir` if you have `bash 4.x` ``` mapfile -t arr < infile; mkdir -p "${arr[@]%/*}" ```
8915681
Is there a command to return the owner of a file?
6
2012-01-18 18:53:36
<p>Is there a shell command to just print the owner of a file?</p> <p>I guess I could just do:</p> <pre><code>ls -l | awk '{print $3}' </code></pre> <p>but this feels like there would be a more straightforward answer to the problem.</p>
1,208
1,123,802
2012-01-18 19:15:40
8,915,705
13
2012-01-18 18:56:09
714,501
2012-01-18 18:56:09
https://stackoverflow.com/q/8915681
https://stackoverflow.com/a/8915705
<p>Try using <code>stat(1)</code></p> <pre><code>[cnicutar@fresh ~]$ stat -c %U file.c cnicutar </code></pre> <p>There are lots of format sequences available: user ID, total size, etc.</p>
<p>Try using <code>stat(1)</code></p> <pre><code>[cnicutar@fresh ~]$ stat -c %U file.c cnicutar </code></pre> <p>There are lots of format sequences available: user ID, total size, etc.</p>
58, 390, 531
linux, scripting, shell
<h1>Is there a command to return the owner of a file?</h1> <p>Is there a shell command to just print the owner of a file?</p> <p>I guess I could just do:</p> <pre><code>ls -l | awk '{print $3}' </code></pre> <p>but this feels like there would be a more straightforward answer to the problem.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,588
bash
# Is there a command to return the owner of a file? Is there a shell command to just print the owner of a file? I guess I could just do: ``` ls -l | awk '{print $3}' ``` but this feels like there would be a more straightforward answer to the problem.
Try using `stat(1)` ``` [cnicutar@fresh ~]$ stat -c %U file.c cnicutar ``` There are lots of format sequences available: user ID, total size, etc.
7265790
$SRCROOT not recognized in shell script attached to XCode project
6
2011-09-01 03:15:50
<p>Trying to run a simple script attached to my xcode project as follows...</p> <pre><code>if [ -d '$HOME/data' ]; then cd "$HOME/data/" rsync -t *.plist '$SRCROOT/data/' fi exit 0 </code></pre> <p>The script seems to run fine if I run it outside of XCode but when running from XCode I'm getting the following er...
6,194
7,285
2011-09-01 15:57:44
7,273,012
13
2011-09-01 15:57:44
7,285
2011-09-01 15:57:44
https://stackoverflow.com/q/7265790
https://stackoverflow.com/a/7273012
<p>Turns out this was my fault. The script was actually not being called at all. In XCode I was referring to the path of the script using...</p> <pre><code>"./$(SRCROOT)/myScript.sh" </code></pre> <p>Switching it to...</p> <pre><code>"$SRCROOT/myScript.sh" </code></pre> <p>Corrected the problem and indeed I can a...
<p>Turns out this was my fault. The script was actually not being called at all. In XCode I was referring to the path of the script using...</p> <pre><code>"./$(SRCROOT)/myScript.sh" </code></pre> <p>Switching it to...</p> <pre><code>"$SRCROOT/myScript.sh" </code></pre> <p>Corrected the problem and indeed I can a...
390, 908
shell, xcode
<h1>$SRCROOT not recognized in shell script attached to XCode project</h1> <p>Trying to run a simple script attached to my xcode project as follows...</p> <pre><code>if [ -d '$HOME/data' ]; then cd "$HOME/data/" rsync -t *.plist '$SRCROOT/data/' fi exit 0 </code></pre> <p>The script seems to run fine if I run i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,589
bash
# $SRCROOT not recognized in shell script attached to XCode project Trying to run a simple script attached to my xcode project as follows... ``` if [ -d '$HOME/data' ]; then cd "$HOME/data/" rsync -t *.plist '$SRCROOT/data/' fi exit 0 ``` The script seems to run fine if I run it outside of XCode but when runni...
Turns out this was my fault. The script was actually not being called at all. In XCode I was referring to the path of the script using... ``` "./$(SRCROOT)/myScript.sh" ``` Switching it to... ``` "$SRCROOT/myScript.sh" ``` Corrected the problem and indeed I can access $SRCROOT from my script now.
7198281
Self-Deleting Script for both Linux Bash and Windows Batch
6
2011-08-25 23:14:00
<p>I have an uninstall script that cleans up an add-on tool used with an application. Versions of the script run on both Windows and Linux.</p> <p>I'd like to be able to delete the uninstall script file and also the directory in which the script runs too (in both the case of a Windows batch file and also for the case ...
8,417
913,102
2017-01-20 18:16:01
7,198,324
13
2011-08-25 23:19:14
487,509
2017-01-20 18:16:01
https://stackoverflow.com/q/7198281
https://stackoverflow.com/a/7198324
<p>In Bash, you can do</p> <pre><code>#!/bin/bash # do your uninstallation here # ... # and now remove the script rm $0 # and the entire directory rmdir `dirname $0` </code></pre>
<p>In Bash, you can do</p> <pre><code>#!/bin/bash # do your uninstallation here # ... # and now remove the script rm $0 # and the entire directory rmdir `dirname $0` </code></pre>
64, 387, 7002, 24431
bash, batch-file, self-destruction, windows
<h1>Self-Deleting Script for both Linux Bash and Windows Batch</h1> <p>I have an uninstall script that cleans up an add-on tool used with an application. Versions of the script run on both Windows and Linux.</p> <p>I'd like to be able to delete the uninstall script file and also the directory in which the script runs ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,590
bash
# Self-Deleting Script for both Linux Bash and Windows Batch I have an uninstall script that cleans up an add-on tool used with an application. Versions of the script run on both Windows and Linux. I'd like to be able to delete the uninstall script file and also the directory in which the script runs too (in both the...
In Bash, you can do ``` #!/bin/bash # do your uninstallation here # ... # and now remove the script rm $0 # and the entire directory rmdir `dirname $0` ```
6958982
Shell script, saving the command value to a variable
6
2011-08-05 15:43:28
<p>I am trying to print the value of <code>VARI</code> in the same line followed by a comma, so that i can have a csv file of these values, but i m not able to save the value of <code>VARI = 'cat filename | head -1 | cut -d, -f${i}'</code></p> <pre><code>i=0 while (( i&lt;130)) ; do if [[ $i -eq 1 || $i -eq 9 || ...
9,890
794,403
2023-10-18 05:28:39
6,959,031
13
2011-08-05 15:47:44
112,968
2023-10-18 05:28:39
https://stackoverflow.com/q/6958982
https://stackoverflow.com/a/6959031
<p>Use backticks (or <code>$()</code> which can be nested), not single quotes:</p> <pre><code>VARI=`cat filename | head -1 | cut -d, -f${i}` # or: VARI=$(cat filename | head -1 | cut -d, -f${i}) </code></pre> <p>Make sure to not have spaces between the variable name, the equal sign, and the variable value.</p> <pre><co...
<p>Use backticks (or <code>$()</code> which can be nested), not single quotes:</p> <pre><code>VARI=`cat filename | head -1 | cut -d, -f${i}` # or: VARI=$(cat filename | head -1 | cut -d, -f${i}) </code></pre> <p>Make sure to not have spaces between the variable name, the equal sign, and the variable value.</p> <pre><co...
58, 390, 13824
echo, linux, shell
<h1>Shell script, saving the command value to a variable</h1> <p>I am trying to print the value of <code>VARI</code> in the same line followed by a comma, so that i can have a csv file of these values, but i m not able to save the value of <code>VARI = 'cat filename | head -1 | cut -d, -f${i}'</code></p> <pre><code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,591
bash
# Shell script, saving the command value to a variable I am trying to print the value of `VARI` in the same line followed by a comma, so that i can have a csv file of these values, but i m not able to save the value of `VARI = 'cat filename | head -1 | cut -d, -f${i}'` ``` i=0 while (( i<130)) ; do if [[ $i -eq 1 |...
Use backticks (or `$()` which can be nested), not single quotes: ``` VARI=`cat filename | head -1 | cut -d, -f${i}` # or: VARI=$(cat filename | head -1 | cut -d, -f${i}) ``` Make sure to not have spaces between the variable name, the equal sign, and the variable value. ``` VAR = x # executes program "VAR" with 2 par...
6197165
Getting a PID from a Background Process Run as Another User
6
2011-06-01 06:33:35
<p>Getting a background process ID is easy to do from the prompt by going:</p> <pre><code>$ my_daemon &amp; $ echo $! </code></pre> <p>But what if I want to run it as a different user like:</p> <pre><code>su - joe -c "/path/to/my_daemon &amp;;" </code></pre> <p>Now how can I capture the PID of my_daemon?</p>
7,529
148,390
2020-09-10 18:54:33
6,197,321
13
2011-06-01 06:51:29
15,168
2011-06-01 06:51:29
https://stackoverflow.com/q/6197165
https://stackoverflow.com/a/6197321
<p>Succinctly - with a good deal of difficulty.</p> <p>You have to arrange for the su'd shell to write the child PID to a file and then pick the output. Given that it will be 'joe' creating the file and not 'dex', that adds another layer of complexity.</p> <p>The simplest solution is probably:</p> <pre><code>su - j...
<p>Succinctly - with a good deal of difficulty.</p> <p>You have to arrange for the su'd shell to write the child PID to a file and then pick the output. Given that it will be 'joe' creating the file and not 'dex', that adds another layer of complexity.</p> <p>The simplest solution is probably:</p> <pre><code>su - j...
387, 3300, 13784
bash, pid, su
<h1>Getting a PID from a Background Process Run as Another User</h1> <p>Getting a background process ID is easy to do from the prompt by going:</p> <pre><code>$ my_daemon &amp; $ echo $! </code></pre> <p>But what if I want to run it as a different user like:</p> <pre><code>su - joe -c "/path/to/my_daemon &amp;;" </c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,592
bash
# Getting a PID from a Background Process Run as Another User Getting a background process ID is easy to do from the prompt by going: ``` $ my_daemon & $ echo $! ``` But what if I want to run it as a different user like: ``` su - joe -c "/path/to/my_daemon &;" ``` Now how can I capture the PID of my_daemon?
Succinctly - with a good deal of difficulty. You have to arrange for the su'd shell to write the child PID to a file and then pick the output. Given that it will be 'joe' creating the file and not 'dex', that adds another layer of complexity. The simplest solution is probably: ``` su - joe -c "/path/to/my_daemon & e...
4814006
Can I assume bash is installed
6
2011-01-27 08:08:30
<p>I have a cross platform product that gets deployed to several Linux distros and I'm busy changing one of its startup scripts. Currently the script uses /bin/sh as interpreter. My question is. How safe am I if I change this to /bin/bash, will there be some cases that bash is not installed or something. Why does all t...
3,113
45,390
2011-08-30 09:02:44
4,814,062
13
2011-01-27 08:19:44
207,248
2011-01-27 08:19:44
https://stackoverflow.com/q/4814006
https://stackoverflow.com/a/4814062
<blockquote> <p>Can I assume bash is installed</p> </blockquote> <p>If portability is a goal, you would be doing yourself a disservice to assume <code>bash</code> was installed. That is not to say that <code>bash</code> won't be installed 99% of the time, but it's the 1% that gets ya. </p> <blockquote> <p>How s...
<blockquote> <p>Can I assume bash is installed</p> </blockquote> <p>If portability is a goal, you would be doing yourself a disservice to assume <code>bash</code> was installed. That is not to say that <code>bash</code> won't be installed 99% of the time, but it's the 1% that gets ya. </p> <blockquote> <p>How s...
58, 387, 1012
bash, debian, linux
<h1>Can I assume bash is installed</h1> <p>I have a cross platform product that gets deployed to several Linux distros and I'm busy changing one of its startup scripts. Currently the script uses /bin/sh as interpreter. My question is. How safe am I if I change this to /bin/bash, will there be some cases that bash is no...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,593
bash
# Can I assume bash is installed I have a cross platform product that gets deployed to several Linux distros and I'm busy changing one of its startup scripts. Currently the script uses /bin/sh as interpreter. My question is. How safe am I if I change this to /bin/bash, will there be some cases that bash is not install...
> Can I assume bash is installed If portability is a goal, you would be doing yourself a disservice to assume `bash` was installed. That is not to say that `bash` won't be installed 99% of the time, but it's the 1% that gets ya. > How safe am I if I change this to /bin/bash, will there be some cases that bash is not ...
4346947
How can I change where unix pipe sends its results for the split command?
6
2010-12-03 15:22:34
<p>Basically I'm doing this:</p> <pre><code>export_something | split -b 1000 </code></pre> <p>which splits the results of the export into files names xaa, xab, xac all 1000 bytes each</p> <p>but I want my output from split to go into files with a specific-prefix. Ordinarily I'd just do this:</p> <pre><code>split -b...
4,316
18,818
2010-12-03 15:26:50
4,346,974
13
2010-12-03 15:25:55
514,460
2010-12-03 15:25:55
https://stackoverflow.com/q/4346947
https://stackoverflow.com/a/4346974
<p>Yes, <code>-</code> is commonly used to denote stdin or stdout, whichever makes more sense. In your example</p> <pre><code>export_something | split -b 1000 - &lt;prefix&gt; </code></pre>
<p>Yes, <code>-</code> is commonly used to denote stdin or stdout, whichever makes more sense. In your example</p> <pre><code>export_something | split -b 1000 - &lt;prefix&gt; </code></pre>
34, 387, 390, 5813
bash, pipe, shell, unix
<h1>How can I change where unix pipe sends its results for the split command?</h1> <p>Basically I'm doing this:</p> <pre><code>export_something | split -b 1000 </code></pre> <p>which splits the results of the export into files names xaa, xab, xac all 1000 bytes each</p> <p>but I want my output from split to go into ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,594
bash
# How can I change where unix pipe sends its results for the split command? Basically I'm doing this: ``` export_something | split -b 1000 ``` which splits the results of the export into files names xaa, xab, xac all 1000 bytes each but I want my output from split to go into files with a specific-prefix. Ordinarily...
Yes, `-` is commonly used to denote stdin or stdout, whichever makes more sense. In your example ``` export_something | split -b 1000 - <prefix> ```
3869102
Putty closes on executing bash script
6
2010-10-06 02:21:33
<p>I am writing my first ever bash script, so excuse the noobie-ness. </p> <p>It's called hello.bash, and this is what it contains:</p> <pre><code>#!/bin/bash echo Hello World </code></pre> <p>I did </p> <pre><code>chmod 700 hello.bash </code></pre> <p>to give myself permissions to execute.</p> <p>Now, when I typ...
3,259
315,828
2010-10-06 02:28:45
3,869,131
13
2010-10-06 02:28:45
2,611
2010-10-06 02:28:45
https://stackoverflow.com/q/3869102
https://stackoverflow.com/a/3869131
<p>From the <a href="http://ss64.com/bash/exec.html" rel="noreferrer">man page</a> for exec:</p> <blockquote> <p>If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment.</p> </blockquote> <p>So your sc...
<p>From the <a href="http://ss64.com/bash/exec.html" rel="noreferrer">man page</a> for exec:</p> <blockquote> <p>If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment.</p> </blockquote> <p>So your sc...
387, 1768
bash, putty
<h1>Putty closes on executing bash script</h1> <p>I am writing my first ever bash script, so excuse the noobie-ness. </p> <p>It's called hello.bash, and this is what it contains:</p> <pre><code>#!/bin/bash echo Hello World </code></pre> <p>I did </p> <pre><code>chmod 700 hello.bash </code></pre> <p>to give myself ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,595
bash
# Putty closes on executing bash script I am writing my first ever bash script, so excuse the noobie-ness. It's called hello.bash, and this is what it contains: ``` #!/bin/bash echo Hello World ``` I did ``` chmod 700 hello.bash ``` to give myself permissions to execute. Now, when I type ``` exec hello.bash ```...
From the [man page](http://ss64.com/bash/exec.html) for exec: > If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment. So your script process runs in place of your terminal and when it exits, so does y...
3814097
Declaring User Defined Variable in Shell Scripting (csh shell)
6
2010-09-28 15:00:12
<p>I am trying to learn shell scripting and trying to create a user defined variable within the script, <code>first</code>:</p> <pre><code>howdy="Hello $USER !" echo $howdy </code></pre> <p>However, when I execute the script (<code>./first</code>) I get this:</p> <pre><code>howdy=Hello aaron!: Command not found. how...
50,221
363,829
2016-08-19 13:04:27
3,814,245
13
2010-09-28 15:15:34
45,318
2016-08-19 13:04:27
https://stackoverflow.com/q/3814097
https://stackoverflow.com/a/3814245
<p>You have two errors in you code:</p> <ol> <li>you are using sh syntax instead of csh one to set the variable</li> <li>you are not escaping the "!" character (history substitution)</li> </ol> <p>Try this:</p> <pre><code>#!/bin/csh set howdy="Hello $USER \!" echo $howdy </code></pre>
<p>You have two errors in you code:</p> <ol> <li>you are using sh syntax instead of csh one to set the variable</li> <li>you are not escaping the "!" character (history substitution)</li> </ol> <p>Try this:</p> <pre><code>#!/bin/csh set howdy="Hello $USER \!" echo $howdy </code></pre>
58, 390, 2829
csh, linux, shell
<h1>Declaring User Defined Variable in Shell Scripting (csh shell)</h1> <p>I am trying to learn shell scripting and trying to create a user defined variable within the script, <code>first</code>:</p> <pre><code>howdy="Hello $USER !" echo $howdy </code></pre> <p>However, when I execute the script (<code>./first</code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,596
bash
# Declaring User Defined Variable in Shell Scripting (csh shell) I am trying to learn shell scripting and trying to create a user defined variable within the script, `first`: ``` howdy="Hello $USER !" echo $howdy ``` However, when I execute the script (`./first`) I get this: ``` howdy=Hello aaron!: Command not foun...
You have two errors in you code: 1. you are using sh syntax instead of csh one to set the variable 2. you are not escaping the "!" character (history substitution) Try this: ``` #!/bin/csh set howdy="Hello $USER \!" echo $howdy ```
2987625
How can I access windows file preview icons from my WPF application
6
2010-06-07 07:04:35
<p>I got a bunch of Pictures and Videos in a directory and needs to be displayed in the WPF application, I am thinking about displaying the Win7 Large Icon itself as the preview image. Because that will save me the work of grabbing an appropriate frame from the video file since Windows is doing that job pretty well alr...
4,974
8,091
2018-03-07 09:55:13
2,994,451
13
2010-06-08 02:33:45
130,689
2018-03-07 09:55:13
https://stackoverflow.com/q/2987625
https://stackoverflow.com/a/2994451
<p>When using the <a href="https://github.com/contre/Windows-API-Code-Pack-1.1" rel="nofollow noreferrer">Windows API Code Pack</a>, you can do:</p> <p>XAML</p> <pre><code> &lt;Image x:Name="img" /&gt; </code></pre> <p>C#</p> <pre><code> img.Source = ShellFile.FromFilePath(@"C:\path\to\file.ext").Thumbnail.BitmapSo...
<p>When using the <a href="https://github.com/contre/Windows-API-Code-Pack-1.1" rel="nofollow noreferrer">Windows API Code Pack</a>, you can do:</p> <p>XAML</p> <pre><code> &lt;Image x:Name="img" /&gt; </code></pre> <p>C#</p> <pre><code> img.Source = ShellFile.FromFilePath(@"C:\path\to\file.ext").Thumbnail.BitmapSo...
378, 8123, 8421
thumbnails, windows-shell, wpf
<h1>How can I access windows file preview icons from my WPF application</h1> <p>I got a bunch of Pictures and Videos in a directory and needs to be displayed in the WPF application, I am thinking about displaying the Win7 Large Icon itself as the preview image. Because that will save me the work of grabbing an appropri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,597
bash
# How can I access windows file preview icons from my WPF application I got a bunch of Pictures and Videos in a directory and needs to be displayed in the WPF application, I am thinking about displaying the Win7 Large Icon itself as the preview image. Because that will save me the work of grabbing an appropriate frame...
When using the [Windows API Code Pack](https://github.com/contre/Windows-API-Code-Pack-1.1), you can do: XAML ``` <Image x:Name="img" /> ``` C# ``` img.Source = ShellFile.FromFilePath(@"C:\path\to\file.ext").Thumbnail.BitmapSource; ``` This requires adding the [`Microsoft-WindowsAPICodePack-Shell`](https://www.n...
2786102
GUNZIP / Extract file "portion by portion"
6
2010-05-07 03:56:47
<p>I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thing even temporarily!</p> <p>No, this is just ONE sup...
2,876
1,154,992
2010-05-07 05:53:54
2,786,159
13
2010-05-07 04:14:37
275,737
2010-05-07 04:14:37
https://stackoverflow.com/q/2786102
https://stackoverflow.com/a/2786159
<p>If you're doing this with (Unix/Linux) shell tools, you can use <code>gunzip -c</code> to uncompress to stdout, then use <code>dd</code> with the <code>skip</code> and <code>count</code> options to copy only one chunk.</p> <p>For example:</p> <pre><code>gunzip -c input.gz | dd bs=10485760 skip=0 count=1 &gt;output...
<p>If you're doing this with (Unix/Linux) shell tools, you can use <code>gunzip -c</code> to uncompress to stdout, then use <code>dd</code> with the <code>skip</code> and <code>count</code> options to copy only one chunk.</p> <p>For example:</p> <pre><code>gunzip -c input.gz | dd bs=10485760 skip=0 count=1 &gt;output...
76, 390, 1930, 26457
compression, gunzip, gzip, shell
<h1>GUNZIP / Extract file "portion by portion"</h1> <p>I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,598
bash
# GUNZIP / Extract file "portion by portion" I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thing even te...
If you're doing this with (Unix/Linux) shell tools, you can use `gunzip -c` to uncompress to stdout, then use `dd` with the `skip` and `count` options to copy only one chunk. For example: ``` gunzip -c input.gz | dd bs=10485760 skip=0 count=1 >output ``` then skip=1, skip=2, etc.
2330014
Is there a simple way in linux to strip a website of text from command line?
6
2010-02-24 22:12:28
<p>I've been searching for a command line tool that would turn html code into just the text that would appear on the site... so it would be equivalent to in a web browser selecting everything and then pasting it into a text editor...</p> <p>Anyone know of something in Ubuntu that would do this? I'm trying to write a ...
4,006
110,797
2010-02-24 22:22:04
2,330,038
13
2010-02-24 22:15:57
20,862
2010-02-24 22:15:57
https://stackoverflow.com/q/2330014
https://stackoverflow.com/a/2330038
<pre><code>lynx -dump http://example.com/ </code></pre>
<pre><code>lynx -dump http://example.com/ </code></pre>
2, 58, 387, 1357
bash, html, linux, parsing
<h1>Is there a simple way in linux to strip a website of text from command line?</h1> <p>I've been searching for a command line tool that would turn html code into just the text that would appear on the site... so it would be equivalent to in a web browser selecting everything and then pasting it into a text editor...<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,599
bash
# Is there a simple way in linux to strip a website of text from command line? I've been searching for a command line tool that would turn html code into just the text that would appear on the site... so it would be equivalent to in a web browser selecting everything and then pasting it into a text editor... Anyone k...
``` lynx -dump http://example.com/ ```
628277
Is there a shell command to recursively give permission to directories and files?
6
2009-03-09 22:27:28
<p>Can someone please give me a recursive command that will go through a directory and make all normal files permission 644 and all sub directories 755?</p> <p>I am really getting tired of doing this manually every time I have to install something on my host. I don't know enough BASH (Shell?) command to do this.</p>
6,327
51,649
2009-03-09 22:50:16
628,285
13
2009-03-09 22:30:17
12,547
2009-03-09 22:38:27
https://stackoverflow.com/q/628277
https://stackoverflow.com/a/628285
<p>First line changes file permissions, and the second changes directory permissions in the active directory and its subdirectories.</p> <pre><code>find . -type f -print0 | xargs -0 chmod 644 find . -type d -print0 | xargs -0 chmod 755 </code></pre>
<p>First line changes file permissions, and the second changes directory permissions in the active directory and its subdirectories.</p> <pre><code>find . -type f -print0 | xargs -0 chmod 644 find . -type d -print0 | xargs -0 chmod 755 </code></pre>
387, 390, 1231
bash, command-line, shell
<h1>Is there a shell command to recursively give permission to directories and files?</h1> <p>Can someone please give me a recursive command that will go through a directory and make all normal files permission 644 and all sub directories 755?</p> <p>I am really getting tired of doing this manually every time I have t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,600
bash
# Is there a shell command to recursively give permission to directories and files? Can someone please give me a recursive command that will go through a directory and make all normal files permission 644 and all sub directories 755? I am really getting tired of doing this manually every time I have to install someth...
First line changes file permissions, and the second changes directory permissions in the active directory and its subdirectories. ``` find . -type f -print0 | xargs -0 chmod 644 find . -type d -print0 | xargs -0 chmod 755 ```
19122755
Output ("echo") a variable to a text file
69
2013-10-01 17:53:27
<p>I'm running a PowerShell script against many servers, and it is logging output to a text file.</p> <p>I'd like to capture the server the script is currently running on. So far I have:</p> <pre><code>$file = "\\server\share\file.txt" $computername = $env:computername $computername | Add-Content -Path $file </code>...
275,404
1,483,127
2025-02-16 03:07:29
19,123,018
12
2013-10-01 18:11:23
1,483,127
2017-05-28 22:16:33
https://stackoverflow.com/q/19122755
https://stackoverflow.com/a/19123018
<p>After some trial and error, I found that</p> <pre><code>$computername = $env:computername </code></pre> <p>works to get a computer name, but sending <code>$computername</code> to a file via <a href="http://technet.microsoft.com/en-us/library/hh849859.aspx" rel="noreferrer">Add-Content</a> doesn't work.</p> <p>I a...
<p>After some trial and error, I found that</p> <pre><code>$computername = $env:computername </code></pre> <p>works to get a computer name, but sending <code>$computername</code> to a file via <a href="http://technet.microsoft.com/en-us/library/hh849859.aspx" rel="noreferrer">Add-Content</a> doesn't work.</p> <p>I a...
526, 724
file-io, powershell
<h1>Output ("echo") a variable to a text file</h1> <p>I'm running a PowerShell script against many servers, and it is logging output to a text file.</p> <p>I'd like to capture the server the script is currently running on. So far I have:</p> <pre><code>$file = "\\server\share\file.txt" $computername = $env:computerna...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,601
bash
# Output ("echo") a variable to a text file I'm running a PowerShell script against many servers, and it is logging output to a text file. I'd like to capture the server the script is currently running on. So far I have: ``` $file = "\\server\share\file.txt" $computername = $env:computername $computername | Add-Con...
After some trial and error, I found that ``` $computername = $env:computername ``` works to get a computer name, but sending `$computername` to a file via [Add-Content](http://technet.microsoft.com/en-us/library/hh849859.aspx) doesn't work. I also tried `$computername.Value`. Instead, if I use ``` $computername = ...
29688115
How do I check if an environment variable is set in cmake
53
2015-04-17 00:15:52
<p>I set an environment variable in my bash profile, so I can see it in the terminal just fine . .</p> <blockquote> <p>blah/builds$ echo $THING</p> <p>thingy</p> </blockquote> <p>How do I display it in a cmake message and check if it is set? I have tried the following, but it just displays thing as blank and skips the ...
69,499
276,193
2019-07-31 11:03:47
32,904,761
12
2015-10-02 09:55:00
396,967
2015-10-02 09:55:00
https://stackoverflow.com/q/29688115
https://stackoverflow.com/a/32904761
<p>You CMake code is correct. The problem is most likely that you only <em>set</em> the environment variable in your shell but did not <em>export</em> it. Run the following before invoking <code>cmake</code>:</p> <pre><code>export THING </code></pre>
<p>You CMake code is correct. The problem is most likely that you only <em>set</em> the environment variable in your shell but did not <em>export</em> it. Run the following before invoking <code>cmake</code>:</p> <pre><code>export THING </code></pre>
387, 8822, 9013
bash, cmake, environment-variables
<h1>How do I check if an environment variable is set in cmake</h1> <p>I set an environment variable in my bash profile, so I can see it in the terminal just fine . .</p> <blockquote> <p>blah/builds$ echo $THING</p> <p>thingy</p> </blockquote> <p>How do I display it in a cmake message and check if it is set? I have trie...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,602
bash
# How do I check if an environment variable is set in cmake I set an environment variable in my bash profile, so I can see it in the terminal just fine . . > blah/builds$ echo $THING > > thingy How do I display it in a cmake message and check if it is set? I have tried the following, but it just displays thing as bl...
You CMake code is correct. The problem is most likely that you only *set* the environment variable in your shell but did not *export* it. Run the following before invoking `cmake`: ``` export THING ```
15293406
Install zsh without root access?
49
2013-03-08 11:54:23
<p>Is it possible (and how)? I really need this for several remote computers where I've got ssh access (but no root access).</p>
37,531
1,444,689
2019-03-01 16:15:51
15,293,550
12
2013-03-08 12:00:28
1,416,629
2013-03-08 12:03:32
https://stackoverflow.com/q/15293406
https://stackoverflow.com/a/15293550
<p>You can try the <code>chsh</code> command. Are you sure zsh isn't installed on the distant computer? If not, you can do this (quoted from <a href="http://zsh.sourceforge.net/FAQ/zshfaq01.html" rel="noreferrer">zsh FAQ Section 1.7</a>)</p> <p>The basic idea is to use exec to replace the current shell with zsh. Ofte...
<p>You can try the <code>chsh</code> command. Are you sure zsh isn't installed on the distant computer? If not, you can do this (quoted from <a href="http://zsh.sourceforge.net/FAQ/zshfaq01.html" rel="noreferrer">zsh FAQ Section 1.7</a>)</p> <p>The basic idea is to use exec to replace the current shell with zsh. Ofte...
58, 387, 390, 391, 3791
bash, linux, shell, terminal, zsh
<h1>Install zsh without root access?</h1> <p>Is it possible (and how)? I really need this for several remote computers where I've got ssh access (but no root access).</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,603
bash
# Install zsh without root access? Is it possible (and how)? I really need this for several remote computers where I've got ssh access (but no root access).
You can try the `chsh` command. Are you sure zsh isn't installed on the distant computer? If not, you can do this (quoted from [zsh FAQ Section 1.7](http://zsh.sourceforge.net/FAQ/zshfaq01.html)) The basic idea is to use exec to replace the current shell with zsh. Often you can do this in a login file such as .profile...
967443
Python module to shellquote/unshellquote?
39
2009-06-08 22:56:09
<p>Is there anything in the Python standard library that will properly parse/unparse strings for using in shell commands? I'm looking for the python analog to perl's <code>String::ShellQuote::shell_quote</code>:</p> <pre><code>$ print String::ShellQuote::shell_quote("hello", "stack", "overflow's", "quite", "cool") hel...
20,066
54,873
2015-01-26 08:59:18
25,147,580
12
2014-08-05 20:19:03
1,733,117
2014-08-05 20:19:03
https://stackoverflow.com/q/967443
https://stackoverflow.com/a/25147580
<p><code>pipes.quote</code> is now <code>shlex.quote</code> in python 3. It is easy enough to use that piece of code.</p> <p><a href="https://github.com/python/cpython/blob/master/Lib/shlex.py#L281" rel="noreferrer">https://github.com/python/cpython/blob/master/Lib/shlex.py#L281</a></p> <p>That version handles zero-l...
<p><code>pipes.quote</code> is now <code>shlex.quote</code> in python 3. It is easy enough to use that piece of code.</p> <p><a href="https://github.com/python/cpython/blob/master/Lib/shlex.py#L281" rel="noreferrer">https://github.com/python/cpython/blob/master/Lib/shlex.py#L281</a></p> <p>That version handles zero-l...
16, 390, 10804
python, quoting, shell
<h1>Python module to shellquote/unshellquote?</h1> <p>Is there anything in the Python standard library that will properly parse/unparse strings for using in shell commands? I'm looking for the python analog to perl's <code>String::ShellQuote::shell_quote</code>:</p> <pre><code>$ print String::ShellQuote::shell_quote("...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,604
bash
# Python module to shellquote/unshellquote? Is there anything in the Python standard library that will properly parse/unparse strings for using in shell commands? I'm looking for the python analog to perl's `String::ShellQuote::shell_quote`: ``` $ print String::ShellQuote::shell_quote("hello", "stack", "overflow's", ...
`pipes.quote` is now `shlex.quote` in python 3. It is easy enough to use that piece of code. <https://github.com/python/cpython/blob/master/Lib/shlex.py#L281> That version handles zero-length argument correctly.
22080937
Skip blank lines when iterating through file line by line
38
2014-02-27 21:33:53
<p>I am iterating through a file line by line and put each word into a array and that works. But it also picks up blank lines and puts it as an item in the array, how can I skip the blank lines?</p> <p>example file</p> <pre><code> Line 1 line 2 line 3 line 4 line 5 line 6 </code></pre> <p>My code</p...
86,744
3,338,990
2024-09-30 00:06:04
22,081,036
12
2014-02-27 21:38:42
1,323,940
2014-02-28 06:52:19
https://stackoverflow.com/q/22080937
https://stackoverflow.com/a/22081036
<p>Remove the blank lines first with <code>sed</code>.</p> <pre><code>for word in `sed '/^$/d' $inputfile`; do myarray[$index]="$word" index=$(($index+1)) done </code></pre>
<p>Remove the blank lines first with <code>sed</code>.</p> <pre><code>for word in `sed '/^$/d' $inputfile`; do myarray[$index]="$word" index=$(($index+1)) done </code></pre>
387
bash
<h1>Skip blank lines when iterating through file line by line</h1> <p>I am iterating through a file line by line and put each word into a array and that works. But it also picks up blank lines and puts it as an item in the array, how can I skip the blank lines?</p> <p>example file</p> <pre><code> Line 1 line 2 l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,605
bash
# Skip blank lines when iterating through file line by line I am iterating through a file line by line and put each word into a array and that works. But it also picks up blank lines and puts it as an item in the array, how can I skip the blank lines? example file ``` Line 1 line 2 line 3 line 4 lin...
Remove the blank lines first with `sed`. ``` for word in `sed '/^$/d' $inputfile`; do myarray[$index]="$word" index=$(($index+1)) done ```
6387907
Whether to escape ( and ) in regex using GNU sed
37
2011-06-17 15:13:16
<p>I've noticed several posts on this site which say that with gnu sed you should use <code>(</code> and <code>)</code> in regex rather than <code>\(</code> and <code>\)</code>. But then I looked in the <a href="http://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command" rel="noreferrer">gnu sed manual</a...
33,938
749,668
2023-03-14 20:29:59
6,390,351
12
2011-06-17 18:46:38
749,668
2011-06-17 18:46:38
https://stackoverflow.com/q/6387907
https://stackoverflow.com/a/6390351
<p>Thanks to rocker, murga, and chris. Each of you helped me understand the issue. I'm answering my own question here in order to (hopefully) put the whole story together in one place.</p> <p>There are two major versions of sed in use: gnu and bsd. Both of them require parens in basic regex to be escaped when used ...
<p>Thanks to rocker, murga, and chris. Each of you helped me understand the issue. I'm answering my own question here in order to (hopefully) put the whole story together in one place.</p> <p>There are two major versions of sed in use: gnu and bsd. Both of them require parens in basic regex to be escaped when used ...
18, 387, 4072, 5282
bash, gnu, regex, sed
<h1>Whether to escape ( and ) in regex using GNU sed</h1> <p>I've noticed several posts on this site which say that with gnu sed you should use <code>(</code> and <code>)</code> in regex rather than <code>\(</code> and <code>\)</code>. But then I looked in the <a href="http://www.gnu.org/software/sed/manual/sed.html#T...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,606
bash
# Whether to escape ( and ) in regex using GNU sed I've noticed several posts on this site which say that with gnu sed you should use `(` and `)` in regex rather than `\(` and `\)`. But then I looked in the [gnu sed manual](http://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command) and saw that they spec...
Thanks to rocker, murga, and chris. Each of you helped me understand the issue. I'm answering my own question here in order to (hopefully) put the whole story together in one place. There are two major versions of sed in use: gnu and bsd. Both of them require parens in basic regex to be escaped when used for grouping ...
14765569
How to test if multiple files exist using a Bash script
32
2013-02-08 04:15:27
<p>How can I use the <code>test</code> command for an arbitrary number of files, passed in using an argument with a wildcard?</p> <p>For example:</p> <pre><code>test -f /var/log/apache2/access.log.* &amp;&amp; echo &quot;exists one or more files&quot; </code></pre> <p>Currently, it prints</p> <pre><code>error: bash: te...
93,973
526,444
2024-06-01 02:01:19
14,765,676
12
2013-02-08 04:27:46
844,759
2022-04-08 22:00:07
https://stackoverflow.com/q/14765569
https://stackoverflow.com/a/14765676
<p>To avoid &quot;too many arguments error&quot;, you need <code>xargs</code>. Unfortunately, <code>test -f</code> doesn't support multiple files. The following one-liner should work:</p> <pre><code>for i in /var/log/apache2/access.log.*; do test -f &quot;$i&quot; &amp;&amp; echo &quot;exists one or more files&quot; &a...
<p>To avoid &quot;too many arguments error&quot;, you need <code>xargs</code>. Unfortunately, <code>test -f</code> doesn't support multiple files. The following one-liner should work:</p> <pre><code>for i in /var/log/apache2/access.log.*; do test -f &quot;$i&quot; &amp;&amp; echo &quot;exists one or more files&quot; &a...
387
bash
<h1>How to test if multiple files exist using a Bash script</h1> <p>How can I use the <code>test</code> command for an arbitrary number of files, passed in using an argument with a wildcard?</p> <p>For example:</p> <pre><code>test -f /var/log/apache2/access.log.* &amp;&amp; echo &quot;exists one or more files&quot; </c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,607
bash
# How to test if multiple files exist using a Bash script How can I use the `test` command for an arbitrary number of files, passed in using an argument with a wildcard? For example: ``` test -f /var/log/apache2/access.log.* && echo "exists one or more files" ``` Currently, it prints ``` error: bash: test: too man...
To avoid "too many arguments error", you need `xargs`. Unfortunately, `test -f` doesn't support multiple files. The following one-liner should work: ``` for i in /var/log/apache2/access.log.*; do test -f "$i" && echo "exists one or more files" && break; done ``` By the way, `/var/log/apache2/access.log.*` is called s...
22464786
Ignoring Bash pipefail for error code 141
31
2014-03-17 20:35:08
<p>Setting the bash <code>pipefail</code> option (via <code>set -o pipefail</code>) allows the script to fail if a non-zero error is caught where there is a non-zero error in any step of a pipe.</p> <p>However, we are running into <code>SIGPIPE</code> errors (error code 141), where data is written to a pipe that no lo...
16,665
19,410
2022-11-15 12:21:03
22,464,942
12
2014-03-17 20:43:13
1,126,841
2014-03-17 20:43:13
https://stackoverflow.com/q/22464786
https://stackoverflow.com/a/22464942
<p>The <code>trap</code> command lets you specify a command to run when encountering a signal. To ignore a signal, pass the empty string:</p> <pre><code>trap '' PIPE </code></pre>
<p>The <code>trap</code> command lets you specify a command to run when encountering a signal. To ignore a signal, pass the empty string:</p> <pre><code>trap '' PIPE </code></pre>
16, 379, 387, 2481, 7615
bash, error-handling, python, signals, sigpipe
<h1>Ignoring Bash pipefail for error code 141</h1> <p>Setting the bash <code>pipefail</code> option (via <code>set -o pipefail</code>) allows the script to fail if a non-zero error is caught where there is a non-zero error in any step of a pipe.</p> <p>However, we are running into <code>SIGPIPE</code> errors (error co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,608
bash
# Ignoring Bash pipefail for error code 141 Setting the bash `pipefail` option (via `set -o pipefail`) allows the script to fail if a non-zero error is caught where there is a non-zero error in any step of a pipe. However, we are running into `SIGPIPE` errors (error code 141), where data is written to a pipe that no ...
The `trap` command lets you specify a command to run when encountering a signal. To ignore a signal, pass the empty string: ``` trap '' PIPE ```
972370
How do you pipe input through grep to another utility?
28
2009-06-09 20:40:05
<p>I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a third command, 'cut':</p> <pre><code>tail -f logfile | grep org.springf...
37,506
39,489
2015-10-19 13:48:51
978,178
12
2009-06-10 21:12:49
26,428
2009-06-10 21:12:49
https://stackoverflow.com/q/972370
https://stackoverflow.com/a/978178
<p>On my system, about 8K was buffered before I got any output. This sequence worked to follow the file immediately:</p> <pre><code>tail -f logfile | while read line ; do echo "$line"| grep 'org.springframework'|cut -c 25- ; done </code></pre>
<p>On my system, about 8K was buffered before I got any output. This sequence worked to follow the file immediately:</p> <pre><code>tail -f logfile | while read line ; do echo "$line"| grep 'org.springframework'|cut -c 25- ; done </code></pre>
387, 1271, 1731, 4257, 5813
bash, cut, cygwin, grep, pipe
<h1>How do you pipe input through grep to another utility?</h1> <p>I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a third co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,610
bash
# How do you pipe input through grep to another utility? I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a third command, 'c...
On my system, about 8K was buffered before I got any output. This sequence worked to follow the file immediately: ``` tail -f logfile | while read line ; do echo "$line"| grep 'org.springframework'|cut -c 25- ; done ```
20705102
How to colorise PowerShell output of Format-Table
27
2013-12-20 13:50:36
<p>I try to colorise the column RAM in red if the value is greater than 100 MB:</p> <pre><code>Get-Process | Format-Table @{ Label = "PID"; Expression={$_.Id}}, @{ Label = "Name"; Expression={$_.Name}}, @{ Label = "RAM (MB)"; Expression={[System.Math]::Round($_.WS/1MB, 1)}}, @{ Labe...
49,393
1,911,082
2024-08-08 22:02:59
20,707,761
12
2013-12-20 16:19:32
2,517,150
2018-07-23 18:42:52
https://stackoverflow.com/q/20705102
https://stackoverflow.com/a/20707761
<h2>You could colorize <em>the row</em> making use of a regular expression...</h2> <pre><code>filter colorize-row{ Get-Process | Select-Object Id, Name, WS, Responding | foreach { # Print 'red' row if WS greater than 100 MB if([System.Math]::Round($_.WS/1MB,1) -match "^([0-9]|[0-9][0-9]|[1-9][0-9...
<h2>You could colorize <em>the row</em> making use of a regular expression...</h2> <pre><code>filter colorize-row{ Get-Process | Select-Object Id, Name, WS, Responding | foreach { # Print 'red' row if WS greater than 100 MB if([System.Math]::Round($_.WS/1MB,1) -match "^([0-9]|[0-9][0-9]|[1-9][0-9...
488, 526, 6439
colors, console, powershell
<h1>How to colorise PowerShell output of Format-Table</h1> <p>I try to colorise the column RAM in red if the value is greater than 100 MB:</p> <pre><code>Get-Process | Format-Table @{ Label = "PID"; Expression={$_.Id}}, @{ Label = "Name"; Expression={$_.Name}}, @{ Label = "RAM (MB)"; Expression...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,611
bash
# How to colorise PowerShell output of Format-Table I try to colorise the column RAM in red if the value is greater than 100 MB: ``` Get-Process | Format-Table @{ Label = "PID"; Expression={$_.Id}}, @{ Label = "Name"; Expression={$_.Name}}, @{ Label = "RAM (MB)"; Expression={[System.Math]::Rou...
## You could colorize *the row* making use of a regular expression... ``` filter colorize-row{ Get-Process | Select-Object Id, Name, WS, Responding | foreach { # Print 'red' row if WS greater than 100 MB if([System.Math]::Round($_.WS/1MB,1) -match "^([0-9]|[0-9][0-9]|[1-9][0-9]?$|^100$)$"){ ...
7970702
Simple search and replace without regex
27
2011-11-01 18:00:19
<p>I've got a file with various wildcards in it that I want to be able to substitute from a (Bash) shell script. I've got the following which works great until one of the variables contains characters that are special to regexes:</p> <pre><code>VERSION=&quot;1.0&quot; perl -i -pe &quot;s/VERSION/${VERSION}/g&quot; txtf...
9,130
188,414
2024-01-11 11:56:17
7,970,786
12
2011-11-01 18:07:48
473,798
2021-04-29 13:29:00
https://stackoverflow.com/q/7970702
https://stackoverflow.com/a/7970786
<p>Use the following:</p> <pre><code>perl -i -pe &quot;s|APP_NAME|\\Q${APP_NAME}|g&quot; txtfile.txt </code></pre> <p>Since a vertical bar is not a legal character as part of a path, you are good to go.</p>
<p>Use the following:</p> <pre><code>perl -i -pe &quot;s|APP_NAME|\\Q${APP_NAME}|g&quot; txtfile.txt </code></pre> <p>Since a vertical bar is not a legal character as part of a path, you are good to go.</p>
387, 580, 1469
bash, perl, text
<h1>Simple search and replace without regex</h1> <p>I've got a file with various wildcards in it that I want to be able to substitute from a (Bash) shell script. I've got the following which works great until one of the variables contains characters that are special to regexes:</p> <pre><code>VERSION=&quot;1.0&quot; pe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,612
bash
# Simple search and replace without regex I've got a file with various wildcards in it that I want to be able to substitute from a (Bash) shell script. I've got the following which works great until one of the variables contains characters that are special to regexes: ``` VERSION="1.0" perl -i -pe "s/VERSION/${VERSIO...
Use the following: ``` perl -i -pe "s|APP_NAME|\\Q${APP_NAME}|g" txtfile.txt ``` Since a vertical bar is not a legal character as part of a path, you are good to go.
5215343
How can I pause in zsh?
25
2011-03-07 02:54:31
<p>I want to write this bash loop for zsh</p> <pre><code>while true; do echo "print something"; read -p "pause"; done </code></pre> <p>This loop echos, then waits for the user to press enter. If I enter it as is, the read statement doesn't pause, causing zsh to infinitely echo "print something" without waiting for t...
16,051
594,496
2023-06-13 15:03:19
5,215,407
12
2011-03-07 03:06:27
319,906
2011-03-07 03:17:36
https://stackoverflow.com/q/5215343
https://stackoverflow.com/a/5215407
<p>It looks like <code>-p</code> does something different in <code>zsh</code>. You will probably need something like <code>read some_variable\?pause</code>.</p>
<p>It looks like <code>-p</code> does something different in <code>zsh</code>. You will probably need something like <code>read some_variable\?pause</code>.</p>
387, 3791
bash, zsh
<h1>How can I pause in zsh?</h1> <p>I want to write this bash loop for zsh</p> <pre><code>while true; do echo "print something"; read -p "pause"; done </code></pre> <p>This loop echos, then waits for the user to press enter. If I enter it as is, the read statement doesn't pause, causing zsh to infinitely echo "print...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,613
bash
# How can I pause in zsh? I want to write this bash loop for zsh ``` while true; do echo "print something"; read -p "pause"; done ``` This loop echos, then waits for the user to press enter. If I enter it as is, the read statement doesn't pause, causing zsh to infinitely echo "print something" without waiting for th...
It looks like `-p` does something different in `zsh`. You will probably need something like `read some_variable\?pause`.
26379379
How to create a symbolic link when target directory doesn't exist?
24
2014-10-15 09:47:21
<p>Is there a flag you can add to the <code>ln</code> command to force the creation of the target directory structure (like <code>mkdir -p</code>).</p> <p>Consider :</p> <pre><code>ln -s /Applications/'Sublime Text.app'/Contents/SharedSupport/bin/subl /usr/local/bin/ </code></pre> <p>Which adds a symlink to the Subl...
29,661
1,772,521
2021-01-19 14:07:54
26,380,036
12
2014-10-15 10:17:03
1,490,552
2014-10-16 11:17:02
https://stackoverflow.com/q/26379379
https://stackoverflow.com/a/26380036
<p>Try like this,</p> <pre><code>mkdir -p /create_your_path/ &amp;&amp; xargs ln -s /link_file_path/file /create_your_path/ </code></pre>
<p>Try like this,</p> <pre><code>mkdir -p /create_your_path/ &amp;&amp; xargs ln -s /link_file_path/file /create_your_path/ </code></pre>
34, 387, 391
bash, terminal, unix
<h1>How to create a symbolic link when target directory doesn't exist?</h1> <p>Is there a flag you can add to the <code>ln</code> command to force the creation of the target directory structure (like <code>mkdir -p</code>).</p> <p>Consider :</p> <pre><code>ln -s /Applications/'Sublime Text.app'/Contents/SharedSupport...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,614
bash
# How to create a symbolic link when target directory doesn't exist? Is there a flag you can add to the `ln` command to force the creation of the target directory structure (like `mkdir -p`). Consider : ``` ln -s /Applications/'Sublime Text.app'/Contents/SharedSupport/bin/subl /usr/local/bin/ ``` Which adds a symli...
Try like this, ``` mkdir -p /create_your_path/ && xargs ln -s /link_file_path/file /create_your_path/ ```
23552704
how to recreate a working CURL command with Invoke-WebRequest in Powershell
24
2014-05-08 21:16:24
<p>This curl command works as desired:</p> <pre><code>curl -H "X-Api-Key:j65k423lj4k2l3fds" ` -X PUT ` -d "alerts_enabled=true" ` https://some/working/file.xml </code></pre> <p>How can I recreate this natively in PS with <code>Invoke-WebRequest</code>? I've tried</p> <pre><code>Invoke-WebRequest -H...
91,886
3,561,945
2024-06-12 18:50:54
23,614,844
12
2014-05-12 17:02:35
3,561,945
2014-05-12 17:02:35
https://stackoverflow.com/q/23552704
https://stackoverflow.com/a/23614844
<p>got it to work natively using invoke-webrequest. powershell guru here at work helped me out. Switched to the New Relic API version 2 (available at <a href="https://rpm.newrelic.com/api/explore" rel="noreferrer">https://rpm.newrelic.com/api/explore</a>), which uses JSON instead of xml, and made some sytax tweaks.</p>...
<p>got it to work natively using invoke-webrequest. powershell guru here at work helped me out. Switched to the New Relic API version 2 (available at <a href="https://rpm.newrelic.com/api/explore" rel="noreferrer">https://rpm.newrelic.com/api/explore</a>), which uses JSON instead of xml, and made some sytax tweaks.</p>...
526, 1554
curl, powershell
<h1>how to recreate a working CURL command with Invoke-WebRequest in Powershell</h1> <p>This curl command works as desired:</p> <pre><code>curl -H "X-Api-Key:j65k423lj4k2l3fds" ` -X PUT ` -d "alerts_enabled=true" ` https://some/working/file.xml </code></pre> <p>How can I recreate this natively in PS...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,615
bash
# how to recreate a working CURL command with Invoke-WebRequest in Powershell This curl command works as desired: ``` curl -H "X-Api-Key:j65k423lj4k2l3fds" ` -X PUT ` -d "alerts_enabled=true" ` https://some/working/file.xml ``` How can I recreate this natively in PS with `Invoke-WebRequest`? I've t...
got it to work natively using invoke-webrequest. powershell guru here at work helped me out. Switched to the New Relic API version 2 (available at <https://rpm.newrelic.com/api/explore>), which uses JSON instead of xml, and made some sytax tweaks. ``` $json = @"{"alert_policy":[{"enabled":"true"}]"@ $headers = @{} $h...
15610794
Bash coding conventions
24
2013-03-25 08:49:43
<p>I am trying to learn some Bash to maybe get a job working with computers one day.</p> <p>To improve my clarity and disciple writing my self-learning code, I am trying to adhere to a set of consistent "guiding principles".</p> <p>As I roll my own "guidelines" I obviously ask myself: should I not be using an establi...
17,686
916,332
2022-05-17 04:10:18
15,629,021
12
2013-03-26 03:43:01
418,413
2013-05-10 15:21:12
https://stackoverflow.com/q/15610794
https://stackoverflow.com/a/15629021
<h1>My shell scripting standards</h1> <ol> <li>Prefer portability, but don't sacrifice security and whitespace awareness to it.</li> <li>Prefer builtins over external commands.</li> <li>But, use fast external commands to process very large inputs.</li> <li>Avoid unnecessary subshells and pipelines.</li> <li>Don't preo...
<h1>My shell scripting standards</h1> <ol> <li>Prefer portability, but don't sacrifice security and whitespace awareness to it.</li> <li>Prefer builtins over external commands.</li> <li>But, use fast external commands to process very large inputs.</li> <li>Avoid unnecessary subshells and pipelines.</li> <li>Don't preo...
387
bash
<h1>Bash coding conventions</h1> <p>I am trying to learn some Bash to maybe get a job working with computers one day.</p> <p>To improve my clarity and disciple writing my self-learning code, I am trying to adhere to a set of consistent "guiding principles".</p> <p>As I roll my own "guidelines" I obviously ask myself:...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,616
bash
# Bash coding conventions I am trying to learn some Bash to maybe get a job working with computers one day. To improve my clarity and disciple writing my self-learning code, I am trying to adhere to a set of consistent "guiding principles". As I roll my own "guidelines" I obviously ask myself: should I not be using ...
# My shell scripting standards 1. Prefer portability, but don't sacrifice security and whitespace awareness to it. 2. Prefer builtins over external commands. 3. But, use fast external commands to process very large inputs. 4. Avoid unnecessary subshells and pipelines. 5. Don't preoptimize. 6. Learn the rules of quotin...
22865507
Using grep and awk together
23
2014-04-04 14:24:51
<p>I have a file (A.txt) with 4 columns of numbers and another file with 3 columns of numbers (B.txt). I need to solve the following problems:</p> <ol> <li><p>Find all lines in A.txt whose 3rd column has a number that appears any where in the 3rd column of B.txt.</p> </li> <li><p>Assume that I have many files like A.tx...
144,121
363,902
2024-02-19 16:11:47
22,865,811
12
2014-04-04 14:39:53
1,534,218
2014-04-04 17:04:51
https://stackoverflow.com/q/22865507
https://stackoverflow.com/a/22865811
<p>Here is an example. Create the following files and run</p> <pre><code>awk -f c.awk B.txt A*.txt </code></pre> <p><strong>c.awk</strong></p> <pre><code>FNR==NR { s[$3] next } $3 in s { print FILENAME, $0 } </code></pre> <p><strong>A1.txt</strong></p> <pre><code>1 2 3 1 2 6 1 2 5 </code></pre> <p><...
<p>Here is an example. Create the following files and run</p> <pre><code>awk -f c.awk B.txt A*.txt </code></pre> <p><strong>c.awk</strong></p> <pre><code>FNR==NR { s[$3] next } $3 in s { print FILENAME, $0 } </code></pre> <p><strong>A1.txt</strong></p> <pre><code>1 2 3 1 2 6 1 2 5 </code></pre> <p><...
387, 990, 1271
awk, bash, grep
<h1>Using grep and awk together</h1> <p>I have a file (A.txt) with 4 columns of numbers and another file with 3 columns of numbers (B.txt). I need to solve the following problems:</p> <ol> <li><p>Find all lines in A.txt whose 3rd column has a number that appears any where in the 3rd column of B.txt.</p> </li> <li><p>As...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,617
bash
# Using grep and awk together I have a file (A.txt) with 4 columns of numbers and another file with 3 columns of numbers (B.txt). I need to solve the following problems: 1. Find all lines in A.txt whose 3rd column has a number that appears any where in the 3rd column of B.txt. 2. Assume that I have many files like A....
Here is an example. Create the following files and run ``` awk -f c.awk B.txt A*.txt ``` **c.awk** ``` FNR==NR { s[$3] next } $3 in s { print FILENAME, $0 } ``` **A1.txt** ``` 1 2 3 1 2 6 1 2 5 ``` **A2.txt** ``` 1 2 3 1 2 6 1 2 5 ``` **B.txt** ``` 1 2 3 1 2 5 2 1 8 ``` The output should be: ```...
16937104
Provide password to ssh command inside bash script, Without the usage of public keys and Expect
23
2013-06-05 10:06:34
<p>I want to use <code>SSH</code> inside a script, but this script is not going to be executed on my machine.</p> <p>In my implementation there are two limitations. </p> <ul> <li>I can not work outside shell's standards,therefore i can not use <code>expect</code> because i do not know if it will be available on this ...
125,740
2,357,195
2024-10-23 17:29:38
16,937,638
12
2013-06-05 10:33:31
34,148
2013-06-05 10:42:25
https://stackoverflow.com/q/16937104
https://stackoverflow.com/a/16937638
<p>First of all: <strong>Don't put secrets in clear text</strong> <em>unless</em> you know why it is a safe thing to do (i.e. you have assessed what damage can be done by an attacker knowing the secret).</p> <p>If you are ok with putting secrets in your script, you could ship an ssh key with it and execute in an <code...
<p>First of all: <strong>Don't put secrets in clear text</strong> <em>unless</em> you know why it is a safe thing to do (i.e. you have assessed what damage can be done by an attacker knowing the secret).</p> <p>If you are ok with putting secrets in your script, you could ship an ssh key with it and execute in an <code...
58, 386, 387, 390
bash, linux, shell, ssh
<h1>Provide password to ssh command inside bash script, Without the usage of public keys and Expect</h1> <p>I want to use <code>SSH</code> inside a script, but this script is not going to be executed on my machine.</p> <p>In my implementation there are two limitations. </p> <ul> <li>I can not work outside shell's sta...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,618
bash
# Provide password to ssh command inside bash script, Without the usage of public keys and Expect I want to use `SSH` inside a script, but this script is not going to be executed on my machine. In my implementation there are two limitations. - I can not work outside shell's standards,therefore i can not use `expect`...
First of all: **Don't put secrets in clear text** *unless* you know why it is a safe thing to do (i.e. you have assessed what damage can be done by an attacker knowing the secret). If you are ok with putting secrets in your script, you could ship an ssh key with it and execute in an `ssh-agent` shell: ``` #!/usr/bin/...
10297002
Passing empty arguments to executables using powershell
23
2012-04-24 11:31:39
<p>Powershell seems to drop empty string arguments when passed to a command. I have this code</p> <pre><code>PS D:\&gt; $b.name = "foo bar" PS D:\&gt; ./echoargs $b.name Arg 0 is D:\echoargs.exe Arg 1 is foo bar PS D:\&gt; $b.name = "" PS D:\&gt; ./echoargs $b.name Arg 0 is D:\echoargs.exe </code></pre> <p>You can as...
18,639
1,353,535
2024-01-30 16:47:43
10,301,470
12
2012-04-24 15:51:15
153,982
2012-04-24 15:51:15
https://stackoverflow.com/q/10297002
https://stackoverflow.com/a/10301470
<p>If you want an empty string to appear try escaped quotes around the argument like so:</p> <pre><code>PS&gt; $b = [psobject]@{name = ''} PS&gt; echoargs `"$($b.Name)`" Arg 0 is &lt;&gt; Command line: "C:\Users\Keith\Pscx\Trunk\Src\Pscx\bin\Release\Apps\EchoArgs.exe" "" </code></pre> <p>Note that I tested this on ...
<p>If you want an empty string to appear try escaped quotes around the argument like so:</p> <pre><code>PS&gt; $b = [psobject]@{name = ''} PS&gt; echoargs `"$($b.Name)`" Arg 0 is &lt;&gt; Command line: "C:\Users\Keith\Pscx\Trunk\Src\Pscx\bin\Release\Apps\EchoArgs.exe" "" </code></pre> <p>Note that I tested this on ...
526, 1231
command-line, powershell
<h1>Passing empty arguments to executables using powershell</h1> <p>Powershell seems to drop empty string arguments when passed to a command. I have this code</p> <pre><code>PS D:\&gt; $b.name = "foo bar" PS D:\&gt; ./echoargs $b.name Arg 0 is D:\echoargs.exe Arg 1 is foo bar PS D:\&gt; $b.name = "" PS D:\&gt; ./echoa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,619
bash
# Passing empty arguments to executables using powershell Powershell seems to drop empty string arguments when passed to a command. I have this code ``` PS D:\> $b.name = "foo bar" PS D:\> ./echoargs $b.name Arg 0 is D:\echoargs.exe Arg 1 is foo bar PS D:\> $b.name = "" PS D:\> ./echoargs $b.name Arg 0 is D:\echoargs...
If you want an empty string to appear try escaped quotes around the argument like so: ``` PS> $b = [psobject]@{name = ''} PS> echoargs `"$($b.Name)`" Arg 0 is <> Command line: "C:\Users\Keith\Pscx\Trunk\Src\Pscx\bin\Release\Apps\EchoArgs.exe" "" ``` Note that I tested this on V3 so I'm not sure if the behavior will...
2499270
How to print ASCII value of a character using basic awk only
23
2010-03-23 10:59:46
<p>I need to print the ASCII value of the given character in awk only.</p> <p>Below code gives <code>0</code> as output:</p> <pre><code>echo a | awk '{ printf("%d \n",$1); }' </code></pre>
35,598
229,608
2022-10-09 10:30:09
2,499,383
12
2010-03-23 11:21:42
131,527
2014-05-05 14:35:26
https://stackoverflow.com/q/2499270
https://stackoverflow.com/a/2499383
<p>see the awk manual for <a href="http://www.gnu.org/software/gawk/manual/html_node/Ordinal-Functions.html" rel="noreferrer">ordinal functions</a> you can use. But since you are using awk, you should be on some version of shell, eg bash. so why not use the shell?</p> <pre><code>$ printf "%d" "'a" 97 </code></pre>
<p>see the awk manual for <a href="http://www.gnu.org/software/gawk/manual/html_node/Ordinal-Functions.html" rel="noreferrer">ordinal functions</a> you can use. But since you are using awk, you should be on some version of shell, eg bash. so why not use the shell?</p> <pre><code>$ printf "%d" "'a" 97 </code></pre>
34, 390, 990
awk, shell, unix
<h1>How to print ASCII value of a character using basic awk only</h1> <p>I need to print the ASCII value of the given character in awk only.</p> <p>Below code gives <code>0</code> as output:</p> <pre><code>echo a | awk '{ printf("%d \n",$1); }' </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,620
bash
# How to print ASCII value of a character using basic awk only I need to print the ASCII value of the given character in awk only. Below code gives `0` as output: ``` echo a | awk '{ printf("%d \n",$1); }' ```
see the awk manual for [ordinal functions](http://www.gnu.org/software/gawk/manual/html_node/Ordinal-Functions.html) you can use. But since you are using awk, you should be on some version of shell, eg bash. so why not use the shell? ``` $ printf "%d" "'a" 97 ```
1924217
PowerShell: Load WebAdministration in ps1 script on both IIS 7 and IIS 7.5
23
2009-12-17 20:03:37
<p>I have a PowerShell script that configures web site and web application settings in IIS. So I use the cmdlets in the WebAdministration snap in. But this script needs to run on Windows 2008, Windows 7 and Windows 2008 R2. And I need it to run with minimal fuss from the user.</p> <p>The problem is that Windows 7 an...
30,399
31,037
2012-11-27 06:31:05
1,924,307
12
2009-12-17 20:20:27
223,370
2009-12-17 20:20:27
https://stackoverflow.com/q/1924217
https://stackoverflow.com/a/1924307
<p>Is it possible to catch the error from one or the other, and do the opposite. Dont have my shell handy but something like:</p> <pre><code>$succeeded = import-module WebAdministration if (($succeeded -ne $null) -and ($succeeded.GetType() -eq [System.Exception]) { #Could not import, trying to snapin add-pssnapin ...
<p>Is it possible to catch the error from one or the other, and do the opposite. Dont have my shell handy but something like:</p> <pre><code>$succeeded = import-module WebAdministration if (($succeeded -ne $null) -and ($succeeded.GetType() -eq [System.Exception]) { #Could not import, trying to snapin add-pssnapin ...
215, 526
iis, powershell
<h1>PowerShell: Load WebAdministration in ps1 script on both IIS 7 and IIS 7.5</h1> <p>I have a PowerShell script that configures web site and web application settings in IIS. So I use the cmdlets in the WebAdministration snap in. But this script needs to run on Windows 2008, Windows 7 and Windows 2008 R2. And I need...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,621
bash
# PowerShell: Load WebAdministration in ps1 script on both IIS 7 and IIS 7.5 I have a PowerShell script that configures web site and web application settings in IIS. So I use the cmdlets in the WebAdministration snap in. But this script needs to run on Windows 2008, Windows 7 and Windows 2008 R2. And I need it to run ...
Is it possible to catch the error from one or the other, and do the opposite. Dont have my shell handy but something like: ``` $succeeded = import-module WebAdministration if (($succeeded -ne $null) -and ($succeeded.GetType() -eq [System.Exception]) { #Could not import, trying to snapin add-pssnapin WebAdministrat...
630382
How to access the 64-bit registry from a 32-bit Powershell instance?
23
2009-03-10 14:11:09
<p>If you launch a 32-bit instance of Powershell (%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe), then the registry provider only sees the limited 32-bit parts of the registry.</p> <pre><code>**32-bit console** PS&gt; (dir HKLM:\SOFTWARE | measure).count - (dir HKLM:\SOFTWARE\wow6432node | measure).count...
32,819
74,439
2021-07-29 11:56:33
630,796
12
2009-03-10 15:30:40
23,843
2009-03-10 15:30:40
https://stackoverflow.com/q/630382
https://stackoverflow.com/a/630796
<p>When Powershell is running as a 32 bit process, I am not aware of a mechanism to "switch it" to 64bit mode. The whole point of virtualization support in 64bit systems is to make 32bit processes believe they are living in a 32bit OS...</p> <p>However, that said I used the following technique in the past and it worke...
<p>When Powershell is running as a 32 bit process, I am not aware of a mechanism to "switch it" to 64bit mode. The whole point of virtualization support in 64bit systems is to make 32bit processes believe they are living in a 32bit OS...</p> <p>However, that said I used the following technique in the past and it worke...
263, 526, 681
64-bit, powershell, registry
<h1>How to access the 64-bit registry from a 32-bit Powershell instance?</h1> <p>If you launch a 32-bit instance of Powershell (%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe), then the registry provider only sees the limited 32-bit parts of the registry.</p> <pre><code>**32-bit console** PS&gt; (dir HKLM...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,622
bash
# How to access the 64-bit registry from a 32-bit Powershell instance? If you launch a 32-bit instance of Powershell (%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe), then the registry provider only sees the limited 32-bit parts of the registry. ``` **32-bit console** PS> (dir HKLM:\SOFTWARE | measure).c...
When Powershell is running as a 32 bit process, I am not aware of a mechanism to "switch it" to 64bit mode. The whole point of virtualization support in 64bit systems is to make 32bit processes believe they are living in a 32bit OS... However, that said I used the following technique in the past and it worked very nic...
36518973
iTerm2 Shell Integration and Oh My Zsh Conflicts
22
2016-04-09 15:38:09
<p>I've recently re-installed iTerm2 and am now running into an interesting problem after setting up iTerm's Shell Integration.</p> <p>Upon open a new terminal window, everything seems to look correct, showing the proper "agnoster" theme from Oh My ZSH:</p> <p><a href="https://i.sstatic.net/tnvsR.png"><img src="https...
15,084
446,491
2020-08-17 11:18:28
36,533,137
12
2016-04-10 17:34:22
3,213,062
2018-08-30 23:23:19
https://stackoverflow.com/q/36518973
https://stackoverflow.com/a/36533137
<p>I just installed the Shell Integration in iTerm 2 (Build 2.9.20160313) and had the exact same problem.</p> <p>The way I solved it was by adding a single line to <code>~/.iterm2_shell_integration.zsh</code> right after <code>export ITERM_SHELL_INTEGRATION_INSTALLED=Yes</code> at line 3:</p> <p><code>ITERM2_PRECMD_...
<p>I just installed the Shell Integration in iTerm 2 (Build 2.9.20160313) and had the exact same problem.</p> <p>The way I solved it was by adding a single line to <code>~/.iterm2_shell_integration.zsh</code> right after <code>export ITERM_SHELL_INTEGRATION_INSTALLED=Yes</code> at line 3:</p> <p><code>ITERM2_PRECMD_...
390, 89892, 93854
iterm2, oh-my-zsh, shell
<h1>iTerm2 Shell Integration and Oh My Zsh Conflicts</h1> <p>I've recently re-installed iTerm2 and am now running into an interesting problem after setting up iTerm's Shell Integration.</p> <p>Upon open a new terminal window, everything seems to look correct, showing the proper "agnoster" theme from Oh My ZSH:</p> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,623
bash
# iTerm2 Shell Integration and Oh My Zsh Conflicts I've recently re-installed iTerm2 and am now running into an interesting problem after setting up iTerm's Shell Integration. Upon open a new terminal window, everything seems to look correct, showing the proper "agnoster" theme from Oh My ZSH: [![working](https://i....
I just installed the Shell Integration in iTerm 2 (Build 2.9.20160313) and had the exact same problem. The way I solved it was by adding a single line to `~/.iterm2_shell_integration.zsh` right after `export ITERM_SHELL_INTEGRATION_INSTALLED=Yes` at line 3: `ITERM2_PRECMD_PS1="$PS1"` Thus, this is how the head of th...
29607287
Powershell module: Dynamic mandatory hierarchical parameters
21
2015-04-13 14:03:14
<p>So what I really want is somewhat usable tab completion in a PS module. ValidateSet seems to be the way to go here.</p> <p>Unfortunately my data is dynamic, so I cannot annotate the parameter with all valid values upfront. DynamicParameters/IDynamicParameters seems to be the solution for <em>that</em> problem.</p> ...
1,346
59,492
2015-04-18 02:57:30
29,680,516
12
2015-04-16 16:17:29
3,874,447
2015-04-18 02:57:30
https://stackoverflow.com/q/29607287
https://stackoverflow.com/a/29680516
<p>I think this works. Unfortunately, it uses reflection to get at some of the cmdlet's private members for your first bullet. I got the idea from <a href="https://gist.github.com/fearthecowboy/1936f841d3a81710ae87" rel="noreferrer">Garrett Serack</a>. I'm not sure if I completely understood how to do the default autho...
<p>I think this works. Unfortunately, it uses reflection to get at some of the cmdlet's private members for your first bullet. I got the idea from <a href="https://gist.github.com/fearthecowboy/1936f841d3a81710ae87" rel="noreferrer">Garrett Serack</a>. I'm not sure if I completely understood how to do the default autho...
9, 526
c#, powershell
<h1>Powershell module: Dynamic mandatory hierarchical parameters</h1> <p>So what I really want is somewhat usable tab completion in a PS module. ValidateSet seems to be the way to go here.</p> <p>Unfortunately my data is dynamic, so I cannot annotate the parameter with all valid values upfront. DynamicParameters/IDyna...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,624
bash
# Powershell module: Dynamic mandatory hierarchical parameters So what I really want is somewhat usable tab completion in a PS module. ValidateSet seems to be the way to go here. Unfortunately my data is dynamic, so I cannot annotate the parameter with all valid values upfront. DynamicParameters/IDynamicParameters se...
I think this works. Unfortunately, it uses reflection to get at some of the cmdlet's private members for your first bullet. I got the idea from [Garrett Serack](https://gist.github.com/fearthecowboy/1936f841d3a81710ae87). I'm not sure if I completely understood how to do the default author, so I made it so that the las...
18532948
How to append a newline after every match using xmlint --xpath
20
2013-08-30 12:28:50
<p>I have the following HTML code:</p> <pre><code>&lt;textarea name="command" class="setting-input fixed-width" rows="9"&gt;1&lt;/textarea&gt;&lt;textarea name="command" class="setting-input fixed-width" rows="5"&gt;2&lt;/textarea&gt; </code></pre> <p>I would like to parse it to receive such output:</p> <pre><co...
13,775
2,345,933
2023-04-09 14:24:51
48,311,523
12
2018-01-17 23:15:26
785,213
2023-04-09 14:24:51
https://stackoverflow.com/q/18532948
https://stackoverflow.com/a/48311523
<p>Hello from the year 2020!</p> <p>As of v2.9.9 of libxml, this behavior <a href="https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce" rel="nofollow noreferrer">has been fixed in <code>xmllint</code> itself</a>.</p> <pre class="lang-bash prettyprint-override"><code>echo \ '&lt;textar...
<p>Hello from the year 2020!</p> <p>As of v2.9.9 of libxml, this behavior <a href="https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce" rel="nofollow noreferrer">has been fixed in <code>xmllint</code> itself</a>.</p> <pre class="lang-bash prettyprint-override"><code>echo \ '&lt;textar...
19, 390, 1227, 70156
shell, xml, xmllint, xpath
<h1>How to append a newline after every match using xmlint --xpath</h1> <p>I have the following HTML code:</p> <pre><code>&lt;textarea name="command" class="setting-input fixed-width" rows="9"&gt;1&lt;/textarea&gt;&lt;textarea name="command" class="setting-input fixed-width" rows="5"&gt;2&lt;/textarea&gt; </code><...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,625
bash
# How to append a newline after every match using xmlint --xpath I have the following HTML code: ``` <textarea name="command" class="setting-input fixed-width" rows="9">1</textarea><textarea name="command" class="setting-input fixed-width" rows="5">2</textarea> ``` I would like to parse it to receive such output...
Hello from the year 2020! As of v2.9.9 of libxml, this behavior [has been fixed in `xmllint` itself](https://gitlab.gnome.org/GNOME/libxml2/commit/da35eeae5b92b88d8ebdb64b4b327ac1c2cf1bce). ``` echo \ '<textarea name="command" class="setting-input fixed-width" rows="9">1</textarea> <textarea name="command" class="se...
38465751
@reboot is not working in CRON
20
2016-07-19 18:16:31
<p>I'm trying to run a shell-script and a command at the start of my Ubuntu server. </p> <p>Here is my <code>CRON</code></p> <pre><code>@reboot /home/steam/check.sh @reboot screen -d -S up -m node /var/www/html/Up1/server/server.js </code></pre> <p>What I'm getting in the logs: <code>grep CRON /var/log/syslog</code...
84,211
5,856,616
2021-11-29 13:50:18
38,484,205
12
2016-07-20 14:34:11
1,248,008
2016-07-20 15:57:41
https://stackoverflow.com/q/38465751
https://stackoverflow.com/a/38484205
<p>Take a look at the systemd.service manpage. It describes how to configure systemd to manage a service. I am sure you will find examples for your system in <code>/usr/lib/systemd/system</code> or similar paths.</p> <p>In your case, the service would look somewhat like this:</p> <pre><code>[Unit] Description=Unturne...
<p>Take a look at the systemd.service manpage. It describes how to configure systemd to manage a service. I am sure you will find examples for your system in <code>/usr/lib/systemd/system</code> or similar paths.</p> <p>In your case, the service would look somewhat like this:</p> <pre><code>[Unit] Description=Unturne...
58, 387, 390, 549, 601
bash, cron, linux, shell, ubuntu
<h1>@reboot is not working in CRON</h1> <p>I'm trying to run a shell-script and a command at the start of my Ubuntu server. </p> <p>Here is my <code>CRON</code></p> <pre><code>@reboot /home/steam/check.sh @reboot screen -d -S up -m node /var/www/html/Up1/server/server.js </code></pre> <p>What I'm getting in the log...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,626
bash
# @reboot is not working in CRON I'm trying to run a shell-script and a command at the start of my Ubuntu server. Here is my `CRON` ``` @reboot /home/steam/check.sh @reboot screen -d -S up -m node /var/www/html/Up1/server/server.js ``` What I'm getting in the logs: `grep CRON /var/log/syslog` ``` Jul 19 19:48:28 v...
Take a look at the systemd.service manpage. It describes how to configure systemd to manage a service. I am sure you will find examples for your system in `/usr/lib/systemd/system` or similar paths. In your case, the service would look somewhat like this: ``` [Unit] Description=Unturned Game Server [Install] WantedB...
19754784
Running a simple shell script as a cronjob
20
2013-11-03 15:49:39
<p>I have a very simple shell script I need to run as a cronjob but I can't get even the test scripts to run. Here's and example script:</p> <p>/home/myUser/scripts/test.sh</p> <pre><code>#!/bin/bash touch file.txt </code></pre> <p>crontab:</p> <pre><code>* * * * * /home/myUser/scripts/test.sh </code></pre> <p>The...
155,404
2,608,063
2018-08-09 21:44:08
19,755,335
12
2013-11-03 16:47:45
89,817
2013-11-03 20:16:48
https://stackoverflow.com/q/19754784
https://stackoverflow.com/a/19755335
<p>What directory is file.txt in? cron runs jobs in your home directory, so unless your script <code>cd</code>s somewhere else, that's where it's going to look for/create file.txt.</p> <p>EDIT: When you refer to a file without specifying its full path (e.g. <code>file.txt</code>, as opposed to the full path <code>/hom...
<p>What directory is file.txt in? cron runs jobs in your home directory, so unless your script <code>cd</code>s somewhere else, that's where it's going to look for/create file.txt.</p> <p>EDIT: When you refer to a file without specifying its full path (e.g. <code>file.txt</code>, as opposed to the full path <code>/hom...
387, 390, 601
bash, cron, shell
<h1>Running a simple shell script as a cronjob</h1> <p>I have a very simple shell script I need to run as a cronjob but I can't get even the test scripts to run. Here's and example script:</p> <p>/home/myUser/scripts/test.sh</p> <pre><code>#!/bin/bash touch file.txt </code></pre> <p>crontab:</p> <pre><code>* * * * ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,627
bash
# Running a simple shell script as a cronjob I have a very simple shell script I need to run as a cronjob but I can't get even the test scripts to run. Here's and example script: /home/myUser/scripts/test.sh ``` #!/bin/bash touch file.txt ``` crontab: ``` * * * * * /home/myUser/scripts/test.sh ``` The script runs...
What directory is file.txt in? cron runs jobs in your home directory, so unless your script `cd`s somewhere else, that's where it's going to look for/create file.txt. EDIT: When you refer to a file without specifying its full path (e.g. `file.txt`, as opposed to the full path `/home/myUser/scripts/file.txt`) in shell,...
10641233
How do I sudo if in Bash?
20
2012-05-17 18:13:16
<p>I need to check for a directory in the home directory of another user. Normally I would sudo but that forks another process and I also lose my environment.</p> <p>For example, I have:</p> <pre><code>if [[ -d "/home/otheruser/svn" ]]; then echo "SVN exists" else echo "SVN does not exist" fi </code></pre> <p>...
13,816
681,040
2025-03-22 00:12:51
10,641,279
12
2012-05-17 18:17:05
193,468
2025-03-22 00:12:51
https://stackoverflow.com/q/10641233
https://stackoverflow.com/a/10641279
<p>You need to run it under a subshell. Example:</p> <pre><code>if sudo bash -c '[[ -d &quot;/home/otheruser/svn&quot; ]]' then echo &quot;SVN exists&quot; else echo &quot;SVN does not exist&quot; fi </code></pre> <p>Note that if you are using <code>-d</code> specifically (or any of the other operators supported by...
<p>You need to run it under a subshell. Example:</p> <pre><code>if sudo bash -c '[[ -d &quot;/home/otheruser/svn&quot; ]]' then echo &quot;SVN exists&quot; else echo &quot;SVN does not exist&quot; fi </code></pre> <p>Note that if you are using <code>-d</code> specifically (or any of the other operators supported by...
387, 390, 1674
bash, shell, sudo
<h1>How do I sudo if in Bash?</h1> <p>I need to check for a directory in the home directory of another user. Normally I would sudo but that forks another process and I also lose my environment.</p> <p>For example, I have:</p> <pre><code>if [[ -d "/home/otheruser/svn" ]]; then echo "SVN exists" else echo "SVN do...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,628
bash
# How do I sudo if in Bash? I need to check for a directory in the home directory of another user. Normally I would sudo but that forks another process and I also lose my environment. For example, I have: ``` if [[ -d "/home/otheruser/svn" ]]; then echo "SVN exists" else echo "SVN does not exist" fi ``` I nee...
You need to run it under a subshell. Example: ``` if sudo bash -c '[[ -d "/home/otheruser/svn" ]]' then echo "SVN exists" else echo "SVN does not exist" fi ``` Note that if you are using `-d` specifically (or any of the other operators supported by `/bin/test`) then using `sudo test` is better and safer, as shown...
9301531
Using aliases with nohup
20
2012-02-15 21:16:29
<p>Why doesn't the following work? </p> <pre><code>$ alias sayHello='/bin/echo "Hello world!"' $ sayHello Hello world! $ nohup sayHello nohup: appending output to `nohup.out' nohup: cannot run command `sayHello': No such file or directory </code></pre> <p>(the reason I ask this question is because I've a...
11,207
884,447
2020-07-08 19:45:33
9,301,796
12
2012-02-15 21:35:07
679,177
2020-07-08 19:45:33
https://stackoverflow.com/q/9301531
https://stackoverflow.com/a/9301796
<p>Because the shell doesn't pass aliases on to child processes (except when you use $() or ``).</p> <p>$ alias sayHello='/bin/echo &quot;Hello world!&quot;'</p> <p>Now an alias is known in this shell process, which is fine but only works in this one shell process.</p> <pre><code>$ sayHello Hello world! </code></pre>...
<p>Because the shell doesn't pass aliases on to child processes (except when you use $() or ``).</p> <p>$ alias sayHello='/bin/echo &quot;Hello world!&quot;'</p> <p>Now an alias is known in this shell process, which is fine but only works in this one shell process.</p> <pre><code>$ sayHello Hello world! </code></pre>...
34, 387, 1448, 18966
alias, bash, nohup, unix
<h1>Using aliases with nohup</h1> <p>Why doesn't the following work? </p> <pre><code>$ alias sayHello='/bin/echo "Hello world!"' $ sayHello Hello world! $ nohup sayHello nohup: appending output to `nohup.out' nohup: cannot run command `sayHello': No such file or directory </code></pre> <p>(the reason I a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,629
bash
# Using aliases with nohup Why doesn't the following work? ``` $ alias sayHello='/bin/echo "Hello world!"' $ sayHello Hello world! $ nohup sayHello nohup: appending output to `nohup.out' nohup: cannot run command `sayHello': No such file or directory ``` (the reason I ask this question is because I've a...
Because the shell doesn't pass aliases on to child processes (except when you use $() or ``). $ alias sayHello='/bin/echo "Hello world!"' Now an alias is known in this shell process, which is fine but only works in this one shell process. ``` $ sayHello Hello world! ``` Since you said "sayHello" in the same shell...
3569784
Using sed to get an env var from /proc/*/environ weirdness with \x00
20
2010-08-25 20:03:58
<p>I'm trying to grovel through some other processes environment to get a specific env var.</p> <p>So I've been trying a sed command like:</p> <p><code>sed -n "s/\x00ENV_VAR_NAME=\([^\x00]*\)\x00/\1/p" /proc/pid/environ</code></p> <p>But I'm getting as output the full environ file. If I replace the \1 with just a s...
12,914
131,795
2017-10-27 16:53:21
3,569,935
12
2010-08-25 20:26:45
68,587
2017-09-08 09:55:59
https://stackoverflow.com/q/3569784
https://stackoverflow.com/a/3569935
<p>You could process the list with gawk, setting the record separator to <code>\0</code> and the field separator to <code>=</code>:</p> <pre><code>gawk -v 'RS=\0' -F= '$1=="ENV_VAR_NAME" {print $2}' /proc/pid/environ </code></pre> <p>Or you could use <code>read</code> in a loop to read each NUL-delimited line. For in...
<p>You could process the list with gawk, setting the record separator to <code>\0</code> and the field separator to <code>=</code>:</p> <pre><code>gawk -v 'RS=\0' -F= '$1=="ENV_VAR_NAME" {print $2}' /proc/pid/environ </code></pre> <p>Or you could use <code>read</code> in a loop to read each NUL-delimited line. For in...
58, 387, 5282, 9013
bash, environment-variables, linux, sed
<h1>Using sed to get an env var from /proc/*/environ weirdness with \x00</h1> <p>I'm trying to grovel through some other processes environment to get a specific env var.</p> <p>So I've been trying a sed command like:</p> <p><code>sed -n "s/\x00ENV_VAR_NAME=\([^\x00]*\)\x00/\1/p" /proc/pid/environ</code></p> <p>But I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,630
bash
# Using sed to get an env var from /proc/*/environ weirdness with \x00 I'm trying to grovel through some other processes environment to get a specific env var. So I've been trying a sed command like: `sed -n "s/\x00ENV_VAR_NAME=\([^\x00]*\)\x00/\1/p" /proc/pid/environ` But I'm getting as output the full environ fil...
You could process the list with gawk, setting the record separator to `\0` and the field separator to `=`: ``` gawk -v 'RS=\0' -F= '$1=="ENV_VAR_NAME" {print $2}' /proc/pid/environ ``` Or you could use `read` in a loop to read each NUL-delimited line. For instance: ``` while read -d $'\0' ENV; do declare "$ENV"; don...
66382994
How to start fzf from a different directory than the current working directory?
19
2021-02-26 09:10:56
<p>I often use <code>fzf</code> to navigate the filesystem, especially the Alt-c key binding.</p> <p>When invoked, <code>fzf</code> generates a list from the current working directory.</p> <p>Is it possible to make <code>fzf</code> generate a list from a specified directory?</p> <p>I have tried <code>fzf &lt;dir&gt;</c...
21,378
1,020,139
2025-11-09 13:29:30
67,056,592
12
2021-04-12 10:12:37
128,384
2021-04-13 09:16:51
https://stackoverflow.com/q/66382994
https://stackoverflow.com/a/67056592
<p>Assuming you're using bash or similar, this is built into the default completion options which get installed with fzf: <a href="https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh" rel="noreferrer">https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh</a></p> <p>tldr; enter start file or di...
<p>Assuming you're using bash or similar, this is built into the default completion options which get installed with fzf: <a href="https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh" rel="noreferrer">https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh</a></p> <p>tldr; enter start file or di...
99, 218, 387, 113660, 134665
bash, directory, filesystems, fzf, vim-fzf
<h1>How to start fzf from a different directory than the current working directory?</h1> <p>I often use <code>fzf</code> to navigate the filesystem, especially the Alt-c key binding.</p> <p>When invoked, <code>fzf</code> generates a list from the current working directory.</p> <p>Is it possible to make <code>fzf</code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,631
bash
# How to start fzf from a different directory than the current working directory? I often use `fzf` to navigate the filesystem, especially the Alt-c key binding. When invoked, `fzf` generates a list from the current working directory. Is it possible to make `fzf` generate a list from a specified directory? I have t...
Assuming you're using bash or similar, this is built into the default completion options which get installed with fzf: <https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh> tldr; enter start file or directory, append `**` and hit `Tab`. So if you'd enter `cd /foo/**` then tab opens fzf with /foo as start...
33721892
Is Get-ChildItem -Recurse broken when there are square brackets in the input path?
19
2015-11-15 16:16:55
<p>OK, so I feel like this <em>must</em> be a bug in PowerShell, but I wanted to see if you guys think this sounds broken. It's quite an easy thing to reproduce, but I can see why it might not be a particularly common use case. The steps I've put below aren't actually what my script was doing, I was actually calculatin...
4,374
5,564,627
2019-03-26 23:45:46
55,367,757
12
2019-03-26 23:45:46
5,771,128
2019-03-26 23:45:46
https://stackoverflow.com/q/33721892
https://stackoverflow.com/a/55367757
<p>TL;DR: Use <code>-LiteralPath</code> for the folder when there might be unusual characters (inc. square brackets) in the names.</p> <hr> <p>I wasn't able to reproduce this as per the OP in PowerShell v5.1.17134.590.</p> <p>However, I was able to reproduce something similar, using the following command to attempt ...
<p>TL;DR: Use <code>-LiteralPath</code> for the folder when there might be unusual characters (inc. square brackets) in the names.</p> <hr> <p>I wasn't able to reproduce this as per the OP in PowerShell v5.1.17134.590.</p> <p>However, I was able to reproduce something similar, using the following command to attempt ...
526, 29006
get-childitem, powershell
<h1>Is Get-ChildItem -Recurse broken when there are square brackets in the input path?</h1> <p>OK, so I feel like this <em>must</em> be a bug in PowerShell, but I wanted to see if you guys think this sounds broken. It's quite an easy thing to reproduce, but I can see why it might not be a particularly common use case. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,632
bash
# Is Get-ChildItem -Recurse broken when there are square brackets in the input path? OK, so I feel like this *must* be a bug in PowerShell, but I wanted to see if you guys think this sounds broken. It's quite an easy thing to reproduce, but I can see why it might not be a particularly common use case. The steps I've p...
TL;DR: Use `-LiteralPath` for the folder when there might be unusual characters (inc. square brackets) in the names. --- I wasn't able to reproduce this as per the OP in PowerShell v5.1.17134.590. However, I was able to reproduce something similar, using the following command to attempt to list files in a folder I s...
43736021
Get exit code of process substitution with pipe into while loop
19
2017-05-02 10:48:26
<p>The following script calls another program reading its output in a while loop (see <a href="https://stackoverflow.com/questions/19570413/bash-how-to-pipe-input-to-while-loop-and-preserve-variables-after-loop-ends">Bash - How to pipe input to while loop and preserve variables after loop ends</a>):</p> <pre><code>whi...
3,660
null
2019-04-15 06:30:00
43,901,140
12
2017-05-10 19:24:21
45,375
2017-05-10 19:24:21
https://stackoverflow.com/q/43736021
https://stackoverflow.com/a/43901140
<p><sup>Note: <code>ls -d / /nosuch</code> is used as an example command below, because it fails (exit code <code>1</code>) while still producing stdout output (<code>/</code>) (in addition to stderr output).</sup></p> <h3>Bash v4.2+ solution:</h3> <p><a href="https://stackoverflow.com/a/43737188/45375">ccarton's hel...
<p><sup>Note: <code>ls -d / /nosuch</code> is used as an example command below, because it fails (exit code <code>1</code>) while still producing stdout output (<code>/</code>) (in addition to stderr output).</sup></p> <h3>Bash v4.2+ solution:</h3> <p><a href="https://stackoverflow.com/a/43737188/45375">ccarton's hel...
387, 63638
bash, process-substitution
<h1>Get exit code of process substitution with pipe into while loop</h1> <p>The following script calls another program reading its output in a while loop (see <a href="https://stackoverflow.com/questions/19570413/bash-how-to-pipe-input-to-while-loop-and-preserve-variables-after-loop-ends">Bash - How to pipe input to wh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,633
bash
# Get exit code of process substitution with pipe into while loop The following script calls another program reading its output in a while loop (see [Bash - How to pipe input to while loop and preserve variables after loop ends](https://stackoverflow.com/questions/19570413/bash-how-to-pipe-input-to-while-loop-and-pres...
Note: `ls -d / /nosuch` is used as an example command below, because it fails (exit code `1`) while still producing stdout output (`/`) (in addition to stderr output). ### Bash v4.2+ solution: [ccarton's helpful answer](https://stackoverflow.com/a/43737188/45375) works well in principle, but by default the `while` lo...
42998669
unzip file using 7z in powershell
19
2017-03-24 11:44:28
<p>What is the command to unzip a file using 7z in powershell?</p> <pre><code>set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" sz x $zipfilePath $destinationUnzipPath -aoa -r; </code></pre> <p>The command works fine but it says <strong>no files to process, everything is Ok</strong> rather than unzipping the file?</p>
64,463
6,000,623
2025-04-02 04:13:18
43,044,267
12
2017-03-27 10:45:57
6,000,623
2017-03-27 10:45:57
https://stackoverflow.com/q/42998669
https://stackoverflow.com/a/43044267
<p>This finally worked for me <code>sz x -o$destinationUnzipPath $zipfilePath -r ;</code></p>
<p>This finally worked for me <code>sz x -o$destinationUnzipPath $zipfilePath -r ;</code></p>
526, 5680
7zip, powershell
<h1>unzip file using 7z in powershell</h1> <p>What is the command to unzip a file using 7z in powershell?</p> <pre><code>set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" sz x $zipfilePath $destinationUnzipPath -aoa -r; </code></pre> <p>The command works fine but it says <strong>no files to process, everything is Ok</st...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,634
bash
# unzip file using 7z in powershell What is the command to unzip a file using 7z in powershell? ``` set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" sz x $zipfilePath $destinationUnzipPath -aoa -r; ``` The command works fine but it says **no files to process, everything is Ok** rather than unzipping the file?
This finally worked for me `sz x -o$destinationUnzipPath $zipfilePath -r ;`
42058539
What does the ${-#*i} mean in shell script?
19
2017-02-05 23:28:44
<p>There is a for loop in the file <code>/etc/profile</code> on CentOS 6:</p> <pre><code>for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" &gt;/dev/null 2&gt;&amp;1 fi fi done </code></pre> <p>What does the ...
7,571
4,857,099
2017-03-01 15:24:20
42,058,674
12
2017-02-05 23:51:20
3,476,320
2017-02-05 23:51:20
https://stackoverflow.com/q/42058539
https://stackoverflow.com/a/42058674
<p><code>$-</code> means shell flags.</p> <p><code>${-#*i}</code> means shell flags minus first match of <code>*i</code>.</p> <p>If these two are not equal, then the shell is considered interactive (flag <code>i</code> is present).</p>
<p><code>$-</code> means shell flags.</p> <p><code>${-#*i}</code> means shell flags minus first match of <code>*i</code>.</p> <p>If these two are not equal, then the shell is considered interactive (flag <code>i</code> is present).</p>
58, 390, 90291
centos6, linux, shell
<h1>What does the ${-#*i} mean in shell script?</h1> <p>There is a for loop in the file <code>/etc/profile</code> on CentOS 6:</p> <pre><code>for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" &gt;/dev/null 2&gt;&amp;1 ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,635
bash
# What does the ${-#*i} mean in shell script? There is a for loop in the file `/etc/profile` on CentOS 6: ``` for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null 2>&1 fi fi done ``` What does the `...
`$-` means shell flags. `${-#*i}` means shell flags minus first match of `*i`. If these two are not equal, then the shell is considered interactive (flag `i` is present).
39619956
Short way to run command if variable is set
19
2016-09-21 14:53:58
<p>This is a hack I just discovered:</p> <pre><code>DEBUG=true $DEBUG &amp;&amp; echo "Hello" </code></pre> <p>And this just happens to work because <code>true</code> is an actual command which returns 0, and the <code>&amp;&amp;</code> operator is happy with that:</p> <pre><code>» true » echo $? 0 </code></pre> <p...
16,589
647,991
2022-02-01 13:16:44
39,621,401
12
2016-09-21 16:01:01
1,126,841
2016-09-21 16:01:01
https://stackoverflow.com/q/39619956
https://stackoverflow.com/a/39621401
<p>Instead of relying on the value of the variable to have an executable value (and a value that you <em>want</em> to be executed), define a function that simply checks if the value is set.</p> <pre><code>debug () [[ -v DEBUG ]] debug &amp;&amp; echo "Hello" </code></pre> <p>If <code>DEBUG</code> is set <em>at all</...
<p>Instead of relying on the value of the variable to have an executable value (and a value that you <em>want</em> to be executed), define a function that simply checks if the value is set.</p> <pre><code>debug () [[ -v DEBUG ]] debug &amp;&amp; echo "Hello" </code></pre> <p>If <code>DEBUG</code> is set <em>at all</...
387
bash
<h1>Short way to run command if variable is set</h1> <p>This is a hack I just discovered:</p> <pre><code>DEBUG=true $DEBUG &amp;&amp; echo "Hello" </code></pre> <p>And this just happens to work because <code>true</code> is an actual command which returns 0, and the <code>&amp;&amp;</code> operator is happy with that:...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,636
bash
# Short way to run command if variable is set This is a hack I just discovered: ``` DEBUG=true $DEBUG && echo "Hello" ``` And this just happens to work because `true` is an actual command which returns 0, and the `&&` operator is happy with that: ``` » true » echo $? 0 ``` Is there a non-hackish way of execute a p...
Instead of relying on the value of the variable to have an executable value (and a value that you *want* to be executed), define a function that simply checks if the value is set. ``` debug () [[ -v DEBUG ]] debug && echo "Hello" ``` If `DEBUG` is set *at all*, even to the empty string, `debug` will succeed and the ...
26109816
Laravel, dump-autoload without Shell Access
19
2014-09-29 22:19:00
<p>I have two controllers with the same name:</p> <p><code>app\controllers\CareersController.php</code> (for public use) <code>app\controllers\Admin\CareersController.php</code> (for admins)</p> <p>Because of the naming conflict, I added <code>namespace admin;</code> to the admin controller.</p> <p>Everything works...
20,629
922,522
2021-05-19 07:56:36
26,112,371
12
2014-09-30 03:35:22
1,317,935
2014-09-30 03:43:49
https://stackoverflow.com/q/26109816
https://stackoverflow.com/a/26112371
<p>You dont need shell access. Artisan includes a <code>dump-autoload</code> function. You can just it via a PHP call within your app:</p> <pre><code>Route::get('/updateapp', function() { \Artisan::call('dump-autoload'); echo 'dump-autoload complete'; }); </code></pre> <p>Edit: just noticed you wrote <em>"com...
<p>You dont need shell access. Artisan includes a <code>dump-autoload</code> function. You can just it via a PHP call within your app:</p> <pre><code>Route::get('/updateapp', function() { \Artisan::call('dump-autoload'); echo 'dump-autoload complete'; }); </code></pre> <p>Edit: just noticed you wrote <em>"com...
5, 390, 75151, 78546, 88458
composer-php, laravel, laravel-4, php, shell
<h1>Laravel, dump-autoload without Shell Access</h1> <p>I have two controllers with the same name:</p> <p><code>app\controllers\CareersController.php</code> (for public use) <code>app\controllers\Admin\CareersController.php</code> (for admins)</p> <p>Because of the naming conflict, I added <code>namespace admin;</co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,637
bash
# Laravel, dump-autoload without Shell Access I have two controllers with the same name: `app\controllers\CareersController.php` (for public use) `app\controllers\Admin\CareersController.php` (for admins) Because of the naming conflict, I added `namespace admin;` to the admin controller. Everything works fine local...
You dont need shell access. Artisan includes a `dump-autoload` function. You can just it via a PHP call within your app: ``` Route::get('/updateapp', function() { \Artisan::call('dump-autoload'); echo 'dump-autoload complete'; }); ``` Edit: just noticed you wrote *"composer isn't installed on the server anywa...
25794905
Why does set -e; true && false && true not exit?
19
2014-09-11 18:45:52
<p>According to <a href="https://stackoverflow.com/a/2871034/274677">this accepted answer</a> using the <code>set -e</code> builtin should suffice for a bash script to exit on the first error. Yet, the following script:</p> <pre><code>#!/usr/bin/env bash set -e echo "a" echo "b" echo "about to fail" &amp;&amp; /bin/...
3,890
274,677
2017-12-04 01:39:00
25,795,239
12
2014-09-11 19:03:47
3,030,305
2014-09-11 19:43:23
https://stackoverflow.com/q/25794905
https://stackoverflow.com/a/25795239
<p>To simplify EtanReisner's detailed answer, <code>set -e</code> only exits on an 'uncaught' error. In your case:</p> <pre><code>echo "about to fail" &amp;&amp; /bin/false &amp;&amp; echo "foo" </code></pre> <p>The failing code, <code>/bin/false</code>, is followed by <code>&amp;&amp;</code> which tests its exit co...
<p>To simplify EtanReisner's detailed answer, <code>set -e</code> only exits on an 'uncaught' error. In your case:</p> <pre><code>echo "about to fail" &amp;&amp; /bin/false &amp;&amp; echo "foo" </code></pre> <p>The failing code, <code>/bin/false</code>, is followed by <code>&amp;&amp;</code> which tests its exit co...
387
bash
<h1>Why does set -e; true && false && true not exit?</h1> <p>According to <a href="https://stackoverflow.com/a/2871034/274677">this accepted answer</a> using the <code>set -e</code> builtin should suffice for a bash script to exit on the first error. Yet, the following script:</p> <pre><code>#!/usr/bin/env bash set -...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,638
bash
# Why does set -e; true && false && true not exit? According to [this accepted answer](https://stackoverflow.com/a/2871034/274677) using the `set -e` builtin should suffice for a bash script to exit on the first error. Yet, the following script: ``` #!/usr/bin/env bash set -e echo "a" echo "b" echo "about to fail" ...
To simplify EtanReisner's detailed answer, `set -e` only exits on an 'uncaught' error. In your case: ``` echo "about to fail" && /bin/false && echo "foo" ``` The failing code, `/bin/false`, is followed by `&&` which tests its exit code. Since `&&` tests the exit code, the assumption is that the programmer knew what h...
4511498
Powershell Invoke-Sqlcmd capture verbose output
19
2010-12-22 16:50:04
<p>I'm trying to capture the verbose output from the Invoke-Sqlcmd in Powershell. Anyone got any ideas to do this:</p> <p>i.e. </p> <pre><code>Invoke-Sqlcmd -Query "PRINT 'Hello World!';" -ServerInstance $Server -verbose &gt; D:\SqlLog.txt </code></pre> <p>The SqlLog.txt file should contain the text "Hello World!"...
61,962
287,139
2020-03-15 01:09:32
4,523,493
12
2010-12-24 00:34:30
4,916
2010-12-24 00:34:30
https://stackoverflow.com/q/4511498
https://stackoverflow.com/a/4523493
<p>Since capturing verbose output is not something one can do easily through the native constructs of the PowerShell host, you can always use the programatic access to the <a href="http://msdn.microsoft.com/en-us/library/dd144526(v=VS.85).aspx" rel="noreferrer">PowerShell object</a>. You can then gain access to the fiv...
<p>Since capturing verbose output is not something one can do easily through the native constructs of the PowerShell host, you can always use the programatic access to the <a href="http://msdn.microsoft.com/en-us/library/dd144526(v=VS.85).aspx" rel="noreferrer">PowerShell object</a>. You can then gain access to the fiv...
526
powershell
<h1>Powershell Invoke-Sqlcmd capture verbose output</h1> <p>I'm trying to capture the verbose output from the Invoke-Sqlcmd in Powershell. Anyone got any ideas to do this:</p> <p>i.e. </p> <pre><code>Invoke-Sqlcmd -Query "PRINT 'Hello World!';" -ServerInstance $Server -verbose &gt; D:\SqlLog.txt </code></pre> <p>T...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,639
bash
# Powershell Invoke-Sqlcmd capture verbose output I'm trying to capture the verbose output from the Invoke-Sqlcmd in Powershell. Anyone got any ideas to do this: i.e. ``` Invoke-Sqlcmd -Query "PRINT 'Hello World!';" -ServerInstance $Server -verbose > D:\SqlLog.txt ``` The SqlLog.txt file should contain the text "...
Since capturing verbose output is not something one can do easily through the native constructs of the PowerShell host, you can always use the programatic access to the [PowerShell object](http://msdn.microsoft.com/en-us/library/dd144526(v=VS.85).aspx). You can then gain access to the five different streams of informat...
2675552
Avoid line breaks when using out-file
19
2010-04-20 13:44:32
<p>I'm getting a little frustrated on a little PowerShell script I'm writing.</p> <p>Basically I loop through text files to check every line against an array of regular expression patterns. The result gets piped to the out-file cmdlet which appends it to another text file.</p> <pre><code>Get-ChildItem $logdir -Recurse ...
19,776
82,820
2024-01-25 21:41:18
2,678,074
12
2010-04-20 19:37:35
75,224
2010-04-20 19:37:35
https://stackoverflow.com/q/2675552
https://stackoverflow.com/a/2678074
<p>Why don't you use <code>Add-Content</code>?</p> <pre><code>gci $logdir -rec *.txt | gc | select-string $pattern | add-content $csvpath </code></pre> <p>You don't need to specify the width and <code>-append</code> switch, the file size is not doubled by default (although you can specify encoding) and it seems that ...
<p>Why don't you use <code>Add-Content</code>?</p> <pre><code>gci $logdir -rec *.txt | gc | select-string $pattern | add-content $csvpath </code></pre> <p>You don't need to specify the width and <code>-append</code> switch, the file size is not doubled by default (although you can specify encoding) and it seems that ...
526, 9313
line-breaks, powershell
<h1>Avoid line breaks when using out-file</h1> <p>I'm getting a little frustrated on a little PowerShell script I'm writing.</p> <p>Basically I loop through text files to check every line against an array of regular expression patterns. The result gets piped to the out-file cmdlet which appends it to another text file....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,640
bash
# Avoid line breaks when using out-file I'm getting a little frustrated on a little PowerShell script I'm writing. Basically I loop through text files to check every line against an array of regular expression patterns. The result gets piped to the out-file cmdlet which appends it to another text file. ``` Get-Child...
Why don't you use `Add-Content`? ``` gci $logdir -rec *.txt | gc | select-string $pattern | add-content $csvpath ``` You don't need to specify the width and `-append` switch, the file size is not doubled by default (although you can specify encoding) and it seems that there is no problem with the empty lines like you...
2644742
Getting ID of an instance newly launched with ec2-api-tools
19
2010-04-15 11:19:16
<p>I'm launching an EC2 instance, by invoking <a href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/index.html?ApiReference-cmd-RunInstances.html" rel="noreferrer"><code>ec2-run-instances</code></a> from simple a bash script, and want to perform further operations on that instance (e.g. associa...
9,074
56,285
2018-10-30 12:31:05
2,644,798
12
2010-04-15 11:29:06
56,285
2010-04-15 12:12:51
https://stackoverflow.com/q/2644742
https://stackoverflow.com/a/2644798
<p>Ok, at least something like this should work:</p> <pre><code>instance_id=$(ec2-run-instances ami-dd8ea5a9 [...] | awk '/INSTANCE/{print $2}') </code></pre> <p>Admittedly I was a bit lazy thinking that it's quicker to ask on SO than to relearn some AWK basics... :-)</p> <p><strong>Edit</strong>: simplified AWK us...
<p>Ok, at least something like this should work:</p> <pre><code>instance_id=$(ec2-run-instances ami-dd8ea5a9 [...] | awk '/INSTANCE/{print $2}') </code></pre> <p>Admittedly I was a bit lazy thinking that it's quicker to ask on SO than to relearn some AWK basics... :-)</p> <p><strong>Edit</strong>: simplified AWK us...
387, 531, 990, 12375, 54462
amazon-ec2, awk, bash, ec2-api-tools, scripting
<h1>Getting ID of an instance newly launched with ec2-api-tools</h1> <p>I'm launching an EC2 instance, by invoking <a href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/index.html?ApiReference-cmd-RunInstances.html" rel="noreferrer"><code>ec2-run-instances</code></a> from simple a bash script, ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,641
bash
# Getting ID of an instance newly launched with ec2-api-tools I'm launching an EC2 instance, by invoking [`ec2-run-instances`](http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/index.html?ApiReference-cmd-RunInstances.html) from simple a bash script, and want to perform further operations on that in...
Ok, at least something like this should work: ``` instance_id=$(ec2-run-instances ami-dd8ea5a9 [...] | awk '/INSTANCE/{print $2}') ``` Admittedly I was a bit lazy thinking that it's quicker to ask on SO than to relearn some AWK basics... :-) **Edit**: simplified AWK usage as Dennis suggested. Also, using `$()` inste...
37976241
Writing data to file in Dockerfile
18
2016-06-22 18:59:13
<p>I have a shell script, script.sh, that writes some lines to a file:</p> <pre><code>#!/usr/bin/env bash printf "blah blah blah blah\n" | sudo tee file.txt </code></pre> <p>Now in my Dockerfile, I add this script and run it, then attempt to add the generated <code>file.txt</code>:</p> <pre><code>ADD script.sh . ...
59,042
6,460,141
2023-02-20 20:02:52
37,992,764
12
2016-06-23 13:15:26
2,227,804
2023-02-20 20:02:52
https://stackoverflow.com/q/37976241
https://stackoverflow.com/a/37992764
<p>When you <code>RUN chmod 755 script.sh &amp;&amp; ./script.sh</code> it actually execute this script <strong>inside</strong> the docker container (ie: in the docker layer).</p> <p>When you <code>ADD file.txt .</code> you are trying to add a file from your <strong>local</strong> filesystem inside the docker container...
<p>When you <code>RUN chmod 755 script.sh &amp;&amp; ./script.sh</code> it actually execute this script <strong>inside</strong> the docker container (ie: in the docker layer).</p> <p>When you <code>ADD file.txt .</code> you are trying to add a file from your <strong>local</strong> filesystem inside the docker container...
387, 390, 33304, 90304, 108477
bash, docker, dockerfile, file-writing, shell
<h1>Writing data to file in Dockerfile</h1> <p>I have a shell script, script.sh, that writes some lines to a file:</p> <pre><code>#!/usr/bin/env bash printf "blah blah blah blah\n" | sudo tee file.txt </code></pre> <p>Now in my Dockerfile, I add this script and run it, then attempt to add the generated <code>file....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,642
bash
# Writing data to file in Dockerfile I have a shell script, script.sh, that writes some lines to a file: ``` #!/usr/bin/env bash printf "blah blah blah blah\n" | sudo tee file.txt ``` Now in my Dockerfile, I add this script and run it, then attempt to add the generated `file.txt`: ``` ADD script.sh . RUN chmod 7...
When you `RUN chmod 755 script.sh && ./script.sh` it actually execute this script **inside** the docker container (ie: in the docker layer). When you `ADD file.txt .` you are trying to add a file from your **local** filesystem inside the docker container (ie: in a new docker layer). You can't do that because the `fil...
21273826
How to create a remote server on LAN instead of using GitHub?
18
2014-01-22 03:51:56
<p>Can I create my own remote server instead of using GitHub? </p> <p>i.e Can I make a remote server on LAN where 3 computers are sharing a drive on a network to do the collaborative work using Gitbash? </p>
21,202
1,754,902
2020-06-02 00:04:53
21,274,699
12
2014-01-22 05:12:28
735,336
2018-03-19 21:34:22
https://stackoverflow.com/q/21273826
https://stackoverflow.com/a/21274699
<p>There are several ways to do this</p> <ol> <li>Host internal repositories like <a href="http://gitlab.com" rel="noreferrer">Gitlab</a> or <a href="https://www.atlassian.com/software/stash" rel="noreferrer">Stash</a>. This will be similar to services like BitBucket or GitHub</li> <li>If you want to have a simple ser...
<p>There are several ways to do this</p> <ol> <li>Host internal repositories like <a href="http://gitlab.com" rel="noreferrer">Gitlab</a> or <a href="https://www.atlassian.com/software/stash" rel="noreferrer">Stash</a>. This will be similar to services like BitBucket or GitHub</li> <li>If you want to have a simple ser...
119, 131, 2090, 61874
collaboration, git, git-bash, lan
<h1>How to create a remote server on LAN instead of using GitHub?</h1> <p>Can I create my own remote server instead of using GitHub? </p> <p>i.e Can I make a remote server on LAN where 3 computers are sharing a drive on a network to do the collaborative work using Gitbash? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,643
bash
# How to create a remote server on LAN instead of using GitHub? Can I create my own remote server instead of using GitHub? i.e Can I make a remote server on LAN where 3 computers are sharing a drive on a network to do the collaborative work using Gitbash?
There are several ways to do this 1. Host internal repositories like [Gitlab](http://gitlab.com) or [Stash](https://www.atlassian.com/software/stash). This will be similar to services like BitBucket or GitHub 2. If you want to have a simple service with SSH authentication - user3159253 has already answered that 3. A v...
15969662
Assure only 1 instance of PowerShell Script is Running at any given Time
18
2013-04-12 11:01:56
<p>I am writing a batch script in PowerShell v1 that will get scheduled to run let's say once every minute. Inevitably, there will come a time when the job needs more than 1 minute to complete and now we have two instances of the script running, and then possibly 3, etc...</p> <p>I want to avoid this by having the scr...
18,115
155,409
2023-09-07 19:27:33
15,970,187
12
2013-04-12 11:28:45
9,833
2013-04-12 11:28:45
https://stackoverflow.com/q/15969662
https://stackoverflow.com/a/15970187
<p>If the script was launched using the powershell.exe -File switch, you can detect all powershell instances that have the script name present in the process commandline property:</p> <pre><code>Get-WmiObject Win32_Process -Filter "Name='powershell.exe' AND CommandLine LIKE '%script.ps1%'" </code></pre>
<p>If the script was launched using the powershell.exe -File switch, you can detect all powershell instances that have the script name present in the process commandline property:</p> <pre><code>Get-WmiObject Win32_Process -Filter "Name='powershell.exe' AND CommandLine LIKE '%script.ps1%'" </code></pre>
64, 526
powershell, windows
<h1>Assure only 1 instance of PowerShell Script is Running at any given Time</h1> <p>I am writing a batch script in PowerShell v1 that will get scheduled to run let's say once every minute. Inevitably, there will come a time when the job needs more than 1 minute to complete and now we have two instances of the script r...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,644
bash
# Assure only 1 instance of PowerShell Script is Running at any given Time I am writing a batch script in PowerShell v1 that will get scheduled to run let's say once every minute. Inevitably, there will come a time when the job needs more than 1 minute to complete and now we have two instances of the script running, a...
If the script was launched using the powershell.exe -File switch, you can detect all powershell instances that have the script name present in the process commandline property: ``` Get-WmiObject Win32_Process -Filter "Name='powershell.exe' AND CommandLine LIKE '%script.ps1%'" ```
4491908
Performance Comparison of Shell Scripts vs high level interpreted langs (C#/Java/etc.)
18
2010-12-20 16:57:17
<p>First - This is not meant to be a 'which is better, ignorant nonionic war thread'... But rather, I generally need help in making an architecture decision / argument to put forward to my boss.</p> <p>Skipping the details - I simply just would love to know and find the results of anyone who has done some performance ...
17,484
191,206
2014-12-17 22:35:24
4,502,777
12
2010-12-21 18:45:50
63,471
2010-12-21 18:52:01
https://stackoverflow.com/q/4491908
https://stackoverflow.com/a/4502777
<p>Once upon a time, ye olde The Great Computer Language Shootout did include some shell scripts. </p> <p>So, courtesy of the <a href="http://web.archive.org/web/20040814112219/shootout.alioth.debian.org/craps.php" rel="noreferrer">Internet Archive, <strong>from 2004</strong></a> -</p> <p><strong>Note</strong> the sh...
<p>Once upon a time, ye olde The Great Computer Language Shootout did include some shell scripts. </p> <p>So, courtesy of the <a href="http://web.archive.org/web/20040814112219/shootout.alioth.debian.org/craps.php" rel="noreferrer">Internet Archive, <strong>from 2004</strong></a> -</p> <p><strong>Note</strong> the sh...
9, 17, 390, 598, 4407
c#, interpreted-language, java, performance, shell
<h1>Performance Comparison of Shell Scripts vs high level interpreted langs (C#/Java/etc.)</h1> <p>First - This is not meant to be a 'which is better, ignorant nonionic war thread'... But rather, I generally need help in making an architecture decision / argument to put forward to my boss.</p> <p>Skipping the details ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,645
bash
# Performance Comparison of Shell Scripts vs high level interpreted langs (C#/Java/etc.) First - This is not meant to be a 'which is better, ignorant nonionic war thread'... But rather, I generally need help in making an architecture decision / argument to put forward to my boss. Skipping the details - I simply just ...
Once upon a time, ye olde The Great Computer Language Shootout did include some shell scripts. So, courtesy of the [Internet Archive, **from 2004**](http://web.archive.org/web/20040814112219/shootout.alioth.debian.org/craps.php) - **Note** the shell scripts didn't have programs for many of the tests. ``` Score M...
4257098
How to pass variables from python script to bash script
18
2010-11-23 14:38:51
<p>I have a bash script, a.sh , and in it I have call a python script b.py . The python script calculates something, and I want it to return a value that will be used later in a.sh . I know I can do</p> <p>In a.sh:</p> <pre><code>var=`python b.py` </code></pre> <p>In b.py:</p> <pre><code>print x # when x is the val...
29,862
170,102
2022-01-20 07:46:08
4,257,122
12
2010-11-23 14:42:55
456,188
2010-11-23 15:35:56
https://stackoverflow.com/q/4257098
https://stackoverflow.com/a/4257122
<p>I would print it to a file chosen on the command line then I'd get that value in bash with something like <code>cat</code>.</p> <p>So you'd go:</p> <pre><code>python b.py tempfile.txt var=`cat tempfile.txt` rm tempfile.txt </code></pre> <p><strong>[EDIT, another idea based on other answers]</strong></p> <p>Your ...
<p>I would print it to a file chosen on the command line then I'd get that value in bash with something like <code>cat</code>.</p> <p>So you'd go:</p> <pre><code>python b.py tempfile.txt var=`cat tempfile.txt` rm tempfile.txt </code></pre> <p><strong>[EDIT, another idea based on other answers]</strong></p> <p>Your ...
16, 276, 387
bash, python, variables
<h1>How to pass variables from python script to bash script</h1> <p>I have a bash script, a.sh , and in it I have call a python script b.py . The python script calculates something, and I want it to return a value that will be used later in a.sh . I know I can do</p> <p>In a.sh:</p> <pre><code>var=`python b.py` </cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,646
bash
# How to pass variables from python script to bash script I have a bash script, a.sh , and in it I have call a python script b.py . The python script calculates something, and I want it to return a value that will be used later in a.sh . I know I can do In a.sh: ``` var=`python b.py` ``` In b.py: ``` print x # whe...
I would print it to a file chosen on the command line then I'd get that value in bash with something like `cat`. So you'd go: ``` python b.py tempfile.txt var=`cat tempfile.txt` rm tempfile.txt ``` **[EDIT, another idea based on other answers]** Your other option is to format your output carefully so you can use ba...
46029517
Docker - run error on window git bash for -v
17
2017-09-04 02:20:50
<p><a href="https://i.sstatic.net/DQcmW.png" rel="noreferrer"><img src="https://i.sstatic.net/DQcmW.png" alt="error pic"></a></p> <p>I run docker in my win10, but use <code>-v</code> params has a error.</p> <pre><code>docker run --privileged=true -d --name=ubuntu14.04 -v e:/docker/data:/data ubuntu /bin/bash </code><...
11,346
6,488,200
2022-06-25 05:11:39
46,030,672
12
2017-09-04 05:20:55
6,309
2017-09-04 07:09:20
https://stackoverflow.com/q/46029517
https://stackoverflow.com/a/46030672
<p>If possible, try the same command in a regular DOS session, instead of a git bash.</p> <p>That will avoid the git bash session to automatically resolve <code>/bin/bash</code> to <code>C:/Program Files/Git/usr/bin/bash</code>, which won't be known at all by the ubuntu container.</p> <p>The OP confirms this is worki...
<p>If possible, try the same command in a regular DOS session, instead of a git bash.</p> <p>That will avoid the git bash session to automatically resolve <code>/bin/bash</code> to <code>C:/Program Files/Git/usr/bin/bash</code>, which won't be known at all by the ubuntu container.</p> <p>The OP confirms this is worki...
64, 119, 387, 90304
bash, docker, git, windows
<h1>Docker - run error on window git bash for -v</h1> <p><a href="https://i.sstatic.net/DQcmW.png" rel="noreferrer"><img src="https://i.sstatic.net/DQcmW.png" alt="error pic"></a></p> <p>I run docker in my win10, but use <code>-v</code> params has a error.</p> <pre><code>docker run --privileged=true -d --name=ubuntu1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,647
bash
# Docker - run error on window git bash for -v [![error pic](https://i.sstatic.net/DQcmW.png)](https://i.sstatic.net/DQcmW.png) I run docker in my win10, but use `-v` params has a error. ``` docker run --privileged=true -d --name=ubuntu14.04 -v e:/docker/data:/data ubuntu /bin/bash ``` error: ``` C:\Program Files\...
If possible, try the same command in a regular DOS session, instead of a git bash. That will avoid the git bash session to automatically resolve `/bin/bash` to `C:/Program Files/Git/usr/bin/bash`, which won't be known at all by the ubuntu container. The OP confirms this is working, provided the following options are ...
28719148
What does the at-sign @ mean in the bash command: date --date @...?
17
2015-02-25 12:33:36
<p>Searching the internet I found explanations only for '$@', meaning 'expand to positional parameters'. But I couldn't find anything about the @ sign by itself.</p> <p>I stumbled over it in the third snipped of the accepted answer to this question: <a href="https://superuser.com/questions/611538/is-there-a-way-to-dis...
19,480
1,785,730
2023-03-16 22:14:26
28,719,325
12
2015-02-25 12:41:58
1,258,041
2015-02-25 12:47:33
https://stackoverflow.com/q/28719148
https://stackoverflow.com/a/28719325
<p>In the context you show, the <code>@</code> is in the beginning of the <code>--date</code> argument to the <code>date</code> command:</p> <pre><code>date -u --date @$((`date +%s` - $date1)) +%H:%M:%S </code></pre> <p>In that case it means that the argument should be treated as the number of seconds since epoch, se...
<p>In the context you show, the <code>@</code> is in the beginning of the <code>--date</code> argument to the <code>date</code> command:</p> <pre><code>date -u --date @$((`date +%s` - $date1)) +%H:%M:%S </code></pre> <p>In that case it means that the argument should be treated as the number of seconds since epoch, se...
387
bash
<h1>What does the at-sign @ mean in the bash command: date --date @...?</h1> <p>Searching the internet I found explanations only for '$@', meaning 'expand to positional parameters'. But I couldn't find anything about the @ sign by itself.</p> <p>I stumbled over it in the third snipped of the accepted answer to this qu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,648
bash
# What does the at-sign @ mean in the bash command: date --date @...? Searching the internet I found explanations only for '$@', meaning 'expand to positional parameters'. But I couldn't find anything about the @ sign by itself. I stumbled over it in the third snipped of the accepted answer to this question: <https:/...
In the context you show, the `@` is in the beginning of the `--date` argument to the `date` command: ``` date -u --date @$((`date +%s` - $date1)) +%H:%M:%S ``` In that case it means that the argument should be treated as the number of seconds since epoch, see an example in `man date`: > Convert seconds since the epo...
26372360
Powershell script indentation for long strings
17
2014-10-14 23:58:24
<p>This problem does not have to be solved this way, but it would save me a lot of precious time if it can be:</p> <p>I have been logging "line at a time" to a log file. Like this:</p> <pre><code>$mylogentry = "A string of text containing information" $mylogentry | out-file -append $log_file_path $array_of_log_entrie...
21,194
3,413,047
2019-03-28 13:03:18
26,373,425
12
2014-10-15 02:17:34
3,905,079
2014-10-15 10:42:30
https://stackoverflow.com/q/26372360
https://stackoverflow.com/a/26373425
<p>You can't escape away the tabs or spaces you inserted into the string; they're inside the quotes and part of the string now (and so are the line breaks for that matter).</p> <h2>You have a few options:</h2> <ol> <li>Don't break the string at all; let it ride. Obviously not what you want to do, but it works.</li>...
<p>You can't escape away the tabs or spaces you inserted into the string; they're inside the quotes and part of the string now (and so are the line breaks for that matter).</p> <h2>You have a few options:</h2> <ol> <li>Don't break the string at all; let it ride. Obviously not what you want to do, but it works.</li>...
526
powershell
<h1>Powershell script indentation for long strings</h1> <p>This problem does not have to be solved this way, but it would save me a lot of precious time if it can be:</p> <p>I have been logging "line at a time" to a log file. Like this:</p> <pre><code>$mylogentry = "A string of text containing information" $mylogentr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,649
bash
# Powershell script indentation for long strings This problem does not have to be solved this way, but it would save me a lot of precious time if it can be: I have been logging "line at a time" to a log file. Like this: ``` $mylogentry = "A string of text containing information" $mylogentry | out-file -append $log_f...
You can't escape away the tabs or spaces you inserted into the string; they're inside the quotes and part of the string now (and so are the line breaks for that matter). ## You have a few options: 1. Don't break the string at all; let it ride. Obviously not what you want to do, but it works. 2. Use @Matt's suggestion...
22629240
piping from stdin to a python code in a bash script
17
2014-03-25 08:42:50
<p>I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows:</p> <pre><code>f input.txt &gt; output.txt </code></pre> <p>In the example above, the python code will read from input.txt and will write to output.txt. </p> <p>I'm ...
26,656
2,699,231
2023-07-05 04:05:51
22,629,930
12
2014-03-25 09:14:00
2,836,621
2014-03-25 22:01:46
https://stackoverflow.com/q/22629240
https://stackoverflow.com/a/22629930
<p><strong>Updated Answer</strong></p> <p>If you absolutely must run the way you ask, you could do something like this:</p> <pre><code>#!/bin/bash python -c 'import os for i in range(3): for j in range(3): print(i + j) ' &lt; "$1" </code></pre> <p><strong>Original Answer</strong></p> <p>Save your python co...
<p><strong>Updated Answer</strong></p> <p>If you absolutely must run the way you ask, you could do something like this:</p> <pre><code>#!/bin/bash python -c 'import os for i in range(3): for j in range(3): print(i + j) ' &lt; "$1" </code></pre> <p><strong>Original Answer</strong></p> <p>Save your python co...
16, 387
bash, python
<h1>piping from stdin to a python code in a bash script</h1> <p>I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows:</p> <pre><code>f input.txt &gt; output.txt </code></pre> <p>In the example above, the python code will re...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,650
bash
# piping from stdin to a python code in a bash script I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows: ``` f input.txt > output.txt ``` In the example above, the python code will read from input.txt and will write to ...
**Updated Answer** If you absolutely must run the way you ask, you could do something like this: ``` #!/bin/bash python -c 'import os for i in range(3): for j in range(3): print(i + j) ' < "$1" ``` **Original Answer** Save your python code in a file called `script.py` and change your script `f` to this: `...
10571335
How to get a list of available files using wget or curl?
17
2012-05-13 11:28:03
<p>I'd like to know if it's possible to do an <code>ls</code> of a URL, so I can see what *.js files are available in a website, for example. Something like:</p> <pre><code>wget --list-files -A.js stackoverflow.com </code></pre> <p>and get</p> <pre><code>ajax/libs/jquery/1.7.1/jquery.min.js js/full.js js/stub.js ......
65,293
355,567
2020-11-23 15:50:08
10,571,500
12
2012-05-13 11:55:24
1,172,002
2012-05-13 11:55:24
https://stackoverflow.com/q/10571335
https://stackoverflow.com/a/10571500
<p>You can't do the equivalent of an <code>ls</code> unless the server provides such listings itself. You could however retrieve <code>index.html</code> and then check for includes, e.g. something like</p> <pre><code>wget -O - http://www.example.com | grep "type=.\?text/javascript.\?" </code></pre> <p>Note that this ...
<p>You can't do the equivalent of an <code>ls</code> unless the server provides such listings itself. You could however retrieve <code>index.html</code> and then check for includes, e.g. something like</p> <pre><code>wget -O - http://www.example.com | grep "type=.\?text/javascript.\?" </code></pre> <p>Note that this ...
387, 391, 1554, 5583
bash, curl, terminal, wget
<h1>How to get a list of available files using wget or curl?</h1> <p>I'd like to know if it's possible to do an <code>ls</code> of a URL, so I can see what *.js files are available in a website, for example. Something like:</p> <pre><code>wget --list-files -A.js stackoverflow.com </code></pre> <p>and get</p> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,651
bash
# How to get a list of available files using wget or curl? I'd like to know if it's possible to do an `ls` of a URL, so I can see what *.js files are available in a website, for example. Something like: ``` wget --list-files -A.js stackoverflow.com ``` and get ``` ajax/libs/jquery/1.7.1/jquery.min.js js/full.js js/...
You can't do the equivalent of an `ls` unless the server provides such listings itself. You could however retrieve `index.html` and then check for includes, e.g. something like ``` wget -O - http://www.example.com | grep "type=.\?text/javascript.\?" ``` Note that this relies on the HTML being formatted in a certain w...
9690756
How to run Java from Cygwin
17
2012-03-13 19:31:54
<p>I'm trying to write a BASH script to get my Java program to run(common issue, right?). I just can't quite get it to work. After many edits, here's how I am trying to set the classpath and then execute the program:</p> <pre><code>java -classpath 'cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar:/cygdrive /...
22,837
959,792
2016-12-19 23:46:04
9,690,985
12
2012-03-13 19:48:00
203,654
2012-03-13 20:00:18
https://stackoverflow.com/q/9690756
https://stackoverflow.com/a/9690985
<ul> <li>Java classpath uses semicolon as the token separator.</li> <li>Use backticks instead of single quotes</li> </ul> <p>Try:</p> <pre><code>java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar;/cygdrive /c/Projects/common/lib/jdom-1.0.jar;/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar; /cyg...
<ul> <li>Java classpath uses semicolon as the token separator.</li> <li>Use backticks instead of single quotes</li> </ul> <p>Try:</p> <pre><code>java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar;/cygdrive /c/Projects/common/lib/jdom-1.0.jar;/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar; /cyg...
17, 387, 1731, 8005
bash, classpath, cygwin, java
<h1>How to run Java from Cygwin</h1> <p>I'm trying to write a BASH script to get my Java program to run(common issue, right?). I just can't quite get it to work. After many edits, here's how I am trying to set the classpath and then execute the program:</p> <pre><code>java -classpath 'cygpath -u "/cygdrive/c/Project...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,652
bash
# How to run Java from Cygwin I'm trying to write a BASH script to get my Java program to run(common issue, right?). I just can't quite get it to work. After many edits, here's how I am trying to set the classpath and then execute the program: ``` java -classpath 'cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0....
- Java classpath uses semicolon as the token separator. - Use backticks instead of single quotes Try: ``` java -classpath `cygpath -u "/cygdrive/c/Projects/common/lib/rome-1.0.jar;/cygdrive /c/Projects/common/lib/jdom-1.0.jar;/cygdrive/c/Projects/common/lib/jsoup-1.6.1.jar; /cygdrive/c/Projects/common/lib/mysql-conne...
5978108
Open Vim from within a Bash shell script
17
2011-05-12 12:38:31
<p>I want to write a Bash shell script that does the following:</p> <ol> <li>Opens a file using Vim;</li> <li>Writes something into the file;</li> <li>Saves the file and exits.</li> </ol> <pre><code>echo 'About to open a file' vim file.txt # I need to use vim application to open a file # Now write something into file....
37,051
246,365
2025-01-15 17:44:59
5,978,288
12
2011-05-12 12:55:36
457,352
2011-05-12 12:55:36
https://stackoverflow.com/q/5978108
https://stackoverflow.com/a/5978288
<p>Vim has several options:</p> <ul> <li><code>-c</code> => pass ex commands. Example: <code>vim myfile.txt -c 'wq'</code> to force the last line of a file to be newline terminated (unless <code>binary</code> is set in some way by a script)</li> <li><code>-s</code> => play a scriptout that was recorded with <code>-W</...
<p>Vim has several options:</p> <ul> <li><code>-c</code> => pass ex commands. Example: <code>vim myfile.txt -c 'wq'</code> to force the last line of a file to be newline terminated (unless <code>binary</code> is set in some way by a script)</li> <li><code>-s</code> => play a scriptout that was recorded with <code>-W</...
58, 370, 387
bash, linux, vim
<h1>Open Vim from within a Bash shell script</h1> <p>I want to write a Bash shell script that does the following:</p> <ol> <li>Opens a file using Vim;</li> <li>Writes something into the file;</li> <li>Saves the file and exits.</li> </ol> <pre><code>echo 'About to open a file' vim file.txt # I need to use vim applicati...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,653
bash
# Open Vim from within a Bash shell script I want to write a Bash shell script that does the following: 1. Opens a file using Vim; 2. Writes something into the file; 3. Saves the file and exits. ``` echo 'About to open a file' vim file.txt # I need to use vim application to open a file # Now write something into fi...
Vim has several options: - `-c` => pass ex commands. Example: `vim myfile.txt -c 'wq'` to force the last line of a file to be newline terminated (unless `binary` is set in some way by a script) - `-s` => play a scriptout that was recorded with `-W`. For example, if your file contains `ZZ`, then `vim myfile.txt -s the_...
5946873
Include non-0 exit codes in the subsequent bash prompt
17
2011-05-10 07:52:01
<p>Occasionally, I will run a command that has a lot of output. Occasionally, the last 30-40 lines of that output (a.k.a. the only part of the output I ever really see) is fine, but much further up, there was an error. I'd like to make it easier to notice that the command failed. To do so, I want the return code to be ...
7,071
367,271
2017-03-10 20:33:50
5,946,917
12
2011-05-10 07:55:14
20,862
2011-05-10 07:55:14
https://stackoverflow.com/q/5946873
https://stackoverflow.com/a/5946917
<p>A little bit of <code>printf</code> abuse:</p> <pre><code>printf '%.*s' $? $? </code></pre>
<p>A little bit of <code>printf</code> abuse:</p> <pre><code>printf '%.*s' $? $? </code></pre>
387, 9938
bash, command-prompt
<h1>Include non-0 exit codes in the subsequent bash prompt</h1> <p>Occasionally, I will run a command that has a lot of output. Occasionally, the last 30-40 lines of that output (a.k.a. the only part of the output I ever really see) is fine, but much further up, there was an error. I'd like to make it easier to notice ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,654
bash
# Include non-0 exit codes in the subsequent bash prompt Occasionally, I will run a command that has a lot of output. Occasionally, the last 30-40 lines of that output (a.k.a. the only part of the output I ever really see) is fine, but much further up, there was an error. I'd like to make it easier to notice that the ...
A little bit of `printf` abuse: ``` printf '%.*s' $? $? ```
4737794
Redirecting two files to standard input
17
2011-01-19 16:22:06
<p>There are several unix commands that are designed to operate on two files. Commonly such commands allow the contents for one of the "files" to be read from standard input by using a single dash in place of the file name.</p> <p>I just came across <a href="http://mywiki.wooledge.org/BashFAQ/036" rel="noreferrer">a ...
7,920
101,186
2011-01-19 20:15:40
4,738,866
12
2011-01-19 17:59:51
26,428
2011-01-19 20:15:40
https://stackoverflow.com/q/4737794
https://stackoverflow.com/a/4738866
<p>Bash, Korn shell (ksh93, anyway) and Z shell all support <a href="http://mywiki.wooledge.org/ProcessSubstitution" rel="noreferrer">process substitution</a>. These appear as files to the utility. Try this:</p> <pre><code>$ bash -c 'echo &lt;(echo)' /dev/fd/63 $ ksh -c 'echo &lt;(echo)' /dev/fd/4 $ zsh -c 'echo &lt;(...
<p>Bash, Korn shell (ksh93, anyway) and Z shell all support <a href="http://mywiki.wooledge.org/ProcessSubstitution" rel="noreferrer">process substitution</a>. These appear as files to the utility. Try this:</p> <pre><code>$ bash -c 'echo &lt;(echo)' /dev/fd/63 $ ksh -c 'echo &lt;(echo)' /dev/fd/4 $ zsh -c 'echo &lt;(...
387, 10327, 31901
bash, http-redirect, sh
<h1>Redirecting two files to standard input</h1> <p>There are several unix commands that are designed to operate on two files. Commonly such commands allow the contents for one of the "files" to be read from standard input by using a single dash in place of the file name.</p> <p>I just came across <a href="http://myw...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,655
bash
# Redirecting two files to standard input There are several unix commands that are designed to operate on two files. Commonly such commands allow the contents for one of the "files" to be read from standard input by using a single dash in place of the file name. I just came across [a technique](http://mywiki.wooledge...
Bash, Korn shell (ksh93, anyway) and Z shell all support [process substitution](http://mywiki.wooledge.org/ProcessSubstitution). These appear as files to the utility. Try this: ``` $ bash -c 'echo <(echo)' /dev/fd/63 $ ksh -c 'echo <(echo)' /dev/fd/4 $ zsh -c 'echo <(echo)' /proc/self/fd/12 ``` You'll see file descri...
2437976
Get color output in bash
17
2010-03-13 10:24:14
<p>when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors dependeing on, for insta...
16,145
171,546
2014-11-19 11:06:19
2,438,008
12
2010-03-13 10:36:00
115,698
2010-03-13 10:36:00
https://stackoverflow.com/q/2437976
https://stackoverflow.com/a/2438008
<p>Sure, just use Bash functions, like, say this one:</p> <pre><code>make() { pathpat="(/[^/]*)+:[0-9]+" ccred=$(echo -e "\033[0;31m") ccyellow=$(echo -e "\033[0;33m") ccend=$(echo -e "\033[0m") /usr/bin/make "$@" 2&gt;&amp;1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&amp;$ccend%g" -e "/[Ww]arning[: ]/ s%...
<p>Sure, just use Bash functions, like, say this one:</p> <pre><code>make() { pathpat="(/[^/]*)+:[0-9]+" ccred=$(echo -e "\033[0;31m") ccyellow=$(echo -e "\033[0;33m") ccend=$(echo -e "\033[0m") /usr/bin/make "$@" 2&gt;&amp;1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&amp;$ccend%g" -e "/[Ww]arning[: ]/ s%...
387
bash
<h1>Get color output in bash</h1> <p>when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get differe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,656
bash
# Get color output in bash when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors...
Sure, just use Bash functions, like, say this one: ``` make() { pathpat="(/[^/]*)+:[0-9]+" ccred=$(echo -e "\033[0;31m") ccyellow=$(echo -e "\033[0;33m") ccend=$(echo -e "\033[0m") /usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend...
55978911
What does triple-single-quote mean in bash?
16
2019-05-04 02:13:15
<p>I have seen lots of uses of single and double-quotes in bash, as well as backtick-quotes, but have never seen what follows. What is the meaning of the transcript below, which seems to show that triple-single-quoting is recognized as meaningful by bash and further seems to show that single quotes inside this thing al...
13,869
3,938,923
2023-08-25 19:39:55
55,978,948
12
2019-05-04 02:21:29
5,249,307
2019-05-04 02:21:29
https://stackoverflow.com/q/55978911
https://stackoverflow.com/a/55978948
<p>There is no “triple quote” ... for example <code>''' '$Q' '''</code> is the concatenation of several strings ... <code>''</code>, <code>' '</code>, <code>$Q</code>, <code>' '</code> and <code>''</code>. Consider each of the others in the same way.</p>
<p>There is no “triple quote” ... for example <code>''' '$Q' '''</code> is the concatenation of several strings ... <code>''</code>, <code>' '</code>, <code>$Q</code>, <code>' '</code> and <code>''</code>. Consider each of the others in the same way.</p>
387, 390
bash, shell
<h1>What does triple-single-quote mean in bash?</h1> <p>I have seen lots of uses of single and double-quotes in bash, as well as backtick-quotes, but have never seen what follows. What is the meaning of the transcript below, which seems to show that triple-single-quoting is recognized as meaningful by bash and further ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,657
bash
# What does triple-single-quote mean in bash? I have seen lots of uses of single and double-quotes in bash, as well as backtick-quotes, but have never seen what follows. What is the meaning of the transcript below, which seems to show that triple-single-quoting is recognized as meaningful by bash and further seems to ...
There is no “triple quote” ... for example `''' '$Q' '''` is the concatenation of several strings ... `''`, `' '`, `$Q`, `' '` and `''`. Consider each of the others in the same way.
47744854
Do here-strings undergo word-splitting?
16
2017-12-11 00:08:16
<p>Quoting <a href="https://www.gnu.org/software/bash/manual/bash.html#Here-Strings" rel="nofollow noreferrer">Bash Reference Manual</a> and <code>man bash</code> (version 4.3):</p> <blockquote> <p><code>[<i>n</i>]&lt;&lt;&lt; <i>word</i></code></p> <p>The <em><code>word</code></em> undergoes brace expansion, t...
458
6,176,817
2018-01-05 17:45:15
47,745,181
12
2017-12-11 01:06:32
3,266,847
2017-12-11 01:06:32
https://stackoverflow.com/q/47744854
https://stackoverflow.com/a/47745181
<p>The change from splitting here-strings to not splitting them happened between bash-4.4-alpha and bash-4.4-beta. Quoting from <a href="http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n437" rel="noreferrer"><code>CHANGES</code></a>:</p> <blockquote> <p>Bash no longer splits the expansion of here-strings, as ...
<p>The change from splitting here-strings to not splitting them happened between bash-4.4-alpha and bash-4.4-beta. Quoting from <a href="http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n437" rel="noreferrer"><code>CHANGES</code></a>:</p> <blockquote> <p>Bash no longer splits the expansion of here-strings, as ...
58, 387, 97914
bash, herestring, linux
<h1>Do here-strings undergo word-splitting?</h1> <p>Quoting <a href="https://www.gnu.org/software/bash/manual/bash.html#Here-Strings" rel="nofollow noreferrer">Bash Reference Manual</a> and <code>man bash</code> (version 4.3):</p> <blockquote> <p><code>[<i>n</i>]&lt;&lt;&lt; <i>word</i></code></p> <p>The <em><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,658
bash
# Do here-strings undergo word-splitting? Quoting [Bash Reference Manual](https://www.gnu.org/software/bash/manual/bash.html#Here-Strings) and `man bash` (version 4.3): > `[n]<<< word` > > The *`word`* undergoes brace expansion, tilde expansion, parameter and > variable expansion, command substitution, arithmetic exp...
The change from splitting here-strings to not splitting them happened between bash-4.4-alpha and bash-4.4-beta. Quoting from [`CHANGES`](http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES#n437): > Bash no longer splits the expansion of here-strings, as the documentation has always said. So the manuals of older Ba...
25595971
Watch file output in bash terminal as it is being written to the file
16
2014-08-31 20:24:40
<p>I am asking this question because I remember very clearly having seen someone I worked with do this before I had a very good understanding of linux and the command line.</p> <p>I am looking for a way to have the content of a file that is being updated sent directly to a terminal rather than simply logged. The clos...
16,148
1,145,948
2014-09-01 00:07:07
25,596,016
12
2014-08-31 20:29:22
2,970,947
2014-08-31 20:29:22
https://stackoverflow.com/q/25595971
https://stackoverflow.com/a/25596016
<p>Use the command <code>tee</code> - from it's <code>man</code> page,</p> <blockquote> <p><strong>Synopsis</strong></p> <pre><code> tee [OPTION]... [FILE]... </code></pre> <p><strong>Description</strong></p> <pre><code> Copy standard input to each FILE, and also to standard output. </code></pre> </blockquo...
<p>Use the command <code>tee</code> - from it's <code>man</code> page,</p> <blockquote> <p><strong>Synopsis</strong></p> <pre><code> tee [OPTION]... [FILE]... </code></pre> <p><strong>Description</strong></p> <pre><code> Copy standard input to each FILE, and also to standard output. </code></pre> </blockquo...
58, 387
bash, linux
<h1>Watch file output in bash terminal as it is being written to the file</h1> <p>I am asking this question because I remember very clearly having seen someone I worked with do this before I had a very good understanding of linux and the command line.</p> <p>I am looking for a way to have the content of a file that is...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,659
bash
# Watch file output in bash terminal as it is being written to the file I am asking this question because I remember very clearly having seen someone I worked with do this before I had a very good understanding of linux and the command line. I am looking for a way to have the content of a file that is being updated s...
Use the command `tee` - from it's `man` page, > **Synopsis** > > ``` > tee [OPTION]... [FILE]... > ``` > > **Description** > > ``` > Copy standard input to each FILE, and also to standard output. > ``` Or, you could run `tail -f` on the written file to watch as it is being written (`-f` is follow).
23850789
Match a string that contains a newline using sed
16
2014-05-24 23:59:36
<p>I have a string like this one:</p> <pre><code> # pap </code></pre> <p>which basically translates to a <code>\t#\n\tpap</code> and I want to replace it with:</p> <pre><code> # pap python </code></pre> <p>which translates to <code>\t#\n\tpap\n\tpython</code>.</p> <p>Tried this with <code>sed</co...
28,626
1,515,697
2024-10-04 11:21:23
23,850,894
12
2014-05-25 00:23:02
164,835
2014-05-25 00:23:02
https://stackoverflow.com/q/23850789
https://stackoverflow.com/a/23850894
<p>try this line with gawk:</p> <pre><code>awk -v RS="\0" -v ORS="" '{gsub(/\t#\n\tpap/,"yourNEwString")}7' file </code></pre> <p>if you want to let <code>sed</code> handle new lines, you have to read the whole file first:</p> <pre><code>sed ':a;N;$!ba;s/\t#\n\tpap/NewString/g' file </code></pre>
<p>try this line with gawk:</p> <pre><code>awk -v RS="\0" -v ORS="" '{gsub(/\t#\n\tpap/,"yourNEwString")}7' file </code></pre> <p>if you want to let <code>sed</code> handle new lines, you have to read the whole file first:</p> <pre><code>sed ':a;N;$!ba;s/\t#\n\tpap/NewString/g' file </code></pre>
58, 387, 549, 990, 5282
awk, bash, linux, sed, ubuntu
<h1>Match a string that contains a newline using sed</h1> <p>I have a string like this one:</p> <pre><code> # pap </code></pre> <p>which basically translates to a <code>\t#\n\tpap</code> and I want to replace it with:</p> <pre><code> # pap python </code></pre> <p>which translates to <code>\t#\n\tp...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,660
bash
# Match a string that contains a newline using sed I have a string like this one: ``` # pap ``` which basically translates to a `\t#\n\tpap` and I want to replace it with: ``` # pap python ``` which translates to `\t#\n\tpap\n\tpython`. Tried this with `sed` in a lot of ways but it's not worki...
try this line with gawk: ``` awk -v RS="\0" -v ORS="" '{gsub(/\t#\n\tpap/,"yourNEwString")}7' file ``` if you want to let `sed` handle new lines, you have to read the whole file first: ``` sed ':a;N;$!ba;s/\t#\n\tpap/NewString/g' file ```
14197470
How does trap / kill work in bash on Linux?
16
2013-01-07 13:59:22
<p>My sample file</p> <p>traptest.sh:</p> <pre><code>#!/bin/bash trap 'echo trapped' TERM while : do sleep 1000 done </code></pre> <p>$ traptest.sh &amp; </p> <blockquote> <blockquote> <p>[1] 4280</p> </blockquote> </blockquote> <p>$ kill %1 &lt;-- kill by job number works</p> <blockquote> <block...
29,146
133,700
2018-03-20 08:05:32
14,198,367
12
2013-01-07 14:55:53
1,280,954
2013-01-07 15:13:30
https://stackoverflow.com/q/14197470
https://stackoverflow.com/a/14198367
<pre><code>kill [pid] </code></pre> <p>send the TERM signal exclusively to the specified PID.</p> <pre><code>kill %1 </code></pre> <p>send the TERM signal to the job #1's entire process group, in this case to the script pid + his children (sleep). </p> <p>I've verified that with strace on sleep process and on scrip...
<pre><code>kill [pid] </code></pre> <p>send the TERM signal exclusively to the specified PID.</p> <pre><code>kill %1 </code></pre> <p>send the TERM signal to the job #1's entire process group, in this case to the script pid + his children (sleep). </p> <p>I've verified that with strace on sleep process and on scrip...
387
bash
<h1>How does trap / kill work in bash on Linux?</h1> <p>My sample file</p> <p>traptest.sh:</p> <pre><code>#!/bin/bash trap 'echo trapped' TERM while : do sleep 1000 done </code></pre> <p>$ traptest.sh &amp; </p> <blockquote> <blockquote> <p>[1] 4280</p> </blockquote> </blockquote> <p>$ kill %1 &lt;-...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,661
bash
# How does trap / kill work in bash on Linux? My sample file traptest.sh: ``` #!/bin/bash trap 'echo trapped' TERM while : do sleep 1000 done ``` $ traptest.sh & > > [1] 4280 $ kill %1 <-- kill by job number works > > Terminated > > > > trapped $ traptest.sh & > > [1] 4280 $ kill 4280 <-- kill by process id...
``` kill [pid] ``` send the TERM signal exclusively to the specified PID. ``` kill %1 ``` send the TERM signal to the job #1's entire process group, in this case to the script pid + his children (sleep). I've verified that with strace on sleep process and on script process Anyway, someone got a similar problem her...
13260974
How to check if process is running in linux
16
2012-11-06 23:17:45
<p>I am trying to automatically check if a process is running or not and have to perform next steps accordingly. I had written a bash script but it doesn't seem to work.</p> <pre><code>if ps aux | grep [M]yProcessName &gt; /dev/null then echo "Running" else echo "Not running" fi </code></pre> <p>Is my <code>if</c...
74,042
1,026,764
2021-08-02 16:00:33
13,264,571
12
2012-11-07 06:51:58
841,108
2012-11-07 06:51:58
https://stackoverflow.com/q/13260974
https://stackoverflow.com/a/13264571
<p>You don't want to know if a particular process (of known pid) is running (this can be done by testing if <code>/proc/1234/</code> exists for pid 1234) but if some process is running a given command (or a given executable).</p> <p>Notice that the <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/kill.2....
<p>You don't want to know if a particular process (of known pid) is running (this can be done by testing if <code>/proc/1234/</code> exists for pid 1234) but if some process is running a given command (or a given executable).</p> <p>Notice that the <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/kill.2....
58, 387
bash, linux
<h1>How to check if process is running in linux</h1> <p>I am trying to automatically check if a process is running or not and have to perform next steps accordingly. I had written a bash script but it doesn't seem to work.</p> <pre><code>if ps aux | grep [M]yProcessName &gt; /dev/null then echo "Running" else echo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,662
bash
# How to check if process is running in linux I am trying to automatically check if a process is running or not and have to perform next steps accordingly. I had written a bash script but it doesn't seem to work. ``` if ps aux | grep [M]yProcessName > /dev/null then echo "Running" else echo "Not running" fi ``` ...
You don't want to know if a particular process (of known pid) is running (this can be done by testing if `/proc/1234/` exists for pid 1234) but if some process is running a given command (or a given executable). Notice that the [kill(2)](http://www.kernel.org/doc/man-pages/online/pages/man2/kill.2.html) syscall can be...
10652492
Bash Autocompletion - How to pass this array to compgen without significant whitespace being collapsed?
16
2012-05-18 12:17:14
<p>The following bash completion passes an array of possible words (i.e. completions) to compgen.</p> <pre><code>basenames=("foo" "fu bar" "baz"); COMPREPLY=($(compgen -W "${basenames[*]}" -- "${COMP_WORDS[COMP_CWORD]}")) </code></pre> <p>The problem is that the whitespace in the array elements is not preserved, tha...
5,892
1,178,669
2024-01-25 17:58:08
11,482,571
12
2012-07-14 09:26:27
1,524,545
2012-07-14 09:26:27
https://stackoverflow.com/q/10652492
https://stackoverflow.com/a/11482571
<p>Why bother with <code>compgen</code>? Just add them to COMPREPLY manually. The following will complete the matching filenames from <code>/some/path</code>, handling filenames safely.</p> <pre><code>some_completion_function() { local files=("/some/path/$2"*) [[ -e ${files[0]} ]] &amp;&amp; COMPREPLY=( "${fil...
<p>Why bother with <code>compgen</code>? Just add them to COMPREPLY manually. The following will complete the matching filenames from <code>/some/path</code>, handling filenames safely.</p> <pre><code>some_completion_function() { local files=("/some/path/$2"*) [[ -e ${files[0]} ]] &amp;&amp; COMPREPLY=( "${fil...
114, 387, 59778
arrays, bash, bash-completion
<h1>Bash Autocompletion - How to pass this array to compgen without significant whitespace being collapsed?</h1> <p>The following bash completion passes an array of possible words (i.e. completions) to compgen.</p> <pre><code>basenames=("foo" "fu bar" "baz"); COMPREPLY=($(compgen -W "${basenames[*]}" -- "${COMP_WORDS...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,663
bash
# Bash Autocompletion - How to pass this array to compgen without significant whitespace being collapsed? The following bash completion passes an array of possible words (i.e. completions) to compgen. ``` basenames=("foo" "fu bar" "baz"); COMPREPLY=($(compgen -W "${basenames[*]}" -- "${COMP_WORDS[COMP_CWORD]}")) ```...
Why bother with `compgen`? Just add them to COMPREPLY manually. The following will complete the matching filenames from `/some/path`, handling filenames safely. ``` some_completion_function() { local files=("/some/path/$2"*) [[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]##*/}" ) } ``` It's not possible to ha...
11213849
How to ls --ignore on osx
16
2012-06-26 18:35:14
<p>I'm trying to do the following on OSX:</p> <p><code>ls -lR --ignore *.app</code></p> <p>So that I can recursively search through all folders <em>except</em> for .app folders.</p> <p>However it seems there is seems to be no <code>--ignore</code> or <code>--hide</code> options in Darwin.</p> <p>Perhaps a script to...
10,590
1,373,278
2017-12-29 11:59:59
11,213,896
12
2012-06-26 18:38:37
97,337
2012-06-26 19:06:29
https://stackoverflow.com/q/11213849
https://stackoverflow.com/a/11213896
<p>Use <code>find</code>:</p> <pre><code>find . -ls -name '*.app' -prune </code></pre>
<p>Use <code>find</code>:</p> <pre><code>find . -ls -name '*.app' -prune </code></pre>
369, 387, 3589
bash, ls, macos
<h1>How to ls --ignore on osx</h1> <p>I'm trying to do the following on OSX:</p> <p><code>ls -lR --ignore *.app</code></p> <p>So that I can recursively search through all folders <em>except</em> for .app folders.</p> <p>However it seems there is seems to be no <code>--ignore</code> or <code>--hide</code> options in ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,664
bash
# How to ls --ignore on osx I'm trying to do the following on OSX: `ls -lR --ignore *.app` So that I can recursively search through all folders *except* for .app folders. However it seems there is seems to be no `--ignore` or `--hide` options in Darwin. Perhaps a script to recursively search one folder deep for a ...
Use `find`: ``` find . -ls -name '*.app' -prune ```
10439590
bash "&" without printing "[1]+ Done "
16
2012-05-03 21:29:46
<p>I call a script in my .bashrc to print number of new messages I have when I open the terminal, I want the call to be non blocking as it accesses the network and sometimes takes a few seconds which means I can't use the terminal until it completes. </p> <p>However if I put: </p> <pre><code> mailcheck &amp; </co...
7,703
892,545
2021-09-18 00:09:44
10,439,832
12
2012-05-03 21:52:34
89,817
2012-05-03 21:52:34
https://stackoverflow.com/q/10439590
https://stackoverflow.com/a/10439832
<p>That message isn't coming from mailcheck, it's from bash's job control telling you about your backgrounded job. The way to avoid it is to tell bash you don't want it managed by job control:</p> <pre><code>mailcheck &amp; disown $! </code></pre>
<p>That message isn't coming from mailcheck, it's from bash's job control telling you about your backgrounded job. The way to avoid it is to tell bash you don't want it managed by job control:</p> <pre><code>mailcheck &amp; disown $! </code></pre>
58, 387, 531
bash, linux, scripting
<h1>bash "&" without printing "[1]+ Done "</h1> <p>I call a script in my .bashrc to print number of new messages I have when I open the terminal, I want the call to be non blocking as it accesses the network and sometimes takes a few seconds which means I can't use the terminal until it completes. </p> <p>However if I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,665
bash
# bash "&" without printing "[1]+ Done " I call a script in my .bashrc to print number of new messages I have when I open the terminal, I want the call to be non blocking as it accesses the network and sometimes takes a few seconds which means I can't use the terminal until it completes. However if I put: ``` ma...
That message isn't coming from mailcheck, it's from bash's job control telling you about your backgrounded job. The way to avoid it is to tell bash you don't want it managed by job control: ``` mailcheck & disown $! ```
7842919
Python equivalent to perl -pe?
16
2011-10-20 22:15:26
<p>I need to pick some numbers out of some text files. I can pick out the lines I need with grep, but didn't know how to extract the numbers from the lines. A colleague showed me how to do this from bash with perl:</p> <pre><code>cat results.txt | perl -pe 's/.+(\d\.\d+)\.\n/\1 /' </code></pre> <p>However, I usually ...
3,018
662,939
2021-07-28 20:53:29
7,842,937
12
2011-10-20 22:18:24
148,870
2011-10-20 22:32:26
https://stackoverflow.com/q/7842919
https://stackoverflow.com/a/7842937
<p>Yes, you can use Python from the command line. <code>python -c &lt;stuff&gt;</code> will run <code>&lt;stuff&gt;</code> as Python code. Example:</p> <pre><code>python -c "import sys; print sys.path" </code></pre> <p>There isn't a direct equivalent to the <code>-p</code> option for Perl (the automatic input/output ...
<p>Yes, you can use Python from the command line. <code>python -c &lt;stuff&gt;</code> will run <code>&lt;stuff&gt;</code> as Python code. Example:</p> <pre><code>python -c "import sys; print sys.path" </code></pre> <p>There isn't a direct equivalent to the <code>-p</code> option for Perl (the automatic input/output ...
16, 387, 5813
bash, pipe, python
<h1>Python equivalent to perl -pe?</h1> <p>I need to pick some numbers out of some text files. I can pick out the lines I need with grep, but didn't know how to extract the numbers from the lines. A colleague showed me how to do this from bash with perl:</p> <pre><code>cat results.txt | perl -pe 's/.+(\d\.\d+)\.\n/\1 ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,666
bash
# Python equivalent to perl -pe? I need to pick some numbers out of some text files. I can pick out the lines I need with grep, but didn't know how to extract the numbers from the lines. A colleague showed me how to do this from bash with perl: ``` cat results.txt | perl -pe 's/.+(\d\.\d+)\.\n/\1 /' ``` However, I u...
Yes, you can use Python from the command line. `python -c <stuff>` will run `<stuff>` as Python code. Example: ``` python -c "import sys; print sys.path" ``` There isn't a direct equivalent to the `-p` option for Perl (the automatic input/output line-by-line processing), but that's mostly because Python doesn't use t...
7477543
Bash scripting, loop through files in folder fails
16
2011-09-19 21:30:57
<p>I'm looping through certain files (all files starting with MOVIE) in a folder with this bash script code:</p> <pre><code>for i in MY-FOLDER/MOVIE* do </code></pre> <p>which works fine when there are files in the folder. But when there aren't any, it somehow goes on with one file which it thinks is named MY-FOLDER/...
15,904
809,829
2019-10-19 15:01:23
7,477,615
12
2011-09-19 21:38:22
29,157
2019-10-19 15:01:23
https://stackoverflow.com/q/7477543
https://stackoverflow.com/a/7477615
<pre><code>for i in $(find MY-FOLDER/MOVIE -type f); do echo $i done </code></pre> <p>The <code>find</code> utility is one of the Swiss Army knives of linux. It starts at the directory you give it and finds all files in all subdirectories, according to the options you give it.</p> <p><code>-type f</code> will find...
<pre><code>for i in $(find MY-FOLDER/MOVIE -type f); do echo $i done </code></pre> <p>The <code>find</code> utility is one of the Swiss Army knives of linux. It starts at the directory you give it and finds all files in all subdirectories, according to the options you give it.</p> <p><code>-type f</code> will find...
387
bash
<h1>Bash scripting, loop through files in folder fails</h1> <p>I'm looping through certain files (all files starting with MOVIE) in a folder with this bash script code:</p> <pre><code>for i in MY-FOLDER/MOVIE* do </code></pre> <p>which works fine when there are files in the folder. But when there aren't any, it someh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,667
bash
# Bash scripting, loop through files in folder fails I'm looping through certain files (all files starting with MOVIE) in a folder with this bash script code: ``` for i in MY-FOLDER/MOVIE* do ``` which works fine when there are files in the folder. But when there aren't any, it somehow goes on with one file which it...
``` for i in $(find MY-FOLDER/MOVIE -type f); do echo $i done ``` The `find` utility is one of the Swiss Army knives of linux. It starts at the directory you give it and finds all files in all subdirectories, according to the options you give it. `-type f` will find only regular files (not directories). As I wrote...
7198098
What is an efficient way to replace list of strings with another list in Unix file?
16
2011-08-25 22:47:57
<p>Suppose I have two lists of strings (list A and list B) with the exact same number of entries, N, in each list, and I want to replace all occurrences of the the nth element of A with the nth element of B in a file in Unix (ideally using Bash scripting).</p> <p>What's the most efficient way to do this?</p> <p>An in...
16,964
null
2012-12-05 18:59:35
7,198,895
12
2011-08-26 00:46:22
7,552
2011-10-04 15:18:42
https://stackoverflow.com/q/7198098
https://stackoverflow.com/a/7198895
<p>This will do it in one pass. It reads listA and listB into awk arrays, then for each line of the linput, it examines each word and if the word is found in listA, the word is replaced by the corresponding word in listB.</p> <pre><code>awk ' FILENAME == ARGV[1] { listA[$1] = FNR; next } FILENAME == ARGV[2] { ...
<p>This will do it in one pass. It reads listA and listB into awk arrays, then for each line of the linput, it examines each word and if the word is found in listA, the word is replaced by the corresponding word in listB.</p> <pre><code>awk ' FILENAME == ARGV[1] { listA[$1] = FNR; next } FILENAME == ARGV[2] { ...
34, 387, 531, 724
bash, file-io, scripting, unix
<h1>What is an efficient way to replace list of strings with another list in Unix file?</h1> <p>Suppose I have two lists of strings (list A and list B) with the exact same number of entries, N, in each list, and I want to replace all occurrences of the the nth element of A with the nth element of B in a file in Unix (i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,668
bash
# What is an efficient way to replace list of strings with another list in Unix file? Suppose I have two lists of strings (list A and list B) with the exact same number of entries, N, in each list, and I want to replace all occurrences of the the nth element of A with the nth element of B in a file in Unix (ideally us...
This will do it in one pass. It reads listA and listB into awk arrays, then for each line of the linput, it examines each word and if the word is found in listA, the word is replaced by the corresponding word in listB. ``` awk ' FILENAME == ARGV[1] { listA[$1] = FNR; next } FILENAME == ARGV[2] { listB[FNR] = $...
7096772
How do I implement tab completion in node.js shell?
16
2011-08-17 17:10:18
<p>I was looking for this feature in node.js and I haven't found it.<br> Can I implement it myself? As far as I know, node.js doesn't load any file at it's startup (like Bash does with <code>.bashrc</code>) and I haven't noticed any way to somehow override shell prompt.</p> <p>Is there a way to implement it without wr...
5,914
666,520
2020-11-21 04:34:18
7,096,913
12
2011-08-17 17:25:22
492,364
2020-11-21 04:34:18
https://stackoverflow.com/q/7096772
https://stackoverflow.com/a/7096913
<p>You could monkey-patch the REPL. Note that you <em>must</em> use the callback version of the <code>completer</code>, otherwise it won't work correctly:</p> <pre><code>var repl = require('repl').start() var _completer = repl.completer.bind(repl) repl.completer = function(line, cb) { // ... _completer(line, cb) } ...
<p>You could monkey-patch the REPL. Note that you <em>must</em> use the callback version of the <code>completer</code>, otherwise it won't work correctly:</p> <pre><code>var repl = require('repl').start() var _completer = repl.completer.bind(repl) repl.completer = function(line, cb) { // ... _completer(line, cb) } ...
3, 390, 46426
javascript, node.js, shell
<h1>How do I implement tab completion in node.js shell?</h1> <p>I was looking for this feature in node.js and I haven't found it.<br> Can I implement it myself? As far as I know, node.js doesn't load any file at it's startup (like Bash does with <code>.bashrc</code>) and I haven't noticed any way to somehow override sh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,669
bash
# How do I implement tab completion in node.js shell? I was looking for this feature in node.js and I haven't found it. Can I implement it myself? As far as I know, node.js doesn't load any file at it's startup (like Bash does with `.bashrc`) and I haven't noticed any way to somehow override shell prompt. Is there ...
You could monkey-patch the REPL. Note that you *must* use the callback version of the `completer`, otherwise it won't work correctly: ``` var repl = require('repl').start() var _completer = repl.completer.bind(repl) repl.completer = function(line, cb) { // ... _completer(line, cb) } ```
3098713
How to make AWK use a variable created in Bash Script
16
2010-06-23 03:17:08
<p>I have script that looks like this</p> <pre><code>#!/bin/bash #exampel inputfile is "myfile.txt" inputfile=$1 basen=`basename $inputfile .txt` # create basename cat $inputfile | awk '{print $basen "\t" $3} # this doesn't print "myfile" but the whole content of it. </code></pre> <p>What I want to do above is to...
29,315
67,405
2023-09-01 06:19:19
3,098,771
12
2010-06-23 03:35:05
373,816
2017-06-26 17:38:53
https://stackoverflow.com/q/3098713
https://stackoverflow.com/a/3098771
<p>You can use it like this.</p> <pre><code>for i in `find $1 -name \*.jar` do jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' &gt;&gt; $classFile done </code></pre> <p>You should use </p> <blockquote> <p>"'${i}'"</p> </blockquote> <p>in AWK to use the </p> <blockquote> <p>$i</p> </blockquote> <p>cr...
<p>You can use it like this.</p> <pre><code>for i in `find $1 -name \*.jar` do jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' &gt;&gt; $classFile done </code></pre> <p>You should use </p> <blockquote> <p>"'${i}'"</p> </blockquote> <p>in AWK to use the </p> <blockquote> <p>$i</p> </blockquote> <p>cr...
34, 58, 387, 990
awk, bash, linux, unix
<h1>How to make AWK use a variable created in Bash Script</h1> <p>I have script that looks like this</p> <pre><code>#!/bin/bash #exampel inputfile is "myfile.txt" inputfile=$1 basen=`basename $inputfile .txt` # create basename cat $inputfile | awk '{print $basen "\t" $3} # this doesn't print "myfile" but the whole...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,670
bash
# How to make AWK use a variable created in Bash Script I have script that looks like this ``` #!/bin/bash #exampel inputfile is "myfile.txt" inputfile=$1 basen=`basename $inputfile .txt` # create basename cat $inputfile | awk '{print $basen "\t" $3} # this doesn't print "myfile" but the whole content of it. ``` ...
You can use it like this. ``` for i in `find $1 -name \*.jar` do jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' >> $classFile done ``` You should use > "'${i}'" in AWK to use the > $i created in Bash Script.
2740868
Difference between piping a file to sh and calling a shell file
16
2010-04-29 21:24:22
<p>This is what was trying to do:</p> <pre><code>$ wget -qO- www.example.com/script.sh | sh </code></pre> <p>which quietly downloads the script and prints it to stdout which is then piped to sh. This unfortunately doesn't quite work, failing to wait for user input at various points, aswell as a few syntax errors.</p>...
11,343
117
2014-03-01 08:53:58
2,741,009
12
2010-04-29 21:47:25
126,769
2010-04-29 21:47:25
https://stackoverflow.com/q/2740868
https://stackoverflow.com/a/2741009
<p>When you pipe to <code>sh</code> , stdin of that shell/script will be the pipe. Thus the script cannot take e.g. user input from the console. When you run the script normally, stdin is the console - where you can enter input.</p>
<p>When you pipe to <code>sh</code> , stdin of that shell/script will be the pipe. Thus the script cannot take e.g. user input from the console. When you run the script normally, stdin is the console - where you can enter input.</p>
390, 5813
pipe, shell
<h1>Difference between piping a file to sh and calling a shell file</h1> <p>This is what was trying to do:</p> <pre><code>$ wget -qO- www.example.com/script.sh | sh </code></pre> <p>which quietly downloads the script and prints it to stdout which is then piped to sh. This unfortunately doesn't quite work, failing to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,671
bash
# Difference between piping a file to sh and calling a shell file This is what was trying to do: ``` $ wget -qO- www.example.com/script.sh | sh ``` which quietly downloads the script and prints it to stdout which is then piped to sh. This unfortunately doesn't quite work, failing to wait for user input at various po...
When you pipe to `sh` , stdin of that shell/script will be the pipe. Thus the script cannot take e.g. user input from the console. When you run the script normally, stdin is the console - where you can enter input.