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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11287274 | "dyld: Library not loaded", "libruby.1.9.1.dylib" when calling "mvim ." in the command line | 8 | 2012-07-02 02:42:02 | <p>I'm trying to open my rails project into mvim (macvim) using "mvim ." but I get the following error.</p>
<pre><code>➜ cs193p git:(master) mvim .
dyld: Library not loaded: /Users/myusername/.rvm/rubies/ruby-1.9.3-p125/lib/libruby.1.9.1.dylib
Referenced from: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Mac... | 6,961 | 554,327 | 2012-07-03 17:58:58 | 11,316,525 | 16 | 2012-07-03 17:58:58 | 789,610 | 2012-07-03 17:58:58 | https://stackoverflow.com/q/11287274 | https://stackoverflow.com/a/11316525 | <p>brew will compile MacVim against your currently active ruby which was probably 1.9.3-p125. <code>rvm use 1.9.3-p194 --default && brew uninstall macvim && brew install macvim</code> is probably your best bet to fix your problem.</p>
| <p>brew will compile MacVim against your currently active ruby which was probably 1.9.3-p125. <code>rvm use 1.9.3-p194 --default && brew uninstall macvim && brew install macvim</code> is probably your best bet to fix your problem.</p> | 12, 370, 390, 29635, 46495 | macvim, ruby, rvm, shell, vim | <h1>"dyld: Library not loaded", "libruby.1.9.1.dylib" when calling "mvim ." in the command line</h1>
<p>I'm trying to open my rails project into mvim (macvim) using "mvim ." but I get the following error.</p>
<pre><code>➜ cs193p git:(master) mvim .
dyld: Library not loaded: /Users/myusername/.rvm/rubies/ruby-1.9.3-p1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,962 | bash | # "dyld: Library not loaded", "libruby.1.9.1.dylib" when calling "mvim ." in the command line
I'm trying to open my rails project into mvim (macvim) using "mvim ." but I get the following error.
```
➜ cs193p git:(master) mvim .
dyld: Library not loaded: /Users/myusername/.rvm/rubies/ruby-1.9.3-p125/lib/libruby.1.9.1... | brew will compile MacVim against your currently active ruby which was probably 1.9.3-p125. `rvm use 1.9.3-p194 --default && brew uninstall macvim && brew install macvim` is probably your best bet to fix your problem. |
10483678 | Deleting content of folder with shell script | 8 | 2012-05-07 14:15:00 | <p>Im having problems trying to empty a folder in my script.</p>
<p>This is working in my command line:</p>
<pre><code>rm -r Folder1/Folder2/*
</code></pre>
<p>But if in my script I do this:</p>
<pre><code>DIR="Folder1/Folder2/"
rm -r "$DIR*"
</code></pre>
<p>It says "rm: Folder1/Folder2/*: No such file or directo... | 6,417 | 550,034 | 2012-05-07 15:25:02 | 10,483,716 | 16 | 2012-05-07 14:17:26 | 635,608 | 2012-05-07 15:25:02 | https://stackoverflow.com/q/10483678 | https://stackoverflow.com/a/10483716 | <p>Glob expansion doesn't happen inside quotes.</p>
<p>Try:</p>
<pre><code>rm -r -- "$DIR"*
</code></pre>
<p>(Just make really sure you don't put a space after the quotes.)</p>
| <p>Glob expansion doesn't happen inside quotes.</p> <p>Try:</p> <pre><code>rm -r -- "$DIR"* </code></pre> <p>(Just make really sure you don't put a space after the quotes.)</p> | 58, 369, 387, 390, 1796 | bash, command, linux, macos, shell | <h1>Deleting content of folder with shell script</h1>
<p>Im having problems trying to empty a folder in my script.</p>
<p>This is working in my command line:</p>
<pre><code>rm -r Folder1/Folder2/*
</code></pre>
<p>But if in my script I do this:</p>
<pre><code>DIR="Folder1/Folder2/"
rm -r "$DIR*"
</code></pre>
<p>I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,963 | bash | # Deleting content of folder with shell script
Im having problems trying to empty a folder in my script.
This is working in my command line:
```
rm -r Folder1/Folder2/*
```
But if in my script I do this:
```
DIR="Folder1/Folder2/"
rm -r "$DIR*"
```
It says "rm: Folder1/Folder2/*: No such file or directory", where... | Glob expansion doesn't happen inside quotes.
Try:
```
rm -r -- "$DIR"*
```
(Just make really sure you don't put a space after the quotes.) |
9682721 | perform an operation for *each* item listed by grep | 8 | 2012-03-13 11:01:10 | <p>How can I perform an operation for each item listed by grep individually?</p>
<p>Background:</p>
<p>I use grep to list all files containing a certain pattern:</p>
<pre><code>grep -l '<pattern>' directory/*.extension1
</code></pre>
<p>I want to delete all listed files <em>but also</em> all files having the ... | 9,498 | 263,589 | 2012-03-14 14:01:38 | 9,683,332 | 16 | 2012-03-13 11:44:44 | 180,736 | 2012-03-14 11:12:34 | https://stackoverflow.com/q/9682721 | https://stackoverflow.com/a/9683332 | <p>If I understand your specification, you want:</p>
<pre><code>grep --null -l '<pattern>' directory/*.extension1 | \
xargs -n 1 -0 -I{} bash -c 'rm "$1" "${1%.*}.extension2"' -- {}
</code></pre>
<p>This is essentially the same as what @triplee's comment describes, except that it's newline... | <p>If I understand your specification, you want:</p> <pre><code>grep --null -l '<pattern>' directory/*.extension1 | \ xargs -n 1 -0 -I{} bash -c 'rm "$1" "${1%.*}.extension2"' -- {} </code></pre> <p>This is essentially the same as what @triplee's comment describes, except that it's newline... | 387, 390, 1271, 5608, 7932 | bash, exec, grep, list, shell | <h1>perform an operation for *each* item listed by grep</h1>
<p>How can I perform an operation for each item listed by grep individually?</p>
<p>Background:</p>
<p>I use grep to list all files containing a certain pattern:</p>
<pre><code>grep -l '<pattern>' directory/*.extension1
</code></pre>
<p>I want to de... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,964 | bash | # perform an operation for *each* item listed by grep
How can I perform an operation for each item listed by grep individually?
Background:
I use grep to list all files containing a certain pattern:
```
grep -l '<pattern>' directory/*.extension1
```
I want to delete all listed files *but also* all files having the... | If I understand your specification, you want:
```
grep --null -l '<pattern>' directory/*.extension1 | \
xargs -n 1 -0 -I{} bash -c 'rm "$1" "${1%.*}.extension2"' -- {}
```
This is essentially the same as what @triplee's comment describes, except that it's newline-safe.
## What's going on here?
`grep` with `--nu... |
8657164 | bash sort for resolution | 8 | 2011-12-28 14:32:04 | <p>i have a list of resolutions (mobile devices, monitors etc...) and i want to sort them by resolution using bash/vim</p>
<p>i have (not ordered):</p>
<pre><code>1024 x 480
96 x 120
1024 x 600
100 x 120
800 x 1280
64 x 98
640 x 320
64 x 128
640 x 960
800 x 480
80 x 120
</code></pre>
<p>then when i do:</p>
<pre><co... | 386 | 1,051,924 | 2017-06-29 16:21:40 | 8,657,206 | 16 | 2011-12-28 14:36:09 | 90,313 | 2011-12-28 15:04:25 | https://stackoverflow.com/q/8657164 | https://stackoverflow.com/a/8657206 | <p>you can use</p>
<pre><code>sort -n -k1 -k3 file
</code></pre>
<p>This does the sort based on the numeric prefix so you'd get the list sorted by the first number</p>
<p>this produces</p>
<pre><code>64 x 98
64 x 128
80 x 120
96 x 120
100 x 120
640 x 320
640 x 960
800 x 480
800 x 1280
1024 x 480
1024 x 600
</code><... | <p>you can use</p> <pre><code>sort -n -k1 -k3 file </code></pre> <p>This does the sort based on the numeric prefix so you'd get the list sorted by the first number</p> <p>this produces</p> <pre><code>64 x 98 64 x 128 80 x 120 96 x 120 100 x 120 640 x 320 640 x 960 800 x 480 800 x 1280 1024 x 480 1024 x 600 </code><... | 134, 387 | bash, sorting | <h1>bash sort for resolution</h1>
<p>i have a list of resolutions (mobile devices, monitors etc...) and i want to sort them by resolution using bash/vim</p>
<p>i have (not ordered):</p>
<pre><code>1024 x 480
96 x 120
1024 x 600
100 x 120
800 x 1280
64 x 98
640 x 320
64 x 128
640 x 960
800 x 480
80 x 120
</code></pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,965 | bash | # bash sort for resolution
i have a list of resolutions (mobile devices, monitors etc...) and i want to sort them by resolution using bash/vim
i have (not ordered):
```
1024 x 480
96 x 120
1024 x 600
100 x 120
800 x 1280
64 x 98
640 x 320
64 x 128
640 x 960
800 x 480
80 x 120
```
then when i do:
```
cat file | sor... | you can use
```
sort -n -k1 -k3 file
```
This does the sort based on the numeric prefix so you'd get the list sorted by the first number
this produces
```
64 x 98
64 x 128
80 x 120
96 x 120
100 x 120
640 x 320
640 x 960
800 x 480
800 x 1280
1024 x 480
1024 x 600
``` |
7362097 | Color words in powershell script format-table output | 8 | 2011-09-09 13:09:28 | <p>Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table.</p>
<pre><code>dir -r -i *.* | Select-String $args[0] |
format-table -Property @{label="Line #";... | 17,179 | 9,140 | 2017-02-28 00:02:25 | 7,362,596 | 16 | 2011-09-09 13:46:26 | 291,709 | 2014-04-22 11:58:48 | https://stackoverflow.com/q/7362097 | https://stackoverflow.com/a/7362596 | <p>You could pipe the table into <code>Out-String</code>, then write the string in parts using <code>Write-Host</code> with the <code>-NoNewLine</code> switch.</p>
<p>Something like this:</p>
<pre><code>filter ColorWord {
param(
[string] $word,
[string] $color
)
$line = $_
$index = $li... | <p>You could pipe the table into <code>Out-String</code>, then write the string in parts using <code>Write-Host</code> with the <code>-NoNewLine</code> switch.</p> <p>Something like this:</p> <pre><code>filter ColorWord { param( [string] $word, [string] $color ) $line = $_ $index = $li... | 526, 24067 | powershell, powershell-2.0 | <h1>Color words in powershell script format-table output</h1>
<p>Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table.</p>
<pre><code>dir -r -i *.* | Sel... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,966 | bash | # Color words in powershell script format-table output
Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table.
```
dir -r -i *.* | Select-String $args[0] |... | You could pipe the table into `Out-String`, then write the string in parts using `Write-Host` with the `-NoNewLine` switch.
Something like this:
```
filter ColorWord {
param(
[string] $word,
[string] $color
)
$line = $_
$index = $line.IndexOf($word, [System.StringComparison]::Invariant... |
3472383 | Why does recursive mode on chmod do everything but recursion? | 8 | 2010-08-12 22:00:55 | <p><code>chmod -R 775 *.cgi</code> only changes permissions on the files in the current directory, the files in the subdirectory don't get modified at all. This is the exact same functionality as simply doing <code>chmod 775 *.cgi</code>. I have seen people use solutions such as with <code>find</code> and whatnot. Ok g... | 14,802 | 322,900 | 2010-08-12 22:14:14 | 3,472,391 | 16 | 2010-08-12 22:03:59 | 282,912 | 2010-08-12 22:14:14 | https://stackoverflow.com/q/3472383 | https://stackoverflow.com/a/3472391 | <p>Probably because you have no directories named <code>*.cgi</code>. Quoth the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/chmod.html" rel="noreferrer">manual</a>:</p>
<blockquote>
<p><strong>-R</strong> Recursively change file mode bits. For each file operand that names a
directory, chmod sh... | <p>Probably because you have no directories named <code>*.cgi</code>. Quoth the <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/chmod.html" rel="noreferrer">manual</a>:</p> <blockquote> <p><strong>-R</strong> Recursively change file mode bits. For each file operand that names a directory, chmod sh... | 34, 387, 4956, 12380 | bash, centos, chmod, unix | <h1>Why does recursive mode on chmod do everything but recursion?</h1>
<p><code>chmod -R 775 *.cgi</code> only changes permissions on the files in the current directory, the files in the subdirectory don't get modified at all. This is the exact same functionality as simply doing <code>chmod 775 *.cgi</code>. I have see... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,967 | bash | # Why does recursive mode on chmod do everything but recursion?
`chmod -R 775 *.cgi` only changes permissions on the files in the current directory, the files in the subdirectory don't get modified at all. This is the exact same functionality as simply doing `chmod 775 *.cgi`. I have seen people use solutions such as ... | Probably because you have no directories named `*.cgi`. Quoth the [manual](http://www.opengroup.org/onlinepubs/009695399/utilities/chmod.html):
> **-R** Recursively change file mode bits. For each file operand that names a
> directory, chmod shall change the file
> mode bits of the directory and all
> files in the fil... |
3226096 | Copy Excel Worksheet from one Workbook to another with Powershell | 8 | 2010-07-12 05:37:34 | <p>I'd like to copy (or move) a worksheet from one workbook to another workbook with Powershell.</p>
<p>I had done this before and cant remember how. I think I used CopyTo() function.</p>
<p>Just to get started.</p>
<pre><code>$missing = [System.Type]::missing
$excel = New-Object -Com Excel.Application
$wb1 = $exce... | 29,227 | 192,296 | 2014-01-08 11:32:50 | 3,226,108 | 16 | 2010-07-12 05:42:23 | 255,259 | 2010-07-12 06:18:19 | https://stackoverflow.com/q/3226096 | https://stackoverflow.com/a/3226108 | <p>See <a href="http://www.vistax64.com/powershell/196157-copying-one-worksheet-one-excel-2007-workbook-another-work.html" rel="noreferrer">post</a> from Kiron</p>
<p>Changed index to copy to second sheet:</p>
<pre><code>$file1 = 'C:\Users\eric\Documents\Book1.xlsx' # source's fullpath
$file2 = 'C:\Users\eric\Documen... | <p>See <a href="http://www.vistax64.com/powershell/196157-copying-one-worksheet-one-excel-2007-workbook-another-work.html" rel="noreferrer">post</a> from Kiron</p> <p>Changed index to copy to second sheet:</p> <pre><code>$file1 = 'C:\Users\eric\Documents\Book1.xlsx' # source's fullpath $file2 = 'C:\Users\eric\Documen... | 162, 522, 526, 1449, 16048 | com, excel, office-automation, powershell, vba | <h1>Copy Excel Worksheet from one Workbook to another with Powershell</h1>
<p>I'd like to copy (or move) a worksheet from one workbook to another workbook with Powershell.</p>
<p>I had done this before and cant remember how. I think I used CopyTo() function.</p>
<p>Just to get started.</p>
<pre><code>$missing = [Sys... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,968 | bash | # Copy Excel Worksheet from one Workbook to another with Powershell
I'd like to copy (or move) a worksheet from one workbook to another workbook with Powershell.
I had done this before and cant remember how. I think I used CopyTo() function.
Just to get started.
```
$missing = [System.Type]::missing
$excel = New-Ob... | See [post](http://www.vistax64.com/powershell/196157-copying-one-worksheet-one-excel-2007-workbook-another-work.html) from Kiron
Changed index to copy to second sheet:
```
$file1 = 'C:\Users\eric\Documents\Book1.xlsx' # source's fullpath
$file2 = 'C:\Users\eric\Documents\Book2.xlsx' # destination's fullpath
$xl = new... |
2699946 | gzip: stdout: File too large when running customized backup script | 8 | 2010-04-23 15:45:47 | <p>I've create a plain and siple backup script that only backs up certain files and folders.</p>
<pre><code>tar -zcf $DIRECTORY/var.www.tar.gz /var/www
tar -zcf $DIRECTORY/development.tar.gz /development
tar -zcf $DIRECTORY/home.tar.gz /home
</code></pre>
<p>Now this script runs for about 30mins then gives me the fol... | 18,473 | 131,637 | 2010-04-23 16:30:19 | 2,700,258 | 16 | 2010-04-23 16:30:19 | 308,679 | 2010-04-23 16:30:19 | https://stackoverflow.com/q/2699946 | https://stackoverflow.com/a/2700258 | <p><em>File too large</em> is a error message from your libc: The output has exceeded the file size limit of your filesystem.</p>
<p>So this is not a <em>gzip</em> issue.</p>
<p>Options: Use another Filesystem or use split:</p>
<pre><code>tar czf - www|split -b 1073741824 - www-backup.tar.
</code></pre>
<p>creates ... | <p><em>File too large</em> is a error message from your libc: The output has exceeded the file size limit of your filesystem.</p> <p>So this is not a <em>gzip</em> issue.</p> <p>Options: Use another Filesystem or use split:</p> <pre><code>tar czf - www|split -b 1073741824 - www-backup.tar. </code></pre> <p>creates ... | 387, 390 | bash, shell | <h1>gzip: stdout: File too large when running customized backup script</h1>
<p>I've create a plain and siple backup script that only backs up certain files and folders.</p>
<pre><code>tar -zcf $DIRECTORY/var.www.tar.gz /var/www
tar -zcf $DIRECTORY/development.tar.gz /development
tar -zcf $DIRECTORY/home.tar.gz /home
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,969 | bash | # gzip: stdout: File too large when running customized backup script
I've create a plain and siple backup script that only backs up certain files and folders.
```
tar -zcf $DIRECTORY/var.www.tar.gz /var/www
tar -zcf $DIRECTORY/development.tar.gz /development
tar -zcf $DIRECTORY/home.tar.gz /home
```
Now this script ... | *File too large* is a error message from your libc: The output has exceeded the file size limit of your filesystem.
So this is not a *gzip* issue.
Options: Use another Filesystem or use split:
```
tar czf - www|split -b 1073741824 - www-backup.tar.
```
creates the backup.
Restore it from multiple parts:
```
cat w... |
1719460 | How do I alter XML with PowerShell/XPath and save the document? | 8 | 2009-11-12 02:10:03 | <p>I'm looking to use PowerShell to alter XML. I haven't been able to copy XML using XPath. I can load the XML, but I can't figure out how to list the XML with an XPath and create another XML file with what I retrieve. </p>
<pre><code>$doc = new-object "System.Xml.XmlDocument"
$doc.Load("XmlPath.xml")
</code></pre>
<... | 16,078 | 128,537 | 2013-09-03 13:17:05 | 1,719,700 | 16 | 2009-11-12 03:29:18 | 153,982 | 2009-11-12 04:13:32 | https://stackoverflow.com/q/1719460 | https://stackoverflow.com/a/1719700 | <p>If you're using PowerShell 2.0 you can use the new Select-Xml cmdlet to select xml based on an XPath expression e.g.:</p>
<pre><code>$xml = '<doc><books><book title="foo"/></books></doc>'
$xml | Select-Xml '//book'
Node Path Pattern
---- ---- -------
book Inp... | <p>If you're using PowerShell 2.0 you can use the new Select-Xml cmdlet to select xml based on an XPath expression e.g.:</p> <pre><code>$xml = '<doc><books><book title="foo"/></books></doc>' $xml | Select-Xml '//book' Node Path Pattern ---- ---- ------- book Inp... | 19, 526, 1227 | powershell, xml, xpath | <h1>How do I alter XML with PowerShell/XPath and save the document?</h1>
<p>I'm looking to use PowerShell to alter XML. I haven't been able to copy XML using XPath. I can load the XML, but I can't figure out how to list the XML with an XPath and create another XML file with what I retrieve. </p>
<pre><code>$doc = new-... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,970 | bash | # How do I alter XML with PowerShell/XPath and save the document?
I'm looking to use PowerShell to alter XML. I haven't been able to copy XML using XPath. I can load the XML, but I can't figure out how to list the XML with an XPath and create another XML file with what I retrieve.
```
$doc = new-object "System.Xml.Xm... | If you're using PowerShell 2.0 you can use the new Select-Xml cmdlet to select xml based on an XPath expression e.g.:
```
$xml = '<doc><books><book title="foo"/></books></doc>'
$xml | Select-Xml '//book'
Node Path Pattern
---- ---- -------
book InputStream //book
```
To remove nodes:
```... |
1203290 | Check whether stderr is a pipe in bash | 8 | 2009-07-29 21:54:05 | <p>I have a bash script that prompts the user for input with 'read'. If stdout or stderr is piped to something other than a terminal, I would like to suppress this step. Is that possible?</p>
| 1,433 | 145,905 | 2009-07-29 22:02:15 | 1,203,321 | 16 | 2009-07-29 22:02:15 | 126,769 | 2009-07-29 22:02:15 | https://stackoverflow.com/q/1203290 | https://stackoverflow.com/a/1203321 | <p>You can check whether a filedescriptor is a tty(attached to a terminal) with the command test -t <filedescriptor no.>. If it is, you can prompt the user. If it isn't, output is probably piped or redicted somewhere.</p>
<pre><code>if test -t 1 ; then
echo stdout is a tty
fi
</code></pre>
| <p>You can check whether a filedescriptor is a tty(attached to a terminal) with the command test -t <filedescriptor no.>. If it is, you can prompt the user. If it isn't, output is probably piped or redicted somewhere.</p> <pre><code>if test -t 1 ; then echo stdout is a tty fi </code></pre> | 387, 5813, 19156 | bash, pipe, stderr | <h1>Check whether stderr is a pipe in bash</h1>
<p>I have a bash script that prompts the user for input with 'read'. If stdout or stderr is piped to something other than a terminal, I would like to suppress this step. Is that possible?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,971 | bash | # Check whether stderr is a pipe in bash
I have a bash script that prompts the user for input with 'read'. If stdout or stderr is piped to something other than a terminal, I would like to suppress this step. Is that possible? | You can check whether a filedescriptor is a tty(attached to a terminal) with the command test -t <filedescriptor no.>. If it is, you can prompt the user. If it isn't, output is probably piped or redicted somewhere.
```
if test -t 1 ; then
echo stdout is a tty
fi
``` |
855616 | A bash one-liner to change into the directory where some file is located | 8 | 2009-05-13 01:10:18 | <p>I often want to change to the directory where a particular executable is located. So I'd like something like</p>
<pre><code>cd `which python`
</code></pre>
<p>to change into the directory where the python command is installed. However, this is obviously illegal, since cd takes a directory, not a file. There is... | 740 | 74,493 | 2021-01-20 20:24:31 | 855,636 | 16 | 2009-05-13 01:16:09 | 18,310 | 2009-05-13 01:35:38 | https://stackoverflow.com/q/855616 | https://stackoverflow.com/a/855636 | <p>Here:</p>
<pre><code>cd $(dirname `which python`)
</code></pre>
<p>Edit:</p>
<p>Even easier (actually tested this time):</p>
<pre><code>function cdfoo() { cd $(dirname `which $@`); }
</code></pre>
<p>Then "cdfoo python".</p>
| <p>Here:</p> <pre><code>cd $(dirname `which python`) </code></pre> <p>Edit:</p> <p>Even easier (actually tested this time):</p> <pre><code>function cdfoo() { cd $(dirname `which $@`); } </code></pre> <p>Then "cdfoo python".</p> | 387, 3718 | bash, cd | <h1>A bash one-liner to change into the directory where some file is located</h1>
<p>I often want to change to the directory where a particular executable is located. So I'd like something like</p>
<pre><code>cd `which python`
</code></pre>
<p>to change into the directory where the python command is installed. How... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,972 | bash | # A bash one-liner to change into the directory where some file is located
I often want to change to the directory where a particular executable is located. So I'd like something like
```
cd `which python`
```
to change into the directory where the python command is installed. However, this is obviously illegal, sin... | Here:
```
cd $(dirname `which python`)
```
Edit:
Even easier (actually tested this time):
```
function cdfoo() { cd $(dirname `which $@`); }
```
Then "cdfoo python". |
75011395 | Unable to install playwright on a Windows due to not recognizing argument | 7 | 2023-01-04 21:13:17 | <p>I have verified on my windows that I have Powershell - the latest version installed.</p>
<p>When I run the command from the Playwright website :</p>
<p><code>pwsh bin/Debug/netX/playwright.ps1 install</code></p>
<p>I get the following error : 'argument bin/Debug/netX/playwright.ps1' is not recognized as the name of ... | 22,793 | 15,339,501 | 2024-11-07 17:40:30 | 75,029,262 | 16 | 2023-01-06 09:42:51 | 6,161,265 | 2023-01-06 09:42:51 | https://stackoverflow.com/q/75011395 | https://stackoverflow.com/a/75029262 | <p>There is an <a href="https://github.com/microsoft/playwright-dotnet/issues/1865" rel="noreferrer">existing GitHub issue</a> regarding this problem. To summarize the solutions listed there, here are a few things you can try:</p>
<p>Install the PowerShell tool:</p>
<pre><code>dotnet tool install --global PowerShell
</... | <p>There is an <a href="https://github.com/microsoft/playwright-dotnet/issues/1865" rel="noreferrer">existing GitHub issue</a> regarding this problem. To summarize the solutions listed there, here are a few things you can try:</p> <p>Install the PowerShell tool:</p> <pre><code>dotnet tool install --global PowerShell </... | 64, 526, 142462 | playwright, powershell, windows | <h1>Unable to install playwright on a Windows due to not recognizing argument</h1>
<p>I have verified on my windows that I have Powershell - the latest version installed.</p>
<p>When I run the command from the Playwright website :</p>
<p><code>pwsh bin/Debug/netX/playwright.ps1 install</code></p>
<p>I get the following... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,973 | bash | # Unable to install playwright on a Windows due to not recognizing argument
I have verified on my windows that I have Powershell - the latest version installed.
When I run the command from the Playwright website :
`pwsh bin/Debug/netX/playwright.ps1 install`
I get the following error : 'argument bin/Debug/netX/play... | There is an [existing GitHub issue](https://github.com/microsoft/playwright-dotnet/issues/1865) regarding this problem. To summarize the solutions listed there, here are a few things you can try:
Install the PowerShell tool:
```
dotnet tool install --global PowerShell
```
Or, Update the PowerShell tool:
```
dotnet ... |
69398129 | PowerShell iterate through json of key value pairs | 7 | 2021-09-30 19:51:18 | <p>I have a json file that maps alpha-2 codes to country names:</p>
<pre><code>{
"AF": "Afghanistan",
"EG": "Ägypten",
...
}
</code></pre>
<p>I want to iterate over each key value pair to process the data. How would I be able to achieve that?</p>
<p>I tried the follow... | 9,700 | 5,203,853 | 2023-08-15 17:05:17 | 69,398,170 | 16 | 2021-09-30 19:55:23 | 5,203,853 | 2023-08-15 17:05:17 | https://stackoverflow.com/q/69398129 | https://stackoverflow.com/a/69398170 | <p>I was able to achieve it like this, using the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Intrinsic_Members#object-views" rel="noreferrer">intrinsic <code>.psobject</code> property</a>:</p>
<pre><code>foreach ($obj in $json.PSObject.Properties) {
$obj.Name
... | <p>I was able to achieve it like this, using the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Intrinsic_Members#object-views" rel="noreferrer">intrinsic <code>.psobject</code> property</a>:</p> <pre><code>foreach ($obj in $json.PSObject.Properties) { $obj.Name ... | 247, 526, 1508 | json, powershell, reflection | <h1>PowerShell iterate through json of key value pairs</h1>
<p>I have a json file that maps alpha-2 codes to country names:</p>
<pre><code>{
"AF": "Afghanistan",
"EG": "Ägypten",
...
}
</code></pre>
<p>I want to iterate over each key value pair to process the data. Ho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,974 | bash | # PowerShell iterate through json of key value pairs
I have a json file that maps alpha-2 codes to country names:
```
{
"AF": "Afghanistan",
"EG": "Ägypten",
...
}
```
I want to iterate over each key value pair to process the data. How would I be able to achieve that?
I tried the following but it always... | I was able to achieve it like this, using the [intrinsic `.psobject` property](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Intrinsic_Members#object-views):
```
foreach ($obj in $json.PSObject.Properties) {
$obj.Name
$obj.Value
}
``` |
64795150 | Windows Sandbox PowerShell logon command window not visible | 7 | 2020-11-11 22:30:04 | <p>I'm trying to use Windows Sandbox with a PowerShell logon command. This is the <code>LogonCommand</code> section of my WSB file:</p>
<pre class="lang-xml prettyprint-override"><code> <LogonCommand>
<Command>C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -executionpolicy unrestricted ... | 5,250 | 2,715,716 | 2021-11-28 12:08:28 | 64,812,427 | 16 | 2020-11-12 22:00:23 | 2,715,716 | 2021-11-28 12:08:28 | https://stackoverflow.com/q/64795150 | https://stackoverflow.com/a/64812427 | <p>Found <em>an</em> answer (doesn't look like the cleanest option, but works):</p>
<pre class="lang-xml prettyprint-override"><code><Command>powershell -executionpolicy unrestricted -command "start powershell {-noexit -file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1}"</Command>
</code></pre>
<u... | <p>Found <em>an</em> answer (doesn't look like the cleanest option, but works):</p> <pre class="lang-xml prettyprint-override"><code><Command>powershell -executionpolicy unrestricted -command "start powershell {-noexit -file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1}"</Command> </code></pre> <u... | 526, 138681 | powershell, windows-sandbox | <h1>Windows Sandbox PowerShell logon command window not visible</h1>
<p>I'm trying to use Windows Sandbox with a PowerShell logon command. This is the <code>LogonCommand</code> section of my WSB file:</p>
<pre class="lang-xml prettyprint-override"><code> <LogonCommand>
<Command>C:\\Windows\\System32\\W... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,975 | bash | # Windows Sandbox PowerShell logon command window not visible
I'm trying to use Windows Sandbox with a PowerShell logon command. This is the `LogonCommand` section of my WSB file:
```
<LogonCommand>
<Command>C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -executionpolicy unrestricted -file "C:\\... | Found *an* answer (doesn't look like the cleanest option, but works):
```
<Command>powershell -executionpolicy unrestricted -command "start powershell {-noexit -file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1}"</Command>
```
- `powershell` switches from CMD to PowerShell
- `-windowstyle normal` won't work to make... |
60106514 | Im using vim to check man page, and there is some weird character,how to make it normal? | 7 | 2020-02-07 02:59:44 | <p>I'm trying using </p>
<pre><code>man ascii | vi -
</code></pre>
<p>to check ascii manual with vim,<br>
then there are some weird character like '^H'</p>
<p><a href="https://i.sstatic.net/CTfrd.png" rel="noreferrer">weird character in vim</a></p>
<p>how to make it normal?</p>
<p>EDIT: </p>
<p>i think this is d... | 2,122 | 10,550,529 | 2020-02-07 15:51:49 | 60,106,865 | 16 | 2020-02-07 03:55:04 | 9,447,571 | 2020-02-07 15:51:49 | https://stackoverflow.com/q/60106514 | https://stackoverflow.com/a/60106865 | <p>What you're seeing here is the man page convention for typesetting bold and underlined characters.</p>
<p>The <code>^H</code> character is the "backspace" or BS character, which you can find in <a href="http://man7.org/linux/man-pages/man7/ascii.7.html" rel="noreferrer">ascii(7)</a> as ASCII 8.</p>
<p>Displaying a... | <p>What you're seeing here is the man page convention for typesetting bold and underlined characters.</p> <p>The <code>^H</code> character is the "backspace" or BS character, which you can find in <a href="http://man7.org/linux/man-pages/man7/ascii.7.html" rel="noreferrer">ascii(7)</a> as ASCII 8.</p> <p>Displaying a... | 293, 370, 387, 390, 391 | bash, shell, terminal, vi, vim | <h1>Im using vim to check man page, and there is some weird character,how to make it normal?</h1>
<p>I'm trying using </p>
<pre><code>man ascii | vi -
</code></pre>
<p>to check ascii manual with vim,<br>
then there are some weird character like '^H'</p>
<p><a href="https://i.sstatic.net/CTfrd.png" rel="noreferrer">w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,976 | bash | # Im using vim to check man page, and there is some weird character,how to make it normal?
I'm trying using
```
man ascii | vi -
```
to check ascii manual with vim,
then there are some weird character like '^H'
[weird character in vim](https://i.sstatic.net/CTfrd.png)
how to make it normal?
EDIT:
i think this ... | What you're seeing here is the man page convention for typesetting bold and underlined characters.
The `^H` character is the "backspace" or BS character, which you can find in [ascii(7)](http://man7.org/linux/man-pages/man7/ascii.7.html) as ASCII 8.
Displaying as `^H` is a convention to indicate "Control-H", the care... |
55181652 | Multiple filter in Get-ChildItem | 7 | 2019-03-15 11:30:30 | <p>I want to apply multiple <code>filter</code> in <em>PowerShell</em> script as of now I am able to add only single <code>filter</code> like below</p>
<pre><code>Get-Childitem "D:\SourceFolder" -recurse -filter "*kps.jpg"
| Copy-Item -Destination "D:\DestFolder"
</code></pre>
<p>From the above query I able to t... | 7,828 | 8,977,696 | 2020-04-26 09:48:21 | 55,181,727 | 16 | 2019-03-15 11:35:53 | 9,898,643 | 2019-03-15 15:50:59 | https://stackoverflow.com/q/55181652 | https://stackoverflow.com/a/55181727 | <p>To filter on more than one condition, use the <code>Include</code> parameter instead of the <code>-Filter</code>.</p>
<pre><code>Get-Childitem "D:\SourceFolder" -Recurse -Include "*kps.jpg", "*kps.png", "*kps.bmp" |
Copy-Item -Destination "D:\DestFolder"
</code></pre>
<p><hr>
<sup>Note: The <code>Include</code> o... | <p>To filter on more than one condition, use the <code>Include</code> parameter instead of the <code>-Filter</code>.</p> <pre><code>Get-Childitem "D:\SourceFolder" -Recurse -Include "*kps.jpg", "*kps.png", "*kps.bmp" | Copy-Item -Destination "D:\DestFolder" </code></pre> <p><hr> <sup>Note: The <code>Include</code> o... | 526, 5098, 73157 | copy-paste, powershell, powershell-3.0 | <h1>Multiple filter in Get-ChildItem</h1>
<p>I want to apply multiple <code>filter</code> in <em>PowerShell</em> script as of now I am able to add only single <code>filter</code> like below</p>
<pre><code>Get-Childitem "D:\SourceFolder" -recurse -filter "*kps.jpg"
| Copy-Item -Destination "D:\DestFolder"
</code><... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,977 | bash | # Multiple filter in Get-ChildItem
I want to apply multiple `filter` in *PowerShell* script as of now I am able to add only single `filter` like below
```
Get-Childitem "D:\SourceFolder" -recurse -filter "*kps.jpg"
| Copy-Item -Destination "D:\DestFolder"
```
From the above query I able to to copy only one file... | To filter on more than one condition, use the `Include` parameter instead of the `-Filter`.
```
Get-Childitem "D:\SourceFolder" -Recurse -Include "*kps.jpg", "*kps.png", "*kps.bmp" |
Copy-Item -Destination "D:\DestFolder"
```
---
Note: The `Include` only works if you also specify `-Recurse` or have the path end in ... |
49553769 | DockerFile call install msi | 7 | 2018-03-29 10:29:03 | <p>I'm having a hard time installing an msi via Dockerfile. My Dockerfile:</p>
<pre><code>FROM microsoft/windowsservercore:latest
RUN mkdir C:\temp
RUN mkdir C:\temp\msis
COPY . "C:/temp/msis"
RUN powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.msi" -ArgumentList "/qn" -PassThru | ... | 8,066 | 6,270,170 | 2019-01-15 08:10:31 | 49,554,508 | 16 | 2018-03-29 11:07:26 | 1,875,339 | 2019-01-15 08:10:31 | https://stackoverflow.com/q/49553769 | https://stackoverflow.com/a/49554508 | <p>Possibly it's a PowerShell parsing problem.</p>
<p>Try these 2 lines instead of your last line:</p>
<pre><code>SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Start-Process 'C:\\temp\\msis\\mySetup.msi' '/qn' -PassThru | Wait-Process;
</code></pre... | <p>Possibly it's a PowerShell parsing problem.</p> <p>Try these 2 lines instead of your last line:</p> <pre><code>SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Start-Process 'C:\\temp\\msis\\mySetup.msi' '/qn' -PassThru | Wait-Process; </code></pre... | 526, 90304 | docker, powershell | <h1>DockerFile call install msi</h1>
<p>I'm having a hard time installing an msi via Dockerfile. My Dockerfile:</p>
<pre><code>FROM microsoft/windowsservercore:latest
RUN mkdir C:\temp
RUN mkdir C:\temp\msis
COPY . "C:/temp/msis"
RUN powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,978 | bash | # DockerFile call install msi
I'm having a hard time installing an msi via Dockerfile. My Dockerfile:
```
FROM microsoft/windowsservercore:latest
RUN mkdir C:\temp
RUN mkdir C:\temp\msis
COPY . "C:/temp/msis"
RUN powershell -version 5.0 -command { Start-process -Filepath "C:\temp\msis\mySetup.msi" -ArgumentList "... | Possibly it's a PowerShell parsing problem.
Try these 2 lines instead of your last line:
```
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Start-Process 'C:\\temp\\msis\\mySetup.msi' '/qn' -PassThru | Wait-Process;
```
After that you can revert to... |
48997929 | How do I create a tmux session with multiple windows already opened? | 7 | 2018-02-26 22:09:55 | <p>I've tried just about everything I can find online, but nothing is working. I have tried the following methods, and the usual result is a new tmux session with only one window.</p>
<hr>
<hr>
<p>Simply in .bashrc.</p>
<p>.bashrc</p>
<pre><code>tmx () {
tmux new-session -A -s SessionName
tmux new-window -... | 10,869 | 1,353,951 | 2018-02-27 04:20:46 | 49,001,088 | 16 | 2018-02-27 04:20:46 | 1,126,841 | 2018-02-27 04:20:46 | https://stackoverflow.com/q/48997929 | https://stackoverflow.com/a/49001088 | <p>You need to create the session in detached mode (<code>-d</code>); otherwise, your script blocks until you detach from the new session. Likewise, your script will block after <code>tmux attach-session</code> until you detach, so you need to select the correct window first. Note that you can <code>-d</code> with <cod... | <p>You need to create the session in detached mode (<code>-d</code>); otherwise, your script blocks until you detach from the new session. Likewise, your script will block after <code>tmux attach-session</code> until you detach, so you need to select the correct window first. Note that you can <code>-d</code> with <cod... | 387, 60238 | bash, tmux | <h1>How do I create a tmux session with multiple windows already opened?</h1>
<p>I've tried just about everything I can find online, but nothing is working. I have tried the following methods, and the usual result is a new tmux session with only one window.</p>
<hr>
<hr>
<p>Simply in .bashrc.</p>
<p>.bashrc</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,979 | bash | # How do I create a tmux session with multiple windows already opened?
I've tried just about everything I can find online, but nothing is working. I have tried the following methods, and the usual result is a new tmux session with only one window.
---
---
Simply in .bashrc.
.bashrc
```
tmx () {
tmux new-ses... | You need to create the session in detached mode (`-d`); otherwise, your script blocks until you detach from the new session. Likewise, your script will block after `tmux attach-session` until you detach, so you need to select the correct window first. Note that you can `-d` with `new-window` to avoid making each new wi... |
47803678 | Is it possible to Rename or give a custom name to a Build in VSTS? | 7 | 2017-12-13 23:30:23 | <p>Is it possible to Rename or give a custom name to a Build in VSTS?</p>
<p>What I want to do is have my builds named after the version number. The version number is written in a <code>.version</code> file in the root directory.</p>
<p>The intended name would be: <code>$(MyVersionNumber):$(Rev:rr)</code></p>
| 4,330 | 438,032 | 2018-02-15 13:23:54 | 47,806,868 | 16 | 2017-12-14 06:06:39 | 6,587,650 | 2017-12-14 06:06:39 | https://stackoverflow.com/q/47803678 | https://stackoverflow.com/a/47806868 | <p>You can update the build number for current build through <a href="https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md" rel="noreferrer">Logging Command</a> (e.g. <code>Write-Host "##vso[build.updatebuildnumber]buildnumber"</code>). </p>
<p>Simple workflow of your code:</p>
<ol>
<li>Incl... | <p>You can update the build number for current build through <a href="https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md" rel="noreferrer">Logging Command</a> (e.g. <code>Write-Host "##vso[build.updatebuildnumber]buildnumber"</code>). </p> <p>Simple workflow of your code:</p> <ol> <li>Incl... | 526, 116537, 118015, 119596 | azure-devops, azure-pipelines, azure-pipelines-build-task, powershell | <h1>Is it possible to Rename or give a custom name to a Build in VSTS?</h1>
<p>Is it possible to Rename or give a custom name to a Build in VSTS?</p>
<p>What I want to do is have my builds named after the version number. The version number is written in a <code>.version</code> file in the root directory.</p>
<p>The i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,980 | bash | # Is it possible to Rename or give a custom name to a Build in VSTS?
Is it possible to Rename or give a custom name to a Build in VSTS?
What I want to do is have my builds named after the version number. The version number is written in a `.version` file in the root directory.
The intended name would be: `$(MyVersio... | You can update the build number for current build through [Logging Command](https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md) (e.g. `Write-Host "##vso[build.updatebuildnumber]buildnumber"`).
Simple workflow of your code:
1. Include `$(rev:.r)` in default build number format (Options), fo... |
42393137 | "let" command is not found in my bash script | 7 | 2017-02-22 13:41:26 | <p>I have the following bash script,</p>
<pre><code>#!/bin/bash
echo $SHELL
i=1
for img in ../img/*.png; do
echo $img
new=$(printf "../img/tmp/pyr%d.png" "$i")
echo $new
# cp "$img" "$new"
let i=i+1
done
# avconv -r 2 -i ../img/tmp/pyr%d.png -b:v 1000k ../pop_pyr.mp4
</code></pre>
<p>In the <code>../img</... | 22,757 | 4,269,285 | 2018-11-19 23:28:27 | 42,393,237 | 16 | 2017-02-22 13:45:31 | 164,835 | 2017-02-22 13:45:31 | https://stackoverflow.com/q/42393137 | https://stackoverflow.com/a/42393237 | <p>do in this way:</p>
<pre><code>i=$((i+1))
</code></pre>
<p>or</p>
<pre><code>i=$(expr $i + 1)
</code></pre>
| <p>do in this way:</p> <pre><code>i=$((i+1)) </code></pre> <p>or</p> <pre><code>i=$(expr $i + 1) </code></pre> | 387 | bash | <h1>"let" command is not found in my bash script</h1>
<p>I have the following bash script,</p>
<pre><code>#!/bin/bash
echo $SHELL
i=1
for img in ../img/*.png; do
echo $img
new=$(printf "../img/tmp/pyr%d.png" "$i")
echo $new
# cp "$img" "$new"
let i=i+1
done
# avconv -r 2 -i ../img/tmp/pyr%d.png -b:v 1000k ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,981 | bash | # "let" command is not found in my bash script
I have the following bash script,
```
#!/bin/bash
echo $SHELL
i=1
for img in ../img/*.png; do
echo $img
new=$(printf "../img/tmp/pyr%d.png" "$i")
echo $new
# cp "$img" "$new"
let i=i+1
done
# avconv -r 2 -i ../img/tmp/pyr%d.png -b:v 1000k ../pop_pyr.mp4
```
... | do in this way:
```
i=$((i+1))
```
or
```
i=$(expr $i + 1)
``` |
42024296 | Sum duplicate row values with awk | 7 | 2017-02-03 12:26:10 | <p>I have a file with the following structure:</p>
<pre><code>1486113768 3656
1486113768 6280
1486113769 530912
1486113769 5629824
1486113770 5122176
1486113772 3565920
1486113772 530912
1486113773 9229920
1486113774 4020960
1486113774 4547928
</code></pre>
<p>My goal is to get rid of duplicate values in the first co... | 7,818 | 1,459,065 | 2021-11-19 16:38:19 | 42,024,367 | 16 | 2017-02-03 12:29:20 | 5,291,015 | 2018-11-05 05:54:04 | https://stackoverflow.com/q/42024296 | https://stackoverflow.com/a/42024367 | <p>Use an <code>Awk</code> as below,</p>
<pre><code>awk '{ seen[$1] += $2 } END { for (i in seen) print i, seen[i] }' file1
1486113768 9936
1486113769 6160736
1486113770 5122176
1486113772 4096832
1486113773 9229920
1486113774 8568888
</code></pre>
<p><code>{seen[$1]+=$2}</code> creates a hash-map with the <code>$1</... | <p>Use an <code>Awk</code> as below,</p> <pre><code>awk '{ seen[$1] += $2 } END { for (i in seen) print i, seen[i] }' file1 1486113768 9936 1486113769 6160736 1486113770 5122176 1486113772 4096832 1486113773 9229920 1486113774 8568888 </code></pre> <p><code>{seen[$1]+=$2}</code> creates a hash-map with the <code>$1</... | 387, 990 | awk, bash | <h1>Sum duplicate row values with awk</h1>
<p>I have a file with the following structure:</p>
<pre><code>1486113768 3656
1486113768 6280
1486113769 530912
1486113769 5629824
1486113770 5122176
1486113772 3565920
1486113772 530912
1486113773 9229920
1486113774 4020960
1486113774 4547928
</code></pre>
<p>My goal is to ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,982 | bash | # Sum duplicate row values with awk
I have a file with the following structure:
```
1486113768 3656
1486113768 6280
1486113769 530912
1486113769 5629824
1486113770 5122176
1486113772 3565920
1486113772 530912
1486113773 9229920
1486113774 4020960
1486113774 4547928
```
My goal is to get rid of duplicate values in th... | Use an `Awk` as below,
```
awk '{ seen[$1] += $2 } END { for (i in seen) print i, seen[i] }' file1
1486113768 9936
1486113769 6160736
1486113770 5122176
1486113772 4096832
1486113773 9229920
1486113774 8568888
```
`{seen[$1]+=$2}` creates a hash-map with the `$1` being treated as the index value and the sum is increm... |
40942370 | How can I echo a string with hard line wrap? | 7 | 2016-12-02 23:23:53 | <p>I am writing a very simple bash script that asks questions that include text from previous answers. For example:</p>
<pre><code>questionText="Hi $userName, I'm going to ask you some questions. At the end of the process, I'll output a file that might be helpful to you."
echo "$questionText"
</code></pre>
<p>Some of... | 6,916 | 7,243,462 | 2022-02-16 09:56:09 | 40,942,556 | 16 | 2016-12-02 23:43:45 | 887,539 | 2022-02-16 09:56:09 | https://stackoverflow.com/q/40942370 | https://stackoverflow.com/a/40942556 | <blockquote>
<p>My searches all lead me to <code>fmt</code> and <code>fold</code>, but those want text files as input, not variables.</p>
</blockquote>
<p>Just use a pipe:</p>
<pre><code>printf '%s\n' "$questionText" | fold
</code></pre>
<p>Using the <code>-s</code> option will make <code>fold</code> only wra... | <blockquote> <p>My searches all lead me to <code>fmt</code> and <code>fold</code>, but those want text files as input, not variables.</p> </blockquote> <p>Just use a pipe:</p> <pre><code>printf '%s\n' "$questionText" | fold </code></pre> <p>Using the <code>-s</code> option will make <code>fold</code> only wra... | 387 | bash | <h1>How can I echo a string with hard line wrap?</h1>
<p>I am writing a very simple bash script that asks questions that include text from previous answers. For example:</p>
<pre><code>questionText="Hi $userName, I'm going to ask you some questions. At the end of the process, I'll output a file that might be helpful t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,983 | bash | # How can I echo a string with hard line wrap?
I am writing a very simple bash script that asks questions that include text from previous answers. For example:
```
questionText="Hi $userName, I'm going to ask you some questions. At the end of the process, I'll output a file that might be helpful to you."
echo "$quest... | > My searches all lead me to `fmt` and `fold`, but those want text files as input, not variables.
Just use a pipe:
```
printf '%s\n' "$questionText" | fold
```
Using the `-s` option will make `fold` only wrap on white space characters, and not in the middle of a word:
```
printf '%s\n' "$questionText" | fold -s
``` |
39172400 | Unseting a value in an associative bash array when the key contains a quote | 7 | 2016-08-26 18:14:25 | <p>I have a bash script that uses filenames as keys in an associative array. Some of the filenames have quotes in them and I can't seem to find any way to unset them.</p>
<p>Here's an example replicating the problem from the terminal:</p>
<pre><code>$ declare -A x
$ y="key with spaces"
$ z="key with spaces and ' quot... | 4,513 | 1,764,245 | 2016-08-26 18:56:42 | 39,172,729 | 16 | 2016-08-26 18:32:58 | 3,729,597 | 2016-08-26 18:56:42 | https://stackoverflow.com/q/39172400 | https://stackoverflow.com/a/39172729 | <p>I find this works for me:</p>
<pre><code>unset 'x[$z]'
</code></pre>
<p>This works for other special characters:</p>
<pre><code>$ y="key with spaces"
$ v="\$ ' \" @ # * & \`"
$ x[$y]=5
$ x[$v]=10
$ echo ${x[*]}
5 10
$ unset 'x[$v]'
$ echo ${x[*]}
5
</code></pre>
| <p>I find this works for me:</p> <pre><code>unset 'x[$z]' </code></pre> <p>This works for other special characters:</p> <pre><code>$ y="key with spaces" $ v="\$ ' \" @ # * & \`" $ x[$y]=5 $ x[$v]=10 $ echo ${x[*]} 5 10 $ unset 'x[$v]' $ echo ${x[*]} 5 </code></pre> | 114, 387, 2575, 4804 | arrays, associative-array, bash, escaping | <h1>Unseting a value in an associative bash array when the key contains a quote</h1>
<p>I have a bash script that uses filenames as keys in an associative array. Some of the filenames have quotes in them and I can't seem to find any way to unset them.</p>
<p>Here's an example replicating the problem from the terminal:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,984 | bash | # Unseting a value in an associative bash array when the key contains a quote
I have a bash script that uses filenames as keys in an associative array. Some of the filenames have quotes in them and I can't seem to find any way to unset them.
Here's an example replicating the problem from the terminal:
```
$ declare ... | I find this works for me:
```
unset 'x[$z]'
```
This works for other special characters:
```
$ y="key with spaces"
$ v="\$ ' \" @ # * & \`"
$ x[$y]=5
$ x[$v]=10
$ echo ${x[*]}
5 10
$ unset 'x[$v]'
$ echo ${x[*]}
5
``` |
38692346 | new tab in iTerm2 | 7 | 2016-08-01 06:35:02 | <p>Im using Iterm2 version Build 3.0.4
I want to create alias to open new tab from the command line (in bash)
I tried this code:</p>
<pre><code> function tab () {
osascript &>/dev/null <<EOF
activate application "iTerm"
tell application "System Events" to keystroke "t" using command down
te... | 8,358 | 2,228,884 | 2023-02-15 08:36:23 | 38,692,695 | 16 | 2016-08-01 06:57:15 | 45,375 | 2016-08-02 14:24:53 | https://stackoverflow.com/q/38692346 | https://stackoverflow.com/a/38692695 | <p>iTerm2 v3 features much-improved AppleScript support, so you can now create tabs directly, without having to send keystrokes:</p>
<pre class="lang-sh prettyprint-override"><code>tab() {
osascript &>/dev/null <<EOF
tell application "iTerm"
activate
tell current window to set tb... | <p>iTerm2 v3 features much-improved AppleScript support, so you can now create tabs directly, without having to send keystrokes:</p> <pre class="lang-sh prettyprint-override"><code>tab() { osascript &>/dev/null <<EOF tell application "iTerm" activate tell current window to set tb... | 387, 25122, 89892 | bash, iterm, iterm2 | <h1>new tab in iTerm2</h1>
<p>Im using Iterm2 version Build 3.0.4
I want to create alias to open new tab from the command line (in bash)
I tried this code:</p>
<pre><code> function tab () {
osascript &>/dev/null <<EOF
activate application "iTerm"
tell application "System Events" to keystroke "t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,985 | bash | # new tab in iTerm2
Im using Iterm2 version Build 3.0.4
I want to create alias to open new tab from the command line (in bash)
I tried this code:
```
function tab () {
osascript &>/dev/null <<EOF
activate application "iTerm"
tell application "System Events" to keystroke "t" using command down
tell app... | iTerm2 v3 features much-improved AppleScript support, so you can now create tabs directly, without having to send keystrokes:
```
tab() {
osascript &>/dev/null <<EOF
tell application "iTerm"
activate
tell current window to set tb to create tab with default profile
tell current session... |
38410686 | How can I post a json string with curl that has characters that need escaping? | 7 | 2016-07-16 11:23:30 | <p>I've got a shell script I've been using to post stuff to a hipchat channel. It works ok until I try and send a message that has characters that need escaping. I run the command like so (note the extra backslash in there to cause a problem)</p>
<pre><code>/usr/local/bin/hipchatmsg.sh "my great message here \ " red
<... | 6,774 | 84,433 | 2016-07-16 12:19:35 | 38,411,136 | 16 | 2016-07-16 12:19:35 | 1,126,841 | 2016-07-16 12:19:35 | https://stackoverflow.com/q/38410686 | https://stackoverflow.com/a/38411136 | <p>The easiest thing to do is use a program like <a href="https://stedolan.github.io/jq/" rel="noreferrer"><code>jq</code></a> to generate the JSON; it will take care of escaping what needs to be escaped.</p>
<pre><code>jq -n --arg color "$COLOR" \
--arg message "$MESSAGE" \
'{color: $color, message_format: "... | <p>The easiest thing to do is use a program like <a href="https://stedolan.github.io/jq/" rel="noreferrer"><code>jq</code></a> to generate the JSON; it will take care of escaping what needs to be escaped.</p> <pre><code>jq -n --arg color "$COLOR" \ --arg message "$MESSAGE" \ '{color: $color, message_format: "... | 387, 390, 1554 | bash, curl, shell | <h1>How can I post a json string with curl that has characters that need escaping?</h1>
<p>I've got a shell script I've been using to post stuff to a hipchat channel. It works ok until I try and send a message that has characters that need escaping. I run the command like so (note the extra backslash in there to cause ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,986 | bash | # How can I post a json string with curl that has characters that need escaping?
I've got a shell script I've been using to post stuff to a hipchat channel. It works ok until I try and send a message that has characters that need escaping. I run the command like so (note the extra backslash in there to cause a problem... | The easiest thing to do is use a program like [`jq`](https://stedolan.github.io/jq/) to generate the JSON; it will take care of escaping what needs to be escaped.
```
jq -n --arg color "$COLOR" \
--arg message "$MESSAGE" \
'{color: $color, message_format: "text", message: $message}' |
/usr/bin/curl -H "Conte... |
36557017 | How to parse strace in shell into plain text? | 7 | 2016-04-11 18:58:32 | <p>I've trace log generated by <a href="http://linux.die.net/man/1/strace" rel="noreferrer"><code>strace</code></a> command like on running PHP by:</p>
<pre><code>sudo strace -e sendto -fp $(pgrep -n php) -o strace.log
</code></pre>
<p>And the output looks like:</p>
<blockquote>
<p><code>11208 sendto(4, "set 29170... | 13,126 | 55,075 | 2016-09-12 00:19:19 | 36,557,550 | 16 | 2016-04-11 19:26:55 | 55,075 | 2016-09-12 00:19:19 | https://stackoverflow.com/q/36557017 | https://stackoverflow.com/a/36557550 | <p>The problem why <code>read</code> doesn't work, because shell is already escaping the characters, so the string is doubled escaped, therefore <code>\r\n</code> is printed as <code>rn</code>.</p>
<p>To <a href="https://stackoverflow.com/q/23621615/55075">ignore escaping of characters by shell</a>, you can use <code>... | <p>The problem why <code>read</code> doesn't work, because shell is already escaping the characters, so the string is doubled escaped, therefore <code>\r\n</code> is printed as <code>rn</code>.</p> <p>To <a href="https://stackoverflow.com/q/23621615/55075">ignore escaping of characters by shell</a>, you can use <code>... | 390, 1357, 4804, 31178 | escaping, parsing, shell, strace | <h1>How to parse strace in shell into plain text?</h1>
<p>I've trace log generated by <a href="http://linux.die.net/man/1/strace" rel="noreferrer"><code>strace</code></a> command like on running PHP by:</p>
<pre><code>sudo strace -e sendto -fp $(pgrep -n php) -o strace.log
</code></pre>
<p>And the output looks like:<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,987 | bash | # How to parse strace in shell into plain text?
I've trace log generated by [`strace`](http://linux.die.net/man/1/strace) command like on running PHP by:
```
sudo strace -e sendto -fp $(pgrep -n php) -o strace.log
```
And the output looks like:
> `` 11208 sendto(4, "set 29170397297_-cache-schema 85 0 127240\r\n\257... | The problem why `read` doesn't work, because shell is already escaping the characters, so the string is doubled escaped, therefore `\r\n` is printed as `rn`.
To [ignore escaping of characters by shell](https://stackoverflow.com/q/23621615/55075), you can use `read -r` which allow backslashes to escape any characters (... |
35127523 | How to save and load history in powershell PSReadLine module? | 7 | 2016-02-01 09:56:55 | <p>I'm using great <a href="https://github.com/lzybkr/PSReadLine" rel="noreferrer">PSReadLine</a> module for Powershell and I really like that is persist my history of commands. But I need to reinstall my system. What is the easiest way to save this history (probably to file) an load it after fresh install of PSReadLin... | 2,335 | 350,384 | 2016-02-01 15:33:26 | 35,134,327 | 16 | 2016-02-01 15:33:26 | 4,003,407 | 2016-02-01 15:33:26 | https://stackoverflow.com/q/35127523 | https://stackoverflow.com/a/35134327 | <p><code>PSReadline</code> module save command history in file. All you need is to backup that file and restore it after reinstalling your system. You can get file name of history file by following command:</p>
<pre><code>(Get-PSReadlineOption).HistorySavePath
</code></pre>
| <p><code>PSReadline</code> module save command history in file. All you need is to backup that file and restore it after reinstalling your system. You can get file name of history file by following command:</p> <pre><code>(Get-PSReadlineOption).HistorySavePath </code></pre> | 526, 117507 | powershell, psreadline | <h1>How to save and load history in powershell PSReadLine module?</h1>
<p>I'm using great <a href="https://github.com/lzybkr/PSReadLine" rel="noreferrer">PSReadLine</a> module for Powershell and I really like that is persist my history of commands. But I need to reinstall my system. What is the easiest way to save this... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,988 | bash | # How to save and load history in powershell PSReadLine module?
I'm using great [PSReadLine](https://github.com/lzybkr/PSReadLine) module for Powershell and I really like that is persist my history of commands. But I need to reinstall my system. What is the easiest way to save this history (probably to file) an load i... | `PSReadline` module save command history in file. All you need is to backup that file and restore it after reinstalling your system. You can get file name of history file by following command:
```
(Get-PSReadlineOption).HistorySavePath
``` |
35042747 | Try & Catch not working when using Invoke-Command | 7 | 2016-01-27 16:25:47 | <p>There's a strange issue in my script.
I'm invoking a command on some servers. If I can't connect to the server (because it's offline or something) I still want to log that (Server is offline > log.txt)</p>
<p>Apparently, when an error occurs in <code>Try</code> block, the <code>Catch</code> block is not executed.</... | 9,660 | 5,084,424 | 2016-01-27 16:43:13 | 35,042,932 | 16 | 2016-01-27 16:33:57 | 3,905,079 | 2016-01-27 16:33:57 | https://stackoverflow.com/q/35042747 | https://stackoverflow.com/a/35042932 | <p>It's not a terminating error, so it will never be caught by <code>try</code>/<code>catch</code>. Add <code>-ErrorAction Stop</code>:</p>
<pre><code>Try {
Invoke-Command -ComputerName hui -ScriptBlock $sb -ErrorAction Stop
}
Catch {
Write-Host "Hello"
}
</code></pre>
| <p>It's not a terminating error, so it will never be caught by <code>try</code>/<code>catch</code>. Add <code>-ErrorAction Stop</code>:</p> <pre><code>Try { Invoke-Command -ComputerName hui -ScriptBlock $sb -ErrorAction Stop } Catch { Write-Host "Hello" } </code></pre> | 526, 7436 | powershell, try-catch | <h1>Try & Catch not working when using Invoke-Command</h1>
<p>There's a strange issue in my script.
I'm invoking a command on some servers. If I can't connect to the server (because it's offline or something) I still want to log that (Server is offline > log.txt)</p>
<p>Apparently, when an error occurs in <code>Try</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,989 | bash | # Try & Catch not working when using Invoke-Command
There's a strange issue in my script.
I'm invoking a command on some servers. If I can't connect to the server (because it's offline or something) I still want to log that (Server is offline > log.txt)
Apparently, when an error occurs in `Try` block, the `Catch` blo... | It's not a terminating error, so it will never be caught by `try`/`catch`. Add `-ErrorAction Stop`:
```
Try {
Invoke-Command -ComputerName hui -ScriptBlock $sb -ErrorAction Stop
}
Catch {
Write-Host "Hello"
}
``` |
28018591 | How do I make a Ruby script into a bash command? | 7 | 2015-01-19 05:44:18 | <p>I have a Ruby file, and I run it as <code>ruby file.rb "parameters"</code>. I prefer to run it as <code>regtask parameters</code> without having to include <code>ruby</code> and the filename every time. I want it to be on the same level as <code>ls</code>. How would I accomplish this?</p>
| 9,468 | 998,117 | 2015-01-19 06:29:38 | 28,018,637 | 16 | 2015-01-19 05:49:23 | 240,443 | 2015-01-19 05:49:23 | https://stackoverflow.com/q/28018591 | https://stackoverflow.com/a/28018637 | <p>Edit your file, make sure this is the first line, so your system knows how to execute your file:</p>
<pre><code>#!/usr/bin/env ruby
</code></pre>
<p>Next, change the file's permissions to make it executable:</p>
<pre><code>chmod a+x file.rb
</code></pre>
<p>And finally, rename it and move it somewhere where it w... | <p>Edit your file, make sure this is the first line, so your system knows how to execute your file:</p> <pre><code>#!/usr/bin/env ruby </code></pre> <p>Next, change the file's permissions to make it executable:</p> <pre><code>chmod a+x file.rb </code></pre> <p>And finally, rename it and move it somewhere where it w... | 12, 387, 8780 | bash, ruby, shebang | <h1>How do I make a Ruby script into a bash command?</h1>
<p>I have a Ruby file, and I run it as <code>ruby file.rb "parameters"</code>. I prefer to run it as <code>regtask parameters</code> without having to include <code>ruby</code> and the filename every time. I want it to be on the same level as <code>ls</code>. Ho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,990 | bash | # How do I make a Ruby script into a bash command?
I have a Ruby file, and I run it as `ruby file.rb "parameters"`. I prefer to run it as `regtask parameters` without having to include `ruby` and the filename every time. I want it to be on the same level as `ls`. How would I accomplish this? | Edit your file, make sure this is the first line, so your system knows how to execute your file:
```
#!/usr/bin/env ruby
```
Next, change the file's permissions to make it executable:
```
chmod a+x file.rb
```
And finally, rename it and move it somewhere where it will be executed without having to write its full pa... |
25412497 | SFTP: return number of files in remote directory? | 7 | 2014-08-20 19:02:50 | <p>I sent a batch of files to a remote server via SFTP. If it were a local directory I could do something like this <code>ls -l | wc -l</code> to get the total number of files. However, with SFTP, I get an error <code>Can't ls: "/|" not found</code>.</p>
| 38,505 | 1,489,498 | 2019-02-08 05:19:21 | 25,412,649 | 16 | 2014-08-20 19:11:07 | 3,776,858 | 2017-10-27 13:59:26 | https://stackoverflow.com/q/25412497 | https://stackoverflow.com/a/25412649 | <pre><code>echo ls -l | sftp server | grep -v '^sftp' | wc -l
</code></pre>
<p>If you want to count the files in a directory the directory path should be put after the ls -l command like</p>
<pre><code>echo ls -l /my/directory/ | sftp server | grep -v '^sftp' | wc -l
</code></pre>
| <pre><code>echo ls -l | sftp server | grep -v '^sftp' | wc -l </code></pre> <p>If you want to count the files in a directory the directory path should be put after the ls -l command like</p> <pre><code>echo ls -l /my/directory/ | sftp server | grep -v '^sftp' | wc -l </code></pre> | 387, 1290 | bash, sftp | <h1>SFTP: return number of files in remote directory?</h1>
<p>I sent a batch of files to a remote server via SFTP. If it were a local directory I could do something like this <code>ls -l | wc -l</code> to get the total number of files. However, with SFTP, I get an error <code>Can't ls: "/|" not found</code>.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,991 | bash | # SFTP: return number of files in remote directory?
I sent a batch of files to a remote server via SFTP. If it were a local directory I could do something like this `ls -l | wc -l` to get the total number of files. However, with SFTP, I get an error `Can't ls: "/|" not found`. | ```
echo ls -l | sftp server | grep -v '^sftp' | wc -l
```
If you want to count the files in a directory the directory path should be put after the ls -l command like
```
echo ls -l /my/directory/ | sftp server | grep -v '^sftp' | wc -l
``` |
22984318 | Bash script commands not working in cron | 7 | 2014-04-10 09:42:49 | <p>I have the following bash script to read logs and check for brute force then block violating IP using iptables. </p>
<pre><code>#!/bin/bash
#blah blah run some commands to get the IP
iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $COUNT ATTEMPTS" |wall
</code></pre>
<p>I d... | 7,373 | 1,004,114 | 2014-04-10 09:55:31 | 22,984,467 | 16 | 2014-04-10 09:49:23 | 3,498,673 | 2014-04-10 09:49:23 | https://stackoverflow.com/q/22984318 | https://stackoverflow.com/a/22984467 | <p>Try to provide full path to iptables e.g.</p>
<pre><code>$ which iptables
/sbin/iptables
</code></pre>
<p>and than modify your script like that:\</p>
<pre><code>#!/bin/bash
#blah blah run some commands to get the IP
/sbin/iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $CO... | <p>Try to provide full path to iptables e.g.</p> <pre><code>$ which iptables /sbin/iptables </code></pre> <p>and than modify your script like that:\</p> <pre><code>#!/bin/bash #blah blah run some commands to get the IP /sbin/iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited echo "BANNED $p FOR $CO... | 58, 387, 601 | bash, cron, linux | <h1>Bash script commands not working in cron</h1>
<p>I have the following bash script to read logs and check for brute force then block violating IP using iptables. </p>
<pre><code>#!/bin/bash
#blah blah run some commands to get the IP
iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,992 | bash | # Bash script commands not working in cron
I have the following bash script to read logs and check for brute force then block violating IP using iptables.
```
#!/bin/bash
#blah blah run some commands to get the IP
iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $COUNT ATTEMPTS... | Try to provide full path to iptables e.g.
```
$ which iptables
/sbin/iptables
```
and than modify your script like that:\
```
#!/bin/bash
#blah blah run some commands to get the IP
/sbin/iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $COUNT ATTEMPTS" |wall
``` |
22950272 | Replace " " with "\ " in a file path string with variable expansion | 7 | 2014-04-08 23:41:34 | <p>I know there is a better way to do this.</p>
<ol>
<li><p>What is the better way?</p></li>
<li><p>How do you do a string replace on a string variable in bash?</p></li>
</ol>
<p><strong>For Example:</strong> (using php because that's what I know)</p>
<pre><code>$path = "path/to/directory/foo bar";
$path = str_repl... | 6,404 | 2,782,583 | 2020-05-19 22:43:10 | 22,950,369 | 16 | 2014-04-08 23:50:14 | 45,375 | 2019-05-09 12:21:18 | https://stackoverflow.com/q/22950272 | https://stackoverflow.com/a/22950369 | <p>To perform the specific replacement in <code>bash</code>:</p>
<pre><code>path='path/to/directory/foo bar'
echo "${path// /\\ }"
</code></pre>
<ul>
<li>Don't use prefix <code>$</code> when <em>assigning</em> to variables in <code>bash</code>.</li>
<li>No spaces are allowed around the <code>=</code>.</li>
<li>Note t... | <p>To perform the specific replacement in <code>bash</code>:</p> <pre><code>path='path/to/directory/foo bar' echo "${path// /\\ }" </code></pre> <ul> <li>Don't use prefix <code>$</code> when <em>assigning</em> to variables in <code>bash</code>.</li> <li>No spaces are allowed around the <code>=</code>.</li> <li>Note t... | 387, 2498, 19863 | bash, expansion, replace | <h1>Replace " " with "\ " in a file path string with variable expansion</h1>
<p>I know there is a better way to do this.</p>
<ol>
<li><p>What is the better way?</p></li>
<li><p>How do you do a string replace on a string variable in bash?</p></li>
</ol>
<p><strong>For Example:</strong> (using php because that's what I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,993 | bash | # Replace " " with "\ " in a file path string with variable expansion
I know there is a better way to do this.
1. What is the better way?
2. How do you do a string replace on a string variable in bash?
**For Example:** (using php because that's what I know)
```
$path = "path/to/directory/foo bar";
$path = str_repl... | To perform the specific replacement in `bash`:
```
path='path/to/directory/foo bar'
echo "${path// /\\ }"
```
- Don't use prefix `$` when *assigning* to variables in `bash`.
- No spaces are allowed around the `=`.
- Note that `path` is assigned with *single* quotes, whereas the string replacement occurs in *double* q... |
22378755 | How to preserve spaces when outputting a shell variable? | 7 | 2014-03-13 12:31:41 | <p>For string matching purposes I need to define a bash variable with leading spaces.
I need to define this starting from an integer, like:</p>
<pre><code>jj=5
</code></pre>
<p>printf seems to me a good idea, so if I want to fill spaces up to 6 character:</p>
<pre><code>jpat=`printf " %6i" $jj`
</code></pre>
<p>b... | 16,501 | 1,562,678 | 2017-04-06 13:56:36 | 22,380,038 | 16 | 2014-03-13 13:24:03 | 96,588 | 2014-03-13 13:24:03 | https://stackoverflow.com/q/22378755 | https://stackoverflow.com/a/22380038 | <p><a href="http://mywiki.wooledge.org/Quotes" rel="noreferrer">Use More Quotes!</a> <code>echo "$jpat"</code> will do what you want.</p>
<p>There is another issue with what you're doing: Command substitutions will <em>remove</em> trailing newlines. It's not an issue in the <code>printf</code> command you're using, bu... | <p><a href="http://mywiki.wooledge.org/Quotes" rel="noreferrer">Use More Quotes!</a> <code>echo "$jpat"</code> will do what you want.</p> <p>There is another issue with what you're doing: Command substitutions will <em>remove</em> trailing newlines. It's not an issue in the <code>printf</code> command you're using, bu... | 139, 387, 1084, 16107 | bash, string, substitution, whitespace | <h1>How to preserve spaces when outputting a shell variable?</h1>
<p>For string matching purposes I need to define a bash variable with leading spaces.
I need to define this starting from an integer, like:</p>
<pre><code>jj=5
</code></pre>
<p>printf seems to me a good idea, so if I want to fill spaces up to 6 charact... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,994 | bash | # How to preserve spaces when outputting a shell variable?
For string matching purposes I need to define a bash variable with leading spaces.
I need to define this starting from an integer, like:
```
jj=5
```
printf seems to me a good idea, so if I want to fill spaces up to 6 character:
```
jpat=`printf " %6i" $j... | [Use More Quotes!](http://mywiki.wooledge.org/Quotes) `echo "$jpat"` will do what you want.
There is another issue with what you're doing: Command substitutions will *remove* trailing newlines. It's not an issue in the `printf` command you're using, but for example assigning `jpat=$(printf " %6i\n" "$jj")` would give ... |
21733118 | How to store value returned by nproc in linux shell? | 7 | 2014-02-12 16:02:59 | <p>I'm trying to store the number of CPUs in a variable for a linux bash shell.
I know nproc returns the number of CPUs however I can't seem to store the value returned in a variable.</p>
<p>I'm sure it's a simple solution so any help would be appreciated.</p>
<p>Thanks</p>
| 18,691 | 2,027,404 | 2014-02-12 16:04:00 | 21,733,143 | 16 | 2014-02-12 16:04:00 | 446,267 | 2014-02-12 16:04:00 | https://stackoverflow.com/q/21733118 | https://stackoverflow.com/a/21733143 | <p>Just use nested call to <strong>nproc</strong>:</p>
<pre><code>$ NPROC=$(nproc)
echo $NPROC
1
</code></pre>
| <p>Just use nested call to <strong>nproc</strong>:</p> <pre><code>$ NPROC=$(nproc) echo $NPROC 1 </code></pre> | 58, 387, 390, 448 | bash, cpu, linux, shell | <h1>How to store value returned by nproc in linux shell?</h1>
<p>I'm trying to store the number of CPUs in a variable for a linux bash shell.
I know nproc returns the number of CPUs however I can't seem to store the value returned in a variable.</p>
<p>I'm sure it's a simple solution so any help would be appreciated.<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,995 | bash | # How to store value returned by nproc in linux shell?
I'm trying to store the number of CPUs in a variable for a linux bash shell.
I know nproc returns the number of CPUs however I can't seem to store the value returned in a variable.
I'm sure it's a simple solution so any help would be appreciated.
Thanks | Just use nested call to **nproc**:
```
$ NPROC=$(nproc)
echo $NPROC
1
``` |
20875365 | Read XML file which contains namespace PowerShell | 7 | 2014-01-02 02:11:46 | <p>All, I am trying to read the <code>Role</code> information from <code>Azure Cloud Service Definition</code> xml file or<code>Azure Cloud Service Configure</code> xml file.</p>
<p>But found <code>XPath</code> does't work for them. Both two xml file contain namespace.
By default the namespace doesn't have alias name.... | 13,215 | 1,553,519 | 2014-01-02 20:59:57 | 20,875,439 | 16 | 2014-01-02 02:24:48 | null | 2014-01-02 02:24:48 | https://stackoverflow.com/q/20875365 | https://stackoverflow.com/a/20875439 | <p>When you use the <code>Select-Xml</code> cmdlet with the <code>-XPath</code> parameter, you also need to specify the namespace. See this article for more information:</p>
<p><a href="http://huddledmasses.org/xpath-and-namespaces-in-powershell/" rel="noreferrer">http://huddledmasses.org/xpath-and-namespaces-in-power... | <p>When you use the <code>Select-Xml</code> cmdlet with the <code>-XPath</code> parameter, you also need to specify the namespace. See this article for more information:</p> <p><a href="http://huddledmasses.org/xpath-and-namespaces-in-powershell/" rel="noreferrer">http://huddledmasses.org/xpath-and-namespaces-in-power... | 19, 526, 1227, 14158 | azure, powershell, xml, xpath | <h1>Read XML file which contains namespace PowerShell</h1>
<p>All, I am trying to read the <code>Role</code> information from <code>Azure Cloud Service Definition</code> xml file or<code>Azure Cloud Service Configure</code> xml file.</p>
<p>But found <code>XPath</code> does't work for them. Both two xml file contain n... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,996 | bash | # Read XML file which contains namespace PowerShell
All, I am trying to read the `Role` information from `Azure Cloud Service Definition` xml file or`Azure Cloud Service Configure` xml file.
But found `XPath` does't work for them. Both two xml file contain namespace.
By default the namespace doesn't have alias name. ... | When you use the `Select-Xml` cmdlet with the `-XPath` parameter, you also need to specify the namespace. See this article for more information:
<http://huddledmasses.org/xpath-and-namespaces-in-powershell/>
Here is a complete, working example
```
$XmlDocument = [xml]@'
<?xml version="1.0" encoding="utf-8"?>
<Servic... |
18266348 | How to only get the number of lines of a file | 7 | 2013-08-16 05:24:12 | <p>How do I get the number of lines of a file in linux?</p>
<p>I only want the number of lines, not the filename.<br>
I want to do it in a single command, without grep or another utility.</p>
<pre><code>wc -l sample.txt
</code></pre>
<p><strong>Output</strong></p>
<pre><code>5 sample.txt
</code></pre>
<p><stron... | 10,076 | 865,389 | 2019-08-27 22:58:49 | 18,266,365 | 16 | 2013-08-16 05:25:36 | 498,705 | 2013-08-16 05:25:36 | https://stackoverflow.com/q/18266348 | https://stackoverflow.com/a/18266365 | <p>Try this</p>
<pre><code>wc -l < sample.txt
</code></pre>
<p><code>wc</code> doesn't print out the filename if it reads the file through standard input. The <code><</code> feeds the file via standard input.</p>
| <p>Try this</p> <pre><code>wc -l < sample.txt </code></pre> <p><code>wc</code> doesn't print out the filename if it reads the file through standard input. The <code><</code> feeds the file via standard input.</p> | 58, 387 | bash, linux | <h1>How to only get the number of lines of a file</h1>
<p>How do I get the number of lines of a file in linux?</p>
<p>I only want the number of lines, not the filename.<br>
I want to do it in a single command, without grep or another utility.</p>
<pre><code>wc -l sample.txt
</code></pre>
<p><strong>Output</strong... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,997 | bash | # How to only get the number of lines of a file
How do I get the number of lines of a file in linux?
I only want the number of lines, not the filename.
I want to do it in a single command, without grep or another utility.
```
wc -l sample.txt
```
**Output**
```
5 sample.txt
```
**Desired Output**
```
5
``` | Try this
```
wc -l < sample.txt
```
`wc` doesn't print out the filename if it reads the file through standard input. The `<` feeds the file via standard input. |
17497667 | How to copy certain files (w/o folder hierarchy), but do not overwrite existing files? | 7 | 2013-07-05 22:35:00 | <p>I need to copy all <code>*.doc</code> files (but not folders whose names match <code>*.doc</code>) from a network folder <code>\\server\source</code> (including files in all nested folders) to a local folder <code>C:\destination</code> without preserving the nested folders hierarchy (i.e. all files should go directl... | 17,080 | 305,118 | 2015-08-23 12:01:00 | 17,497,953 | 16 | 2013-07-05 23:10:52 | 1,868,534 | 2015-08-23 12:01:00 | https://stackoverflow.com/q/17497667 | https://stackoverflow.com/a/17497953 | <p>I would produce the list of files first and validate as you go through the list.</p>
<p>Something like this:</p>
<pre><code>$srcdir = "\\server\source\";
$destdir = "C:\destination\";
$files = (Get-ChildItem $SrcDir -recurse -filter *.doc | where-object {-not ($_.PSIsContainer)});
$files|foreach($_){
if (!([sy... | <p>I would produce the list of files first and validate as you go through the list.</p> <p>Something like this:</p> <pre><code>$srcdir = "\\server\source\"; $destdir = "C:\destination\"; $files = (Get-ChildItem $SrcDir -recurse -filter *.doc | where-object {-not ($_.PSIsContainer)}); $files|foreach($_){ if (!([sy... | 526, 4330, 5310, 8000, 16609 | copy, file, flatten, overwrite, powershell | <h1>How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?</h1>
<p>I need to copy all <code>*.doc</code> files (but not folders whose names match <code>*.doc</code>) from a network folder <code>\\server\source</code> (including files in all nested folders) to a local folder <code>C:\dest... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,998 | bash | # How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?
I need to copy all `*.doc` files (but not folders whose names match `*.doc`) from a network folder `\\server\source` (including files in all nested folders) to a local folder `C:\destination` without preserving the nested folders ... | I would produce the list of files first and validate as you go through the list.
Something like this:
```
$srcdir = "\\server\source\";
$destdir = "C:\destination\";
$files = (Get-ChildItem $SrcDir -recurse -filter *.doc | where-object {-not ($_.PSIsContainer)});
$files|foreach($_){
if (!([system.io.file]::Exists... |
10987039 | Prevent typed characters from being displayed (like disabling "echo" attribute in termios) | 7 | 2012-06-11 20:23:42 | <p>I'm writing a bash script in which I read single characters from the input. I do so using <code>read -n 1 -s</code>. <code>-n 1</code> is to read only a single character; <code>-s</code> is "silent" mode, in which the typed characters won't be visible.</p>
<p>The problem is, that when the currently executed command... | 5,055 | 592,323 | 2012-06-11 20:25:54 | 10,987,064 | 16 | 2012-06-11 20:25:54 | 1,446,378 | 2012-06-11 20:25:54 | https://stackoverflow.com/q/10987039 | https://stackoverflow.com/a/10987064 | <pre><code>stty -echo
# Anything they type won't output here
stty echo
# Now it will
</code></pre>
| <pre><code>stty -echo # Anything they type won't output here stty echo # Now it will </code></pre> | 387, 391, 531, 34856 | bash, scripting, terminal, termios | <h1>Prevent typed characters from being displayed (like disabling "echo" attribute in termios)</h1>
<p>I'm writing a bash script in which I read single characters from the input. I do so using <code>read -n 1 -s</code>. <code>-n 1</code> is to read only a single character; <code>-s</code> is "silent" mode, in which the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 8,999 | bash | # Prevent typed characters from being displayed (like disabling "echo" attribute in termios)
I'm writing a bash script in which I read single characters from the input. I do so using `read -n 1 -s`. `-n 1` is to read only a single character; `-s` is "silent" mode, in which the typed characters won't be visible.
The p... | ```
stty -echo
# Anything they type won't output here
stty echo
# Now it will
``` |
8201729 | Rename files to md5 sum + extension (BASH) | 7 | 2011-11-20 13:14:34 | <p>I need some help with a bash script. Script needs to rename all files in a directory to its md5 sum + extension.</p>
<p>I have found the bash script below, but it needs to be changed so that it will add the extension.</p>
<pre><code>md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
<... | 12,387 | 275,191 | 2018-10-23 03:25:25 | 8,204,659 | 16 | 2011-11-20 20:56:06 | 967,492 | 2011-11-20 20:56:06 | https://stackoverflow.com/q/8201729 | https://stackoverflow.com/a/8204659 | <p>This might work for you:</p>
<pre><code># mkdir temp && cd temp && touch file.{a..e}
# ls
file.a file.b file.c file.d file.e
# md5sum * | sed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/' | sh
`file.a' -> `d41d8cd98f00b204e9800998ecf8427e.a'
`file.b' -> `d41d8cd98f00b204e9800998ecf8427e.... | <p>This might work for you:</p> <pre><code># mkdir temp && cd temp && touch file.{a..e} # ls file.a file.b file.c file.d file.e # md5sum * | sed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/' | sh `file.a' -> `d41d8cd98f00b204e9800998ecf8427e.a' `file.b' -> `d41d8cd98f00b204e9800998ecf8427e.... | 58, 387, 4510, 13475 | bash, batch-rename, linux, rename | <h1>Rename files to md5 sum + extension (BASH)</h1>
<p>I need some help with a bash script. Script needs to rename all files in a directory to its md5 sum + extension.</p>
<p>I have found the bash script below, but it needs to be changed so that it will add the extension.</p>
<pre><code>md5sum * | sed 's/^\(\w*\)\s*\... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,000 | bash | # Rename files to md5 sum + extension (BASH)
I need some help with a bash script. Script needs to rename all files in a directory to its md5 sum + extension.
I have found the bash script below, but it needs to be changed so that it will add the extension.
```
md5sum * | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read ... | This might work for you:
```
# mkdir temp && cd temp && touch file.{a..e}
# ls
file.a file.b file.c file.d file.e
# md5sum * | sed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/' | sh
`file.a' -> `d41d8cd98f00b204e9800998ecf8427e.a'
`file.b' -> `d41d8cd98f00b204e9800998ecf8427e.b'
`file.c' -> `d41d8cd98f00b204e980... |
7032547 | Best way to generate a random string following a specific pattern in Bash | 7 | 2011-08-11 20:41:05 | <p>I'm wanting to generate many six character strings all following this pattern:</p>
<blockquote>
<p>[consonant][vowel][consonant][consonant][vowel][consonant]</p>
</blockquote>
<p>e.g.</p>
<blockquote>
<p>haplop<br>
github<br>
qursog</p>
</blockquote>
<p>I've looked at various ways of doing this, but noth... | 10,093 | 109,561 | 2013-11-17 14:24:30 | 7,032,701 | 16 | 2011-08-11 20:54:08 | 650,405 | 2011-08-11 20:54:08 | https://stackoverflow.com/q/7032547 | https://stackoverflow.com/a/7032701 | <p>Here is how you could generate a vowel:</p>
<pre><code>s=aeiou
p=$(( $RANDOM % 5))
c=${s:$p:1}
</code></pre>
<p>Use the same method for consonants.</p>
<p>You can wrap this into a small function:</p>
<pre><code>function vowel() {
s=aeoiu
p=$(( $RANDOM % 5))
echo -n ${s:$p:1}
}
</code></pre>
<p>And t... | <p>Here is how you could generate a vowel:</p> <pre><code>s=aeiou p=$(( $RANDOM % 5)) c=${s:$p:1} </code></pre> <p>Use the same method for consonants.</p> <p>You can wrap this into a small function:</p> <pre><code>function vowel() { s=aeoiu p=$(( $RANDOM % 5)) echo -n ${s:$p:1} } </code></pre> <p>And t... | 58, 139, 197, 387 | bash, linux, random, string | <h1>Best way to generate a random string following a specific pattern in Bash</h1>
<p>I'm wanting to generate many six character strings all following this pattern:</p>
<blockquote>
<p>[consonant][vowel][consonant][consonant][vowel][consonant]</p>
</blockquote>
<p>e.g.</p>
<blockquote>
<p>haplop<br>
github<br>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,001 | bash | # Best way to generate a random string following a specific pattern in Bash
I'm wanting to generate many six character strings all following this pattern:
> [consonant][vowel][consonant][consonant][vowel][consonant]
e.g.
> haplop
> github
> qursog
I've looked at various ways of doing this, but nothing I have t... | Here is how you could generate a vowel:
```
s=aeiou
p=$(( $RANDOM % 5))
c=${s:$p:1}
```
Use the same method for consonants.
You can wrap this into a small function:
```
function vowel() {
s=aeoiu
p=$(( $RANDOM % 5))
echo -n ${s:$p:1}
}
```
And then you have a nice pattern to generate the string:
```
s... |
4736197 | What is correct syntax for arrays in powershell? | 7 | 2011-01-19 14:12:31 | <p>Example1:</p>
<blockquote>
<p>Note 2: The comma is also used so
separate items in an array {0,-30}</p>
</blockquote>
<p>Example2:</p>
<blockquote>
<p>To create an array, we create a
variable and assign the array. Arrays
are noted by the “@” symbol. Let’s
take the discussion above and use an
array to... | 7,152 | 423,278 | 2011-01-20 15:26:46 | 4,736,356 | 16 | 2011-01-19 14:27:26 | 3,305 | 2011-01-19 14:27:26 | https://stackoverflow.com/q/4736197 | https://stackoverflow.com/a/4736356 | <p>Example 2 uses the array cast syntax which allows a single element, for example, to be treated as an array:</p>
<pre><code>$myList = @("Hello")
</code></pre>
<p>Essentially, it allows anything between the parenthesis to be treated as an array including the output from other commands:</p>
<pre><code>$myArray = @(G... | <p>Example 2 uses the array cast syntax which allows a single element, for example, to be treated as an array:</p> <pre><code>$myList = @("Hello") </code></pre> <p>Essentially, it allows anything between the parenthesis to be treated as an array including the output from other commands:</p> <pre><code>$myArray = @(G... | 114, 526, 24067 | arrays, powershell, powershell-2.0 | <h1>What is correct syntax for arrays in powershell?</h1>
<p>Example1:</p>
<blockquote>
<p>Note 2: The comma is also used so
separate items in an array {0,-30}</p>
</blockquote>
<p>Example2:</p>
<blockquote>
<p>To create an array, we create a
variable and assign the array. Arrays
are noted by the “@” symbo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,002 | bash | # What is correct syntax for arrays in powershell?
Example1:
> Note 2: The comma is also used so
> separate items in an array {0,-30}
Example2:
> To create an array, we create a
> variable and assign the array. Arrays
> are noted by the “@” symbol. Let’s
> take the discussion above and use an
> array to connect to ... | Example 2 uses the array cast syntax which allows a single element, for example, to be treated as an array:
```
$myList = @("Hello")
```
Essentially, it allows anything between the parenthesis to be treated as an array including the output from other commands:
```
$myArray = @(Get-Process Excel)
```
Alternatively y... |
4539470 | Making executable all PHP files (recursively) | 7 | 2010-12-27 14:54:31 | <p>I just downloaded MediaWiki software on my server for installation. After decompressing it, I noticed that PHP files were not executable.</p>
<p>I ran chmod <code>+x *.php*</code> (there are also .php5 files) but it didn't work in subdirectories.</p>
<p>How can I add the executable flag to all PHP scripts inside t... | 10,412 | 471,213 | 2025-03-17 14:30:39 | 4,539,523 | 16 | 2010-12-27 15:02:31 | 58,262 | 2025-03-17 14:30:39 | https://stackoverflow.com/q/4539470 | https://stackoverflow.com/a/4539523 | <p>Use bash in the MediaWiki directory</p>
<pre><code>find . -iname "*.php" -print0 | xargs -0 chmod +x
</code></pre>
| <p>Use bash in the MediaWiki directory</p> <pre><code>find . -iname "*.php" -print0 | xargs -0 chmod +x </code></pre> | 5, 387, 12380 | bash, chmod, php | <h1>Making executable all PHP files (recursively)</h1>
<p>I just downloaded MediaWiki software on my server for installation. After decompressing it, I noticed that PHP files were not executable.</p>
<p>I ran chmod <code>+x *.php*</code> (there are also .php5 files) but it didn't work in subdirectories.</p>
<p>How ca... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,003 | bash | # Making executable all PHP files (recursively)
I just downloaded MediaWiki software on my server for installation. After decompressing it, I noticed that PHP files were not executable.
I ran chmod `+x *.php*` (there are also .php5 files) but it didn't work in subdirectories.
How can I add the executable flag to all... | Use bash in the MediaWiki directory
```
find . -iname "*.php" -print0 | xargs -0 chmod +x
``` |
3400031 | bash: Filtering out directories and extensions from find? | 7 | 2010-08-03 19:22:35 | <p>I'm trying to find files modified recently with this</p>
<pre><code>find . -mtime 0
</code></pre>
<p>Which gives me</p>
<pre><code>en/content/file.xml
es/file.php
en/file.php.swp
css/main.css
js/main.js
</code></pre>
<p>But I'd like to filter out the <code>en</code> and <code>es</code> directories but would like... | 13,244 | 145,190 | 2010-08-04 09:43:46 | 3,400,093 | 16 | 2010-08-03 19:30:30 | 371,793 | 2010-08-03 19:30:30 | https://stackoverflow.com/q/3400031 | https://stackoverflow.com/a/3400093 | <p>properly, just in find:</p>
<pre><code>find -mtime 0 -not \( -name '*.swp' -o -path './es*' -o -path './en*' \)
</code></pre>
| <p>properly, just in find:</p> <pre><code>find -mtime 0 -not \( -name '*.swp' -o -path './es*' -o -path './en*' \) </code></pre> | 387, 10193 | bash, find | <h1>bash: Filtering out directories and extensions from find?</h1>
<p>I'm trying to find files modified recently with this</p>
<pre><code>find . -mtime 0
</code></pre>
<p>Which gives me</p>
<pre><code>en/content/file.xml
es/file.php
en/file.php.swp
css/main.css
js/main.js
</code></pre>
<p>But I'd like to filter out... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,004 | bash | # bash: Filtering out directories and extensions from find?
I'm trying to find files modified recently with this
```
find . -mtime 0
```
Which gives me
```
en/content/file.xml
es/file.php
en/file.php.swp
css/main.css
js/main.js
```
But I'd like to filter out the `en` and `es` directories but would like to grab any... | properly, just in find:
```
find -mtime 0 -not \( -name '*.swp' -o -path './es*' -o -path './en*' \)
``` |
2540997 | Create more than one eshell instance in emacs | 7 | 2010-03-29 20:21:53 | <p>Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I can M-x eshell to open the first eshell instance but future invocations just focus the first instance.</p>
| 2,132 | 18,446 | 2024-12-08 05:04:27 | 2,541,089 | 16 | 2010-03-29 20:36:44 | 23,309 | 2010-03-29 20:36:44 | https://stackoverflow.com/q/2540997 | https://stackoverflow.com/a/2541089 | <p>You can do this:</p>
<pre><code>`C-u M-x eshell`
</code></pre>
<p>This will create <code>*eshell*</code>, <code>*eshell*<2></code>, and so on.</p>
| <p>You can do this:</p> <pre><code>`C-u M-x eshell` </code></pre> <p>This will create <code>*eshell*</code>, <code>*eshell*<2></code>, and so on.</p> | 371, 3416, 32732 | emacs, eshell, xmonad | <h1>Create more than one eshell instance in emacs</h1>
<p>Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I can M-x eshell to open the first eshell instance but future invocations just focus the first instance.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,005 | bash | # Create more than one eshell instance in emacs
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I can M-x eshell to open the first eshell instance but future invocations just focus the first instance. | You can do this:
```
`C-u M-x eshell`
```
This will create `*eshell*`, `*eshell*<2>`, and so on. |
2314376 | How do I divide the output of a command by two, and store the result into a bash variable? | 7 | 2010-02-22 21:33:16 | <p>Say if i wanted to do this command:</p>
<pre><code>(cat file | wc -l)/2
</code></pre>
<p>and store it in a variable such as middle, how would i do it?</p>
<p>I know its simply not the case of </p>
<pre><code>$middle=$(cat file | wc -l)/2
</code></pre>
<p>so how would i do it?</p>
| 16,426 | 94,279 | 2011-08-16 21:42:55 | 2,314,434 | 16 | 2010-02-22 21:41:20 | 85,950 | 2010-02-22 21:41:20 | https://stackoverflow.com/q/2314376 | https://stackoverflow.com/a/2314434 | <pre><code>middle=$((`wc -l < file` / 2))
</code></pre>
| <pre><code>middle=$((`wc -l < file` / 2)) </code></pre> | 34, 387, 390 | bash, shell, unix | <h1>How do I divide the output of a command by two, and store the result into a bash variable?</h1>
<p>Say if i wanted to do this command:</p>
<pre><code>(cat file | wc -l)/2
</code></pre>
<p>and store it in a variable such as middle, how would i do it?</p>
<p>I know its simply not the case of </p>
<pre><code>$midd... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,006 | bash | # How do I divide the output of a command by two, and store the result into a bash variable?
Say if i wanted to do this command:
```
(cat file | wc -l)/2
```
and store it in a variable such as middle, how would i do it?
I know its simply not the case of
```
$middle=$(cat file | wc -l)/2
```
so how would i do it? | ```
middle=$((`wc -l < file` / 2))
``` |
1715347 | if-statement always evaluates to TRUE | 7 | 2009-11-11 14:00:48 | <p>Is there any reason why this script always returns "running", regardless of whether my process is started or stopped?</p>
<pre><code>if ps ax | grep -v grep | grep "processName" > /dev/null
then
echo $"running"
else
echo $"not running"
fi
</code></pre>
<p>Thank you very much</p>
<p><strong>UPDATE :</str... | 3,847 | 150,566 | 2012-10-16 20:13:36 | 1,715,370 | 16 | 2009-11-11 14:05:53 | 115,845 | 2009-11-11 16:11:30 | https://stackoverflow.com/q/1715347 | https://stackoverflow.com/a/1715370 | <p>Try this instead:</p>
<pre><code>ps aux | grep -q "[p]rocessName"
if [ $? -eq 0 ]; then
echo "running"
else
echo "not running"
fi
</code></pre>
<p>The brackets around the first letter of processName means do don't need the "grep -v grep", while the -q means we don't need the pipe to /dev/null</p>
<p>$? gi... | <p>Try this instead:</p> <pre><code>ps aux | grep -q "[p]rocessName" if [ $? -eq 0 ]; then echo "running" else echo "not running" fi </code></pre> <p>The brackets around the first letter of processName means do don't need the "grep -v grep", while the -q means we don't need the pipe to /dev/null</p> <p>$? gi... | 34, 58, 387, 5910 | bash, linux, process, unix | <h1>if-statement always evaluates to TRUE</h1>
<p>Is there any reason why this script always returns "running", regardless of whether my process is started or stopped?</p>
<pre><code>if ps ax | grep -v grep | grep "processName" > /dev/null
then
echo $"running"
else
echo $"not running"
fi
</code></pre>
<p>Th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,007 | bash | # if-statement always evaluates to TRUE
Is there any reason why this script always returns "running", regardless of whether my process is started or stopped?
```
if ps ax | grep -v grep | grep "processName" > /dev/null
then
echo $"running"
else
echo $"not running"
fi
```
Thank you very much
**UPDATE :**
I add... | Try this instead:
```
ps aux | grep -q "[p]rocessName"
if [ $? -eq 0 ]; then
echo "running"
else
echo "not running"
fi
```
The brackets around the first letter of processName means do don't need the "grep -v grep", while the -q means we don't need the pipe to /dev/null
$? gives you the return code of the pre... |
1561055 | Switch from file contents to STDIN in piped command? (Linux Shell) | 7 | 2009-10-13 15:38:37 | <p>I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I'd like to be able to automate it by writing the commands in a file for re-use. Trouble is, if the program hits EOF, it loops infinitely trying to read in the next command ... | 7,627 | 109,549 | 2015-06-04 00:29:53 | 1,564,754 | 16 | 2009-10-14 07:22:37 | 109,744 | 2009-10-14 07:22:37 | https://stackoverflow.com/q/1561055 | https://stackoverflow.com/a/1564754 | <p>I would do something like</p>
<pre>
<code>(cat your_file_with_commands; cat) | sh your_script</code>
</pre>
<p>That way, when the file with commands is done, the second <code>cat</code> will feed your script with whatever you type on stdin afterwards.</p>
| <p>I would do something like</p> <pre> <code>(cat your_file_with_commands; cat) | sh your_script</code> </pre> <p>That way, when the file with commands is done, the second <code>cat</code> will feed your script with whatever you type on stdin afterwards.</p> | 387, 390, 5310, 5813, 11366 | bash, file, named-pipes, pipe, shell | <h1>Switch from file contents to STDIN in piped command? (Linux Shell)</h1>
<p>I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I'd like to be able to automate it by writing the commands in a file for re-use. Trouble is, if t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,008 | bash | # Switch from file contents to STDIN in piped command? (Linux Shell)
I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I'd like to be able to automate it by writing the commands in a file for re-use. Trouble is, if the progra... | I would do something like
```
(cat your_file_with_commands; cat) | sh your_script
```
That way, when the file with commands is done, the second `cat` will feed your script with whatever you type on stdin afterwards. |
69063656 | Is it possible to stop `powershell` wrapping output in ANSI sequences? | 6 | 2021-09-05 13:03:49 | <p>I <code>CreateProcess</code>(win32) <code>powershell</code> and read raw bytes from it.
And I see that it produces a lot of invisible chars.
For example <code>\u{1b}[2J\u{1b}[m\u{1b}[</code></p>
<p>Is there any way how to stop it?</p>
<p>*Exactly it's possible to strip them manually but I do hope there other way.</p... | 4,222 | 9,976,869 | 2025-11-13 16:56:45 | 69,065,907 | 16 | 2021-09-05 17:52:43 | 45,375 | 2025-11-13 16:56:45 | https://stackoverflow.com/q/69063656 | https://stackoverflow.com/a/69065907 | <ul>
<li><p>You mention <code>powershell</code> (<code>powershell.exe</code>), i.e. the CLI of <em>Windows PowerShell</em>.</p>
</li>
<li><p><strong>Windows PowerShell</strong> (unlike <em>PowerShell (Core) 7</em>, see below) <strong><em>itself</em> does <em>not</em> use coloring / formatting based on <a href="https://... | <ul> <li><p>You mention <code>powershell</code> (<code>powershell.exe</code>), i.e. the CLI of <em>Windows PowerShell</em>.</p> </li> <li><p><strong>Windows PowerShell</strong> (unlike <em>PowerShell (Core) 7</em>, see below) <strong><em>itself</em> does <em>not</em> use coloring / formatting based on <a href="https://... | 64, 526, 889 | powershell, winapi, windows | <h1>Is it possible to stop `powershell` wrapping output in ANSI sequences?</h1>
<p>I <code>CreateProcess</code>(win32) <code>powershell</code> and read raw bytes from it.
And I see that it produces a lot of invisible chars.
For example <code>\u{1b}[2J\u{1b}[m\u{1b}[</code></p>
<p>Is there any way how to stop it?</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,009 | bash | # Is it possible to stop `powershell` wrapping output in ANSI sequences?
I `CreateProcess`(win32) `powershell` and read raw bytes from it.
And I see that it produces a lot of invisible chars.
For example `\u{1b}[2J\u{1b}[m\u{1b}[`
Is there any way how to stop it?
*Exactly it's possible to strip them manually but I d... | - You mention `powershell` (`powershell.exe`), i.e. the CLI of *Windows PowerShell*.
- **Windows PowerShell** (unlike *PowerShell (Core) 7*, see below) ***itself* does *not* use coloring / formatting based on [VT / ANSI escape sequences](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequence... |
61754413 | set Powershell core as a default GNU Make shell on windows/linux | 6 | 2020-05-12 14:32:02 | <p>In the makefile on Windows.</p>
<p>With the following make version:</p>
<pre><code>PS C:\projects> make --version
GNU Make 4.1
Built for i686-w64-mingw32
Copyright (C) 1988-2014 Free Software Foundation, Inc.
</code></pre>
<p>I have tried to set <code>SHELL := pwsh</code> / <code>COMSPEC := pwsh</code> and run... | 5,724 | 4,105,482 | 2020-09-11 14:14:50 | 63,840,549 | 16 | 2020-09-11 03:50:20 | 7,607,701 | 2020-09-11 14:14:50 | https://stackoverflow.com/q/61754413 | https://stackoverflow.com/a/63840549 | <p>What @raspy says is true, but, I found a <em>glorious</em> workaround!</p>
<p>If you take a look at this <a href="http://git.savannah.gnu.org/cgit/make.git/tree/src/job.c#n2909" rel="noreferrer">if statement right here</a> you'll notice that if the <code>shellflags</code> is set to something besides <code>-c</code> ... | <p>What @raspy says is true, but, I found a <em>glorious</em> workaround!</p> <p>If you take a look at this <a href="http://git.savannah.gnu.org/cgit/make.git/tree/src/job.c#n2909" rel="noreferrer">if statement right here</a> you'll notice that if the <code>shellflags</code> is set to something besides <code>-c</code> ... | 526, 4301, 13213 | gnu-make, makefile, powershell | <h1>set Powershell core as a default GNU Make shell on windows/linux</h1>
<p>In the makefile on Windows.</p>
<p>With the following make version:</p>
<pre><code>PS C:\projects> make --version
GNU Make 4.1
Built for i686-w64-mingw32
Copyright (C) 1988-2014 Free Software Foundation, Inc.
</code></pre>
<p>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 | 9,010 | bash | # set Powershell core as a default GNU Make shell on windows/linux
In the makefile on Windows.
With the following make version:
```
PS C:\projects> make --version
GNU Make 4.1
Built for i686-w64-mingw32
Copyright (C) 1988-2014 Free Software Foundation, Inc.
```
I have tried to set `SHELL := pwsh` / `COMSPEC := pwsh... | What @raspy says is true, but, I found a *glorious* workaround!
If you take a look at this [if statement right here](http://git.savannah.gnu.org/cgit/make.git/tree/src/job.c#n2909) you'll notice that if the `shellflags` is set to something besides `-c` or `-ce` it will *always* use the slow option (Which means it will... |
63210511 | Wait until a condition becomes true in bash | 6 | 2020-08-01 22:10:17 | <p>When writing shell scripts, I repeatedly have the need to wait for a given condition to become true, e.g. a remote URL becoming available (checked with curl) or a file that should exist, etc.</p>
<p>Ideally, I'd like to have a function or script <code>await</code> such that I can write, e.g.,</p>
<pre><code>await [[... | 12,853 | 1,104,870 | 2022-03-10 17:31:52 | 63,210,546 | 16 | 2020-08-01 22:15:29 | 1,899,640 | 2022-03-10 17:31:52 | https://stackoverflow.com/q/63210511 | https://stackoverflow.com/a/63210546 | <p>You can use an <code>until</code> loop:</p>
<pre><code>until some condition
do
sleep 5
done
</code></pre>
<p>e.g.</p>
<pre><code>until nc -z localhost 22
do
echo "SSHd is not up yet. Waiting..."
sleep 5
done
</code></pre>
<p>If you want to add a timeout, you'll have to add that separately with a coun... | <p>You can use an <code>until</code> loop:</p> <pre><code>until some condition do sleep 5 done </code></pre> <p>e.g.</p> <pre><code>until nc -z localhost 22 do echo "SSHd is not up yet. Waiting..." sleep 5 done </code></pre> <p>If you want to add a timeout, you'll have to add that separately with a coun... | 387, 390 | bash, shell | <h1>Wait until a condition becomes true in bash</h1>
<p>When writing shell scripts, I repeatedly have the need to wait for a given condition to become true, e.g. a remote URL becoming available (checked with curl) or a file that should exist, etc.</p>
<p>Ideally, I'd like to have a function or script <code>await</code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,011 | bash | # Wait until a condition becomes true in bash
When writing shell scripts, I repeatedly have the need to wait for a given condition to become true, e.g. a remote URL becoming available (checked with curl) or a file that should exist, etc.
Ideally, I'd like to have a function or script `await` such that I can write, e.... | You can use an `until` loop:
```
until some condition
do
sleep 5
done
```
e.g.
```
until nc -z localhost 22
do
echo "SSHd is not up yet. Waiting..."
sleep 5
done
```
If you want to add a timeout, you'll have to add that separately with a counter or using the [internal `SECONDS` variable](https://tldp.org/LDP/... |
62889225 | How to install a particular version of helm? | 6 | 2020-07-14 06:25:34 | <p>I am installing helm through a script which uses these commands to install the latest version -</p>
<pre><code>curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3.2.0
chmod 700 get_helm.sh
./get_helm.sh
</code></pre>
<p>however , i don't want it to install the latest versi... | 14,403 | 12,075,171 | 2022-10-15 04:32:57 | 62,896,709 | 16 | 2020-07-14 13:48:29 | 7,568,391 | 2020-07-14 13:48:29 | https://stackoverflow.com/q/62889225 | https://stackoverflow.com/a/62896709 | <p>You can find all the versions of helm binaries on <a href="https://github.com/helm/helm/releases" rel="noreferrer">Helm Releases page</a></p>
<p>If you want to install <a href="https://github.com/helm/helm/releases/tag/v3.2.4" rel="noreferrer">v3.2.4</a></p>
<pre><code>$ wget https://get.helm.sh/helm-v3.2.4-linux-am... | <p>You can find all the versions of helm binaries on <a href="https://github.com/helm/helm/releases" rel="noreferrer">Helm Releases page</a></p> <p>If you want to install <a href="https://github.com/helm/helm/releases/tag/v3.2.4" rel="noreferrer">v3.2.4</a></p> <pre><code>$ wget https://get.helm.sh/helm-v3.2.4-linux-am... | 390, 1796, 5792, 106338, 124512 | command, kubernetes, kubernetes-helm, shell, version | <h1>How to install a particular version of helm?</h1>
<p>I am installing helm through a script which uses these commands to install the latest version -</p>
<pre><code>curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3.2.0
chmod 700 get_helm.sh
./get_helm.sh
</code></pre>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,012 | bash | # How to install a particular version of helm?
I am installing helm through a script which uses these commands to install the latest version -
```
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3.2.0
chmod 700 get_helm.sh
./get_helm.sh
```
however , i don't want it to i... | You can find all the versions of helm binaries on [Helm Releases page](https://github.com/helm/helm/releases)
If you want to install [v3.2.4](https://github.com/helm/helm/releases/tag/v3.2.4)
```
$ wget https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz
$ tar -zxvf helm-v3.2.4-linux-amd64.tar.gz
$ sudo mv linux-amd64... |
55980492 | Get current Subscription ID | 6 | 2019-05-04 07:34:26 | <p>Using the Powershell Azure module, is there a way to get the active subscription ID?</p>
<p>I can set the subscription using <code>Set-AzContext</code>, but <code>Get-AzContext</code> returns the subscription name without a specific <code>ID</code> column</p>
<p><code>Get-AzSubscription</code> returns a list of su... | 10,003 | 2,649,626 | 2019-05-04 10:04:30 | 55,980,802 | 16 | 2019-05-04 08:25:53 | 6,067,741 | 2019-05-04 08:25:53 | https://stackoverflow.com/q/55980492 | https://stackoverflow.com/a/55980802 | <p>you could do that with the following command:</p>
<pre><code>(Get-AzContext).Subscription.id
</code></pre>
| <p>you could do that with the following command:</p> <pre><code>(Get-AzContext).Subscription.id </code></pre> | 526, 14158, 81879 | azure, azure-powershell, powershell | <h1>Get current Subscription ID</h1>
<p>Using the Powershell Azure module, is there a way to get the active subscription ID?</p>
<p>I can set the subscription using <code>Set-AzContext</code>, but <code>Get-AzContext</code> returns the subscription name without a specific <code>ID</code> column</p>
<p><code>Get-AzSub... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,013 | bash | # Get current Subscription ID
Using the Powershell Azure module, is there a way to get the active subscription ID?
I can set the subscription using `Set-AzContext`, but `Get-AzContext` returns the subscription name without a specific `ID` column
`Get-AzSubscription` returns a list of subscriptions, but not the activ... | you could do that with the following command:
```
(Get-AzContext).Subscription.id
``` |
53201641 | Passing Newline character as an argument within shell | 6 | 2018-11-08 04:40:05 | <p>The program takes single character as an argument. </p>
<pre><code>./myprog <character>
</code></pre>
<p>How can i pass <strong>\n</strong> in the shell to the myprog ?</p>
| 8,326 | 5,675,033 | 2018-11-08 07:22:52 | 53,201,679 | 16 | 2018-11-08 04:44:59 | 240,443 | 2018-11-08 07:22:52 | https://stackoverflow.com/q/53201641 | https://stackoverflow.com/a/53201679 | <p>Easiest but not very pretty:</p>
<pre><code>./myprog "
"
</code></pre>
<p>EDIT: Still easiest, but I forgot about it:</p>
<pre><code>./myprog $'\n'
</code></pre>
<p>Another alternative:</p>
<pre><code>./myprog ^M # not ^ and M, but the literal LF character
# in `bas... | <p>Easiest but not very pretty:</p> <pre><code>./myprog " " </code></pre> <p>EDIT: Still easiest, but I forgot about it:</p> <pre><code>./myprog $'\n' </code></pre> <p>Another alternative:</p> <pre><code>./myprog ^M # not ^ and M, but the literal LF character # in `bas... | 387, 3705 | bash, newline | <h1>Passing Newline character as an argument within shell</h1>
<p>The program takes single character as an argument. </p>
<pre><code>./myprog <character>
</code></pre>
<p>How can i pass <strong>\n</strong> in the shell to the myprog ?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,014 | bash | # Passing Newline character as an argument within shell
The program takes single character as an argument.
```
./myprog <character>
```
How can i pass **\n** in the shell to the myprog ? | Easiest but not very pretty:
```
./myprog "
"
```
EDIT: Still easiest, but I forgot about it:
```
./myprog $'\n'
```
Another alternative:
```
./myprog ^M # not ^ and M, but the literal LF character
# in `bash`, obtained by Ctrl-V, Enter
```
Or, you can do what these p... |
52257001 | MYSQL Shell connect error from Command line | 6 | 2018-09-10 11:40:17 | <p>I am trying to connect to mysqlshell client from my linux command line
when I try to connect, using</p>
<pre><code>mysqlsh mysql -h IP -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port -u -port 3306 user -ppassword -e "show databases"
</c... | 5,024 | 8,068,633 | 2018-09-10 13:08:33 | 52,258,543 | 16 | 2018-09-10 13:08:33 | 2,908,599 | 2018-09-10 13:08:33 | https://stackoverflow.com/q/52257001 | https://stackoverflow.com/a/52258543 | <p>The proper format of <code>mysqlsh</code> is a bit different:</p>
<pre><code>mysqlsh --user=user --password=password --port=5721 --host <hostname or IP>
</code></pre>
| <p>The proper format of <code>mysqlsh</code> is a bit different:</p> <pre><code>mysqlsh --user=user --password=password --port=5721 --host <hostname or IP> </code></pre> | 21, 387, 390 | bash, mysql, shell | <h1>MYSQL Shell connect error from Command line</h1>
<p>I am trying to connect to mysqlshell client from my linux command line
when I try to connect, using</p>
<pre><code>mysqlsh mysql -h IP -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,015 | bash | # MYSQL Shell connect error from Command line
I am trying to connect to mysqlshell client from my linux command line
when I try to connect, using
```
mysqlsh mysql -h IP -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port -u user -ppassword -e "show databases"
mysqlsh mysql -h IP:port -u -port 3306 user -... | The proper format of `mysqlsh` is a bit different:
```
mysqlsh --user=user --password=password --port=5721 --host <hostname or IP>
``` |
51578269 | Can't restart webmin [status 2] | 6 | 2018-07-29 07:37:14 | <p>I've updated webmin, but now, it refuse to restart :</p>
<pre><code>● webmin.service - LSB: web-based administration interface for Unix systems
Loaded: loaded (/etc/init.d/webmin; generated; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-07-29 09:30:29 CEST; 12s ago
Docs: man:system... | 14,407 | 9,295,883 | 2020-06-10 15:49:54 | 51,578,450 | 16 | 2018-07-29 08:08:48 | 9,295,883 | 2018-07-29 08:08:48 | https://stackoverflow.com/q/51578269 | https://stackoverflow.com/a/51578450 | <h1>SOLUTION</h1>
<p>I tried to start like this</p>
<pre><code>root@vps513135:~# /etc/webmin/start
Starting Webmin server in /usr/share/webmin
Failed to open SSL key /home/sowdowdow/domains/sow.sowdowdow.fr/ssl.key at /usr/share/webmin/miniserv.pl line 4414.
</code></pre>
<p>The output is a bit more clear, and final... | <h1>SOLUTION</h1> <p>I tried to start like this</p> <pre><code>root@vps513135:~# /etc/webmin/start Starting Webmin server in /usr/share/webmin Failed to open SSL key /home/sowdowdow/domains/sow.sowdowdow.fr/ssl.key at /usr/share/webmin/miniserv.pl line 4414. </code></pre> <p>The output is a bit more clear, and final... | 58, 387, 1012, 10094, 119137 | bash, debian, linux, systemctl, webmin | <h1>Can't restart webmin [status 2]</h1>
<p>I've updated webmin, but now, it refuse to restart :</p>
<pre><code>● webmin.service - LSB: web-based administration interface for Unix systems
Loaded: loaded (/etc/init.d/webmin; generated; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-07-29 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,016 | bash | # Can't restart webmin [status 2]
I've updated webmin, but now, it refuse to restart :
```
● webmin.service - LSB: web-based administration interface for Unix systems
Loaded: loaded (/etc/init.d/webmin; generated; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-07-29 09:30:29 CEST; 12s a... | # SOLUTION
I tried to start like this
```
root@vps513135:~# /etc/webmin/start
Starting Webmin server in /usr/share/webmin
Failed to open SSL key /home/sowdowdow/domains/sow.sowdowdow.fr/ssl.key at /usr/share/webmin/miniserv.pl line 4414.
```
The output is a bit more clear, and finally found a solution [here](https:/... |
43689289 | PowerShell output is crossing between functions | 6 | 2017-04-28 21:41:28 | <p>I am writing a PowerShell script in version 5.1 on Windows 10 that gets certain pieces of information about a local system ( and eventually its subnets ) and outputs them into a text file. At first, I had all of the aspects in a single function. I ran into output issues when outputting <code>getUsersAndGroups</code>... | 1,682 | 4,979,758 | 2024-09-12 20:06:03 | 43,691,123 | 16 | 2017-04-29 02:09:12 | 45,375 | 2024-09-12 20:06:03 | https://stackoverflow.com/q/43689289 | https://stackoverflow.com/a/43691123 |
<p><strong>tl; dr:</strong></p>
<p>The underlying problem affects both <em>Windows PowerShell</em> and <em>PowerShell (Core) 7+</em>, up to at least v7.4.x (current as of this writing), and, since it is a(n unfortunate) side effect of by-design behavior, may or may not get fixed.</p>
<p><strong>To prevent output from ... | <p><strong>tl; dr:</strong></p> <p>The underlying problem affects both <em>Windows PowerShell</em> and <em>PowerShell (Core) 7+</em>, up to at least v7.4.x (current as of this writing), and, since it is a(n unfortunate) side effect of by-design behavior, may or may not get fixed.</p> <p><strong>To prevent output from ... | 526, 23744 | console-output, powershell | <h1>PowerShell output is crossing between functions</h1>
<p>I am writing a PowerShell script in version 5.1 on Windows 10 that gets certain pieces of information about a local system ( and eventually its subnets ) and outputs them into a text file. At first, I had all of the aspects in a single function. I ran into out... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,017 | bash | # PowerShell output is crossing between functions
I am writing a PowerShell script in version 5.1 on Windows 10 that gets certain pieces of information about a local system ( and eventually its subnets ) and outputs them into a text file. At first, I had all of the aspects in a single function. I ran into output issue... | **tl; dr:**
The underlying problem affects both *Windows PowerShell* and *PowerShell (Core) 7+*, up to at least v7.4.x (current as of this writing), and, since it is a(n unfortunate) side effect of by-design behavior, may or may not get fixed.
**To prevent output from appearing *out of order*, force *synchronous* dis... |
43090156 | Replace "." with "_" in file name | 6 | 2017-03-29 09:54:00 | <p>I am using PowerShell to replace pdf file names:</p>
<pre><code>Get-ChildItem -Path C:\All -Filter *.pdf | Rename-Item -NewName { $_.Name.Replace('.','_') }
</code></pre>
<p>It works fine if I replace <code>%20</code> to <code>_</code>, but if we use "test.one.pdf", I need "test_one.pdf" as output, if I use above ... | 10,375 | 5,089,065 | 2019-10-23 06:14:41 | 43,090,430 | 16 | 2017-03-29 10:06:14 | 2,208,505 | 2017-03-29 10:06:14 | https://stackoverflow.com/q/43090156 | https://stackoverflow.com/a/43090430 | <p>Your code will rename <code>name.001.pdf</code> to <code>name_001_pdf</code>, so unless you actually want to remove the extensions of your files you need to replace only within the files name and not the extension.</p>
<pre><code>Get-ChildItem -Path "C:\All" -Filter "*.pdf" | Rename-Item -NewName { $_.BaseName.Repl... | <p>Your code will rename <code>name.001.pdf</code> to <code>name_001_pdf</code>, so unless you actually want to remove the extensions of your files you need to replace only within the files name and not the extension.</p> <pre><code>Get-ChildItem -Path "C:\All" -Filter "*.pdf" | Rename-Item -NewName { $_.BaseName.Repl... | 526 | powershell | <h1>Replace "." with "_" in file name</h1>
<p>I am using PowerShell to replace pdf file names:</p>
<pre><code>Get-ChildItem -Path C:\All -Filter *.pdf | Rename-Item -NewName { $_.Name.Replace('.','_') }
</code></pre>
<p>It works fine if I replace <code>%20</code> to <code>_</code>, but if we use "test.one.pdf", I nee... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,018 | bash | # Replace "." with "_" in file name
I am using PowerShell to replace pdf file names:
```
Get-ChildItem -Path C:\All -Filter *.pdf | Rename-Item -NewName { $_.Name.Replace('.','_') }
```
It works fine if I replace `%20` to `_`, but if we use "test.one.pdf", I need "test_one.pdf" as output, if I use above syntax it re... | Your code will rename `name.001.pdf` to `name_001_pdf`, so unless you actually want to remove the extensions of your files you need to replace only within the files name and not the extension.
```
Get-ChildItem -Path "C:\All" -Filter "*.pdf" | Rename-Item -NewName { $_.BaseName.Replace(".","_") + $_.Extension }
``` |
39496829 | PowerShell Start-Process not setting $lastexitcode | 6 | 2016-09-14 17:57:18 | <p>I have a set of test DLL's that I'm running from a powershell script that calls OpenCover.Console.exe via the <code>Start-Process</code> command.</p>
<p>I have the <code>-returntargetcode</code> flag set</p>
<p>After execution I check <code>$lastexitcode</code> and <code>$?</code>. They return 1 and True respectiv... | 11,931 | 4,355,808 | 2023-01-30 09:47:27 | 39,497,158 | 16 | 2016-09-14 18:21:19 | 3,776,535 | 2019-08-10 07:04:17 | https://stackoverflow.com/q/39496829 | https://stackoverflow.com/a/39497158 | <p>By default, <code>Start-Process</code> is asynchronous, so it doesn't wait for your process to exit. If you want your command-line tool to run synchronously, drop the <code>Start-Process</code> and invoke the command directly. That's the only way it will set <code>$LASTEXITCODE</code>. For example, causing CMD... | <p>By default, <code>Start-Process</code> is asynchronous, so it doesn't wait for your process to exit. If you want your command-line tool to run synchronously, drop the <code>Start-Process</code> and invoke the command directly. That's the only way it will set <code>$LASTEXITCODE</code>. For example, causing CMD... | 526 | powershell | <h1>PowerShell Start-Process not setting $lastexitcode</h1>
<p>I have a set of test DLL's that I'm running from a powershell script that calls OpenCover.Console.exe via the <code>Start-Process</code> command.</p>
<p>I have the <code>-returntargetcode</code> flag set</p>
<p>After execution I check <code>$lastexitcode<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,019 | bash | # PowerShell Start-Process not setting $lastexitcode
I have a set of test DLL's that I'm running from a powershell script that calls OpenCover.Console.exe via the `Start-Process` command.
I have the `-returntargetcode` flag set
After execution I check `$lastexitcode` and `$?`. They return 1 and True respectively all... | By default, `Start-Process` is asynchronous, so it doesn't wait for your process to exit. If you want your command-line tool to run synchronously, drop the `Start-Process` and invoke the command directly. That's the only way it will set `$LASTEXITCODE`. For example, causing CMD.exe to exit with a 2:
```
cmd /c exit 2
... |
37103664 | Passing a variable to a remote host in a bash script with ssh and EOF | 6 | 2016-05-08 18:57:39 | <p>I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct.
The main server is connecting to them via ssh, executing all commands that are in the EOF statement:</p>
<pre><code>#!/bin/bash
# parsing servers
# defining one local variable $VAR
ssh -T -p ... | 10,136 | 6,062,172 | 2016-05-08 20:00:50 | 37,104,048 | 16 | 2016-05-08 19:38:26 | 14,122 | 2016-05-08 19:45:56 | https://stackoverflow.com/q/37103664 | https://stackoverflow.com/a/37104048 | <p>Use <code>printf %q</code> to escape content in an <code>eval</code>-safe form; after doing so, you can pass them on the command line of the remote shell, and retrieve them via <code>$1</code>, <code>$2</code>, etc. within the remote script:</p>
<pre><code># put contents of $VAR into $var_str in a format that a she... | <p>Use <code>printf %q</code> to escape content in an <code>eval</code>-safe form; after doing so, you can pass them on the command line of the remote shell, and retrieve them via <code>$1</code>, <code>$2</code>, etc. within the remote script:</p> <pre><code># put contents of $VAR into $var_str in a format that a she... | 386, 387, 7449, 8192 | bash, heredoc, remote-access, ssh | <h1>Passing a variable to a remote host in a bash script with ssh and EOF</h1>
<p>I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct.
The main server is connecting to them via ssh, executing all commands that are in the EOF statement:</p>
<pre><cod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,020 | bash | # Passing a variable to a remote host in a bash script with ssh and EOF
I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct.
The main server is connecting to them via ssh, executing all commands that are in the EOF statement:
```
#!/bin/bash
# par... | Use `printf %q` to escape content in an `eval`-safe form; after doing so, you can pass them on the command line of the remote shell, and retrieve them via `$1`, `$2`, etc. within the remote script:
```
# put contents of $VAR into $var_str in a format that a shell can interpret
printf -v var_str %q "$VAR"
# ... |
36771670 | How to kill a process with 'kill' combined with 'grep' | 6 | 2016-04-21 13:48:56 | <p>I'd like to kill a process/script with a simple command using. At the moment I do the following</p>
<pre><code>ps -ef | grep myscriptname
kill 123456
</code></pre>
<p>But is there a way to maybe combine the 2 command together so I don't need to look and manually write the pid, something like this <code>kill grep m... | 21,279 | 3,845,362 | 2024-06-04 17:01:42 | 36,771,750 | 16 | 2016-04-21 13:51:58 | 4,323 | 2016-04-21 13:51:58 | https://stackoverflow.com/q/36771670 | https://stackoverflow.com/a/36771750 | <p>You want <code>pkill</code>:</p>
<pre><code>pkill myscriptname
</code></pre>
<p>On some systems there is a similar tool called <code>killall</code>, but be careful because on Solaris it really does kill everything!</p>
<p>Note that there is also <code>pgrep</code> which you can use to replace your <code>ps | grep... | <p>You want <code>pkill</code>:</p> <pre><code>pkill myscriptname </code></pre> <p>On some systems there is a similar tool called <code>killall</code>, but be careful because on Solaris it really does kill everything!</p> <p>Note that there is also <code>pgrep</code> which you can use to replace your <code>ps | grep... | 387, 1271, 5779, 5910 | bash, grep, kill, process | <h1>How to kill a process with 'kill' combined with 'grep'</h1>
<p>I'd like to kill a process/script with a simple command using. At the moment I do the following</p>
<pre><code>ps -ef | grep myscriptname
kill 123456
</code></pre>
<p>But is there a way to maybe combine the 2 command together so I don't need to look a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,021 | bash | # How to kill a process with 'kill' combined with 'grep'
I'd like to kill a process/script with a simple command using. At the moment I do the following
```
ps -ef | grep myscriptname
kill 123456
```
But is there a way to maybe combine the 2 command together so I don't need to look and manually write the pid, someth... | You want `pkill`:
```
pkill myscriptname
```
On some systems there is a similar tool called `killall`, but be careful because on Solaris it really does kill everything!
Note that there is also `pgrep` which you can use to replace your `ps | grep` pipeline:
```
pgrep myscriptname
```
It prints the PID for you, and ... |
33979231 | Status of process on linux | 6 | 2015-11-29 03:52:38 | <p>I have a list of <code>pid</code>'s in the following array</p>
<pre><code>All_Process_Pid
</code></pre>
<p>For each process, I want to check the status of process by using its <code>pid</code>. </p>
<p>More precisely, for each <code>pid</code>, I want to know if its corresponding process is -</p>
<ol>
<li><p>Run... | 20,407 | 5,595,353 | 2015-12-01 09:03:03 | 33,979,279 | 16 | 2015-11-29 04:02:13 | 2,482,571 | 2015-11-29 04:08:46 | https://stackoverflow.com/q/33979231 | https://stackoverflow.com/a/33979279 | <p>First of all, there are more process states than "Running", "Done" and "Stopped", from <strong>man ps</strong>:</p>
<pre><code>PROCESS STATE CODES
Here are the different values that the s, stat and state output
specifiers (header "STAT" or "S") will display to describe the
state of a process:
D... | <p>First of all, there are more process states than "Running", "Done" and "Stopped", from <strong>man ps</strong>:</p> <pre><code>PROCESS STATE CODES Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process: D... | 387, 3300, 5910, 6951 | bash, pid, process, status | <h1>Status of process on linux</h1>
<p>I have a list of <code>pid</code>'s in the following array</p>
<pre><code>All_Process_Pid
</code></pre>
<p>For each process, I want to check the status of process by using its <code>pid</code>. </p>
<p>More precisely, for each <code>pid</code>, I want to know if its correspondi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,022 | bash | # Status of process on linux
I have a list of `pid`'s in the following array
```
All_Process_Pid
```
For each process, I want to check the status of process by using its `pid`.
More precisely, for each `pid`, I want to know if its corresponding process is -
1. Running
2. Done
3. Stopped
How can I do this in bash? | First of all, there are more process states than "Running", "Done" and "Stopped", from **man ps**:
```
PROCESS STATE CODES
Here are the different values that the s, stat and state output
specifiers (header "STAT" or "S") will display to describe the
state of a process:
D uninterruptible sleep (... |
32441841 | How do I uninstall a powershell module from my computer? | 6 | 2015-09-07 15:17:45 | <p>I installed a Powershell module (posh-git) using PS-Get but I am finding that it is quite slow. I want to uninstall it but using <code>Remove-Module posh-git</code> only uninstalls it from my current session but I would like to make this permanent.</p>
| 13,392 | 95,055 | 2015-09-07 15:26:23 | 32,441,955 | 16 | 2015-09-07 15:26:23 | 67,392 | 2015-09-07 15:26:23 | https://stackoverflow.com/q/32441841 | https://stackoverflow.com/a/32441955 | <p>This is an open issue for PS-GET: <a href="https://github.com/psget/psget/issues/164">https://github.com/psget/psget/issues/164</a>:</p>
<blockquote>
<p>This should be a feature.
Nowadays, you have to delete it manually from <code>C:\Users\[yourUser]\Documents\WindowsPowerShell\modules</code> directory.</p>
</b... | <p>This is an open issue for PS-GET: <a href="https://github.com/psget/psget/issues/164">https://github.com/psget/psget/issues/164</a>:</p> <blockquote> <p>This should be a feature. Nowadays, you have to delete it manually from <code>C:\Users\[yourUser]\Documents\WindowsPowerShell\modules</code> directory.</p> </b... | 64, 526 | powershell, windows | <h1>How do I uninstall a powershell module from my computer?</h1>
<p>I installed a Powershell module (posh-git) using PS-Get but I am finding that it is quite slow. I want to uninstall it but using <code>Remove-Module posh-git</code> only uninstalls it from my current session but I would like to make this permanent.</p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,023 | bash | # How do I uninstall a powershell module from my computer?
I installed a Powershell module (posh-git) using PS-Get but I am finding that it is quite slow. I want to uninstall it but using `Remove-Module posh-git` only uninstalls it from my current session but I would like to make this permanent. | This is an open issue for PS-GET: <https://github.com/psget/psget/issues/164>:
> This should be a feature.
> Nowadays, you have to delete it manually from `C:\Users\[yourUser]\Documents\WindowsPowerShell\modules` directory. |
29942892 | how to use shell script in not_if condition | 6 | 2015-04-29 11:50:47 | <p>I want to use shell script output to validate the resource in guard condition.I am using below code still its not working.</p>
<pre><code>bash "stampDisksuccess" do
code <<-EOH
whoami
EOH
user 'root'
not_if {"`sudo sh /home/scripts/getStampedDisk.sh test... | 11,451 | 3,886,612 | 2015-04-29 13:27:44 | 29,944,132 | 16 | 2015-04-29 12:44:20 | 3,627,607 | 2015-04-29 13:27:44 | https://stackoverflow.com/q/29942892 | https://stackoverflow.com/a/29944132 | <p>Let's dissect it:</p>
<pre><code>not_if {"`sudo sh /home/scripts/getStampedDisk.sh test`" == ''}
</code></pre>
<ul>
<li>Not_if ... quite obvious, it's the guard</li>
<li><code>{</code> Block opening</li>
<li><code>"</code>string opening</li>
<li>backticks opening</li>
<li>command</li>
<li>closing backticks and quo... | <p>Let's dissect it:</p> <pre><code>not_if {"`sudo sh /home/scripts/getStampedDisk.sh test`" == ''} </code></pre> <ul> <li>Not_if ... quite obvious, it's the guard</li> <li><code>{</code> Block opening</li> <li><code>"</code>string opening</li> <li>backticks opening</li> <li>command</li> <li>closing backticks and quo... | 387, 8465, 46913 | bash, chef-infra, recipe | <h1>how to use shell script in not_if condition</h1>
<p>I want to use shell script output to validate the resource in guard condition.I am using below code still its not working.</p>
<pre><code>bash "stampDisksuccess" do
code <<-EOH
whoami
EOH
user 'root'
n... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,024 | bash | # how to use shell script in not_if condition
I want to use shell script output to validate the resource in guard condition.I am using below code still its not working.
```
bash "stampDisksuccess" do
code <<-EOH
whoami
EOH
user 'root'
not_if {"`sudo sh /home/scr... | Let's dissect it:
```
not_if {"`sudo sh /home/scripts/getStampedDisk.sh test`" == ''}
```
- Not_if ... quite obvious, it's the guard
- `{` Block opening
- `"`string opening
- backticks opening
- command
- closing backticks and quote
- `==` operator
- `''` constant empty string
- `}` closing block
That's a lot of ope... |
24798423 | xcodebuild fails to build from terminal but succeeded from xcode | 6 | 2014-07-17 08:25:23 | <p>I'm trying to build a framework using xcode 6-beta 3
when compiling it using xcode it works but when compiling it from a terminal with the command:</p>
<pre><code>xcodebuild -project <projName> -scheme <schemeName> -configuration Debug clean build
</code></pre>
<p>I'm getting the following error</p>... | 12,803 | 1,637,386 | 2014-07-22 08:05:41 | 24,881,932 | 16 | 2014-07-22 08:05:41 | 1,637,386 | 2014-07-22 08:05:41 | https://stackoverflow.com/q/24798423 | https://stackoverflow.com/a/24881932 | <p>I have found an answer.<br/>
Since custom frameworks were announced only in iOS 8, <code>-sdk iphonesimulator8.0</code> need to be added to the script, it defines Xcode to build the project only for Ios 8.<br/>
it should look like:<br/></p>
<pre><code>xcodebuild -project <projName> -scheme <schemeName>... | <p>I have found an answer.<br/> Since custom frameworks were announced only in iOS 8, <code>-sdk iphonesimulator8.0</code> need to be added to the script, it defines Xcode to build the project only for Ios 8.<br/> it should look like:<br/></p> <pre><code>xcodebuild -project <projName> -scheme <schemeName>... | 908, 10327, 12892, 104803, 104810 | ios8, sh, xcode, xcode6, xcodebuild | <h1>xcodebuild fails to build from terminal but succeeded from xcode</h1>
<p>I'm trying to build a framework using xcode 6-beta 3
when compiling it using xcode it works but when compiling it from a terminal with the command:</p>
<pre><code>xcodebuild -project <projName> -scheme <schemeName> -configuratio... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,025 | bash | # xcodebuild fails to build from terminal but succeeded from xcode
I'm trying to build a framework using xcode 6-beta 3
when compiling it using xcode it works but when compiling it from a terminal with the command:
```
xcodebuild -project <projName> -scheme <schemeName> -configuration Debug clean build
```
I'm gett... | I have found an answer.
Since custom frameworks were announced only in iOS 8, `-sdk iphonesimulator8.0` need to be added to the script, it defines Xcode to build the project only for Ios 8.
it should look like:
```
xcodebuild -project <projName> -scheme <schemeName> -sdk iphonesimulator8.0 -configuration Debug cle... |
24364305 | Azure: How to check storage account exists in Azure with Get-AzureStorageAccount | 6 | 2014-06-23 11:05:11 | <p>I am building a power shell script to automate the setup of a website environment in Azure. This web uses an account storage. I want to the script not to create the account storage if exists.</p>
<p>I thought that using <code>Get-AzureStorageAccount</code> this way may work but it does not:</p>
<pre><code>Write-Ve... | 14,799 | 224,301 | 2021-06-17 12:30:29 | 24,369,476 | 16 | 2014-06-23 15:15:41 | 2,157,294 | 2014-06-23 15:15:41 | https://stackoverflow.com/q/24364305 | https://stackoverflow.com/a/24369476 | <p>I would suggest using the Test-AzureName cmdlet to determine if it exists. So, something like this.</p>
<pre><code>if (!(Test-AzureName -Storage $Name))
{
Write-Host "Creating Storage Account $Name"
New-AzureStorageAccount -StorageAccountName $Name -Location $Location
}
</code></pre>
<p>You can use Tes... | <p>I would suggest using the Test-AzureName cmdlet to determine if it exists. So, something like this.</p> <pre><code>if (!(Test-AzureName -Storage $Name)) { Write-Host "Creating Storage Account $Name" New-AzureStorageAccount -StorageAccountName $Name -Location $Location } </code></pre> <p>You can use Tes... | 526, 14158, 35808 | azure, azure-storage, powershell | <h1>Azure: How to check storage account exists in Azure with Get-AzureStorageAccount</h1>
<p>I am building a power shell script to automate the setup of a website environment in Azure. This web uses an account storage. I want to the script not to create the account storage if exists.</p>
<p>I thought that using <code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,026 | bash | # Azure: How to check storage account exists in Azure with Get-AzureStorageAccount
I am building a power shell script to automate the setup of a website environment in Azure. This web uses an account storage. I want to the script not to create the account storage if exists.
I thought that using `Get-AzureStorageAccou... | I would suggest using the Test-AzureName cmdlet to determine if it exists. So, something like this.
```
if (!(Test-AzureName -Storage $Name))
{
Write-Host "Creating Storage Account $Name"
New-AzureStorageAccount -StorageAccountName $Name -Location $Location
}
```
You can use Test-AzureName for other servic... |
20895619 | Why can't I echo contents into a new file as sudo? | 6 | 2014-01-03 02:41:09 | <p>I came across this weird problem just now and I can't seem to get to the bottom of it. I'm trying to add a config file to /etc/sudoers.d/ but get permission denied. In the example below, the file "tweedle" doesn't exist and:</p>
<pre><code>drwxr-xr-x 2 root root 4.0K Jan 2 18:27 sudoers.d/
</code></pre>
<p>So... | 4,907 | 814,669 | 2018-12-30 21:20:22 | 20,895,725 | 16 | 2014-01-03 02:53:28 | 827,263 | 2018-12-30 21:20:22 | https://stackoverflow.com/q/20895619 | https://stackoverflow.com/a/20895725 | <p>The <code>echo</code> command is being run as <code>root</code>, but the redirection is done by your shell, so it's executed as the current user, not as <code>root</code>.</p>
<p>The simplest solution is to invoke a root shell to run both the command and the redirection.</p>
<p>Rather than:</p>
<pre><code>sudo ec... | <p>The <code>echo</code> command is being run as <code>root</code>, but the redirection is done by your shell, so it's executed as the current user, not as <code>root</code>.</p> <p>The simplest solution is to invoke a root shell to run both the command and the redirection.</p> <p>Rather than:</p> <pre><code>sudo ec... | 387, 1674, 13824 | bash, echo, sudo | <h1>Why can't I echo contents into a new file as sudo?</h1>
<p>I came across this weird problem just now and I can't seem to get to the bottom of it. I'm trying to add a config file to /etc/sudoers.d/ but get permission denied. In the example below, the file "tweedle" doesn't exist and:</p>
<pre><code>drwxr-xr-x 2 r... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,027 | bash | # Why can't I echo contents into a new file as sudo?
I came across this weird problem just now and I can't seem to get to the bottom of it. I'm trying to add a config file to /etc/sudoers.d/ but get permission denied. In the example below, the file "tweedle" doesn't exist and:
```
drwxr-xr-x 2 root root 4.0K Jan ... | The `echo` command is being run as `root`, but the redirection is done by your shell, so it's executed as the current user, not as `root`.
The simplest solution is to invoke a root shell to run both the command and the redirection.
Rather than:
```
sudo echo line > file
```
try this:
```
sudo sh -c 'echo line > fi... |
20758981 | Self-extracting script in sh shell | 6 | 2013-12-24 10:11:30 | <p>How would I go about making a self extracting archive that can be executed on <code>sh</code>?</p>
<p>The closest I have come to is:</p>
<pre><code>extract_archive () {
printf '<archive_contents>' | tar -C "$extract_dir" -xvf -
}
</code></pre>
<p>Where <code><archive_contents></code> contains a ta... | 14,215 | null | 2024-02-02 20:05:10 | 20,760,267 | 16 | 2013-12-24 11:41:23 | 395,616 | 2013-12-24 11:41:23 | https://stackoverflow.com/q/20758981 | https://stackoverflow.com/a/20760267 | <p>Alternative variant is to use marker for end of shell script and use sed to cut-out shell script itself.</p>
<p>Script <code>selfextract.sh</code>:</p>
<pre><code>#!/bin/bash
sed '0,/^#EOF#$/d' $0 | tar zx; exit 0
#EOF#
</code></pre>
<p>How to use:</p>
<pre><code># create sfx
cat selfextract.sh data.tar.gz >... | <p>Alternative variant is to use marker for end of shell script and use sed to cut-out shell script itself.</p> <p>Script <code>selfextract.sh</code>:</p> <pre><code>#!/bin/bash sed '0,/^#EOF#$/d' $0 | tar zx; exit 0 #EOF# </code></pre> <p>How to use:</p> <pre><code># create sfx cat selfextract.sh data.tar.gz >... | 390, 9783, 10327 | self-extracting, sh, shell | <h1>Self-extracting script in sh shell</h1>
<p>How would I go about making a self extracting archive that can be executed on <code>sh</code>?</p>
<p>The closest I have come to is:</p>
<pre><code>extract_archive () {
printf '<archive_contents>' | tar -C "$extract_dir" -xvf -
}
</code></pre>
<p>Where <code>&... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,028 | bash | # Self-extracting script in sh shell
How would I go about making a self extracting archive that can be executed on `sh`?
The closest I have come to is:
```
extract_archive () {
printf '<archive_contents>' | tar -C "$extract_dir" -xvf -
}
```
Where `<archive_contents>` contains a tarball with null characters, `%... | Alternative variant is to use marker for end of shell script and use sed to cut-out shell script itself.
Script `selfextract.sh`:
```
#!/bin/bash
sed '0,/^#EOF#$/d' $0 | tar zx; exit 0
#EOF#
```
How to use:
```
# create sfx
cat selfextract.sh data.tar.gz >example_sfx.sh
# unpack sfx
bash example_sfx.sh
``` |
19924150 | vagrant supressing non-zero exit staus for shell provisioner | 6 | 2013-11-12 08:22:27 | <p>I'm having a script provisioner in vagrant. My box is ubuntu 64bit Precise. The relevant lines of my script look like this:</p>
<pre><code>sudo bash -c 'echo "deb https://oss.oracle.com/debian/ unstable main non-free" >/etc/apt/sources.list.d/oracle.list'
wget -q https://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O-... | 5,495 | 1,581,069 | 2018-03-09 22:18:33 | 19,924,650 | 16 | 2013-11-12 08:50:05 | 1,458,569 | 2013-11-12 13:22:38 | https://stackoverflow.com/q/19924150 | https://stackoverflow.com/a/19924650 | <p>You can force the error status to <em>zero</em> using <code>; true</code>:</p>
<pre><code>sudo sh -c "apt-get update -qq ; true"
</code></pre>
| <p>You can force the error status to <em>zero</em> using <code>; true</code>:</p> <pre><code>sudo sh -c "apt-get update -qq ; true" </code></pre> | 390, 16113, 66981 | apt-get, shell, vagrant | <h1>vagrant supressing non-zero exit staus for shell provisioner</h1>
<p>I'm having a script provisioner in vagrant. My box is ubuntu 64bit Precise. The relevant lines of my script look like this:</p>
<pre><code>sudo bash -c 'echo "deb https://oss.oracle.com/debian/ unstable main non-free" >/etc/apt/sources.list.d/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,029 | bash | # vagrant supressing non-zero exit staus for shell provisioner
I'm having a script provisioner in vagrant. My box is ubuntu 64bit Precise. The relevant lines of my script look like this:
```
sudo bash -c 'echo "deb https://oss.oracle.com/debian/ unstable main non-free" >/etc/apt/sources.list.d/oracle.list'
wget -q ht... | You can force the error status to *zero* using `; true`:
```
sudo sh -c "apt-get update -qq ; true"
``` |
19224811 | find ip address of my system for a particular interface with shell script (bash) | 6 | 2013-10-07 12:22:24 | <p>I am trying to find ip-address of my own system through a shell script and write into a text thats my script content</p>
<pre><code>#!/bin/bash
wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
eth0ip=$(ip addr | grep inet | grep eth0 | awk -F" " '{print $2}' | sed -e 's/\/.*... | 14,814 | 2,594,972 | 2018-10-23 18:09:01 | 19,225,338 | 16 | 2013-10-07 12:47:17 | 1,745,001 | 2013-10-07 12:47:17 | https://stackoverflow.com/q/19224811 | https://stackoverflow.com/a/19225338 | <p>Let's clean up your code first. You don't need chains of a dozen different commands and pipes when you're already using awk. This:</p>
<pre><code>wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
</code></pre>
<p>can be written simply as this:</p>
<pre><code>wifiip=$(ip addr ... | <p>Let's clean up your code first. You don't need chains of a dozen different commands and pipes when you're already using awk. This:</p> <pre><code>wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//') </code></pre> <p>can be written simply as this:</p> <pre><code>wifiip=$(ip addr ... | 58, 387, 390, 990, 5282 | awk, bash, linux, sed, shell | <h1>find ip address of my system for a particular interface with shell script (bash)</h1>
<p>I am trying to find ip-address of my own system through a shell script and write into a text thats my script content</p>
<pre><code>#!/bin/bash
wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,030 | bash | # find ip address of my system for a particular interface with shell script (bash)
I am trying to find ip-address of my own system through a shell script and write into a text thats my script content
```
#!/bin/bash
wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
eth0ip=$(ip ... | Let's clean up your code first. You don't need chains of a dozen different commands and pipes when you're already using awk. This:
```
wifiip=$(ip addr | grep inet | grep wlan0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
```
can be written simply as this:
```
wifiip=$(ip addr | awk '/inet/ && /wlan0/{sub(/\/.*$/,"... |
18516048 | Why is my boolean of value 0 returning true? | 6 | 2013-08-29 16:14:19 | <p>I've been working on some PowerShell scripts and found something a little odd.
I have a script that accepts 4 mandatory parameters: two strings and two Booleans.</p>
<p><code>.\[scriptname] [string1] [string2] [bool1] [bool2]</code></p>
<p>This works fine, and I've checked that they are all being passed correctly.... | 9,879 | 2,618,717 | 2013-09-02 23:10:03 | 18,516,573 | 16 | 2013-08-29 16:42:31 | 775,544 | 2013-09-02 23:10:03 | https://stackoverflow.com/q/18516048 | https://stackoverflow.com/a/18516573 | <p><a href="http://blogs.msdn.com/b/powershell/archive/2006/12/24/boolean-values-and-operators.aspx">This blog</a> by Jeffrey Snover offers some insight on the behavior of booleans in Powershell. Below is an excerpt, where he creates a simple function "test" to return true or false depending on the input parameter:</p... | <p><a href="http://blogs.msdn.com/b/powershell/archive/2006/12/24/boolean-values-and-operators.aspx">This blog</a> by Jeffrey Snover offers some insight on the behavior of booleans in Powershell. Below is an excerpt, where he creates a simple function "test" to return true or false depending on the input parameter:</p... | 1, 360, 526, 2848, 73157 | .net, boolean, parameters, powershell, powershell-3.0 | <h1>Why is my boolean of value 0 returning true?</h1>
<p>I've been working on some PowerShell scripts and found something a little odd.
I have a script that accepts 4 mandatory parameters: two strings and two Booleans.</p>
<p><code>.\[scriptname] [string1] [string2] [bool1] [bool2]</code></p>
<p>This works fine, and ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,031 | bash | # Why is my boolean of value 0 returning true?
I've been working on some PowerShell scripts and found something a little odd.
I have a script that accepts 4 mandatory parameters: two strings and two Booleans.
`.\[scriptname] [string1] [string2] [bool1] [bool2]`
This works fine, and I've checked that they are all bei... | [This blog](http://blogs.msdn.com/b/powershell/archive/2006/12/24/boolean-values-and-operators.aspx) by Jeffrey Snover offers some insight on the behavior of booleans in Powershell. Below is an excerpt, where he creates a simple function "test" to return true or false depending on the input parameter:
```
PS> test "0"... |
17261296 | Write to file descriptor 3 without writing to disk? | 6 | 2013-06-23 13:41:24 | <p>Is there a way to interact with file descriptors without having to open a file on disk?</p>
<p>This won't work without a file first being assigned to fd3:</p>
<pre><code>echo a >&3
</code></pre>
| 4,298 | 1,762,276 | 2016-06-22 14:02:55 | 17,262,352 | 16 | 2013-06-23 15:34:38 | 7,552 | 2013-06-23 15:34:38 | https://stackoverflow.com/q/17261296 | https://stackoverflow.com/a/17262352 | <p>Depends on what you want to do. Suppose you want to write strings at your leisure and print them reversed. set up a file descriptor redirecting into a process substitution waiting for stdin:</p>
<pre><code>$ exec 3> >(rev)
$ echo hello world >&3
dlrow olleh
</code></pre>
<p>When you're done with it, y... | <p>Depends on what you want to do. Suppose you want to write strings at your leisure and print them reversed. set up a file descriptor redirecting into a process substitution waiting for stdin:</p> <pre><code>$ exec 3> >(rev) $ echo hello world >&3 dlrow olleh </code></pre> <p>When you're done with it, y... | 387, 390, 7604 | bash, file-descriptor, shell | <h1>Write to file descriptor 3 without writing to disk?</h1>
<p>Is there a way to interact with file descriptors without having to open a file on disk?</p>
<p>This won't work without a file first being assigned to fd3:</p>
<pre><code>echo a >&3
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,032 | bash | # Write to file descriptor 3 without writing to disk?
Is there a way to interact with file descriptors without having to open a file on disk?
This won't work without a file first being assigned to fd3:
```
echo a >&3
``` | Depends on what you want to do. Suppose you want to write strings at your leisure and print them reversed. set up a file descriptor redirecting into a process substitution waiting for stdin:
```
$ exec 3> >(rev)
$ echo hello world >&3
dlrow olleh
```
When you're done with it, you can close the file descriptor
```
$ ... |
17056187 | Generating a comma-separated sequence of numbers based on input in Bash | 6 | 2013-06-12 01:04:20 | <p>I've found more than few things on here to help me as I'm learning to code in Bash and they all come close but not quite.</p>
<p>I need to take an input of a positive integer and print out on a single line down to one, all separated by commas, without a comma at the end of the last variable.</p>
<p>This is what I ... | 11,554 | 2,476,606 | 2013-06-12 02:01:51 | 17,056,225 | 16 | 2013-06-12 01:10:16 | 1,030,675 | 2013-06-12 01:10:16 | https://stackoverflow.com/q/17056187 | https://stackoverflow.com/a/17056225 | <p>Use <code>seq</code> with the <code>-s</code> option:</p>
<pre><code>seq -s, $counter -1 1
</code></pre>
| <p>Use <code>seq</code> with the <code>-s</code> option:</p> <pre><code>seq -s, $counter -1 1 </code></pre> | 387, 390, 531 | bash, scripting, shell | <h1>Generating a comma-separated sequence of numbers based on input in Bash</h1>
<p>I've found more than few things on here to help me as I'm learning to code in Bash and they all come close but not quite.</p>
<p>I need to take an input of a positive integer and print out on a single line down to one, all separated by... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,033 | bash | # Generating a comma-separated sequence of numbers based on input in Bash
I've found more than few things on here to help me as I'm learning to code in Bash and they all come close but not quite.
I need to take an input of a positive integer and print out on a single line down to one, all separated by commas, without... | Use `seq` with the `-s` option:
```
seq -s, $counter -1 1
``` |
16946905 | Differences between [] and () in an "if" condition | 6 | 2013-06-05 18:07:19 | <p>Could someone explain me or point me out some document where the differences between "if () ..." and "if [] ..." can be clarified please?</p>
| 8,845 | 1,315,787 | 2013-06-05 18:11:22 | 16,946,973 | 16 | 2013-06-05 18:11:18 | 1,204,143 | 2013-06-05 18:11:18 | https://stackoverflow.com/q/16946905 | https://stackoverflow.com/a/16946973 | <p><code>if</code> simply takes an ordinary shell command as an argument, and evaluates the exit code of the command. For example, you can do</p>
<pre><code>if grep pattern file; then ...; fi
</code></pre>
<p><code>()</code> in bash executes the contents in a subshell, so you can specify basically any command in the ... | <p><code>if</code> simply takes an ordinary shell command as an argument, and evaluates the exit code of the command. For example, you can do</p> <pre><code>if grep pattern file; then ...; fi </code></pre> <p><code>()</code> in bash executes the contents in a subshell, so you can specify basically any command in the ... | 387, 390 | bash, shell | <h1>Differences between [] and () in an "if" condition</h1>
<p>Could someone explain me or point me out some document where the differences between "if () ..." and "if [] ..." can be clarified please?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,034 | bash | # Differences between [] and () in an "if" condition
Could someone explain me or point me out some document where the differences between "if () ..." and "if [] ..." can be clarified please? | `if` simply takes an ordinary shell command as an argument, and evaluates the exit code of the command. For example, you can do
```
if grep pattern file; then ...; fi
```
`()` in bash executes the contents in a subshell, so you can specify basically any command in the subshell.
`[]` in bash is a shell command (techn... |
16844446 | Copy multiple files using PowerShell | 6 | 2013-05-30 19:32:42 | <p>I am currently learning how to use PowerShell. I was wondering if it would be possible for someone to tell me how to copy multiple text files from multiple sub-directories using the command line portion of PowerShell. I know how to do this in regular CMD and it looks something like this:</p>
<pre><code>for /f "deli... | 24,659 | 1,480,714 | 2021-11-07 17:15:58 | 16,844,618 | 16 | 2013-05-30 19:44:02 | 1,480,714 | 2013-05-30 19:44:02 | https://stackoverflow.com/q/16844446 | https://stackoverflow.com/a/16844618 | <p>I was actually able to figure it out. This is how i did it:</p>
<pre><code>get-childitem -path "SOURCE\PATH" -filter *.txt -recurse | copy-item -destination "DESTINATION\PATH"
</code></pre>
<p>Thanks anyway!</p>
| <p>I was actually able to figure it out. This is how i did it:</p> <pre><code>get-childitem -path "SOURCE\PATH" -filter *.txt -recurse | copy-item -destination "DESTINATION\PATH" </code></pre> <p>Thanks anyway!</p> | 526 | powershell | <h1>Copy multiple files using PowerShell</h1>
<p>I am currently learning how to use PowerShell. I was wondering if it would be possible for someone to tell me how to copy multiple text files from multiple sub-directories using the command line portion of PowerShell. I know how to do this in regular CMD and it looks som... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,035 | bash | # Copy multiple files using PowerShell
I am currently learning how to use PowerShell. I was wondering if it would be possible for someone to tell me how to copy multiple text files from multiple sub-directories using the command line portion of PowerShell. I know how to do this in regular CMD and it looks something li... | I was actually able to figure it out. This is how i did it:
```
get-childitem -path "SOURCE\PATH" -filter *.txt -recurse | copy-item -destination "DESTINATION\PATH"
```
Thanks anyway! |
15557206 | sed replace in-line a specific column number value at a specific line number | 6 | 2013-03-21 20:17:14 | <p>I have a 5 columns csv file (space separated) like this :</p>
<pre><code>username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 20130320 disabled 20130321 enabled
username4 20130310 disabled 20130310 disabled
</code></pre>
<p>I'am trying to change the value of the 4th co... | 42,518 | 2,196,728 | 2013-03-22 11:36:51 | 15,557,267 | 16 | 2013-03-21 20:20:15 | 1,066,031 | 2013-03-21 20:31:33 | https://stackoverflow.com/q/15557206 | https://stackoverflow.com/a/15557267 | <p>Here is one way:</p>
<pre><code>$ sed '/^username4/{s/ [^ ]*/ anything/3}' file
username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 20130320 disabled 20130321 enabled
username4 20130310 disabled anything disabled
# store changes back to the file
$ sed -i '/^username4... | <p>Here is one way:</p> <pre><code>$ sed '/^username4/{s/ [^ ]*/ anything/3}' file username1 20130310 enabled 20130310 enabled username2 20130310 enabled 20130321 disabled username3 20130320 disabled 20130321 enabled username4 20130310 disabled anything disabled # store changes back to the file $ sed -i '/^username4... | 58, 390, 5282 | linux, sed, shell | <h1>sed replace in-line a specific column number value at a specific line number</h1>
<p>I have a 5 columns csv file (space separated) like this :</p>
<pre><code>username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 20130320 disabled 20130321 enabled
username4 20130310 disa... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,036 | bash | # sed replace in-line a specific column number value at a specific line number
I have a 5 columns csv file (space separated) like this :
```
username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 20130320 disabled 20130321 enabled
username4 20130310 disabled 20130310 disabl... | Here is one way:
```
$ sed '/^username4/{s/ [^ ]*/ anything/3}' file
username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 20130320 disabled 20130321 enabled
username4 20130310 disabled anything disabled
# store changes back to the file
$ sed -i '/^username4/{s/ [^ ]*/ an... |
15458805 | How to exit from ssh session created from bash script? | 6 | 2013-03-17 08:12:55 | <p>I have the following bash script <code>test.sh</code></p>
<pre><code>#!/bin/bash
ssh -o "StrictHostKeyChecking no" user@$1
#do some stuff
exit
</code></pre>
<p>However if I run this script <code>./test.sh</code> I need to enter <strong>ctrl+d</strong> to get out of the ssh session and it appears as if the <code>ex... | 17,258 | 784,637 | 2015-07-23 20:38:05 | 15,458,837 | 16 | 2013-03-17 08:17:17 | 841,108 | 2013-03-17 08:34:41 | https://stackoverflow.com/q/15458805 | https://stackoverflow.com/a/15458837 | <p>You may want to code a <a href="http://www.tldp.org/LDP/abs/html/here-docs.html" rel="noreferrer">here document</a></p>
<pre><code>#!/bin/bash
ssh -o "StrictHostKeyChecking no" user@$1 << ENDHERE
here do some remote stuff
also here
exit
ENDHERE
</code></pre>
<p>If you code <code><<-ENDHERE</co... | <p>You may want to code a <a href="http://www.tldp.org/LDP/abs/html/here-docs.html" rel="noreferrer">here document</a></p> <pre><code>#!/bin/bash ssh -o "StrictHostKeyChecking no" user@$1 << ENDHERE here do some remote stuff also here exit ENDHERE </code></pre> <p>If you code <code><<-ENDHERE</co... | 58, 386, 387 | bash, linux, ssh | <h1>How to exit from ssh session created from bash script?</h1>
<p>I have the following bash script <code>test.sh</code></p>
<pre><code>#!/bin/bash
ssh -o "StrictHostKeyChecking no" user@$1
#do some stuff
exit
</code></pre>
<p>However if I run this script <code>./test.sh</code> I need to enter <strong>ctrl+d</strong>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,037 | bash | # How to exit from ssh session created from bash script?
I have the following bash script `test.sh`
```
#!/bin/bash
ssh -o "StrictHostKeyChecking no" user@$1
#do some stuff
exit
```
However if I run this script `./test.sh` I need to enter **ctrl+d** to get out of the ssh session and it appears as if the `exit` comma... | You may want to code a [here document](http://www.tldp.org/LDP/abs/html/here-docs.html)
```
#!/bin/bash
ssh -o "StrictHostKeyChecking no" user@$1 << ENDHERE
here do some remote stuff
also here
exit
ENDHERE
```
If you code `<<-ENDHERE` the initial spaces or tabs in each line of the here document are suppresse... |
13437513 | Executing Node.js file from outside the folder breaks file path | 6 | 2012-11-18 04:31:55 | <p>I have a Node.js file called "server.js".</p>
<p>In the script, I am opening some files using something like:</p>
<pre><code>var certPem = fs.readFileSync('cert_and_key_dev.pem', encoding='ascii');
</code></pre>
<p>Using the bash shell, if I cd into the directory where the server.js is, and run the command:</p>
... | 6,394 | 860,967 | 2012-11-18 05:03:17 | 13,437,639 | 16 | 2012-11-18 04:58:35 | 1,777,444 | 2012-11-18 04:58:35 | https://stackoverflow.com/q/13437513 | https://stackoverflow.com/a/13437639 | <p>Put this at the beginning of your script.</p>
<pre><code>process.chdir(__dirname);
</code></pre>
<p>This will change the process's working directory into the directory path of the file (<code>__dirname</code>) being executed.</p>
<p>For more information on the function read <a href="http://nodejs.org/api/process.... | <p>Put this at the beginning of your script.</p> <pre><code>process.chdir(__dirname); </code></pre> <p>This will change the process's working directory into the directory path of the file (<code>__dirname</code>) being executed.</p> <p>For more information on the function read <a href="http://nodejs.org/api/process.... | 387, 724, 46426 | bash, file-io, node.js | <h1>Executing Node.js file from outside the folder breaks file path</h1>
<p>I have a Node.js file called "server.js".</p>
<p>In the script, I am opening some files using something like:</p>
<pre><code>var certPem = fs.readFileSync('cert_and_key_dev.pem', encoding='ascii');
</code></pre>
<p>Using the bash shell, if I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,038 | bash | # Executing Node.js file from outside the folder breaks file path
I have a Node.js file called "server.js".
In the script, I am opening some files using something like:
```
var certPem = fs.readFileSync('cert_and_key_dev.pem', encoding='ascii');
```
Using the bash shell, if I cd into the directory where the server.... | Put this at the beginning of your script.
```
process.chdir(__dirname);
```
This will change the process's working directory into the directory path of the file (`__dirname`) being executed.
For more information on the function read [this](http://nodejs.org/api/process.html#process_process_chdir_directory). |
12969479 | Using regex in find command for multiple file types | 6 | 2012-10-19 07:35:11 | <p>I am currently using </p>
<pre><code>find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ; \
find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ;
</code></pre>
<p>to search for a string in all files ending with .c, .C, .h, .H, .cc and .CC listed in all subdirectories. But since this includes two commands this feels... | 22,004 | 1,331,727 | 2019-06-27 14:17:35 | 12,969,670 | 16 | 2012-10-19 07:47:50 | 732,284 | 2019-06-27 14:17:35 | https://stackoverflow.com/q/12969479 | https://stackoverflow.com/a/12969670 | <p>You can use the boolean OR argument:</p>
<pre><code>find . -name '*.[ch]' -o -name '*.[CH]' -o -name '*.cc' -o -name '*.CC'
</code></pre>
<p>The above searches the current directory and all sub-directories for files that end in:</p>
<ul>
<li><code>.c</code>, <code>.h</code> OR</li>
<li><code>.C</code>, <code>.H</... | <p>You can use the boolean OR argument:</p> <pre><code>find . -name '*.[ch]' -o -name '*.[CH]' -o -name '*.cc' -o -name '*.CC' </code></pre> <p>The above searches the current directory and all sub-directories for files that end in:</p> <ul> <li><code>.c</code>, <code>.h</code> OR</li> <li><code>.C</code>, <code>.H</... | 18, 387, 1280 | bash, file-extension, regex | <h1>Using regex in find command for multiple file types</h1>
<p>I am currently using </p>
<pre><code>find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ; \
find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ;
</code></pre>
<p>to search for a string in all files ending with .c, .C, .h, .H, .cc and .CC listed in all su... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,039 | bash | # Using regex in find command for multiple file types
I am currently using
```
find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ; \
find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ;
```
to search for a string in all files ending with .c, .C, .h, .H, .cc and .CC listed in all subdirectories. But since this include... | You can use the boolean OR argument:
```
find . -name '*.[ch]' -o -name '*.[CH]' -o -name '*.cc' -o -name '*.CC'
```
The above searches the current directory and all sub-directories for files that end in:
- `.c`, `.h` OR
- `.C`, `.H` OR
- `.cc` OR
- `.CC`. |
10054968 | inserting variables within my awk statement | 6 | 2012-04-07 13:39:05 | <p>Here is a snippet of my awk statement..I'm trying to insert these 2 variables in the statement but they are not getting evaluated. Can someone point me in the right direction?</p>
<pre><code>ZONE=`date "+%Z %Y"`
DAY=`date "+%a"`
awk '{if (NR<2) {print "["$1, $2, $3"]"}}'
</code></pre>
<p>I'm trying this:</p>
... | 9,730 | 1,317,336 | 2018-05-09 15:40:32 | 10,055,737 | 16 | 2012-04-07 15:31:16 | 1,315,563 | 2012-04-07 15:31:16 | https://stackoverflow.com/q/10054968 | https://stackoverflow.com/a/10055737 | <p>You can use -v option:</p>
<pre><code>ZONE=`date "+%Z %Y"`
DAY=`date "+%a"`
awk -vzone="$ZONE" -vday="$DAY" 'BEGIN { print zone, day }'
</code></pre>
| <p>You can use -v option:</p> <pre><code>ZONE=`date "+%Z %Y"` DAY=`date "+%a"` awk -vzone="$ZONE" -vday="$DAY" 'BEGIN { print zone, day }' </code></pre> | 387, 990 | awk, bash | <h1>inserting variables within my awk statement</h1>
<p>Here is a snippet of my awk statement..I'm trying to insert these 2 variables in the statement but they are not getting evaluated. Can someone point me in the right direction?</p>
<pre><code>ZONE=`date "+%Z %Y"`
DAY=`date "+%a"`
awk '{if (NR<2) {print "["$1, ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,040 | bash | # inserting variables within my awk statement
Here is a snippet of my awk statement..I'm trying to insert these 2 variables in the statement but they are not getting evaluated. Can someone point me in the right direction?
```
ZONE=`date "+%Z %Y"`
DAY=`date "+%a"`
awk '{if (NR<2) {print "["$1, $2, $3"]"}}'
```
I'm t... | You can use -v option:
```
ZONE=`date "+%Z %Y"`
DAY=`date "+%a"`
awk -vzone="$ZONE" -vday="$DAY" 'BEGIN { print zone, day }'
``` |
9722273 | Using netsh on PowerShell fails with error: The parameter is incorrect | 6 | 2012-03-15 14:52:36 | <p>I've been trying to run the following command on PowerShell:</p>
<pre><code> netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}
</code></pre>
<p>The problem is, it returns <code>"The parameter is incorrect"</code> every time. I've check the cert hash number, and... | 12,506 | 1,250,033 | 2018-05-03 14:19:49 | 9,739,104 | 16 | 2012-03-16 14:28:41 | 1,250,033 | 2013-08-15 15:58:49 | https://stackoverflow.com/q/9722273 | https://stackoverflow.com/a/9739104 | <p>I finally learned what the problem was: although in PowerShell you can execute <code>cmd</code> commands natively, the parsing of the command slightly changes, and in this case it disrupted the interpretation of the <code>appid</code> parameter (those curly brackets!).</p>
<p>To solve it, I just enclosed the bracke... | <p>I finally learned what the problem was: although in PowerShell you can execute <code>cmd</code> commands natively, the parsing of the command slightly changes, and in this case it disrupted the interpretation of the <code>appid</code> parameter (those curly brackets!).</p> <p>To solve it, I just enclosed the bracke... | 526, 641, 2631, 14423, 42672 | cmd, netsh, powershell, ssl, ssl-certificate | <h1>Using netsh on PowerShell fails with error: The parameter is incorrect</h1>
<p>I've been trying to run the following command on PowerShell:</p>
<pre><code> netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}
</code></pre>
<p>The problem is, it returns <code>"The... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,041 | bash | # Using netsh on PowerShell fails with error: The parameter is incorrect
I've been trying to run the following command on PowerShell:
```
netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}
```
The problem is, it returns `"The parameter is incorrect"` every time. I've check t... | I finally learned what the problem was: although in PowerShell you can execute `cmd` commands natively, the parsing of the command slightly changes, and in this case it disrupted the interpretation of the `appid` parameter (those curly brackets!).
To solve it, I just enclosed the brackets (`{}`) and `<random guid>` in... |
8518518 | replace names of all directiories and files in PS | 6 | 2011-12-15 10:23:21 | <p>I want to replace all space characters into "_" in names of all subfolders and files.
Unfortunately when I type:</p>
<pre><code>Get-ChildItem -recurse -name | ForEach-Object { Rename-Item $_ $_.replace(" ","_") }
</code></pre>
<p>Error message:</p>
<blockquote>
<p>Rename-Item : Source and destination path must ... | 14,486 | 939,399 | 2020-06-03 02:29:26 | 8,520,172 | 16 | 2011-12-15 12:32:05 | 9,833 | 2011-12-15 12:32:05 | https://stackoverflow.com/q/8518518 | https://stackoverflow.com/a/8520172 | <p>Don't use the Name switch, it outputs only the names of the objects, not their full path. Try this:</p>
<pre><code>Get-ChildItem -Recurse | `
Where-Object {$_.Name -match ' '} | `
Rename-Item -NewName { $_.Name -replace ' ','_' }
</code></pre>
| <p>Don't use the Name switch, it outputs only the names of the objects, not their full path. Try this:</p> <pre><code>Get-ChildItem -Recurse | ` Where-Object {$_.Name -match ' '} | ` Rename-Item -NewName { $_.Name -replace ' ','_' } </code></pre> | 526, 9802 | powershell, renaming | <h1>replace names of all directiories and files in PS</h1>
<p>I want to replace all space characters into "_" in names of all subfolders and files.
Unfortunately when I type:</p>
<pre><code>Get-ChildItem -recurse -name | ForEach-Object { Rename-Item $_ $_.replace(" ","_") }
</code></pre>
<p>Error message:</p>
<block... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,042 | bash | # replace names of all directiories and files in PS
I want to replace all space characters into "_" in names of all subfolders and files.
Unfortunately when I type:
```
Get-ChildItem -recurse -name | ForEach-Object { Rename-Item $_ $_.replace(" ","_") }
```
Error message:
> Rename-Item : Source and destination path... | Don't use the Name switch, it outputs only the names of the objects, not their full path. Try this:
```
Get-ChildItem -Recurse | `
Where-Object {$_.Name -match ' '} | `
Rename-Item -NewName { $_.Name -replace ' ','_' }
``` |
6546241 | Linux command for physical memory, getting the value only | 6 | 2011-07-01 09:41:42 | <p>In Linux <code>cat /proc/meminfo | grep MemTotal</code> gets back <code>MemTotal: 12298824 kB</code></p>
<p>I want only the numbers here</p>
<p>so i wrote <code>cat /proc/meminfo | grep MemTotal | cut -d':' -f2</code> which gave me <code>12298824 kB</code></p>
<p>I only want the numbers here, can anyone help ... | 11,598 | 707,414 | 2012-10-17 22:51:26 | 6,546,314 | 16 | 2011-07-01 09:46:42 | 571,189 | 2011-07-01 10:28:55 | https://stackoverflow.com/q/6546241 | https://stackoverflow.com/a/6546314 | <p>Use <strong>awk</strong>:</p>
<pre><code>cat /proc/meminfo | grep MemTotal | awk '{print $2}'
</code></pre>
<hr>
<p>From <a href="https://stackoverflow.com/users/25148/lars-wirzenius">@Lars Wirzenius's</a> comment(No <code>cat</code> and No <code>grep</code>):</p>
<pre><code>awk '/MemTotal/ { print $2 }' /proc/m... | <p>Use <strong>awk</strong>:</p> <pre><code>cat /proc/meminfo | grep MemTotal | awk '{print $2}' </code></pre> <hr> <p>From <a href="https://stackoverflow.com/users/25148/lars-wirzenius">@Lars Wirzenius's</a> comment(No <code>cat</code> and No <code>grep</code>):</p> <pre><code>awk '/MemTotal/ { print $2 }' /proc/m... | 58, 390 | linux, shell | <h1>Linux command for physical memory, getting the value only</h1>
<p>In Linux <code>cat /proc/meminfo | grep MemTotal</code> gets back <code>MemTotal: 12298824 kB</code></p>
<p>I want only the numbers here</p>
<p>so i wrote <code>cat /proc/meminfo | grep MemTotal | cut -d':' -f2</code> which gave me <code>122988... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,043 | bash | # Linux command for physical memory, getting the value only
In Linux `cat /proc/meminfo | grep MemTotal` gets back `MemTotal: 12298824 kB`
I want only the numbers here
so i wrote `cat /proc/meminfo | grep MemTotal | cut -d':' -f2` which gave me `12298824 kB`
I only want the numbers here, can anyone help me?
Note: ... | Use **awk**:
```
cat /proc/meminfo | grep MemTotal | awk '{print $2}'
```
---
From [@Lars Wirzenius's](https://stackoverflow.com/users/25148/lars-wirzenius) comment(No `cat` and No `grep`):
```
awk '/MemTotal/ { print $2 }' /proc/meminfo
``` |
3633557 | How to count number of non empty lines in a file using sed? | 6 | 2010-09-03 06:46:13 | <p>how to find how many lines I have in file by sed
(need to ignore spaces and empty lines)</p>
<p>for example</p>
<p>if I have file with 139 lines (line can include only one character)
then sed should return 139</p>
<p>lidia</p>
| 10,947 | 396,841 | 2013-12-13 07:25:15 | 3,633,763 | 16 | 2010-09-03 07:23:21 | 387,076 | 2010-09-03 07:23:21 | https://stackoverflow.com/q/3633557 | https://stackoverflow.com/a/3633763 | <p>This is a job for <code>grep</code>, not <code>sed</code>:</p>
<pre><code><myfile grep -c '[^[:space:]]'
</code></pre>
| <p>This is a job for <code>grep</code>, not <code>sed</code>:</p> <pre><code><myfile grep -c '[^[:space:]]' </code></pre> | 387, 390, 5282 | bash, sed, shell | <h1>How to count number of non empty lines in a file using sed?</h1>
<p>how to find how many lines I have in file by sed
(need to ignore spaces and empty lines)</p>
<p>for example</p>
<p>if I have file with 139 lines (line can include only one character)
then sed should return 139</p>
<p>lidia</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,044 | bash | # How to count number of non empty lines in a file using sed?
how to find how many lines I have in file by sed
(need to ignore spaces and empty lines)
for example
if I have file with 139 lines (line can include only one character)
then sed should return 139
lidia | This is a job for `grep`, not `sed`:
```
<myfile grep -c '[^[:space:]]'
``` |
2150323 | Is it possible to cout to terminal while redirecting cout to outfile? | 6 | 2010-01-27 21:20:35 | <p>I'm running a program and redirecting <code>cout</code> to an outfile, like so: </p>
<pre><code>./program < infile.in > outfile.o
</code></pre>
<p>I want to be able to read in an option ('-h' or '--help') from the command line and output a help message to the terminal. Is there a way I can do this but sti... | 3,630 | 260,359 | 2010-03-11 14:26:23 | 2,150,353 | 16 | 2010-01-27 21:23:55 | 229,044 | 2010-01-27 21:32:49 | https://stackoverflow.com/q/2150323 | https://stackoverflow.com/a/2150353 | <p>You should use cerr to output your help message to STDERR, which is not included in your redirection to outfile.o.</p>
<p>Given <code>./program < infile.in > outfile.o</code>:</p>
<pre><code>cout << "This writes to STDOUT, and gets redirected to outfile.";
cerr << "This doesn't get redirected, an... | <p>You should use cerr to output your help message to STDERR, which is not included in your redirection to outfile.o.</p> <p>Given <code>./program < infile.in > outfile.o</code>:</p> <pre><code>cout << "This writes to STDOUT, and gets redirected to outfile."; cerr << "This doesn't get redirected, an... | 10, 387, 390, 4147, 31901 | bash, c++, cout, http-redirect, shell | <h1>Is it possible to cout to terminal while redirecting cout to outfile?</h1>
<p>I'm running a program and redirecting <code>cout</code> to an outfile, like so: </p>
<pre><code>./program < infile.in > outfile.o
</code></pre>
<p>I want to be able to read in an option ('-h' or '--help') from the command line ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,045 | bash | # Is it possible to cout to terminal while redirecting cout to outfile?
I'm running a program and redirecting `cout` to an outfile, like so:
```
./program < infile.in > outfile.o
```
I want to be able to read in an option ('-h' or '--help') from the command line and output a help message to the terminal. Is there a ... | You should use cerr to output your help message to STDERR, which is not included in your redirection to outfile.o.
Given `./program < infile.in > outfile.o`:
```
cout << "This writes to STDOUT, and gets redirected to outfile.";
cerr << "This doesn't get redirected, and displays on screen.";
```
If, later on, you wan... |
34796888 | How to open google chrome from terminal? | 117 | 2016-01-14 18:19:13 | <p>I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case. </p>
<p>I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.</p>
<ul>
<li>How do I open google chrome from the terminal?<... | 267,438 | 5,724,610 | 2022-10-31 01:56:49 | 34,797,507 | 15 | 2016-01-14 18:54:42 | 5,724,610 | 2019-07-31 19:59:09 | https://stackoverflow.com/q/34796888 | https://stackoverflow.com/a/34797507 | <p>UPDATE: </p>
<ol>
<li>How do I open google chrome from the terminal?</li>
</ol>
<p>Thank you for the quick response. <code>open http://localhost/</code> opened that domain in my default browser on my Mac.</p>
<ol start="2">
<li>What alias could I use to open the current git project in the browser?</li>
</ol>
<p>... | <p>UPDATE: </p> <ol> <li>How do I open google chrome from the terminal?</li> </ol> <p>Thank you for the quick response. <code>open http://localhost/</code> opened that domain in my default browser on my Mac.</p> <ol start="2"> <li>What alias could I use to open the current git project in the browser?</li> </ol> <p>... | 119, 387, 391, 1448, 3600 | alias, bash, git, google-chrome, terminal | <h1>How to open google chrome from terminal?</h1>
<p>I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case. </p>
<p>I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.</p>
<ul>
<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,046 | bash | # How to open google chrome from terminal?
I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case.
I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.
- How do I open google chro... | UPDATE:
1. How do I open google chrome from the terminal?
Thank you for the quick response. `open http://localhost/` opened that domain in my default browser on my Mac.
2. What alias could I use to open the current git project in the browser?
I ended up writing this alias, did the trick:
```
# Opens git file's loc... |
2063995 | PowerShell "echo on" | 103 | 2010-01-14 12:28:39 | <p>This is a duplicate of <a href="https://serverfault.com/questions/102098/powershell-script-showing-commands-run">https://serverfault.com/questions/102098/powershell-script-showing-commands-run</a>. I thought it would be more appropriate to ask this question here.</p>
<p>I am playing around with PowerShell scripts ... | 71,174 | 177,333 | 2025-06-25 02:27:05 | 2,065,077 | 15 | 2010-01-14 15:16:09 | 153,982 | 2010-01-14 18:10:19 | https://stackoverflow.com/q/2063995 | https://stackoverflow.com/a/2065077 | <p>Start-Transcript doesn't catch any exe output. That's a show stopper for me. I hate to say it but the best way I've found to do this is:</p>
<pre><code>cmd /c powershell.exe -file c:\users\hillr\foo.ps1 > foo.log
</code></pre>
<p>This captures everything AFAICT.</p>
| <p>Start-Transcript doesn't catch any exe output. That's a show stopper for me. I hate to say it but the best way I've found to do this is:</p> <pre><code>cmd /c powershell.exe -file c:\users\hillr\foo.ps1 > foo.log </code></pre> <p>This captures everything AFAICT.</p> | 277, 526, 1796, 13824, 29634 | command, debugging, echo, powershell, script-debugging | <h1>PowerShell "echo on"</h1>
<p>This is a duplicate of <a href="https://serverfault.com/questions/102098/powershell-script-showing-commands-run">https://serverfault.com/questions/102098/powershell-script-showing-commands-run</a>. I thought it would be more appropriate to ask this question here.</p>
<p>I am playing a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,047 | bash | # PowerShell "echo on"
This is a duplicate of <https://serverfault.com/questions/102098/powershell-script-showing-commands-run>. I thought it would be more appropriate to ask this question here.
I am playing around with PowerShell scripts and they're working great. However, I am wondering if there is any way to also ... | Start-Transcript doesn't catch any exe output. That's a show stopper for me. I hate to say it but the best way I've found to do this is:
```
cmd /c powershell.exe -file c:\users\hillr\foo.ps1 > foo.log
```
This captures everything AFAICT. |
12426659 | How to extract last part of string in bash? | 79 | 2012-09-14 14:35:17 | <p>I have this variable:</p>
<pre><code>A="Some variable has value abc.123"
</code></pre>
<p>I need to extract this value i.e <code>abc.123</code>. Is this possible in bash?</p>
| 122,255 | 710,818 | 2023-11-15 11:36:50 | 12,426,692 | 15 | 2012-09-14 14:37:35 | 28,169 | 2022-04-16 19:18:47 | https://stackoverflow.com/q/12426659 | https://stackoverflow.com/a/12426692 | <p>How do you know where the value begins? If it's always the 5th and 6th words, you could use e.g.:</p>
<pre><code>B=$(echo "$A" | cut -d ' ' -f 5-)
</code></pre>
<p>This uses the <code>cut</code> command to slice out part of the line, using a simple space as the word delimiter.</p>
| <p>How do you know where the value begins? If it's always the 5th and 6th words, you could use e.g.:</p> <pre><code>B=$(echo "$A" | cut -d ' ' -f 5-) </code></pre> <p>This uses the <code>cut</code> command to slice out part of the line, using a simple space as the word delimiter.</p> | 139, 387, 990 | awk, bash, string | <h1>How to extract last part of string in bash?</h1>
<p>I have this variable:</p>
<pre><code>A="Some variable has value abc.123"
</code></pre>
<p>I need to extract this value i.e <code>abc.123</code>. Is this possible in bash?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,048 | bash | # How to extract last part of string in bash?
I have this variable:
```
A="Some variable has value abc.123"
```
I need to extract this value i.e `abc.123`. Is this possible in bash? | How do you know where the value begins? If it's always the 5th and 6th words, you could use e.g.:
```
B=$(echo "$A" | cut -d ' ' -f 5-)
```
This uses the `cut` command to slice out part of the line, using a simple space as the word delimiter. |
10448160 | How do I set $? or the return code in Bash? | 71 | 2012-05-04 11:41:44 | <p>I want to set a return value once so it goes into the while loop:</p>
<pre><code>#!/bin/bash
while [ $? -eq 1 ]
do
#do something until it returns 0
done
</code></pre>
<p>In order to get this working I need to set <code>$? = 1</code> at the beginning, but that doesn't work.</p>
| 122,471 | 906,738 | 2024-04-19 10:24:19 | 10,448,206 | 15 | 2012-05-04 11:44:25 | 1,100,552 | 2012-05-04 11:44:25 | https://stackoverflow.com/q/10448160 | https://stackoverflow.com/a/10448206 | <pre><code>#!/bin/bash
RC=1
while [ $RC -eq 1 ]
do
#do something until it returns 0
RC=$?
done
</code></pre>
| <pre><code>#!/bin/bash RC=1 while [ $RC -eq 1 ] do #do something until it returns 0 RC=$? done </code></pre> | 379, 387, 9206, 10021 | bash, error-handling, exit-code, return-value | <h1>How do I set $? or the return code in Bash?</h1>
<p>I want to set a return value once so it goes into the while loop:</p>
<pre><code>#!/bin/bash
while [ $? -eq 1 ]
do
#do something until it returns 0
done
</code></pre>
<p>In order to get this working I need to set <code>$? = 1</code> at the beginning, but tha... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,049 | bash | # How do I set $? or the return code in Bash?
I want to set a return value once so it goes into the while loop:
```
#!/bin/bash
while [ $? -eq 1 ]
do
#do something until it returns 0
done
```
In order to get this working I need to set `$? = 1` at the beginning, but that doesn't work. | ```
#!/bin/bash
RC=1
while [ $RC -eq 1 ]
do
#do something until it returns 0
RC=$?
done
``` |
9202495 | Have Find print just the filenames, not full paths | 64 | 2012-02-08 22:27:41 | <p>I'm using the find command in a ksh script, and I'm trying to retrieve just the filenames, rather than the full path. As in, I want it to return text.exe, not <code>//severname/dir1/dir2/text.exe</code>.</p>
<p>How would I go about getting that? To clarify, I know the directory the files are in, I am just grabbing t... | 80,201 | 835,523 | 2023-07-21 21:59:41 | 9,202,564 | 15 | 2012-02-08 22:33:00 | 164,835 | 2015-09-03 16:59:01 | https://stackoverflow.com/q/9202495 | https://stackoverflow.com/a/9202564 | <p>you can do it with:</p>
<pre><code>find ..... |sed 's#.*/##'
</code></pre>
<p>however does it really make sense? if there are two files with same filename but located in different directories, how can you distinguish them?</p>
<p>e.g.</p>
<pre><code>you are in /foo
/foo/a.txt
/foo/bar/a.txt
</code></pre>
<p><s... | <p>you can do it with:</p> <pre><code>find ..... |sed 's#.*/##' </code></pre> <p>however does it really make sense? if there are two files with same filename but located in different directories, how can you distinguish them?</p> <p>e.g.</p> <pre><code>you are in /foo /foo/a.txt /foo/bar/a.txt </code></pre> <p><s... | 390, 1964 | ksh, shell | <h1>Have Find print just the filenames, not full paths</h1>
<p>I'm using the find command in a ksh script, and I'm trying to retrieve just the filenames, rather than the full path. As in, I want it to return text.exe, not <code>//severname/dir1/dir2/text.exe</code>.</p>
<p>How would I go about getting that? To clarify,... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,050 | bash | # Have Find print just the filenames, not full paths
I'm using the find command in a ksh script, and I'm trying to retrieve just the filenames, rather than the full path. As in, I want it to return text.exe, not `//severname/dir1/dir2/text.exe`.
How would I go about getting that? To clarify, I know the directory the ... | you can do it with:
```
find ..... |sed 's#.*/##'
```
however does it really make sense? if there are two files with same filename but located in different directories, how can you distinguish them?
e.g.
```
you are in /foo
/foo/a.txt
/foo/bar/a.txt
```
**EDIT**
edit the answer to gain some better text formattin... |
4145667 | How to override the path of PHP to use the MAMP path? | 60 | 2010-11-10 14:47:16 | <p>After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory
....) I now have to use MAMP but each time I have to type the path </p>
<pre><code>Applications/MAMP/bin/php5.3/bin/php to do command line.
</code></pre>
<p><strong>How to ju... | 146,680 | 318,071 | 2022-02-13 22:39:46 | 52,618,229 | 15 | 2018-10-03 00:48:11 | 529,403 | 2019-03-01 00:46:37 | https://stackoverflow.com/q/4145667 | https://stackoverflow.com/a/52618229 | <p>Everytime you save MAMP config (PHP section), it saves the current version of PHP on <code>~/.profile</code> file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)</p>
<p>However, you n... | <p>Everytime you save MAMP config (PHP section), it saves the current version of PHP on <code>~/.profile</code> file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)</p> <p>However, you n... | 5, 369, 390, 2699, 6268 | macos, mamp, path, php, shell | <h1>How to override the path of PHP to use the MAMP path?</h1>
<p>After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory
....) I now have to use MAMP but each time I have to type the path </p>
<pre><code>Applications/MAMP/bin/php5.3/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,051 | bash | # How to override the path of PHP to use the MAMP path?
After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory
....) I now have to use MAMP but each time I have to type the path
```
Applications/MAMP/bin/php5.3/bin/php to do command... | Everytime you save MAMP config (PHP section), it saves the current version of PHP on `~/.profile` file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)
However, you need to refresh your t... |
6475252 | Bash script, watch folder, execute command | 56 | 2011-06-25 01:39:26 | <p>I am trying to create a bash script with 2 parameters: </p>
<ul>
<li><strong>a directory</strong> </li>
<li><strong>a command</strong>. </li>
</ul>
<p>I want to watch the directory parameter for changes: when something has been changed the script should execute the command. </p>
<p>I'm running MacOS, not Linux; a... | 68,156 | 340,688 | 2024-09-25 09:03:52 | 27,829,420 | 15 | 2015-01-07 22:01:45 | 340,688 | 2017-07-21 18:00:55 | https://stackoverflow.com/q/6475252 | https://stackoverflow.com/a/27829420 | <p>Here's an example of watching a folder for changes and running a the less compiler when one is updated. As a prereq you need <a href="https://nodejs.org/en/download/" rel="noreferrer"><code>npm</code></a> and these the module <a href="https://www.npmjs.com/package/onchange" rel="noreferrer">onchange</a>. The node co... | <p>Here's an example of watching a folder for changes and running a the less compiler when one is updated. As a prereq you need <a href="https://nodejs.org/en/download/" rel="noreferrer"><code>npm</code></a> and these the module <a href="https://www.npmjs.com/package/onchange" rel="noreferrer">onchange</a>. The node co... | 369, 387, 390 | bash, macos, shell | <h1>Bash script, watch folder, execute command</h1>
<p>I am trying to create a bash script with 2 parameters: </p>
<ul>
<li><strong>a directory</strong> </li>
<li><strong>a command</strong>. </li>
</ul>
<p>I want to watch the directory parameter for changes: when something has been changed the script should execute t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,052 | bash | # Bash script, watch folder, execute command
I am trying to create a bash script with 2 parameters:
- **a directory**
- **a command**.
I want to watch the directory parameter for changes: when something has been changed the script should execute the command.
I'm running MacOS, not Linux; any pointers or external re... | Here's an example of watching a folder for changes and running a the less compiler when one is updated. As a prereq you need [`npm`](https://nodejs.org/en/download/) and these the module [onchange](https://www.npmjs.com/package/onchange). The node community has a whole bunch of different watch commands (like onchange) ... |
4267400 | Colour highlighting output based on regex in shell | 55 | 2010-11-24 13:42:50 | <p>I'd like to know if I can colour highlight the output of a shell command that matches certain strings. </p>
<p>For example, if I run myCommand, with the output below:</p>
<pre><code>> myCommand
DEBUG foo bar
INFO bla bla
ERROR yak yak
</code></pre>
<p>I'd like all lines matching ^ERROR\s.* to be highlighted re... | 41,749 | 60,956 | 2019-05-14 19:09:08 | 4,272,561 | 15 | 2010-11-24 23:41:35 | 387,076 | 2010-11-24 23:41:35 | https://stackoverflow.com/q/4267400 | https://stackoverflow.com/a/4272561 | <p>If you want to enable this globally, you'll want a terminal feature, not a process that you pipe output into, because a pipe would be disruptive to some command (two problems are that stdout and stderr would appear out-of-order and buffered, and that some commands just behave differently when outputting to a termina... | <p>If you want to enable this globally, you'll want a terminal feature, not a process that you pipe output into, because a pipe would be disruptive to some command (two problems are that stdout and stderr would appear out-of-order and buffered, and that some commands just behave differently when outputting to a termina... | 58, 387, 390 | bash, linux, shell | <h1>Colour highlighting output based on regex in shell</h1>
<p>I'd like to know if I can colour highlight the output of a shell command that matches certain strings. </p>
<p>For example, if I run myCommand, with the output below:</p>
<pre><code>> myCommand
DEBUG foo bar
INFO bla bla
ERROR yak yak
</code></pre>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,053 | bash | # Colour highlighting output based on regex in shell
I'd like to know if I can colour highlight the output of a shell command that matches certain strings.
For example, if I run myCommand, with the output below:
```
> myCommand
DEBUG foo bar
INFO bla bla
ERROR yak yak
```
I'd like all lines matching ^ERROR\s.* to b... | If you want to enable this globally, you'll want a terminal feature, not a process that you pipe output into, because a pipe would be disruptive to some command (two problems are that stdout and stderr would appear out-of-order and buffered, and that some commands just behave differently when outputting to a terminal).... |
3517982 | In a unix shell, how to get yesterday's date into a variable? | 46 | 2010-08-19 01:05:16 | <p>I've got a shell script which does the following to store the current day's date in a variable 'dt':</p>
<pre><code>date "+%a %d/%m/%Y" | read dt
echo ${dt}
</code></pre>
<p>How would i go about getting <em>yesterdays</em> date into a variable?</p>
<p>Basically what i'm trying to achieve is to use grep to pull al... | 142,724 | 59,198 | 2018-04-07 17:49:58 | 3,518,086 | 15 | 2010-08-19 01:34:32 | 14,860 | 2010-08-19 01:34:32 | https://stackoverflow.com/q/3517982 | https://stackoverflow.com/a/3518086 | <p>If you have Perl available (and your <code>date</code> doesn't have nice features like <code>yesterday</code>), you can use:</p>
<pre><code>pax> date
Thu Aug 18 19:29:49 XYZ 2010
pax> dt=$(perl -e 'use POSIX;print strftime "%d/%m/%Y%",localtime time-86400;')
pax> echo $dt
17/08/2010
</code></pre>
| <p>If you have Perl available (and your <code>date</code> doesn't have nice features like <code>yesterday</code>), you can use:</p> <pre><code>pax> date Thu Aug 18 19:29:49 XYZ 2010 pax> dt=$(perl -e 'use POSIX;print strftime "%d/%m/%Y%",localtime time-86400;') pax> echo $dt 17/08/2010 </code></pre> | 34, 390, 1263, 1964, 5920 | datetime, hp-ux, ksh, shell, unix | <h1>In a unix shell, how to get yesterday's date into a variable?</h1>
<p>I've got a shell script which does the following to store the current day's date in a variable 'dt':</p>
<pre><code>date "+%a %d/%m/%Y" | read dt
echo ${dt}
</code></pre>
<p>How would i go about getting <em>yesterdays</em> date into a variable?... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,054 | bash | # In a unix shell, how to get yesterday's date into a variable?
I've got a shell script which does the following to store the current day's date in a variable 'dt':
```
date "+%a %d/%m/%Y" | read dt
echo ${dt}
```
How would i go about getting *yesterdays* date into a variable?
Basically what i'm trying to achieve i... | If you have Perl available (and your `date` doesn't have nice features like `yesterday`), you can use:
```
pax> date
Thu Aug 18 19:29:49 XYZ 2010
pax> dt=$(perl -e 'use POSIX;print strftime "%d/%m/%Y%",localtime time-86400;')
pax> echo $dt
17/08/2010
``` |
54262245 | Having trouble deleting a local branch even after checkout to another branch | 33 | 2019-01-18 22:29:13 | <p>I'm trying to delete my local branch and tried most of the solutions I found on here which is to checkout to another branch and then run <code>git branch -D (or -d) <my_branch></code>. I tried that but I am still getting the same error that states "Cannot delete branch 'my_branch' checked out at 'my_path'</p>
... | 56,459 | 4,363,111 | 2023-11-19 04:22:08 | 54,300,196 | 15 | 2019-01-22 01:56:09 | 4,363,111 | 2019-01-22 01:56:09 | https://stackoverflow.com/q/54262245 | https://stackoverflow.com/a/54300196 | <p>Did a bit more browsing and came across <a href="https://stackoverflow.com/questions/48346607/git-worktree-prune-what-it-does">this answer</a> that uses <code>git worktree prune</code> to remove information on (non-locked) worktrees that no longer exist. This essentially removed my worktree from <code>git worktree l... | <p>Did a bit more browsing and came across <a href="https://stackoverflow.com/questions/48346607/git-worktree-prune-what-it-does">this answer</a> that uses <code>git worktree prune</code> to remove information on (non-locked) worktrees that no longer exist. This essentially removed my worktree from <code>git worktree l... | 119, 1879, 61874 | branch, git, git-bash | <h1>Having trouble deleting a local branch even after checkout to another branch</h1>
<p>I'm trying to delete my local branch and tried most of the solutions I found on here which is to checkout to another branch and then run <code>git branch -D (or -d) <my_branch></code>. I tried that but I am still getting the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,055 | bash | # Having trouble deleting a local branch even after checkout to another branch
I'm trying to delete my local branch and tried most of the solutions I found on here which is to checkout to another branch and then run `git branch -D (or -d) <my_branch>`. I tried that but I am still getting the same error that states "Ca... | Did a bit more browsing and came across [this answer](https://stackoverflow.com/questions/48346607/git-worktree-prune-what-it-does) that uses `git worktree prune` to remove information on (non-locked) worktrees that no longer exist. This essentially removed my worktree from `git worktree list` and then I proceeded to d... |
13094248 | How do I get accented letters to actually work on bash? | 32 | 2012-10-26 20:51:14 | <p>My bash installation on cygwin doesn't handle accented letters properly. I tried adding</p>
<pre><code>set input-meta on # to accept 8-bit characters
set output-meta on # to show 8-bit characters
set convert-meta on # to show it as character, not the octal representation
</code></pre>
<p>to my input rc, but ... | 14,645 | 1,714,385 | 2012-11-23 14:08:09 | 13,530,739 | 15 | 2012-11-23 14:08:09 | 439,427 | 2012-11-23 14:08:09 | https://stackoverflow.com/q/13094248 | https://stackoverflow.com/a/13530739 | <p>To get accented letters on bash via <code>Cygwin</code> using <code>Mintty 1.1.2</code> just do the following:</p>
<ol>
<li>Go to the <strong>menu</strong> (if you don't see any menu, right click on your Terminal).</li>
<li>Click <strong>Options...</strong>.</li>
<li>Click <strong>Text</strong>.</li>
<li>Change the... | <p>To get accented letters on bash via <code>Cygwin</code> using <code>Mintty 1.1.2</code> just do the following:</p> <ol> <li>Go to the <strong>menu</strong> (if you don't see any menu, right click on your Terminal).</li> <li>Click <strong>Options...</strong>.</li> <li>Click <strong>Text</strong>.</li> <li>Change the... | 387, 1731, 24047 | bash, cygwin, non-ascii-characters | <h1>How do I get accented letters to actually work on bash?</h1>
<p>My bash installation on cygwin doesn't handle accented letters properly. I tried adding</p>
<pre><code>set input-meta on # to accept 8-bit characters
set output-meta on # to show 8-bit characters
set convert-meta on # to show it as character, no... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,056 | bash | # How do I get accented letters to actually work on bash?
My bash installation on cygwin doesn't handle accented letters properly. I tried adding
```
set input-meta on # to accept 8-bit characters
set output-meta on # to show 8-bit characters
set convert-meta on # to show it as character, not the octal represen... | To get accented letters on bash via `Cygwin` using `Mintty 1.1.2` just do the following:
1. Go to the **menu** (if you don't see any menu, right click on your Terminal).
2. Click **Options...**.
3. Click **Text**.
4. Change the **Locale** to `C`.
5. Change the **Character set** to `ISO-8859-1 (Western European)`.
![C... |
28038633 | wc -l is NOT counting last of the file if it does not have end of line character | 30 | 2015-01-20 05:53:45 | <p>I need to count all lines of an unix file. The file has 3 lines but <code>wc -l</code> gives only 2 count.</p>
<p>I understand that it is not counting last line because it does not have end of line character</p>
<p>Could any one please tell me how to count that line as well ?</p>
| 11,392 | 975,199 | 2023-11-28 08:05:37 | 28,038,682 | 15 | 2015-01-20 05:59:11 | 548,225 | 2015-01-20 06:17:52 | https://stackoverflow.com/q/28038633 | https://stackoverflow.com/a/28038682 | <p>It is better to have all lines ending with EOL <code>\n</code> in Unix files. You can do:</p>
<pre><code>{ cat file; echo ''; } | wc -l
</code></pre>
<p>Or this awk:</p>
<pre><code>awk 'END{print NR}' file
</code></pre>
| <p>It is better to have all lines ending with EOL <code>\n</code> in Unix files. You can do:</p> <pre><code>{ cat file; echo ''; } | wc -l </code></pre> <p>Or this awk:</p> <pre><code>awk 'END{print NR}' file </code></pre> | 34, 58, 387, 390 | bash, linux, shell, unix | <h1>wc -l is NOT counting last of the file if it does not have end of line character</h1>
<p>I need to count all lines of an unix file. The file has 3 lines but <code>wc -l</code> gives only 2 count.</p>
<p>I understand that it is not counting last line because it does not have end of line character</p>
<p>Could any ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,057 | bash | # wc -l is NOT counting last of the file if it does not have end of line character
I need to count all lines of an unix file. The file has 3 lines but `wc -l` gives only 2 count.
I understand that it is not counting last line because it does not have end of line character
Could any one please tell me how to count th... | It is better to have all lines ending with EOL `\n` in Unix files. You can do:
```
{ cat file; echo ''; } | wc -l
```
Or this awk:
```
awk 'END{print NR}' file
``` |
13814413 | How to auto login in MySQL from a shell script? | 30 | 2012-12-11 05:50:48 | <p>I have a MySQL server with an user with a password. I want to execute some SQL queries in shell scripts without specifying the password like this:</p>
<p><code>config.sh</code>:</p>
<pre><code>MYSQL_ROOT="root"
MYSQL_PASS="password"
</code></pre>
<p><code>mysql.sh</code>:</p>
<pre><code>source config.sh
mysql -u... | 75,750 | 1,249,053 | 2020-01-14 16:34:39 | 13,814,511 | 15 | 2012-12-11 06:00:27 | 586,880 | 2017-06-07 20:41:43 | https://stackoverflow.com/q/13814413 | https://stackoverflow.com/a/13814511 | <p>Try this:</p>
<pre><code>if [ $MYSQL_PASS ]
then
mysql -u "$MYSQL_ROOT" -p"$MYSQL_PASS" -e "SHOW DATABASES"
else
mysql -u "$MYSQL_ROOT" -e "SHOW DATABASES"
fi
</code></pre>
| <p>Try this:</p> <pre><code>if [ $MYSQL_PASS ] then mysql -u "$MYSQL_ROOT" -p"$MYSQL_PASS" -e "SHOW DATABASES" else mysql -u "$MYSQL_ROOT" -e "SHOW DATABASES" fi </code></pre> | 21, 387, 390 | bash, mysql, shell | <h1>How to auto login in MySQL from a shell script?</h1>
<p>I have a MySQL server with an user with a password. I want to execute some SQL queries in shell scripts without specifying the password like this:</p>
<p><code>config.sh</code>:</p>
<pre><code>MYSQL_ROOT="root"
MYSQL_PASS="password"
</code></pre>
<p><code>m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,058 | bash | # How to auto login in MySQL from a shell script?
I have a MySQL server with an user with a password. I want to execute some SQL queries in shell scripts without specifying the password like this:
`config.sh`:
```
MYSQL_ROOT="root"
MYSQL_PASS="password"
```
`mysql.sh`:
```
source config.sh
mysql -u$MYSQL_ROOT -p$M... | Try this:
```
if [ $MYSQL_PASS ]
then
mysql -u "$MYSQL_ROOT" -p"$MYSQL_PASS" -e "SHOW DATABASES"
else
mysql -u "$MYSQL_ROOT" -e "SHOW DATABASES"
fi
``` |
762927 | Powershell ps1 file "is not recognized as a cmdlet, function, operable program, or script file." | 30 | 2009-04-18 04:55:32 | <p>I made a Powershell function just now and saved it to a ps1 file.
However, when I try to execute it from within powershell, it won't run.</p>
<p>I've allready changed to the settings for running unsigned code by entering this command:</p>
<pre><code>set-executionpolicy remotesigned
</code></pre>
<p>The function i... | 118,583 | 80,907 | 2023-10-17 23:05:06 | 762,931 | 15 | 2009-04-18 05:00:50 | 92,209 | 2009-04-18 05:14:45 | https://stackoverflow.com/q/762927 | https://stackoverflow.com/a/762931 | <p>This is a typical error across many platforms where your environment path does not include your current directory. so when you execute your script (or command or program etc), your runtime environment looks everywhere except your current/working directory.</p>
<p>Try </p>
<pre><code>PS> .\listAllPaths.ps1 c:\ *... | <p>This is a typical error across many platforms where your environment path does not include your current directory. so when you execute your script (or command or program etc), your runtime environment looks everywhere except your current/working directory.</p> <p>Try </p> <pre><code>PS> .\listAllPaths.ps1 c:\ *... | 526 | powershell | <h1>Powershell ps1 file "is not recognized as a cmdlet, function, operable program, or script file."</h1>
<p>I made a Powershell function just now and saved it to a ps1 file.
However, when I try to execute it from within powershell, it won't run.</p>
<p>I've allready changed to the settings for running unsigned code b... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,059 | bash | # Powershell ps1 file "is not recognized as a cmdlet, function, operable program, or script file."
I made a Powershell function just now and saved it to a ps1 file.
However, when I try to execute it from within powershell, it won't run.
I've allready changed to the settings for running unsigned code by entering this ... | This is a typical error across many platforms where your environment path does not include your current directory. so when you execute your script (or command or program etc), your runtime environment looks everywhere except your current/working directory.
Try
```
PS> .\listAllPaths.ps1 c:\ *.pdf testingPDF.txt
```
... |
4241985 | Calling generic static method in PowerShell | 26 | 2010-11-22 03:19:40 | <p>How do you call a generic static method of a custom class in Powershell?</p>
<p>Given the following class:</p>
<pre><code>public class Sample
{
public static string MyMethod<T>( string anArgument )
{
return string.Format( "Generic type is {0} with argument {1}", typeof(T), anArgument );
}... | 18,426 | 25,702 | 2015-01-29 00:54:46 | 4,244,013 | 15 | 2010-11-22 09:37:35 | 293,099 | 2013-11-19 20:40:34 | https://stackoverflow.com/q/4241985 | https://stackoverflow.com/a/4244013 | <p>You can call generic methods, refer to the post <a href="http://www.leeholmes.com/blog/2007/06/19/invoking-generic-methods-on-non-generic-classes-in-powershell/" rel="noreferrer">Invoking Generic Methods on Non-Generic Classes in PowerShell</a>.</p>
<p>This is not straightforward, you need to use <code>MakeGenericM... | <p>You can call generic methods, refer to the post <a href="http://www.leeholmes.com/blog/2007/06/19/invoking-generic-methods-on-non-generic-classes-in-powershell/" rel="noreferrer">Invoking Generic Methods on Non-Generic Classes in PowerShell</a>.</p> <p>This is not straightforward, you need to use <code>MakeGenericM... | 9, 148, 526, 24067 | c#, generics, powershell, powershell-2.0 | <h1>Calling generic static method in PowerShell</h1>
<p>How do you call a generic static method of a custom class in Powershell?</p>
<p>Given the following class:</p>
<pre><code>public class Sample
{
public static string MyMethod<T>( string anArgument )
{
return string.Format( "Generic type is {... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,060 | bash | # Calling generic static method in PowerShell
How do you call a generic static method of a custom class in Powershell?
Given the following class:
```
public class Sample
{
public static string MyMethod<T>( string anArgument )
{
return string.Format( "Generic type is {0} with argument {1}", typeof(T),... | You can call generic methods, refer to the post [Invoking Generic Methods on Non-Generic Classes in PowerShell](http://www.leeholmes.com/blog/2007/06/19/invoking-generic-methods-on-non-generic-classes-in-powershell/).
This is not straightforward, you need to use `MakeGenericMethod` function. It is pretty simple if met... |
3499699 | How do you call msdeploy from powershell when the parameters have spaces? | 26 | 2010-08-17 06:00:49 | <p>I'm running into a problem with spaces in my parameters that I try to send into msdeploy from a powershell script.</p>
<p>There are a number of other related articles but none of them solve the problem.
<br><a href="http://forums.iis.net/p/1163820/1929826.aspx#1929826" rel="nofollow noreferrer">Problems Using Power... | 23,621 | 92,364 | 2019-11-30 23:51:16 | 3,503,027 | 15 | 2010-08-17 13:41:46 | 2,495 | 2010-08-17 13:41:46 | https://stackoverflow.com/q/3499699 | https://stackoverflow.com/a/3503027 | <p>Using the technique from <a href="https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes/1674950#1674950">Keith's answer</a> to <a href="https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes">How to run... | <p>Using the technique from <a href="https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes/1674950#1674950">Keith's answer</a> to <a href="https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes">How to run... | 215, 526, 25779 | iis, msdeploy, powershell | <h1>How do you call msdeploy from powershell when the parameters have spaces?</h1>
<p>I'm running into a problem with spaces in my parameters that I try to send into msdeploy from a powershell script.</p>
<p>There are a number of other related articles but none of them solve the problem.
<br><a href="http://forums.iis... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,061 | bash | # How do you call msdeploy from powershell when the parameters have spaces?
I'm running into a problem with spaces in my parameters that I try to send into msdeploy from a powershell script.
There are a number of other related articles but none of them solve the problem.
[Problems Using Power Shell And MSDeploy.](... | Using the technique from [Keith's answer](https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-with-parameters-with-spaces-and-quotes/1674950#1674950) to [How to run exe in powershell with parameters with spaces and quotes](https://stackoverflow.com/questions/1673967/how-to-run-exe-in-powershell-wit... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.