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
39329017
how to build console command in spring boot web application using spring shell?
15
2016-09-05 10:50:38
<p>I have created restfull web application using spring boot web starter which works well. I am able to access it through urls. </p> <p>But I have requirement to create console command which can compute and store some values at the backend. I want to be able to run console command manually or through bash script.</p> ...
17,568
1,191,081
2018-08-16 20:03:06
39,329,520
12
2016-09-05 11:22:01
641,627
2018-08-16 20:03:06
https://stackoverflow.com/q/39329017
https://stackoverflow.com/a/39329520
<p>Here's 2 options:</p> <blockquote> <p><strong>(1) Rest API called from the command line</strong></p> </blockquote> <p>You could create a Spring <code>@RestController</code>, which you then call from the command line ?</p> <pre><code>curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http...
<p>Here's 2 options:</p> <blockquote> <p><strong>(1) Rest API called from the command line</strong></p> </blockquote> <p>You could create a Spring <code>@RestController</code>, which you then call from the command line ?</p> <pre><code>curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http...
17, 1211, 95875, 104375, 111386
java, spring, spring-boot, spring-shell, spring-web
<h1>how to build console command in spring boot web application using spring shell?</h1> <p>I have created restfull web application using spring boot web starter which works well. I am able to access it through urls. </p> <p>But I have requirement to create console command which can compute and store some values at th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,672
bash
# how to build console command in spring boot web application using spring shell? I have created restfull web application using spring boot web starter which works well. I am able to access it through urls. But I have requirement to create console command which can compute and store some values at the backend. I want...
Here's 2 options: > **(1) Rest API called from the command line** You could create a Spring `@RestController`, which you then call from the command line ? ``` curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http://hostname:8080/service -d ' { "field":"value", "field2":"...
27607323
PowerShell - How to use 'Start-Process' and rename the newly launched windowtitle
15
2014-12-22 17:14:23
<p>I am trying to use the PowerShell (version 2) <code>Start-Process</code> and rename the newly launched window title. I have the following snippet of code that works fine, it launches a new PowerShell window and tails logs (<code>$c</code> contains the log file to tail):-</p> <pre class="lang-powershell prettyprin...
16,399
2,977,451
2022-03-18 05:11:17
27,607,611
12
2014-12-22 17:32:15
702,944
2014-12-22 17:32:15
https://stackoverflow.com/q/27607323
https://stackoverflow.com/a/27607611
<p>A "dirty" solution would be:</p> <pre><code>start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait" </code></pre> <p>I would recommend creating a script for you commands and use parameters for input.</p> <p>Untitled2.ps1</p> <pre><...
<p>A "dirty" solution would be:</p> <pre><code>start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait" </code></pre> <p>I would recommend creating a script for you commands and use parameters for input.</p> <p>Untitled2.ps1</p> <pre><...
526
powershell
<h1>PowerShell - How to use 'Start-Process' and rename the newly launched windowtitle</h1> <p>I am trying to use the PowerShell (version 2) <code>Start-Process</code> and rename the newly launched window title. I have the following snippet of code that works fine, it launches a new PowerShell window and tails logs (<co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,673
bash
# PowerShell - How to use 'Start-Process' and rename the newly launched windowtitle I am trying to use the PowerShell (version 2) `Start-Process` and rename the newly launched window title. I have the following snippet of code that works fine, it launches a new PowerShell window and tails logs (`$c` contains the log f...
A "dirty" solution would be: ``` start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait" ``` I would recommend creating a script for you commands and use parameters for input. Untitled2.ps1 ``` param($c) $host.ui.RawUI.WindowTitle = '...
27002192
Bash "declare -A" does not work on macOS
15
2014-11-18 19:16:40
<p>My guess is that Bash is not updated on macOS. When googling update Bash macOS, I keep getting the bug fix patch. Anyway, I need to use associative arrays in macOS Bash where the command:</p> <pre><code>declare -A </code></pre> <p>yields the error:</p> <blockquote> <p>-bash: declare: -A: invalid option<br> de...
8,777
1,103,966
2024-05-02 06:53:38
27,002,208
12
2014-11-18 19:17:41
258,523
2014-11-18 19:17:41
https://stackoverflow.com/q/27002192
https://stackoverflow.com/a/27002208
<p><code>declare -A</code> (associative arrays) are a bash 4+ feature.</p> <p>The OS X bash is likely 3.X.</p> <p>I don't know that OS X has an official update for bash 4+.</p> <p>brew/etc. might though.</p>
<p><code>declare -A</code> (associative arrays) are a bash 4+ feature.</p> <p>The OS X bash is likely 3.X.</p> <p>I don't know that OS X has an official update for bash 4+.</p> <p>brew/etc. might though.</p>
58, 369, 387, 2575
associative-array, bash, linux, macos
<h1>Bash "declare -A" does not work on macOS</h1> <p>My guess is that Bash is not updated on macOS. When googling update Bash macOS, I keep getting the bug fix patch. Anyway, I need to use associative arrays in macOS Bash where the command:</p> <pre><code>declare -A </code></pre> <p>yields the error:</p> <blockquote...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,674
bash
# Bash "declare -A" does not work on macOS My guess is that Bash is not updated on macOS. When googling update Bash macOS, I keep getting the bug fix patch. Anyway, I need to use associative arrays in macOS Bash where the command: ``` declare -A ``` yields the error: > -bash: declare: -A: invalid option > declare...
`declare -A` (associative arrays) are a bash 4+ feature. The OS X bash is likely 3.X. I don't know that OS X has an official update for bash 4+. brew/etc. might though.
23581519
How to create a valid empty JSON array with PowerShell?
15
2014-05-10 13:17:41
<p>Converting arrays to JSON string in PowerShell couldn't be more simple:</p> <pre><code>@(1,2,3) | ConvertTo-Json </code></pre> <p>Produces:</p> <pre><code>[ 1, 2, 3 ] </code></pre> <p>However if the array is empty the result is an empty string:</p> <pre><code>@() | ConvertTo-Json </code></pre> <p>R...
13,359
1,269,946
2024-05-14 01:23:10
23,581,702
12
2014-05-10 13:35:15
570,689
2014-05-10 13:35:15
https://stackoverflow.com/q/23581519
https://stackoverflow.com/a/23581702
<p>It works without pipelining</p> <pre><code>PS C:\&gt; ConvertTo-Json @() [ ] </code></pre>
<p>It works without pipelining</p> <pre><code>PS C:\&gt; ConvertTo-Json @() [ ] </code></pre>
114, 526, 1508
arrays, json, powershell
<h1>How to create a valid empty JSON array with PowerShell?</h1> <p>Converting arrays to JSON string in PowerShell couldn't be more simple:</p> <pre><code>@(1,2,3) | ConvertTo-Json </code></pre> <p>Produces:</p> <pre><code>[ 1, 2, 3 ] </code></pre> <p>However if the array is empty the result is an empty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,675
bash
# How to create a valid empty JSON array with PowerShell? Converting arrays to JSON string in PowerShell couldn't be more simple: ``` @(1,2,3) | ConvertTo-Json ``` Produces: ``` [ 1, 2, 3 ] ``` However if the array is empty the result is an empty string: ``` @() | ConvertTo-Json ``` Results an empty ...
It works without pipelining ``` PS C:\> ConvertTo-Json @() [ ] ```
17731345
How to terminate variable expansion to create a string in Powershell
15
2013-07-18 18:34:25
<p>How do I tell powershell the end of a variable to be expanded into a string when it sits next to other alphabetic characters?</p> <p>$StringToAdd = "iss"<br> $CompeteString = "Miss$StringToAddippi"</p> <p>Thanks!</p>
4,654
1,008,452
2013-11-30 21:42:58
17,731,393
12
2013-07-18 18:38:06
509,839
2013-07-18 18:44:08
https://stackoverflow.com/q/17731345
https://stackoverflow.com/a/17731393
<p>Use curly braces, <code>{</code> and <code>}</code>, to delimit the variable expansion. For example:</p> <pre><code>PS C:\&gt; $StringToAdd = "iss" PS C:\&gt; $CompeteString = "Miss${StringToAdd}ippi" PS C:\&gt; $CompeteString Mississippi </code></pre>
<p>Use curly braces, <code>{</code> and <code>}</code>, to delimit the variable expansion. For example:</p> <pre><code>PS C:\&gt; $StringToAdd = "iss" PS C:\&gt; $CompeteString = "Miss${StringToAdd}ippi" PS C:\&gt; $CompeteString Mississippi </code></pre>
526
powershell
<h1>How to terminate variable expansion to create a string in Powershell</h1> <p>How do I tell powershell the end of a variable to be expanded into a string when it sits next to other alphabetic characters?</p> <p>$StringToAdd = "iss"<br> $CompeteString = "Miss$StringToAddippi"</p> <p>Thanks!</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,676
bash
# How to terminate variable expansion to create a string in Powershell How do I tell powershell the end of a variable to be expanded into a string when it sits next to other alphabetic characters? $StringToAdd = "iss" $CompeteString = "Miss$StringToAddippi" Thanks!
Use curly braces, `{` and `}`, to delimit the variable expansion. For example: ``` PS C:\> $StringToAdd = "iss" PS C:\> $CompeteString = "Miss${StringToAdd}ippi" PS C:\> $CompeteString Mississippi ```
13755082
How do I install PSCX Powershell module?
15
2012-12-07 00:27:38
<p>I'm running Windows 7 with PowerShell 2 installed.</p> <p>I've downloaded version 2.1 from here - <a href="http://pscx.codeplex.com/releases" rel="noreferrer">http://pscx.codeplex.com/releases</a></p> <p>The Release notes say </p> <ul> <li>unblock the zip file - {which I did}</li> <li>extract the contents of the ...
23,209
6,268
2021-07-27 20:34:55
13,755,218
12
2012-12-07 00:42:32
6,268
2012-12-07 00:42:32
https://stackoverflow.com/q/13755082
https://stackoverflow.com/a/13755218
<p>I hadn't actually completed the last step of my above question completely which turned out to be the answer.</p> <p>Here is that answer for completeness</p> <ul> <li>Unblock the zip file you have downloaded</li> <li>extract the zip file - this will likely give a folder structure of <code>Pscx-2.1.0/Pscx-2.1.0/{lot...
<p>I hadn't actually completed the last step of my above question completely which turned out to be the answer.</p> <p>Here is that answer for completeness</p> <ul> <li>Unblock the zip file you have downloaded</li> <li>extract the zip file - this will likely give a folder structure of <code>Pscx-2.1.0/Pscx-2.1.0/{lot...
526, 24067
powershell, powershell-2.0
<h1>How do I install PSCX Powershell module?</h1> <p>I'm running Windows 7 with PowerShell 2 installed.</p> <p>I've downloaded version 2.1 from here - <a href="http://pscx.codeplex.com/releases" rel="noreferrer">http://pscx.codeplex.com/releases</a></p> <p>The Release notes say </p> <ul> <li>unblock the zip file - {...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,677
bash
# How do I install PSCX Powershell module? I'm running Windows 7 with PowerShell 2 installed. I've downloaded version 2.1 from here - <http://pscx.codeplex.com/releases> The Release notes say - unblock the zip file - {which I did} - extract the contents of the ZIP file to your $env:Home\Documents\WindowsPowerShell\...
I hadn't actually completed the last step of my above question completely which turned out to be the answer. Here is that answer for completeness - Unblock the zip file you have downloaded - extract the zip file - this will likely give a folder structure of `Pscx-2.1.0/Pscx-2.1.0/{lots of files}` - rename the child f...
13672420
Using bash process substitution for a sudo command
15
2012-12-02 18:35:43
<p>I would like to use bash process substitution for a sudo command.</p> <p>For example, here's a non-sudo command that works for me:</p> <pre><code>$ cat &lt;(echo "installed.txt") installed.txt </code></pre> <p>And here's a sudo version of the command that does not work:</p> <pre><code>$ sudo cat &lt;(echo "insta...
4,223
822,162
2021-07-23 19:39:43
13,672,556
12
2012-12-02 18:52:00
465,183
2012-12-02 18:52:00
https://stackoverflow.com/q/13672420
https://stackoverflow.com/a/13672556
<p>Try doing this in your shell :</p> <pre><code>$ sudo bash -c 'cat &lt;(echo "installed.txt for UID=$UID")' installed.txt for UID=0 </code></pre>
<p>Try doing this in your shell :</p> <pre><code>$ sudo bash -c 'cat &lt;(echo "installed.txt for UID=$UID")' installed.txt for UID=0 </code></pre>
387
bash
<h1>Using bash process substitution for a sudo command</h1> <p>I would like to use bash process substitution for a sudo command.</p> <p>For example, here's a non-sudo command that works for me:</p> <pre><code>$ cat &lt;(echo "installed.txt") installed.txt </code></pre> <p>And here's a sudo version of the command tha...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,678
bash
# Using bash process substitution for a sudo command I would like to use bash process substitution for a sudo command. For example, here's a non-sudo command that works for me: ``` $ cat <(echo "installed.txt") installed.txt ``` And here's a sudo version of the command that does not work: ``` $ sudo cat <(echo "in...
Try doing this in your shell : ``` $ sudo bash -c 'cat <(echo "installed.txt for UID=$UID")' installed.txt for UID=0 ```
6595129
Delete positional parameters in Bash?
15
2011-07-06 10:45:41
<p>You can skip positional parameters with <code>shift</code> but can you delete positional parameters by passing the position?</p> <pre><code>x(){ CODE; echo "$@"; }; x 1 2 3 4 5 6 7 8 &gt; 1 2 4 5 6 7 8 </code></pre> <p>I would like to add CODE to <code>x()</code> to delete positional parameter 3. I don't want to d...
14,293
827,886
2018-02-10 11:07:16
6,595,442
12
2011-07-06 11:11:09
96,588
2011-07-06 11:16:21
https://stackoverflow.com/q/6595129
https://stackoverflow.com/a/6595442
<p>The best way, if you want to be able to pass on the parameters to another process, or handle space separated parameters, is to re-<code>set</code> the parameters:</p> <pre><code>$ x(){ echo "Parameter count before: $#"; set -- "${@:1:2}" "${@:4:8}"; echo "$@"; echo "Parameter count after: $#"; } $ x 1 2 3 4 5 6 7 8...
<p>The best way, if you want to be able to pass on the parameters to another process, or handle space separated parameters, is to re-<code>set</code> the parameters:</p> <pre><code>$ x(){ echo "Parameter count before: $#"; set -- "${@:1:2}" "${@:4:8}"; echo "$@"; echo "Parameter count after: $#"; } $ x 1 2 3 4 5 6 7 8...
360, 387, 390
bash, parameters, shell
<h1>Delete positional parameters in Bash?</h1> <p>You can skip positional parameters with <code>shift</code> but can you delete positional parameters by passing the position?</p> <pre><code>x(){ CODE; echo "$@"; }; x 1 2 3 4 5 6 7 8 &gt; 1 2 4 5 6 7 8 </code></pre> <p>I would like to add CODE to <code>x()</code> to d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,679
bash
# Delete positional parameters in Bash? You can skip positional parameters with `shift` but can you delete positional parameters by passing the position? ``` x(){ CODE; echo "$@"; }; x 1 2 3 4 5 6 7 8 > 1 2 4 5 6 7 8 ``` I would like to add CODE to `x()` to delete positional parameter 3. I don't want to do `echo "${...
The best way, if you want to be able to pass on the parameters to another process, or handle space separated parameters, is to re-`set` the parameters: ``` $ x(){ echo "Parameter count before: $#"; set -- "${@:1:2}" "${@:4:8}"; echo "$@"; echo "Parameter count after: $#"; } $ x 1 2 3 4 5 6 7 8 Parameter count before: ...
5665169
Looping through directories in Bash
15
2011-04-14 14:57:11
<p>I require the script to <code>cd</code> to a directory, then delete all but a few files in sub-directories—but leave the folders alone. Would it help to use <code>switch</code>/<code>case</code>s for each file I need to preserve?</p> <p>Ideally, I think it should keep searching for further sub-dirs, instead of me ...
46,999
706,380
2018-05-08 16:43:04
5,665,578
12
2011-04-14 15:25:01
459,745
2013-07-03 13:49:39
https://stackoverflow.com/q/5665169
https://stackoverflow.com/a/5665578
<p>How about this?</p> <pre class="lang-sh prettyprint-override"><code>$ find /Users/YourName/Desktop/Test -type f -maxdepth 2 -not -name watch.log -delete </code></pre> <p><br></p> <h2>Explanation</h2> <ul> <li><code>-type</code>: look for files only</li> <li><code>-maxdepth</code>: go down two levels at most</li>...
<p>How about this?</p> <pre class="lang-sh prettyprint-override"><code>$ find /Users/YourName/Desktop/Test -type f -maxdepth 2 -not -name watch.log -delete </code></pre> <p><br></p> <h2>Explanation</h2> <ul> <li><code>-type</code>: look for files only</li> <li><code>-maxdepth</code>: go down two levels at most</li>...
387, 531, 2314
bash, loops, scripting
<h1>Looping through directories in Bash</h1> <p>I require the script to <code>cd</code> to a directory, then delete all but a few files in sub-directories—but leave the folders alone. Would it help to use <code>switch</code>/<code>case</code>s for each file I need to preserve?</p> <p>Ideally, I think it should keep s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,680
bash
# Looping through directories in Bash I require the script to `cd` to a directory, then delete all but a few files in sub-directories—but leave the folders alone. Would it help to use `switch`/`case`s for each file I need to preserve? Ideally, I think it should keep searching for further sub-dirs, instead of me havin...
How about this? ``` $ find /Users/YourName/Desktop/Test -type f -maxdepth 2 -not -name watch.log -delete ``` ## Explanation - `-type`: look for files only - `-maxdepth`: go down two levels at most - `-not -name` (combo): exclude `watch.log` from the search - `-delete`: deletes files ## Recommendation Try out the a...
4453177
How to use TFS PowerShell to get list of changesets and associated work items?
15
2010-12-15 17:50:52
<p>I'm a novice with the PowerShell and TFS cmdlets and I'm trying to retrieve a list of changesets in an area path, and their associated work items.</p> <p>I've got as far as listing changesets since a certain date:</p> <pre><code>Get-TfsItemHistory "$/Project/Branch" -Version “D01/12/10~” -Recurse </code></pre> <...
17,235
370,692
2015-05-05 12:03:03
4,453,417
12
2010-12-15 18:18:13
153,982
2010-12-15 18:18:13
https://stackoverflow.com/q/4453177
https://stackoverflow.com/a/4453417
<p>Yes, you're on the right track. Try this as a way to view workitems associated with a changeset:</p> <pre><code>Get-TfsItemHistory "$/Project/Branch" -Version "D01/12/10~" -Recurse | Select ChangesetId -exp WorkItems | Format-Table Id,Title -GroupBy ChangesetId -Auto </code></pre>
<p>Yes, you're on the right track. Try this as a way to view workitems associated with a changeset:</p> <pre><code>Get-TfsItemHistory "$/Project/Branch" -Version "D01/12/10~" -Recurse | Select ChangesetId -exp WorkItems | Format-Table Id,Title -GroupBy ChangesetId -Auto </code></pre>
526, 733
powershell, tfs
<h1>How to use TFS PowerShell to get list of changesets and associated work items?</h1> <p>I'm a novice with the PowerShell and TFS cmdlets and I'm trying to retrieve a list of changesets in an area path, and their associated work items.</p> <p>I've got as far as listing changesets since a certain date:</p> <pre><cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,681
bash
# How to use TFS PowerShell to get list of changesets and associated work items? I'm a novice with the PowerShell and TFS cmdlets and I'm trying to retrieve a list of changesets in an area path, and their associated work items. I've got as far as listing changesets since a certain date: ``` Get-TfsItemHistory "$/Pro...
Yes, you're on the right track. Try this as a way to view workitems associated with a changeset: ``` Get-TfsItemHistory "$/Project/Branch" -Version "D01/12/10~" -Recurse | Select ChangesetId -exp WorkItems | Format-Table Id,Title -GroupBy ChangesetId -Auto ```
4434797
Read a config file in BASH without using "source"
15
2010-12-14 00:24:14
<p>I'm attempting to read a config file that is formatted as follows:</p> <pre><code>USER = username TARGET = arrows </code></pre> <p>I realize that if I got rid of the spaces, I could simply source the config file, but for security reasons I'm trying to avoid that. I know there is a way to read the config file line...
19,419
541,289
2019-02-28 20:53:55
4,434,843
12
2010-12-14 00:34:13
207,248
2013-06-06 09:27:41
https://stackoverflow.com/q/4434797
https://stackoverflow.com/a/4434843
<p>The following script iterates over each line in your input file (<em>vars</em> in my case) and does a pattern match against <code>=</code>. If the equal sign is found it will use <a href="http://www.network-theory.co.uk/docs/bashref/ShellParameterExpansion.html">Parameter Expansion</a> to parse out the variable <em>...
<p>The following script iterates over each line in your input file (<em>vars</em> in my case) and does a pattern match against <code>=</code>. If the equal sign is found it will use <a href="http://www.network-theory.co.uk/docs/bashref/ShellParameterExpansion.html">Parameter Expansion</a> to parse out the variable <em>...
387, 1271, 3574, 4413
bash, config, eval, grep
<h1>Read a config file in BASH without using "source"</h1> <p>I'm attempting to read a config file that is formatted as follows:</p> <pre><code>USER = username TARGET = arrows </code></pre> <p>I realize that if I got rid of the spaces, I could simply source the config file, but for security reasons I'm trying to avoi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,682
bash
# Read a config file in BASH without using "source" I'm attempting to read a config file that is formatted as follows: ``` USER = username TARGET = arrows ``` I realize that if I got rid of the spaces, I could simply source the config file, but for security reasons I'm trying to avoid that. I know there is a way to ...
The following script iterates over each line in your input file (*vars* in my case) and does a pattern match against `=`. If the equal sign is found it will use [Parameter Expansion](http://www.network-theory.co.uk/docs/bashref/ShellParameterExpansion.html) to parse out the variable *name* from the *value*. It then sto...
1132135
Is Perl faster than bash?
15
2009-07-15 15:27:52
<p>I have a bash script that cuts out a section of a logfile between 2 timestamps, but because of the size of the files, it takes quite a while to run.</p> <p>If I were to rewrite the script in Perl, could I achieve a significant speed increase - or would I have to move to something like C to accomplish this?</p> <pr...
20,386
3,764
2009-09-23 13:41:45
1,132,279
12
2009-07-15 15:51:18
100,754
2009-07-15 23:09:56
https://stackoverflow.com/q/1132135
https://stackoverflow.com/a/1132279
<p><strong>Updated script based on Brent's comment:</strong> This one is untested.</p> <pre><code>#!/usr/bin/perl use strict; use warnings; my %months = ( jan =&gt; 1, feb =&gt; 2, mar =&gt; 3, apr =&gt; 4, may =&gt; 5, jun =&gt; 6, jul =&gt; 7, aug =&gt; 8, sep =&gt; 9, oct =&gt; 10, nov =&gt; 11, d...
<p><strong>Updated script based on Brent's comment:</strong> This one is untested.</p> <pre><code>#!/usr/bin/perl use strict; use warnings; my %months = ( jan =&gt; 1, feb =&gt; 2, mar =&gt; 3, apr =&gt; 4, may =&gt; 5, jun =&gt; 6, jul =&gt; 7, aug =&gt; 8, sep =&gt; 9, oct =&gt; 10, nov =&gt; 11, d...
387, 543, 580, 588, 598
bash, comparison, optimization, performance, perl
<h1>Is Perl faster than bash?</h1> <p>I have a bash script that cuts out a section of a logfile between 2 timestamps, but because of the size of the files, it takes quite a while to run.</p> <p>If I were to rewrite the script in Perl, could I achieve a significant speed increase - or would I have to move to something ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,683
bash
# Is Perl faster than bash? I have a bash script that cuts out a section of a logfile between 2 timestamps, but because of the size of the files, it takes quite a while to run. If I were to rewrite the script in Perl, could I achieve a significant speed increase - or would I have to move to something like C to accomp...
**Updated script based on Brent's comment:** This one is untested. ``` #!/usr/bin/perl use strict; use warnings; my %months = ( jan => 1, feb => 2, mar => 3, apr => 4, may => 5, jun => 6, jul => 7, aug => 8, sep => 9, oct => 10, nov => 11, dec => 12, ); while ( my $line = <> ) { my $ts = substr ...
73939916
How to upgrade PowerShell version
14
2022-10-03 19:22:59
<p>Lately, firing up PowerShell, I noticed that there is a phrase that says:</p> <blockquote> <p>Install the latest PowerShell for new features and improvements! <a href="https://aka.ms/PSWindows" rel="noreferrer">https://aka.ms/PSWindows</a></p> </blockquote> <p>So why not trying it following the actual Microsoft docu...
42,234
4,652,358
2024-06-21 18:45:51
73,940,006
12
2022-10-03 19:31:23
12,251,609
2022-10-03 19:31:23
https://stackoverflow.com/q/73939916
https://stackoverflow.com/a/73940006
<p>Powershell 7 (core) is its own application. Search for <code>pwsh.exe</code> and run that</p>
<p>Powershell 7 (core) is its own application. Search for <code>pwsh.exe</code> and run that</p>
64, 526, 108010, 144089
powershell, powershell-5.0, powershell-7.0, windows
<h1>How to upgrade PowerShell version</h1> <p>Lately, firing up PowerShell, I noticed that there is a phrase that says:</p> <blockquote> <p>Install the latest PowerShell for new features and improvements! <a href="https://aka.ms/PSWindows" rel="noreferrer">https://aka.ms/PSWindows</a></p> </blockquote> <p>So why not tr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,684
bash
# How to upgrade PowerShell version Lately, firing up PowerShell, I noticed that there is a phrase that says: > Install the latest PowerShell for new features and improvements! > <https://aka.ms/PSWindows> So why not trying it following the actual Microsoft documentation: 1. I run `$PSVersionTable` and the version ...
Powershell 7 (core) is its own application. Search for `pwsh.exe` and run that
38082179
How to translate a Windows path for Windows Subsystem for Linux
14
2016-06-28 17:00:52
<p>I'm looking for a way to translate Win32 paths into POSIX paths, preferably using Win32 tools.</p> <p><strong>Background</strong></p> <p>The latest Windows 10 Insider Build introduced the Windows Subsystem for Linux (WSL) including a native <code>bash</code> provided by Canonical, the company behind Ubuntu. Their im...
10,983
1,329,116
2022-03-23 09:15:47
69,510,047
12
2021-10-09 19:41:56
15,964,568
2022-03-23 09:15:47
https://stackoverflow.com/q/38082179
https://stackoverflow.com/a/69510047
<p>The <a href="https://github.com/wslutilities/wslu" rel="noreferrer">WSL Utilities</a> package now provides this capability via the <code>wslpath</code> command.</p> <p>WSLU is installed by default with the Ubuntu distribution, but may need to be added manually to other distributions. Instructions for package instal...
<p>The <a href="https://github.com/wslutilities/wslu" rel="noreferrer">WSL Utilities</a> package now provides this capability via the <code>wslpath</code> command.</p> <p>WSLU is installed by default with the Ubuntu distribution, but may need to be added manually to other distributions. Instructions for package instal...
387, 107329, 119526
bash, windows-10, windows-subsystem-for-linux
<h1>How to translate a Windows path for Windows Subsystem for Linux</h1> <p>I'm looking for a way to translate Win32 paths into POSIX paths, preferably using Win32 tools.</p> <p><strong>Background</strong></p> <p>The latest Windows 10 Insider Build introduced the Windows Subsystem for Linux (WSL) including a native <co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,685
bash
# How to translate a Windows path for Windows Subsystem for Linux I'm looking for a way to translate Win32 paths into POSIX paths, preferably using Win32 tools. **Background** The latest Windows 10 Insider Build introduced the Windows Subsystem for Linux (WSL) including a native `bash` provided by Canonical, the com...
The [WSL Utilities](https://github.com/wslutilities/wslu) package now provides this capability via the `wslpath` command. WSLU is installed by default with the Ubuntu distribution, but may need to be added manually to other distributions. Instructions for package installation are on the Github page linked above. Exam...
39898824
What does |% mean in PowerShell
14
2016-10-06 14:34:50
<p>I've come across this today:</p> <pre><code>$tests = (Get-ChildItem . -Recurse -Name bin |% { Get-ChildItem $_ -Recurse -Filter *.Unit.Tests.dll } |% { $($_.FullName) }) Write-Host ------------- TESTS ----------- Write-Host $tests Write-Host ------------------------------- .\tools\xunit\xunit.console.exe $tests -x...
20,970
4,572,605
2019-03-06 16:29:36
39,898,932
12
2016-10-06 14:39:22
3,905,079
2016-10-06 14:39:22
https://stackoverflow.com/q/39898824
https://stackoverflow.com/a/39898932
<p><code>%</code> is an <a href="https://technet.microsoft.com/en-us/library/hh847830.aspx" rel="noreferrer">alias</a> for <a href="https://technet.microsoft.com/en-us/library/hh849731.aspx" rel="noreferrer">the <code>ForEach-Object</code> cmdlet</a>.</p> <p>An alias is just another name by which you can reference a c...
<p><code>%</code> is an <a href="https://technet.microsoft.com/en-us/library/hh847830.aspx" rel="noreferrer">alias</a> for <a href="https://technet.microsoft.com/en-us/library/hh849731.aspx" rel="noreferrer">the <code>ForEach-Object</code> cmdlet</a>.</p> <p>An alias is just another name by which you can reference a c...
526
powershell
<h1>What does |% mean in PowerShell</h1> <p>I've come across this today:</p> <pre><code>$tests = (Get-ChildItem . -Recurse -Name bin |% { Get-ChildItem $_ -Recurse -Filter *.Unit.Tests.dll } |% { $($_.FullName) }) Write-Host ------------- TESTS ----------- Write-Host $tests Write-Host ------------------------------- ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,686
bash
# What does |% mean in PowerShell I've come across this today: ``` $tests = (Get-ChildItem . -Recurse -Name bin |% { Get-ChildItem $_ -Recurse -Filter *.Unit.Tests.dll } |% { $($_.FullName) }) Write-Host ------------- TESTS ----------- Write-Host $tests Write-Host ------------------------------- .\tools\xunit\xunit....
`%` is an [alias](https://technet.microsoft.com/en-us/library/hh847830.aspx) for [the `ForEach-Object` cmdlet](https://technet.microsoft.com/en-us/library/hh849731.aspx). An alias is just another name by which you can reference a cmdlet or function. For example `dir`, `ls`, and `gci` are all aliases for `Get-ChildItem...
22812853
SSH to server, Sudo su - then run commands in bash
14
2014-04-02 13:21:00
<p>I have the following </p> <pre><code>#!/bin/bash USER='scott' PASS='tiger' ssh -t $USER@server006.web.com "sudo su - http" </code></pre> <p>This Works, but I was trying to get it to run a script afterwards, and if I do, using -c or &lt; <p>The script does a grep like this:</p> <pre><code>grep -i "Exception:" ...
38,312
1,053,904
2014-04-02 15:25:58
22,813,198
12
2014-04-02 13:35:04
3,489,298
2014-04-02 13:35:04
https://stackoverflow.com/q/22812853
https://stackoverflow.com/a/22813198
<p>Try</p> <pre><code>ssh -t $USER@server006.web.com 'sudo -u http grep -i "Exception:" /opt/local/server/logs/exceptions.log | grep -e "|*-*-*:*:*,*|" | tail -1 | awk -F"|" "{print $2}" &gt;&gt; log.log' </code></pre> <p>Sudo already runs the command as a different user to there's no need to su again.</p> <p>Only r...
<p>Try</p> <pre><code>ssh -t $USER@server006.web.com 'sudo -u http grep -i "Exception:" /opt/local/server/logs/exceptions.log | grep -e "|*-*-*:*:*,*|" | tail -1 | awk -F"|" "{print $2}" &gt;&gt; log.log' </code></pre> <p>Sudo already runs the command as a different user to there's no need to su again.</p> <p>Only r...
386, 387, 390, 989, 1674
aix, bash, shell, ssh, sudo
<h1>SSH to server, Sudo su - then run commands in bash</h1> <p>I have the following </p> <pre><code>#!/bin/bash USER='scott' PASS='tiger' ssh -t $USER@server006.web.com "sudo su - http" </code></pre> <p>This Works, but I was trying to get it to run a script afterwards, and if I do, using -c or &lt; <p>The script ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,687
bash
# SSH to server, Sudo su - then run commands in bash I have the following ``` #!/bin/bash USER='scott' PASS='tiger' ssh -t $USER@server006.web.com "sudo su - http" ``` This Works, but I was trying to get it to run a script afterwards, and if I do, using -c or < The script does a grep like this: ``` grep -i "Exce...
Try ``` ssh -t $USER@server006.web.com 'sudo -u http grep -i "Exception:" /opt/local/server/logs/exceptions.log | grep -e "|*-*-*:*:*,*|" | tail -1 | awk -F"|" "{print $2}" >> log.log' ``` Sudo already runs the command as a different user to there's no need to su again. Only reason to do sudo su is to have a fast wa...
19029850
PowerShell release COM object
14
2013-09-26 13:35:46
<p>I have a small utility function in one PowerShell script:</p> <pre><code>function Unzip-File{ param( [Parameter(Mandatory=$true)] [string]$ZipFile, [Parameter(Mandatory=$true)] [string]$Path ) $shell=New-Object -ComObject shell.application $zip = $shell.namespace($Z...
17,984
588,868
2018-10-01 18:43:01
19,030,001
12
2013-09-26 13:43:23
520,612
2013-12-15 13:12:51
https://stackoverflow.com/q/19029850
https://stackoverflow.com/a/19030001
<p>Usually I use this function:</p> <pre><code>function Release-Ref ($ref) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$ref) | out-null [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() } </code></pre> <p>because I've noted that my comobject always stay alive, I thi...
<p>Usually I use this function:</p> <pre><code>function Release-Ref ($ref) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$ref) | out-null [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() } </code></pre> <p>because I've noted that my comobject always stay alive, I thi...
526
powershell
<h1>PowerShell release COM object</h1> <p>I have a small utility function in one PowerShell script:</p> <pre><code>function Unzip-File{ param( [Parameter(Mandatory=$true)] [string]$ZipFile, [Parameter(Mandatory=$true)] [string]$Path ) $shell=New-Object -ComObject shell.appl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,688
bash
# PowerShell release COM object I have a small utility function in one PowerShell script: ``` function Unzip-File{ param( [Parameter(Mandatory=$true)] [string]$ZipFile, [Parameter(Mandatory=$true)] [string]$Path ) $shell=New-Object -ComObject shell.application $zip = ...
Usually I use this function: ``` function Release-Ref ($ref) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$ref) | out-null [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() } ``` because I've noted that my comobject always stay alive, I think Powershell 2.0 is not ab...
6502836
Interactive search and replace from shell
14
2011-06-28 07:06:56
<p>Search and replace over multiple files is difficult in my editor. There are plenty of tricks that can be done with <code>find</code>, <code>xargs</code> and <code>sed</code>/<code>awk</code> incluing search-and replace in multiple files. But somehow I couldn't find a way to make this interactive. Do you know a way t...
5,559
61,342
2019-03-22 11:50:54
13,513,811
12
2012-11-22 13:32:27
1,820,630
2013-06-26 12:49:38
https://stackoverflow.com/q/6502836
https://stackoverflow.com/a/13513811
<p>KISS principle:</p> <pre><code>vim :args `ls` :argdo %s#SEARCH#REPLACE#gec |update </code></pre> <p>First character afer %s is used as separator</p>
<p>KISS principle:</p> <pre><code>vim :args `ls` :argdo %s#SEARCH#REPLACE#gec |update </code></pre> <p>First character afer %s is used as separator</p>
390, 2498, 10193
find, replace, shell
<h1>Interactive search and replace from shell</h1> <p>Search and replace over multiple files is difficult in my editor. There are plenty of tricks that can be done with <code>find</code>, <code>xargs</code> and <code>sed</code>/<code>awk</code> incluing search-and replace in multiple files. But somehow I couldn't find ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,689
bash
# Interactive search and replace from shell Search and replace over multiple files is difficult in my editor. There are plenty of tricks that can be done with `find`, `xargs` and `sed`/`awk` incluing search-and replace in multiple files. But somehow I couldn't find a way to make this interactive. Do you know a way to ...
KISS principle: ``` vim :args `ls` :argdo %s#SEARCH#REPLACE#gec |update ``` First character afer %s is used as separator
6185994
Unix find: list of files from stdin
14
2011-05-31 10:07:49
<p>I'm working in Linux &amp; bash (or Cygwin &amp; bash).</p> <p>I have a huge--<em>huge</em>--directory structure, and I have to find a few needles in the haystack.</p> <p>Specifically, I'm looking for these files (20 or so):</p> <pre><code>foo.c bar.h ... quux.txt </code></pre> <p>I know that they are in a subdi...
16,302
15,456
2011-05-31 13:25:52
6,186,687
12
2011-05-31 11:10:48
632,407
2011-05-31 11:16:32
https://stackoverflow.com/q/6185994
https://stackoverflow.com/a/6186687
<p>If your directory structure is huge but not changing frequently, it is good to run</p> <pre><code>cd /to/root/of/the/files find . -type f -print &gt; ../LIST_OF_FILES.txt #and sometimes handy the next one too find . -type d -print &gt; ../LIST_OF_DIRS.txt </code></pre> <p>after it you can really FAST find anything...
<p>If your directory structure is huge but not changing frequently, it is good to run</p> <pre><code>cd /to/root/of/the/files find . -type f -print &gt; ../LIST_OF_FILES.txt #and sometimes handy the next one too find . -type d -print &gt; ../LIST_OF_DIRS.txt </code></pre> <p>after it you can really FAST find anything...
34, 387, 10193
bash, find, unix
<h1>Unix find: list of files from stdin</h1> <p>I'm working in Linux &amp; bash (or Cygwin &amp; bash).</p> <p>I have a huge--<em>huge</em>--directory structure, and I have to find a few needles in the haystack.</p> <p>Specifically, I'm looking for these files (20 or so):</p> <pre><code>foo.c bar.h ... quux.txt </co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,690
bash
# Unix find: list of files from stdin I'm working in Linux & bash (or Cygwin & bash). I have a huge--*huge*--directory structure, and I have to find a few needles in the haystack. Specifically, I'm looking for these files (20 or so): ``` foo.c bar.h ... quux.txt ``` I know that they are in a subdirectory somewhere...
If your directory structure is huge but not changing frequently, it is good to run ``` cd /to/root/of/the/files find . -type f -print > ../LIST_OF_FILES.txt #and sometimes handy the next one too find . -type d -print > ../LIST_OF_DIRS.txt ``` after it you can really FAST find anything (with grep, sed, etc..) and upda...
5038803
Function local read-only vs. global read-only variable with the same name
14
2011-02-18 07:45:18
<p>I get a suprising behaviour when I have a function local read-only variable and global read-only variable with the same name.</p> <p>When read-only option is removed from global declaration. I.e.</p> <pre><code>declare -r var="main" </code></pre> <p>is changed to:</p> <pre><code>declare var="main" </code></pre> ...
4,326
272,735
2011-03-07 05:31:22
5,039,040
12
2011-02-18 08:22:47
131,966
2011-03-07 05:31:22
https://stackoverflow.com/q/5038803
https://stackoverflow.com/a/5039040
<p>Actually, making local copies of readonly global variables is explicitely forbidden for security reasons, as documented in bash source code (in <code>variables.c:make_local_variable</code>):</p> <blockquote> <p><strong>The test against old_var's context level is to disallow local copies of readonly global variabl...
<p>Actually, making local copies of readonly global variables is explicitely forbidden for security reasons, as documented in bash source code (in <code>variables.c:make_local_variable</code>):</p> <blockquote> <p><strong>The test against old_var's context level is to disallow local copies of readonly global variabl...
387, 2182
bash, scope
<h1>Function local read-only vs. global read-only variable with the same name</h1> <p>I get a suprising behaviour when I have a function local read-only variable and global read-only variable with the same name.</p> <p>When read-only option is removed from global declaration. I.e.</p> <pre><code>declare -r var="main"...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,691
bash
# Function local read-only vs. global read-only variable with the same name I get a suprising behaviour when I have a function local read-only variable and global read-only variable with the same name. When read-only option is removed from global declaration. I.e. ``` declare -r var="main" ``` is changed to: ``` d...
Actually, making local copies of readonly global variables is explicitely forbidden for security reasons, as documented in bash source code (in `variables.c:make_local_variable`): > **The test against old_var's context level is to disallow local copies of readonly global variables (since "I" believe that this could be...
4198233
Spread 'sed' command over multiple lines
14
2010-11-16 19:41:09
<p>I am trying to spread one sed command over several lines in a bash file. I have multiple patterns that sed checks for and I am hoping to separate some of the patterns by a line change. Here is my current script that does not work, putting everything on one line works but I was hoping to just clean it up a bit and sp...
19,372
217,114
2018-07-16 06:43:47
4,198,487
12
2010-11-16 20:11:23
26,428
2018-05-16 15:31:06
https://stackoverflow.com/q/4198233
https://stackoverflow.com/a/4198487
<p>The problem is on this line:</p> <pre><code>-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \ </code></pre> <p>There's a missing <code>s/</code>. It should be:</p> <pre><code>-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i;...
<p>The problem is on this line:</p> <pre><code>-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \ </code></pre> <p>There's a missing <code>s/</code>. It should be:</p> <pre><code>-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i;...
387, 5282
bash, sed
<h1>Spread 'sed' command over multiple lines</h1> <p>I am trying to spread one sed command over several lines in a bash file. I have multiple patterns that sed checks for and I am hoping to separate some of the patterns by a line change. Here is my current script that does not work, putting everything on one line works...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,692
bash
# Spread 'sed' command over multiple lines I am trying to spread one sed command over several lines in a bash file. I have multiple patterns that sed checks for and I am hoping to separate some of the patterns by a line change. Here is my current script that does not work, putting everything on one line works but I wa...
The problem is on this line: ``` -e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \ ``` There's a missing `s/`. It should be: ``` -e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p...
3174883
How to remove last directory from a path with sed?
14
2010-07-04 13:54:15
<p>How to remove the last dir with <code>sed</code> (not <code>dirname</code>), like this:</p> <pre><code>echo "/dir1/dir2/dir3/dir4" | sed ..... </code></pre> <p>So I would get <code>/dir1/dir2/dir3</code>.</p>
34,291
381,293
2020-08-20 12:27:16
3,174,901
12
2010-07-04 14:00:42
241,521
2010-07-04 14:00:42
https://stackoverflow.com/q/3174883
https://stackoverflow.com/a/3174901
<pre><code>sed 's,/*[^/]\+/*$,,' </code></pre> <p>If it's part of the shell script, then <code>dirname</code> will be definitely more clear.</p>
<pre><code>sed 's,/*[^/]\+/*$,,' </code></pre> <p>If it's part of the shell script, then <code>dirname</code> will be definitely more clear.</p>
390, 5282, 6268
path, sed, shell
<h1>How to remove last directory from a path with sed?</h1> <p>How to remove the last dir with <code>sed</code> (not <code>dirname</code>), like this:</p> <pre><code>echo "/dir1/dir2/dir3/dir4" | sed ..... </code></pre> <p>So I would get <code>/dir1/dir2/dir3</code>.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,693
bash
# How to remove last directory from a path with sed? How to remove the last dir with `sed` (not `dirname`), like this: ``` echo "/dir1/dir2/dir3/dir4" | sed ..... ``` So I would get `/dir1/dir2/dir3`.
``` sed 's,/*[^/]\+/*$,,' ``` If it's part of the shell script, then `dirname` will be definitely more clear.
53135226
What am I allowed to name a function in Powershell?
13
2018-11-03 20:29:42
<pre><code>PS &gt; function ]{1} PS &gt; ] 1 PS &gt; PS </code></pre> <p>Why does this work? </p> <p>What else can I name a function? All I've found so far that works is <code>*</code> and <code>]</code>. </p>
1,534
6,726,363
2018-11-03 21:11:30
53,135,308
12
2018-11-03 20:38:58
3,905,079
2018-11-03 21:11:30
https://stackoverflow.com/q/53135226
https://stackoverflow.com/a/53135308
<p>You can name it almost anything. You can even include newlines and emoji* in the name.</p> <pre><code>function Weird`nFunctionの名前😀 { Write-Host hey } $c = gcm Weird* $c.Name &amp; $c </code></pre> <p>Escaping helps with lots of things like that:</p> <pre><code>function `{ { Write-Host cool } `{ function `0 { Wr...
<p>You can name it almost anything. You can even include newlines and emoji* in the name.</p> <pre><code>function Weird`nFunctionの名前😀 { Write-Host hey } $c = gcm Weird* $c.Name &amp; $c </code></pre> <p>Escaping helps with lots of things like that:</p> <pre><code>function `{ { Write-Host cool } `{ function `0 { Wr...
526
powershell
<h1>What am I allowed to name a function in Powershell?</h1> <pre><code>PS &gt; function ]{1} PS &gt; ] 1 PS &gt; PS </code></pre> <p>Why does this work? </p> <p>What else can I name a function? All I've found so far that works is <code>*</code> and <code>]</code>. </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,694
bash
# What am I allowed to name a function in Powershell? ``` PS > function ]{1} PS > ] 1 PS > PS ``` Why does this work? What else can I name a function? All I've found so far that works is `*` and `]`.
You can name it almost anything. You can even include newlines and emoji* in the name. ``` function Weird`nFunctionの名前😀 { Write-Host hey } $c = gcm Weird* $c.Name & $c ``` Escaping helps with lots of things like that: ``` function `{ { Write-Host cool } `{ function `0 { Write-Host null } gci function:\? ``` I'll ...
47570866
PowerShell cmdlet Test-NetConnection not available
13
2017-11-30 10:13:04
<p>I noticed that the cmdlet <code>Test-NetConnection</code> was not installed on Server 2012. Since Server 2012 comes with PowerShell version 3 so I thought it might help to update to the latest version 5.1.</p> <p>I did the update but the cmdlet <code>Test-NetConnection</code> is still not available.</p> <p>Only <c...
73,461
5,675,553
2022-02-23 21:46:26
47,571,225
12
2017-11-30 10:31:24
1,630,171
2017-11-30 10:31:24
https://stackoverflow.com/q/47570866
https://stackoverflow.com/a/47571225
<p>The availability of many cmdlets is tied to the Windows version, not the PowerShell version. If you can't upgrade your Windows version you can't have <code>Test-NetConnection</code>.</p> <p>You could use a commandline port scanner like <a href="https://nmap.org/download.html" rel="noreferrer">nmap</a> or <a href="h...
<p>The availability of many cmdlets is tied to the Windows version, not the PowerShell version. If you can't upgrade your Windows version you can't have <code>Test-NetConnection</code>.</p> <p>You could use a commandline port scanner like <a href="https://nmap.org/download.html" rel="noreferrer">nmap</a> or <a href="h...
526, 84278
powershell, windows-server-2012
<h1>PowerShell cmdlet Test-NetConnection not available</h1> <p>I noticed that the cmdlet <code>Test-NetConnection</code> was not installed on Server 2012. Since Server 2012 comes with PowerShell version 3 so I thought it might help to update to the latest version 5.1.</p> <p>I did the update but the cmdlet <code>Test-...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,695
bash
# PowerShell cmdlet Test-NetConnection not available I noticed that the cmdlet `Test-NetConnection` was not installed on Server 2012. Since Server 2012 comes with PowerShell version 3 so I thought it might help to update to the latest version 5.1. I did the update but the cmdlet `Test-NetConnection` is still not avai...
The availability of many cmdlets is tied to the Windows version, not the PowerShell version. If you can't upgrade your Windows version you can't have `Test-NetConnection`. You could use a commandline port scanner like [nmap](https://nmap.org/download.html) or [scanline](https://www.mcafee.com/ca/downloads/free-tools/s...
46562463
How to load environment variables for the process of a systemd service?
13
2017-10-04 10:20:42
<p>i am developing some services scripts that need to be executed on boot on Raspbian (Jessie) and i decided to use systemd. I just started to read some quick tutorials on how to use it, but I have problems with the environment.</p> <p>The processes that are executed require (in their code) some environment variables ...
19,309
6,119,246
2017-10-05 05:53:59
46,578,750
12
2017-10-05 05:53:59
7,449,540
2017-10-05 05:53:59
https://stackoverflow.com/q/46562463
https://stackoverflow.com/a/46578750
<p>Environment can be set in systemd service file as below under Exec options</p> <pre><code>Environment=LD_LIBRARY_PATH=/usr/lib </code></pre> <p>Below is the official documentation of systemd Environment/EnvironmentFile usage</p> <p><strong>Environment=</strong></p> <p>Sets environment variables for executed proc...
<p>Environment can be set in systemd service file as below under Exec options</p> <pre><code>Environment=LD_LIBRARY_PATH=/usr/lib </code></pre> <p>Below is the official documentation of systemd Environment/EnvironmentFile usage</p> <p><strong>Environment=</strong></p> <p>Sets environment variables for executed proc...
387, 390, 9013, 81442, 84436
bash, environment-variables, raspbian, shell, systemd
<h1>How to load environment variables for the process of a systemd service?</h1> <p>i am developing some services scripts that need to be executed on boot on Raspbian (Jessie) and i decided to use systemd. I just started to read some quick tutorials on how to use it, but I have problems with the environment.</p> <p>Th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,696
bash
# How to load environment variables for the process of a systemd service? i am developing some services scripts that need to be executed on boot on Raspbian (Jessie) and i decided to use systemd. I just started to read some quick tutorials on how to use it, but I have problems with the environment. The processes that...
Environment can be set in systemd service file as below under Exec options ``` Environment=LD_LIBRARY_PATH=/usr/lib ``` Below is the official documentation of systemd Environment/EnvironmentFile usage **Environment=** Sets environment variables for executed processes. Takes a space-separated list of variable assign...
44111831
bash: read multi-line string into multiple variables
13
2017-05-22 11:33:53
<p>How can I assign a newline-separated string with e.g. three lines to three variables ?</p> <pre><code># test string s='line 01 line 02 line 03' # this doesn't seem to make any difference at all IFS=$'\n' # first naive attempt read a b c &lt;&lt;&lt; "${s}" # this prints 'line 01||': # everything after the first ...
10,088
217,844
2023-09-14 18:28:33
44,112,055
12
2017-05-22 11:46:05
1,454,708
2023-09-14 18:28:33
https://stackoverflow.com/q/44111831
https://stackoverflow.com/a/44112055
<p>read default input delimiter is \n</p> <pre><code>{ read a; read b; read c;} &lt;&lt;&lt; &quot;${s}&quot; </code></pre> <p>-d char : allows to specify another input delimiter</p> <p>For example is there is no character SOH (1 ASCII) in input string</p> <pre><code>IFS=$'\n' read -r -d$'\1' a b c &lt;&lt;&lt; &quot;$...
<p>read default input delimiter is \n</p> <pre><code>{ read a; read b; read c;} &lt;&lt;&lt; &quot;${s}&quot; </code></pre> <p>-d char : allows to specify another input delimiter</p> <p>For example is there is no character SOH (1 ASCII) in input string</p> <pre><code>IFS=$'\n' read -r -d$'\1' a b c &lt;&lt;&lt; &quot;$...
139, 387
bash, string
<h1>bash: read multi-line string into multiple variables</h1> <p>How can I assign a newline-separated string with e.g. three lines to three variables ?</p> <pre><code># test string s='line 01 line 02 line 03' # this doesn't seem to make any difference at all IFS=$'\n' # first naive attempt read a b c &lt;&lt;&lt; "$...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,697
bash
# bash: read multi-line string into multiple variables How can I assign a newline-separated string with e.g. three lines to three variables ? ``` # test string s='line 01 line 02 line 03' # this doesn't seem to make any difference at all IFS=$'\n' # first naive attempt read a b c <<< "${s}" # this prints 'line 01|...
read default input delimiter is \n ``` { read a; read b; read c;} <<< "${s}" ``` -d char : allows to specify another input delimiter For example is there is no character SOH (1 ASCII) in input string ``` IFS=$'\n' read -r -d$'\1' a b c <<< "${s}" ``` We set `IFS` to `$'\n'` because IFS default value is : ``` $ pr...
35296482
Invalid Web Uri error on Register-PSRepository
13
2016-02-09 15:58:56
<p>After Windows November update (<code>PackageManagement</code> and <code>PowerShellGet</code> modules of 1.0.0.1 version) I can't register HTTPS NuGet servers as PSRepository anymore:</p> <pre><code>Register-PSRepository -Name test -SourceLocation https://some-nuget/api/v2 </code></pre> <p>It returns error:</p> <p...
21,817
515,835
2023-06-14 11:06:41
35,296,483
12
2016-02-09 15:58:56
515,835
2016-03-21 14:51:50
https://stackoverflow.com/q/35296482
https://stackoverflow.com/a/35296483
<p>This is caused with a bug related to accessing HTTPS endpoints which probably will be fixed soon.</p> <p>I still want to share a workaround kindly hinted by <a href="https://github.com/OneGet/oneget" rel="noreferrer">OneGet team</a>:</p> <pre><code>Function Register-PSRepositoryFix { [CmdletBinding()] Para...
<p>This is caused with a bug related to accessing HTTPS endpoints which probably will be fixed soon.</p> <p>I still want to share a workaround kindly hinted by <a href="https://github.com/OneGet/oneget" rel="noreferrer">OneGet team</a>:</p> <pre><code>Function Register-PSRepositoryFix { [CmdletBinding()] Para...
526, 115517, 115604
oneget, powershell, powershellget
<h1>Invalid Web Uri error on Register-PSRepository</h1> <p>After Windows November update (<code>PackageManagement</code> and <code>PowerShellGet</code> modules of 1.0.0.1 version) I can't register HTTPS NuGet servers as PSRepository anymore:</p> <pre><code>Register-PSRepository -Name test -SourceLocation https://some-...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,698
bash
# Invalid Web Uri error on Register-PSRepository After Windows November update (`PackageManagement` and `PowerShellGet` modules of 1.0.0.1 version) I can't register HTTPS NuGet servers as PSRepository anymore: ``` Register-PSRepository -Name test -SourceLocation https://some-nuget/api/v2 ``` It returns error: ``` #...
This is caused with a bug related to accessing HTTPS endpoints which probably will be fixed soon. I still want to share a workaround kindly hinted by [OneGet team](https://github.com/OneGet/oneget): ``` Function Register-PSRepositoryFix { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] ...
30269722
Declaring arrays in ZSH
13
2015-05-15 22:33:43
<p>I'm having trouble converting a shell script to zsh. I have the following array defined, but it is throwing the error <code>unknown file attribute: \n</code>. (I'm converting a dotfiles repo to my zsh)</p> <pre><code>declare -r -a FILES_TO_SOURCE=( "bash_aliases" "bash_exports" "bash_functions" "bas...
19,207
3,272,411
2015-05-16 21:12:08
30,270,126
12
2015-05-15 23:20:23
258,523
2015-05-16 21:12:08
https://stackoverflow.com/q/30269722
https://stackoverflow.com/a/30270126
<p>From <code>man zshbuiltins</code>, under the entry for <code>typeset</code> (of which <code>declare</code> is a synonym):</p> <blockquote> <p>For each <em>name=value</em> assignment, the parameter <em>name</em> is set to <em>value</em>. Note that arrays currently cannot be assigned in <stron...
<p>From <code>man zshbuiltins</code>, under the entry for <code>typeset</code> (of which <code>declare</code> is a synonym):</p> <blockquote> <p>For each <em>name=value</em> assignment, the parameter <em>name</em> is set to <em>value</em>. Note that arrays currently cannot be assigned in <stron...
390, 1231, 3791
command-line, shell, zsh
<h1>Declaring arrays in ZSH</h1> <p>I'm having trouble converting a shell script to zsh. I have the following array defined, but it is throwing the error <code>unknown file attribute: \n</code>. (I'm converting a dotfiles repo to my zsh)</p> <pre><code>declare -r -a FILES_TO_SOURCE=( "bash_aliases" "bash_expor...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,699
bash
# Declaring arrays in ZSH I'm having trouble converting a shell script to zsh. I have the following array defined, but it is throwing the error `unknown file attribute: \n`. (I'm converting a dotfiles repo to my zsh) ``` declare -r -a FILES_TO_SOURCE=( "bash_aliases" "bash_exports" "bash_functions" "b...
From `man zshbuiltins`, under the entry for `typeset` (of which `declare` is a synonym): > For each *name=value* assignment, the parameter *name* is set to *value*. Note that arrays currently cannot > be assigned in **typeset** expressions, only scalars and integers. Try this instead: ``` declare -a FILES_TO_SOURCE ...
25450521
File Name Contains Certain Text
13
2014-08-22 15:26:14
<p>I know this is a new guy question, but I cant find anything. I think the issue might have to do with variable type issue?</p> <p>I'm trying to look at a files name and see if pattern1 is contained in the file name. If so then replace the pattern text with "TEST".</p> <p>Right now it doesn't error out, but it skip...
79,994
3,557,977
2014-08-22 16:09:24
25,450,723
12
2014-08-22 15:38:40
3,245,749
2014-08-22 15:38:40
https://stackoverflow.com/q/25450521
https://stackoverflow.com/a/25450723
<p>The whole issue is that you use -Contains where you should use -Match. Try this though, it's easily expandable if you have more conditions to add:</p> <pre><code>$pattern1 = "January" $pattern2 = "December 31" $path = "C:\Users\...\METRICS-TEST\Metrics 2014\January 2014 Client Metrics" Switch(Get-ChildItem -Path $...
<p>The whole issue is that you use -Contains where you should use -Match. Try this though, it's easily expandable if you have more conditions to add:</p> <pre><code>$pattern1 = "January" $pattern2 = "December 31" $path = "C:\Users\...\METRICS-TEST\Metrics 2014\January 2014 Client Metrics" Switch(Get-ChildItem -Path $...
526, 24067
powershell, powershell-2.0
<h1>File Name Contains Certain Text</h1> <p>I know this is a new guy question, but I cant find anything. I think the issue might have to do with variable type issue?</p> <p>I'm trying to look at a files name and see if pattern1 is contained in the file name. If so then replace the pattern text with "TEST".</p> <p>Ri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,700
bash
# File Name Contains Certain Text I know this is a new guy question, but I cant find anything. I think the issue might have to do with variable type issue? I'm trying to look at a files name and see if pattern1 is contained in the file name. If so then replace the pattern text with "TEST". Right now it doesn't error...
The whole issue is that you use -Contains where you should use -Match. Try this though, it's easily expandable if you have more conditions to add: ``` $pattern1 = "January" $pattern2 = "December 31" $path = "C:\Users\...\METRICS-TEST\Metrics 2014\January 2014 Client Metrics" Switch(Get-ChildItem -Path $path){ {$_...
20790798
Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task
13
2013-12-26 20:22:30
<p>I've got a script that's I want to run as a scheduled task, but it's not doing the thing it's supposed to. I'm trying to call an executable with Start-Process and the -Wait switch before continuing. Line is</p> <blockquote> <p>Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestore...
24,025
3,137,716
2013-12-26 20:39:45
20,790,955
12
2013-12-26 20:39:45
574,168
2013-12-26 20:39:45
https://stackoverflow.com/q/20790798
https://stackoverflow.com/a/20790955
<p>Can't tell you why it's doing it, but I think this might work around it:</p> <pre><code>$proc = Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Passthru do {start-sleep -Milliseconds 500} until ($proc.HasExited) </code></pre> ...
<p>Can't tell you why it's doing it, but I think this might work around it:</p> <pre><code>$proc = Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Passthru do {start-sleep -Milliseconds 500} until ($proc.HasExited) </code></pre> ...
526, 9299, 21289, 26462, 36466
powershell, scheduled-tasks, start-process, wait, windows-server-2008-r2
<h1>Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task</h1> <p>I've got a script that's I want to run as a scheduled task, but it's not doing the thing it's supposed to. I'm trying to call an executable with Start-Process and the -Wait switch before con...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,701
bash
# Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task I've got a script that's I want to run as a scheduled task, but it's not doing the thing it's supposed to. I'm trying to call an executable with Start-Process and the -Wait switch before continuing. ...
Can't tell you why it's doing it, but I think this might work around it: ``` $proc = Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Passthru do {start-sleep -Milliseconds 500} until ($proc.HasExited) ``` The -Passthru switch wil...
19563737
Change current directory with node
13
2013-10-24 10:44:41
<p>I'm trying to write a command line utility in node.js. As one of the features it should change the current working directory of the shell it was called from. Something like node.js version of <code>cd</code>. Is it possible to achieve this? If so, how?</p> <p>&nbsp;</p> <hr> <p>&nbsp;</p> <p>To clarify, I'd like...
23,815
876,409
2022-01-28 11:41:24
19,565,916
12
2013-10-24 12:26:06
893,780
2013-10-24 12:35:31
https://stackoverflow.com/q/19563737
https://stackoverflow.com/a/19565916
<p>In short: you can't. The working directory is limited to the context of a process (and perhaps child processes, but certainly not parent processes). So the cwd of your Node process cannot propagate back to your shell process.</p> <p>A common trick is to have your Node app print the working directory to stdout, and ...
<p>In short: you can't. The working directory is limited to the context of a process (and perhaps child processes, but certainly not parent processes). So the cwd of your Node process cannot propagate back to your shell process.</p> <p>A common trick is to have your Node app print the working directory to stdout, and ...
3, 387, 390, 46426
bash, javascript, node.js, shell
<h1>Change current directory with node</h1> <p>I'm trying to write a command line utility in node.js. As one of the features it should change the current working directory of the shell it was called from. Something like node.js version of <code>cd</code>. Is it possible to achieve this? If so, how?</p> <p>&nbsp;</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,702
bash
# Change current directory with node I'm trying to write a command line utility in node.js. As one of the features it should change the current working directory of the shell it was called from. Something like node.js version of `cd`. Is it possible to achieve this? If so, how? --- To clarify, I'd like to be able to...
In short: you can't. The working directory is limited to the context of a process (and perhaps child processes, but certainly not parent processes). So the cwd of your Node process cannot propagate back to your shell process. A common trick is to have your Node app print the working directory to stdout, and have your ...
19456184
CLI: implement something like git commit (open a text editor and get value)
13
2013-10-18 17:59:57
<p>I am making a command line app. I want to allow the user, when they are adding values for things in the terminal, to be able to add the value with their text editor. How does git achieve this? </p> <p>I want to open their default editor, allow them to enter text, and when they save get the value and use that value ...
2,488
2,433,617
2013-10-18 18:07:31
19,456,297
12
2013-10-18 18:07:31
1,126,841
2013-10-18 18:07:31
https://stackoverflow.com/q/19456184
https://stackoverflow.com/a/19456297
<p>Typically, you do four things:</p> <ol> <li>Create a temporary file</li> <li>Fork an external process which execs the program specified in the environment variable <code>$EDITOR</code>, giving the name of the temporary file as an argument.</li> <li>Wait for the process to return.</li> <li>Open and read from the tem...
<p>Typically, you do four things:</p> <ol> <li>Create a temporary file</li> <li>Fork an external process which execs the program specified in the environment variable <code>$EDITOR</code>, giving the name of the temporary file as an argument.</li> <li>Wait for the process to return.</li> <li>Open and read from the tem...
119, 390, 1231, 11225, 46426
command-line, command-line-interface, git, node.js, shell
<h1>CLI: implement something like git commit (open a text editor and get value)</h1> <p>I am making a command line app. I want to allow the user, when they are adding values for things in the terminal, to be able to add the value with their text editor. How does git achieve this? </p> <p>I want to open their default e...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,703
bash
# CLI: implement something like git commit (open a text editor and get value) I am making a command line app. I want to allow the user, when they are adding values for things in the terminal, to be able to add the value with their text editor. How does git achieve this? I want to open their default editor, allow them...
Typically, you do four things: 1. Create a temporary file 2. Fork an external process which execs the program specified in the environment variable `$EDITOR`, giving the name of the temporary file as an argument. 3. Wait for the process to return. 4. Open and read from the temporary file to see what the user wrote.
17847276
Is an exception from a .NET method a terminating or not-terminating error?
13
2013-07-25 01:02:21
<p>In this <a href="http://rkeithhill.wordpress.com/2009/08/03/effective-powershell-item-16-dealing-with-errors/" rel="nofollow noreferrer">great article</a> Keith explains the difference between terminating and non-terminating errors in Powershell. According to Keith exceptions thrown from calls to a member of a .NET ...
4,203
284,111
2025-03-15 22:42:01
17,849,307
12
2013-07-25 04:56:19
153,982
2013-07-25 05:01:52
https://stackoverflow.com/q/17847276
https://stackoverflow.com/a/17849307
<p>Yeah, this came up on the PowerShell MVP email list earlier this year. PowerShell changes its error handling behavior for .NET exceptions depending on whether or not there is an outer try/catch. This is just speculation but I'm guessing that this was for simple scripting scenarios. That is, if the scripter (admin...
<p>Yeah, this came up on the PowerShell MVP email list earlier this year. PowerShell changes its error handling behavior for .NET exceptions depending on whether or not there is an outer try/catch. This is just speculation but I'm guessing that this was for simple scripting scenarios. That is, if the scripter (admin...
379, 526, 5142
error-handling, exception, powershell
<h1>Is an exception from a .NET method a terminating or not-terminating error?</h1> <p>In this <a href="http://rkeithhill.wordpress.com/2009/08/03/effective-powershell-item-16-dealing-with-errors/" rel="nofollow noreferrer">great article</a> Keith explains the difference between terminating and non-terminating errors i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,704
bash
# Is an exception from a .NET method a terminating or not-terminating error? In this [great article](http://rkeithhill.wordpress.com/2009/08/03/effective-powershell-item-16-dealing-with-errors/) Keith explains the difference between terminating and non-terminating errors in Powershell. According to Keith exceptions th...
Yeah, this came up on the PowerShell MVP email list earlier this year. PowerShell changes its error handling behavior for .NET exceptions depending on whether or not there is an outer try/catch. This is just speculation but I'm guessing that this was for simple scripting scenarios. That is, if the scripter (admin) mess...
13976472
What does if [ "x" != x ] do in bash?
13
2012-12-20 16:29:05
<p>I'm looking at the source code of virtualenv, and the activate script contains this code: </p> <pre><code>if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then _OLD_VIRTUAL_PS1="$PS1" if [ "x" != x ] ; then PS1="$PS1" else if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then # special...
6,283
1,559,908
2012-12-20 16:34:40
13,976,553
12
2012-12-20 16:33:23
978,917
2012-12-20 16:33:23
https://stackoverflow.com/q/13976472
https://stackoverflow.com/a/13976553
<p>In Bash, that test is guaranteed to fail; <code>[ "x" != x ]</code> always returns a non-zero exit status (i.e. "false"), because <code>"x"</code> and <code>x</code> are both the string consisting of the single character <code>x</code>. (The quotation marks don't really have any effect in this case.)</p> <p>What's ...
<p>In Bash, that test is guaranteed to fail; <code>[ "x" != x ]</code> always returns a non-zero exit status (i.e. "false"), because <code>"x"</code> and <code>x</code> are both the string consisting of the single character <code>x</code>. (The quotation marks don't really have any effect in this case.)</p> <p>What's ...
390
shell
<h1>What does if [ "x" != x ] do in bash?</h1> <p>I'm looking at the source code of virtualenv, and the activate script contains this code: </p> <pre><code>if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then _OLD_VIRTUAL_PS1="$PS1" if [ "x" != x ] ; then PS1="$PS1" else if [ "`basename \"$VI...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,705
bash
# What does if [ "x" != x ] do in bash? I'm looking at the source code of virtualenv, and the activate script contains this code: ``` if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then _OLD_VIRTUAL_PS1="$PS1" if [ "x" != x ] ; then PS1="$PS1" else if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ]...
In Bash, that test is guaranteed to fail; `[ "x" != x ]` always returns a non-zero exit status (i.e. "false"), because `"x"` and `x` are both the string consisting of the single character `x`. (The quotation marks don't really have any effect in this case.) What's more, the command `PS1="$PS1"` doesn't really do anyth...
12818987
Pass ATTR{idVendor} as argument in udev script
13
2012-10-10 12:08:15
<p>I have a script which is run whenever a usb device by vendor 1004 is connected. The udev rule I am using works and looks like this.</p> <pre><code>SUBSYSTEM=="usb", ATTR{idVendor}=="1004", RUN+="/var/www/beta/trigger.php" </code></pre> <p>Now I would like to have this script run whenever ANY usb device is connecte...
18,562
1,230,420
2017-05-10 13:44:14
12,819,134
12
2012-10-10 12:15:49
1,686,814
2012-10-10 12:15:49
https://stackoverflow.com/q/12818987
https://stackoverflow.com/a/12819134
<p><code>udev</code> sets for you several environmental variables that you can use, among others <code>ID_VENDOR</code>. Try that little script:</p> <pre><code>#!/bin/bash echo "Called by udev" &gt;&gt; /tmp/testenv env &gt;&gt; /tmp/testenv echo "Vendor id is $ID_VENDOR" &gt;&gt; /tmp/testenv </code></pre> <p>Put i...
<p><code>udev</code> sets for you several environmental variables that you can use, among others <code>ID_VENDOR</code>. Try that little script:</p> <pre><code>#!/bin/bash echo "Called by udev" &gt;&gt; /tmp/testenv env &gt;&gt; /tmp/testenv echo "Vendor id is $ID_VENDOR" &gt;&gt; /tmp/testenv </code></pre> <p>Put i...
58, 390, 393, 11490
linux, shell, udev, usb
<h1>Pass ATTR{idVendor} as argument in udev script</h1> <p>I have a script which is run whenever a usb device by vendor 1004 is connected. The udev rule I am using works and looks like this.</p> <pre><code>SUBSYSTEM=="usb", ATTR{idVendor}=="1004", RUN+="/var/www/beta/trigger.php" </code></pre> <p>Now I would like to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,706
bash
# Pass ATTR{idVendor} as argument in udev script I have a script which is run whenever a usb device by vendor 1004 is connected. The udev rule I am using works and looks like this. ``` SUBSYSTEM=="usb", ATTR{idVendor}=="1004", RUN+="/var/www/beta/trigger.php" ``` Now I would like to have this script run whenever ANY...
`udev` sets for you several environmental variables that you can use, among others `ID_VENDOR`. Try that little script: ``` #!/bin/bash echo "Called by udev" >> /tmp/testenv env >> /tmp/testenv echo "Vendor id is $ID_VENDOR" >> /tmp/testenv ``` Put it in a rule, and you will see how much things are set up for you.
12405119
Unix cut: Print same Field twice
13
2012-09-13 11:22:29
<p>Say I have file - a.csv</p> <pre><code>ram,33,professional,doc shaym,23,salaried,eng </code></pre> <p>Now I need this output (pls dont ask me why)</p> <pre><code>ram,doc,doc, shayam,eng,eng, </code></pre> <p>I am using cut command</p> <pre><code>cut -d',' -f1,4,4 a.csv </code></pre> <p>But the output remains<...
8,901
1,662,774
2019-07-14 13:24:54
12,405,420
12
2012-09-13 11:39:52
387,076
2012-09-13 11:48:09
https://stackoverflow.com/q/12405119
https://stackoverflow.com/a/12405420
<p>You can't print the same field twice. <code>cut</code> prints a selection of fields (or characters or bytes) in order. See <a href="https://unix.stackexchange.com/questions/47048/combining-2-different-cut-outputs-in-a-single-command">Combining 2 different cut outputs in a single command?</a> and <a href="https://uni...
<p>You can't print the same field twice. <code>cut</code> prints a selection of fields (or characters or bytes) in order. See <a href="https://unix.stackexchange.com/questions/47048/combining-2-different-cut-outputs-in-a-single-command">Combining 2 different cut outputs in a single command?</a> and <a href="https://uni...
34, 390, 4257, 5282
cut, sed, shell, unix
<h1>Unix cut: Print same Field twice</h1> <p>Say I have file - a.csv</p> <pre><code>ram,33,professional,doc shaym,23,salaried,eng </code></pre> <p>Now I need this output (pls dont ask me why)</p> <pre><code>ram,doc,doc, shayam,eng,eng, </code></pre> <p>I am using cut command</p> <pre><code>cut -d',' -f1,4,4 a.csv...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,707
bash
# Unix cut: Print same Field twice Say I have file - a.csv ``` ram,33,professional,doc shaym,23,salaried,eng ``` Now I need this output (pls dont ask me why) ``` ram,doc,doc, shayam,eng,eng, ``` I am using cut command ``` cut -d',' -f1,4,4 a.csv ``` But the output remains ``` ram,doc shyam,eng ``` That means *...
You can't print the same field twice. `cut` prints a selection of fields (or characters or bytes) in order. See [Combining 2 different cut outputs in a single command?](https://unix.stackexchange.com/questions/47048/combining-2-different-cut-outputs-in-a-single-command) and [Reorder fields/characters with cut command](...
10700660
Add-PsSnapin WebAdministration in Windows7
13
2012-05-22 10:58:08
<p>I want to use PowerShell to administer my IIS7 on Windows7 64 bits. </p> <p>I try install IIS7 Powershell snap-in <a href="http://www.iis.net/download/PowerShell" rel="nofollow noreferrer">http://www.iis.net/download/PowerShell</a></p> <p>I "Run as administrator", then typing the command listed below: msiexec /I ...
29,484
206,730
2012-05-22 13:48:41
10,701,434
12
2012-05-22 11:48:26
311,712
2012-05-22 11:48:26
https://stackoverflow.com/q/10700660
https://stackoverflow.com/a/10701434
<p>Here is the function I have in my profile.ps1 for loading the WebAdmin module. It covers IIS 7 and 7.5</p> <pre><code># Web administration is loaded as a module on Windows 2008 R2 but as a set of snapins # for Windows 2008 (not R2) function Util-Load-Web-Administration { $ModuleName = "WebAdministration" $...
<p>Here is the function I have in my profile.ps1 for loading the WebAdmin module. It covers IIS 7 and 7.5</p> <pre><code># Web administration is loaded as a module on Windows 2008 R2 but as a set of snapins # for Windows 2008 (not R2) function Util-Load-Web-Administration { $ModuleName = "WebAdministration" $...
526, 23478, 34595, 35311, 68067
iis-7.5, powershell, snap-in, web-administration, windows-7
<h1>Add-PsSnapin WebAdministration in Windows7</h1> <p>I want to use PowerShell to administer my IIS7 on Windows7 64 bits. </p> <p>I try install IIS7 Powershell snap-in <a href="http://www.iis.net/download/PowerShell" rel="nofollow noreferrer">http://www.iis.net/download/PowerShell</a></p> <p>I "Run as administrator...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,708
bash
# Add-PsSnapin WebAdministration in Windows7 I want to use PowerShell to administer my IIS7 on Windows7 64 bits. I try install IIS7 Powershell snap-in <http://www.iis.net/download/PowerShell> I "Run as administrator", then typing the command listed below: msiexec /I iis7psprov_x64.msi but I get this error message: "...
Here is the function I have in my profile.ps1 for loading the WebAdmin module. It covers IIS 7 and 7.5 ``` # Web administration is loaded as a module on Windows 2008 R2 but as a set of snapins # for Windows 2008 (not R2) function Util-Load-Web-Administration { $ModuleName = "WebAdministration" $ModuleLoaded =...
8641109
Encrypt a file using bash shell script
13
2011-12-27 04:18:34
<p>I want to encrypt a file using openssl. I can do it by using </p> <pre><code>openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss </code></pre> <p>When I run this command, it gets password from me two times. I want to set password with the script and I used </p> <pre><code>openssl des3 -salt -in /prit...
14,623
1,044,804
2014-12-27 09:48:29
8,641,318
12
2011-12-27 04:56:47
970,195
2011-12-27 04:56:47
https://stackoverflow.com/q/8641109
https://stackoverflow.com/a/8641318
<p>Try something like this - </p> <pre><code>openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss -pass pass:pritom </code></pre> <p>From the <code>man</code> page:</p> <blockquote> <p><code>PASS PHRASE ARGUMENTS<br> Several commands accept password arguments, typically using -passin and -passo...
<p>Try something like this - </p> <pre><code>openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss -pass pass:pritom </code></pre> <p>From the <code>man</code> page:</p> <blockquote> <p><code>PASS PHRASE ARGUMENTS<br> Several commands accept password arguments, typically using -passin and -passo...
58, 219, 387, 390, 1999
bash, encryption, linux, openssl, shell
<h1>Encrypt a file using bash shell script</h1> <p>I want to encrypt a file using openssl. I can do it by using </p> <pre><code>openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss </code></pre> <p>When I run this command, it gets password from me two times. I want to set password with the script and I us...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,709
bash
# Encrypt a file using bash shell script I want to encrypt a file using openssl. I can do it by using ``` openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss ``` When I run this command, it gets password from me two times. I want to set password with the script and I used ``` openssl des3 -salt -in /pri...
Try something like this - ``` openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss -pass pass:pritom ``` From the `man` page: > `PASS PHRASE ARGUMENTS > Several commands accept password arguments, typically using -passin and -passout for input and output > passwords respectively. These allow the passwor...
8082947
How to pass an array to a bash function
13
2011-11-10 16:34:41
<p>How do I pass an array to a function, and why wouldn't this work? The solutions in other questions didn't work for me. For the record, I don't need to copy the array so I don't mind passing a reference. All I want to do is loop over it.</p> <pre><code>$ ar=(a b c) $ function test() { echo ${1[@]}; } $ echo ${ar[@]}...
8,503
995,421
2013-09-04 02:10:49
8,083,147
12
2011-11-10 16:46:53
378,193
2011-11-10 16:46:53
https://stackoverflow.com/q/8082947
https://stackoverflow.com/a/8083147
<pre><code>#!/bin/bash ar=( a b c ) test() { local ref=$1[@] echo ${!ref} } test ar </code></pre>
<pre><code>#!/bin/bash ar=( a b c ) test() { local ref=$1[@] echo ${!ref} } test ar </code></pre>
114, 387, 390
arrays, bash, shell
<h1>How to pass an array to a bash function</h1> <p>How do I pass an array to a function, and why wouldn't this work? The solutions in other questions didn't work for me. For the record, I don't need to copy the array so I don't mind passing a reference. All I want to do is loop over it.</p> <pre><code>$ ar=(a b c) $ ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,710
bash
# How to pass an array to a bash function How do I pass an array to a function, and why wouldn't this work? The solutions in other questions didn't work for me. For the record, I don't need to copy the array so I don't mind passing a reference. All I want to do is loop over it. ``` $ ar=(a b c) $ function test() { ec...
``` #!/bin/bash ar=( a b c ) test() { local ref=$1[@] echo ${!ref} } test ar ```
7721081
Does there exist standard way to run external program in Common Lisp?
13
2011-10-11 03:24:18
<p>In clisp, the following code works:</p> <pre><code>(defun hit-history () (shell "tail ssqHitNum.txt")) </code></pre> <p>However, in Clozure CL, the <code>shell</code> function is not supported!</p>
8,029
777,131
2019-09-27 20:11:21
7,721,356
12
2011-10-11 04:24:09
271,324
2017-01-03 22:45:12
https://stackoverflow.com/q/7721081
https://stackoverflow.com/a/7721356
<p>No, there is no standard way, but there are libraries which provide this functionality for the important implementations. For example, there's trivial-shell available in <a href="http://www.quicklisp.org/" rel="nofollow noreferrer">Quicklisp</a>, which provides <code>shell-command</code>. (I didn't actually test it,...
<p>No, there is no standard way, but there are libraries which provide this functionality for the important implementations. For example, there's trivial-shell available in <a href="http://www.quicklisp.org/" rel="nofollow noreferrer">Quicklisp</a>, which provides <code>shell-command</code>. (I didn't actually test it,...
390, 7610, 7932, 58311
ccl, common-lisp, exec, shell
<h1>Does there exist standard way to run external program in Common Lisp?</h1> <p>In clisp, the following code works:</p> <pre><code>(defun hit-history () (shell "tail ssqHitNum.txt")) </code></pre> <p>However, in Clozure CL, the <code>shell</code> function is not supported!</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,711
bash
# Does there exist standard way to run external program in Common Lisp? In clisp, the following code works: ``` (defun hit-history () (shell "tail ssqHitNum.txt")) ``` However, in Clozure CL, the `shell` function is not supported!
No, there is no standard way, but there are libraries which provide this functionality for the important implementations. For example, there's trivial-shell available in [Quicklisp](http://www.quicklisp.org/), which provides `shell-command`. (I didn't actually test it, but its among the [recommended libraries](http://w...
2331936
Bash Scripting and bc
13
2010-02-25 05:50:20
<p>I'm trying to write a bash script and I needed to do some floating point math. Basically I want to do something like this:</p> <pre><code>NUM=$(echo "scale=25;$1/10" | bc) if [ $? -ne 0 ] then echo bad fi </code></pre> <p>The problem I'm running into is $? tends to hold the output from the echo program and not th...
62,030
262,125
2013-07-09 23:44:56
2,331,976
12
2010-02-25 05:59:19
131,527
2010-02-25 08:31:22
https://stackoverflow.com/q/2331936
https://stackoverflow.com/a/2331976
<p>I don't see anything wrong. $NUM is supposed to hold your <code>bc</code> command results</p> <p>see:</p> <pre><code>NUM=$(echo "scale=25;$1/10" | bc) echo "\$? is $?" echo "NUM is $NUM" </code></pre> <p>output</p> <pre><code>$ ./shell.sh 10 $? is 0 NUM is 1.0000000000000000000000000 </code></pre> <p>another wa...
<p>I don't see anything wrong. $NUM is supposed to hold your <code>bc</code> command results</p> <p>see:</p> <pre><code>NUM=$(echo "scale=25;$1/10" | bc) echo "\$? is $?" echo "NUM is $NUM" </code></pre> <p>output</p> <pre><code>$ ./shell.sh 10 $? is 0 NUM is 1.0000000000000000000000000 </code></pre> <p>another wa...
387, 531, 10327, 34696
bash, bc, scripting, sh
<h1>Bash Scripting and bc</h1> <p>I'm trying to write a bash script and I needed to do some floating point math. Basically I want to do something like this:</p> <pre><code>NUM=$(echo "scale=25;$1/10" | bc) if [ $? -ne 0 ] then echo bad fi </code></pre> <p>The problem I'm running into is $? tends to hold the output f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,712
bash
# Bash Scripting and bc I'm trying to write a bash script and I needed to do some floating point math. Basically I want to do something like this: ``` NUM=$(echo "scale=25;$1/10" | bc) if [ $? -ne 0 ] then echo bad fi ``` The problem I'm running into is $? tends to hold the output from the echo program and not the b...
I don't see anything wrong. $NUM is supposed to hold your `bc` command results see: ``` NUM=$(echo "scale=25;$1/10" | bc) echo "\$? is $?" echo "NUM is $NUM" ``` output ``` $ ./shell.sh 10 $? is 0 NUM is 1.0000000000000000000000000 ``` another way is to use awk ``` NUM=$(awk -vinput="$1" 'BEGIN{printf "%.25f", in...
1127994
To bind clear to ^l in Bash
13
2009-07-14 20:56:53
<p>I would like to have <code>Ctrl-l</code> for <code>clear</code> in my Bash.</p> <p><strong>How can you bind <code>Ctrl-l</code> to <code>clear</code> in Bash?</strong></p>
5,431
54,964
2020-07-06 03:06:20
1,128,021
12
2009-07-14 21:02:15
47,529
2009-07-14 21:02:15
https://stackoverflow.com/q/1127994
https://stackoverflow.com/a/1128021
<p>Put this in your <code>~/.inputrc</code>:</p> <pre><code>C-L: backward-kill-line </code></pre> <p>(assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put <code>clear-screen</code> instead of <code>backward-kill-line</code>).</p>
<p>Put this in your <code>~/.inputrc</code>:</p> <pre><code>C-L: backward-kill-line </code></pre> <p>(assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put <code>clear-screen</code> instead of <code>backward-kill-line</code>).</p>
387, 1137
bash, binding
<h1>To bind clear to ^l in Bash</h1> <p>I would like to have <code>Ctrl-l</code> for <code>clear</code> in my Bash.</p> <p><strong>How can you bind <code>Ctrl-l</code> to <code>clear</code> in Bash?</strong></p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,713
bash
# To bind clear to ^l in Bash I would like to have `Ctrl-l` for `clear` in my Bash. **How can you bind `Ctrl-l` to `clear` in Bash?**
Put this in your `~/.inputrc`: ``` C-L: backward-kill-line ``` (assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put `clear-screen` instead of `backward-kill-line`).
548676
How useful/difficult would it be for me to learn linux shell scripting? Alternative recommendations?
13
2009-02-14 07:15:10
<p>I am in desperate need of some advice.</p> <p>I'm almost done with my junior year as a CS major. I sort of feel like a late comer because I didn't really get into computer science until sophomore year... Through hard work, lots of credit hours during the year and summer school I am almost caught up to my peers b...
14,494
14,013
2017-10-22 05:35:36
548,720
12
2009-02-14 08:02:09
1,438
2009-02-17 22:24:15
https://stackoverflow.com/q/548676
https://stackoverflow.com/a/548720
<p>Sounds like a fine plan. Some suggestions:</p> <ol> <li><p>Learn to automate everything you can. Make it a habit. If you do something more than a couple times, put it in a script. It's not just to avoid typing but to document the process. Improve your scripts as you notice problems. Share your scripts when ap...
<p>Sounds like a fine plan. Some suggestions:</p> <ol> <li><p>Learn to automate everything you can. Make it a habit. If you do something more than a couple times, put it in a script. It's not just to avoid typing but to document the process. Improve your scripts as you notice problems. Share your scripts when ap...
58, 390
linux, shell
<h1>How useful/difficult would it be for me to learn linux shell scripting? Alternative recommendations?</h1> <p>I am in desperate need of some advice.</p> <p>I'm almost done with my junior year as a CS major. I sort of feel like a late comer because I didn't really get into computer science until sophomore year... ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,714
bash
# How useful/difficult would it be for me to learn linux shell scripting? Alternative recommendations? I am in desperate need of some advice. I'm almost done with my junior year as a CS major. I sort of feel like a late comer because I didn't really get into computer science until sophomore year... Through hard work,...
Sounds like a fine plan. Some suggestions: 1. Learn to automate everything you can. Make it a habit. If you do something more than a couple times, put it in a script. It's not just to avoid typing but to document the process. Improve your scripts as you notice problems. Share your scripts when appropriate. 2. Learn th...
63508364
Azure DevOps reports PowerShell task as passed even with non-0 exit code
12
2020-08-20 15:26:48
<p>In Azure DevOps I have a task to run a PowerShell script. In certain scenarios, the script should exit with a non-0 code, causing the task to be reported as failed. However, Azure DevOps reports the task as passed regardless.</p> <p>This is a problem because I have a subsequent job that should run if this job fails,...
16,254
567,059
2022-09-22 11:52:52
63,516,324
12
2020-08-21 03:58:58
11,882,186
2020-08-21 03:58:58
https://stackoverflow.com/q/63508364
https://stackoverflow.com/a/63516324
<p>It seems that the Azure PowerShell task has an issue capturing the exit code from a script file, it works fine with the inline scripts. You can <a href="https://developercommunity.visualstudio.com/content/problem/post.html?space=21" rel="noreferrer">report this problem</a> to Microsoft development team. Hope they wi...
<p>It seems that the Azure PowerShell task has an issue capturing the exit code from a script file, it works fine with the inline scripts. You can <a href="https://developercommunity.visualstudio.com/content/problem/post.html?space=21" rel="noreferrer">report this problem</a> to Microsoft development team. Hope they wi...
526, 10001, 116537
azure-devops, powershell, task
<h1>Azure DevOps reports PowerShell task as passed even with non-0 exit code</h1> <p>In Azure DevOps I have a task to run a PowerShell script. In certain scenarios, the script should exit with a non-0 code, causing the task to be reported as failed. However, Azure DevOps reports the task as passed regardless.</p> <p>Th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,715
bash
# Azure DevOps reports PowerShell task as passed even with non-0 exit code In Azure DevOps I have a task to run a PowerShell script. In certain scenarios, the script should exit with a non-0 code, causing the task to be reported as failed. However, Azure DevOps reports the task as passed regardless. This is a problem...
It seems that the Azure PowerShell task has an issue capturing the exit code from a script file, it works fine with the inline scripts. You can [report this problem](https://developercommunity.visualstudio.com/content/problem/post.html?space=21) to Microsoft development team. Hope they will provide a fix soon. However...
62367579
Jshell in intellij doesn't allow generic types
12
2020-06-14 02:00:06
<p>I just started using jshell in intellij idea community version. When I write the below code in jshell, it works.</p> <pre><code>List&lt;String&gt; list = List.of("a", "b", "c"); System.out.println(list); </code></pre> <p>However the same code doesn't work in intellij. It says "Expression expected". It executes fin...
1,250
13,741,014
2020-06-14 11:38:37
62,367,608
12
2020-06-14 02:06:39
6,099,347
2020-06-14 02:06:39
https://stackoverflow.com/q/62367579
https://stackoverflow.com/a/62367608
<p>Not an IntelliJ IDEA expert but I get my way around by writing a anonymous class:</p> <pre><code>new Object() { void method() { List&lt;String&gt; list = List.of("a", "b", "c"); System.out.println(list); } }.method(); </code></pre>
<p>Not an IntelliJ IDEA expert but I get my way around by writing a anonymous class:</p> <pre><code>new Object() { void method() { List&lt;String&gt; list = List.of("a", "b", "c"); System.out.println(list); } }.method(); </code></pre>
17, 8945, 116030, 141882
intellij-idea, java, java-14, jshell
<h1>Jshell in intellij doesn't allow generic types</h1> <p>I just started using jshell in intellij idea community version. When I write the below code in jshell, it works.</p> <pre><code>List&lt;String&gt; list = List.of("a", "b", "c"); System.out.println(list); </code></pre> <p>However the same code doesn't work in ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,716
bash
# Jshell in intellij doesn't allow generic types I just started using jshell in intellij idea community version. When I write the below code in jshell, it works. ``` List<String> list = List.of("a", "b", "c"); System.out.println(list); ``` However the same code doesn't work in intellij. It says "Expression expected"...
Not an IntelliJ IDEA expert but I get my way around by writing a anonymous class: ``` new Object() { void method() { List<String> list = List.of("a", "b", "c"); System.out.println(list); } }.method(); ```
41096875
Programmatically change keyboard layout
12
2016-12-12 08:35:06
<p>I work in a Swiss company environment with <code>de-CH</code> as the standard keyboard layout, while using a <code>de-DE</code> keyboard.</p> <p>I'm able to change my keyboard settings manually to the preferred <code>de-DE</code>-layout, set it as standard and and assign a shortcut.</p> <p>However: somehow my settin...
37,431
5,979,902
2025-04-09 21:43:58
48,477,139
12
2018-01-27 15:10:52
9,276,816
2018-01-27 15:10:52
https://stackoverflow.com/q/41096875
https://stackoverflow.com/a/48477139
<p>Use this command</p> <pre><code>powershell -command "Set-WinUserLanguageList -Force 'en-US'" </code></pre> <p>or</p> <pre><code>powershell -command "Set-WinUserLanguageList -Force 'fr-FR'" </code></pre>
<p>Use this command</p> <pre><code>powershell -command "Set-WinUserLanguageList -Force 'en-US'" </code></pre> <p>or</p> <pre><code>powershell -command "Set-WinUserLanguageList -Force 'fr-FR'" </code></pre>
526
powershell
<h1>Programmatically change keyboard layout</h1> <p>I work in a Swiss company environment with <code>de-CH</code> as the standard keyboard layout, while using a <code>de-DE</code> keyboard.</p> <p>I'm able to change my keyboard settings manually to the preferred <code>de-DE</code>-layout, set it as standard and and ass...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,717
bash
# Programmatically change keyboard layout I work in a Swiss company environment with `de-CH` as the standard keyboard layout, while using a `de-DE` keyboard. I'm able to change my keyboard settings manually to the preferred `de-DE`-layout, set it as standard and and assign a shortcut. However: somehow my settings di...
Use this command ``` powershell -command "Set-WinUserLanguageList -Force 'en-US'" ``` or ``` powershell -command "Set-WinUserLanguageList -Force 'fr-FR'" ```
45086059
How can I reference UWP classes in PowerShell
12
2017-07-13 16:12:15
<p>I want to use a data type from a Universal Windows Platform library, how can I reference the containing namespace or assembly in PowerShell?</p> <p>For example, I want to use the <a href="https://learn.microsoft.com/en-us/uwp/api/Windows.Data.Json.JsonObject" rel="noreferrer"><code>Windows.Data.Json.JsonObject</cod...
2,783
712,649
2017-07-13 16:29:43
45,086,380
12
2017-07-13 16:29:43
712,649
2017-07-13 16:29:43
https://stackoverflow.com/q/45086059
https://stackoverflow.com/a/45086380
<p>Shortly after posting this question, I stumbled on <a href="https://github.com/Windos/BurntToast/blob/c0abfdac392ace8dd7c28bb0cd46842024aaaf30/BurntToast/Public/Submit-BTNotification.ps1" rel="noreferrer">the GitHub repo for BurntToast</a>, a module that allows raising UWP Toast Notifications from PowerShell, and it...
<p>Shortly after posting this question, I stumbled on <a href="https://github.com/Windos/BurntToast/blob/c0abfdac392ace8dd7c28bb0cd46842024aaaf30/BurntToast/Public/Submit-BTNotification.ps1" rel="noreferrer">the GitHub repo for BurntToast</a>, a module that allows raising UWP Toast Notifications from PowerShell, and it...
1, 64, 526, 113708
.net, powershell, uwp, windows
<h1>How can I reference UWP classes in PowerShell</h1> <p>I want to use a data type from a Universal Windows Platform library, how can I reference the containing namespace or assembly in PowerShell?</p> <p>For example, I want to use the <a href="https://learn.microsoft.com/en-us/uwp/api/Windows.Data.Json.JsonObject" r...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,718
bash
# How can I reference UWP classes in PowerShell I want to use a data type from a Universal Windows Platform library, how can I reference the containing namespace or assembly in PowerShell? For example, I want to use the [`Windows.Data.Json.JsonObject` class](https://learn.microsoft.com/en-us/uwp/api/Windows.Data.Json...
Shortly after posting this question, I stumbled on [the GitHub repo for BurntToast](https://github.com/Windos/BurntToast/blob/c0abfdac392ace8dd7c28bb0cd46842024aaaf30/BurntToast/Public/Submit-BTNotification.ps1), a module that allows raising UWP Toast Notifications from PowerShell, and it references the WinRT ToastNoti...
40332945
Deployment slot specific appsettin in ARM template?
12
2016-10-30 19:50:21
<p>I'm trying to get into that Visual Studio Resource Group template. So far it's looking good, and I have added some appsettings for a web app, but my question is, how can I make them deployment slot specific? Is there something in the json for the template or the parameter file?</p>
11,665
1,105,889
2023-12-27 14:59:49
40,342,821
12
2016-10-31 13:07:10
7,005,159
2016-11-03 01:39:21
https://stackoverflow.com/q/40332945
https://stackoverflow.com/a/40342821
<p>Please have a try to add the json code snipped in the ARM template. I have tested it. It works successfully.</p> <pre><code> "resources": [ { "apiVersion": "2015-08-01", "name": "appsettings", "type": "config", "dependsOn": [ "[resourceId('Microsoft.Web/Si...
<p>Please have a try to add the json code snipped in the ARM template. I have tested it. It works successfully.</p> <pre><code> "resources": [ { "apiVersion": "2015-08-01", "name": "appsettings", "type": "config", "dependsOn": [ "[resourceId('Microsoft.Web/Si...
81879, 108005, 108143, 115276, 119184
azure-deployment-slots, azure-powershell, azure-resource-group, azure-resource-manager, visual-studio-2015
<h1>Deployment slot specific appsettin in ARM template?</h1> <p>I'm trying to get into that Visual Studio Resource Group template. So far it's looking good, and I have added some appsettings for a web app, but my question is, how can I make them deployment slot specific? Is there something in the json for the template ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,719
bash
# Deployment slot specific appsettin in ARM template? I'm trying to get into that Visual Studio Resource Group template. So far it's looking good, and I have added some appsettings for a web app, but my question is, how can I make them deployment slot specific? Is there something in the json for the template or the pa...
Please have a try to add the json code snipped in the ARM template. I have tested it. It works successfully. ``` "resources": [ { "apiVersion": "2015-08-01", "name": "appsettings", "type": "config", "dependsOn": [ "[resourceId('Microsoft.Web/Sites/Slots', va...
38705320
Multiple commands within ScriptBlock
12
2016-08-01 18:02:31
<p>I'm having trouble running multiple commands within a Scriptblock parameter. All documentation points towards using a semicolon for separation between cmdlets. Using the same methodology of separating cmdlets via a semicolon works on my local machine, but not on a remote machine through invoke-command. </p> <p>F...
44,938
5,405,559
2022-11-14 01:46:24
38,705,532
12
2016-08-01 18:18:15
3,905,079
2022-11-14 01:46:24
https://stackoverflow.com/q/38705320
https://stackoverflow.com/a/38705532
<p>I am able to reproduce this.. it only returns the first statement. It's not the semicolon, it does the same thing if you use line breaks.</p> <p>These options work:</p> <pre><code>Invoke-Command -ComputerName computer -ScriptBlock { (Get-Service) Get-Process } </code></pre> <p>Or this curiously:</p> <pre><co...
<p>I am able to reproduce this.. it only returns the first statement. It's not the semicolon, it does the same thing if you use line breaks.</p> <p>These options work:</p> <pre><code>Invoke-Command -ComputerName computer -ScriptBlock { (Get-Service) Get-Process } </code></pre> <p>Or this curiously:</p> <pre><co...
526, 43391
invoke-command, powershell
<h1>Multiple commands within ScriptBlock</h1> <p>I'm having trouble running multiple commands within a Scriptblock parameter. All documentation points towards using a semicolon for separation between cmdlets. Using the same methodology of separating cmdlets via a semicolon works on my local machine, but not on a remo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,720
bash
# Multiple commands within ScriptBlock I'm having trouble running multiple commands within a Scriptblock parameter. All documentation points towards using a semicolon for separation between cmdlets. Using the same methodology of separating cmdlets via a semicolon works on my local machine, but not on a remote machine ...
I am able to reproduce this.. it only returns the first statement. It's not the semicolon, it does the same thing if you use line breaks. These options work: ``` Invoke-Command -ComputerName computer -ScriptBlock { (Get-Service) Get-Process } ``` Or this curiously: ``` Invoke-Command -ComputerName computer ...
38697974
How to append line to empty file using sed, but not echo?
12
2016-08-01 11:42:27
<p>I have the following problem: in a script, that must not be executed as root, I have to write a line to a newly created, empty file. This file is in /etc, so I need elevated privilages to write to it.</p> <p>Creating the file is simple:</p> <pre><code>sudo touch /etc/myfile </code></pre> <p>Now, just using echo t...
10,415
3,617,426
2020-08-26 19:27:01
38,698,093
12
2016-08-01 11:48:41
1,983,854
2016-08-01 11:54:04
https://stackoverflow.com/q/38697974
https://stackoverflow.com/a/38698093
<p>You can use <code>tee</code>:</p> <pre><code>echo "something" | sudo tee /etc/myfile # tee -a to append </code></pre> <p>Or redirect to <code>/dev/null</code> if you don't want to see the output:</p> <pre><code>echo "something" | sudo tee /etc/myfile &gt; /dev/null </code></pre> <p>Another option is to use <co...
<p>You can use <code>tee</code>:</p> <pre><code>echo "something" | sudo tee /etc/myfile # tee -a to append </code></pre> <p>Or redirect to <code>/dev/null</code> if you don't want to see the output:</p> <pre><code>echo "something" | sudo tee /etc/myfile &gt; /dev/null </code></pre> <p>Another option is to use <co...
387, 390, 1674, 5282, 13824
bash, echo, sed, shell, sudo
<h1>How to append line to empty file using sed, but not echo?</h1> <p>I have the following problem: in a script, that must not be executed as root, I have to write a line to a newly created, empty file. This file is in /etc, so I need elevated privilages to write to it.</p> <p>Creating the file is simple:</p> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,721
bash
# How to append line to empty file using sed, but not echo? I have the following problem: in a script, that must not be executed as root, I have to write a line to a newly created, empty file. This file is in /etc, so I need elevated privilages to write to it. Creating the file is simple: ``` sudo touch /etc/myfile ...
You can use `tee`: ``` echo "something" | sudo tee /etc/myfile # tee -a to append ``` Or redirect to `/dev/null` if you don't want to see the output: ``` echo "something" | sudo tee /etc/myfile > /dev/null ``` Another option is to use `sh -c` to perform the full command under sudo: ``` sudo sh -c 'echo "somethin...
37935415
Bash regex string variable match
12
2016-06-21 04:08:22
<p>I have the following script i wrote in perl that works just fine. But i am trying to achieve the same thing using bash.</p> <pre><code>#!/usr/bin/perl use 5.010; use strict; INIT { my $string = 'Seconds_Behind_Master: 1'; my ($s) = ($string =~ /Seconds_Behind_Master: ([\d]+)/); if ($s &gt; 10) { ...
48,634
2,105,790
2021-04-17 00:56:55
37,935,476
12
2016-06-21 04:13:42
48,382
2016-06-21 05:09:46
https://stackoverflow.com/q/37935415
https://stackoverflow.com/a/37935476
<p>You can use a tool for it e.g. <code>sed</code> if you want to stay with regexps:</p> <pre><code>#!/bin/sh string="Seconds_Behind_Master: 1" s=`echo $string | sed -r 's/Seconds_Behind_Master: ([0-9]+)/\1/g'` if [ $s -gt 10 ] then echo "Too long... $s" else echo "It's OK" fi </code></pre>
<p>You can use a tool for it e.g. <code>sed</code> if you want to stay with regexps:</p> <pre><code>#!/bin/sh string="Seconds_Behind_Master: 1" s=`echo $string | sed -r 's/Seconds_Behind_Master: ([0-9]+)/\1/g'` if [ $s -gt 10 ] then echo "Too long... $s" else echo "It's OK" fi </code></pre>
18, 387, 580
bash, perl, regex
<h1>Bash regex string variable match</h1> <p>I have the following script i wrote in perl that works just fine. But i am trying to achieve the same thing using bash.</p> <pre><code>#!/usr/bin/perl use 5.010; use strict; INIT { my $string = 'Seconds_Behind_Master: 1'; my ($s) = ($string =~ /Seconds_Behind_Maste...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,722
bash
# Bash regex string variable match I have the following script i wrote in perl that works just fine. But i am trying to achieve the same thing using bash. ``` #!/usr/bin/perl use 5.010; use strict; INIT { my $string = 'Seconds_Behind_Master: 1'; my ($s) = ($string =~ /Seconds_Behind_Master: ([\d]+)/); i...
You can use a tool for it e.g. `sed` if you want to stay with regexps: ``` #!/bin/sh string="Seconds_Behind_Master: 1" s=`echo $string | sed -r 's/Seconds_Behind_Master: ([0-9]+)/\1/g'` if [ $s -gt 10 ] then echo "Too long... $s" else echo "It's OK" fi ```
33460595
Fatal: bad numeric config value for 'core.sharedrepository' in .git/config : invalid unit (in Git Bash)
12
2015-11-01 08:58:03
<p>On performing :</p> <pre><code>$ git push -u origin --all </code></pre> <p>I got an error: </p> <pre><code>remote: error: insufficient permission for adding an object to repository database ./objects </code></pre> <p>I googled, and find out a solution by <a href="https://stackoverflow.com/questions/6448242/git-p...
5,748
4,357,799
2015-11-01 09:31:14
33,460,604
12
2015-11-01 08:59:00
6,309
2015-11-01 09:31:14
https://stackoverflow.com/q/33460595
https://stackoverflow.com/a/33460604
<blockquote> <p>I thought I have to enter name of group in the actual command</p> </blockquote> <p>No: <code>dev</code> is simply not a valid value for that setting.</p> <p>Try '<code>group</code>' only.</p> <pre><code>git config core.sharedRepository group </code></pre> <p>If you need to modify manually the conf...
<blockquote> <p>I thought I have to enter name of group in the actual command</p> </blockquote> <p>No: <code>dev</code> is simply not a valid value for that setting.</p> <p>Try '<code>group</code>' only.</p> <pre><code>git config core.sharedRepository group </code></pre> <p>If you need to modify manually the conf...
119, 3574, 61874
config, git, git-bash
<h1>Fatal: bad numeric config value for 'core.sharedrepository' in .git/config : invalid unit (in Git Bash)</h1> <p>On performing :</p> <pre><code>$ git push -u origin --all </code></pre> <p>I got an error: </p> <pre><code>remote: error: insufficient permission for adding an object to repository database ./objects <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,723
bash
# Fatal: bad numeric config value for 'core.sharedrepository' in .git/config : invalid unit (in Git Bash) On performing : ``` $ git push -u origin --all ``` I got an error: ``` remote: error: insufficient permission for adding an object to repository database ./objects ``` I googled, and find out a solution by [Ri...
> I thought I have to enter name of group in the actual command No: `dev` is simply not a valid value for that setting. Try '`group`' only. ``` git config core.sharedRepository group ``` If you need to modify manually the config, make sure to look for the `.git/config` file in your *local* cloned repo (not on the s...
30524456
PowerShell quotes for Start-Process ArgumentList
12
2015-05-29 08:11:20
<p>I'm trying to have the app <a href="http://www.eonet.ne.jp/%7Egakana/tablacus/explorer_en.html" rel="nofollow noreferrer">tablacus explorer</a> open a folder path. This works fine with the following formatting:</p> <pre><code>$exe = 'S:\Tools\explorer\TE64.exe' Start-Process $exe -ArgumentList '&quot;Tabs,Close othe...
21,622
2,304,170
2023-11-10 07:29:02
30,524,642
12
2015-05-29 08:21:28
2,304,170
2023-11-10 07:27:13
https://stackoverflow.com/q/30524456
https://stackoverflow.com/a/30524642
<p>I found two solutions for this on the <a href="https://social.technet.microsoft.com/Forums/en-US/455837c4-44a5-4359-b179-02f6b6f4d95b/using-double-quotes-within-a-string?forum=winserverpowershell" rel="nofollow noreferrer">MS Blog</a>:</p> <pre><code>$Args = @&quot; &quot;Tabs,Close other tabs&quot; &quot;Open,$dir&...
<p>I found two solutions for this on the <a href="https://social.technet.microsoft.com/Forums/en-US/455837c4-44a5-4359-b179-02f6b6f4d95b/using-double-quotes-within-a-string?forum=winserverpowershell" rel="nofollow noreferrer">MS Blog</a>:</p> <pre><code>$Args = @&quot; &quot;Tabs,Close other tabs&quot; &quot;Open,$dir&...
430, 526
powershell, quotes
<h1>PowerShell quotes for Start-Process ArgumentList</h1> <p>I'm trying to have the app <a href="http://www.eonet.ne.jp/%7Egakana/tablacus/explorer_en.html" rel="nofollow noreferrer">tablacus explorer</a> open a folder path. This works fine with the following formatting:</p> <pre><code>$exe = 'S:\Tools\explorer\TE64.ex...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,724
bash
# PowerShell quotes for Start-Process ArgumentList I'm trying to have the app [tablacus explorer](http://www.eonet.ne.jp/%7Egakana/tablacus/explorer_en.html) open a folder path. This works fine with the following formatting: ``` $exe = 'S:\Tools\explorer\TE64.exe' Start-Process $exe -ArgumentList '"Tabs,Close other t...
I found two solutions for this on the [MS Blog](https://social.technet.microsoft.com/Forums/en-US/455837c4-44a5-4359-b179-02f6b6f4d95b/using-double-quotes-within-a-string?forum=winserverpowershell): ``` $Args = @" "Tabs,Close other tabs" "Open,$dir" "@ Start-Process $exe -ArgumentList $Args ``` or ``` Start-Pro...
28204622
Possible to change tab completion behavior in fish shell?
12
2015-01-28 23:50:04
<p><strong>Update</strong>: <strong>This complaint relates to an old version of fish -- see the below comment from one of the fish developers describing the awesome improvements to the fish pager behavior which nullified this complaint.</strong></p> <p>The fish shell is pretty cool -- however I hate one of the feature...
6,072
2,619,765
2015-11-25 23:51:32
28,207,051
12
2015-01-29 04:32:25
1,441,328
2015-01-29 04:32:25
https://stackoverflow.com/q/28204622
https://stackoverflow.com/a/28207051
<p>I commend you for writing up this detailed and thoughtful post, and it deserves an equally detailed and thoughtful response!</p> <p>The tab completion behavior has been rewritten in fish top-of-tree (not yet released), and is referred to as the "new pager." You can see the design goals and discussion <a href="https...
<p>I commend you for writing up this detailed and thoughtful post, and it deserves an equally detailed and thoughtful response!</p> <p>The tab completion behavior has been rewritten in fish top-of-tree (not yet released), and is referred to as the "new pager." You can see the design goals and discussion <a href="https...
387, 390, 1177, 55824
bash, fish, shell, tabs
<h1>Possible to change tab completion behavior in fish shell?</h1> <p><strong>Update</strong>: <strong>This complaint relates to an old version of fish -- see the below comment from one of the fish developers describing the awesome improvements to the fish pager behavior which nullified this complaint.</strong></p> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,725
bash
# Possible to change tab completion behavior in fish shell? **Update**: **This complaint relates to an old version of fish -- see the below comment from one of the fish developers describing the awesome improvements to the fish pager behavior which nullified this complaint.** The fish shell is pretty cool -- however ...
I commend you for writing up this detailed and thoughtful post, and it deserves an equally detailed and thoughtful response! The tab completion behavior has been rewritten in fish top-of-tree (not yet released), and is referred to as the "new pager." You can see the design goals and discussion [here](https://github.co...
26187170
Difference between \n and \r in expect?
12
2014-10-03 21:37:33
<p>In this particular script they use <code>\n</code>.</p> <pre><code>#!/usr/bin/expect set password [lindex $argv 0] spawn asadmin enable-secure-admin expect "admin" send "admin\n" expect "password" send "$password\n" expect eof exit </code></pre> <p><strong>Question</strong></p> <p>Could <code>\r</code> just as ...
12,135
3,293,148
2014-10-03 21:59:19
26,187,389
12
2014-10-03 21:59:19
13,317
2014-10-03 21:59:19
https://stackoverflow.com/q/26187170
https://stackoverflow.com/a/26187389
<p><code>\n</code> is linefeed, Ctrl-J or character 012. <code>\r</code> is carriage return, Ctrl-M or character 015.</p> <p>In an interactive unix context, when you're typing them (or simulating typing them, as with expect), they are interchangeable. Linefeed is the formal line-terminator character, but tty devices n...
<p><code>\n</code> is linefeed, Ctrl-J or character 012. <code>\r</code> is carriage return, Ctrl-M or character 015.</p> <p>In an interactive unix context, when you're typing them (or simulating typing them, as with expect), they are interchangeable. Linefeed is the formal line-terminator character, but tty devices n...
58, 387, 9048
bash, expect, linux
<h1>Difference between \n and \r in expect?</h1> <p>In this particular script they use <code>\n</code>.</p> <pre><code>#!/usr/bin/expect set password [lindex $argv 0] spawn asadmin enable-secure-admin expect "admin" send "admin\n" expect "password" send "$password\n" expect eof exit </code></pre> <p><strong>Questio...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,726
bash
# Difference between \n and \r in expect? In this particular script they use `\n`. ``` #!/usr/bin/expect set password [lindex $argv 0] spawn asadmin enable-secure-admin expect "admin" send "admin\n" expect "password" send "$password\n" expect eof exit ``` **Question** Could `\r` just as well have been used? If no...
`\n` is linefeed, Ctrl-J or character 012. `\r` is carriage return, Ctrl-M or character 015. In an interactive unix context, when you're typing them (or simulating typing them, as with expect), they are interchangeable. Linefeed is the formal line-terminator character, but tty devices normally translate carriage retur...
24374784
Backslashes in Powershell
12
2014-06-23 20:29:26
<p>Why does the string for the -split parameter require two backslashes while the string for the -join parameter requires only one backslash? The backtick is the escape character in Powershell. What does a backslash preceding a character do for you?</p> <pre><code>$path = 'C:\folder\test\unit1\testing\results\report.t...
14,210
447,901
2014-06-24 01:56:27
24,374,828
12
2014-06-23 20:32:32
153,982
2014-06-24 01:56:27
https://stackoverflow.com/q/24374784
https://stackoverflow.com/a/24374828
<p><code>-split</code> splits on a regex by default. So it is the regex that requires escaping a backslash. You can tell PowerShell not to use a regex like so:</p> <pre><code>$path -split '\',-1,'SimpleMatch' </code></pre> <p><code>-join</code> is just taking whatever characters you supply to use as the delimiter to...
<p><code>-split</code> splits on a regex by default. So it is the regex that requires escaping a backslash. You can tell PowerShell not to use a regex like so:</p> <pre><code>$path -split '\',-1,'SimpleMatch' </code></pre> <p><code>-join</code> is just taking whatever characters you supply to use as the delimiter to...
64, 526, 10804
powershell, quoting, windows
<h1>Backslashes in Powershell</h1> <p>Why does the string for the -split parameter require two backslashes while the string for the -join parameter requires only one backslash? The backtick is the escape character in Powershell. What does a backslash preceding a character do for you?</p> <pre><code>$path = 'C:\folder\...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,727
bash
# Backslashes in Powershell Why does the string for the -split parameter require two backslashes while the string for the -join parameter requires only one backslash? The backtick is the escape character in Powershell. What does a backslash preceding a character do for you? ``` $path = 'C:\folder\test\unit1\testing\r...
`-split` splits on a regex by default. So it is the regex that requires escaping a backslash. You can tell PowerShell not to use a regex like so: ``` $path -split '\',-1,'SimpleMatch' ``` `-join` is just taking whatever characters you supply to use as the delimiter to stick between the strings being joined.
23424783
OSTYPE not available in shell script
12
2014-05-02 09:22:54
<p>Currently I'm setting up a new system using the new Xubuntu trusty tahr. I'm not very familiar with shell scripting, but I have one which needs the OSTYPE environment variable to determine what to do.</p> <p>If I call <code>echo $OSTYPE</code> in the xfce-terminal I get succesfully <code>linux-gnu</code>.</p> <p>I...
9,858
651,601
2019-05-14 07:08:49
23,425,163
12
2014-05-02 09:45:29
2,199,765
2017-03-23 12:02:39
https://stackoverflow.com/q/23424783
https://stackoverflow.com/a/23425163
<p>The <code>OSTYPE</code> environment variable is not recognized by the original Bourne shell, which is what is being invoked by the first line of your script. </p> <p>Replace it with:</p> <pre><code>#!/bin/bash </code></pre> <p>or</p> <pre><code>#!/bin/ksh </code></pre> <p>as appropriate to your setup.</p>
<p>The <code>OSTYPE</code> environment variable is not recognized by the original Bourne shell, which is what is being invoked by the first line of your script. </p> <p>Replace it with:</p> <pre><code>#!/bin/bash </code></pre> <p>or</p> <pre><code>#!/bin/ksh </code></pre> <p>as appropriate to your setup.</p>
58, 390, 9013, 10327, 103312
environment-variables, linux, sh, shell, ubuntu-14.04
<h1>OSTYPE not available in shell script</h1> <p>Currently I'm setting up a new system using the new Xubuntu trusty tahr. I'm not very familiar with shell scripting, but I have one which needs the OSTYPE environment variable to determine what to do.</p> <p>If I call <code>echo $OSTYPE</code> in the xfce-terminal I get...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,728
bash
# OSTYPE not available in shell script Currently I'm setting up a new system using the new Xubuntu trusty tahr. I'm not very familiar with shell scripting, but I have one which needs the OSTYPE environment variable to determine what to do. If I call `echo $OSTYPE` in the xfce-terminal I get succesfully `linux-gnu`. ...
The `OSTYPE` environment variable is not recognized by the original Bourne shell, which is what is being invoked by the first line of your script. Replace it with: ``` #!/bin/bash ``` or ``` #!/bin/ksh ``` as appropriate to your setup.
22863783
bash script - can't get for loop working
12
2014-04-04 13:08:57
<p><strong>Background Info:</strong></p> <p>I'm trying to follow the example posted here: <a href="http://www.cyberciti.biz/faq/bash-for-loop/" rel="noreferrer">http://www.cyberciti.biz/faq/bash-for-loop/</a> I would like loop 9 times using a control variable called "i". </p> <p><strong>Problem Description</strong><...
14,403
1,078,009
2016-04-22 23:18:06
22,863,926
12
2014-04-04 13:16:10
1,364,218
2016-04-22 23:18:06
https://stackoverflow.com/q/22863783
https://stackoverflow.com/a/22863926
<p>Ubuntu's default shell is <code>dash</code>, which doesn't recognise either of the bashisms (brace expansion, C-style for loop) you tried. Try running your script using <code>bash</code> explicitly:</p> <pre><code>bash myscript.sh </code></pre> <p>or by setting the shebang to <code>#!/bin/bash</code>. Make sure NO...
<p>Ubuntu's default shell is <code>dash</code>, which doesn't recognise either of the bashisms (brace expansion, C-style for loop) you tried. Try running your script using <code>bash</code> explicitly:</p> <pre><code>bash myscript.sh </code></pre> <p>or by setting the shebang to <code>#!/bin/bash</code>. Make sure NO...
58, 387, 2531
bash, for-loop, linux
<h1>bash script - can't get for loop working</h1> <p><strong>Background Info:</strong></p> <p>I'm trying to follow the example posted here: <a href="http://www.cyberciti.biz/faq/bash-for-loop/" rel="noreferrer">http://www.cyberciti.biz/faq/bash-for-loop/</a> I would like loop 9 times using a control variable called "...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,729
bash
# bash script - can't get for loop working **Background Info:** I'm trying to follow the example posted here: <http://www.cyberciti.biz/faq/bash-for-loop/> I would like loop 9 times using a control variable called "i". **Problem Description** My code looks like this: ``` for i in {0..8..1} do echo "i is $i" tm...
Ubuntu's default shell is `dash`, which doesn't recognise either of the bashisms (brace expansion, C-style for loop) you tried. Try running your script using `bash` explicitly: ``` bash myscript.sh ``` or by setting the shebang to `#!/bin/bash`. Make sure NOT to run the script with `sh myscript.sh`. dash should work...
22380733
How to write a text file with color
12
2014-03-13 13:52:31
<p>I'm trying to write a text file with two colors depending on the output. I using the <code>echo -e</code> command as I would when printing with colors in the console, like this:</p> <pre><code>RETURNED=$? if [ $RETURNED == 0 ] then echo -e "\e[1;32mffmpeg -t $DURACION -f x11grab -s $RESOLUCION -r ${FPS[j]}...
16,623
3,364,845
2020-06-11 15:37:20
22,382,293
12
2014-03-13 14:48:22
96,588
2014-03-13 22:16:11
https://stackoverflow.com/q/22380733
https://stackoverflow.com/a/22382293
<p>Have you tried <code>less -R file.txt</code>? That should show you the colour (works for me at least).</p> <p>If you want colour coding which is supported by non-shell applications your best bet is probably to output HTML, for example:</p> <pre><code>printf '&lt;code style="color: %s;"&gt;%s&lt;/code&gt;' "green" ...
<p>Have you tried <code>less -R file.txt</code>? That should show you the colour (works for me at least).</p> <p>If you want colour coding which is supported by non-shell applications your best bet is probably to output HTML, for example:</p> <pre><code>printf '&lt;code style="color: %s;"&gt;%s&lt;/code&gt;' "green" ...
387
bash
<h1>How to write a text file with color</h1> <p>I'm trying to write a text file with two colors depending on the output. I using the <code>echo -e</code> command as I would when printing with colors in the console, like this:</p> <pre><code>RETURNED=$? if [ $RETURNED == 0 ] then echo -e "\e[1;32mffmpeg -t $DU...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,730
bash
# How to write a text file with color I'm trying to write a text file with two colors depending on the output. I using the `echo -e` command as I would when printing with colors in the console, like this: ``` RETURNED=$? if [ $RETURNED == 0 ] then echo -e "\e[1;32mffmpeg -t $DURACION -f x11grab -s $RESOLUCIO...
Have you tried `less -R file.txt`? That should show you the colour (works for me at least). If you want colour coding which is supported by non-shell applications your best bet is probably to output HTML, for example: ``` printf '<code style="color: %s;">%s</code>' "green" "ffmpeg -t $DURACION -f x11grab -s $RESOLUCI...
20520303
Get Azure VM Detail by PowerShell
12
2013-12-11 13:21:53
<p>I am trying to run <code>Get-AzureVM</code> PowerShell command, it is running fine but not return any output. </p> <p>Also tried in following flavor but still blank result any idea?</p> <pre><code>Get-AzureVM -Name "vmname" |Select-Object name,instancesize,location </code></pre>
23,905
2,940,180
2017-02-07 13:48:21
20,521,167
12
2013-12-11 14:02:15
3,015,576
2015-03-17 02:25:45
https://stackoverflow.com/q/20520303
https://stackoverflow.com/a/20521167
<p>You should call <code>Select-AzureSubscription "subscription name"</code> first.</p> <p>It likely is defaulting to a subscription that doesn't have any virtual machines in it. </p> <p>To view your current subscription names call:</p> <pre><code>Get-AzureSubscription | select SubscriptionName </code></pre>
<p>You should call <code>Select-AzureSubscription "subscription name"</code> first.</p> <p>It likely is defaulting to a subscription that doesn't have any virtual machines in it. </p> <p>To view your current subscription names call:</p> <pre><code>Get-AzureSubscription | select SubscriptionName </code></pre>
526, 14158, 73157
azure, powershell, powershell-3.0
<h1>Get Azure VM Detail by PowerShell</h1> <p>I am trying to run <code>Get-AzureVM</code> PowerShell command, it is running fine but not return any output. </p> <p>Also tried in following flavor but still blank result any idea?</p> <pre><code>Get-AzureVM -Name "vmname" |Select-Object name,instancesize,location </code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,731
bash
# Get Azure VM Detail by PowerShell I am trying to run `Get-AzureVM` PowerShell command, it is running fine but not return any output. Also tried in following flavor but still blank result any idea? ``` Get-AzureVM -Name "vmname" |Select-Object name,instancesize,location ```
You should call `Select-AzureSubscription "subscription name"` first. It likely is defaulting to a subscription that doesn't have any virtual machines in it. To view your current subscription names call: ``` Get-AzureSubscription | select SubscriptionName ```
17272968
Escaping characters in variables inside sed expression
12
2013-06-24 10:12:17
<p>So im having an issue where this portion of my script is not working. I'm not sure exactly whats going on, but I get the feeling its because I have not escaped certain characters inside the variables. I tried the following with no luck:</p> <pre><code>crontab -l | sed "s%$CTMP%\*\/$FREQ \* \* \* \* cd $DIR &amp;&am...
18,124
2,272,450
2013-06-24 11:05:39
17,273,270
12
2013-06-24 10:28:06
1,258,041
2013-06-24 10:58:37
https://stackoverflow.com/q/17272968
https://stackoverflow.com/a/17273270
<p>Yes, the problem is likely that <code>$CTMP</code> contains asterisks, which are interpreted by <code>sed</code> as quantifiers. <code>.</code> is also a special character. Try escaping them:</p> <pre><code>CTMP_ESC=$(sed 's/[\*\.]/\\&amp;/g' &lt;&lt;&lt;"$CTMP") </code></pre> <p>and then use <code>CTMP_ESC</code>...
<p>Yes, the problem is likely that <code>$CTMP</code> contains asterisks, which are interpreted by <code>sed</code> as quantifiers. <code>.</code> is also a special character. Try escaping them:</p> <pre><code>CTMP_ESC=$(sed 's/[\*\.]/\\&amp;/g' &lt;&lt;&lt;"$CTMP") </code></pre> <p>and then use <code>CTMP_ESC</code>...
387, 5282
bash, sed
<h1>Escaping characters in variables inside sed expression</h1> <p>So im having an issue where this portion of my script is not working. I'm not sure exactly whats going on, but I get the feeling its because I have not escaped certain characters inside the variables. I tried the following with no luck:</p> <pre><code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,732
bash
# Escaping characters in variables inside sed expression So im having an issue where this portion of my script is not working. I'm not sure exactly whats going on, but I get the feeling its because I have not escaped certain characters inside the variables. I tried the following with no luck: ``` crontab -l | sed "s%...
Yes, the problem is likely that `$CTMP` contains asterisks, which are interpreted by `sed` as quantifiers. `.` is also a special character. Try escaping them: ``` CTMP_ESC=$(sed 's/[\*\.]/\\&/g' <<<"$CTMP") ``` and then use `CTMP_ESC` instead of `CTMP`. Also, you don't need to escape `/` in your `sed` command, becau...
14275224
Exit after trap fires
12
2013-01-11 09:35:03
<p>Take this script</p> <pre class="lang-sh prettyprint-override"><code>#!/bin/sh fd () { echo Hello world exit } trap fd EXIT INT for g in {1..5} do echo foo sleep 1 done </code></pre> <p>I would like <code>fd</code> to fire once, either from Control-C or if the script exits normally. However if you hit C...
1,468
1,002,260
2017-04-06 11:01:13
14,275,357
12
2013-01-11 09:42:41
874,188
2013-01-11 11:00:23
https://stackoverflow.com/q/14275224
https://stackoverflow.com/a/14275357
<p>Do cascading traps. <code>exit 127</code> will run the <code>EXIT</code> trap and set the exit code to 127, so you can say</p> <pre><code>#!/bin/sh fd () { echo Hello world # No explicit exit here! } trap fd EXIT trap 'exit 127' INT </code></pre> <p>I remember learning this from other people's scripts after ...
<p>Do cascading traps. <code>exit 127</code> will run the <code>EXIT</code> trap and set the exit code to 127, so you can say</p> <pre><code>#!/bin/sh fd () { echo Hello world # No explicit exit here! } trap fd EXIT trap 'exit 127' INT </code></pre> <p>I remember learning this from other people's scripts after ...
387, 124723
bash, shell-trap
<h1>Exit after trap fires</h1> <p>Take this script</p> <pre class="lang-sh prettyprint-override"><code>#!/bin/sh fd () { echo Hello world exit } trap fd EXIT INT for g in {1..5} do echo foo sleep 1 done </code></pre> <p>I would like <code>fd</code> to fire once, either from Control-C or if the script exits...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,733
bash
# Exit after trap fires Take this script ``` #!/bin/sh fd () { echo Hello world exit } trap fd EXIT INT for g in {1..5} do echo foo sleep 1 done ``` I would like `fd` to fire once, either from Control-C or if the script exits normally. However if you hit Control-C it will run twice. How can I fix this?
Do cascading traps. `exit 127` will run the `EXIT` trap and set the exit code to 127, so you can say ``` #!/bin/sh fd () { echo Hello world # No explicit exit here! } trap fd EXIT trap 'exit 127' INT ``` I remember learning this from other people's scripts after struggling with various workarounds to your probl...
13010420
Bash ignore error and get return code
12
2012-10-22 11:23:45
<p>I am using <code>set -e</code> to abort on errors. </p> <p>But for particular one function I want to ignore error and on error I want return code of the function. </p> <p>Example:</p> <pre><code>do_work || true if [ $? -ne 0 ] then echo "Error" fi </code></pre> <p>But it is not work return code is al...
9,278
428,705
2015-08-18 22:41:26
13,014,483
12
2012-10-22 15:17:26
89,817
2012-10-22 15:17:26
https://stackoverflow.com/q/13010420
https://stackoverflow.com/a/13014483
<pre><code>do_work || { status=$? echo "Error" } </code></pre>
<pre><code>do_work || { status=$? echo "Error" } </code></pre>
387
bash
<h1>Bash ignore error and get return code</h1> <p>I am using <code>set -e</code> to abort on errors. </p> <p>But for particular one function I want to ignore error and on error I want return code of the function. </p> <p>Example:</p> <pre><code>do_work || true if [ $? -ne 0 ] then echo "Error" fi </code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,734
bash
# Bash ignore error and get return code I am using `set -e` to abort on errors. But for particular one function I want to ignore error and on error I want return code of the function. Example: ``` do_work || true if [ $? -ne 0 ] then echo "Error" fi ``` But it is not work return code is always true due |...
``` do_work || { status=$? echo "Error" } ```
12060557
Solution to error 'find: missing argument to -exec' with find -exec cp {} TARGET_DIR +
12
2012-08-21 18:06:30
<p>I was getting ready to post this as a question, but after fiddling around with it a little longer, I found the solution. So I thought I would go ahead and post it here in case it helps someone else.</p> <p>I had trouble with find -exec cmd +. I got the error: </p> <pre><code>$ find ./ -name "*JIM*" -exec cp {} $...
8,962
1,303,577
2012-08-21 18:10:24
12,060,558
12
2012-08-21 18:06:30
1,303,577
2012-08-21 18:10:24
https://stackoverflow.com/q/12060557
https://stackoverflow.com/a/12060558
<p>As mentioned in the opening post, the solution I found is:</p> <pre><code>$ find ./ -name "*JIM*" -exec cp --target-directory=$TARGET_DIR {} + </code></pre> <p>Where <code>--target-directory=</code> could also be replaced with <code>-t</code></p>
<p>As mentioned in the opening post, the solution I found is:</p> <pre><code>$ find ./ -name "*JIM*" -exec cp --target-directory=$TARGET_DIR {} + </code></pre> <p>Where <code>--target-directory=</code> could also be replaced with <code>-t</code></p>
387, 2313, 7932, 10193, 25299
arguments, bash, cp, exec, find
<h1>Solution to error 'find: missing argument to -exec' with find -exec cp {} TARGET_DIR +</h1> <p>I was getting ready to post this as a question, but after fiddling around with it a little longer, I found the solution. So I thought I would go ahead and post it here in case it helps someone else.</p> <p>I had trouble...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,735
bash
# Solution to error 'find: missing argument to -exec' with find -exec cp {} TARGET_DIR + I was getting ready to post this as a question, but after fiddling around with it a little longer, I found the solution. So I thought I would go ahead and post it here in case it helps someone else. I had trouble with find -exec ...
As mentioned in the opening post, the solution I found is: ``` $ find ./ -name "*JIM*" -exec cp --target-directory=$TARGET_DIR {} + ``` Where `--target-directory=` could also be replaced with `-t`
11049748
How to cut multiple columns from several files and print the output to different files
12
2012-06-15 11:22:32
<p>I have several files and I only want to take specific columns from it. At the moment, I am using the following code:</p> <pre><code>$cut -f 1,2,5 AD0062-C.vcf &gt; cutAD0062.txt </code></pre> <p>However, to speed up the process I was wondering if I could cut the same columns (fields 1,2,5) in multiple files and th...
49,884
1,458,512
2017-12-13 05:03:43
11,049,831
12
2012-06-15 11:27:39
348,785
2012-06-15 11:27:39
https://stackoverflow.com/q/11049748
https://stackoverflow.com/a/11049831
<p>You can write a for...loop:</p> <pre><code>for i in AD*-C.vcf do cut -f 1,2,5 $i &gt; cut${i%-C.vcf}.txt done </code></pre>
<p>You can write a for...loop:</p> <pre><code>for i in AD*-C.vcf do cut -f 1,2,5 $i &gt; cut${i%-C.vcf}.txt done </code></pre>
34, 58, 390, 4257
cut, linux, shell, unix
<h1>How to cut multiple columns from several files and print the output to different files</h1> <p>I have several files and I only want to take specific columns from it. At the moment, I am using the following code:</p> <pre><code>$cut -f 1,2,5 AD0062-C.vcf &gt; cutAD0062.txt </code></pre> <p>However, to speed up the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,736
bash
# How to cut multiple columns from several files and print the output to different files I have several files and I only want to take specific columns from it. At the moment, I am using the following code: ``` $cut -f 1,2,5 AD0062-C.vcf > cutAD0062.txt ``` However, to speed up the process I was wondering if I could ...
You can write a for...loop: ``` for i in AD*-C.vcf do cut -f 1,2,5 $i > cut${i%-C.vcf}.txt done ```
9529791
set multiple variables from one awk command?
12
2012-03-02 07:52:06
<p>This is a very common script:</p> <pre><code>#!/bin/bash teststr="col1 col2" var1=`echo ${teststr} | awk '{print $1}'` var2=`echo ${teststr} | awk '{print $2}'` echo var1=${var1} echo var2=${var2} </code></pre> <p>However I dont like this, especially when there are more fields to parse. I guess there should be...
29,679
393,414
2023-09-28 13:36:46
9,529,999
12
2012-03-02 08:10:39
967,492
2023-09-28 13:36:46
https://stackoverflow.com/q/9529791
https://stackoverflow.com/a/9529999
<p>This might work for you:</p> <pre><code>var=(col0 col1 col2) echo &quot;${var[1]}&quot; </code></pre> <p>Will output:</p> <pre><code>col1 </code></pre>
<p>This might work for you:</p> <pre><code>var=(col0 col1 col2) echo &quot;${var[1]}&quot; </code></pre> <p>Will output:</p> <pre><code>col1 </code></pre>
387, 990
awk, bash
<h1>set multiple variables from one awk command?</h1> <p>This is a very common script:</p> <pre><code>#!/bin/bash teststr="col1 col2" var1=`echo ${teststr} | awk '{print $1}'` var2=`echo ${teststr} | awk '{print $2}'` echo var1=${var1} echo var2=${var2} </code></pre> <p>However I dont like this, especially when th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,737
bash
# set multiple variables from one awk command? This is a very common script: ``` #!/bin/bash teststr="col1 col2" var1=`echo ${teststr} | awk '{print $1}'` var2=`echo ${teststr} | awk '{print $2}'` echo var1=${var1} echo var2=${var2} ``` However I dont like this, especially when there are more fields to parse. I g...
This might work for you: ``` var=(col0 col1 col2) echo "${var[1]}" ``` Will output: ``` col1 ```
9458752
Variable for number of lines in a file
12
2012-02-27 00:41:29
<p>I'm trying to put the number of lines in a file into an integer variable.</p> <p>This is how i'm doing it</p> <pre><code>typeset -i x x=`wc -l $1` </code></pre> <p>where $1 is the command line arg</p> <p>The problem is that wc -l gives a number and the filename like: 5 blah</p> <p>Is there a way to only put the...
25,692
1,056,858
2018-04-23 15:17:28
9,458,764
12
2012-02-27 00:44:41
129,570
2012-02-27 00:44:41
https://stackoverflow.com/q/9458752
https://stackoverflow.com/a/9458764
<p>You could do <code>cat $1 | wc -l</code> instead.</p> <p>Or <code>wc -l $1 | cut -d " " -f 1</code>.</p>
<p>You could do <code>cat $1 | wc -l</code> instead.</p> <p>Or <code>wc -l $1 | cut -d " " -f 1</code>.</p>
34, 387
bash, unix
<h1>Variable for number of lines in a file</h1> <p>I'm trying to put the number of lines in a file into an integer variable.</p> <p>This is how i'm doing it</p> <pre><code>typeset -i x x=`wc -l $1` </code></pre> <p>where $1 is the command line arg</p> <p>The problem is that wc -l gives a number and the filename lik...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,738
bash
# Variable for number of lines in a file I'm trying to put the number of lines in a file into an integer variable. This is how i'm doing it ``` typeset -i x x=`wc -l $1` ``` where $1 is the command line arg The problem is that wc -l gives a number and the filename like: 5 blah Is there a way to only put the numbe...
You could do `cat $1 | wc -l` instead. Or `wc -l $1 | cut -d " " -f 1`.
9044661
Are shell aliases POSIX compliant?
12
2012-01-28 10:45:43
<p>I am writing a utility which lets you set shell aliases persistently.</p> <p>I have it in my head that unix shell aliases are POSIX compliant, but I can't remember where I heard this and my google fu has not yielded any definitive answer.</p> <p>Most of my experience is with zsh and bash.</p> <p>Is it safe to ass...
1,820
133,414
2012-01-28 10:54:15
9,044,709
12
2012-01-28 10:54:15
635,608
2012-01-28 10:54:15
https://stackoverflow.com/q/9044661
https://stackoverflow.com/a/9044709
<p><a href="http://pubs.opengroup.org/onlinepubs/007904975/utilities/alias.html" rel="noreferrer"><code>alias</code></a> (and <code>unalias</code>) are indeed in POSIX.</p> <p>See also <a href="http://pubs.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_03_01" rel="noreferrer">alias substitution</...
<p><a href="http://pubs.opengroup.org/onlinepubs/007904975/utilities/alias.html" rel="noreferrer"><code>alias</code></a> (and <code>unalias</code>) are indeed in POSIX.</p> <p>See also <a href="http://pubs.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_03_01" rel="noreferrer">alias substitution</...
390, 1448, 1993
alias, posix, shell
<h1>Are shell aliases POSIX compliant?</h1> <p>I am writing a utility which lets you set shell aliases persistently.</p> <p>I have it in my head that unix shell aliases are POSIX compliant, but I can't remember where I heard this and my google fu has not yielded any definitive answer.</p> <p>Most of my experience is ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,739
bash
# Are shell aliases POSIX compliant? I am writing a utility which lets you set shell aliases persistently. I have it in my head that unix shell aliases are POSIX compliant, but I can't remember where I heard this and my google fu has not yielded any definitive answer. Most of my experience is with zsh and bash. Is ...
[`alias`](http://pubs.opengroup.org/onlinepubs/007904975/utilities/alias.html) (and `unalias`) are indeed in POSIX. See also [alias substitution](http://pubs.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_03_01) and [alias names](http://pubs.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap03.h...
6870362
Can I create a script with parameter that has [alias("db")] in Powershell?
12
2011-07-29 08:13:13
<p>If I define the following</p> <pre><code>[parameter(Mandatory = $true)] [alias("db")] [string]$database, </code></pre> <p>then I get an error</p> <pre><code>Parameter alias cannot be specified because an alias with the name 'db' was defined multiple times for the command. </code></pre> <p>Which is true, since <c...
9,218
39,068
2022-10-27 13:36:12
6,874,332
12
2011-07-29 14:01:38
22,211
2022-10-27 13:36:12
https://stackoverflow.com/q/6870362
https://stackoverflow.com/a/6874332
<p>Sorry, you can't. <code>-Debug</code> is a common parameter, so <code>-Debug</code> and <code>-db</code> are switches that are available on pretty much everything including the functions you write yourself. As the error tells you, it's already defined.</p> <p>Even if it were possible to go around undefining built-in...
<p>Sorry, you can't. <code>-Debug</code> is a common parameter, so <code>-Debug</code> and <code>-db</code> are switches that are available on pretty much everything including the functions you write yourself. As the error tells you, it's already defined.</p> <p>Even if it were possible to go around undefining built-in...
526
powershell
<h1>Can I create a script with parameter that has [alias("db")] in Powershell?</h1> <p>If I define the following</p> <pre><code>[parameter(Mandatory = $true)] [alias("db")] [string]$database, </code></pre> <p>then I get an error</p> <pre><code>Parameter alias cannot be specified because an alias with the name 'db' w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,740
bash
# Can I create a script with parameter that has [alias("db")] in Powershell? If I define the following ``` [parameter(Mandatory = $true)] [alias("db")] [string]$database, ``` then I get an error ``` Parameter alias cannot be specified because an alias with the name 'db' was defined multiple times for the command. `...
Sorry, you can't. `-Debug` is a common parameter, so `-Debug` and `-db` are switches that are available on pretty much everything including the functions you write yourself. As the error tells you, it's already defined. Even if it were possible to go around undefining built-in aliases, that unexpectantly changes the m...
3321738
Shell Scripting: Using xargs to execute parallel instances of a shell function
12
2010-07-23 19:33:42
<p>I'm trying to use xargs in a shell script to run parallel instances of a function I've defined in the same script. The function times the fetching of a page, and so it's important that the pages are actually fetched concurrently in parallel processes, and not in background processes (if my understanding of this is w...
11,317
385,123
2010-07-24 15:21:53
3,322,993
12
2010-07-23 23:03:19
26,428
2010-07-23 23:03:19
https://stackoverflow.com/q/3321738
https://stackoverflow.com/a/3322993
<p>Here's a demo of how you might be able to get your function to work:</p> <pre><code>$ f() { echo "[$@]"; } $ export -f f $ echo -e "b 1\nc 2\nd 3 4" | xargs -P 0 -n 1 -I{} bash -c f\ \{\} [b 1] [d 3 4] [c 2] </code></pre> <p>The keys to making this work are to <code>export</code> the function so the <code>bash</co...
<p>Here's a demo of how you might be able to get your function to work:</p> <pre><code>$ f() { echo "[$@]"; } $ export -f f $ echo -e "b 1\nc 2\nd 3 4" | xargs -P 0 -n 1 -I{} bash -c f\ \{\} [b 1] [d 3 4] [c 2] </code></pre> <p>The keys to making this work are to <code>export</code> the function so the <code>bash</co...
387, 390, 10326
bash, shell, xargs
<h1>Shell Scripting: Using xargs to execute parallel instances of a shell function</h1> <p>I'm trying to use xargs in a shell script to run parallel instances of a function I've defined in the same script. The function times the fetching of a page, and so it's important that the pages are actually fetched concurrently ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,741
bash
# Shell Scripting: Using xargs to execute parallel instances of a shell function I'm trying to use xargs in a shell script to run parallel instances of a function I've defined in the same script. The function times the fetching of a page, and so it's important that the pages are actually fetched concurrently in parall...
Here's a demo of how you might be able to get your function to work: ``` $ f() { echo "[$@]"; } $ export -f f $ echo -e "b 1\nc 2\nd 3 4" | xargs -P 0 -n 1 -I{} bash -c f\ \{\} [b 1] [d 3 4] [c 2] ``` The keys to making this work are to `export` the function so the `bash` that `xargs` spawns will see it and to escape...
451713
How to learn your way through Linux's shell
12
2009-01-16 19:50:10
<p><strong>I want to stop losing precious time when dealing with Linux/Unix's shell.</strong></p> <p>If I could get to understand it well, that would be great. Otherwise:</p> <ul> <li>I may end up losing a day just for setting up a crontab.</li> <li>I'll keep wondering why the shebang in <em>this</em> script doesn't ...
4,104
25,167
2011-03-16 00:38:50
451,791
12
2009-01-16 20:11:13
28,804
2009-01-16 20:11:13
https://stackoverflow.com/q/451713
https://stackoverflow.com/a/451791
<p>Man pages are probably the "ultimate" solution. I'm always amazed at what gems they contain.</p> <p>You can even use <code>man bash</code> to answer some of the questions you raise in this question.</p>
<p>Man pages are probably the "ultimate" solution. I'm always amazed at what gems they contain.</p> <p>You can even use <code>man bash</code> to answer some of the questions you raise in this question.</p>
34, 58, 387, 390
bash, linux, shell, unix
<h1>How to learn your way through Linux's shell</h1> <p><strong>I want to stop losing precious time when dealing with Linux/Unix's shell.</strong></p> <p>If I could get to understand it well, that would be great. Otherwise:</p> <ul> <li>I may end up losing a day just for setting up a crontab.</li> <li>I'll keep wonde...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,742
bash
# How to learn your way through Linux's shell **I want to stop losing precious time when dealing with Linux/Unix's shell.** If I could get to understand it well, that would be great. Otherwise: - I may end up losing a day just for setting up a crontab. - I'll keep wondering why the shebang in *this* script doesn't w...
Man pages are probably the "ultimate" solution. I'm always amazed at what gems they contain. You can even use `man bash` to answer some of the questions you raise in this question.
68136128
How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping?
11
2021-06-25 19:16:49
<p>This self-answered question aims to give a <strong>systematic overview of the PowerShell CLI (command-line interface)</strong>, both for <em>Windows PowerShell</em> (<code>powershell.exe</code>) and <a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="noreferrer"><em>PowerShell (Core) v6+</e...
1,727
45,375
2021-06-27 19:23:13
68,136,129
12
2021-06-25 19:16:49
45,375
2021-06-27 19:23:13
https://stackoverflow.com/q/68136128
https://stackoverflow.com/a/68136129
<h3>PowerShell CLI fundamentals:</h3> <ul> <li><p><strong>PowerShell editions</strong>: The CLI of the legacy, bundled-with-Windows <em><strong>Windows PowerShell</strong></em> edition is <strong><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe" rel="nor...
<h3>PowerShell CLI fundamentals:</h3> <ul> <li><p><strong>PowerShell editions</strong>: The CLI of the legacy, bundled-with-Windows <em><strong>Windows PowerShell</strong></em> edition is <strong><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe" rel="nor...
526, 10804, 11225, 12658, 26698
character-encoding, command-line-interface, io-redirection, powershell, quoting
<h1>How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping?</h1> <p>This self-answered question aims to give a <strong>systematic overview of the PowerShell CLI (command-line interface)</strong>, both for <em>Windows PowerShell</em> (<code>powershel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,743
bash
# How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping? This self-answered question aims to give a **systematic overview of the PowerShell CLI (command-line interface)**, both for *Windows PowerShell* (`powershell.exe`) and [*PowerShell (Core) v6...
### PowerShell CLI fundamentals: - **PowerShell editions**: The CLI of the legacy, bundled-with-Windows ***Windows PowerShell*** edition is **[`powershell.exe`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe)**, whereas that of the cross-platform, install-on-de...
48148664
The Term '-Execution Policy' is not recognized
11
2018-01-08 10:44:50
<p>I would like to run such a statement in powershell:</p> <pre><code>-ExecutionPolicy Bypass -File install-sshd.ps1 </code></pre> <p>But I get this error message:</p> <blockquote> <p>-ExecutionPolicy : The term '-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable progra...
68,246
2,107,488
2022-07-02 07:51:37
48,160,516
12
2018-01-09 02:04:22
9,132,707
2018-01-09 02:04:22
https://stackoverflow.com/q/48148664
https://stackoverflow.com/a/48160516
<p>As for.. . "Sorry, I am really new in PowerShel world. What is typo? – Kaja"</p> <p>Please watch this series <a href="https://www.youtube.com/results?search_query=beginning+powershell" rel="noreferrer">https://www.youtube.com/results?search_query=beginning+powershell</a></p> <p>If you are in the cmd prompt or any...
<p>As for.. . "Sorry, I am really new in PowerShel world. What is typo? – Kaja"</p> <p>Please watch this series <a href="https://www.youtube.com/results?search_query=beginning+powershell" rel="noreferrer">https://www.youtube.com/results?search_query=beginning+powershell</a></p> <p>If you are in the cmd prompt or any...
526
powershell
<h1>The Term '-Execution Policy' is not recognized</h1> <p>I would like to run such a statement in powershell:</p> <pre><code>-ExecutionPolicy Bypass -File install-sshd.ps1 </code></pre> <p>But I get this error message:</p> <blockquote> <p>-ExecutionPolicy : The term '-ExecutionPolicy' is not recognized as the nam...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,744
bash
# The Term '-Execution Policy' is not recognized I would like to run such a statement in powershell: ``` -ExecutionPolicy Bypass -File install-sshd.ps1 ``` But I get this error message: > -ExecutionPolicy : The term '-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable pro...
As for.. . "Sorry, I am really new in PowerShel world. What is typo? – Kaja" Please watch this series <https://www.youtube.com/results?search_query=beginning+powershell> If you are in the cmd prompt or any other cmd terminal, you do this.. ``` powershell.exe -ExecutionPolicy Bypass "D:\Scripts\Script.ps1" ``` If yo...
47304329
Error "syntax error near unexpected token '('" in Bash script when selecting files
11
2017-11-15 09:59:33
<p>Running this script, <code>bash ./cleanup.bash</code>,</p> <pre><code>#!/bin/bash ## Going to directory-moving stuff rm -rf !(composer.json|.git) </code></pre> <p>Gives the error:</p> <blockquote> <p>cleanup.bash: line 10: syntax error near unexpected token '(' cleanup.bash: line 10: 'rm -rf !(composer.json|.git)'</...
12,372
933,065
2021-11-27 13:51:53
47,305,041
12
2017-11-15 10:31:38
5,291,015
2021-11-27 13:45:37
https://stackoverflow.com/q/47304329
https://stackoverflow.com/a/47305041
<p>I guess your problem is due to the shell extended glob option not set when run from the script. When you claim it works in the command line, you have somehow set the <code>extglob</code> flag which allow to <code>!()</code> globs.</p> <p>Since the Bash script, whenever started with a <code>#!/bin/bash</code>, starts...
<p>I guess your problem is due to the shell extended glob option not set when run from the script. When you claim it works in the command line, you have somehow set the <code>extglob</code> flag which allow to <code>!()</code> globs.</p> <p>Since the Bash script, whenever started with a <code>#!/bin/bash</code>, starts...
58, 387, 391
bash, linux, terminal
<h1>Error "syntax error near unexpected token '('" in Bash script when selecting files</h1> <p>Running this script, <code>bash ./cleanup.bash</code>,</p> <pre><code>#!/bin/bash ## Going to directory-moving stuff rm -rf !(composer.json|.git) </code></pre> <p>Gives the error:</p> <blockquote> <p>cleanup.bash: line 10: sy...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,745
bash
# Error "syntax error near unexpected token '('" in Bash script when selecting files Running this script, `bash ./cleanup.bash`, ``` #!/bin/bash ## Going to directory-moving stuff rm -rf !(composer.json|.git) ``` Gives the error: > cleanup.bash: line 10: syntax error near unexpected token '(' > cleanup.bash: line 1...
I guess your problem is due to the shell extended glob option not set when run from the script. When you claim it works in the command line, you have somehow set the `extglob` flag which allow to `!()` globs. Since the Bash script, whenever started with a `#!/bin/bash`, starts a new sub-shell, the extended options set...
46452001
Task Scheduler - get history information into script variables
11
2017-09-27 15:39:01
<p>Is there a way of getting the task scheduler history information into an array or variable inside a batch or PowerShell script.</p> <p>For example, get the information such as task name, date and time when the task started (event ID: 100 ) and when it completed (event ID: 102). This is so I can update a SQL databa...
11,225
4,555,823
2017-09-27 17:38:07
46,454,037
12
2017-09-27 17:38:07
712,649
2017-09-27 17:38:07
https://stackoverflow.com/q/46452001
https://stackoverflow.com/a/46454037
<p>The Task Scheduler logs to the following event channel:<br> <code>Microsoft-Windows-TaskScheduler/Operational</code></p> <p>You can use <code>Get-WinEvent</code> to gather the events. Start out by defining a filter hash table for the id <code>100</code> start events</p> <pre><code># Event filter for the initial qu...
<p>The Task Scheduler logs to the following event channel:<br> <code>Microsoft-Windows-TaskScheduler/Operational</code></p> <p>You can use <code>Get-WinEvent</code> to gather the events. Start out by defining a filter hash table for the id <code>100</code> start events</p> <pre><code># Event filter for the initial qu...
526, 7002, 115698
batch-file, powershell, taskscheduler
<h1>Task Scheduler - get history information into script variables</h1> <p>Is there a way of getting the task scheduler history information into an array or variable inside a batch or PowerShell script.</p> <p>For example, get the information such as task name, date and time when the task started (event ID: 100 ) and ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,746
bash
# Task Scheduler - get history information into script variables Is there a way of getting the task scheduler history information into an array or variable inside a batch or PowerShell script. For example, get the information such as task name, date and time when the task started (event ID: 100 ) and when it complete...
The Task Scheduler logs to the following event channel: `Microsoft-Windows-TaskScheduler/Operational` You can use `Get-WinEvent` to gather the events. Start out by defining a filter hash table for the id `100` start events ``` # Event filter for the initial query for all "Start" events in the last 24 hours $EventFi...
42211173
bash script to run a constant number of jobs in the background
11
2017-02-13 18:39:23
<p>I need a bash script to run some jobs in the background, three jobs at a time.</p> <p>I know can do this in the following way, and for illustration, I will assume the number of jobs is 6:</p> <pre><code>./j1 &amp; ./j2 &amp; ./j3 &amp; wait ./j4 &amp; ./j5 &amp; ./j6 &amp; wait </code></pre> <p>However, this way,...
6,901
7,226,097
2025-06-16 06:39:58
42,211,360
12
2017-02-13 18:50:31
14,122
2017-08-25 22:02:28
https://stackoverflow.com/q/42211173
https://stackoverflow.com/a/42211360
<p>With GNU xargs:</p> <pre><code>printf '%s\0' j{1..6} | xargs -0 -n1 -P3 sh -c './"$1"' _ </code></pre> <hr> <p>With bash (4.x) builtins:</p> <pre><code>max_jobs=3; cur_jobs=0 for ((i=0; i&lt;6; i++)); do # If true, wait until the next background job finishes to continue. ((cur_jobs &gt;= max_jobs)) &amp;&amp...
<p>With GNU xargs:</p> <pre><code>printf '%s\0' j{1..6} | xargs -0 -n1 -P3 sh -c './"$1"' _ </code></pre> <hr> <p>With bash (4.x) builtins:</p> <pre><code>max_jobs=3; cur_jobs=0 for ((i=0; i&lt;6; i++)); do # If true, wait until the next background job finishes to continue. ((cur_jobs &gt;= max_jobs)) &amp;&amp...
58, 387, 390
bash, linux, shell
<h1>bash script to run a constant number of jobs in the background</h1> <p>I need a bash script to run some jobs in the background, three jobs at a time.</p> <p>I know can do this in the following way, and for illustration, I will assume the number of jobs is 6:</p> <pre><code>./j1 &amp; ./j2 &amp; ./j3 &amp; wait ./...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,747
bash
# bash script to run a constant number of jobs in the background I need a bash script to run some jobs in the background, three jobs at a time. I know can do this in the following way, and for illustration, I will assume the number of jobs is 6: ``` ./j1 & ./j2 & ./j3 & wait ./j4 & ./j5 & ./j6 & wait ``` However, t...
With GNU xargs: ``` printf '%s\0' j{1..6} | xargs -0 -n1 -P3 sh -c './"$1"' _ ``` --- With bash (4.x) builtins: ``` max_jobs=3; cur_jobs=0 for ((i=0; i<6; i++)); do # If true, wait until the next background job finishes to continue. ((cur_jobs >= max_jobs)) && wait -n # Increment the current number of jobs ru...
39583092
What does "cat > somefilename <<EOF" (particularly, the greater-than and double less-than symbols) do in shell?
11
2016-09-19 22:35:47
<p>Just came across the following command:</p> <pre><code>cat &gt; myspider.py &lt;&lt;EOF </code></pre> <p>But I'm not sure of the use of <code>&gt;</code> and <code>&lt;&lt;</code>.</p>
8,076
4,238,076
2024-06-14 09:34:42
39,583,120
12
2016-09-19 22:38:29
14,122
2023-12-15 16:05:24
https://stackoverflow.com/q/39583092
https://stackoverflow.com/a/39583120
<p><code>&lt;&lt;EOF</code> is the start of a heredoc. Content after this line and prior to the next line containing only <code>EOF</code> is fed on stdin to the process <code>cat</code>.</p> <p><code>&gt; myspider.py</code> is a stdout redirection. <code>myspider.py</code> will be truncated if it already exists (and i...
<p><code>&lt;&lt;EOF</code> is the start of a heredoc. Content after this line and prior to the next line containing only <code>EOF</code> is fed on stdin to the process <code>cat</code>.</p> <p><code>&gt; myspider.py</code> is a stdout redirection. <code>myspider.py</code> will be truncated if it already exists (and i...
387, 390
bash, shell
<h1>What does "cat > somefilename <<EOF" (particularly, the greater-than and double less-than symbols) do in shell?</h1> <p>Just came across the following command:</p> <pre><code>cat &gt; myspider.py &lt;&lt;EOF </code></pre> <p>But I'm not sure of the use of <code>&gt;</code> and <code>&lt;&lt;</code>.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,748
bash
# What does "cat > somefilename < Just came across the following command: ``` cat > myspider.py <<EOF ``` But I'm not sure of the use of `>` and `<<`.
`<<EOF` is the start of a heredoc. Content after this line and prior to the next line containing only `EOF` is fed on stdin to the process `cat`. `> myspider.py` is a stdout redirection. `myspider.py` will be truncated if it already exists (and is a regular file), and output of `cat` will be written into it. Since `c...
39443913
Passing a command with arguments as a string to docker run
11
2016-09-12 05:36:11
<p>The issue I'm facing is how to pass a command with arguments to <code>docker run</code>. The problem is that <code>docker run</code> does not take command plus arguments as a single string. They need to be provided as individual first-class arguments to <code>docker run</code>, such as:</p> <pre><code>#!/bin/bash d...
22,039
143,397
2016-09-13 01:25:24
39,460,934
12
2016-09-13 01:25:24
147,356
2016-09-13 01:25:24
https://stackoverflow.com/q/39443913
https://stackoverflow.com/a/39460934
<p>Start with the syntax of the <code>docker run</code> command, which is:</p> <pre><code>docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] </code></pre> <p>This means if you run:</p> <pre><code>DOCKER_COMMAND='bash -c "(cd build &amp;&amp; make)"' docker run --rm -it myImage "$DOCKER_COMMAND" </code></pre...
<p>Start with the syntax of the <code>docker run</code> command, which is:</p> <pre><code>docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] </code></pre> <p>This means if you run:</p> <pre><code>DOCKER_COMMAND='bash -c "(cd build &amp;&amp; make)"' docker run --rm -it myImage "$DOCKER_COMMAND" </code></pre...
58, 387, 390, 19749, 90304
bash, docker, linux, shell, variable-expansion
<h1>Passing a command with arguments as a string to docker run</h1> <p>The issue I'm facing is how to pass a command with arguments to <code>docker run</code>. The problem is that <code>docker run</code> does not take command plus arguments as a single string. They need to be provided as individual first-class argument...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,749
bash
# Passing a command with arguments as a string to docker run The issue I'm facing is how to pass a command with arguments to `docker run`. The problem is that `docker run` does not take command plus arguments as a single string. They need to be provided as individual first-class arguments to `docker run`, such as: ``...
Start with the syntax of the `docker run` command, which is: ``` docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] ``` This means if you run: ``` DOCKER_COMMAND='bash -c "(cd build && make)"' docker run --rm -it myImage "$DOCKER_COMMAND" ``` You are passing the entirety of the `$DOCKER_COMMAND` variable a...
36442572
How to make RETURN trap in bash preserve the return code?
11
2016-04-06 05:50:36
<p>Below is the simplified scheme of the script I am writing. The program must take parameters in different ways, so there is a fine division to several functions.</p> <p>The problem is that the chainloading of the return value from deeper functions breaks on the trap, where the result is to be checked to show a messag...
6,882
685,107
2025-05-04 16:42:53
36,442,661
12
2016-04-06 05:56:34
685,107
2016-04-06 06:10:43
https://stackoverflow.com/q/36442572
https://stackoverflow.com/a/36442661
<p>Funny enough,</p> <pre><code>trap "return_trap; trap - RETURN" RETURN </code></pre> <p>simply works.</p> <pre><code>[ ! -v MANUAL ] &amp;&amp; { check_params; retval2=$? [ $retval2 -eq 0 ] \ &amp;&amp; echo "check_params() returned with 0. Not running manual setup." \ || false }|| ask_for_...
<p>Funny enough,</p> <pre><code>trap "return_trap; trap - RETURN" RETURN </code></pre> <p>simply works.</p> <pre><code>[ ! -v MANUAL ] &amp;&amp; { check_params; retval2=$? [ $retval2 -eq 0 ] \ &amp;&amp; echo "check_params() returned with 0. Not running manual setup." \ || false }|| ask_for_...
58, 387, 124485
bash, bash-trap, linux
<h1>How to make RETURN trap in bash preserve the return code?</h1> <p>Below is the simplified scheme of the script I am writing. The program must take parameters in different ways, so there is a fine division to several functions.</p> <p>The problem is that the chainloading of the return value from deeper functions bre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,750
bash
# How to make RETURN trap in bash preserve the return code? Below is the simplified scheme of the script I am writing. The program must take parameters in different ways, so there is a fine division to several functions. The problem is that the chainloading of the return value from deeper functions breaks on the trap...
Funny enough, ``` trap "return_trap; trap - RETURN" RETURN ``` simply works. ``` [ ! -v MANUAL ] && { check_params; retval2=$? [ $retval2 -eq 0 ] \ && echo "check_params() returned with 0. Not running manual setup." \ || false }|| ask_for_params ``` And here’s the trace. ``` + check_a_param...
35308981
Add double quotes to variable to escape space
11
2016-02-10 07:14:24
<p>I am running a script which has $FileName variable containing the absolute path with spaces. Due to the space within the directory name and file name, the script fails to executes without finding the actual path. All I need is to add $FilePath within double quotes. How should I append double quotes in the beginning ...
36,552
3,331,975
2019-02-15 13:56:26
35,309,729
12
2016-02-10 08:04:59
712,649
2016-02-10 08:04:59
https://stackoverflow.com/q/35308981
https://stackoverflow.com/a/35309729
<p>In addition to the backtick escape character (<code>`</code>), you can use the <code>-f</code> format operator:</p> <pre><code>$FilePath = Join-Path $Dir -ChildPath "$File.txt" $FilePathWithQuotes = '"{0}"' -f $FilePath </code></pre> <p>This will ensure that <code>$FilePath</code> is expanded before being placed i...
<p>In addition to the backtick escape character (<code>`</code>), you can use the <code>-f</code> format operator:</p> <pre><code>$FilePath = Join-Path $Dir -ChildPath "$File.txt" $FilePathWithQuotes = '"{0}"' -f $FilePath </code></pre> <p>This will ensure that <code>$FilePath</code> is expanded before being placed i...
526
powershell
<h1>Add double quotes to variable to escape space</h1> <p>I am running a script which has $FileName variable containing the absolute path with spaces. Due to the space within the directory name and file name, the script fails to executes without finding the actual path. All I need is to add $FilePath within double quot...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,751
bash
# Add double quotes to variable to escape space I am running a script which has $FileName variable containing the absolute path with spaces. Due to the space within the directory name and file name, the script fails to executes without finding the actual path. All I need is to add $FilePath within double quotes. How s...
In addition to the backtick escape character (`` ` ``), you can use the `-f` format operator: ``` $FilePath = Join-Path $Dir -ChildPath "$File.txt" $FilePathWithQuotes = '"{0}"' -f $FilePath ``` This will ensure that `$FilePath` is expanded before being placed in the string
34166077
Multi-line variables remove new line character - Fish
11
2015-12-08 21:11:00
<p>When I set any multiline text as a variable in fish, it removes the new line characters and replaces them with space, how can I stop it from doing that? Minimal complete example:</p> <pre><code>~ ) set lines (cat .lorem); set start 2; set end 4; ~ ) cat .lorem once upon a midnight dreary while i pondered weak and w...
4,893
3,657,151
2024-08-13 04:14:52
34,186,172
12
2015-12-09 18:19:05
1,441,328
2015-12-09 18:19:05
https://stackoverflow.com/q/34166077
https://stackoverflow.com/a/34186172
<p>fish splits command substitutions on newlines. This means that <code>$lines</code> is a list. You can read more <a href="http://fishshell.com/docs/current/tutorial.html#tut_lists" rel="noreferrer">about lists here</a>.</p> <p>When you pass a list to a command, each entry in the list becomes a separate argument. <co...
<p>fish splits command substitutions on newlines. This means that <code>$lines</code> is a list. You can read more <a href="http://fishshell.com/docs/current/tutorial.html#tut_lists" rel="noreferrer">about lists here</a>.</p> <p>When you pass a list to a command, each entry in the list becomes a separate argument. <co...
390, 55824
fish, shell
<h1>Multi-line variables remove new line character - Fish</h1> <p>When I set any multiline text as a variable in fish, it removes the new line characters and replaces them with space, how can I stop it from doing that? Minimal complete example:</p> <pre><code>~ ) set lines (cat .lorem); set start 2; set end 4; ~ ) cat ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,752
bash
# Multi-line variables remove new line character - Fish When I set any multiline text as a variable in fish, it removes the new line characters and replaces them with space, how can I stop it from doing that? Minimal complete example: ``` ~ ) set lines (cat .lorem); set start 2; set end 4; ~ ) cat .lorem once upon a...
fish splits command substitutions on newlines. This means that `$lines` is a list. You can read more [about lists here](http://fishshell.com/docs/current/tutorial.html#tut_lists). When you pass a list to a command, each entry in the list becomes a separate argument. `echo` space-separates its arguments. That explains ...
34008223
Check if directory exists on remote machine with ssh
11
2015-11-30 21:21:48
<p>This question has been already posted but I would like to know if there is a way to know if a directory exists on a remote machine with ssh BUT from the command line directly and not from a script. As I saw in this previous post: <a href="https://stackoverflow.com/questions/15927911/how-to-check-if-dir-exist-over-ss...
13,279
5,577,751
2019-08-15 20:17:06
34,020,570
12
2015-12-01 12:34:29
3,744,681
2015-12-01 12:34:29
https://stackoverflow.com/q/34008223
https://stackoverflow.com/a/34020570
<p>This is a one liner:</p> <pre><code>ssh armand@127.0.0.1 '[ -d Documents ] &amp;&amp; echo exists || echo does not exist' </code></pre>
<p>This is a one liner:</p> <pre><code>ssh armand@127.0.0.1 '[ -d Documents ] &amp;&amp; echo exists || echo does not exist' </code></pre>
386, 387
bash, ssh
<h1>Check if directory exists on remote machine with ssh</h1> <p>This question has been already posted but I would like to know if there is a way to know if a directory exists on a remote machine with ssh BUT from the command line directly and not from a script. As I saw in this previous post: <a href="https://stackove...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,753
bash
# Check if directory exists on remote machine with ssh This question has been already posted but I would like to know if there is a way to know if a directory exists on a remote machine with ssh BUT from the command line directly and not from a script. As I saw in this previous post: [How to check if dir exists over s...
This is a one liner: ``` ssh armand@127.0.0.1 '[ -d Documents ] && echo exists || echo does not exist' ```
32774889
How to round-trip this JSON to PSObject and back in Powershell
11
2015-09-25 04:37:39
<p>Powershell can't seem to correctly round-trip this JSON object:</p> <pre><code>{ "settings": { "minimumApproverCount": 2, "creatorVoteCounts": false, "scope": [ { "refName": "refs/heads/d14rel", "matchKind": "Exact", "repository...
2,405
46,926
2015-09-25 04:59:14
32,775,099
12
2015-09-25 04:59:14
323,582
2015-09-25 04:59:14
https://stackoverflow.com/q/32774889
https://stackoverflow.com/a/32775099
<p>Use the parameter <code>Depth</code> with value 3 or larger. The default 2 is not enough, deeper data are simply converted to strings.</p> <pre><code>$json | ConvertFrom-Json | ConvertTo-Json -Depth 3 </code></pre> <p>Output</p> <pre><code>{ "settings": { "minimumApproverCount": 2, ...
<p>Use the parameter <code>Depth</code> with value 3 or larger. The default 2 is not enough, deeper data are simply converted to strings.</p> <pre><code>$json | ConvertFrom-Json | ConvertTo-Json -Depth 3 </code></pre> <p>Output</p> <pre><code>{ "settings": { "minimumApproverCount": 2, ...
526, 1508
json, powershell
<h1>How to round-trip this JSON to PSObject and back in Powershell</h1> <p>Powershell can't seem to correctly round-trip this JSON object:</p> <pre><code>{ "settings": { "minimumApproverCount": 2, "creatorVoteCounts": false, "scope": [ { "refName": "refs/heads/d1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,754
bash
# How to round-trip this JSON to PSObject and back in Powershell Powershell can't seem to correctly round-trip this JSON object: ``` { "settings": { "minimumApproverCount": 2, "creatorVoteCounts": false, "scope": [ { "refName": "refs/heads/d14rel", ...
Use the parameter `Depth` with value 3 or larger. The default 2 is not enough, deeper data are simply converted to strings. ``` $json | ConvertFrom-Json | ConvertTo-Json -Depth 3 ``` Output ``` { "settings": { "minimumApproverCount": 2, "creatorVoteCounts": false, ...
28534621
Remove Files older than 3 years
11
2015-02-16 04:40:10
<p>I need to remove any file in the directory that is older than 2 years old. It is very important that I keep the newest files and delete the old files. </p> <p>I have searched and found this. </p> <pre><code>find /path/to/files* -mtime +365 -exec rm {} \; </code></pre> <p>Can I just multiply the number?</p> <pr...
29,557
4,529,428
2016-09-01 09:34:20
28,534,707
12
2015-02-16 04:48:37
2,970,947
2015-02-16 04:48:37
https://stackoverflow.com/q/28534621
https://stackoverflow.com/a/28534707
<blockquote> <p>Can I just multiply the number?</p> <pre><code>find /path/to/files -mtime +1095 -exec rm {} \; </code></pre> </blockquote> <p>Yes. And to &quot;echo&quot; before you remove</p> <pre><code>find /path/to/files -mtime +1095 -print </code></pre> <p>Then the version with <code>-exec rm {} \;</code> to remove...
<blockquote> <p>Can I just multiply the number?</p> <pre><code>find /path/to/files -mtime +1095 -exec rm {} \; </code></pre> </blockquote> <p>Yes. And to &quot;echo&quot; before you remove</p> <pre><code>find /path/to/files -mtime +1095 -print </code></pre> <p>Then the version with <code>-exec rm {} \;</code> to remove...
58, 387, 37510
bash, delete-file, linux
<h1>Remove Files older than 3 years</h1> <p>I need to remove any file in the directory that is older than 2 years old. It is very important that I keep the newest files and delete the old files. </p> <p>I have searched and found this. </p> <pre><code>find /path/to/files* -mtime +365 -exec rm {} \; </code></pre> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,755
bash
# Remove Files older than 3 years I need to remove any file in the directory that is older than 2 years old. It is very important that I keep the newest files and delete the old files. I have searched and found this. ``` find /path/to/files* -mtime +365 -exec rm {} \; ``` Can I just multiply the number? ``` find /...
> Can I just multiply the number? > > ``` > find /path/to/files -mtime +1095 -exec rm {} \; > ``` Yes. And to "echo" before you remove ``` find /path/to/files -mtime +1095 -print ``` Then the version with `-exec rm {} \;` to remove the files (when you are ready).
27904943
Popen.communicate() returns (None, None) even if script print results
11
2015-01-12 15:03:44
<p>I have problem with Popen.communicate().</p> <p>I have script which return string. </p> <p>Then I have wrote second script which takes that variable.</p> <pre><code>v = "./myscript arg1 arg2" com = subprocess.Popen(v, shell=True).communicate() print com </code></pre> <p>com returns (None, None). The point is tha...
8,156
2,084,386
2018-10-29 10:30:28
27,904,973
12
2015-01-12 15:05:13
1,222,951
2018-10-29 10:30:28
https://stackoverflow.com/q/27904943
https://stackoverflow.com/a/27904973
<p>From the <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate" rel="nofollow noreferrer">docs</a>:</p> <blockquote> <p>Note that if you want to send data to the process’s stdin, you need to create the <code>Popen</code> object with <code>stdin=PIPE</code>. Similarly, to get anyt...
<p>From the <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate" rel="nofollow noreferrer">docs</a>:</p> <blockquote> <p>Note that if you want to send data to the process’s stdin, you need to create the <code>Popen</code> object with <code>stdin=PIPE</code>. Similarly, to get anyt...
16, 390
python, shell
<h1>Popen.communicate() returns (None, None) even if script print results</h1> <p>I have problem with Popen.communicate().</p> <p>I have script which return string. </p> <p>Then I have wrote second script which takes that variable.</p> <pre><code>v = "./myscript arg1 arg2" com = subprocess.Popen(v, shell=True).commu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,756
bash
# Popen.communicate() returns (None, None) even if script print results I have problem with Popen.communicate(). I have script which return string. Then I have wrote second script which takes that variable. ``` v = "./myscript arg1 arg2" com = subprocess.Popen(v, shell=True).communicate() print com ``` com returns...
From the [docs](https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate): > Note that if you want to send data to the process’s stdin, you need to create the `Popen` object with `stdin=PIPE`. Similarly, to get anything other than `None` in the result tuple, you need to give `stdout=PIPE` and/or ...
27577478
What does the semicolon do when it is run in a bash command?
11
2014-12-20 05:56:57
<p>For example, when running</p> <pre><code>echo a; echo b </code></pre> <p>in the terminal, its output is:</p> <pre><code>a b </code></pre> <p>It seems to me that the semicolon waits for the first command (<code>echo a</code>) to finish, then it starts the second command (<code>echo b</code>).</p> <p><strong>Q:</...
14,417
null
2014-12-20 06:13:25
27,577,487
12
2014-12-20 05:58:45
3,150,943
2014-12-20 06:13:25
https://stackoverflow.com/q/27577478
https://stackoverflow.com/a/27577487
<p>The <code>;</code> separates the two commands.</p> <pre><code>echo a; echo b </code></pre> <p>It lets the bash know that <code>echo a</code> and <code>echo b</code> are two separate commands and need to be run separately one after the other</p> <p>Try without semicolons</p> <pre><code>$ echo a echo b a echo b <...
<p>The <code>;</code> separates the two commands.</p> <pre><code>echo a; echo b </code></pre> <p>It lets the bash know that <code>echo a</code> and <code>echo b</code> are two separate commands and need to be run separately one after the other</p> <p>Try without semicolons</p> <pre><code>$ echo a echo b a echo b <...
387, 391, 4072
bash, gnu, terminal
<h1>What does the semicolon do when it is run in a bash command?</h1> <p>For example, when running</p> <pre><code>echo a; echo b </code></pre> <p>in the terminal, its output is:</p> <pre><code>a b </code></pre> <p>It seems to me that the semicolon waits for the first command (<code>echo a</code>) to finish, then it...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,757
bash
# What does the semicolon do when it is run in a bash command? For example, when running ``` echo a; echo b ``` in the terminal, its output is: ``` a b ``` It seems to me that the semicolon waits for the first command (`echo a`) to finish, then it starts the second command (`echo b`). **Q:** Is the semicolon just...
The `;` separates the two commands. ``` echo a; echo b ``` It lets the bash know that `echo a` and `echo b` are two separate commands and need to be run separately one after the other Try without semicolons ``` $ echo a echo b a echo b ``` Here the statement is taken as a single command `echo` and `a echo b` is pa...
10496758
'Unexpected end of file' and 'error importing function definition' error running shellscript using qsub
11
2012-05-08 10:21:50
<p>I have the following shellscript:</p> <pre><code>#!/bin/sh cd /sw/local/bin/ export LD_LIBRARY_PATH=/sw/local/lib:/usr/local/Trolltech/Qt-4.7.2/lib:$LD_LIBRARY_PATH ./FeatureFinderRaw -in /homes/JG-C1-18.mzML -out /homes/test_remove_after_use.featureXML -threads 20 </code></pre> <p>It works fine when I run it from...
29,685
651,779
2022-06-06 08:10:00
27,130,671
12
2014-11-25 15:30:14
442,359
2014-11-25 15:30:14
https://stackoverflow.com/q/10496758
https://stackoverflow.com/a/27130671
<p>Also have this problem in a wrapper script that uses </p> <pre><code>qsub -shell no -b yes -cwd -V somescript.bash arg1 arg2 etc </code></pre> <p>if you use it to submit another bash shell script. It produces the annonying </p> <pre><code>/bin/sh: module: line 1: syntax error: unexpected end of file /bin/sh: erro...
<p>Also have this problem in a wrapper script that uses </p> <pre><code>qsub -shell no -b yes -cwd -V somescript.bash arg1 arg2 etc </code></pre> <p>if you use it to submit another bash shell script. It produces the annonying </p> <pre><code>/bin/sh: module: line 1: syntax error: unexpected end of file /bin/sh: erro...
58, 390, 9228, 26217
cluster-computing, linux, qsub, shell
<h1>'Unexpected end of file' and 'error importing function definition' error running shellscript using qsub</h1> <p>I have the following shellscript:</p> <pre><code>#!/bin/sh cd /sw/local/bin/ export LD_LIBRARY_PATH=/sw/local/lib:/usr/local/Trolltech/Qt-4.7.2/lib:$LD_LIBRARY_PATH ./FeatureFinderRaw -in /homes/JG-C1-18...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,758
bash
# 'Unexpected end of file' and 'error importing function definition' error running shellscript using qsub I have the following shellscript: ``` #!/bin/sh cd /sw/local/bin/ export LD_LIBRARY_PATH=/sw/local/lib:/usr/local/Trolltech/Qt-4.7.2/lib:$LD_LIBRARY_PATH ./FeatureFinderRaw -in /homes/JG-C1-18.mzML -out /homes/te...
Also have this problem in a wrapper script that uses ``` qsub -shell no -b yes -cwd -V somescript.bash arg1 arg2 etc ``` if you use it to submit another bash shell script. It produces the annonying ``` /bin/sh: module: line 1: syntax error: unexpected end of file /bin/sh: error importing function definition for `BAS...
26298979
configure command not found cygwin
11
2014-10-10 12:01:24
<p>This question has been asked many time but I am not able to resolve the problem from them so I am asking</p> <p>I had installed Cygwin a few days ago.I tried using <code>./configure</code> command but it says</p> <blockquote> <p>-bash: ./configure: No such file or directory</p> </blockquote> <p>I tried using</p...
31,121
null
2023-04-23 01:50:27
26,299,319
12
2014-10-10 12:19:17
60,281
2014-10-10 12:24:23
https://stackoverflow.com/q/26298979
https://stackoverflow.com/a/26299319
<p>If a software project is set up to be built using <a href="http://www.gnu.org/software/autoconf/" rel="noreferrer">autoconf</a>, that tool generates a script canonically called <code>configure</code>. It queries the system for various parameters that are subsequently used in the build, and is <em>specific to the sof...
<p>If a software project is set up to be built using <a href="http://www.gnu.org/software/autoconf/" rel="noreferrer">autoconf</a>, that tool generates a script canonically called <code>configure</code>. It queries the system for various parameters that are subsequently used in the build, and is <em>specific to the sof...
387, 1731
bash, cygwin
<h1>configure command not found cygwin</h1> <p>This question has been asked many time but I am not able to resolve the problem from them so I am asking</p> <p>I had installed Cygwin a few days ago.I tried using <code>./configure</code> command but it says</p> <blockquote> <p>-bash: ./configure: No such file or dire...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,759
bash
# configure command not found cygwin This question has been asked many time but I am not able to resolve the problem from them so I am asking I had installed Cygwin a few days ago.I tried using `./configure` command but it says > -bash: ./configure: No such file or directory I tried using ``` where configure ``` ...
If a software project is set up to be built using [autoconf](http://www.gnu.org/software/autoconf/), that tool generates a script canonically called `configure`. It queries the system for various parameters that are subsequently used in the build, and is *specific to the software package to be built*. Different softwar...
23369917
Cleaner way to write multiple sed commands?
11
2014-04-29 16:11:19
<p>Is there a more DRY way to write the following commands (will be putting them in a bash shell script):</p> <pre><code>sudo sed -i 's/^#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed -i 's/^#PermitEmptyPasswords yes...
2,946
3,188,544
2016-08-22 17:25:53
23,370,005
12
2014-04-29 16:15:53
2,235,132
2014-04-29 16:26:11
https://stackoverflow.com/q/23369917
https://stackoverflow.com/a/23370005
<p>Since the patterns to be matched are similar, you could make use of alternation for the 4 strings and capture it. Make the <code>#</code> at the beginning of the string optional.</p> <p>The following would combine those into one:</p> <pre><code>sed -i -r 's/^#?(PermitRootLogin|PermitEmptyPasswords|PasswordAuthent...
<p>Since the patterns to be matched are similar, you could make use of alternation for the 4 strings and capture it. Make the <code>#</code> at the beginning of the string optional.</p> <p>The following would combine those into one:</p> <pre><code>sed -i -r 's/^#?(PermitRootLogin|PermitEmptyPasswords|PasswordAuthent...
58, 387, 390, 549, 5282
bash, linux, sed, shell, ubuntu
<h1>Cleaner way to write multiple sed commands?</h1> <p>Is there a more DRY way to write the following commands (will be putting them in a bash shell script):</p> <pre><code>sudo sed -i 's/^#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,760
bash
# Cleaner way to write multiple sed commands? Is there a more DRY way to write the following commands (will be putting them in a bash shell script): ``` sudo sed -i 's/^#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed...
Since the patterns to be matched are similar, you could make use of alternation for the 4 strings and capture it. Make the `#` at the beginning of the string optional. The following would combine those into one: ``` sed -i -r 's/^#?(PermitRootLogin|PermitEmptyPasswords|PasswordAuthentication|X11Forwarding) yes/\1 no/...
20769621
Saving the result of a MongoDB query
11
2013-12-25 06:12:16
<p>When doing a research in mongo shell I often write quite complex queries and want the result to be stored in other collection. I know the way to do it with <code>.forEach()</code>:</p> <p><code>db.documents.find(query).forEach(function(d){db.results.insert(d)})</code></p> <p>But it's kind of tedious to write that ...
23,132
1,085,375
2017-01-10 09:25:51
20,770,564
12
2013-12-25 08:12:04
1,085,375
2017-01-10 09:25:51
https://stackoverflow.com/q/20769621
https://stackoverflow.com/a/20770564
<p>Here's a solution I'll use: <code>db.results.insert(db.docs.find(...).toArray())</code></p> <p>There is still too much noise, though.</p> <p><em>UPD</em>: There is also an option to rewrite <code>find</code> using aggregation pipeline. Then you can use <a href="https://docs.mongodb.com/v3.2/reference/operator/aggr...
<p>Here's a solution I'll use: <code>db.results.insert(db.docs.find(...).toArray())</code></p> <p>There is still too much noise, though.</p> <p><em>UPD</em>: There is also an option to rewrite <code>find</code> using aggregation pipeline. Then you can use <a href="https://docs.mongodb.com/v3.2/reference/operator/aggr...
30073, 69521
mongodb, mongo-shell
<h1>Saving the result of a MongoDB query</h1> <p>When doing a research in mongo shell I often write quite complex queries and want the result to be stored in other collection. I know the way to do it with <code>.forEach()</code>:</p> <p><code>db.documents.find(query).forEach(function(d){db.results.insert(d)})</code></...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,761
bash
# Saving the result of a MongoDB query When doing a research in mongo shell I often write quite complex queries and want the result to be stored in other collection. I know the way to do it with `.forEach()`: `db.documents.find(query).forEach(function(d){db.results.insert(d)})` But it's kind of tedious to write that...
Here's a solution I'll use: `db.results.insert(db.docs.find(...).toArray())` There is still too much noise, though. *UPD*: There is also an option to rewrite `find` using aggregation pipeline. Then you can use [`$out` operator](https://docs.mongodb.com/v3.2/reference/operator/aggregation/out/).
20445398
Use Backup-SqlDatabase cmdlet with SQL Server Authentication
11
2013-12-07 19:11:11
<p>Is there a way to call Backup-SqlDatabase cmdlet but have it connect to SQL Server 2012 with SQL Server credentials? </p> <p>The command I am currently using is:</p> <pre><code>Backup-SqlDatabase -ServerInstance $serverName -Database $sqldbname -BackupFile "$($backupFolder)$($dbname)_db_$($addinionToName).bak" </c...
25,361
645,460
2013-12-09 20:50:29
20,480,506
12
2013-12-09 20:50:29
135,965
2013-12-09 20:50:29
https://stackoverflow.com/q/20445398
https://stackoverflow.com/a/20480506
<p>The backup-sqldatabase cmdlet supports the Credential parameter. If you look at the help for the cmdlet there's even an example (from help backup-sqldatabase -full):</p> <pre><code> -------------------------- EXAMPLE 4 -------------------------- C:\PS&gt;Backup-SqlDatabase -ServerInstance Computer\Instance -Datab...
<p>The backup-sqldatabase cmdlet supports the Credential parameter. If you look at the help for the cmdlet there's even an example (from help backup-sqldatabase -full):</p> <pre><code> -------------------------- EXAMPLE 4 -------------------------- C:\PS&gt;Backup-SqlDatabase -ServerInstance Computer\Instance -Datab...
526, 74269, 98685
backup-sqldatabase, powershell, sql-server-2012
<h1>Use Backup-SqlDatabase cmdlet with SQL Server Authentication</h1> <p>Is there a way to call Backup-SqlDatabase cmdlet but have it connect to SQL Server 2012 with SQL Server credentials? </p> <p>The command I am currently using is:</p> <pre><code>Backup-SqlDatabase -ServerInstance $serverName -Database $sqldbname ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,762
bash
# Use Backup-SqlDatabase cmdlet with SQL Server Authentication Is there a way to call Backup-SqlDatabase cmdlet but have it connect to SQL Server 2012 with SQL Server credentials? The command I am currently using is: ``` Backup-SqlDatabase -ServerInstance $serverName -Database $sqldbname -BackupFile "$($backupFolder...
The backup-sqldatabase cmdlet supports the Credential parameter. If you look at the help for the cmdlet there's even an example (from help backup-sqldatabase -full): ``` -------------------------- EXAMPLE 4 -------------------------- C:\PS>Backup-SqlDatabase -ServerInstance Computer\Instance -Database MyDB -Credent...
17847390
How to resume stopped job on a remote machine given pid?
11
2013-07-25 01:15:42
<p>I have a process on a machine which I stopped (with a Ctrl-Z). After ssh'ing onto the machine, how do I resume the process?</p>
12,855
807,037
2013-07-25 03:14:13
17,847,912
12
2013-07-25 02:15:35
41,861
2013-07-25 02:15:35
https://stackoverflow.com/q/17847390
https://stackoverflow.com/a/17847912
<p>You will need to find the PID and then issue <code>kill -CONT &lt;pid&gt;</code>.</p> <p>You can find the PID by using <code>ps</code> with some options to produce extended output. Stopped jobs have a <code>T</code> in the <code>STAT</code> (or <code>S</code>) column.</p> <p>If you succeed in continuing the proce...
<p>You will need to find the PID and then issue <code>kill -CONT &lt;pid&gt;</code>.</p> <p>You can find the PID by using <code>ps</code> with some options to produce extended output. Stopped jobs have a <code>T</code> in the <code>STAT</code> (or <code>S</code>) column.</p> <p>If you succeed in continuing the proce...
58, 390
linux, shell
<h1>How to resume stopped job on a remote machine given pid?</h1> <p>I have a process on a machine which I stopped (with a Ctrl-Z). After ssh'ing onto the machine, how do I resume the process?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,763
bash
# How to resume stopped job on a remote machine given pid? I have a process on a machine which I stopped (with a Ctrl-Z). After ssh'ing onto the machine, how do I resume the process?
You will need to find the PID and then issue `kill -CONT <pid>`. You can find the PID by using `ps` with some options to produce extended output. Stopped jobs have a `T` in the `STAT` (or `S`) column. If you succeed in continuing the process but it no longer has a controlling terminal (and it needs one) then it could...
11131389
Having a optional parameter that requires another parameter to be present
11
2012-06-21 04:13:17
<p>Quite simply, how do I initialize the <code>params</code> part of my Powershell Script so I can have a command line arguments like</p> <pre><code>Get-Foo [-foo1] &lt;foo1Arg&gt; [-foo2 &lt;foo2Arg&gt; [-bar &lt;barArg&gt;]] </code></pre> <p>So the only time I can use <code>-bar</code> is when <code>foo2</code> has...
15,113
80,274
2016-12-31 21:55:15
16,058,329
12
2013-04-17 11:04:11
2,290,272
2013-04-17 11:04:11
https://stackoverflow.com/q/11131389
https://stackoverflow.com/a/16058329
<p>My reading of the original question is slightly different to C.B.'s. From</p> <pre><code>Get-Foo [-foo1] &lt;foo1Arg&gt; [-foo2 &lt;foo2Arg&gt; [-bar &lt;barArg&gt;]] </code></pre> <p>The first argument $foo1 is always mandatory, while if $bar is specified $foo2 must be specified too.</p> <p>So my coding of it w...
<p>My reading of the original question is slightly different to C.B.'s. From</p> <pre><code>Get-Foo [-foo1] &lt;foo1Arg&gt; [-foo2 &lt;foo2Arg&gt; [-bar &lt;barArg&gt;]] </code></pre> <p>The first argument $foo1 is always mandatory, while if $bar is specified $foo2 must be specified too.</p> <p>So my coding of it w...
526, 24067
powershell, powershell-2.0
<h1>Having a optional parameter that requires another parameter to be present</h1> <p>Quite simply, how do I initialize the <code>params</code> part of my Powershell Script so I can have a command line arguments like</p> <pre><code>Get-Foo [-foo1] &lt;foo1Arg&gt; [-foo2 &lt;foo2Arg&gt; [-bar &lt;barArg&gt;]] </code></...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,764
bash
# Having a optional parameter that requires another parameter to be present Quite simply, how do I initialize the `params` part of my Powershell Script so I can have a command line arguments like ``` Get-Foo [-foo1] <foo1Arg> [-foo2 <foo2Arg> [-bar <barArg>]] ``` So the only time I can use `-bar` is when `foo2` has ...
My reading of the original question is slightly different to C.B.'s. From ``` Get-Foo [-foo1] <foo1Arg> [-foo2 <foo2Arg> [-bar <barArg>]] ``` The first argument $foo1 is always mandatory, while if $bar is specified $foo2 must be specified too. So my coding of it would be to put $foo1 in both parameter sets. ``` fun...
15763044
Why can't I pass a directory as an argument to a for loop in bash?
11
2013-04-02 11:33:41
<p>I have a simple bash script, simple.sh, as follows:</p> <pre><code>#/usr/local/bin/bash for i in $1 do echo The current file is $i done </code></pre> <p>When I run it with the following argument: </p> <pre><code>./simple.sh /home/test/* </code></pre> <p>it would only print and list out the first fi...
15,465
1,835,622
2013-04-02 12:39:03
15,763,133
12
2013-04-02 11:37:36
1,952,956
2013-04-02 11:52:21
https://stackoverflow.com/q/15763044
https://stackoverflow.com/a/15763133
<p>If you take "$1", it is the first file/directory, which is possible! You should do it in this way:</p> <pre><code>for i in "$@" do echo The current file is ${i} done </code></pre> <p>If you execute it with:</p> <pre><code>./simple.sh * </code></pre> <p>They list you all files of the actual dictionary</p> <p>"...
<p>If you take "$1", it is the first file/directory, which is possible! You should do it in this way:</p> <pre><code>for i in "$@" do echo The current file is ${i} done </code></pre> <p>If you execute it with:</p> <pre><code>./simple.sh * </code></pre> <p>They list you all files of the actual dictionary</p> <p>"...
218, 387
bash, directory
<h1>Why can't I pass a directory as an argument to a for loop in bash?</h1> <p>I have a simple bash script, simple.sh, as follows:</p> <pre><code>#/usr/local/bin/bash for i in $1 do echo The current file is $i done </code></pre> <p>When I run it with the following argument: </p> <pre><code>./simple.sh ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,765
bash
# Why can't I pass a directory as an argument to a for loop in bash? I have a simple bash script, simple.sh, as follows: ``` #/usr/local/bin/bash for i in $1 do echo The current file is $i done ``` When I run it with the following argument: ``` ./simple.sh /home/test/* ``` it would only print and list...
If you take "$1", it is the first file/directory, which is possible! You should do it in this way: ``` for i in "$@" do echo The current file is ${i} done ``` If you execute it with: ``` ./simple.sh * ``` They list you all files of the actual dictionary "$1" is alphabetical the first file/directory of your curre...
14106679
Is there an inline-if with assignment (ternary conditional) in bash?
11
2012-12-31 23:05:15
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3953645/ternary-operator-in-bash">Ternary operator (?:) in Bash</a> </p> </blockquote> <p>If this were AS3 or Java, I would do the following:</p> <pre><code>fileName = dirName + "/" + (useDefault ? defaultName...
20,968
617,937
2013-01-01 20:43:08
14,106,707
12
2012-12-31 23:11:15
827,263
2013-01-01 20:43:08
https://stackoverflow.com/q/14106679
https://stackoverflow.com/a/14106707
<p>There is no <code>?:</code> conditional operator in the shell, but you could make the code a little less redundant like this:</p> <pre><code>if [ $useDefault ]; then tmpname="$defaultName" else tmpname="$customName" fi fileName="$dirName/$tmpname.txt" </code></pre> <p>Or you could write your own shell func...
<p>There is no <code>?:</code> conditional operator in the shell, but you could make the code a little less redundant like this:</p> <pre><code>if [ $useDefault ]; then tmpname="$defaultName" else tmpname="$customName" fi fileName="$dirName/$tmpname.txt" </code></pre> <p>Or you could write your own shell func...
387, 390, 2773, 7992
bash, if-statement, operators, shell
<h1>Is there an inline-if with assignment (ternary conditional) in bash?</h1> <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3953645/ternary-operator-in-bash">Ternary operator (?:) in Bash</a> </p> </blockquote> <p>If this were AS3 or Java, I would do the f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,766
bash
# Is there an inline-if with assignment (ternary conditional) in bash? > **Possible Duplicate:** > [Ternary operator (?:) in Bash](https://stackoverflow.com/questions/3953645/ternary-operator-in-bash) If this were AS3 or Java, I would do the following: ``` fileName = dirName + "/" + (useDefault ? defaultName : cus...
There is no `?:` conditional operator in the shell, but you could make the code a little less redundant like this: ``` if [ $useDefault ]; then tmpname="$defaultName" else tmpname="$customName" fi fileName="$dirName/$tmpname.txt" ``` Or you could write your own shell function that acts like the `?:` operator:...
13903312
Where is the v2.0 and v3.0 folder for PowerShell?
11
2012-12-16 16:40:09
<p>On my box, I installed PowerShell 2.0, but the $PSHome varialbe always return the path below:</p> <p>C:\Windows\System32\WindowsPowerShell\v1.0</p> <p>So, where is the v2.0 or v3.0 folder?</p>
13,676
264,052
2012-12-16 17:01:53
13,903,465
12
2012-12-16 17:01:53
526,535
2012-12-16 17:01:53
https://stackoverflow.com/q/13903312
https://stackoverflow.com/a/13903465
<p>Just like how 64-bit system files in Windows are in <code>System32</code>, all versions of Powershell install into the path that says <code>v1.0</code>. One of the things that MS doesn't seem to learn from. Didn't you wonder that Powershell script files have the extension <code>ps1</code>, <code>psm1</code> etc?</p>...
<p>Just like how 64-bit system files in Windows are in <code>System32</code>, all versions of Powershell install into the path that says <code>v1.0</code>. One of the things that MS doesn't seem to learn from. Didn't you wonder that Powershell script files have the extension <code>ps1</code>, <code>psm1</code> etc?</p>...
526, 24067
powershell, powershell-2.0
<h1>Where is the v2.0 and v3.0 folder for PowerShell?</h1> <p>On my box, I installed PowerShell 2.0, but the $PSHome varialbe always return the path below:</p> <p>C:\Windows\System32\WindowsPowerShell\v1.0</p> <p>So, where is the v2.0 or v3.0 folder?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,767
bash
# Where is the v2.0 and v3.0 folder for PowerShell? On my box, I installed PowerShell 2.0, but the $PSHome varialbe always return the path below: C:\Windows\System32\WindowsPowerShell\v1.0 So, where is the v2.0 or v3.0 folder?
Just like how 64-bit system files in Windows are in `System32`, all versions of Powershell install into the path that says `v1.0`. One of the things that MS doesn't seem to learn from. Didn't you wonder that Powershell script files have the extension `ps1`, `psm1` etc?
13500866
How to compare hexadecimal numbers with hexadecimal numbers in shell?
11
2012-11-21 19:41:29
<p>How to compare hexadecimal number with hexadecimal numbers in shell? </p>
18,551
1,812,956
2019-04-04 14:14:10
13,503,150
12
2012-11-21 22:32:22
507,519
2012-11-21 22:32:22
https://stackoverflow.com/q/13500866
https://stackoverflow.com/a/13503150
<p>At least <code>bash</code> supports hexadecimal integers directly, provided that they are prefixed with <code>0x</code>:</p> <pre><code>$ [[ 0xdead -lt 0xcafe ]] &amp;&amp; echo yes || echo no no $ [[ 0xdead -gt 0xcafe ]] &amp;&amp; echo yes || echo no yes </code></pre> <p>You just use the comparison operators nor...
<p>At least <code>bash</code> supports hexadecimal integers directly, provided that they are prefixed with <code>0x</code>:</p> <pre><code>$ [[ 0xdead -lt 0xcafe ]] &amp;&amp; echo yes || echo no no $ [[ 0xdead -gt 0xcafe ]] &amp;&amp; echo yes || echo no yes </code></pre> <p>You just use the comparison operators nor...
387, 390
bash, shell
<h1>How to compare hexadecimal numbers with hexadecimal numbers in shell?</h1> <p>How to compare hexadecimal number with hexadecimal numbers in shell? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,768
bash
# How to compare hexadecimal numbers with hexadecimal numbers in shell? How to compare hexadecimal number with hexadecimal numbers in shell?
At least `bash` supports hexadecimal integers directly, provided that they are prefixed with `0x`: ``` $ [[ 0xdead -lt 0xcafe ]] && echo yes || echo no no $ [[ 0xdead -gt 0xcafe ]] && echo yes || echo no yes ``` You just use the comparison operators normally...
9479814
How to split a string in bash delimited by /
11
2012-02-28 09:57:47
<p>I have to split a string in a bash script by "/" but I tried:</p> <pre><code>for i in $(echo $www | tr "/") </code></pre> <p>But it did not work, any suggestion ?</p> <p>Thanks a lot.</p>
16,064
554,892
2012-02-28 14:48:55
9,479,906
12
2012-02-28 10:04:10
20,862
2012-02-28 10:04:10
https://stackoverflow.com/q/9479814
https://stackoverflow.com/a/9479906
<pre><code>$ IFS=/ read -a foo &lt;&lt;&lt; 'abc def/ghi/jkl' $ echo "${foo[0]}*${foo[1]}*${foo[2]}" abc def*ghi*jkl </code></pre>
<pre><code>$ IFS=/ read -a foo &lt;&lt;&lt; 'abc def/ghi/jkl' $ echo "${foo[0]}*${foo[1]}*${foo[2]}" abc def*ghi*jkl </code></pre>
387
bash
<h1>How to split a string in bash delimited by /</h1> <p>I have to split a string in a bash script by "/" but I tried:</p> <pre><code>for i in $(echo $www | tr "/") </code></pre> <p>But it did not work, any suggestion ?</p> <p>Thanks a lot.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,769
bash
# How to split a string in bash delimited by / I have to split a string in a bash script by "/" but I tried: ``` for i in $(echo $www | tr "/") ``` But it did not work, any suggestion ? Thanks a lot.
``` $ IFS=/ read -a foo <<< 'abc def/ghi/jkl' $ echo "${foo[0]}*${foo[1]}*${foo[2]}" abc def*ghi*jkl ```
2361709
Efficient way to get your IP address in shell scripts
11
2010-03-02 08:25:24
<p><strong>Context:</strong> On *nix systems, one may get the IP address of the machine in a shell script this way:</p> <pre><code>ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' </code></pre> <p>Or this way too:</p> <pre><code>ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{print ...
27,630
2,050
2016-06-23 13:39:30
2,362,674
12
2010-03-02 11:16:42
131,527
2010-03-02 11:16:42
https://stackoverflow.com/q/2361709
https://stackoverflow.com/a/2362674
<p>you can do it with just one awk command. No need to use too many pipes.</p> <pre><code>$ ifconfig | awk -F':' '/inet addr/&amp;&amp;!/127.0.0.1/{split($2,_," ");print _[1]}' </code></pre>
<p>you can do it with just one awk command. No need to use too many pipes.</p> <pre><code>$ ifconfig | awk -F':' '/inet addr/&amp;&amp;!/127.0.0.1/{split($2,_," ");print _[1]}' </code></pre>
390, 531, 1231
command-line, scripting, shell
<h1>Efficient way to get your IP address in shell scripts</h1> <p><strong>Context:</strong> On *nix systems, one may get the IP address of the machine in a shell script this way:</p> <pre><code>ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' </code></pre> <p>Or this way too:</p> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,770
bash
# Efficient way to get your IP address in shell scripts **Context:** On *nix systems, one may get the IP address of the machine in a shell script this way: ``` ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' ``` Or this way too: ``` ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{...
you can do it with just one awk command. No need to use too many pipes. ``` $ ifconfig | awk -F':' '/inet addr/&&!/127.0.0.1/{split($2,_," ");print _[1]}' ```
1827862
What determines whether the Powershell pipeline will unroll a collection?
11
2009-12-01 18:07:20
<pre><code># array C:\&gt; (1,2,3).count 3 C:\&gt; (1,2,3 | measure).count 3 # hashtable C:\&gt; @{1=1; 2=2; 3=3}.count 3 C:\&gt; (@{1=1; 2=2; 3=3} | measure).count 1 # array returned from function C:\&gt; function UnrollMe { $args } C:\&gt; (UnrollMe a,b,c).count 3 C:\&gt; (UnrollMe a,b,c | measure).count 1 C:\&gt; ...
3,833
74,439
2009-12-02 04:41:07
1,829,401
12
2009-12-01 22:31:21
153,982
2009-12-02 04:41:07
https://stackoverflow.com/q/1827862
https://stackoverflow.com/a/1829401
<p>$args is unrolled. Remember that function parameters are normally passed using space to separate them. When you pass in 1,2,3 you are passing in a single argument that is an array of three numbers that gets assigned to $args[0]:</p> <pre><code>PS&gt; function UnrollMe { $args } PS&gt; UnrollMe 1 2 3 | measure Cou...
<p>$args is unrolled. Remember that function parameters are normally passed using space to separate them. When you pass in 1,2,3 you are passing in a single argument that is an array of three numbers that gets assigned to $args[0]:</p> <pre><code>PS&gt; function UnrollMe { $args } PS&gt; UnrollMe 1 2 3 | measure Cou...
343, 526, 629, 2844
collections, ienumerable, pipeline, powershell
<h1>What determines whether the Powershell pipeline will unroll a collection?</h1> <pre><code># array C:\&gt; (1,2,3).count 3 C:\&gt; (1,2,3 | measure).count 3 # hashtable C:\&gt; @{1=1; 2=2; 3=3}.count 3 C:\&gt; (@{1=1; 2=2; 3=3} | measure).count 1 # array returned from function C:\&gt; function UnrollMe { $args } C...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,771
bash
# What determines whether the Powershell pipeline will unroll a collection? ``` # array C:\> (1,2,3).count 3 C:\> (1,2,3 | measure).count 3 # hashtable C:\> @{1=1; 2=2; 3=3}.count 3 C:\> (@{1=1; 2=2; 3=3} | measure).count 1 # array returned from function C:\> function UnrollMe { $args } C:\> (UnrollMe a,b,c).count 3...
$args is unrolled. Remember that function parameters are normally passed using space to separate them. When you pass in 1,2,3 you are passing in a single argument that is an array of three numbers that gets assigned to $args[0]: ``` PS> function UnrollMe { $args } PS> UnrollMe 1 2 3 | measure Count : 3 ``` Puttin...