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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
29855489 | String replacement (to lowercase) in Bash 4.3.33 - bad substitution error | 13 | 2015-04-24 19:03:09 | <p>I'm trying to change uppercase to lowercase using string replacement in bash, but i'm getting a bad substitution error. </p>
<pre><code>> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output is hey
</code></pre>
<p>I've seen similar questions to this, but in most cases it w... | 13,766 | 2,636,151 | 2015-05-22 17:30:35 | 30,402,648 | 11 | 2015-05-22 17:30:35 | 1,524,545 | 2015-05-22 17:30:35 | https://stackoverflow.com/q/29855489 | https://stackoverflow.com/a/30402648 | <p>Looks like the bash that is first in <code>PATH</code> happens to be 4.3.33, but the bash you're running in the interactive session is probably an older version. Run <code>echo "$BASH_VERSION"</code> to check.</p>
<p>If the above is correct, run </p>
<pre><code>type bash
</code></pre>
<p>to see the path of the ne... | <p>Looks like the bash that is first in <code>PATH</code> happens to be 4.3.33, but the bash you're running in the interactive session is probably an older version. Run <code>echo "$BASH_VERSION"</code> to check.</p> <p>If the above is correct, run </p> <pre><code>type bash </code></pre> <p>to see the path of the ne... | 139, 387, 2498, 9848, 16107 | bash, lowercase, replace, string, substitution | <h1>String replacement (to lowercase) in Bash 4.3.33 - bad substitution error</h1>
<p>I'm trying to change uppercase to lowercase using string replacement in bash, but i'm getting a bad substitution error. </p>
<pre><code>> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,275 | bash | # String replacement (to lowercase) in Bash 4.3.33 - bad substitution error
I'm trying to change uppercase to lowercase using string replacement in bash, but i'm getting a bad substitution error.
```
> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output is hey
```
I've seen similar q... | Looks like the bash that is first in `PATH` happens to be 4.3.33, but the bash you're running in the interactive session is probably an older version. Run `echo "$BASH_VERSION"` to check.
If the above is correct, run
```
type bash
```
to see the path of the newer version, probably something like `/opt/local/bin/bash... |
27360145 | Understanding scope of functions in powershell workflow | 13 | 2014-12-08 14:26:59 | <p>Copy and paste the following into a new Powershell ISE script and hit F5:</p>
<pre><code>workflow workflow1{
"in workflow1"
func1
}
function func1 {
"in func1"
func2
}
function func2 {
"in func2"
}
workflow1
</code></pre>
<p>the error I get is:</p>
<blockquote>
<p>The term 'func2' is not rec... | 9,426 | 201,657 | 2016-01-31 12:33:06 | 27,362,808 | 11 | 2014-12-08 16:51:12 | 2,627,148 | 2014-12-08 16:51:12 | https://stackoverflow.com/q/27360145 | https://stackoverflow.com/a/27362808 | <p>Think of Workflows as short-sighted programming elements.</p>
<p>A Workflow cannot see beyond what's immediately available in the scope.
So nested functions are not working with a single workflow, because it cannot see them.</p>
<p>The fix is to nest workflows along with nested functions. Such as this:</p>
<pre><... | <p>Think of Workflows as short-sighted programming elements.</p> <p>A Workflow cannot see beyond what's immediately available in the scope. So nested functions are not working with a single workflow, because it cannot see them.</p> <p>The fix is to nest workflows along with nested functions. Such as this:</p> <pre><... | 526, 103401 | powershell, powershell-workflow | <h1>Understanding scope of functions in powershell workflow</h1>
<p>Copy and paste the following into a new Powershell ISE script and hit F5:</p>
<pre><code>workflow workflow1{
"in workflow1"
func1
}
function func1 {
"in func1"
func2
}
function func2 {
"in func2"
}
workflow1
</code></pre>
<p>the e... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,276 | bash | # Understanding scope of functions in powershell workflow
Copy and paste the following into a new Powershell ISE script and hit F5:
```
workflow workflow1{
"in workflow1"
func1
}
function func1 {
"in func1"
func2
}
function func2 {
"in func2"
}
workflow1
```
the error I get is:
> The term 'func2... | Think of Workflows as short-sighted programming elements.
A Workflow cannot see beyond what's immediately available in the scope.
So nested functions are not working with a single workflow, because it cannot see them.
The fix is to nest workflows along with nested functions. Such as this:
```
workflow workflow1
{
... |
22764288 | Windows PowerShell give password in command Enter-PSSession | 13 | 2014-03-31 14:29:03 | <p>I am writing a project where I run a PowerShell script and create a new PSSession as follows:</p>
<pre><code>PowerShell.exe -Command enter-pssession myUser -credential userName
</code></pre>
<p>When I run this, it opens a dialog to prompt the user for a password. However, I would prefer for the user to be able to ... | 39,114 | 2,661,085 | 2022-11-15 07:30:19 | 22,764,365 | 11 | 2014-03-31 14:32:02 | 567,435 | 2014-03-31 14:32:02 | https://stackoverflow.com/q/22764288 | https://stackoverflow.com/a/22764365 | <p>Yes, you can provide password while opening a <code>new-pssession</code> like below</p>
<pre><code>$passwd = convertto-securestring -AsPlainText -Force -String <your password>
$cred = new-object -typename System.Management.Automation.PSCredential
-argumentlist "Domain\User",$passwd
$session = new-pssession... | <p>Yes, you can provide password while opening a <code>new-pssession</code> like below</p> <pre><code>$passwd = convertto-securestring -AsPlainText -Force -String <your password> $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Domain\User",$passwd $session = new-pssession... | 64, 526 | powershell, windows | <h1>Windows PowerShell give password in command Enter-PSSession</h1>
<p>I am writing a project where I run a PowerShell script and create a new PSSession as follows:</p>
<pre><code>PowerShell.exe -Command enter-pssession myUser -credential userName
</code></pre>
<p>When I run this, it opens a dialog to prompt the use... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,277 | bash | # Windows PowerShell give password in command Enter-PSSession
I am writing a project where I run a PowerShell script and create a new PSSession as follows:
```
PowerShell.exe -Command enter-pssession myUser -credential userName
```
When I run this, it opens a dialog to prompt the user for a password. However, I woul... | Yes, you can provide password while opening a `new-pssession` like below
```
$passwd = convertto-securestring -AsPlainText -Force -String <your password>
$cred = new-object -typename System.Management.Automation.PSCredential
-argumentlist "Domain\User",$passwd
$session = new-pssession -computername <computer> -cred... |
22394904 | PowerShell Test-Path returns False when testing a network share | 13 | 2014-03-14 02:14:26 | <p>The user has appropriate permissions to read the share, and the share maps properly.
This issue seems to happen only in PowerShell v2.0.</p>
<p>If I remove all mapped drives, remap one drive, and run Test-Path:</p>
<pre><code>net use /delete * /y
net use G: \\somefileserver\share
Test-Path G:\
</code></pre>
<p>Te... | 72,979 | 3,418,092 | 2023-07-13 19:59:41 | 22,394,973 | 11 | 2014-03-14 02:22:09 | null | 2014-03-14 02:22:09 | https://stackoverflow.com/q/22394904 | https://stackoverflow.com/a/22394973 | <p>If the <code>Test-Path</code> cmdlet is truly buggy, then I'd suggest using the <code>Exists()</code> method on the <code>System.IO.Directory</code> .NET class.</p>
<pre><code>[System.IO.Directory]::Exists('G:\'); # This returns $true for me
</code></pre>
| <p>If the <code>Test-Path</code> cmdlet is truly buggy, then I'd suggest using the <code>Exists()</code> method on the <code>System.IO.Directory</code> .NET class.</p> <pre><code>[System.IO.Directory]::Exists('G:\'); # This returns $true for me </code></pre> | 526, 10269, 24067, 28183 | net-use, network-drive, powershell, powershell-2.0 | <h1>PowerShell Test-Path returns False when testing a network share</h1>
<p>The user has appropriate permissions to read the share, and the share maps properly.
This issue seems to happen only in PowerShell v2.0.</p>
<p>If I remove all mapped drives, remap one drive, and run Test-Path:</p>
<pre><code>net use /delete ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,278 | bash | # PowerShell Test-Path returns False when testing a network share
The user has appropriate permissions to read the share, and the share maps properly.
This issue seems to happen only in PowerShell v2.0.
If I remove all mapped drives, remap one drive, and run Test-Path:
```
net use /delete * /y
net use G: \\somefiles... | If the `Test-Path` cmdlet is truly buggy, then I'd suggest using the `Exists()` method on the `System.IO.Directory` .NET class.
```
[System.IO.Directory]::Exists('G:\'); # This returns $true for me
``` |
22277892 | Wait for Network Interface Before Executing Command | 13 | 2014-03-09 03:05:17 | <p>I have a couple ideas on how I would achieve this. Not sure how I would script it.</p>
<p>Method 1: (probably the better choice)</p>
<p>Create a loop that pings a server until reply is received then execute command
if no reply is received in X amount of time/runs continue script.</p>
<p>Method 2: </p>
<p>Check i... | 11,093 | 2,602,638 | 2024-03-28 15:47:58 | 22,277,977 | 11 | 2014-03-09 03:20:45 | 3,352,674 | 2014-03-09 04:14:17 | https://stackoverflow.com/q/22277892 | https://stackoverflow.com/a/22277977 | <p>This command should wait until it can contact google or it has tried 50 times:</p>
<pre><code>for i in {1..50}; do ping -c1 www.google.com &> /dev/null && break; done
</code></pre>
<p>The <code>for i in {1..50}</code> loops 50 times or until a <code>break</code> is executed. The <code>ping -c1 www.g... | <p>This command should wait until it can contact google or it has tried 50 times:</p> <pre><code>for i in {1..50}; do ping -c1 www.google.com &> /dev/null && break; done </code></pre> <p>The <code>for i in {1..50}</code> loops 50 times or until a <code>break</code> is executed. The <code>ping -c1 www.g... | 387, 390, 794 | bash, network-programming, shell | <h1>Wait for Network Interface Before Executing Command</h1>
<p>I have a couple ideas on how I would achieve this. Not sure how I would script it.</p>
<p>Method 1: (probably the better choice)</p>
<p>Create a loop that pings a server until reply is received then execute command
if no reply is received in X amount of ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,279 | bash | # Wait for Network Interface Before Executing Command
I have a couple ideas on how I would achieve this. Not sure how I would script it.
Method 1: (probably the better choice)
Create a loop that pings a server until reply is received then execute command
if no reply is received in X amount of time/runs continue scri... | This command should wait until it can contact google or it has tried 50 times:
```
for i in {1..50}; do ping -c1 www.google.com &> /dev/null && break; done
```
The `for i in {1..50}` loops 50 times or until a `break` is executed. The `ping -c1 www.google.com` sends 1 ping packet to google, and `&> /dev/null` redirect... |
17972783 | How to use the Copy-Item cmdlet correctly to copy piped files | 13 | 2013-07-31 14:11:08 | <p>I am building a small script which should copy all <code>.zip</code> files to a special folder called <code>F:\tempzip</code>.</p>
<p>I tried it with <a href="https://technet.microsoft.com/en-us/library/hh849793.aspx" rel="nofollow noreferrer">Copy-Item</a> cmdlet, but I didn't manage to do it. The script should c... | 50,249 | 2,508,411 | 2019-07-01 21:34:10 | 17,973,401 | 11 | 2013-07-31 14:37:53 | 2,215,029 | 2016-07-15 10:30:44 | https://stackoverflow.com/q/17972783 | https://stackoverflow.com/a/17973401 | <p>When piping items to <code>copy-item</code> you need to tell it that <code>"F:\tempzip"</code> is the destination path.</p>
<pre><code>| Copy-Item -Destination F:\tempzip
</code></pre>
<p>You can also cutout piping to the <code>where</code> operator by using <code>Get-ChildItem</code>'s parameter <code>-filter</co... | <p>When piping items to <code>copy-item</code> you need to tell it that <code>"F:\tempzip"</code> is the destination path.</p> <pre><code>| Copy-Item -Destination F:\tempzip </code></pre> <p>You can also cutout piping to the <code>where</code> operator by using <code>Get-ChildItem</code>'s parameter <code>-filter</co... | 526, 4330, 24067 | copy, powershell, powershell-2.0 | <h1>How to use the Copy-Item cmdlet correctly to copy piped files</h1>
<p>I am building a small script which should copy all <code>.zip</code> files to a special folder called <code>F:\tempzip</code>.</p>
<p>I tried it with <a href="https://technet.microsoft.com/en-us/library/hh849793.aspx" rel="nofollow noreferrer">... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,280 | bash | # How to use the Copy-Item cmdlet correctly to copy piped files
I am building a small script which should copy all `.zip` files to a special folder called `F:\tempzip`.
I tried it with [Copy-Item](https://technet.microsoft.com/en-us/library/hh849793.aspx) cmdlet, but I didn't manage to do it. The script should copy a... | When piping items to `copy-item` you need to tell it that `"F:\tempzip"` is the destination path.
```
| Copy-Item -Destination F:\tempzip
```
You can also cutout piping to the `where` operator by using `Get-ChildItem`'s parameter `-filter`.
```
Get-Childitem "C:\imscript" -recurse -filter "*.zip" | Copy-Item -Destin... |
10856609 | Why is Powershell ISE showing errors that Powershell console does not show? | 13 | 2012-06-01 19:59:21 | <p>I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). <strong>They both work but ISE shows errors that the console does not. Why?</strong></p>
<p>The code is:</p>
<pre><code>git push origin master
Writ... | 8,727 | 518,298 | 2015-11-07 16:25:10 | 13,422,583 | 11 | 2012-11-16 18:48:15 | 206,349 | 2012-11-16 18:48:15 | https://stackoverflow.com/q/10856609 | https://stackoverflow.com/a/13422583 | <p>I don't know why they output differently, but the message that we see from <code>git push</code> is coming over stderr. This means that they are <strong>both</strong> showing errors, although the ISE is making them much louder, and converting it into error <strong><em>objects</em></strong>.</p>
<p>Consider this out... | <p>I don't know why they output differently, but the message that we see from <code>git push</code> is coming over stderr. This means that they are <strong>both</strong> showing errors, although the ISE is making them much louder, and converting it into error <strong><em>objects</em></strong>.</p> <p>Consider this out... | 526, 22864, 24067, 24068 | powershell, powershell-1.0, powershell-2.0, powershell-ise | <h1>Why is Powershell ISE showing errors that Powershell console does not show?</h1>
<p>I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). <strong>They both work but ISE shows errors that the console doe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,281 | bash | # Why is Powershell ISE showing errors that Powershell console does not show?
I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). **They both work but ISE shows errors that the console does not. Why?**
... | I don't know why they output differently, but the message that we see from `git push` is coming over stderr. This means that they are **both** showing errors, although the ISE is making them much louder, and converting it into error ***objects***.
Consider this output from the PowerShell prompt:
```
PS> git push
Ever... |
7800482 | In BASH, How do i replace \r from a variable that exist in a file written using HTML <textarea></textarea> | 13 | 2011-10-17 22:42:58 | <p>How do i replace the \r?</p>
<pre><code>#!/bin/bash
...
# setup
if [[ $i =~ $screen ]]; then
ORIGINAL=${BASH_REMATCH[1]} # original value is: 3DROTATE\r
AFTER =${ORIGINAL/\\r/} # does not replace \r
myThirdPartyApplication -o $replvar # FAILS because of \r
fi
</code></pre>
| 32,237 | null | 2018-10-13 18:07:05 | 7,800,522 | 11 | 2011-10-17 22:48:57 | 975,090 | 2018-10-13 18:07:05 | https://stackoverflow.com/q/7800482 | https://stackoverflow.com/a/7800522 | <p>You could use sed, i.e.,</p>
<pre><code>AFTER=`echo $ORIGINAL | sed 's/\\r//g'`
</code></pre>
| <p>You could use sed, i.e.,</p> <pre><code>AFTER=`echo $ORIGINAL | sed 's/\\r//g'` </code></pre> | 58, 387, 5430, 29051, 43830 | archlinux, bash, bash4, fedora, linux | <h1>In BASH, How do i replace \r from a variable that exist in a file written using HTML <textarea></textarea></h1>
<p>How do i replace the \r?</p>
<pre><code>#!/bin/bash
...
# setup
if [[ $i =~ $screen ]]; then
ORIGINAL=${BASH_REMATCH[1]} # original value is: 3DROTATE\r
AFTER =${ORIGINAL/\\r/} ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,282 | bash | # In BASH, How do i replace \r from a variable that exist in a file written using HTML
How do i replace the \r?
```
#!/bin/bash
...
# setup
if [[ $i =~ $screen ]]; then
ORIGINAL=${BASH_REMATCH[1]} # original value is: 3DROTATE\r
AFTER =${ORIGINAL/\\r/} # does not replace \r
myThird... | You could use sed, i.e.,
```
AFTER=`echo $ORIGINAL | sed 's/\\r//g'`
``` |
3281220 | Cannot understand command substitution in Fish shell | 13 | 2010-07-19 13:02:03 | <p>In sh:</p>
<pre><code>~$ `echo ls`
bin/ Desktop/
</code></pre>
<p>But in fish:</p>
<pre><code>fish: Illegal command name “(echo ls)”
~% (echo ls)
</code></pre>
<p>(Note that the error message appears above the command line.)</p>
<pre><code>~% echo (echo ls)
ls
~% eval (echo ls)
bin/ Desktop/
fish: Illegal co... | 23,093 | 222,893 | 2020-11-17 11:06:27 | 3,282,733 | 11 | 2010-07-19 15:58:54 | 222,893 | 2020-11-17 11:06:27 | https://stackoverflow.com/q/3281220 | https://stackoverflow.com/a/3282733 | <h1>Update</h1>
<p>This answer was written ten year ago in 2010.
Recent versions of fish (I tested on 3.1.2) updated and <code>set cmd ls; $cmd</code> is valid now.</p>
<h1>How</h1>
<p>This because command substitutions belong to parameter expansions and are not allowed as commands.</p>
<p>A similar example:</p>
<p>in ... | <h1>Update</h1> <p>This answer was written ten year ago in 2010. Recent versions of fish (I tested on 3.1.2) updated and <code>set cmd ls; $cmd</code> is valid now.</p> <h1>How</h1> <p>This because command substitutions belong to parameter expansions and are not allowed as commands.</p> <p>A similar example:</p> <p>in ... | 387, 390, 1231, 55824 | bash, command-line, fish, shell | <h1>Cannot understand command substitution in Fish shell</h1>
<p>In sh:</p>
<pre><code>~$ `echo ls`
bin/ Desktop/
</code></pre>
<p>But in fish:</p>
<pre><code>fish: Illegal command name “(echo ls)”
~% (echo ls)
</code></pre>
<p>(Note that the error message appears above the command line.)</p>
<pre><code>~% echo (... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,283 | bash | # Cannot understand command substitution in Fish shell
In sh:
```
~$ `echo ls`
bin/ Desktop/
```
But in fish:
```
fish: Illegal command name “(echo ls)”
~% (echo ls)
```
(Note that the error message appears above the command line.)
```
~% echo (echo ls)
ls
~% eval (echo ls)
bin/ Desktop/
fish: Illegal command ... | # Update
This answer was written ten year ago in 2010.
Recent versions of fish (I tested on 3.1.2) updated and `set cmd ls; $cmd` is valid now.
# How
This because command substitutions belong to parameter expansions and are not allowed as commands.
A similar example:
in sh:
```
tmpls=ls
$tmpls
```
But in fish:
... |
2308268 | Storing files inside BASH scripts | 13 | 2010-02-22 01:22:04 | <p>Is there a way to store binary data inside a BASH script so that it can be piped to a program later in that script?</p>
<p>At the moment (on Mac OS X) I'm doing</p>
<pre><code>play sound.m4a
# do stuff
</code></pre>
<p>I'd like to be able to do something like:</p>
<pre><code>SOUND <<< the m4a data, enco... | 13,838 | 201,130 | 2015-06-02 08:10:33 | 2,308,313 | 11 | 2010-02-22 01:36:14 | 111,644 | 2010-02-22 01:44:09 | https://stackoverflow.com/q/2308268 | https://stackoverflow.com/a/2308313 | <p>Base64 encode it. For example:</p>
<pre><code>$ openssl base64 < sound.m4a
</code></pre>
<p>and then in the script:</p>
<pre><code>S=<<SOUND
YOURBASE64GOESHERE
SOUND
echo $S | openssl base64 -d | play
</code></pre>
| <p>Base64 encode it. For example:</p> <pre><code>$ openssl base64 < sound.m4a </code></pre> <p>and then in the script:</p> <pre><code>S=<<SOUND YOURBASE64GOESHERE SOUND echo $S | openssl base64 -d | play </code></pre> | 387 | bash | <h1>Storing files inside BASH scripts</h1>
<p>Is there a way to store binary data inside a BASH script so that it can be piped to a program later in that script?</p>
<p>At the moment (on Mac OS X) I'm doing</p>
<pre><code>play sound.m4a
# do stuff
</code></pre>
<p>I'd like to be able to do something like:</p>
<pre>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,284 | bash | # Storing files inside BASH scripts
Is there a way to store binary data inside a BASH script so that it can be piped to a program later in that script?
At the moment (on Mac OS X) I'm doing
```
play sound.m4a
# do stuff
```
I'd like to be able to do something like:
```
SOUND <<< the m4a data, encoded somehow?
END
... | Base64 encode it. For example:
```
$ openssl base64 < sound.m4a
```
and then in the script:
```
S=<<SOUND
YOURBASE64GOESHERE
SOUND
echo $S | openssl base64 -d | play
``` |
1703061 | PowerShell -match operator and multiple groups | 13 | 2009-11-09 19:07:04 | <p>I have the following log entry that I am processing in PowerShell I'm trying to extract all the activity names and durations using the <code>-match</code> operator but I am only getting one match group back. I'm not getting all of the matches that I see when I do the same thing in C# using the <code>Regex</code> ob... | 24,487 | 3,957 | 2021-06-18 15:47:06 | 1,703,380 | 11 | 2009-11-09 20:02:08 | 153,982 | 2021-06-18 11:32:02 | https://stackoverflow.com/q/1703061 | https://stackoverflow.com/a/1703380 | <p>You can do this with the <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Select-String" rel="nofollow noreferrer">Select-String</a> cmdlet in V2, but you need to specify the <em>-AllMatches</em> switch, e.g.:</p>
<pre><code>$formattedMessage | Select-String 'regexpattern' -A... | <p>You can do this with the <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Select-String" rel="nofollow noreferrer">Select-String</a> cmdlet in V2, but you need to specify the <em>-AllMatches</em> switch, e.g.:</p> <pre><code>$formattedMessage | Select-String 'regexpattern' -A... | 1, 18, 526 | .net, powershell, regex | <h1>PowerShell -match operator and multiple groups</h1>
<p>I have the following log entry that I am processing in PowerShell I'm trying to extract all the activity names and durations using the <code>-match</code> operator but I am only getting one match group back. I'm not getting all of the matches that I see when I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,285 | bash | # PowerShell -match operator and multiple groups
I have the following log entry that I am processing in PowerShell I'm trying to extract all the activity names and durations using the `-match` operator but I am only getting one match group back. I'm not getting all of the matches that I see when I do the same thing in... | You can do this with the [Select-String](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Select-String) cmdlet in V2, but you need to specify the *-AllMatches* switch, e.g.:
```
$formattedMessage | Select-String 'regexpattern' -AllMatches
```
Keep in mind that with the `-match` operat... |
1272675 | How to grab an arbitrary chunk from a file on Unix/Linux | 13 | 2009-08-13 15:21:40 | <p>I'm trying to copy a chunk from one binary file into a new file. I have the byte offset and length of the chunk I want to grab.</p>
<p>I have tried using the <code>dd</code> utility, but this seems to read and discard the data up to the offset, rather than just seeking (I guess because <code>dd</code> is for copying... | 13,763 | 155,883 | 2022-12-28 20:27:41 | 1,280,828 | 11 | 2009-08-15 00:37:03 | 4,421 | 2009-10-07 11:15:47 | https://stackoverflow.com/q/1272675 | https://stackoverflow.com/a/1280828 | <p>Yes it's awkward to do this with dd today. We're considering adding skip_bytes and count_bytes params to dd in coreutils to help. The following should work though:</p>
<pre><code>#!/bin/sh
bs=100000
infile=$1
skip=$2
length=$3
(
dd bs=1 skip=$skip count=0
dd bs=$bs count=$(($length / $bs))
dd bs=$(($length ... | <p>Yes it's awkward to do this with dd today. We're considering adding skip_bytes and count_bytes params to dd in coreutils to help. The following should work though:</p> <pre><code>#!/bin/sh bs=100000 infile=$1 skip=$2 length=$3 ( dd bs=1 skip=$skip count=0 dd bs=$bs count=$(($length / $bs)) dd bs=$(($length ... | 34, 387, 390 | bash, shell, unix | <h1>How to grab an arbitrary chunk from a file on Unix/Linux</h1>
<p>I'm trying to copy a chunk from one binary file into a new file. I have the byte offset and length of the chunk I want to grab.</p>
<p>I have tried using the <code>dd</code> utility, but this seems to read and discard the data up to the offset, rather... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,286 | bash | # How to grab an arbitrary chunk from a file on Unix/Linux
I'm trying to copy a chunk from one binary file into a new file. I have the byte offset and length of the chunk I want to grab.
I have tried using the `dd` utility, but this seems to read and discard the data up to the offset, rather than just seeking (I gues... | Yes it's awkward to do this with dd today. We're considering adding skip_bytes and count_bytes params to dd in coreutils to help. The following should work though:
```
#!/bin/sh
bs=100000
infile=$1
skip=$2
length=$3
(
dd bs=1 skip=$skip count=0
dd bs=$bs count=$(($length / $bs))
dd bs=$(($length % $bs)) count=... |
54812828 | Powershell Start-Process VS Invoke-Item | 12 | 2019-02-21 17:21:29 | <p>What's the difference between <code>Start-Process</code> and <code>Invoke-Item</code>? I noticed that you can't <code>Invoke-Item chrome</code>. I assume that <code>Invoke-Item</code> is specifically for files with a given file path. But are there any advantages to using <code>Invoke-Item</code> instead of <code>... | 21,482 | 10,773,347 | 2019-02-21 20:50:54 | 54,815,684 | 11 | 2019-02-21 20:27:12 | 1,778,866 | 2019-02-21 20:50:54 | https://stackoverflow.com/q/54812828 | https://stackoverflow.com/a/54815684 | <p>The <code>Invoke-Item</code> cmdlet performs the default action on the specified item. For example, it runs an executable file or opens a document file in the application associated with the document file type. The default action depends on the type of item and is determined by the PowerShell provider that provides ... | <p>The <code>Invoke-Item</code> cmdlet performs the default action on the specified item. For example, it runs an executable file or opens a document file in the application associated with the document file type. The default action depends on the type of item and is determined by the PowerShell provider that provides ... | 526, 26462 | powershell, start-process | <h1>Powershell Start-Process VS Invoke-Item</h1>
<p>What's the difference between <code>Start-Process</code> and <code>Invoke-Item</code>? I noticed that you can't <code>Invoke-Item chrome</code>. I assume that <code>Invoke-Item</code> is specifically for files with a given file path. But are there any advantages to... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,287 | bash | # Powershell Start-Process VS Invoke-Item
What's the difference between `Start-Process` and `Invoke-Item`? I noticed that you can't `Invoke-Item chrome`. I assume that `Invoke-Item` is specifically for files with a given file path. But are there any advantages to using `Invoke-Item` instead of `Start-Process` (besides... | The `Invoke-Item` cmdlet performs the default action on the specified item. For example, it runs an executable file or opens a document file in the application associated with the document file type. The default action depends on the type of item and is determined by the PowerShell provider that provides access to the ... |
47176906 | return values from bash script | 12 | 2017-11-08 10:13:11 | <p>I want to create a Bash file that returns a value.
Meaning, in script script_a.bash I have a certain calculation, and script script_b.bash will call it.</p>
<p>script_a.bash:</p>
<pre><code>return $1*5
</code></pre>
<p>script_b.bash:</p>
<pre><code>a_value=./script_a.bash 3
</code></pre>
<p>when a_value will be 15.<... | 29,344 | 3,106,804 | 2022-08-23 08:37:30 | 47,176,984 | 11 | 2017-11-08 10:16:51 | 1,030,675 | 2017-11-08 10:16:51 | https://stackoverflow.com/q/47176906 | https://stackoverflow.com/a/47176984 | <p>Use command substitution to capture the output of <code>echo</code>, and use arithmetic expression to count the result:</p>
<p>script_a.bash:</p>
<pre><code>echo $(( $1 * 5 ))
</code></pre>
<p>script_b.bash</p>
<pre><code>a_value=$( script_a.bash 3 )
</code></pre>
| <p>Use command substitution to capture the output of <code>echo</code>, and use arithmetic expression to count the result:</p> <p>script_a.bash:</p> <pre><code>echo $(( $1 * 5 )) </code></pre> <p>script_b.bash</p> <pre><code>a_value=$( script_a.bash 3 ) </code></pre> | 58, 387, 9206, 13824 | bash, echo, linux, return-value | <h1>return values from bash script</h1>
<p>I want to create a Bash file that returns a value.
Meaning, in script script_a.bash I have a certain calculation, and script script_b.bash will call it.</p>
<p>script_a.bash:</p>
<pre><code>return $1*5
</code></pre>
<p>script_b.bash:</p>
<pre><code>a_value=./script_a.bash 3
</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,288 | bash | # return values from bash script
I want to create a Bash file that returns a value.
Meaning, in script script_a.bash I have a certain calculation, and script script_b.bash will call it.
script_a.bash:
```
return $1*5
```
script_b.bash:
```
a_value=./script_a.bash 3
```
when a_value will be 15.
I read a little bi... | Use command substitution to capture the output of `echo`, and use arithmetic expression to count the result:
script_a.bash:
```
echo $(( $1 * 5 ))
```
script_b.bash
```
a_value=$( script_a.bash 3 )
``` |
46981484 | Why and how do you use JShell? | 12 | 2017-10-27 18:38:45 | <p>I went through a couple of tutorials for JShell and I still do not understand the most important part: why would I even use JShell?</p>
<p>Here what Oracle says: </p>
<blockquote>
<p>"You can test individual statements, try out different variations of a
method, and experiment with unfamiliar APIs within the JS... | 5,086 | 5,077,585 | 2017-10-28 05:41:45 | 46,985,517 | 11 | 2017-10-28 01:54:29 | 1,746,118 | 2017-10-28 05:41:38 | https://stackoverflow.com/q/46981484 | https://stackoverflow.com/a/46985517 | <p>Though I would really encourage you to go ahead and read <a href="http://openjdk.java.net/jeps/222" rel="noreferrer">The Java Shell</a> motivation and goals.</p>
<p>Yet to answer your question with a slight hands-on and I would actually be glad to know about the time you take and procedure you would follow while tr... | <p>Though I would really encourage you to go ahead and read <a href="http://openjdk.java.net/jeps/222" rel="noreferrer">The Java Shell</a> motivation and goals.</p> <p>Yet to answer your question with a slight hands-on and I would actually be glad to know about the time you take and procedure you would follow while tr... | 17, 63533, 109916, 116030 | java, java-9, jshell, read-eval-print-loop | <h1>Why and how do you use JShell?</h1>
<p>I went through a couple of tutorials for JShell and I still do not understand the most important part: why would I even use JShell?</p>
<p>Here what Oracle says: </p>
<blockquote>
<p>"You can test individual statements, try out different variations of a
method, and exper... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,289 | bash | # Why and how do you use JShell?
I went through a couple of tutorials for JShell and I still do not understand the most important part: why would I even use JShell?
Here what Oracle says:
> "You can test individual statements, try out different variations of a
> method, and experiment with unfamiliar APIs within the... | Though I would really encourage you to go ahead and read [The Java Shell](http://openjdk.java.net/jeps/222) motivation and goals.
Yet to answer your question with a slight hands-on and I would actually be glad to know about the time you take and procedure you would follow while trying this out on an IDE. So, with few ... |
45562771 | If output of bash command is empty, do something | 12 | 2017-08-08 08:09:23 | <p>Hi I am new to bash so please excuse me if I have a really silly/easy question. I am writing a script which allows the user to change their region (for wireless). What I am wanting to do is put a check in place, so if they type in an incorrect value, it brings up the prompt again to input the region. I want to do th... | 20,588 | 4,657,045 | 2017-08-08 08:38:08 | 45,563,383 | 11 | 2017-08-08 08:38:08 | 4,024,473 | 2017-08-08 08:38:08 | https://stackoverflow.com/q/45562771 | https://stackoverflow.com/a/45563383 | <p>You can use the <code>-z</code> test, type <code>help test</code> in Bash to learn more (<code>test</code> is the same as the <code>[</code> command).</p>
<p>You should only call <code>iw reg set</code> once, unless it fails.</p>
<pre><code>echo "Please set a region: "
while true # infinite loop
do
# read in... | <p>You can use the <code>-z</code> test, type <code>help test</code> in Bash to learn more (<code>test</code> is the same as the <code>[</code> command).</p> <p>You should only call <code>iw reg set</code> once, unless it fails.</p> <pre><code>echo "Please set a region: " while true # infinite loop do # read in... | 58, 387, 531 | bash, linux, scripting | <h1>If output of bash command is empty, do something</h1>
<p>Hi I am new to bash so please excuse me if I have a really silly/easy question. I am writing a script which allows the user to change their region (for wireless). What I am wanting to do is put a check in place, so if they type in an incorrect value, it bring... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,290 | bash | # If output of bash command is empty, do something
Hi I am new to bash so please excuse me if I have a really silly/easy question. I am writing a script which allows the user to change their region (for wireless). What I am wanting to do is put a check in place, so if they type in an incorrect value, it brings up the ... | You can use the `-z` test, type `help test` in Bash to learn more (`test` is the same as the `[` command).
You should only call `iw reg set` once, unless it fails.
```
echo "Please set a region: "
while true # infinite loop
do
# read in the region:
read reg
# try the command, and catch its output:
... |
42568949 | Passing an ordered hashtable to a function | 12 | 2017-03-03 01:17:37 | <p>How can I go about passing an ordered hashtable to a function?</p>
<p>The following throws an error:</p>
<blockquote>
<p>The ordered attribute can be specified only on a hash literal node.</p>
</blockquote>
<pre><code>function doStuff {
Param (
[ordered]$theOrderedHashtable
)
$theOrderedHash... | 5,660 | 3,053,920 | 2021-12-20 22:52:02 | 42,569,034 | 11 | 2017-03-03 01:28:20 | 712,649 | 2017-03-03 09:50:58 | https://stackoverflow.com/q/42568949 | https://stackoverflow.com/a/42569034 | <p>Use the full type name:</p>
<pre><code>function Do-Stuff {
param(
[System.Collections.Specialized.OrderedDictionary]$OrderedHashtable
)
$OrderedHashtable
}
</code></pre>
<p>To support both regular hashtables and ordered dictionaries, <strike>you'll have to use separate parameter sets:</strike> ... | <p>Use the full type name:</p> <pre><code>function Do-Stuff { param( [System.Collections.Specialized.OrderedDictionary]$OrderedHashtable ) $OrderedHashtable } </code></pre> <p>To support both regular hashtables and ordered dictionaries, <strike>you'll have to use separate parameter sets:</strike> ... | 526, 73157 | powershell, powershell-3.0 | <h1>Passing an ordered hashtable to a function</h1>
<p>How can I go about passing an ordered hashtable to a function?</p>
<p>The following throws an error:</p>
<blockquote>
<p>The ordered attribute can be specified only on a hash literal node.</p>
</blockquote>
<pre><code>function doStuff {
Param (
[or... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,291 | bash | # Passing an ordered hashtable to a function
How can I go about passing an ordered hashtable to a function?
The following throws an error:
> The ordered attribute can be specified only on a hash literal node.
```
function doStuff {
Param (
[ordered]$theOrderedHashtable
)
$theOrderedHashtable
}
... | Use the full type name:
```
function Do-Stuff {
param(
[System.Collections.Specialized.OrderedDictionary]$OrderedHashtable
)
$OrderedHashtable
}
```
To support both regular hashtables and ordered dictionaries, you'll have to use separate parameter sets: use the `[System.Collections.IDictionary]` i... |
40686922 | How to split a string on a multi-character delimiter in Bash? | 12 | 2016-11-18 22:28:54 | <p>Why doesn't the following Bash code work?</p>
<pre><code>for i in $( echo "emmbbmmaaddsb" | split -t "mm" )
do
echo "$i"
done
</code></pre>
<p>Expected output:</p>
<pre><code>e
bb
aaddsb
</code></pre>
| 44,635 | 2,223,605 | 2024-05-03 21:44:39 | 40,687,088 | 11 | 2016-11-18 22:46:32 | 14,122 | 2016-11-18 23:02:59 | https://stackoverflow.com/q/40686922 | https://stackoverflow.com/a/40687088 | <p>Since you're expecting newlines, you can simply replace all instances of <code>mm</code> in your string with a newline. In pure native bash:</p>
<pre><code>in='emmbbmmaaddsb'
sep='mm'
printf '%s\n' "${in//$sep/$'\n'}"
</code></pre>
<hr>
<p>If you wanted to do such a replacement on a longer input stream, you might... | <p>Since you're expecting newlines, you can simply replace all instances of <code>mm</code> in your string with a newline. In pure native bash:</p> <pre><code>in='emmbbmmaaddsb' sep='mm' printf '%s\n' "${in//$sep/$'\n'}" </code></pre> <hr> <p>If you wanted to do such a replacement on a longer input stream, you might... | 387, 390, 549, 24516 | bash, gnu-coreutils, shell, ubuntu | <h1>How to split a string on a multi-character delimiter in Bash?</h1>
<p>Why doesn't the following Bash code work?</p>
<pre><code>for i in $( echo "emmbbmmaaddsb" | split -t "mm" )
do
echo "$i"
done
</code></pre>
<p>Expected output:</p>
<pre><code>e
bb
aaddsb
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,292 | bash | # How to split a string on a multi-character delimiter in Bash?
Why doesn't the following Bash code work?
```
for i in $( echo "emmbbmmaaddsb" | split -t "mm" )
do
echo "$i"
done
```
Expected output:
```
e
bb
aaddsb
``` | Since you're expecting newlines, you can simply replace all instances of `mm` in your string with a newline. In pure native bash:
```
in='emmbbmmaaddsb'
sep='mm'
printf '%s\n' "${in//$sep/$'\n'}"
```
---
If you wanted to do such a replacement on a longer input stream, you might be better off using `awk`, as bash's b... |
32039852 | Returning output from bash script to calling C++ function | 12 | 2015-08-16 20:55:57 | <p>I am writing a baby program for practice. What I am trying to accomplish is basically a simple little GUI which displays services (for Linux); with buttons to start, stop, enable, and disable services (Much like the msconfig application "Services" tab in Windows). I am using C++ with Qt Creator on Fedora 21. </p>
<... | 7,219 | 4,565,156 | 2015-08-16 21:47:28 | 32,039,951 | 11 | 2015-08-16 21:06:45 | 4,307,644 | 2015-08-16 21:06:45 | https://stackoverflow.com/q/32039852 | https://stackoverflow.com/a/32039951 | <p>We're going to take advantage of the <code>popen</code> function, here.</p>
<pre><code>std::string exec(char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
r... | <p>We're going to take advantage of the <code>popen</code> function, here.</p> <pre><code>std::string exec(char* cmd) { FILE* pipe = popen(cmd, "r"); if (!pipe) return "ERROR"; char buffer[128]; std::string result = ""; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) r... | 10, 58, 387 | bash, c++, linux | <h1>Returning output from bash script to calling C++ function</h1>
<p>I am writing a baby program for practice. What I am trying to accomplish is basically a simple little GUI which displays services (for Linux); with buttons to start, stop, enable, and disable services (Much like the msconfig application "Services" ta... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,293 | bash | # Returning output from bash script to calling C++ function
I am writing a baby program for practice. What I am trying to accomplish is basically a simple little GUI which displays services (for Linux); with buttons to start, stop, enable, and disable services (Much like the msconfig application "Services" tab in Wind... | We're going to take advantage of the `popen` function, here.
```
std::string exec(char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
... |
24672560 | Most elegant way to extract a directory from a zipfile using PowerShell? | 12 | 2014-07-10 09:10:10 | <p>I need to unzip a specific directory from a zipfile.</p>
<p>Like for example extract the directory 'test\etc\script' from zipfile 'c:\tmp\test.zip' and place it in c:\tmp\output\test\etc\script.</p>
<p>The code below works but has two quirks:</p>
<ul>
<li><p>I need to recursively find the directory ('script') in ... | 27,198 | 1,743,111 | 2016-10-29 17:35:11 | 24,681,376 | 11 | 2014-07-10 16:08:21 | 323,582 | 2014-07-10 16:08:21 | https://stackoverflow.com/q/24672560 | https://stackoverflow.com/a/24681376 | <p>As far as the folder location in a zip is known, the original code can be simplified:</p>
<pre class="lang-psh prettyprint-override"><code>$source = 'c:\tmp\test.zip' # zip file
$target = 'c:\tmp\output' # target root
$folder = 'test\etc\script' # path in the zip
$shell = New-Object -ComObject Shell.Applicati... | <p>As far as the folder location in a zip is known, the original code can be simplified:</p> <pre class="lang-psh prettyprint-override"><code>$source = 'c:\tmp\test.zip' # zip file $target = 'c:\tmp\output' # target root $folder = 'test\etc\script' # path in the zip $shell = New-Object -ComObject Shell.Applicati... | 526 | powershell | <h1>Most elegant way to extract a directory from a zipfile using PowerShell?</h1>
<p>I need to unzip a specific directory from a zipfile.</p>
<p>Like for example extract the directory 'test\etc\script' from zipfile 'c:\tmp\test.zip' and place it in c:\tmp\output\test\etc\script.</p>
<p>The code below works but has tw... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,294 | bash | # Most elegant way to extract a directory from a zipfile using PowerShell?
I need to unzip a specific directory from a zipfile.
Like for example extract the directory 'test\etc\script' from zipfile 'c:\tmp\test.zip' and place it in c:\tmp\output\test\etc\script.
The code below works but has two quirks:
- I need to ... | As far as the folder location in a zip is known, the original code can be simplified:
```
$source = 'c:\tmp\test.zip' # zip file
$target = 'c:\tmp\output' # target root
$folder = 'test\etc\script' # path in the zip
$shell = New-Object -ComObject Shell.Application
# find script folder e.g. c:\tmp\test.zip\test\e... |
18982611 | Subshell IO redirection | 12 | 2013-09-24 13:11:43 | <p>Given a file <code>"foo.txt"</code>, created from:</p>
<pre><code>$ seq 1 10 > "foo.txt"
</code></pre>
<p>I'm trying to read both the first and last line of the file, and I started by redirecting the file to a subshell, so that the list of commands will consume the file in sequence -- each command consumes the ... | 4,377 | 1,655,939 | 2013-09-24 13:45:03 | 18,983,112 | 11 | 2013-09-24 13:33:22 | 140,750 | 2013-09-24 13:45:03 | https://stackoverflow.com/q/18982611 | https://stackoverflow.com/a/18983112 | <p>It's just a buffering issue. Try:</p>
<pre><code>cat foo.txt | ( head -1; tail -1)
</code></pre>
<p>and you will (probably) see the same thing (head consumes the entire input). Probably what is happening is that head is behaving differently with a regular file than with a pipe, and the process substitution (whi... | <p>It's just a buffering issue. Try:</p> <pre><code>cat foo.txt | ( head -1; tail -1) </code></pre> <p>and you will (probably) see the same thing (head consumes the entire input). Probably what is happening is that head is behaving differently with a regular file than with a pipe, and the process substitution (whi... | 387, 7604, 31901, 57788 | bash, file-descriptor, http-redirect, subshell | <h1>Subshell IO redirection</h1>
<p>Given a file <code>"foo.txt"</code>, created from:</p>
<pre><code>$ seq 1 10 > "foo.txt"
</code></pre>
<p>I'm trying to read both the first and last line of the file, and I started by redirecting the file to a subshell, so that the list of commands will consume the file in seque... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,295 | bash | # Subshell IO redirection
Given a file `"foo.txt"`, created from:
```
$ seq 1 10 > "foo.txt"
```
I'm trying to read both the first and last line of the file, and I started by redirecting the file to a subshell, so that the list of commands will consume the file in sequence -- each command consumes the input from the... | It's just a buffering issue. Try:
```
cat foo.txt | ( head -1; tail -1)
```
and you will (probably) see the same thing (head consumes the entire input). Probably what is happening is that head is behaving differently with a regular file than with a pipe, and the process substitution (which is the name for the `<(cmd)... |
18496627 | How to reliably reference external .NET assemblies in a PowerShell v3 module? | 12 | 2013-08-28 19:28:11 | <p>I am working on a PowerShell v3 module that needs to work with Types which are contained in a few external .NET assemblies.</p>
<p>I would like this module to be reasonably self-contained for ease of deployment and I do not want to rely on these assemblies being loaded in the GAC. Ideally, I would like to place th... | 8,488 | 1,077,421 | 2013-08-28 19:37:37 | 18,496,792 | 11 | 2013-08-28 19:37:37 | 67,392 | 2013-08-28 19:37:37 | https://stackoverflow.com/q/18496627 | https://stackoverflow.com/a/18496792 | <p>The <a href="http://technet.microsoft.com/library/hh849709.aspx" rel="noreferrer"><code>New-ModuleManifest</code></a> documentation for its <code>-RequiredAssemblies</code> parameter agrees:</p>
<blockquote>
<p>Specifies the assembly (.dll) files that the module requires. Enter the assembly file names. Windows Power... | <p>The <a href="http://technet.microsoft.com/library/hh849709.aspx" rel="noreferrer"><code>New-ModuleManifest</code></a> documentation for its <code>-RequiredAssemblies</code> parameter agrees:</p> <blockquote> <p>Specifies the assembly (.dll) files that the module requires. Enter the assembly file names. Windows Power... | 526, 67488, 73157 | powershell, powershell-3.0, powershell-module | <h1>How to reliably reference external .NET assemblies in a PowerShell v3 module?</h1>
<p>I am working on a PowerShell v3 module that needs to work with Types which are contained in a few external .NET assemblies.</p>
<p>I would like this module to be reasonably self-contained for ease of deployment and I do not want ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,296 | bash | # How to reliably reference external .NET assemblies in a PowerShell v3 module?
I am working on a PowerShell v3 module that needs to work with Types which are contained in a few external .NET assemblies.
I would like this module to be reasonably self-contained for ease of deployment and I do not want to rely on these... | The [`New-ModuleManifest`](http://technet.microsoft.com/library/hh849709.aspx) documentation for its `-RequiredAssemblies` parameter agrees:
> Specifies the assembly (.dll) files that the module requires. Enter the assembly file names. Windows PowerShell loads the specified assemblies before updating types or formats,... |
15689912 | How to copy to the clipboard the current path? | 12 | 2013-03-28 18:51:24 | <p>How can I copy the current path in the bash terminal, using just one command? </p>
| 12,578 | 248,959 | 2014-08-27 14:09:39 | 15,690,667 | 11 | 2013-03-28 19:38:32 | 1,073,695 | 2014-08-27 14:09:39 | https://stackoverflow.com/q/15689912 | https://stackoverflow.com/a/15690667 | <p>Needs <code>xsel</code> installed:</p>
<pre><code>pwd | xsel -i
</code></pre>
<p>(if you don't want the trailing newline, use <code>printf %s "$(pwd)" | xsel -i</code> (mostly correct) <code>pwd | head -c -1 | xsel -i</code> (perfectly correct))</p>
<hr>
<p>Update August 2014: The <code>xsel</code> program is br... | <p>Needs <code>xsel</code> installed:</p> <pre><code>pwd | xsel -i </code></pre> <p>(if you don't want the trailing newline, use <code>printf %s "$(pwd)" | xsel -i</code> (mostly correct) <code>pwd | head -c -1 | xsel -i</code> (perfectly correct))</p> <hr> <p>Update August 2014: The <code>xsel</code> program is br... | 58, 387, 28564 | bash, linux, pwd | <h1>How to copy to the clipboard the current path?</h1>
<p>How can I copy the current path in the bash terminal, using just one command? </p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,297 | bash | # How to copy to the clipboard the current path?
How can I copy the current path in the bash terminal, using just one command? | Needs `xsel` installed:
```
pwd | xsel -i
```
(if you don't want the trailing newline, use `printf %s "$(pwd)" | xsel -i` (mostly correct) `pwd | head -c -1 | xsel -i` (perfectly correct))
---
Update August 2014: The `xsel` program is broken: See my [bugreport](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=7585... |
12787501 | wget and run/remove bash script in one line | 12 | 2012-10-08 18:36:26 | <pre><code>wget http://sitehere.com/install.sh -v -O install.sh; rm -rf install.sh
</code></pre>
<p>That runs the script after download right and then removes it?</p>
| 18,488 | 1,729,652 | 2015-03-09 00:12:04 | 12,787,541 | 11 | 2012-10-08 18:39:26 | 1,687,321 | 2012-10-08 18:39:26 | https://stackoverflow.com/q/12787501 | https://stackoverflow.com/a/12787541 | <p>I think you might need to actually execute it:</p>
<pre><code>wget http://sitehere.com/install.sh -v -O install.sh; ./install.sh; rm -rf install.sh
</code></pre>
<p>Also, if you want a little more robustness, you can use <code>&&</code> to separate commands, which will only attempt to execute the next comm... | <p>I think you might need to actually execute it:</p> <pre><code>wget http://sitehere.com/install.sh -v -O install.sh; ./install.sh; rm -rf install.sh </code></pre> <p>Also, if you want a little more robustness, you can use <code>&&</code> to separate commands, which will only attempt to execute the next comm... | 387, 390, 5583 | bash, shell, wget | <h1>wget and run/remove bash script in one line</h1>
<pre><code>wget http://sitehere.com/install.sh -v -O install.sh; rm -rf install.sh
</code></pre>
<p>That runs the script after download right and then removes it?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,298 | bash | # wget and run/remove bash script in one line
```
wget http://sitehere.com/install.sh -v -O install.sh; rm -rf install.sh
```
That runs the script after download right and then removes it? | I think you might need to actually execute it:
```
wget http://sitehere.com/install.sh -v -O install.sh; ./install.sh; rm -rf install.sh
```
Also, if you want a little more robustness, you can use `&&` to separate commands, which will only attempt to execute the next command if the previous one succeeds:
```
wget ht... |
11929493 | Windows bat alternative for Bash inline command | 12 | 2012-08-13 06:58:36 | <p>Is there any Windows equivalent syntax to run a command within another command in a bat script file?</p>
<p>In Linux, you can simply use <a href="https://stackoverflow.com/questions/8663595/bash-for-inline-command">$(...)</a> or ``.</p>
| 7,551 | 141,438 | 2017-11-15 18:33:45 | 11,929,597 | 11 | 2012-08-13 07:08:37 | 14,860 | 2012-08-13 07:08:37 | https://stackoverflow.com/q/11929493 | https://stackoverflow.com/a/11929597 | <p>Yes, at least for simple things:</p>
<pre><code>@setlocal enableextensions enabledelayedexpansion
@echo off
for /f %%w in ('echo xyzzy') do set var=%%w
echo Output is %var%
endlocal
</code></pre>
<p>The output of that script is:</p>
<pre><code>Output is xyzzy
</code></pre>
<p>with the <code>xyzzy</code> coming f... | <p>Yes, at least for simple things:</p> <pre><code>@setlocal enableextensions enabledelayedexpansion @echo off for /f %%w in ('echo xyzzy') do set var=%%w echo Output is %var% endlocal </code></pre> <p>The output of that script is:</p> <pre><code>Output is xyzzy </code></pre> <p>with the <code>xyzzy</code> coming f... | 64, 387, 2631, 7002 | bash, batch-file, cmd, windows | <h1>Windows bat alternative for Bash inline command</h1>
<p>Is there any Windows equivalent syntax to run a command within another command in a bat script file?</p>
<p>In Linux, you can simply use <a href="https://stackoverflow.com/questions/8663595/bash-for-inline-command">$(...)</a> or ``.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,299 | bash | # Windows bat alternative for Bash inline command
Is there any Windows equivalent syntax to run a command within another command in a bat script file?
In Linux, you can simply use [$(...)](https://stackoverflow.com/questions/8663595/bash-for-inline-command) or ``. | Yes, at least for simple things:
```
@setlocal enableextensions enabledelayedexpansion
@echo off
for /f %%w in ('echo xyzzy') do set var=%%w
echo Output is %var%
endlocal
```
The output of that script is:
```
Output is xyzzy
```
with the `xyzzy` coming from the `echo` command.
Running `for /?` from a command windo... |
11119240 | PowerShell command over multiple lines | 12 | 2012-06-20 12:09:58 | <p>I have a batch script that looks like this:</p>
<h3>Test.bat</h3>
<pre><code>@echo off
:: Starts a PowerShell session that starts a PowerShell process with administrator privileges
powershell -noprofile -command "&{$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -v... | 16,698 | 1,353,661 | 2018-08-24 19:54:14 | 11,119,387 | 11 | 2012-06-20 12:17:41 | 63,733 | 2018-08-24 19:53:48 | https://stackoverflow.com/q/11119240 | https://stackoverflow.com/a/11119387 | <p>You may try the caret <code>^</code> to indicate that the current line continues on the next one:</p>
<pre><code>powershell -noprofile -command "&{"^
"$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;"^
"$process.WaitForExit();"^
"}"
</code></pre... | <p>You may try the caret <code>^</code> to indicate that the current line continues on the next one:</p> <pre><code>powershell -noprofile -command "&{"^ "$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;"^ "$process.WaitForExit();"^ "}" </code></pre... | 526, 7002 | batch-file, powershell | <h1>PowerShell command over multiple lines</h1>
<p>I have a batch script that looks like this:</p>
<h3>Test.bat</h3>
<pre><code>@echo off
:: Starts a PowerShell session that starts a PowerShell process with administrator privileges
powershell -noprofile -command "&{$process = start-process powershell -Argumen... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,300 | bash | # PowerShell command over multiple lines
I have a batch script that looks like this:
### Test.bat
```
@echo off
:: Starts a PowerShell session that starts a PowerShell process with administrator privileges
powershell -noprofile -command "&{$process = start-process powershell -ArgumentList '-noprofile -noexit -file ... | You may try the caret `^` to indicate that the current line continues on the next one:
```
powershell -noprofile -command "&{"^
"$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;"^
"$process.WaitForExit();"^
"}"
```
Please note also the leading space a... |
9829769 | Strange "half to even" rounding in different languages | 12 | 2012-03-22 20:12:35 | <p>GNU bash, version 4.2.24:</p>
<pre><code>$> printf "%.0f, %.0f\n" 48.5 49.5
48, 50
</code></pre>
<p>Ruby 1.8.7</p>
<pre><code>> printf( "%.0f, %.0f\n", 48.5, 49.5 )
48, 50
</code></pre>
<p>Perl 5.12.4</p>
<pre><code>$> perl -e 'printf( "%.0f, %.0f\n", 48.5, 49.5 )'
48, 50
</code></pre>
<p>gcc 4.5.3:</... | 1,570 | 570,689 | 2012-03-23 18:21:11 | 9,829,924 | 11 | 2012-03-22 20:24:35 | 1,097,181 | 2012-03-22 20:24:35 | https://stackoverflow.com/q/9829769 | https://stackoverflow.com/a/9829924 | <pre><code>GHCi> round 48.5
48
GHCi> round 49.5
50
</code></pre>
<p>The only difference is that <code>printf</code> isn't using <code>round</code> — presumably because it has to be able to round to more than just whole integers. I don't think IEEE 754 specifies anything about how to implement <code>printf</code>... | <pre><code>GHCi> round 48.5 48 GHCi> round 49.5 50 </code></pre> <p>The only difference is that <code>printf</code> isn't using <code>round</code> — presumably because it has to be able to round to more than just whole integers. I don't think IEEE 754 specifies anything about how to implement <code>printf</code>... | 8, 12, 387, 580, 1925 | bash, c, haskell, perl, ruby | <h1>Strange "half to even" rounding in different languages</h1>
<p>GNU bash, version 4.2.24:</p>
<pre><code>$> printf "%.0f, %.0f\n" 48.5 49.5
48, 50
</code></pre>
<p>Ruby 1.8.7</p>
<pre><code>> printf( "%.0f, %.0f\n", 48.5, 49.5 )
48, 50
</code></pre>
<p>Perl 5.12.4</p>
<pre><code>$> perl -e 'printf( "%.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,301 | bash | # Strange "half to even" rounding in different languages
GNU bash, version 4.2.24:
```
$> printf "%.0f, %.0f\n" 48.5 49.5
48, 50
```
Ruby 1.8.7
```
> printf( "%.0f, %.0f\n", 48.5, 49.5 )
48, 50
```
Perl 5.12.4
```
$> perl -e 'printf( "%.0f, %.0f\n", 48.5, 49.5 )'
48, 50
```
gcc 4.5.3:
```
> printf( "%.0f, %.0f\... | ```
GHCi> round 48.5
48
GHCi> round 49.5
50
```
The only difference is that `printf` isn't using `round` — presumably because it has to be able to round to more than just whole integers. I don't think IEEE 754 specifies anything about how to implement `printf`-style formatting functions, just rounding, which Haskell d... |
7747673 | How to alias an export in bash | 12 | 2011-10-12 23:14:42 | <p>I am trying to set an env variable which I can use to do relative directory chains. I am trying to do it the following way but cant get it to work. How do I do it?</p>
<pre><code>alias sroot="export SROOT="$PWD""
alias drumit="cd $SROOT/abc/def/drumit"
</code></pre>
<p>If I type sroot, ... | 37,818 | 992,421 | 2021-03-17 14:38:33 | 7,747,758 | 11 | 2011-10-12 23:27:09 | 125,170 | 2011-10-12 23:27:09 | https://stackoverflow.com/q/7747673 | https://stackoverflow.com/a/7747758 | <p>Your $PWD and $SROOT variables are being expanded at the time you define the aliases, not when you are using them. Put a \ in front of them to escape them while they are defined.</p>
<pre><code>alias sroot="export SROOT="\$PWD""
alias drumit="cd \$SROOT/abc/def/drumit"
</code></pre>
| <p>Your $PWD and $SROOT variables are being expanded at the time you define the aliases, not when you are using them. Put a \ in front of them to escape them while they are defined.</p> <pre><code>alias sroot="export SROOT="\$PWD"" alias drumit="cd \$SROOT/abc/def/drumit" </code></pre> | 387, 1448, 4167 | alias, bash, export | <h1>How to alias an export in bash</h1>
<p>I am trying to set an env variable which I can use to do relative directory chains. I am trying to do it the following way but cant get it to work. How do I do it?</p>
<pre><code>alias sroot="export SROOT="$PWD""
alias drumit="cd $SROOT/abc/def/drumit&... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,302 | bash | # How to alias an export in bash
I am trying to set an env variable which I can use to do relative directory chains. I am trying to do it the following way but cant get it to work. How do I do it?
```
alias sroot="export SROOT="$PWD""
alias drumit="cd $SROOT/abc/def/drumit"
```
If I type sroot, it takes the alias bu... | Your $PWD and $SROOT variables are being expanded at the time you define the aliases, not when you are using them. Put a \ in front of them to escape them while they are defined.
```
alias sroot="export SROOT="\$PWD""
alias drumit="cd \$SROOT/abc/def/drumit"
``` |
5631600 | Executing unix shell commands using PHP | 12 | 2011-04-12 07:09:02 | <p>A text box will be used to capture the command. I've been told that I have to use the <code>exec()</code> function to execute UNIX shell commands.</p>
<p>Something like this, user types ls in the text box. The <code>exec()</code> function will execute the UNIX command and the command will be displayed on the web pa... | 37,570 | 478,636 | 2015-04-14 08:15:23 | 5,631,631 | 11 | 2011-04-12 07:11:46 | 276,382 | 2011-04-12 07:19:12 | https://stackoverflow.com/q/5631600 | https://stackoverflow.com/a/5631631 | <p>You could start looking at the php manual:</p>
<p><a href="http://de.php.net/manual/en/book.exec.php" rel="noreferrer">System program execution</a></p>
<p>But like sdleihssirhc mentioned, watchout this IS very dangerous and you should <strong>NOT</strong> allow everything to be executed!<br>
If you still want to d... | <p>You could start looking at the php manual:</p> <p><a href="http://de.php.net/manual/en/book.exec.php" rel="noreferrer">System program execution</a></p> <p>But like sdleihssirhc mentioned, watchout this IS very dangerous and you should <strong>NOT</strong> allow everything to be executed!<br> If you still want to d... | 5, 34, 390 | php, shell, unix | <h1>Executing unix shell commands using PHP</h1>
<p>A text box will be used to capture the command. I've been told that I have to use the <code>exec()</code> function to execute UNIX shell commands.</p>
<p>Something like this, user types ls in the text box. The <code>exec()</code> function will execute the UNIX comman... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,303 | bash | # Executing unix shell commands using PHP
A text box will be used to capture the command. I've been told that I have to use the `exec()` function to execute UNIX shell commands.
Something like this, user types ls in the text box. The `exec()` function will execute the UNIX command and the command will be displayed on... | You could start looking at the php manual:
[System program execution](http://de.php.net/manual/en/book.exec.php)
But like sdleihssirhc mentioned, watchout this IS very dangerous and you should **NOT** allow everything to be executed!
If you still want to do it, to get the output of the shell, just use
[exec](http:... |
3890204 | What is up with this PowerShell command line quoting/escaping? | 12 | 2010-10-08 11:53:06 | <p>I obviously don't know what I'm doing.</p>
<p>I have finally got this PowerShell command to work. But I can't figure out why it works.</p>
<p>My concern is the final "" characters:</p>
<pre><code> &"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" `
-verb:sync `
-source:contentPath="$build_d... | 5,620 | 64,105 | 2019-03-04 20:05:06 | 3,890,440 | 11 | 2010-10-08 12:28:05 | 323,582 | 2010-10-08 12:42:25 | https://stackoverflow.com/q/3890204 | https://stackoverflow.com/a/3890440 | <p>This is a notorious issue. The ticket “Executing commands which require quotes and variables is practically impossible” is the most voted bug: <a href="https://connect.microsoft.com/PowerShell/Feedback" rel="nofollow noreferrer">https://connect.microsoft.com/PowerShell/Feedback</a></p>
<p>You can find there a few w... | <p>This is a notorious issue. The ticket “Executing commands which require quotes and variables is practically impossible” is the most voted bug: <a href="https://connect.microsoft.com/PowerShell/Feedback" rel="nofollow noreferrer">https://connect.microsoft.com/PowerShell/Feedback</a></p> <p>You can find there a few w... | 526, 17062, 25779 | msdeploy, powershell, psake | <h1>What is up with this PowerShell command line quoting/escaping?</h1>
<p>I obviously don't know what I'm doing.</p>
<p>I have finally got this PowerShell command to work. But I can't figure out why it works.</p>
<p>My concern is the final "" characters:</p>
<pre><code> &"C:\Program Files\IIS\Microsoft Web D... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,304 | bash | # What is up with this PowerShell command line quoting/escaping?
I obviously don't know what I'm doing.
I have finally got this PowerShell command to work. But I can't figure out why it works.
My concern is the final "" characters:
```
&"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" `
-verb:sync `... | This is a notorious issue. The ticket “Executing commands which require quotes and variables is practically impossible” is the most voted bug: <https://connect.microsoft.com/PowerShell/Feedback>
You can find there a few workarounds as well. But I would recommend you to compose all the parameters as an *array* and use ... |
3679974 | Run shell command with input redirections from python 2.4? | 12 | 2010-09-09 19:38:56 | <p>What I'd like to achieve is the launch of the following shell command:</p>
<pre><code>mysql -h hostAddress -u userName -p userPassword
databaseName < fileName
</code></pre>
<p>From within a python 2.4 script with something not unlike:</p>
<pre><code>cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName, "<", f... | 8,482 | 443,779 | 2010-09-09 20:54:20 | 3,680,037 | 11 | 2010-09-09 19:47:27 | 20,310 | 2010-09-09 20:18:26 | https://stackoverflow.com/q/3679974 | https://stackoverflow.com/a/3680037 | <p>You have to feed the file into mysql stdin by yourself. This should do it.</p>
<pre><code>import subprocess
...
filename = ...
cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName]
f = open(filename)
subprocess.call(cmd, stdin=f)
</code></pre>
| <p>You have to feed the file into mysql stdin by yourself. This should do it.</p> <pre><code>import subprocess ... filename = ... cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName] f = open(filename) subprocess.call(cmd, stdin=f) </code></pre> | 16, 390, 26698 | io-redirection, python, shell | <h1>Run shell command with input redirections from python 2.4?</h1>
<p>What I'd like to achieve is the launch of the following shell command:</p>
<pre><code>mysql -h hostAddress -u userName -p userPassword
databaseName < fileName
</code></pre>
<p>From within a python 2.4 script with something not unlike:</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,305 | bash | # Run shell command with input redirections from python 2.4?
What I'd like to achieve is the launch of the following shell command:
```
mysql -h hostAddress -u userName -p userPassword
databaseName < fileName
```
From within a python 2.4 script with something not unlike:
```
cmd = ["mysql", "-h", ip, "-u", mysqlUs... | You have to feed the file into mysql stdin by yourself. This should do it.
```
import subprocess
...
filename = ...
cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName]
f = open(filename)
subprocess.call(cmd, stdin=f)
``` |
3533253 | How to simulate a cron job | 12 | 2010-08-20 17:17:06 | <p>I want to run a script once day (and only on weekends), however, I cannot use cron job for that.</p>
<p>I was thinking about having an infinite while loop, sleep for 24 hours, check if it is a weekend, and if so execute the script.</p>
<p>What it's a good solution under bash on linux?</p>
<p>my current implementa... | 3,390 | 149,045 | 2017-07-12 15:37:42 | 3,535,453 | 11 | 2010-08-20 23:05:50 | 23,744 | 2010-09-07 12:48:12 | https://stackoverflow.com/q/3533253 | https://stackoverflow.com/a/3535453 | <p>Back in the day when there were no per-user crontabs, I often accomplished this using at(1).</p>
<pre><code>#!/bin/sh
... do stuff...
at -f /path/to/me 5pm tomorrow
</code></pre>
<p>This way your script runs and schedules itself for the next invocation.</p>
<p>I don't think you can specify a timespec of "next wee... | <p>Back in the day when there were no per-user crontabs, I often accomplished this using at(1).</p> <pre><code>#!/bin/sh ... do stuff... at -f /path/to/me 5pm tomorrow </code></pre> <p>This way your script runs and schedules itself for the next invocation.</p> <p>I don't think you can specify a timespec of "next wee... | 387, 531, 580, 601 | bash, cron, perl, scripting | <h1>How to simulate a cron job</h1>
<p>I want to run a script once day (and only on weekends), however, I cannot use cron job for that.</p>
<p>I was thinking about having an infinite while loop, sleep for 24 hours, check if it is a weekend, and if so execute the script.</p>
<p>What it's a good solution under bash on ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,306 | bash | # How to simulate a cron job
I want to run a script once day (and only on weekends), however, I cannot use cron job for that.
I was thinking about having an infinite while loop, sleep for 24 hours, check if it is a weekend, and if so execute the script.
What it's a good solution under bash on linux?
my current impl... | Back in the day when there were no per-user crontabs, I often accomplished this using at(1).
```
#!/bin/sh
... do stuff...
at -f /path/to/me 5pm tomorrow
```
This way your script runs and schedules itself for the next invocation.
I don't think you can specify a timespec of "next weekend", so you'll just have to resc... |
2839810 | Converting a bash script to python (small script) | 12 | 2010-05-15 10:47:53 | <p>I’ve a bash script I’ve been using for a Linux environment but now I have to use it on a Windows platform and want to convert the bash script to a python script which I can run.</p>
<p>The bash script is rather simple (I think) and I’ve tried to convert it by google by way around but can’t convert it successfully.<... | 55,516 | 188,082 | 2016-07-13 21:00:49 | 2,840,002 | 11 | 2010-05-15 11:55:14 | 303,180 | 2010-05-15 12:08:28 | https://stackoverflow.com/q/2839810 | https://stackoverflow.com/a/2840002 | <p>It should be fairly simple to port your program. The only tricky part will be running the db2 command and (maybe) refactoring reads.py so that it can be called as a library function.</p>
<p>The basic idea is the same:</p>
<ul>
<li>Setting local variables is the same.</li>
<li>Replace <code>echo</code> with <code>... | <p>It should be fairly simple to port your program. The only tricky part will be running the db2 command and (maybe) refactoring reads.py so that it can be called as a library function.</p> <p>The basic idea is the same:</p> <ul> <li>Setting local variables is the same.</li> <li>Replace <code>echo</code> with <code>... | 16, 387 | bash, python | <h1>Converting a bash script to python (small script)</h1>
<p>I’ve a bash script I’ve been using for a Linux environment but now I have to use it on a Windows platform and want to convert the bash script to a python script which I can run.</p>
<p>The bash script is rather simple (I think) and I’ve tried to convert it ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,307 | bash | # Converting a bash script to python (small script)
I’ve a bash script I’ve been using for a Linux environment but now I have to use it on a Windows platform and want to convert the bash script to a python script which I can run.
The bash script is rather simple (I think) and I’ve tried to convert it by google by way... | It should be fairly simple to port your program. The only tricky part will be running the db2 command and (maybe) refactoring reads.py so that it can be called as a library function.
The basic idea is the same:
- Setting local variables is the same.
- Replace `echo` with `print`.
- Replace your loop with `for r in ra... |
78570018 | -bash: cannot execute: required file not found | 11 | 2024-06-03 11:31:33 | <p>I am having multiple problems with making my pythonscript dartsapp.py executable for my pi.</p>
<p>At first i tried to use</p>
<pre><code>chmod +x dartsapp.py
</code></pre>
<p>and</p>
<pre><code>./dartsapp.py
</code></pre>
<p>but i got the error:</p>
<pre><code>-bash: ./dartsapp.py: cannot execute: required file not... | 32,286 | 25,224,706 | 2025-03-16 01:48:06 | 78,570,143 | 11 | 2024-06-03 12:01:38 | 1,745,001 | 2024-06-03 12:01:38 | https://stackoverflow.com/q/78570018 | https://stackoverflow.com/a/78570143 | <pre><code>head -n 3 dartsapp.py | cat -e
</code></pre>
<p>outputs:</p>
<pre><code>#!/usr/bin/python3^M$
^M$
# Python-App fM-CM-<r das PunktezM-CM-$hlen beim Darts^M$
</code></pre>
<p>and so those <code>^Ms</code> at the end of each line tells us that <code>dartsapp.py</code> has DOS line endings, see <a href="https... | <pre><code>head -n 3 dartsapp.py | cat -e </code></pre> <p>outputs:</p> <pre><code>#!/usr/bin/python3^M$ ^M$ # Python-App fM-CM-<r das PunktezM-CM-$hlen beim Darts^M$ </code></pre> <p>and so those <code>^Ms</code> at the end of each line tells us that <code>dartsapp.py</code> has DOS line endings, see <a href="https... | 16, 387, 14766 | bash, pyinstaller, python | <h1>-bash: cannot execute: required file not found</h1>
<p>I am having multiple problems with making my pythonscript dartsapp.py executable for my pi.</p>
<p>At first i tried to use</p>
<pre><code>chmod +x dartsapp.py
</code></pre>
<p>and</p>
<pre><code>./dartsapp.py
</code></pre>
<p>but i got the error:</p>
<pre><code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,308 | bash | # -bash: cannot execute: required file not found
I am having multiple problems with making my pythonscript dartsapp.py executable for my pi.
At first i tried to use
```
chmod +x dartsapp.py
```
and
```
./dartsapp.py
```
but i got the error:
```
-bash: ./dartsapp.py: cannot execute: required file not found
```
I... | ```
head -n 3 dartsapp.py | cat -e
```
outputs:
```
#!/usr/bin/python3^M$
^M$
# Python-App fM-CM-<r das PunktezM-CM-$hlen beim Darts^M$
```
and so those `^Ms` at the end of each line tells us that `dartsapp.py` has DOS line endings, see [linux-bash-shell-script-error-cannot-execute-required-file-not-found](https://u... |
74485129 | removing duplicated strings within a column with shell | 11 | 2022-11-18 05:02:02 | <p>I have a file with two columns separated by tabs as follows:</p>
<pre><code>OG0000000 PF03169,PF03169,PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,PF00083,PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG0000005 PF00012,PF01061,PF12697,PF00012,
</code></pre>
<p>I just wa... | 312 | 7,552,213 | 2022-11-19 16:10:52 | 74,485,625 | 11 | 2022-11-18 06:22:22 | 548,225 | 2022-11-19 16:10:52 | https://stackoverflow.com/q/74485129 | https://stackoverflow.com/a/74485625 | <p>This <code>awk</code> should work for you:</p>
<pre class="lang-bash prettyprint-override"><code>awk -F '[\t,]' '
{
printf "%s", $1 "\t"
for (i=2; i<=NF; ++i) {
if (!seen[$i]++)
printf "%s,", $i
}
print ""
delete seen
}' file
OG0000000 PF031... | <p>This <code>awk</code> should work for you:</p> <pre class="lang-bash prettyprint-override"><code>awk -F '[\t,]' ' { printf "%s", $1 "\t" for (i=2; i<=NF; ++i) { if (!seen[$i]++) printf "%s,", $i } print "" delete seen }' file OG0000000 PF031... | 390, 990, 5282 | awk, sed, shell | <h1>removing duplicated strings within a column with shell</h1>
<p>I have a file with two columns separated by tabs as follows:</p>
<pre><code>OG0000000 PF03169,PF03169,PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,PF00083,PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG00000... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,309 | bash | # removing duplicated strings within a column with shell
I have a file with two columns separated by tabs as follows:
```
OG0000000 PF03169,PF03169,PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,PF00083,PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF00690,
OG0000005 PF00012,PF0106... | This `awk` should work for you:
```
awk -F '[\t,]' '
{
printf "%s", $1 "\t"
for (i=2; i<=NF; ++i) {
if (!seen[$i]++)
printf "%s,", $i
}
print ""
delete seen
}' file
OG0000000 PF03169,MAC1_004431-T1,
OG0000002 PF07690,PF00083,
OG0000003 MAC1_000127-T1,
OG0000004 PF13246,PF00689,PF... |
69075612 | Cross-platform method to detect whether /dev/tty is available & functional | 11 | 2021-09-06 13:44:58 | <p>I have a bash script from which I want to access /dev/tty, but only when it's available.</p>
<p>When it's not available (in my case: when running my script in GitHub Actions) then when I try to access it I get <code>/dev/tty: No such device or address</code>, and I'm trying to detect that in advance to avoid the err... | 5,046 | 68,051 | 2022-04-20 12:48:24 | 69,088,164 | 11 | 2021-09-07 12:21:44 | 68,051 | 2022-04-20 12:39:17 | https://stackoverflow.com/q/69075612 | https://stackoverflow.com/a/69088164 | <p>After testing lots of promising but not quite perfect suggestions (see the other answers), I think I've found my own solution that does exactly fit my needs:</p>
<pre class="lang-sh prettyprint-override"><code>if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
# /dev/tty is available and usab... | <p>After testing lots of promising but not quite perfect suggestions (see the other answers), I think I've found my own solution that does exactly fit my needs:</p> <pre class="lang-sh prettyprint-override"><code>if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then # /dev/tty is available and usab... | 58, 369, 387, 390, 17165 | bash, linux, macos, shell, tty | <h1>Cross-platform method to detect whether /dev/tty is available & functional</h1>
<p>I have a bash script from which I want to access /dev/tty, but only when it's available.</p>
<p>When it's not available (in my case: when running my script in GitHub Actions) then when I try to access it I get <code>/dev/tty: No such... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,310 | bash | # Cross-platform method to detect whether /dev/tty is available & functional
I have a bash script from which I want to access /dev/tty, but only when it's available.
When it's not available (in my case: when running my script in GitHub Actions) then when I try to access it I get `/dev/tty: No such device or address`,... | After testing lots of promising but not quite perfect suggestions (see the other answers), I think I've found my own solution that does exactly fit my needs:
```
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
# /dev/tty is available and usable
else
# /dev/tty is not available
fi
```
To explain:
`: >/dev... |
64412442 | PowerShell Out-File outputs extra spaces in between characters | 11 | 2020-10-18 10:52:15 | <p>I'm using a simple script that outputs current directory's path inside a log file:</p>
<pre><code>(Get-Item .).FullName | out-file "C:\windows\system32\rcwm\rc.log" -append
</code></pre>
<p>This works most of the time. However, seemingly at random, appending will result in added spaces after every characte... | 15,177 | 10,307,457 | 2025-02-18 06:03:22 | 64,412,443 | 11 | 2020-10-18 10:52:15 | 10,307,457 | 2022-03-26 09:31:58 | https://stackoverflow.com/q/64412442 | https://stackoverflow.com/a/64412443 | <p>After some time, I decided to try to change the encodings with which powershell outputs strings inside my log file.</p>
<p>I still don't understand why or how powershell decides which encoding to use, but it's best if <em>you</em> let powershell know which encoding you want to use:</p>
<pre><code>(Get-Item .).FullNa... | <p>After some time, I decided to try to change the encodings with which powershell outputs strings inside my log file.</p> <p>I still don't understand why or how powershell decides which encoding to use, but it's best if <em>you</em> let powershell know which encoding you want to use:</p> <pre><code>(Get-Item .).FullNa... | 139, 526, 1124, 12658, 84917 | character-encoding, encoding, output, powershell, string | <h1>PowerShell Out-File outputs extra spaces in between characters</h1>
<p>I'm using a simple script that outputs current directory's path inside a log file:</p>
<pre><code>(Get-Item .).FullName | out-file "C:\windows\system32\rcwm\rc.log" -append
</code></pre>
<p>This works most of the time. However, seeming... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,311 | bash | # PowerShell Out-File outputs extra spaces in between characters
I'm using a simple script that outputs current directory's path inside a log file:
```
(Get-Item .).FullName | out-file "C:\windows\system32\rcwm\rc.log" -append
```
This works most of the time. However, seemingly at random, appending will result in ad... | After some time, I decided to try to change the encodings with which powershell outputs strings inside my log file.
I still don't understand why or how powershell decides which encoding to use, but it's best if *you* let powershell know which encoding you want to use:
```
(Get-Item .).FullName | out-file "C:\windows\... |
58597755 | import Azure Devops pipeline variables from json file | 11 | 2019-10-28 20:11:46 | <p>I want to use json file to store variables used by powershell script. In azure devops I have configured pipeline, pipeline contains powershell script with a list of variables in it. I would like to use json file and store in this file all variables. I want to store json file in Azure repo, and use it once pipeline i... | 21,941 | 8,512,333 | 2020-02-06 15:33:10 | 58,600,981 | 11 | 2019-10-29 03:10:56 | 11,439,664 | 2019-10-29 07:51:26 | https://stackoverflow.com/q/58597755 | https://stackoverflow.com/a/58600981 | <p>Why not directly to use the Powershell built-in cmdlet: <code>ConvertFrom-Json</code>. See this official doc about this cmdlet description: <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-6" rel="noreferrer">Powershell: ConvertFrom-Json</a>.<... | <p>Why not directly to use the Powershell built-in cmdlet: <code>ConvertFrom-Json</code>. See this official doc about this cmdlet description: <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-6" rel="noreferrer">Powershell: ConvertFrom-Json</a>.<... | 1508, 81879, 116537, 119596 | azure-devops, azure-pipelines, azure-powershell, json | <h1>import Azure Devops pipeline variables from json file</h1>
<p>I want to use json file to store variables used by powershell script. In azure devops I have configured pipeline, pipeline contains powershell script with a list of variables in it. I would like to use json file and store in this file all variables. I wa... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,312 | bash | # import Azure Devops pipeline variables from json file
I want to use json file to store variables used by powershell script. In azure devops I have configured pipeline, pipeline contains powershell script with a list of variables in it. I would like to use json file and store in this file all variables. I want to sto... | Why not directly to use the Powershell built-in cmdlet: `ConvertFrom-Json`. See this official doc about this cmdlet description: [Powershell: ConvertFrom-Json](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-6).
You can add the script:
```
Get-Content ... |
31313305 | Portably trapping ERR in shell script | 11 | 2015-07-09 09:22:58 | <p>I'm trying to write a shell script that aborts when a command fails and displays the offending line number.</p>
<pre><code>set -e
trap 'echo "$0 FAILED at line ${LINENO}"' ERR
</code></pre>
<p>Turned out the trap line does not work with Ubuntu's default shell script interpreter, dash. If I change the shebang line ... | 7,047 | 363,949 | 2019-10-09 05:19:20 | 58,297,505 | 11 | 2019-10-09 05:19:20 | 3,105,901 | 2019-10-09 05:19:20 | https://stackoverflow.com/q/31313305 | https://stackoverflow.com/a/58297505 | <p>You can trap on exit and test the exit code like this:</p>
<pre><code>set -e
trap '[ $? -eq 0 ] && exit 0 || echo "$0 FAILED at line ${LINENO}"' EXIT
</code></pre>
| <p>You can trap on exit and test the exit code like this:</p> <pre><code>set -e trap '[ $? -eq 0 ] && exit 0 || echo "$0 FAILED at line ${LINENO}"' EXIT </code></pre> | 379, 387, 390, 137448 | bash, dash-shell, error-handling, shell | <h1>Portably trapping ERR in shell script</h1>
<p>I'm trying to write a shell script that aborts when a command fails and displays the offending line number.</p>
<pre><code>set -e
trap 'echo "$0 FAILED at line ${LINENO}"' ERR
</code></pre>
<p>Turned out the trap line does not work with Ubuntu's default shell script i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,313 | bash | # Portably trapping ERR in shell script
I'm trying to write a shell script that aborts when a command fails and displays the offending line number.
```
set -e
trap 'echo "$0 FAILED at line ${LINENO}"' ERR
```
Turned out the trap line does not work with Ubuntu's default shell script interpreter, dash. If I change the... | You can trap on exit and test the exit code like this:
```
set -e
trap '[ $? -eq 0 ] && exit 0 || echo "$0 FAILED at line ${LINENO}"' EXIT
``` |
38738862 | Run a UEFI shell command from inside UEFI application | 11 | 2016-08-03 08:53:58 | <p>I'm new to UEFI application development.</p>
<p>My requirement is that,</p>
<p>I need to run an UEFI shell command from my UEFI application (<code>app.efi</code>) source code.
Need guidance on how I can do this.</p>
<p>Example,</p>
<blockquote>
<p><code>cp</code> command in UEFI shell is used to copy a file fr... | 6,269 | 2,006,333 | 2018-10-25 01:49:04 | 52,862,057 | 11 | 2018-10-17 19:12:54 | 10,520,161 | 2018-10-18 17:04:58 | https://stackoverflow.com/q/38738862 | https://stackoverflow.com/a/52862057 | <p>Calling a UEFI shell command from a UEFI application can be done using the <code>EFI_SHELL_EXECUTE</code> function of <code>EFI_SHELL_PROTOCOL</code>, defined under <code>MdePkg/Include/Protocol/Shell.h</code>.</p>
<p>You need to include the protocol GUID in the inf file of your UEFI application:</p>
<pre><code>[P... | <p>Calling a UEFI shell command from a UEFI application can be done using the <code>EFI_SHELL_EXECUTE</code> function of <code>EFI_SHELL_PROTOCOL</code>, defined under <code>MdePkg/Include/Protocol/Shell.h</code>.</p> <p>You need to include the protocol GUID in the inf file of your UEFI application:</p> <pre><code>[P... | 390, 1796, 32808, 95406 | bootloader, command, shell, uefi | <h1>Run a UEFI shell command from inside UEFI application</h1>
<p>I'm new to UEFI application development.</p>
<p>My requirement is that,</p>
<p>I need to run an UEFI shell command from my UEFI application (<code>app.efi</code>) source code.
Need guidance on how I can do this.</p>
<p>Example,</p>
<blockquote>
<p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,314 | bash | # Run a UEFI shell command from inside UEFI application
I'm new to UEFI application development.
My requirement is that,
I need to run an UEFI shell command from my UEFI application (`app.efi`) source code.
Need guidance on how I can do this.
Example,
> `cp` command in UEFI shell is used to copy a file from one pa... | Calling a UEFI shell command from a UEFI application can be done using the `EFI_SHELL_EXECUTE` function of `EFI_SHELL_PROTOCOL`, defined under `MdePkg/Include/Protocol/Shell.h`.
You need to include the protocol GUID in the inf file of your UEFI application:
```
[Protocols]
gEfiShellProtocolGuid ## ... |
50214436 | Executing 'bash -c' in 'docker exec' command | 11 | 2018-05-07 12:37:41 | <p><em>Context:</em> I'm trying to write a shortcut for my daily use of the <code>docker exec</code> command. For some reasons, I'm experimenting the problem that my output is sometimes broken when I'm using a bash console inside a container (history messed up, lines overwrite each other as I'm writing, ...)</p>
<p>I... | 18,811 | 5,018,771 | 2018-05-07 13:47:09 | 50,215,203 | 11 | 2018-05-07 13:17:31 | 7,200,715 | 2018-05-07 13:47:09 | https://stackoverflow.com/q/50214436 | https://stackoverflow.com/a/50215203 | <p>It's not Docker related, but Bash (<em>In other words, the docker's part of the command works well, it's just bash grumbling on the container like it would grumble on your host</em>):</p>
<h3>Minimal reproducible error</h3>
<pre><code>cmd='bash -c "echo hello"'
$cmd
hello": -c: line 0: unexpected EOF while lookin... | <p>It's not Docker related, but Bash (<em>In other words, the docker's part of the command works well, it's just bash grumbling on the container like it would grumble on your host</em>):</p> <h3>Minimal reproducible error</h3> <pre><code>cmd='bash -c "echo hello"' $cmd hello": -c: line 0: unexpected EOF while lookin... | 387, 90304, 128467 | bash, docker, docker-exec | <h1>Executing 'bash -c' in 'docker exec' command</h1>
<p><em>Context:</em> I'm trying to write a shortcut for my daily use of the <code>docker exec</code> command. For some reasons, I'm experimenting the problem that my output is sometimes broken when I'm using a bash console inside a container (history messed up, lin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,315 | bash | # Executing 'bash -c' in 'docker exec' command
*Context:* I'm trying to write a shortcut for my daily use of the `docker exec` command. For some reasons, I'm experimenting the problem that my output is sometimes broken when I'm using a bash console inside a container (history messed up, lines overwrite each other as I... | It's not Docker related, but Bash (*In other words, the docker's part of the command works well, it's just bash grumbling on the container like it would grumble on your host*):
### Minimal reproducible error
```
cmd='bash -c "echo hello"'
$cmd
hello": -c: line 0: unexpected EOF while looking for matching `"'
hello":... |
44374914 | Escaping ampersand within a string variable using sed | 11 | 2017-06-05 17:58:07 | <p>I am replacing the text <code>SUBJECT</code> with a value from an array variable like this: </p>
<pre><code>#!/bin/bash
# array of subjects, the ampersand causes a problem.
subjects=("Digital Art" "Digital Photography" "3D Modelling & Animation")
echo $subjects[2] # Subject: 3D Modelling & Animation
sed ... | 8,092 | 2,700,631 | 2022-11-17 16:09:17 | 44,375,021 | 11 | 2017-06-05 18:05:20 | 548,225 | 2017-06-05 18:05:20 | https://stackoverflow.com/q/44374914 | https://stackoverflow.com/a/44375021 | <p>Problem is presence of <code>&</code> in your replacement text. <code>&</code> makes <code>sed</code> place fully matched text in replacement hence <code>SUBJECT</code> appears in output.</p>
<p>You can use this trick:</p>
<pre><code>sed -i "s/SUBJECT/${subjects[2]//&/\\&}/g" test.svg
</code></pre>... | <p>Problem is presence of <code>&</code> in your replacement text. <code>&</code> makes <code>sed</code> place fully matched text in replacement hence <code>SUBJECT</code> appears in output.</p> <p>You can use this trick:</p> <pre><code>sed -i "s/SUBJECT/${subjects[2]//&/\\&}/g" test.svg </code></pre>... | 387, 5282 | bash, sed | <h1>Escaping ampersand within a string variable using sed</h1>
<p>I am replacing the text <code>SUBJECT</code> with a value from an array variable like this: </p>
<pre><code>#!/bin/bash
# array of subjects, the ampersand causes a problem.
subjects=("Digital Art" "Digital Photography" "3D Modelling & Animation")
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,316 | bash | # Escaping ampersand within a string variable using sed
I am replacing the text `SUBJECT` with a value from an array variable like this:
```
#!/bin/bash
# array of subjects, the ampersand causes a problem.
subjects=("Digital Art" "Digital Photography" "3D Modelling & Animation")
echo $subjects[2] # Subject: 3D Mode... | Problem is presence of `&` in your replacement text. `&` makes `sed` place fully matched text in replacement hence `SUBJECT` appears in output.
You can use this trick:
```
sed -i "s/SUBJECT/${subjects[2]//&/\\&}/g" test.svg
```
`${subjects[2]//&/\\&}` replaces each `&` with `\&` in 2nd element of `subjects` array be... |
43241124 | In Powershell, what is $input for? | 11 | 2017-04-05 20:35:12 | <p>I was trying to create a hash table,</p>
<pre><code>$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
</code></pre>
<p>and could not figure out for the life of me why it wouldn't display as usual with commands like <code>write-host</code>, or simply <code>$input</code>. <code>write-host</code> returned <code>System.Colle... | 8,093 | 4,504,862 | 2017-04-05 20:46:47 | 43,241,218 | 11 | 2017-04-05 20:40:01 | 3,905,079 | 2017-04-05 20:43:52 | https://stackoverflow.com/q/43241124 | https://stackoverflow.com/a/43241218 | <p><a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables" rel="noreferrer">It's an automatic variable</a>:</p>
<blockquote>
<h2><code>$INPUT</code></h2>
<p>Contains an enumerator that enumerates all input that is passed
to a function. The ... | <p><a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables" rel="noreferrer">It's an automatic variable</a>:</p> <blockquote> <h2><code>$INPUT</code></h2> <p>Contains an enumerator that enumerates all input that is passed to a function. The ... | 526 | powershell | <h1>In Powershell, what is $input for?</h1>
<p>I was trying to create a hash table,</p>
<pre><code>$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
</code></pre>
<p>and could not figure out for the life of me why it wouldn't display as usual with commands like <code>write-host</code>, or simply <code>$input</code>. <code>w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,317 | bash | # In Powershell, what is $input for?
I was trying to create a hash table,
```
$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
```
and could not figure out for the life of me why it wouldn't display as usual with commands like `write-host`, or simply `$input`. `write-host` returned `System.Collections.ArrayList+ArrayListEn... | [It's an automatic variable](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables):
> ## `$INPUT`
>
> Contains an enumerator that enumerates all input that is passed
> to a function. The `$input` variable is available only to functions and
> script blocks ... |
42510388 | How to start local Azure Service Fabric Cluster with PowerShell or CLI | 11 | 2017-02-28 13:42:59 | <p>I am developing in Azure Service Fabric and there are several times when the Service Fabric is not started for some reason (usually after a reboot). The Service Fabric Manager in the system tray has horrible response time (if it responds at all).</p>
<p>Is there a PowerShell cmdlet or even a cli command that I can ... | 5,879 | 724,317 | 2017-08-18 13:14:15 | 42,513,134 | 11 | 2017-02-28 15:47:57 | 4,079,967 | 2017-02-28 15:47:57 | https://stackoverflow.com/q/42510388 | https://stackoverflow.com/a/42513134 | <p>You can just use the <code>Start-Service</code> cmdlet</p>
<pre><code>PS C:\windows\system32> Start-Service FabricHostSvc
WARNING: Waiting for service 'Microsoft Service Fabric Host Service (FabricHostSvc)' to start...
</code></pre>
<p>You can also check if the host is running by running <code>Get-Service</code... | <p>You can just use the <code>Start-Service</code> cmdlet</p> <pre><code>PS C:\windows\system32> Start-Service FabricHostSvc WARNING: Waiting for service 'Microsoft Service Fabric Host Service (FabricHostSvc)' to start... </code></pre> <p>You can also check if the host is running by running <code>Get-Service</code... | 526, 14158, 111637 | azure, azure-service-fabric, powershell | <h1>How to start local Azure Service Fabric Cluster with PowerShell or CLI</h1>
<p>I am developing in Azure Service Fabric and there are several times when the Service Fabric is not started for some reason (usually after a reboot). The Service Fabric Manager in the system tray has horrible response time (if it responds... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,318 | bash | # How to start local Azure Service Fabric Cluster with PowerShell or CLI
I am developing in Azure Service Fabric and there are several times when the Service Fabric is not started for some reason (usually after a reboot). The Service Fabric Manager in the system tray has horrible response time (if it responds at all).... | You can just use the `Start-Service` cmdlet
```
PS C:\windows\system32> Start-Service FabricHostSvc
WARNING: Waiting for service 'Microsoft Service Fabric Host Service (FabricHostSvc)' to start...
```
You can also check if the host is running by running `Get-Service`
```
PS C:\windows\system32> Get-Service Fabrichos... |
40415960 | How to split file by percentage of no. of lines? | 11 | 2016-11-04 05:38:02 | <p><strong>How to split file by percentage of no. of lines?</strong></p>
<p>Let's say I want to split my file into 3 portions (60%/20%/20% parts), I could do this manually, -_- :</p>
<pre><code>$ wc -l brown.txt
57339 brown.txt
$ bc <<< "57339 / 10 * 6"
34398
$ bc <<< "57339 / 10 * 2"
11466
$ bc &... | 3,807 | 610,569 | 2024-10-22 03:27:01 | 42,125,973 | 11 | 2017-02-09 00:08:48 | 3,266,847 | 2017-02-10 16:07:41 | https://stackoverflow.com/q/40415960 | https://stackoverflow.com/a/42125973 | <p>There is a utility that takes as arguments the line numbers that should become the first of each respective new file: <code>csplit</code>. This is a wrapper around its <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/csplit.html" rel="noreferrer">POSIX version</a>:</p>
<pre><code>#!/bin/bash
usag... | <p>There is a utility that takes as arguments the line numbers that should become the first of each respective new file: <code>csplit</code>. This is a wrapper around its <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/csplit.html" rel="noreferrer">POSIX version</a>:</p> <pre><code>#!/bin/bash usag... | 387, 990, 2193, 5282, 5310 | awk, bash, file, sed, split | <h1>How to split file by percentage of no. of lines?</h1>
<p><strong>How to split file by percentage of no. of lines?</strong></p>
<p>Let's say I want to split my file into 3 portions (60%/20%/20% parts), I could do this manually, -_- :</p>
<pre><code>$ wc -l brown.txt
57339 brown.txt
$ bc <<< "57339 / 10 ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,319 | bash | # How to split file by percentage of no. of lines?
**How to split file by percentage of no. of lines?**
Let's say I want to split my file into 3 portions (60%/20%/20% parts), I could do this manually, -_- :
```
$ wc -l brown.txt
57339 brown.txt
$ bc <<< "57339 / 10 * 6"
34398
$ bc <<< "57339 / 10 * 2"
11466
$ bc <... | There is a utility that takes as arguments the line numbers that should become the first of each respective new file: `csplit`. This is a wrapper around its [POSIX version](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/csplit.html):
```
#!/bin/bash
usage () {
printf '%s\n' "${0##*/} [-ks] [-f prefix] ... |
40146155 | Erlang remote shell not working | 11 | 2016-10-20 05:30:21 | <p>I have some strange behaviour on my docker containers (CentOS). When I SSH into it there's a running instance of Erlang VM (api@127.0.0.1) I can't connect to it with -remsh argument, however I can ping it. My Erlang node (api@127.0.0.1) works correctly though.</p>
<pre><code>bash-4.2# ./bin/erl -name 'remote@127.0.... | 3,426 | 7,045,911 | 2016-10-24 17:28:38 | 40,223,638 | 11 | 2016-10-24 16:56:53 | 1,301,970 | 2016-10-24 17:28:38 | https://stackoverflow.com/q/40146155 | https://stackoverflow.com/a/40223638 | <p>What is <code>$TERM</code> in shell you're trying to open remote? There is a problem when TERM is absent or is not known to ncurses which Erlang is built against, making remote shell connection fail silently. Try this one:</p>
<p><code>TERM=xterm ./bin/erl -name 'remote@127.0.0.1' -remsh 'api@127.0.0.1'</code></p... | <p>What is <code>$TERM</code> in shell you're trying to open remote? There is a problem when TERM is absent or is not known to ncurses which Erlang is built against, making remote shell connection fail silently. Try this one:</p> <p><code>TERM=xterm ./bin/erl -name 'remote@127.0.0.1' -remsh 'api@127.0.0.1'</code></p... | 538, 51067 | erlang, erlang-shell | <h1>Erlang remote shell not working</h1>
<p>I have some strange behaviour on my docker containers (CentOS). When I SSH into it there's a running instance of Erlang VM (api@127.0.0.1) I can't connect to it with -remsh argument, however I can ping it. My Erlang node (api@127.0.0.1) works correctly though.</p>
<pre><code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,320 | bash | # Erlang remote shell not working
I have some strange behaviour on my docker containers (CentOS). When I SSH into it there's a running instance of Erlang VM (api@127.0.0.1) I can't connect to it with -remsh argument, however I can ping it. My Erlang node (api@127.0.0.1) works correctly though.
```
bash-4.2# ./bin/erl... | What is `$TERM` in shell you're trying to open remote? There is a problem when TERM is absent or is not known to ncurses which Erlang is built against, making remote shell connection fail silently. Try this one:
`TERM=xterm ./bin/erl -name 'remote@127.0.0.1' -remsh 'api@127.0.0.1'`
I once reported [the problem](http:... |
38901752 | Verify Passwords Match in Windows Powershell | 11 | 2016-08-11 16:29:48 | <p>I'm creating a script to handle unattended domain joining for the school district I work at. We have several IT guys who handle sysprep, so I'm creating a script that will encrypt passwords to use for Add-Computer. </p>
<p>What I am having trouble with is having a script that takes two password entries, and restar... | 14,271 | 6,705,970 | 2022-04-24 00:28:05 | 38,901,898 | 11 | 2016-08-11 16:39:05 | 6,101,687 | 2016-08-11 16:39:05 | https://stackoverflow.com/q/38901752 | https://stackoverflow.com/a/38901898 | <p>You're looking to compare two secure strings, so you'll need to decrypt them first. Here's an implementation of what you're trying to do: </p>
<pre><code>Write-Host "Hey..!! I am here to compare the password you are entering..."
$pwd1 = Read-Host "Passowrd" -AsSecureString
$pwd2 = Read-Host "Re-enter Passowrd" -AsS... | <p>You're looking to compare two secure strings, so you'll need to decrypt them first. Here's an implementation of what you're trying to do: </p> <pre><code>Write-Host "Hey..!! I am here to compare the password you are entering..." $pwd1 = Read-Host "Passowrd" -AsSecureString $pwd2 = Read-Host "Re-enter Passowrd" -AsS... | 526 | powershell | <h1>Verify Passwords Match in Windows Powershell</h1>
<p>I'm creating a script to handle unattended domain joining for the school district I work at. We have several IT guys who handle sysprep, so I'm creating a script that will encrypt passwords to use for Add-Computer. </p>
<p>What I am having trouble with is havin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,321 | bash | # Verify Passwords Match in Windows Powershell
I'm creating a script to handle unattended domain joining for the school district I work at. We have several IT guys who handle sysprep, so I'm creating a script that will encrypt passwords to use for Add-Computer.
What I am having trouble with is having a script that ta... | You're looking to compare two secure strings, so you'll need to decrypt them first. Here's an implementation of what you're trying to do:
```
Write-Host "Hey..!! I am here to compare the password you are entering..."
$pwd1 = Read-Host "Passowrd" -AsSecureString
$pwd2 = Read-Host "Re-enter Passowrd" -AsSecureString
$pw... |
36840315 | run composer and laravel (artisan) commands without ssh access | 11 | 2016-04-25 12:16:35 | <p>I want to test some Laravel applications on my basic shared host.</p>
<p>Currently I just upload my complete application including the vendor files, however this takes quite long.</p>
<p>Since I do not have <code>ssh</code> access to my host I'd like to know whether there's an option to run composer / artisan comm... | 9,025 | 2,940,794 | 2019-11-11 20:46:05 | 36,840,519 | 11 | 2016-04-25 12:25:48 | 1,227,923 | 2016-04-25 12:27:02 | https://stackoverflow.com/q/36840315 | https://stackoverflow.com/a/36840519 | <p>Check if your shared hosting provider has <code>console</code> feature in their CP which allows to run shell commands. Maybe you'll be able to run commands from there.</p>
<p>As alternative, you could right your own artisan runner and <a href="https://laravel.com/docs/5.1/artisan#calling-commands-via-code" rel="nor... | <p>Check if your shared hosting provider has <code>console</code> feature in their CP which allows to run shell commands. Maybe you'll be able to run commands from there.</p> <p>As alternative, you could right your own artisan runner and <a href="https://laravel.com/docs/5.1/artisan#calling-commands-via-code" rel="nor... | 5, 386, 390, 75151 | laravel, php, shell, ssh | <h1>run composer and laravel (artisan) commands without ssh access</h1>
<p>I want to test some Laravel applications on my basic shared host.</p>
<p>Currently I just upload my complete application including the vendor files, however this takes quite long.</p>
<p>Since I do not have <code>ssh</code> access to my host I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,322 | bash | # run composer and laravel (artisan) commands without ssh access
I want to test some Laravel applications on my basic shared host.
Currently I just upload my complete application including the vendor files, however this takes quite long.
Since I do not have `ssh` access to my host I'd like to know whether there's an... | Check if your shared hosting provider has `console` feature in their CP which allows to run shell commands. Maybe you'll be able to run commands from there.
As alternative, you could right your own artisan runner and [call artisan commands from the code](https://laravel.com/docs/5.1/artisan#calling-commands-via-code):... |
33598620 | Copy file with rsync or scp over multiple level or hops of SSH | 11 | 2015-11-08 20:23:59 | <p>I need to transfer around 4.2 GB of files from my <code>local computer</code> to a <code>server B</code>. However to ssh into server B, I need to ssh into <code>server A</code>.</p>
<p>Currently I'm copying files from my <code>local computer</code> to server A and then from <code>server A</code> to <code>server B</... | 3,168 | 835,149 | 2021-12-31 08:41:05 | 33,598,859 | 11 | 2015-11-08 20:45:35 | 2,196,426 | 2015-11-08 20:45:35 | https://stackoverflow.com/q/33598620 | https://stackoverflow.com/a/33598859 | <p>You can always use <code>ssh</code> with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):</p>
<pre><code>Host <server-A>
User <user-A>
Host <server-B>
User <user-B>
ProxyCommand ssh <server-A> -W %h:%p
</code></pre>
<p>Yo... | <p>You can always use <code>ssh</code> with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):</p> <pre><code>Host <server-A> User <user-A> Host <server-B> User <user-B> ProxyCommand ssh <server-A> -W %h:%p </code></pre> <p>Yo... | 386, 387, 1159, 3149, 48830 | bash, file-copying, rsync, scp, ssh | <h1>Copy file with rsync or scp over multiple level or hops of SSH</h1>
<p>I need to transfer around 4.2 GB of files from my <code>local computer</code> to a <code>server B</code>. However to ssh into server B, I need to ssh into <code>server A</code>.</p>
<p>Currently I'm copying files from my <code>local computer</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,323 | bash | # Copy file with rsync or scp over multiple level or hops of SSH
I need to transfer around 4.2 GB of files from my `local computer` to a `server B`. However to ssh into server B, I need to ssh into `server A`.
Currently I'm copying files from my `local computer` to server A and then from `server A` to `server B`.
So... | You can always use `ssh` with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):
```
Host <server-A>
User <user-A>
Host <server-B>
User <user-B>
ProxyCommand ssh <server-A> -W %h:%p
```
You can call your rsync:
```
rsync -avz --del ~/Desktop/abc/ <server-... |
33235806 | Upload BIG files via HTTP | 11 | 2015-10-20 11:46:27 | <p>I'm trying to upload really big VM Images (5-15 Gb size) to an HTTP server using PowerShell.</p>
<p>I tried to use for that few methods (here links to <a href="http://pastebin.com/ZvQSCxxY" rel="noreferrer">script with net.WebClient.UploadFile</a> and <a href="http://pastebin.com/yUFhSDCJ" rel="noreferrer">script w... | 14,021 | 2,090,761 | 2022-03-10 16:30:30 | 33,247,022 | 11 | 2015-10-20 21:21:59 | 33,445 | 2022-03-10 16:30:30 | https://stackoverflow.com/q/33235806 | https://stackoverflow.com/a/33247022 | <p>By default HttpWebRequest is buffering data in memory.
Just set <code>HttpWebRequest.AllowWriteStreamBuffering</code> property to false and you would be able to upload files with almost any size.
See more details at <a href="https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.allowwritestreambuffe... | <p>By default HttpWebRequest is buffering data in memory. Just set <code>HttpWebRequest.AllowWriteStreamBuffering</code> property to false and you would be able to upload files with almost any size. See more details at <a href="https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.allowwritestreambuffe... | 526, 4209, 10701 | file-upload, httpwebrequest, powershell | <h1>Upload BIG files via HTTP</h1>
<p>I'm trying to upload really big VM Images (5-15 Gb size) to an HTTP server using PowerShell.</p>
<p>I tried to use for that few methods (here links to <a href="http://pastebin.com/ZvQSCxxY" rel="noreferrer">script with net.WebClient.UploadFile</a> and <a href="http://pastebin.com/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,324 | bash | # Upload BIG files via HTTP
I'm trying to upload really big VM Images (5-15 Gb size) to an HTTP server using PowerShell.
I tried to use for that few methods (here links to [script with net.WebClient.UploadFile](http://pastebin.com/ZvQSCxxY) and [script with Invoke-webRequest](http://pastebin.com/yUFhSDCJ))
It works ... | By default HttpWebRequest is buffering data in memory.
Just set `HttpWebRequest.AllowWriteStreamBuffering` property to false and you would be able to upload files with almost any size.
See more details at [msdn](https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.allowwritestreambuffering "AllowWrite... |
33240221 | How to use trap reliably using Bash running foreground child processes | 11 | 2015-10-20 15:06:34 | <p>I have a Bash script that runs a long running process in the foreground. When it receives a SIGQUIT signal, it should perform various cleanup operations such as killing itself and all of its child processes (via kill of process group etc.). A minimal script, that should catch the signal, is shown below (called <code... | 4,577 | 257,924 | 2024-03-15 02:32:09 | 33,241,062 | 11 | 2015-10-20 15:44:39 | 1,126,841 | 2015-10-20 15:44:39 | https://stackoverflow.com/q/33240221 | https://stackoverflow.com/a/33241062 | <p><code>bash</code> must wait for <code>sleep</code> to complete before it can execute the handler. A good workaround is to run <code>sleep</code> in the background, then immediately wait for it. While <code>sleep</code> is uninterruptible, <code>wait</code> is not.</p>
<pre><code>trap 'kill $sleep_pid; echo "TRAP CA... | <p><code>bash</code> must wait for <code>sleep</code> to complete before it can execute the handler. A good workaround is to run <code>sleep</code> in the background, then immediately wait for it. While <code>sleep</code> is uninterruptible, <code>wait</code> is not.</p> <pre><code>trap 'kill $sleep_pid; echo "TRAP CA... | 387 | bash | <h1>How to use trap reliably using Bash running foreground child processes</h1>
<p>I have a Bash script that runs a long running process in the foreground. When it receives a SIGQUIT signal, it should perform various cleanup operations such as killing itself and all of its child processes (via kill of process group etc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,325 | bash | # How to use trap reliably using Bash running foreground child processes
I have a Bash script that runs a long running process in the foreground. When it receives a SIGQUIT signal, it should perform various cleanup operations such as killing itself and all of its child processes (via kill of process group etc.). A min... | `bash` must wait for `sleep` to complete before it can execute the handler. A good workaround is to run `sleep` in the background, then immediately wait for it. While `sleep` is uninterruptible, `wait` is not.
```
trap 'kill $sleep_pid; echo "TRAP CAUGHT"; exit 1' QUIT
echo starting sleep
sleep 11666 &
sleep_pid=$!
w... |
2563300 | How can I find the location of the tcsh shell script I'm executing? | 11 | 2010-04-01 20:04:09 | <p>Say I put an executable tcsh file in /path/to/my_script.csh</p>
<p>and my current directory is anywhere, for example I'm in /path</p>
<p>So I type to/my_script.csh</p>
<p>I want to have a line in my_script.csh that will return "/path/to/my_script.csh" - like ruby's </p>
<pre><code>__FILE__
</code></pre>
| 29,009 | 179,412 | 2024-04-30 04:22:03 | 24,945,405 | 11 | 2014-07-24 23:02:30 | 3,109,254 | 2014-07-24 23:02:30 | https://stackoverflow.com/q/2563300 | https://stackoverflow.com/a/24945405 | <p>In c shell, try like this:</p>
<pre><code>set rootdir = `dirname $0`
set abs_rootdir = `cd $rootdir && pwd`
echo $abs_rootdir
</code></pre>
| <p>In c shell, try like this:</p> <pre><code>set rootdir = `dirname $0` set abs_rootdir = `cd $rootdir && pwd` echo $abs_rootdir </code></pre> | 218, 390, 6268, 8599 | directory, path, shell, tcsh | <h1>How can I find the location of the tcsh shell script I'm executing?</h1>
<p>Say I put an executable tcsh file in /path/to/my_script.csh</p>
<p>and my current directory is anywhere, for example I'm in /path</p>
<p>So I type to/my_script.csh</p>
<p>I want to have a line in my_script.csh that will return "/path/to... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,326 | bash | # How can I find the location of the tcsh shell script I'm executing?
Say I put an executable tcsh file in /path/to/my_script.csh
and my current directory is anywhere, for example I'm in /path
So I type to/my_script.csh
I want to have a line in my_script.csh that will return "/path/to/my_script.csh" - like ruby's
... | In c shell, try like this:
```
set rootdir = `dirname $0`
set abs_rootdir = `cd $rootdir && pwd`
echo $abs_rootdir
``` |
23548577 | Best way to overwrite file with itself | 11 | 2014-05-08 17:24:22 | <p>What is the fastest / most elegant way to read out a file and then write the content to that same file?</p>
<p>On Linux, this is not always the same as 'touching' a file, e.g. if the file represents some hardware device.</p>
<p>One possibility that worked for me is <code>echo $(cat $file) > $file</code> but I w... | 11,883 | 1,020,237 | 2016-10-22 19:53:41 | 23,548,686 | 11 | 2014-05-08 17:30:29 | 68,587 | 2014-05-08 17:30:29 | https://stackoverflow.com/q/23548577 | https://stackoverflow.com/a/23548686 | <p>You cannot generically do this in one step because writing to the file can interfere with reading from it. If you try this on a regular file, it's likely the <code>></code> redirection will blank the file out before anything is even read.</p>
<p>Your safest bet is to split it into two steps. You can hide it behi... | <p>You cannot generically do this in one step because writing to the file can interfere with reading from it. If you try this on a regular file, it's likely the <code>></code> redirection will blank the file out before anything is even read.</p> <p>Your safest bet is to split it into two steps. You can hide it behi... | 58, 387, 390 | bash, linux, shell | <h1>Best way to overwrite file with itself</h1>
<p>What is the fastest / most elegant way to read out a file and then write the content to that same file?</p>
<p>On Linux, this is not always the same as 'touching' a file, e.g. if the file represents some hardware device.</p>
<p>One possibility that worked for me is <... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,327 | bash | # Best way to overwrite file with itself
What is the fastest / most elegant way to read out a file and then write the content to that same file?
On Linux, this is not always the same as 'touching' a file, e.g. if the file represents some hardware device.
One possibility that worked for me is `echo $(cat $file) > $fi... | You cannot generically do this in one step because writing to the file can interfere with reading from it. If you try this on a regular file, it's likely the `>` redirection will blank the file out before anything is even read.
Your safest bet is to split it into two steps. You can hide it behind a function call if yo... |
23235991 | what's the meaning of 'c' in result of command "ls -l /dev/tty'? | 11 | 2014-04-23 06:01:35 | <p>I'm writing some code to interpret the output of the <code>ls</code> command in Linux (to make it more friendly to newcomers). As one of the test cases, I executed the command 'ls -l /dev/tty', and it returned</p>
<pre><code>crw-rw-rw- 1 root root 5, 0 Apr 15 23:46 /dev/tty
</code></pre>
<p>What is the meaning of ... | 7,764 | 2,533,918 | 2014-04-23 08:00:46 | 23,236,028 | 11 | 2014-04-23 06:04:17 | 14,860 | 2014-04-23 06:15:30 | https://stackoverflow.com/q/23235991 | https://stackoverflow.com/a/23236028 | <p>It's a character-based (as opposed to block-based) device file.</p>
<p>Blocked-based devices are anything where it makes sense to transfer data in (surprisingly enough) blocks. By that, I mean things like disks.</p>
<p>Character-based devices (and again, this should come as no surprise) tend to transfer characters... | <p>It's a character-based (as opposed to block-based) device file.</p> <p>Blocked-based devices are anything where it makes sense to transfer data in (surprisingly enough) blocks. By that, I mean things like disks.</p> <p>Character-based devices (and again, this should come as no surprise) tend to transfer characters... | 58, 387 | bash, linux | <h1>what's the meaning of 'c' in result of command "ls -l /dev/tty'?</h1>
<p>I'm writing some code to interpret the output of the <code>ls</code> command in Linux (to make it more friendly to newcomers). As one of the test cases, I executed the command 'ls -l /dev/tty', and it returned</p>
<pre><code>crw-rw-rw- 1 root... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,328 | bash | # what's the meaning of 'c' in result of command "ls -l /dev/tty'?
I'm writing some code to interpret the output of the `ls` command in Linux (to make it more friendly to newcomers). As one of the test cases, I executed the command 'ls -l /dev/tty', and it returned
```
crw-rw-rw- 1 root root 5, 0 Apr 15 23:46 /dev/tt... | It's a character-based (as opposed to block-based) device file.
Blocked-based devices are anything where it makes sense to transfer data in (surprisingly enough) blocks. By that, I mean things like disks.
Character-based devices (and again, this should come as no surprise) tend to transfer characters at a time. Thing... |
22514348 | how to 'ls' another directory in unix script? | 11 | 2014-03-19 17:59:22 | <p>My code</p>
<pre><code>echo $ls | /var/lib/judgem/records/
</code></pre>
<p>I'm trying to get the script to show me all the files inside the folder "records"</p>
<p>How do I do that?</p>
| 26,876 | 1,808,262 | 2017-10-20 06:35:17 | 22,515,329 | 11 | 2014-03-19 18:43:37 | 2,836,621 | 2014-03-19 18:43:37 | https://stackoverflow.com/q/22514348 | https://stackoverflow.com/a/22515329 | <p>Or, if you want to list the contents of another directory without the full path, i.e. as though you were in the other directory, but without ending up there after the command has finished, you can use a subshell like this:</p>
<pre><code>(cd /var/lib/judgem/records/ && ls)
</code></pre>
<p>You will notice ... | <p>Or, if you want to list the contents of another directory without the full path, i.e. as though you were in the other directory, but without ending up there after the command has finished, you can use a subshell like this:</p> <pre><code>(cd /var/lib/judgem/records/ && ls) </code></pre> <p>You will notice ... | 34, 390 | shell, unix | <h1>how to 'ls' another directory in unix script?</h1>
<p>My code</p>
<pre><code>echo $ls | /var/lib/judgem/records/
</code></pre>
<p>I'm trying to get the script to show me all the files inside the folder "records"</p>
<p>How do I do that?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,329 | bash | # how to 'ls' another directory in unix script?
My code
```
echo $ls | /var/lib/judgem/records/
```
I'm trying to get the script to show me all the files inside the folder "records"
How do I do that? | Or, if you want to list the contents of another directory without the full path, i.e. as though you were in the other directory, but without ending up there after the command has finished, you can use a subshell like this:
```
(cd /var/lib/judgem/records/ && ls)
```
You will notice you stay in whatever directory you ... |
22238465 | Removing line break powershell | 11 | 2014-03-06 23:33:40 | <p>I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know.</p>
<pre><code>foreach ($item in $array) {
"_"+$item+"_"
}
</code></pre>
<p>Output:</p>
<pre><code>_
itemname_
</code></pre>
<p>Desired Output:</p>
... | 58,385 | 3,267,427 | 2023-04-26 23:25:57 | 22,238,539 | 11 | 2014-03-06 23:40:04 | 574,168 | 2014-03-07 00:11:47 | https://stackoverflow.com/q/22238465 | https://stackoverflow.com/a/22238539 | <p>Okay, I think this should work. I was under the impression you wanted those underscores in the result.</p>
<pre><code>$array -replace "`n|`r"
</code></pre>
| <p>Okay, I think this should work. I was under the impression you wanted those underscores in the result.</p> <pre><code>$array -replace "`n|`r" </code></pre> | 526, 9313 | line-breaks, powershell | <h1>Removing line break powershell</h1>
<p>I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know.</p>
<pre><code>foreach ($item in $array) {
"_"+$item+"_"
}
</code></pre>
<p>Output:</p>
<pre><code>_
itemname... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,330 | bash | # Removing line break powershell
I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know.
```
foreach ($item in $array) {
"_"+$item+"_"
}
```
Output:
```
_
itemname_
```
Desired Output:
```
itemname
```
I'... | Okay, I think this should work. I was under the impression you wanted those underscores in the result.
```
$array -replace "`n|`r"
``` |
18954527 | Self-daemonizing bash script | 11 | 2013-09-23 08:11:17 | <p>I want to make a script to be <strong><em>self-daemonizing</em></strong>, i.e., no need to invoke <code>nohup $SCRIPT &>/dev/null &</code> manually on the shell prompt.</p>
<p>My plan is to create a section of code like the following:</p>
<pre><code>#!/bin/bash
SCRIPTNAME="$0"
...
# Preps are done abo... | 8,120 | 149,900 | 2014-12-12 15:07:32 | 18,954,966 | 11 | 2013-09-23 08:39:21 | 445,221 | 2013-09-23 08:59:19 | https://stackoverflow.com/q/18954527 | https://stackoverflow.com/a/18954966 | <p>Here are things I see.</p>
<pre><code>if [[ $1 != "--daemonize" ]]; then
</code></pre>
<p>Shouln't that be <code>== --daemonize?</code></p>
<pre><code>nohup $SCRIPTNAME --daemonize "${PARAMS[@]}" &>/dev/null &
</code></pre>
<p>Instead of calling your script again, you could just summon a subshell th... | <p>Here are things I see.</p> <pre><code>if [[ $1 != "--daemonize" ]]; then </code></pre> <p>Shouln't that be <code>== --daemonize?</code></p> <pre><code>nohup $SCRIPTNAME --daemonize "${PARAMS[@]}" &>/dev/null & </code></pre> <p>Instead of calling your script again, you could just summon a subshell th... | 387, 2510 | bash, daemon | <h1>Self-daemonizing bash script</h1>
<p>I want to make a script to be <strong><em>self-daemonizing</em></strong>, i.e., no need to invoke <code>nohup $SCRIPT &>/dev/null &</code> manually on the shell prompt.</p>
<p>My plan is to create a section of code like the following:</p>
<pre><code>#!/bin/bash
SCRI... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,331 | bash | # Self-daemonizing bash script
I want to make a script to be ***self-daemonizing***, i.e., no need to invoke `nohup $SCRIPT &>/dev/null &` manually on the shell prompt.
My plan is to create a section of code like the following:
```
#!/bin/bash
SCRIPTNAME="$0"
...
# Preps are done above
if [[ "$1" != "--daemonize" ... | Here are things I see.
```
if [[ $1 != "--daemonize" ]]; then
```
Shouln't that be `== --daemonize?`
```
nohup $SCRIPTNAME --daemonize "${PARAMS[@]}" &>/dev/null &
```
Instead of calling your script again, you could just summon a subshell that's placed in a background:
```
(
Codes that run in daemon mode.
) </... |
18453057 | Use sed or awk to fix date format | 11 | 2013-08-26 21:10:00 | <p>I'm trying to convert a HTML containing a table to a .csv file using a <code>bash</code> script.</p>
<p>So far I've acomplished the following steps:</p>
<ol>
<li>Convert to Unix format (with <code>dos2unix</code>)</li>
<li>Remove all spaces and tabs (with <code>sed 's/[ \t]//g'</code>)</li>
<li>Remove all the blan... | 36,361 | 355,931 | 2016-03-29 16:35:35 | 18,453,187 | 11 | 2013-08-26 21:18:30 | 773,159 | 2013-08-26 21:18:30 | https://stackoverflow.com/q/18453057 | https://stackoverflow.com/a/18453187 | <p><code>Awk</code> can do this task pretty easily:</p>
<pre><code>awk '
BEGIN { FS = OFS = "," }
{ split($3, date, /\//)
$3 = date[3] "-" date[2] "-" date[1]
print $0
}
' infile
</code></pre>
<p>It yields:</p>
<pre><code>500,2,2007-09-13,30000.00,12,B-1
501,2,2007-09-15,14000.00,8,B-2
</co... | <p><code>Awk</code> can do this task pretty easily:</p> <pre><code>awk ' BEGIN { FS = OFS = "," } { split($3, date, /\//) $3 = date[3] "-" date[2] "-" date[1] print $0 } ' infile </code></pre> <p>It yields:</p> <pre><code>500,2,2007-09-13,30000.00,12,B-1 501,2,2007-09-15,14000.00,8,B-2 </co... | 18, 387, 990, 5282 | awk, bash, regex, sed | <h1>Use sed or awk to fix date format</h1>
<p>I'm trying to convert a HTML containing a table to a .csv file using a <code>bash</code> script.</p>
<p>So far I've acomplished the following steps:</p>
<ol>
<li>Convert to Unix format (with <code>dos2unix</code>)</li>
<li>Remove all spaces and tabs (with <code>sed 's/[ \... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,332 | bash | # Use sed or awk to fix date format
I'm trying to convert a HTML containing a table to a .csv file using a `bash` script.
So far I've acomplished the following steps:
1. Convert to Unix format (with `dos2unix`)
2. Remove all spaces and tabs (with `sed 's/[ \t]//g'`)
3. Remove all the blank lines (with `sed ':a;N;$!b... | `Awk` can do this task pretty easily:
```
awk '
BEGIN { FS = OFS = "," }
{ split($3, date, /\//)
$3 = date[3] "-" date[2] "-" date[1]
print $0
}
' infile
```
It yields:
```
500,2,2007-09-13,30000.00,12,B-1
501,2,2007-09-15,14000.00,8,B-2
``` |
18344459 | Escape dollar sign in a Bash script (which uses AWK) | 11 | 2013-08-20 20:32:52 | <p>I want to use AWK in my Bash script, and this line clearly doesn't work:</p>
<pre><code>line="foo bar"
echo $line | awk '{print $1}'
</code></pre>
<p>How do I escape <code>$1</code>, so it doesn't get replaced with the first argument of the script?</p>
| 17,288 | 1,293,653 | 2025-05-27 01:51:55 | 18,345,001 | 11 | 2013-08-20 21:08:10 | 283,078 | 2017-01-23 00:18:30 | https://stackoverflow.com/q/18344459 | https://stackoverflow.com/a/18345001 | <p>Your script (with single quotes around the awk script) will work as expected:</p>
<pre><code>$ cat script-single
#!/bin/bash
line="foo bar"
echo $line | awk '{print $1}'
$ ./script-single test
foo
</code></pre>
<p>The following, however, <em>will</em> break (the script will output an empty line):</p>
<pre><code>... | <p>Your script (with single quotes around the awk script) will work as expected:</p> <pre><code>$ cat script-single #!/bin/bash line="foo bar" echo $line | awk '{print $1}' $ ./script-single test foo </code></pre> <p>The following, however, <em>will</em> break (the script will output an empty line):</p> <pre><code>... | 387, 990 | awk, bash | <h1>Escape dollar sign in a Bash script (which uses AWK)</h1>
<p>I want to use AWK in my Bash script, and this line clearly doesn't work:</p>
<pre><code>line="foo bar"
echo $line | awk '{print $1}'
</code></pre>
<p>How do I escape <code>$1</code>, so it doesn't get replaced with the first argument of the scri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,333 | bash | # Escape dollar sign in a Bash script (which uses AWK)
I want to use AWK in my Bash script, and this line clearly doesn't work:
```
line="foo bar"
echo $line | awk '{print $1}'
```
How do I escape `$1`, so it doesn't get replaced with the first argument of the script? | Your script (with single quotes around the awk script) will work as expected:
```
$ cat script-single
#!/bin/bash
line="foo bar"
echo $line | awk '{print $1}'
$ ./script-single test
foo
```
The following, however, *will* break (the script will output an empty line):
```
$ cat script-double
#!/bin/bash
line="foo bar... |
15665637 | awk - if column = null | 11 | 2013-03-27 17:38:05 | <p>Using awk, how would you assign 'null' a value to read?</p>
<p>I'm sure there's a set character for this, I just can't find it.</p>
<p>For example,</p>
<p>I've got a string of awk like this:</p>
<pre><code>awk '
$3==24{print "stuff"}
$3==23{print "stuff"}
'
</code></pre>
<p>I need to know how to account for bla... | 50,195 | 1,296,327 | 2016-06-14 20:55:41 | 15,665,675 | 11 | 2013-03-27 17:40:02 | 465,183 | 2013-03-27 17:47:16 | https://stackoverflow.com/q/15665637 | https://stackoverflow.com/a/15665675 | <p>Try doing this :</p>
<pre><code>awk '
$3==24{print "stuff"}
$3==23{print "stuff"}
!$3{print "null"}
' file.txt
</code></pre>
<p>If you need to process <code>$3</code> if it's zero (<code>false</code> for <code>awk</code>), try doing this :</p>
<pre><code>!$3 && $3 != 0{print "null"}
</code></p... | <p>Try doing this :</p> <pre><code>awk ' $3==24{print "stuff"} $3==23{print "stuff"} !$3{print "null"} ' file.txt </code></pre> <p>If you need to process <code>$3</code> if it's zero (<code>false</code> for <code>awk</code>), try doing this :</p> <pre><code>!$3 && $3 != 0{print "null"} </code></p... | 387, 990 | awk, bash | <h1>awk - if column = null</h1>
<p>Using awk, how would you assign 'null' a value to read?</p>
<p>I'm sure there's a set character for this, I just can't find it.</p>
<p>For example,</p>
<p>I've got a string of awk like this:</p>
<pre><code>awk '
$3==24{print "stuff"}
$3==23{print "stuff"}
'
</code></pre>
<p>I nee... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,334 | bash | # awk - if column = null
Using awk, how would you assign 'null' a value to read?
I'm sure there's a set character for this, I just can't find it.
For example,
I've got a string of awk like this:
```
awk '
$3==24{print "stuff"}
$3==23{print "stuff"}
'
```
I need to know how to account for blank colums using the sa... | Try doing this :
```
awk '
$3==24{print "stuff"}
$3==23{print "stuff"}
!$3{print "null"}
' file.txt
```
If you need to process `$3` if it's zero (`false` for `awk`), try doing this :
```
!$3 && $3 != 0{print "null"}
``` |
13355534 | Preserve newlines when concatenating or using heredoc in PowerShell | 11 | 2012-11-13 04:18:25 | <p>Suppose I have the a document <code>c:\temp\temp.txt</code> with contents</p>
<pre><code>line 1
line 2
</code></pre>
<p>and I create the following function</p>
<pre><code>PS>function wrapit($text) {
@"
---Start---
$text
---End---
"@
}
</code></pre>
<p>Then running <code>PS> wrapit((Get-Content c:\temp\temp... | 6,569 | 5,056 | 2017-06-04 22:39:09 | 13,355,659 | 11 | 2012-11-13 04:37:35 | 608,772 | 2017-06-04 22:39:09 | https://stackoverflow.com/q/13355534 | https://stackoverflow.com/a/13355659 | <p>A simple way to do what you want is:</p>
<pre><code>wrapit((Get-Content c:\temp\temp.txt | out-string))
</code></pre>
<p>Now the explanation: Here-strings @"" just behave like strings "" and the result is due to the PowerShell behaviour in variables expansion. Just try:</p>
<pre><code>$a = Get-Content c:\temp\tem... | <p>A simple way to do what you want is:</p> <pre><code>wrapit((Get-Content c:\temp\temp.txt | out-string)) </code></pre> <p>Now the explanation: Here-strings @"" just behave like strings "" and the result is due to the PowerShell behaviour in variables expansion. Just try:</p> <pre><code>$a = Get-Content c:\temp\tem... | 526 | powershell | <h1>Preserve newlines when concatenating or using heredoc in PowerShell</h1>
<p>Suppose I have the a document <code>c:\temp\temp.txt</code> with contents</p>
<pre><code>line 1
line 2
</code></pre>
<p>and I create the following function</p>
<pre><code>PS>function wrapit($text) {
@"
---Start---
$text
---End---
"@
}... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,335 | bash | # Preserve newlines when concatenating or using heredoc in PowerShell
Suppose I have the a document `c:\temp\temp.txt` with contents
```
line 1
line 2
```
and I create the following function
```
PS>function wrapit($text) {
@"
---Start---
$text
---End---
"@
}
```
Then running `PS> wrapit((Get-Content c:\temp\temp.t... | A simple way to do what you want is:
```
wrapit((Get-Content c:\temp\temp.txt | out-string))
```
Now the explanation: Here-strings @"" just behave like strings "" and the result is due to the PowerShell behaviour in variables expansion. Just try:
```
$a = Get-Content c:\temp\temp.txt
"$a"
```
---
Regarding your co... |
13019218 | Powershell - LIKE against an array | 11 | 2012-10-22 20:22:00 | <p>For every file being processed, its name is being checked to satisfy the condition. For example, given the following list of filters:</p>
<pre><code>$excludeFiles = @"
aaa.bbb
ccccc.*
ddddd???.exe
"@ | SplitAndTrim;
</code></pre>
<p>It should exclude a file from processing if it matches any of the lines. Trying to... | 27,421 | 897,326 | 2025-11-17 05:03:14 | 13,019,721 | 11 | 2012-10-22 20:56:25 | 9,833 | 2012-10-23 01:27:44 | https://stackoverflow.com/q/13019218 | https://stackoverflow.com/a/13019721 | <p>You can perform a pattern match against a collection of names, but not against a list of patterns. Try this:</p>
<pre><code>foreach($pattern in $excludeFiles)
{
if($fileName -like $pattern) {break}
}
</code></pre>
<p>Here is how it can be wrapped into a function:</p>
<pre><code>function like($str,$patterns){
... | <p>You can perform a pattern match against a collection of names, but not against a list of patterns. Try this:</p> <pre><code>foreach($pattern in $excludeFiles) { if($fileName -like $pattern) {break} } </code></pre> <p>Here is how it can be wrapped into a function:</p> <pre><code>function like($str,$patterns){ ... | 114, 526, 90430 | arrays, powershell, sql-like | <h1>Powershell - LIKE against an array</h1>
<p>For every file being processed, its name is being checked to satisfy the condition. For example, given the following list of filters:</p>
<pre><code>$excludeFiles = @"
aaa.bbb
ccccc.*
ddddd???.exe
"@ | SplitAndTrim;
</code></pre>
<p>It should exclude a file from processi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,336 | bash | # Powershell - LIKE against an array
For every file being processed, its name is being checked to satisfy the condition. For example, given the following list of filters:
```
$excludeFiles = @"
aaa.bbb
ccccc.*
ddddd???.exe
"@ | SplitAndTrim;
```
It should exclude a file from processing if it matches any of the lines... | You can perform a pattern match against a collection of names, but not against a list of patterns. Try this:
```
foreach($pattern in $excludeFiles)
{
if($fileName -like $pattern) {break}
}
```
Here is how it can be wrapped into a function:
```
function like($str,$patterns){
foreach($pattern in $patterns) { i... |
12735788 | Simple find and replace with sed | 11 | 2012-10-04 20:56:27 | <p>I'm trying to replace a number that is in a couple different strings in a text file. Basically it would take the form of </p>
<pre><code>tableNameNUMBER
carNUMBER
</code></pre>
<p>I'm pretty new to bash and scripting and I wasn't sure how to replace <code>NUMBER</code> with what I pass in. So I've tried this:</p... | 25,652 | 207,524 | 2016-11-09 11:52:52 | 12,736,546 | 11 | 2012-10-04 21:48:34 | 368,630 | 2012-10-04 21:48:34 | https://stackoverflow.com/q/12735788 | https://stackoverflow.com/a/12736546 | <p>This should work just fine:</p>
<pre><code>sed "s/NUMBER/$1/g" myScript.txt > test.txt
</code></pre>
<p>The <code>g</code> on the end allows set to replace NUMBER if it appears multiple times on one line.</p>
<p>In fact, a quick test:</p>
<h3>foo.txt</h3>
<pre><code>carNUMBER
tableNameNUMBER
NUMBER
NUMBERfoo... | <p>This should work just fine:</p> <pre><code>sed "s/NUMBER/$1/g" myScript.txt > test.txt </code></pre> <p>The <code>g</code> on the end allows set to replace NUMBER if it appears multiple times on one line.</p> <p>In fact, a quick test:</p> <h3>foo.txt</h3> <pre><code>carNUMBER tableNameNUMBER NUMBER NUMBERfoo... | 387 | bash | <h1>Simple find and replace with sed</h1>
<p>I'm trying to replace a number that is in a couple different strings in a text file. Basically it would take the form of </p>
<pre><code>tableNameNUMBER
carNUMBER
</code></pre>
<p>I'm pretty new to bash and scripting and I wasn't sure how to replace <code>NUMBER</code> wi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,337 | bash | # Simple find and replace with sed
I'm trying to replace a number that is in a couple different strings in a text file. Basically it would take the form of
```
tableNameNUMBER
carNUMBER
```
I'm pretty new to bash and scripting and I wasn't sure how to replace `NUMBER` with what I pass in. So I've tried this:
```
#!... | This should work just fine:
```
sed "s/NUMBER/$1/g" myScript.txt > test.txt
```
The `g` on the end allows set to replace NUMBER if it appears multiple times on one line.
In fact, a quick test:
### foo.txt
```
carNUMBER
tableNameNUMBER
NUMBER
NUMBERfoo
$ NUMBER=3.14
$ sed "s/NUMBER/$NUMBER/g" foo.txt
car3.14
table... |
10842567 | How can I get nuget (powershell) to insert <DependentUpon> elements in the target csproj file | 11 | 2012-05-31 23:23:05 | <p>I'm writing a nuget package for a windows service, the idea is that my colleagues can create a windows service install the package and all of the default logging settings, entlib libraries and other house keep tasks will be set up for them.</p>
<p>I've gotten pretty much everything to work except for one thing whic... | 3,171 | 527,338 | 2014-12-11 09:22:19 | 10,891,075 | 11 | 2012-06-05 03:09:29 | 527,338 | 2012-06-05 03:09:29 | https://stackoverflow.com/q/10842567 | https://stackoverflow.com/a/10891075 | <p>Well after around 2 days of powershell and msbuild hell I finally got a working solution. See below. A word of warning calling project.Save() is crucial - without this you will get a "conflicting file modification detected" warning. If you call project.Save() first you will be merely asked to reload the solution onc... | <p>Well after around 2 days of powershell and msbuild hell I finally got a working solution. See below. A word of warning calling project.Save() is crucial - without this you will get a "conflicting file modification detected" warning. If you call project.Save() first you will be merely asked to reload the solution onc... | 526, 10101, 34905, 62770, 62984 | csproj, envdte, nuget, nuget-package, powershell | <h1>How can I get nuget (powershell) to insert <DependentUpon> elements in the target csproj file</h1>
<p>I'm writing a nuget package for a windows service, the idea is that my colleagues can create a windows service install the package and all of the default logging settings, entlib libraries and other house keep task... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,338 | bash | # How can I get nuget (powershell) to insert elements in the target csproj file
I'm writing a nuget package for a windows service, the idea is that my colleagues can create a windows service install the package and all of the default logging settings, entlib libraries and other house keep tasks will be set up for them... | Well after around 2 days of powershell and msbuild hell I finally got a working solution. See below. A word of warning calling project.Save() is crucial - without this you will get a "conflicting file modification detected" warning. If you call project.Save() first you will be merely asked to reload the solution once y... |
10802850 | Validating PowerShell PSCredential | 11 | 2012-05-29 16:11:26 | <p>Let's say I have a <code>PSCrendential</code> object in PowerShell that I created using <code>Get-Credential</code>.</p>
<p>How can I validate the input against Active Directory ?</p>
<p>By now I found this way, but I feel it's a bit ugly :</p>
<pre><code>[void][System.Reflection.Assembly]::LoadWithPartialName("S... | 19,094 | 588,868 | 2017-05-26 07:59:34 | 10,803,169 | 11 | 2012-05-29 16:33:00 | 520,612 | 2012-05-29 16:33:00 | https://stackoverflow.com/q/10802850 | https://stackoverflow.com/a/10803169 | <p>I believe using <code>System.DirectoryServices.AccountManagement</code> is the less ugly way:</p>
<p>This is using ADSI (more ugly?):</p>
<pre><code>$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
# Get current domain using logged-on user's cre... | <p>I believe using <code>System.DirectoryServices.AccountManagement</code> is the less ugly way:</p> <p>This is using ADSI (more ugly?):</p> <pre><code>$cred = Get-Credential #Read credentials $username = $cred.username $password = $cred.GetNetworkCredential().password # Get current domain using logged-on user's cre... | 136, 526 | powershell, security | <h1>Validating PowerShell PSCredential</h1>
<p>Let's say I have a <code>PSCrendential</code> object in PowerShell that I created using <code>Get-Credential</code>.</p>
<p>How can I validate the input against Active Directory ?</p>
<p>By now I found this way, but I feel it's a bit ugly :</p>
<pre><code>[void][System.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,339 | bash | # Validating PowerShell PSCredential
Let's say I have a `PSCrendential` object in PowerShell that I created using `Get-Credential`.
How can I validate the input against Active Directory ?
By now I found this way, but I feel it's a bit ugly :
```
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Direct... | I believe using `System.DirectoryServices.AccountManagement` is the less ugly way:
This is using ADSI (more ugly?):
```
$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP:... |
9874921 | How do I call the split function in awk to split a string on "\."? | 11 | 2012-03-26 15:23:26 | <p>How do I use the <code>split</code> function to split by "\."?</p>
<p>For example, first consider splitting by <code>:</code>:</p>
<pre><code>echo "03:26:12" | awk '{split($0,a,":"); print a[3] a[2] a[1]}'
</code></pre>
<p>Which produces this output:</p>
<pre><code>122603
</code></pre>
<p>But if the incoming s... | 38,408 | 1,268,200 | 2012-07-23 06:03:59 | 9,874,983 | 11 | 2012-03-26 15:27:51 | 773,159 | 2012-03-26 15:27:51 | https://stackoverflow.com/q/9874921 | https://stackoverflow.com/a/9874983 | <p>You must escape both characters:</p>
<pre><code>echo "03\.26\.12" | awk '{split($0,a,/\\\./); print a[3] a[2] a[1]}'
</code></pre>
<p>Result:</p>
<pre><code>122603
</code></pre>
| <p>You must escape both characters:</p> <pre><code>echo "03\.26\.12" | awk '{split($0,a,/\\\./); print a[3] a[2] a[1]}' </code></pre> <p>Result:</p> <pre><code>122603 </code></pre> | 387, 990 | awk, bash | <h1>How do I call the split function in awk to split a string on "\."?</h1>
<p>How do I use the <code>split</code> function to split by "\."?</p>
<p>For example, first consider splitting by <code>:</code>:</p>
<pre><code>echo "03:26:12" | awk '{split($0,a,":"); print a[3] a[2] a[1]}'
</code></pre>
<p>Which produces... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,340 | bash | # How do I call the split function in awk to split a string on "\."?
How do I use the `split` function to split by "\."?
For example, first consider splitting by `:`:
```
echo "03:26:12" | awk '{split($0,a,":"); print a[3] a[2] a[1]}'
```
Which produces this output:
```
122603
```
But if the incoming string is in... | You must escape both characters:
```
echo "03\.26\.12" | awk '{split($0,a,/\\\./); print a[3] a[2] a[1]}'
```
Result:
```
122603
``` |
6839273 | bash/readline equivalent of escape-dot in vi-mode | 11 | 2011-07-27 03:51:23 | <p>Having recently switched to vi-mode in bash, the one thing I miss is <kbd>esc</kbd> <kbd>.</kbd> to get the last argument of the last command.</p>
<p>I know about <kbd>ctrl</kbd> <kbd>_</kbd>, but I always end up hitting <kbd>ctrl</kbd> <kbd>-</kbd> instead.</p>
<p>Is there another vi-mode equivalent for this?</p>... | 2,440 | 609,144 | 2016-10-09 18:41:03 | 9,749,374 | 11 | 2012-03-17 10:52:25 | 382,050 | 2013-07-27 09:29:27 | https://stackoverflow.com/q/6839273 | https://stackoverflow.com/a/9749374 | <p>I believe the closest solution to what you want is this:</p>
<p>In your .bashrc, right after "set -o vi"...</p>
<pre><code>set -o vi
bind -m vi-command ".":insert-last-argument
</code></pre>
<p>This tells your bash to invoke the "insert-last-argument" action when '.' is used in vi-command mode. This of course mea... | <p>I believe the closest solution to what you want is this:</p> <p>In your .bashrc, right after "set -o vi"...</p> <pre><code>set -o vi bind -m vi-command ".":insert-last-argument </code></pre> <p>This tells your bash to invoke the "insert-last-argument" action when '.' is used in vi-command mode. This of course mea... | 293, 387, 10353 | bash, readline, vi | <h1>bash/readline equivalent of escape-dot in vi-mode</h1>
<p>Having recently switched to vi-mode in bash, the one thing I miss is <kbd>esc</kbd> <kbd>.</kbd> to get the last argument of the last command.</p>
<p>I know about <kbd>ctrl</kbd> <kbd>_</kbd>, but I always end up hitting <kbd>ctrl</kbd> <kbd>-</kbd> instead... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,341 | bash | # bash/readline equivalent of escape-dot in vi-mode
Having recently switched to vi-mode in bash, the one thing I miss is `esc` `.` to get the last argument of the last command.
I know about `ctrl` `_`, but I always end up hitting `ctrl` `-` instead.
Is there another vi-mode equivalent for this? | I believe the closest solution to what you want is this:
In your .bashrc, right after "set -o vi"...
```
set -o vi
bind -m vi-command ".":insert-last-argument
```
This tells your bash to invoke the "insert-last-argument" action when '.' is used in vi-command mode. This of course means that you lose the normal "." fu... |
8509045 | execve("/bin/sh", 0, 0); in a pipe | 11 | 2011-12-14 17:36:24 | <p>I have the following example program:</p>
<pre><code>#include <stdio.h>
int
main(int argc, char ** argv){
char buf[100];
printf("Please enter your name: ");
fflush(stdout);
gets(buf);
printf("Hello \"%s\"\n", buf);
execve("/bin/sh", 0, 0);
}
</code></pre>
<p>I and when I run withou... | 14,588 | 1,098,332 | 2011-12-14 18:02:32 | 8,509,410 | 11 | 2011-12-14 18:02:14 | 1,023,815 | 2011-12-14 18:02:14 | https://stackoverflow.com/q/8509045 | https://stackoverflow.com/a/8509410 | <p>You can run your program without any modifications like this:</p>
<pre><code>(echo -e 'testName\n'; cat ) | ./a.out
</code></pre>
<p>This way you ensure that your program's standard input doesn't end after what <code>echo</code> outputs. Instead, <code>cat</code> continues to supply input to your program. The sour... | <p>You can run your program without any modifications like this:</p> <pre><code>(echo -e 'testName\n'; cat ) | ./a.out </code></pre> <p>This way you ensure that your program's standard input doesn't end after what <code>echo</code> outputs. Instead, <code>cat</code> continues to supply input to your program. The sour... | 8, 390, 2796, 5813, 66835 | c, execve, freebsd, pipe, shell | <h1>execve("/bin/sh", 0, 0); in a pipe</h1>
<p>I have the following example program:</p>
<pre><code>#include <stdio.h>
int
main(int argc, char ** argv){
char buf[100];
printf("Please enter your name: ");
fflush(stdout);
gets(buf);
printf("Hello \"%s\"\n", buf);
execve("/bin/sh", 0, 0);... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,342 | bash | # execve("/bin/sh", 0, 0); in a pipe
I have the following example program:
```
#include <stdio.h>
int
main(int argc, char ** argv){
char buf[100];
printf("Please enter your name: ");
fflush(stdout);
gets(buf);
printf("Hello \"%s\"\n", buf);
execve("/bin/sh", 0, 0);
}
```
I and when I run w... | You can run your program without any modifications like this:
```
(echo -e 'testName\n'; cat ) | ./a.out
```
This way you ensure that your program's standard input doesn't end after what `echo` outputs. Instead, `cat` continues to supply input to your program. The source of that subsequent input is your terminal sinc... |
6361337 | Bash- How to convert non-alphanumerical character to "_" | 11 | 2011-06-15 16:52:32 | <p>I am trying to store user input in a variable and clean that variable in order to keep only alphanumerical caract + some others (I mean [a-zA-Z0-9-_]).</p>
<p>I tried using this but it isn't exhaustive :</p>
<pre><code>SERVICE_NAME=$(echo $SERVICE_NAME | tr A-Z a-z | tr ' ' _ | tr \' _ | tr \" _)
</code></pre>
<p... | 5,467 | 595,223 | 2011-06-16 21:00:54 | 6,361,365 | 11 | 2011-06-15 16:55:13 | 259,466 | 2011-06-15 16:55:13 | https://stackoverflow.com/q/6361337 | https://stackoverflow.com/a/6361365 | <pre><code>$ echo 'asd!@QCW@@D' | tr A-Z a-z | sed -e 's/[^a-zA-Z0-9\-]/_/g'
asd__qcw__d
</code></pre>
<p>I would use <code>sed</code> for this and use the <code>^</code> (not) operator in your set of valid characters and replace everything else with an underscore. The above shows the syntax with the output.</p>
<p>A... | <pre><code>$ echo 'asd!@QCW@@D' | tr A-Z a-z | sed -e 's/[^a-zA-Z0-9\-]/_/g' asd__qcw__d </code></pre> <p>I would use <code>sed</code> for this and use the <code>^</code> (not) operator in your set of valid characters and replace everything else with an underscore. The above shows the syntax with the output.</p> <p>A... | 18, 139, 387 | bash, regex, string | <h1>Bash- How to convert non-alphanumerical character to "_"</h1>
<p>I am trying to store user input in a variable and clean that variable in order to keep only alphanumerical caract + some others (I mean [a-zA-Z0-9-_]).</p>
<p>I tried using this but it isn't exhaustive :</p>
<pre><code>SERVICE_NAME=$(echo $SERVICE_N... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,343 | bash | # Bash- How to convert non-alphanumerical character to "_"
I am trying to store user input in a variable and clean that variable in order to keep only alphanumerical caract + some others (I mean [a-zA-Z0-9-_]).
I tried using this but it isn't exhaustive :
```
SERVICE_NAME=$(echo $SERVICE_NAME | tr A-Z a-z | tr ' ' _... | ```
$ echo 'asd!@QCW@@D' | tr A-Z a-z | sed -e 's/[^a-zA-Z0-9\-]/_/g'
asd__qcw__d
```
I would use `sed` for this and use the `^` (not) operator in your set of valid characters and replace everything else with an underscore. The above shows the syntax with the output.
And, as a bonus, if you want to replace a run of i... |
5489494 | PowerShell Module Manifest - automatically loading a Required Module | 11 | 2011-03-30 16:55:45 | <p>I am creating a module that depends on several other modules that I need loaded into the global environment. I tried creating a script and using ScriptsToProcess to import the modules, but it looks like the check for RequiredModules happens before ScriptstoProcess runs. </p>
<p>Is there a nice, clean way in a Modul... | 17,811 | 45,571 | 2017-02-23 15:43:21 | 5,490,326 | 11 | 2011-03-30 18:08:36 | 8,718 | 2017-02-23 15:43:21 | https://stackoverflow.com/q/5489494 | https://stackoverflow.com/a/5490326 | <h2>In PowerShell 3 and up, RequiredModules <strong>are</strong> automatically loaded</h2>
<p>It's also the only way to make sure people using PowerShellGet (i.e. the <a href="https://powershellgallery.com" rel="nofollow noreferrer">PowerShell Gallery</a>) install your dependencies, if you're going to distribute the m... | <h2>In PowerShell 3 and up, RequiredModules <strong>are</strong> automatically loaded</h2> <p>It's also the only way to make sure people using PowerShellGet (i.e. the <a href="https://powershellgallery.com" rel="nofollow noreferrer">PowerShell Gallery</a>) install your dependencies, if you're going to distribute the m... | 526, 67488 | powershell, powershell-module | <h1>PowerShell Module Manifest - automatically loading a Required Module</h1>
<p>I am creating a module that depends on several other modules that I need loaded into the global environment. I tried creating a script and using ScriptsToProcess to import the modules, but it looks like the check for RequiredModules happen... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,344 | bash | # PowerShell Module Manifest - automatically loading a Required Module
I am creating a module that depends on several other modules that I need loaded into the global environment. I tried creating a script and using ScriptsToProcess to import the modules, but it looks like the check for RequiredModules happens before ... | ## In PowerShell 3 and up, RequiredModules **are** automatically loaded
It's also the only way to make sure people using PowerShellGet (i.e. the [PowerShell Gallery](https://powershellgallery.com)) install your dependencies, if you're going to distribute the module.
It would still fail if the required modules are mis... |
3765597 | Reading a specific line of a file | 11 | 2010-09-22 00:59:09 | <p>What is the best way (better performance) to read a specific line of a file? Currently, I'm using the following command line:</p>
<pre><code>head -line_number file_name | tail -1
</code></pre>
<p>ps.: preferentially, using shell tools.</p>
| 23,939 | 143,665 | 2019-11-25 02:52:26 | 3,765,615 | 11 | 2010-09-22 01:04:08 | 89,391 | 2010-09-22 01:04:08 | https://stackoverflow.com/q/3765597 | https://stackoverflow.com/a/3765615 | <p>You could use <code>sed</code>.</p>
<pre><code># print line number 10
$ sed -n '10p' file_name
$ sed '10!d' file_name
$ sed '10q;d' file_name
</code></pre>
| <p>You could use <code>sed</code>.</p> <pre><code># print line number 10 $ sed -n '10p' file_name $ sed '10!d' file_name $ sed '10q;d' file_name </code></pre> | 390, 1231, 1469 | command-line, shell, text | <h1>Reading a specific line of a file</h1>
<p>What is the best way (better performance) to read a specific line of a file? Currently, I'm using the following command line:</p>
<pre><code>head -line_number file_name | tail -1
</code></pre>
<p>ps.: preferentially, using shell tools.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,345 | bash | # Reading a specific line of a file
What is the best way (better performance) to read a specific line of a file? Currently, I'm using the following command line:
```
head -line_number file_name | tail -1
```
ps.: preferentially, using shell tools. | You could use `sed`.
```
# print line number 10
$ sed -n '10p' file_name
$ sed '10!d' file_name
$ sed '10q;d' file_name
``` |
3155101 | How to start a console-based process and apply a custom title using Powershell | 11 | 2010-07-01 04:31:40 | <p>I am converting an old <code>cmd</code> command to Powershell, and currently use:</p>
<pre><code>START "My Title" Path/To/ConsoleApp.exe
</code></pre>
<p>This works as expected to launch ConsoleApp with My Title as it's window title. This has been replaced with Start-Process which works correctly, but does not pro... | 7,736 | 2,918 | 2020-10-26 14:40:22 | 3,156,713 | 11 | 2010-07-01 09:57:14 | 347,011 | 2010-07-01 09:57:14 | https://stackoverflow.com/q/3155101 | https://stackoverflow.com/a/3156713 | <p>There is a small quirk when changing the text of the process' main window: if you try to change the text straight after you have started the process, it may fail due to one of many possible reasons (e.g. the handle to the control which displays the text does not exist at the time of the function call). So the soluti... | <p>There is a small quirk when changing the text of the process' main window: if you try to change the text straight after you have started the process, it may fail due to one of many possible reasons (e.g. the handle to the control which displays the text does not exist at the time of the function call). So the soluti... | 526, 26462 | powershell, start-process | <h1>How to start a console-based process and apply a custom title using Powershell</h1>
<p>I am converting an old <code>cmd</code> command to Powershell, and currently use:</p>
<pre><code>START "My Title" Path/To/ConsoleApp.exe
</code></pre>
<p>This works as expected to launch ConsoleApp with My Title as it's window ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,346 | bash | # How to start a console-based process and apply a custom title using Powershell
I am converting an old `cmd` command to Powershell, and currently use:
```
START "My Title" Path/To/ConsoleApp.exe
```
This works as expected to launch ConsoleApp with My Title as it's window title. This has been replaced with Start-Pro... | There is a small quirk when changing the text of the process' main window: if you try to change the text straight after you have started the process, it may fail due to one of many possible reasons (e.g. the handle to the control which displays the text does not exist at the time of the function call). So the solution ... |
2673771 | why is the line #!/bin/ksh is the first line in a shell script | 11 | 2010-04-20 08:53:02 | <p><code>#!/bin/ksh</code> is the first line in a shell script always</p>
<p>what is the importance of this line and why is it kept as the first line.</p>
| 50,158 | 134,713 | 2010-04-20 08:54:38 | 2,673,779 | 11 | 2010-04-20 08:54:30 | 28,169 | 2010-04-20 08:54:30 | https://stackoverflow.com/q/2673771 | https://stackoverflow.com/a/2673779 | <p>This line tells the operating system what interpreter to invoke to run the script.</p>
<p>Without it, there's no way to know that this script needs to be run using the <code>ksh</code> interpreter.</p>
<p>The sequence is known as a "shebang", and you can read more about it on <a href="http://en.wikipedia.org/wiki/... | <p>This line tells the operating system what interpreter to invoke to run the script.</p> <p>Without it, there's no way to know that this script needs to be run using the <code>ksh</code> interpreter.</p> <p>The sequence is known as a "shebang", and you can read more about it on <a href="http://en.wikipedia.org/wiki/... | 34, 390 | shell, unix | <h1>why is the line #!/bin/ksh is the first line in a shell script</h1>
<p><code>#!/bin/ksh</code> is the first line in a shell script always</p>
<p>what is the importance of this line and why is it kept as the first line.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,347 | bash | # why is the line #!/bin/ksh is the first line in a shell script
`#!/bin/ksh` is the first line in a shell script always
what is the importance of this line and why is it kept as the first line. | This line tells the operating system what interpreter to invoke to run the script.
Without it, there's no way to know that this script needs to be run using the `ksh` interpreter.
The sequence is known as a "shebang", and you can read more about it on [Wikipedia](http://en.wikipedia.org/wiki/Shebang_%28Unix%29). |
1475111 | Retrieving the First Non-Option Command Line Argument | 11 | 2009-09-25 02:18:07 | <p>I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in</p>
<pre><code>$ mycommand -o option1 -f another --spec more arg1 arg2
</code></pre>
<p>I want to retrieve "arg1."</p>
<p>How can this be done i... | 4,057 | 122,147 | 2009-09-28 14:28:35 | 1,475,223 | 11 | 2009-09-25 03:01:49 | 140,740 | 2009-09-25 03:01:49 | https://stackoverflow.com/q/1475111 | https://stackoverflow.com/a/1475223 | <p>Using <a href="http://linux.die.net/man/1/getopt" rel="noreferrer">getopt</a> is probably the way to go. </p>
<p>If you wanted to see argument scanning code in bash, the non-getopt way is:</p>
<pre><code>realargs="$@"
while [ $# -gt 0 ]; do
case "$1" in
-x | -y | -z)
echo recognized one argument ... | <p>Using <a href="http://linux.die.net/man/1/getopt" rel="noreferrer">getopt</a> is probably the way to go. </p> <p>If you wanted to see argument scanning code in bash, the non-getopt way is:</p> <pre><code>realargs="$@" while [ $# -gt 0 ]; do case "$1" in -x | -y | -z) echo recognized one argument ... | 387, 390, 13551 | bash, shell, wrapper | <h1>Retrieving the First Non-Option Command Line Argument</h1>
<p>I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in</p>
<pre><code>$ mycommand -o option1 -f another --spec more arg1 arg2
</code></pre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,348 | bash | # Retrieving the First Non-Option Command Line Argument
I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in
```
$ mycommand -o option1 -f another --spec more arg1 arg2
```
I want to retrieve "arg1."
... | Using [getopt](http://linux.die.net/man/1/getopt) is probably the way to go.
If you wanted to see argument scanning code in bash, the non-getopt way is:
```
realargs="$@"
while [ $# -gt 0 ]; do
case "$1" in
-x | -y | -z)
echo recognized one argument option $1 with arg $2
shift
;;
... |
1061664 | Does renice on a parent renice the child? | 11 | 2009-06-30 04:04:09 | <p>I know if I nice a shell script (ie: before it runs) all processes that start from the shell script will also be niced.</p>
<p>What if I start a shell script and the renice it, do all the child processes become reniced as well?</p>
<p>Looked in the renice man pages and there are no mention of child processes.</p>
| 4,776 | 42,303 | 2009-06-30 04:16:33 | 1,061,699 | 11 | 2009-06-30 04:16:33 | 14,860 | 2009-06-30 04:16:33 | https://stackoverflow.com/q/1061664 | https://stackoverflow.com/a/1061699 | <p>Children inherit the <em>current</em> priority of a process when they're created. That means, if you renice the parent and start a child, it will have the modified priority.</p>
<p>Children that are already running when you renice are not affected.</p>
<p>The clue is in the <code>fork()</code> man pages (starting ... | <p>Children inherit the <em>current</em> priority of a process when they're created. That means, if you renice the parent and start a child, it will have the modified priority.</p> <p>Children that are already running when you renice are not affected.</p> <p>The clue is in the <code>fork()</code> man pages (starting ... | 390, 14919, 33567 | nice, renice, shell | <h1>Does renice on a parent renice the child?</h1>
<p>I know if I nice a shell script (ie: before it runs) all processes that start from the shell script will also be niced.</p>
<p>What if I start a shell script and the renice it, do all the child processes become reniced as well?</p>
<p>Looked in the renice man page... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,349 | bash | # Does renice on a parent renice the child?
I know if I nice a shell script (ie: before it runs) all processes that start from the shell script will also be niced.
What if I start a shell script and the renice it, do all the child processes become reniced as well?
Looked in the renice man pages and there are no ment... | Children inherit the *current* priority of a process when they're created. That means, if you renice the parent and start a child, it will have the modified priority.
Children that are already running when you renice are not affected.
The clue is in the `fork()` man pages (starting a child is a `fork/exec` operation)... |
48774 | Boolean Expressions in Shell Scripts | 11 | 2008-09-07 20:51:35 | <p>What's the "right" way to do the following as a boolean expression?</p>
<pre><code>for i in `ls $1/resources`; do
if [ $i != "database.db" ]
then
if [ $i != "tiles" ]
then
if [ $i != "map.pdf" ]
then
if [ $i != "map.png" ]
then
... | 19,642 | 79 | 2015-07-25 19:10:08 | 64,106 | 11 | 2008-09-15 15:47:04 | 4,421 | 2013-12-03 01:08:31 | https://stackoverflow.com/q/48774 | https://stackoverflow.com/a/64106 | <p>The other solutions have a couple of common mistakes:
<a href="http://www.pixelbeat.org/programming/shell_script_mistakes.html" rel="nofollow noreferrer">http://www.pixelbeat.org/programming/shell_script_mistakes.html</a></p>
<ol>
<li><p><code>for i in $(ls ...)</code> is redundant/problematic
just do: <code>for i ... | <p>The other solutions have a couple of common mistakes: <a href="http://www.pixelbeat.org/programming/shell_script_mistakes.html" rel="nofollow noreferrer">http://www.pixelbeat.org/programming/shell_script_mistakes.html</a></p> <ol> <li><p><code>for i in $(ls ...)</code> is redundant/problematic just do: <code>for i ... | 387, 390, 2095 | bash, expression, shell | <h1>Boolean Expressions in Shell Scripts</h1>
<p>What's the "right" way to do the following as a boolean expression?</p>
<pre><code>for i in `ls $1/resources`; do
if [ $i != "database.db" ]
then
if [ $i != "tiles" ]
then
if [ $i != "map.pdf" ]
then
if [ $... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,350 | bash | # Boolean Expressions in Shell Scripts
What's the "right" way to do the following as a boolean expression?
```
for i in `ls $1/resources`; do
if [ $i != "database.db" ]
then
if [ $i != "tiles" ]
then
if [ $i != "map.pdf" ]
then
if [ $i != "map.png" ]
... | The other solutions have a couple of common mistakes:
<http://www.pixelbeat.org/programming/shell_script_mistakes.html>
1. `for i in $(ls ...)` is redundant/problematic
just do: `for i in $1/resources*; do ...`
2. `[ $i != file1 -a $1 != file2 ]` This actually has 2 problems.
a. The `$i` is not quoted, hence na... |
52337101 | Curl Error: Parameter cannot be processed because the parameter name 'u' is ambiguous | 10 | 2018-09-14 17:57:38 | <p>I am trying to connect (in PowerShell) via
<strong>curl</strong>
but with no success.</p>
<p>Below is the following code I've inserting in order to establish the connection:</p>
<pre><code> curl -u <USER>:<PASSWORD> https://something.com
</code></pre>
<p>but got the error:</p>
<pre><code> Invoke-W... | 17,362 | 5,461,381 | 2022-10-05 18:14:34 | 73,095,976 | 11 | 2022-07-24 05:23:35 | 12,991,445 | 2022-07-24 05:23:35 | https://stackoverflow.com/q/52337101 | https://stackoverflow.com/a/73095976 | <p>As @Maximilian Burszley wrote, curl in PowerShell is an alias to another command, not the curl command you intended.</p>
<p>In my opinion the simplest solution is to remove the alias, and then the curl command will be available without the overhead of Get-Alias and without using curl with the executable's path.</p>
... | <p>As @Maximilian Burszley wrote, curl in PowerShell is an alias to another command, not the curl command you intended.</p> <p>In my opinion the simplest solution is to remove the alias, and then the curl command will be available without the overhead of Get-Alias and without using curl with the executable's path.</p> ... | 526, 1554 | curl, powershell | <h1>Curl Error: Parameter cannot be processed because the parameter name 'u' is ambiguous</h1>
<p>I am trying to connect (in PowerShell) via
<strong>curl</strong>
but with no success.</p>
<p>Below is the following code I've inserting in order to establish the connection:</p>
<pre><code> curl -u <USER>:<PAS... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,351 | bash | # Curl Error: Parameter cannot be processed because the parameter name 'u' is ambiguous
I am trying to connect (in PowerShell) via
**curl**
but with no success.
Below is the following code I've inserting in order to establish the connection:
```
curl -u <USER>:<PASSWORD> https://something.com
```
but got the erro... | As @Maximilian Burszley wrote, curl in PowerShell is an alias to another command, not the curl command you intended.
In my opinion the simplest solution is to remove the alias, and then the curl command will be available without the overhead of Get-Alias and without using curl with the executable's path.
This is the ... |
69026642 | jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level> | 10 | 2021-09-02 08:22:58 | <pre class="lang-sh prettyprint-override"><code>cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44ab"
jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.organizations.Org1MSP.adminPrivate... | 26,218 | 10,744,717 | 2025-10-27 09:00:47 | 69,027,872 | 11 | 2021-09-02 09:46:34 | 9,952,196 | 2021-09-02 09:46:34 | https://stackoverflow.com/q/69026642 | https://stackoverflow.com/a/69027872 | <p>You can assign a string to a variable that can be used inside a <code>jq</code> filter:</p>
<pre class="lang-sh prettyprint-override"><code>PRIV_KEY="44ab..._sk"
jq --arg path "$PRIV_KEY" '.organizations.Org1MSP.adminPrivateKey.path |= $path' explorer/connection-profile/test-network.json
</code>... | <p>You can assign a string to a variable that can be used inside a <code>jq</code> filter:</p> <pre class="lang-sh prettyprint-override"><code>PRIV_KEY="44ab..._sk" jq --arg path "$PRIV_KEY" '.organizations.Org1MSP.adminPrivateKey.path |= $path' explorer/connection-profile/test-network.json </code>... | 276, 390, 9993, 105170 | jq, shell, syntax-error, variables | <h1>jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level></h1>
<pre class="lang-sh prettyprint-override"><code>cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44ab"
jq: error: syntax error, unexpected IDENT... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,352 | bash | # jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at
```
cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44ab"
jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.o... | You can assign a string to a variable that can be used inside a `jq` filter:
```
PRIV_KEY="44ab..._sk"
jq --arg path "$PRIV_KEY" '.organizations.Org1MSP.adminPrivateKey.path |= $path' explorer/connection-profile/test-network.json
```
This method is safer than trying to embed an expanded shell variable directly in the... |
63102809 | POSIX: abcdef to ab bc cd de ef | 10 | 2020-07-26 16:29:30 | <p>Using POSIX <code>sed</code> or <code>awk</code>, I would like to duplicate every second character in every pair of neighboring characters and list every newly-formed pair on a new line.</p>
<p>example.txt:</p>
<pre><code>abcd 10001.
</code></pre>
<p>Expected result:</p>
<pre><code>ab
bc
cd
d
1
10
00
00
01
1.
</co... | 364 | 908,703 | 2020-07-31 13:43:22 | 63,103,052 | 11 | 2020-07-26 16:51:01 | 298,607 | 2020-07-26 16:51:01 | https://stackoverflow.com/q/63102809 | https://stackoverflow.com/a/63103052 | <p>Try:</p>
<pre><code>$ echo "abcd 10001." | awk '{for(i=1;i<length($0);i++) print substr($0,i,2)}'
ab
bc
cd
d
1
10
00
00
01
1.
</code></pre>
| <p>Try:</p> <pre><code>$ echo "abcd 10001." | awk '{for(i=1;i<length($0);i++) print substr($0,i,2)}' ab bc cd d 1 10 00 00 01 1. </code></pre> | 390, 990, 1993, 5282 | awk, posix, sed, shell | <h1>POSIX: abcdef to ab bc cd de ef</h1>
<p>Using POSIX <code>sed</code> or <code>awk</code>, I would like to duplicate every second character in every pair of neighboring characters and list every newly-formed pair on a new line.</p>
<p>example.txt:</p>
<pre><code>abcd 10001.
</code></pre>
<p>Expected result:</p>
<pre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,353 | bash | # POSIX: abcdef to ab bc cd de ef
Using POSIX `sed` or `awk`, I would like to duplicate every second character in every pair of neighboring characters and list every newly-formed pair on a new line.
example.txt:
```
abcd 10001.
```
Expected result:
```
ab
bc
cd
d
1
10
00
00
01
1.
```
So far, this is what I have... | Try:
```
$ echo "abcd 10001." | awk '{for(i=1;i<length($0);i++) print substr($0,i,2)}'
ab
bc
cd
d
1
10
00
00
01
1.
``` |
59229488 | Using PowerShell sls (Select-String) vs grep vs findstr | 10 | 2019-12-07 19:33:43 | <p>Could someone clarify how sls (Select-String) works compared to grep and findstr?</p>
<p>grep: <code>grep <pattern> files.txt</code></p>
<p>sls: <code>sls <pattern> files.txt</code>
(default parameter position for sls is pattern then file)</p>
<p>grep examples: <code>grep "search text" *.log</code> ;... | 9,936 | 524,587 | 2021-04-08 21:25:06 | 59,230,138 | 11 | 2019-12-07 20:56:30 | 11,025,476 | 2019-12-07 21:12:55 | https://stackoverflow.com/q/59229488 | https://stackoverflow.com/a/59230138 | <p>When you use <code>Out-String</code> by default, it turns the piped input object (an array of service objects in this case) into a single string. Luckily, the <code>-Stream</code> switch allows each line to be output as a single string instead. Regarding case-sensitivity, <code>Select-String</code> supports the <cod... | <p>When you use <code>Out-String</code> by default, it turns the piped input object (an array of service objects in this case) into a single string. Luckily, the <code>-Stream</code> switch allows each line to be output as a single string instead. Regarding case-sensitivity, <code>Select-String</code> supports the <cod... | 139, 488, 526 | console, powershell, string | <h1>Using PowerShell sls (Select-String) vs grep vs findstr</h1>
<p>Could someone clarify how sls (Select-String) works compared to grep and findstr?</p>
<p>grep: <code>grep <pattern> files.txt</code></p>
<p>sls: <code>sls <pattern> files.txt</code>
(default parameter position for sls is pattern then file... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,354 | bash | # Using PowerShell sls (Select-String) vs grep vs findstr
Could someone clarify how sls (Select-String) works compared to grep and findstr?
grep: `grep <pattern> files.txt`
sls: `sls <pattern> files.txt`
(default parameter position for sls is pattern then file)
grep examples: `grep "search text" *.log` ; `cat *.log... | When you use `Out-String` by default, it turns the piped input object (an array of service objects in this case) into a single string. Luckily, the `-Stream` switch allows each line to be output as a single string instead. Regarding case-sensitivity, `Select-String` supports the `-CaseSensitive` switch.
```
# For case... |
38561009 | Where is the standard place to put a PowerShell script version number? | 10 | 2016-07-25 06:29:01 | <p>Since PowerShell version 3 there has been very well defined comment based help comment block:
<a href="https://technet.microsoft.com/en-us/library/hh847834.aspx" rel="noreferrer">https://technet.microsoft.com/en-us/library/hh847834.aspx</a>
What I would like to know is there a standard for versioning a PowerShell sc... | 11,695 | 6,602,343 | 2019-07-19 18:03:55 | 57,051,598 | 11 | 2019-07-16 06:55:10 | 1,701,026 | 2019-07-17 08:34:57 | https://stackoverflow.com/q/38561009 | https://stackoverflow.com/a/57051598 | <p>Use the <code>ScriptFileInfo</code> cmdlets, like: <a href="https://learn.microsoft.com/en-us/powershell/module/powershellget/new-scriptfileinfo?view=powershell-6" rel="noreferrer"><code>New-ScriptFileInfo</code></a></p>
<pre><code><#PSScriptInfo
.VERSION 1.0.1
.GUID 54688e75-298c-4d4b-a2d0-1234567890ab
.AUTHOR ... | <p>Use the <code>ScriptFileInfo</code> cmdlets, like: <a href="https://learn.microsoft.com/en-us/powershell/module/powershellget/new-scriptfileinfo?view=powershell-6" rel="noreferrer"><code>New-ScriptFileInfo</code></a></p> <pre><code><#PSScriptInfo .VERSION 1.0.1 .GUID 54688e75-298c-4d4b-a2d0-1234567890ab .AUTHOR ... | 9, 526, 5792 | c#, powershell, version | <h1>Where is the standard place to put a PowerShell script version number?</h1>
<p>Since PowerShell version 3 there has been very well defined comment based help comment block:
<a href="https://technet.microsoft.com/en-us/library/hh847834.aspx" rel="noreferrer">https://technet.microsoft.com/en-us/library/hh847834.aspx<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,355 | bash | # Where is the standard place to put a PowerShell script version number?
Since PowerShell version 3 there has been very well defined comment based help comment block:
<https://technet.microsoft.com/en-us/library/hh847834.aspx>
What I would like to know is there a standard for versioning a PowerShell script like there ... | Use the `ScriptFileInfo` cmdlets, like: [`New-ScriptFileInfo`](https://learn.microsoft.com/en-us/powershell/module/powershellget/new-scriptfileinfo?view=powershell-6)
```
<#PSScriptInfo
.VERSION 1.0.1
.GUID 54688e75-298c-4d4b-a2d0-1234567890ab
.AUTHOR iRon
.DESCRIPTION Your description
.COMPANYNAME
.COPYRIGHT
.TAGS Po... |
53687124 | Bash : Check if file is sorted with sort -c file | 10 | 2018-12-08 21:24:53 | <p>With </p>
<pre><code>sort -c file
</code></pre>
<p>I received the first bad line that is unsorted as report, or nothing if the file is sorted. (And sort -c do not sort the file.)</p>
<p>I want to check if I received a report or not.
Something going like this :</p>
<pre><code>if [ $(sort -c file) == *something* ]... | 6,995 | 7,563,004 | 2020-08-05 17:35:53 | 53,687,147 | 11 | 2018-12-08 21:28:55 | 3,776,858 | 2018-12-08 21:28:55 | https://stackoverflow.com/q/53687124 | https://stackoverflow.com/a/53687147 | <pre><code>if sort -C file; then
# return code 0
echo "sorted"
else
# return code not 0
echo "not sorted"
fi
</code></pre>
| <pre><code>if sort -C file; then # return code 0 echo "sorted" else # return code not 0 echo "not sorted" fi </code></pre> | 134, 387 | bash, sorting | <h1>Bash : Check if file is sorted with sort -c file</h1>
<p>With </p>
<pre><code>sort -c file
</code></pre>
<p>I received the first bad line that is unsorted as report, or nothing if the file is sorted. (And sort -c do not sort the file.)</p>
<p>I want to check if I received a report or not.
Something going like th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,356 | bash | # Bash : Check if file is sorted with sort -c file
With
```
sort -c file
```
I received the first bad line that is unsorted as report, or nothing if the file is sorted. (And sort -c do not sort the file.)
I want to check if I received a report or not.
Something going like this :
```
if [ $(sort -c file) == *someth... | ```
if sort -C file; then
# return code 0
echo "sorted"
else
# return code not 0
echo "not sorted"
fi
``` |
50778021 | how to reload .bashrc in dockerfile | 10 | 2018-06-09 19:58:16 | <p>I am adding many things to the .bashrc in the Dockerfile which is necessary to execute some of the commands I want to run later in the Dockerfile,<br />
I tried <code>source .bashrc</code> which does not work.<br />
I tried using <code>RUN /bin/bash -c --login ...</code> but I get an error : <code>mesg: ttyname fail... | 15,395 | 6,270,020 | 2024-02-12 17:21:02 | 50,780,759 | 11 | 2018-06-10 05:15:32 | 6,309 | 2020-01-15 11:59:41 | https://stackoverflow.com/q/50778021 | https://stackoverflow.com/a/50780759 | <p>Each command in a Dockerfile creates a new temporary container, but without tty (<a href="https://github.com/moby/moby/issues/1870" rel="noreferrer">issue 1870</a>, discussed in <a href="https://github.com/moby/moby/pull/4955" rel="noreferrer">PR 4955</a>, but closed in favor of <a href="https://github.com/moby/moby... | <p>Each command in a Dockerfile creates a new temporary container, but without tty (<a href="https://github.com/moby/moby/issues/1870" rel="noreferrer">issue 1870</a>, discussed in <a href="https://github.com/moby/moby/pull/4955" rel="noreferrer">PR 4955</a>, but closed in favor of <a href="https://github.com/moby/moby... | 387, 90304, 108477 | bash, docker, dockerfile | <h1>how to reload .bashrc in dockerfile</h1>
<p>I am adding many things to the .bashrc in the Dockerfile which is necessary to execute some of the commands I want to run later in the Dockerfile,<br />
I tried <code>source .bashrc</code> which does not work.<br />
I tried using <code>RUN /bin/bash -c --login ...</code> ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,357 | bash | # how to reload .bashrc in dockerfile
I am adding many things to the .bashrc in the Dockerfile which is necessary to execute some of the commands I want to run later in the Dockerfile,
I tried `source .bashrc` which does not work.
I tried using `RUN /bin/bash -c --login ...` but I get an error : `mesg: ttyname fai... | Each command in a Dockerfile creates a new temporary container, but without tty ([issue 1870](https://github.com/moby/moby/issues/1870), discussed in [PR 4955](https://github.com/moby/moby/pull/4955), but closed in favor of [PR 4882](https://github.com/moby/moby/pull/4882)).
The lack of tty during docker builds trigge... |
46922689 | How to purge messages for Service Bus Topic Subscription | 10 | 2017-10-25 01:51:59 | <p>Just wondering the best way (even if via Portal, Powershell, or C#) to purge the messages off of a Service Bus Topic's Subscription.</p>
<p>Imagine we have a topic with 4 subscriptions, and we only want to purge the messages from one of the subscriptions.</p>
<p>I have a feeling the only way may be to read the mes... | 20,290 | 3,003,119 | 2024-10-28 11:24:06 | 46,923,108 | 11 | 2017-10-25 02:43:48 | 188,096 | 2017-10-25 02:43:48 | https://stackoverflow.com/q/46922689 | https://stackoverflow.com/a/46923108 | <p>You can most certainly do it via code. If you're using <a href="https://www.nuget.org/packages/WindowsAzure.ServiceBus/" rel="noreferrer"><code>Service Bus SDK</code></a>, you could do something like the following:</p>
<pre><code> static void PurgeMessagesFromSubscription()
{
var connectionString = "... | <p>You can most certainly do it via code. If you're using <a href="https://www.nuget.org/packages/WindowsAzure.ServiceBus/" rel="noreferrer"><code>Service Bus SDK</code></a>, you could do something like the following:</p> <pre><code> static void PurgeMessagesFromSubscription() { var connectionString = "... | 9, 526, 14158, 77249, 112770 | azure, azureservicebus, azure-servicebus-topics, c#, powershell | <h1>How to purge messages for Service Bus Topic Subscription</h1>
<p>Just wondering the best way (even if via Portal, Powershell, or C#) to purge the messages off of a Service Bus Topic's Subscription.</p>
<p>Imagine we have a topic with 4 subscriptions, and we only want to purge the messages from one of the subscript... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,358 | bash | # How to purge messages for Service Bus Topic Subscription
Just wondering the best way (even if via Portal, Powershell, or C#) to purge the messages off of a Service Bus Topic's Subscription.
Imagine we have a topic with 4 subscriptions, and we only want to purge the messages from one of the subscriptions.
I have a ... | You can most certainly do it via code. If you're using [`Service Bus SDK`](https://www.nuget.org/packages/WindowsAzure.ServiceBus/), you could do something like the following:
```
static void PurgeMessagesFromSubscription()
{
var connectionString = "Endpoint=sb://account-name.servicebus.windows.net/;Sh... |
46216038 | How do I define RequiredModules in a PowerShell module manifest (psd1)? | 10 | 2017-09-14 09:57:51 | <p>I'm trying to create a simple dependency between two PowerShell modules, but I'm getting the syntax or <em>something</em> wrong. </p>
<p><code>Module1.psd1</code>:</p>
<pre><code>@{
RootModule = 'Module1.psm1'
ModuleVersion = '1.0'
GUID = '11111111-1111-1111-1111-111111111111'
... | 10,401 | 1,764,844 | 2019-02-17 20:48:42 | 46,236,512 | 11 | 2017-09-15 09:41:25 | 1,764,844 | 2017-09-15 09:41:25 | https://stackoverflow.com/q/46216038 | https://stackoverflow.com/a/46236512 | <p>The issue turned out to be that <code>Test-ModuleManifest</code> expects all required modules to be installed on the local system.</p>
<p>So the fix is to install <code>Module1</code>, then validate the manifest of <code>Module2</code>.</p>
<p>See <a href="https://github.com/PowerShell/PowerShellGet/blob/90c5a3d4c... | <p>The issue turned out to be that <code>Test-ModuleManifest</code> expects all required modules to be installed on the local system.</p> <p>So the fix is to install <code>Module1</code>, then validate the manifest of <code>Module2</code>.</p> <p>See <a href="https://github.com/PowerShell/PowerShellGet/blob/90c5a3d4c... | 526, 3849, 7720 | manifest, module, powershell | <h1>How do I define RequiredModules in a PowerShell module manifest (psd1)?</h1>
<p>I'm trying to create a simple dependency between two PowerShell modules, but I'm getting the syntax or <em>something</em> wrong. </p>
<p><code>Module1.psd1</code>:</p>
<pre><code>@{
RootModule = 'Module1.psm1'
ModuleVer... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,359 | bash | # How do I define RequiredModules in a PowerShell module manifest (psd1)?
I'm trying to create a simple dependency between two PowerShell modules, but I'm getting the syntax or *something* wrong.
`Module1.psd1`:
```
@{
RootModule = 'Module1.psm1'
ModuleVersion = '1.0'
GUID = '1111... | The issue turned out to be that `Test-ModuleManifest` expects all required modules to be installed on the local system.
So the fix is to install `Module1`, then validate the manifest of `Module2`.
See <https://github.com/PowerShell/PowerShellGet/blob/90c5a3d4c8a2e698d38cfb5ef4b1c44d79180d66/Tests/PSGetPublishModule.T... |
44970342 | Why is an empty loop invalid in shell script? | 10 | 2017-07-07 12:04:51 | <p>I wanted to make my shell script wait infinitely and thought the below code would do it.</p>
<pre><code>#!/bin/bash
while true
do
done
</code></pre>
<p>However, the above script reports syntax error.</p>
<blockquote>
<p>./Infinite_Loop.sh: line 4: syntax error near unexpected token `done'</p>
<p>./Infinite_Loop.sh: ... | 12,974 | 8,219,037 | 2017-07-07 12:42:24 | 44,970,532 | 11 | 2017-07-07 12:15:30 | 1,347,519 | 2017-07-07 12:42:24 | https://stackoverflow.com/q/44970342 | https://stackoverflow.com/a/44970532 | <blockquote>
<p>I wanted to make my shell script wait infinitely</p>
</blockquote>
<p>If your system supports it use:</p>
<pre class="lang-sh prettyprint-override"><code>sleep infinity
</code></pre>
<p>If your system doesn't support it, use <code>sleep</code> with a large interval:</p>
<pre class="lang-sh prettyp... | <blockquote> <p>I wanted to make my shell script wait infinitely</p> </blockquote> <p>If your system supports it use:</p> <pre class="lang-sh prettyprint-override"><code>sleep infinity </code></pre> <p>If your system doesn't support it, use <code>sleep</code> with a large interval:</p> <pre class="lang-sh prettyp... | 387, 390, 2314 | bash, loops, shell | <h1>Why is an empty loop invalid in shell script?</h1>
<p>I wanted to make my shell script wait infinitely and thought the below code would do it.</p>
<pre><code>#!/bin/bash
while true
do
done
</code></pre>
<p>However, the above script reports syntax error.</p>
<blockquote>
<p>./Infinite_Loop.sh: line 4: syntax error n... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,360 | bash | # Why is an empty loop invalid in shell script?
I wanted to make my shell script wait infinitely and thought the below code would do it.
```
#!/bin/bash
while true
do
done
```
However, the above script reports syntax error.
> ./Infinite_Loop.sh: line 4: syntax error near unexpected token `done'
>
> ./Infinite_Loop.... | > I wanted to make my shell script wait infinitely
If your system supports it use:
```
sleep infinity
```
If your system doesn't support it, use `sleep` with a large interval:
```
while :; do sleep 86400; done
```
Note:
- Using `while :` in place of `while true` may/will remove an unnecessary `fork`, depending on... |
41806280 | Modify a byte in a binary file using standard Linux command-line tools | 10 | 2017-01-23 12:22:11 | <p>I need to modify a byte in a binary file at a certain offset.</p>
<p><strong>Example:</strong></p>
<ul>
<li>Input file: <code>A.bin</code></li>
<li>Output file: <code>B.bin</code></li>
</ul>
<p>I need to read a byte at the offset <code>0x40c</code> from <code>A.bin</code>, clear to 0 least significant 2 bits of this... | 11,351 | 552,247 | 2022-05-24 04:01:17 | 41,807,154 | 11 | 2017-01-23 13:07:23 | 119,861 | 2022-05-24 04:01:17 | https://stackoverflow.com/q/41806280 | https://stackoverflow.com/a/41807154 | <pre class="lang-html prettyprint-override"><code># Read one byte at offset 40C
b_hex=$(xxd -seek $((16#40C)) -l 1 -ps A.bin -)
# Delete the three least significant bits
b_dec=$(($((16#$b_hex)) & $((2#11111000))))
cp A.bin B.bin
# Write one byte back at offset 40C
printf "00040c: %02x" $b_dec | xxd -r -... | <pre class="lang-html prettyprint-override"><code># Read one byte at offset 40C b_hex=$(xxd -seek $((16#40C)) -l 1 -ps A.bin -) # Delete the three least significant bits b_dec=$(($((16#$b_hex)) & $((2#11111000)))) cp A.bin B.bin # Write one byte back at offset 40C printf "00040c: %02x" $b_dec | xxd -r -... | 368, 387, 390, 2132, 5826 | bash, binary, edit, patch, shell | <h1>Modify a byte in a binary file using standard Linux command-line tools</h1>
<p>I need to modify a byte in a binary file at a certain offset.</p>
<p><strong>Example:</strong></p>
<ul>
<li>Input file: <code>A.bin</code></li>
<li>Output file: <code>B.bin</code></li>
</ul>
<p>I need to read a byte at the offset <code>0... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,361 | bash | # Modify a byte in a binary file using standard Linux command-line tools
I need to modify a byte in a binary file at a certain offset.
**Example:**
- Input file: `A.bin`
- Output file: `B.bin`
I need to read a byte at the offset `0x40c` from `A.bin`, clear to 0 least significant 2 bits of this byte, and then write ... | ```
# Read one byte at offset 40C
b_hex=$(xxd -seek $((16#40C)) -l 1 -ps A.bin -)
# Delete the three least significant bits
b_dec=$(($((16#$b_hex)) & $((2#11111000))))
cp A.bin B.bin
# Write one byte back at offset 40C
printf "00040c: %02x" $b_dec | xxd -r - B.bin
```
It was tested in Bash and [Z shell](https://en.w... |
37926844 | How to mock a call to an exe file with Pester? | 10 | 2016-06-20 15:55:23 | <p>Developing a script in PowerShell, I require to call an external executable file(.exe). currently I am developing this script with a TDD approach, therefore I require to mock the called to this .exe file.</p>
<p>I try this :</p>
<pre><code>Describe "Create-NewObject" {
Context "Create-Object" {
It "Run... | 3,756 | 2,785,211 | 2020-05-05 07:14:07 | 37,927,372 | 11 | 2016-06-20 16:22:18 | 2,785,211 | 2016-06-20 16:22:18 | https://stackoverflow.com/q/37926844 | https://stackoverflow.com/a/37927372 | <p>I found a way to mock the call to this executable files:</p>
<pre><code>function Create-Object
{
$exp = '& "C:\temp\my.exe"'
Invoke-Expression -Command $exp
}
</code></pre>
<p>And the test with the mock should looks like:</p>
<pre><code>Describe "Create-NewObject" {
Context "Create-Object" {
... | <p>I found a way to mock the call to this executable files:</p> <pre><code>function Create-Object { $exp = '& "C:\temp\my.exe"' Invoke-Expression -Command $exp } </code></pre> <p>And the test with the mock should looks like:</p> <pre><code>Describe "Create-NewObject" { Context "Create-Object" { ... | 526, 1931, 6691, 80193 | mocking, pester, powershell, unit-testing | <h1>How to mock a call to an exe file with Pester?</h1>
<p>Developing a script in PowerShell, I require to call an external executable file(.exe). currently I am developing this script with a TDD approach, therefore I require to mock the called to this .exe file.</p>
<p>I try this :</p>
<pre><code>Describe "Create-Ne... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,362 | bash | # How to mock a call to an exe file with Pester?
Developing a script in PowerShell, I require to call an external executable file(.exe). currently I am developing this script with a TDD approach, therefore I require to mock the called to this .exe file.
I try this :
```
Describe "Create-NewObject" {
Context "Cre... | I found a way to mock the call to this executable files:
```
function Create-Object
{
$exp = '& "C:\temp\my.exe"'
Invoke-Expression -Command $exp
}
```
And the test with the mock should looks like:
```
Describe "Create-NewObject" {
Context "Create-Object" {
It "Runs" {
Mock Invoke-Expre... |
36293083 | How to stop PowerShell SqlCommand from echoing parameters | 10 | 2016-03-29 19:09:57 | <p>I have a few functions that use the SqlCommand object to to data inserts, and queries. But one function (the last one in the file) seems to echo (most of) the attributes into the output. The function in question: </p>
<pre><code>function Add-DataStudentChangeEvent($person,
$key,
$currentValue,
... | 5,012 | 90,764 | 2016-03-29 19:34:20 | 36,293,546 | 11 | 2016-03-29 19:34:20 | 1,001,100 | 2016-03-29 19:34:20 | https://stackoverflow.com/q/36293083 | https://stackoverflow.com/a/36293546 | <p>What you are seeing are return values from functions. For example, <code>SqlParameterCollection.AddWithValue()</code> returns a <strong>SqlParameter</strong>, and <code>SqlCommand.ExecuteNonQuery()</code> returns an <strong>int</strong>. Unlike C#, any values that you don't explicitly deal with, will be written to... | <p>What you are seeing are return values from functions. For example, <code>SqlParameterCollection.AddWithValue()</code> returns a <strong>SqlParameter</strong>, and <code>SqlCommand.ExecuteNonQuery()</code> returns an <strong>int</strong>. Unlike C#, any values that you don't explicitly deal with, will be written to... | 526, 4852 | powershell, sqlcommand | <h1>How to stop PowerShell SqlCommand from echoing parameters</h1>
<p>I have a few functions that use the SqlCommand object to to data inserts, and queries. But one function (the last one in the file) seems to echo (most of) the attributes into the output. The function in question: </p>
<pre><code>function Add-DataStu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,363 | bash | # How to stop PowerShell SqlCommand from echoing parameters
I have a few functions that use the SqlCommand object to to data inserts, and queries. But one function (the last one in the file) seems to echo (most of) the attributes into the output. The function in question:
```
function Add-DataStudentChangeEvent($pers... | What you are seeing are return values from functions. For example, `SqlParameterCollection.AddWithValue()` returns a **SqlParameter**, and `SqlCommand.ExecuteNonQuery()` returns an **int**. Unlike C#, any values that you don't explicitly deal with, will be written to the output stream.
There are two ways to deal with ... |
35780715 | How to set environment variables of parent shell in Python? | 10 | 2016-03-03 18:59:57 | <p>I'm trying to modify the environment variables on a parent shell from within Python. What I've attempted so far hasn't worked:</p>
<pre><code>~ $ export TESTING=test
~ $ echo $TESTING
test
~ $
~ $
~ $ python
Python 2.7.10 (default, Jun 1 2015, 18:05:38)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or... | 19,531 | 702,948 | 2019-10-05 14:08:45 | 35,780,849 | 11 | 2016-03-03 19:06:53 | 3,697,163 | 2016-03-03 19:14:17 | https://stackoverflow.com/q/35780715 | https://stackoverflow.com/a/35780849 | <p>This isn't possible. </p>
<p>Child processes inherit their environments from their parents rather than share them. Therefore any modifications you make to your environment will be reflected <em>only</em> in the child (python) process. Practically, you're just overwriting the dictionary the <code>os</code> module ha... | <p>This isn't possible. </p> <p>Child processes inherit their environments from their parents rather than share them. Therefore any modifications you make to your environment will be reflected <em>only</em> in the child (python) process. Practically, you're just overwriting the dictionary the <code>os</code> module ha... | 16, 390, 9013 | environment-variables, python, shell | <h1>How to set environment variables of parent shell in Python?</h1>
<p>I'm trying to modify the environment variables on a parent shell from within Python. What I've attempted so far hasn't worked:</p>
<pre><code>~ $ export TESTING=test
~ $ echo $TESTING
test
~ $
~ $
~ $ python
Python 2.7.10 (default, Jun 1 2015, 1... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,364 | bash | # How to set environment variables of parent shell in Python?
I'm trying to modify the environment variables on a parent shell from within Python. What I've attempted so far hasn't worked:
```
~ $ export TESTING=test
~ $ echo $TESTING
test
~ $
~ $
~ $ python
Python 2.7.10 (default, Jun 1 2015, 18:05:38)
[GCC 4.9.2] ... | This isn't possible.
Child processes inherit their environments from their parents rather than share them. Therefore any modifications you make to your environment will be reflected *only* in the child (python) process. Practically, you're just overwriting the dictionary the `os` module has created based on your envir... |
30127764 | Finding a file within recursive directory of zip files | 10 | 2015-05-08 15:41:22 | <p>I have an entire directory structure with zip files. I would like to:</p>
<ol>
<li>Traverse the entire directory structure recursively grabbing all the zip files</li>
<li>I would like to find a specific file "*myLostFile.ext" within one of these zip files.</li>
</ol>
<p><strong>What I have tried</strong><br>
1. I ... | 18,845 | 117,700 | 2024-06-06 19:23:25 | 30,128,230 | 11 | 2015-05-08 16:05:45 | 3,422,102 | 2015-05-08 16:05:45 | https://stackoverflow.com/q/30127764 | https://stackoverflow.com/a/30128230 | <p>You can omit using find for single-level (or recursive in bash 4 with <code>globstar</code>) searches of <code>.zip</code> files using a <code>for</code> loop approach:</p>
<pre><code>for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
</code></pre>
<p>for recursive searching... | <p>You can omit using find for single-level (or recursive in bash 4 with <code>globstar</code>) searches of <code>.zip</code> files using a <code>for</code> loop approach:</p> <pre><code>for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done </code></pre> <p>for recursive searching... | 58, 387, 549, 1271, 5282 | bash, grep, linux, sed, ubuntu | <h1>Finding a file within recursive directory of zip files</h1>
<p>I have an entire directory structure with zip files. I would like to:</p>
<ol>
<li>Traverse the entire directory structure recursively grabbing all the zip files</li>
<li>I would like to find a specific file "*myLostFile.ext" within one of these zip fi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,365 | bash | # Finding a file within recursive directory of zip files
I have an entire directory structure with zip files. I would like to:
1. Traverse the entire directory structure recursively grabbing all the zip files
2. I would like to find a specific file "*myLostFile.ext" within one of these zip files.
**What I have tried... | You can omit using find for single-level (or recursive in bash 4 with `globstar`) searches of `.zip` files using a `for` loop approach:
```
for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
```
for recursive searching in bash 4:
```
shopt -s globstar
for i in **/*.zip; do grep -iq "mylostf... |
25638938 | Remove a word from a string bash | 10 | 2014-09-03 07:45:34 | <p>I have the string </p>
<pre><code>file="this-is-a-{test}file"
</code></pre>
<p>I want to remove <code>{test}</code> from this string.
I used </p>
<pre><code>echo $file | sed 's/[{][^}]*//'
</code></pre>
<p>but this returned me </p>
<pre><code>this-is-a-}file
</code></pre>
<p>How can I remove <code>}</co... | 36,499 | 3,691,289 | 2014-09-03 08:06:21 | 25,638,988 | 11 | 2014-09-03 07:48:16 | 548,225 | 2014-09-03 07:48:16 | https://stackoverflow.com/q/25638938 | https://stackoverflow.com/a/25638988 | <p>You can use <code>sed</code> with correct regex:</p>
<pre><code>s="this-is-a-{test}file"
sed 's/{[^}]*}//' <<< "$s"
this-is-a-file
</code></pre>
<p>Or this awk:</p>
<pre><code>awk -F '{[^}]*}' '{print $1 $2}' <<< "$s"
this-is-a-file
</code></pre>
| <p>You can use <code>sed</code> with correct regex:</p> <pre><code>s="this-is-a-{test}file" sed 's/{[^}]*}//' <<< "$s" this-is-a-file </code></pre> <p>Or this awk:</p> <pre><code>awk -F '{[^}]*}' '{print $1 $2}' <<< "$s" this-is-a-file </code></pre> | 387 | bash | <h1>Remove a word from a string bash</h1>
<p>I have the string </p>
<pre><code>file="this-is-a-{test}file"
</code></pre>
<p>I want to remove <code>{test}</code> from this string.
I used </p>
<pre><code>echo $file | sed 's/[{][^}]*//'
</code></pre>
<p>but this returned me </p>
<pre><code>this-is-a-}file
</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,366 | bash | # Remove a word from a string bash
I have the string
```
file="this-is-a-{test}file"
```
I want to remove `{test}` from this string.
I used
```
echo $file | sed 's/[{][^}]*//'
```
but this returned me
```
this-is-a-}file
```
How can I remove `}` too?
Thanks | You can use `sed` with correct regex:
```
s="this-is-a-{test}file"
sed 's/{[^}]*}//' <<< "$s"
this-is-a-file
```
Or this awk:
```
awk -F '{[^}]*}' '{print $1 $2}' <<< "$s"
this-is-a-file
``` |
25567408 | Why are some processes shown in pstree not shown in ps -ef? | 10 | 2014-08-29 11:31:21 | <p>As title, I run the above commands in sh shell of Linux, but I just cannot find the the child processes of pid 7459 by running "ps -ef | grep dummy".
Can someone explain why there could be such difference between these 2 commands?
They are active processes ,not LWP(thread), right? How can I display the threa... | 6,247 | 3,989,978 | 2014-08-29 12:14:06 | 25,568,095 | 11 | 2014-08-29 12:14:06 | 1,057,909 | 2014-08-29 12:14:06 | https://stackoverflow.com/q/25567408 | https://stackoverflow.com/a/25568095 | <p>As @nos has already said, <code>pstree</code> displays threads by default, but <code>ps -ef</code> does not.</p>
<p><code>ps</code> can show threads, you just didn't ask it to. Try this (it might depend what version you have):</p>
<pre><code>ps -eLf
</code></pre>
<p>This is all in the <a href="http://linux.die.ne... | <p>As @nos has already said, <code>pstree</code> displays threads by default, but <code>ps -ef</code> does not.</p> <p><code>ps</code> can show threads, you just didn't ask it to. Try this (it might depend what version you have):</p> <pre><code>ps -eLf </code></pre> <p>This is all in the <a href="http://linux.die.ne... | 58, 390, 90497 | linux, pstree, shell | <h1>Why are some processes shown in pstree not shown in ps -ef?</h1>
<p>As title, I run the above commands in sh shell of Linux, but I just cannot find the the child processes of pid 7459 by running "ps -ef | grep dummy".
Can someone explain why there could be such difference between these 2 commands?
They are ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,367 | bash | # Why are some processes shown in pstree not shown in ps -ef?
As title, I run the above commands in sh shell of Linux, but I just cannot find the the child processes of pid 7459 by running "ps -ef | grep dummy".
Can someone explain why there could be such difference between these 2 commands?
They are active processes ... | As @nos has already said, `pstree` displays threads by default, but `ps -ef` does not.
`ps` can show threads, you just didn't ask it to. Try this (it might depend what version you have):
```
ps -eLf
```
This is all in the [man page](http://linux.die.net/man/1/ps).
Linux threads are merely processes that share the s... |
25305421 | Save the output of a powershell command in a variable and use it in batch script? | 10 | 2014-08-14 10:07:40 | <p>What I am trying to do is to save the output of a powershell command (run from a batch script) and use it in the batch script.</p>
<p>Can you please advise me what to do?</p>
<p>The power shell comand is:</p>
<pre><code>[System.Net.Dns]::GetHostByName((hostname)).HostName
</code></pre>
<p>I want to use the output in... | 2,454 | 2,352,982 | 2018-02-22 08:09:45 | 25,305,537 | 11 | 2014-08-14 10:13:34 | 2,152,082 | 2014-08-14 10:13:34 | https://stackoverflow.com/q/25305421 | https://stackoverflow.com/a/25305537 | <pre><code>for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
echo %return%
</code></pre>
| <pre><code>for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i echo %return% </code></pre> | 64, 526, 7002, 9785 | batch-file, fqdn, powershell, windows | <h1>Save the output of a powershell command in a variable and use it in batch script?</h1>
<p>What I am trying to do is to save the output of a powershell command (run from a batch script) and use it in the batch script.</p>
<p>Can you please advise me what to do?</p>
<p>The power shell comand is:</p>
<pre><code>[Syste... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,368 | bash | # Save the output of a powershell command in a variable and use it in batch script?
What I am trying to do is to save the output of a powershell command (run from a batch script) and use it in the batch script.
Can you please advise me what to do?
The power shell comand is:
```
[System.Net.Dns]::GetHostByName((host... | ```
for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
echo %return%
``` |
25210330 | Script for clearing Chrome or Firefox cache on Windows | 10 | 2014-08-08 18:49:50 | <p>With Internet Explorer you can create a <code>.bat</code> file to clear the cache.</p>
<p>Example:</p>
<pre><code>RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
REM History:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
REM Cookies:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
REM Temp Int... | 111,990 | 214,977 | 2019-10-21 17:06:39 | 25,213,068 | 11 | 2014-08-08 22:20:52 | 1,958,726 | 2018-12-20 14:16:00 | https://stackoverflow.com/q/25210330 | https://stackoverflow.com/a/25213068 | <p>In Chrome, you can clear the cache by deleting the contents of the Cache folder in <code>%LocalAppData%\Google\Chrome\User Data\Default\Cache</code>. The history, cookies, and so on are SQLite database files in the parent folder, so you could get rid of them too if you wanted everything gone, like in your example wi... | <p>In Chrome, you can clear the cache by deleting the contents of the Cache folder in <code>%LocalAppData%\Google\Chrome\User Data\Default\Cache</code>. The history, cookies, and so on are SQLite database files in the parent folder, so you could get rid of them too if you wanted everything gone, like in your example wi... | 526, 691, 3600, 31001, 34595 | browser-cache, firefox, google-chrome, powershell, windows-7 | <h1>Script for clearing Chrome or Firefox cache on Windows</h1>
<p>With Internet Explorer you can create a <code>.bat</code> file to clear the cache.</p>
<p>Example:</p>
<pre><code>RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
REM History:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
REM Cookies:
REM... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,369 | bash | # Script for clearing Chrome or Firefox cache on Windows
With Internet Explorer you can create a `.bat` file to clear the cache.
Example:
```
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
REM History:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
REM Cookies:
REM RunDll32.exe InetCpl.cpl,ClearMyTrack... | In Chrome, you can clear the cache by deleting the contents of the Cache folder in `%LocalAppData%\Google\Chrome\User Data\Default\Cache`. The history, cookies, and so on are SQLite database files in the parent folder, so you could get rid of them too if you wanted everything gone, like in your example with Internet Ex... |
25085346 | Why sys.path doesn't contain cwd()? | 10 | 2014-08-01 17:09:35 | <p>I use python3 with emacs (editor and shell) under Linux OS. Why the cwd is not in the sys.path ?? How can we put it, for all sessions !!
I Thank you.</p>
| 5,622 | 3,900,254 | 2020-02-27 17:48:31 | 25,085,442 | 11 | 2014-08-01 17:16:19 | 100,297 | 2014-08-01 17:39:12 | https://stackoverflow.com/q/25085346 | https://stackoverflow.com/a/25085442 | <p>You do <strong>not</strong> want to add <code>cwd()</code> to the <code>sys.path</code>. <em>Always</em> adding <code>cwd()</code> would be a <em>terrible idea</em> as you can no longer control what files are available for import.</p>
<p>Python adds the <em>directory of the script being executed</em> instead.</p>
... | <p>You do <strong>not</strong> want to add <code>cwd()</code> to the <code>sys.path</code>. <em>Always</em> adding <code>cwd()</code> would be a <em>terrible idea</em> as you can no longer control what files are available for import.</p> <p>Python adds the <em>directory of the script being executed</em> instead.</p> ... | 16, 58, 371, 390 | emacs, linux, python, shell | <h1>Why sys.path doesn't contain cwd()?</h1>
<p>I use python3 with emacs (editor and shell) under Linux OS. Why the cwd is not in the sys.path ?? How can we put it, for all sessions !!
I Thank you.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,370 | bash | # Why sys.path doesn't contain cwd()?
I use python3 with emacs (editor and shell) under Linux OS. Why the cwd is not in the sys.path ?? How can we put it, for all sessions !!
I Thank you. | You do **not** want to add `cwd()` to the `sys.path`. *Always* adding `cwd()` would be a *terrible idea* as you can no longer control what files are available for import.
Python adds the *directory of the script being executed* instead.
E.g. when you run:
```
python.exe path/to/script.py
```
then `path/to` is autom... |
24679868 | How to copy a file to multiple folders in PowerShell | 10 | 2014-07-10 14:57:42 | <p>I am running a script that has multiple environments in it that can be selected from a window that pops up. the only problem I have run into is when I want to set up the script to copy from a source function that I have created and put it into multiple locations at once.</p>
<p>The part of the code I need help with... | 42,376 | 3,745,470 | 2022-11-25 13:13:59 | 24,680,019 | 11 | 2014-07-10 15:04:44 | 67,392 | 2014-07-10 15:04:44 | https://stackoverflow.com/q/24679868 | https://stackoverflow.com/a/24680019 | <p><code>copy-item</code> only takes a single value for its <code>-destination</code> parameter, so you need a loop of some type.</p>
<p>Assuming you want the same file name in multiple folders:</p>
<pre><code>$destFolders | Foreach-Object { Copy-Item -Path $Source -dest (Join-Path $_ $destFileName) }
</code></pre>
... | <p><code>copy-item</code> only takes a single value for its <code>-destination</code> parameter, so you need a loop of some type.</p> <p>Assuming you want the same file name in multiple folders:</p> <pre><code>$destFolders | Foreach-Object { Copy-Item -Path $Source -dest (Join-Path $_ $destFileName) } </code></pre> ... | 526, 22864, 73157 | powershell, powershell-3.0, powershell-ise | <h1>How to copy a file to multiple folders in PowerShell</h1>
<p>I am running a script that has multiple environments in it that can be selected from a window that pops up. the only problem I have run into is when I want to set up the script to copy from a source function that I have created and put it into multiple lo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,371 | bash | # How to copy a file to multiple folders in PowerShell
I am running a script that has multiple environments in it that can be selected from a window that pops up. the only problem I have run into is when I want to set up the script to copy from a source function that I have created and put it into multiple locations a... | `copy-item` only takes a single value for its `-destination` parameter, so you need a loop of some type.
Assuming you want the same file name in multiple folders:
```
$destFolders | Foreach-Object { Copy-Item -Path $Source -dest (Join-Path $_ $destFileName) }
```
should do it. |
23848294 | How can I print a newline as \n in Bash? | 10 | 2014-05-24 18:22:28 | <p>Basically, I want to achieve something like the inverse of <code>echo -e</code>.</p>
<p>I have a variable which stores a command output, but I want to print newlines as \n.</p>
| 10,985 | 1,634,837 | 2022-04-23 19:24:36 | 23,849,180 | 11 | 2014-05-24 20:08:39 | 815,741 | 2014-05-24 21:11:07 | https://stackoverflow.com/q/23848294 | https://stackoverflow.com/a/23849180 | <p>Here's my solution:</p>
<pre><code>sed 's/$/\\n/' | tr -d '\n'
</code></pre>
| <p>Here's my solution:</p> <pre><code>sed 's/$/\\n/' | tr -d '\n' </code></pre> | 387, 390 | bash, shell | <h1>How can I print a newline as \n in Bash?</h1>
<p>Basically, I want to achieve something like the inverse of <code>echo -e</code>.</p>
<p>I have a variable which stores a command output, but I want to print newlines as \n.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,372 | bash | # How can I print a newline as \n in Bash?
Basically, I want to achieve something like the inverse of `echo -e`.
I have a variable which stores a command output, but I want to print newlines as \n. | Here's my solution:
```
sed 's/$/\\n/' | tr -d '\n'
``` |
22874724 | Linux - Only find a pattern within a line, not the whole line | 10 | 2014-04-04 23:35:59 | <p>I want to use a regex to find a pattern in a file. That pattern may be in the middle of a line, but I don't want the whole line. I tried <code>grep -a pattern file</code> but this returns the entire line that contains the regex. The following is an example of what I'm trying to do. Does anyone know a way to do this?... | 873 | 3,499,973 | 2014-04-05 13:19:22 | 22,874,737 | 11 | 2014-04-04 23:37:30 | 753,731 | 2014-04-04 23:37:30 | https://stackoverflow.com/q/22874724 | https://stackoverflow.com/a/22874737 | <p>you were close, you need the <code>-o</code> flag</p>
<pre><code>grep -o 'Xx.*yY' <<<AAAAAAAAAAAAAXxXxXxXxBananasyYyYyYyYBBBBBBBCCCCCC
XxXxXxXxBananasyYyYyYyY
</code></pre>
| <p>you were close, you need the <code>-o</code> flag</p> <pre><code>grep -o 'Xx.*yY' <<<AAAAAAAAAAAAAXxXxXxXxBananasyYyYyYyYBBBBBBBCCCCCC XxXxXxXxBananasyYyYyYyY </code></pre> | 18, 58, 387 | bash, linux, regex | <h1>Linux - Only find a pattern within a line, not the whole line</h1>
<p>I want to use a regex to find a pattern in a file. That pattern may be in the middle of a line, but I don't want the whole line. I tried <code>grep -a pattern file</code> but this returns the entire line that contains the regex. The following is ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,373 | bash | # Linux - Only find a pattern within a line, not the whole line
I want to use a regex to find a pattern in a file. That pattern may be in the middle of a line, but I don't want the whole line. I tried `grep -a pattern file` but this returns the entire line that contains the regex. The following is an example of what I... | you were close, you need the `-o` flag
```
grep -o 'Xx.*yY' <<<AAAAAAAAAAAAAXxXxXxXxBananasyYyYyYyYBBBBBBBCCCCCC
XxXxXxXxBananasyYyYyYyY
``` |
21462178 | Read content from text file formed in Windows in Linux bash | 10 | 2014-01-30 16:36:05 | <p>I am trying to download files from a database using wget and url. E.g.</p>
<p>wget "<a href="http://www.rcsb.org/pdb/files/1BXS.pdb" rel="noreferrer">http://www.rcsb.org/pdb/files/1BXS.pdb</a>"</p>
<p>So format of the url is as such: <a href="http://www.rcsb.org/pdb/files/" rel="noreferrer">http://www.rcsb.org/pdb... | 5,361 | 3,254,054 | 2014-01-31 09:30:47 | 21,462,535 | 11 | 2014-01-30 16:51:22 | 89,817 | 2014-01-30 16:51:22 | https://stackoverflow.com/q/21462178 | https://stackoverflow.com/a/21462535 | <p>It sounds like your id_numbers.txt file has DOS/Windows-style line endings (carriage return followed by linefeed characters) instead of plain unix line endings (just linefeed). The result is that <code>read</code> thinks the line ends with a carriage return, <code>$line</code> actually has a carriage return at the e... | <p>It sounds like your id_numbers.txt file has DOS/Windows-style line endings (carriage return followed by linefeed characters) instead of plain unix line endings (just linefeed). The result is that <code>read</code> thinks the line ends with a carriage return, <code>$line</code> actually has a carriage return at the e... | 139, 387, 7792 | bash, string, string-concatenation | <h1>Read content from text file formed in Windows in Linux bash</h1>
<p>I am trying to download files from a database using wget and url. E.g.</p>
<p>wget "<a href="http://www.rcsb.org/pdb/files/1BXS.pdb" rel="noreferrer">http://www.rcsb.org/pdb/files/1BXS.pdb</a>"</p>
<p>So format of the url is as such: <a href="htt... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 11,374 | bash | # Read content from text file formed in Windows in Linux bash
I am trying to download files from a database using wget and url. E.g.
wget "<http://www.rcsb.org/pdb/files/1BXS.pdb>"
So format of the url is as such: <http://www.rcsb.org/pdb/files/>($idnumber).pdb"
But I have many files to download; so I wrote a bash ... | It sounds like your id_numbers.txt file has DOS/Windows-style line endings (carriage return followed by linefeed characters) instead of plain unix line endings (just linefeed). The result is that `read` thinks the line ends with a carriage return, `$line` actually has a carriage return at the end, and that gets embedde... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.