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
9060269
Find time in milliseconds?
33
2012-01-30 06:42:00
<p>How can I find the time in milliseconds using PowerShell?</p>
100,421
941,939
2023-01-04 17:26:11
9,060,395
11
2012-01-30 06:58:11
520,612
2018-10-30 15:05:59
https://stackoverflow.com/q/9060269
https://stackoverflow.com/a/9060395
<p>In PowerShell you can cast a time value to a timespan and call the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.timespan.totalmilliseconds?view=netframework-4.7.2" rel="noreferrer">TotalMilliseconds</a> method:</p> <pre><code>([TimeSpan]"00:05:00").TotalMilliseconds # Returns 300000 ([TimeSpan] (Ge...
<p>In PowerShell you can cast a time value to a timespan and call the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.timespan.totalmilliseconds?view=netframework-4.7.2" rel="noreferrer">TotalMilliseconds</a> method:</p> <pre><code>([TimeSpan]"00:05:00").TotalMilliseconds # Returns 300000 ([TimeSpan] (Ge...
526, 2647
powershell, timespan
<h1>Find time in milliseconds?</h1> <p>How can I find the time in milliseconds using PowerShell?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,175
bash
# Find time in milliseconds? How can I find the time in milliseconds using PowerShell?
In PowerShell you can cast a time value to a timespan and call the [TotalMilliseconds](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.totalmilliseconds?view=netframework-4.7.2) method: ``` ([TimeSpan]"00:05:00").TotalMilliseconds # Returns 300000 ([TimeSpan] (Get-Date).ToShortTimeString()).TotalMillisec...
6635059
Filter the output of a command as if it was text
32
2011-07-09 13:35:42
<p>I have a simple question, but I am also a beginner in PowerShell. I think it has to do with the fact that the output of the <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Process" rel="noreferrer">Get-Process</a> command (alias <code>ps</code>) is objects and not tex...
131,936
381,995
2021-01-28 10:11:55
6,639,359
11
2011-07-10 05:20:53
526,535
2019-10-26 07:45:46
https://stackoverflow.com/q/6635059
https://stackoverflow.com/a/6639359
<p>The other answers are right of course about your specific question of starting services that have "sql" in their name, but to answer the generic question:</p> <p>You can do <code>Get-Service | Out-String</code>, and you will get the output as string, much like how Unix commands work.</p> <p>Also when the output is...
<p>The other answers are right of course about your specific question of starting services that have "sql" in their name, but to answer the generic question:</p> <p>You can do <code>Get-Service | Out-String</code>, and you will get the output as string, much like how Unix commands work.</p> <p>Also when the output is...
526
powershell
<h1>Filter the output of a command as if it was text</h1> <p>I have a simple question, but I am also a beginner in PowerShell. I think it has to do with the fact that the output of the <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Process" rel="noreferrer">Get-Process<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,176
bash
# Filter the output of a command as if it was text I have a simple question, but I am also a beginner in PowerShell. I think it has to do with the fact that the output of the [Get-Process](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Process) command (alias `ps`) is objects a...
The other answers are right of course about your specific question of starting services that have "sql" in their name, but to answer the generic question: You can do `Get-Service | Out-String`, and you will get the output as string, much like how Unix commands work. Also when the output is piped to non-PowerShell com...
5545117
Firefox refresh current tab from command-line
31
2011-04-04 22:38:38
<p>I'd like to trigger a tab refresh on Firefox from a command line. I'm working on a web app and the refresh goes after the app compiles. I trigger the compile from a command in my IDE. It's not a fixed url, nor can it be derived from the open file in the IDE. Thus, the currently open url in the active tab.</p> <p>Th...
16,694
691,910
2023-01-25 20:14:35
57,236,737
11
2019-07-27 23:09:36
175,830
2019-07-27 23:09:36
https://stackoverflow.com/q/5545117
https://stackoverflow.com/a/57236737
<p>Here's an updated version of @geekQ's script that will return focus to the previous program (however, the firefox window will still be pulled to the top).</p> <pre><code>#!/bin/bash CURRENT_WID=$(xdotool getwindowfocus) WID=$(xdotool search --name "Mozilla Firefox") xdotool windowactivate $WID xdotool key F5 xdo...
<p>Here's an updated version of @geekQ's script that will return focus to the previous program (however, the firefox window will still be pulled to the top).</p> <pre><code>#!/bin/bash CURRENT_WID=$(xdotool getwindowfocus) WID=$(xdotool search --name "Mozilla Firefox") xdotool windowactivate $WID xdotool key F5 xdo...
390, 691, 1362
automation, firefox, shell
<h1>Firefox refresh current tab from command-line</h1> <p>I'd like to trigger a tab refresh on Firefox from a command line. I'm working on a web app and the refresh goes after the app compiles. I trigger the compile from a command in my IDE. It's not a fixed url, nor can it be derived from the open file in the IDE. Thu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,177
bash
# Firefox refresh current tab from command-line I'd like to trigger a tab refresh on Firefox from a command line. I'm working on a web app and the refresh goes after the app compiles. I trigger the compile from a command in my IDE. It's not a fixed url, nor can it be derived from the open file in the IDE. Thus, the cu...
Here's an updated version of @geekQ's script that will return focus to the previous program (however, the firefox window will still be pulled to the top). ``` #!/bin/bash CURRENT_WID=$(xdotool getwindowfocus) WID=$(xdotool search --name "Mozilla Firefox") xdotool windowactivate $WID xdotool key F5 xdotool windowact...
42568201
Jenkins pipeline sh does not seem to respect pipe in shell command
26
2017-03-02 23:56:19
<p>I am using a Jenkinsfile in a pipeline on version 2.32.2. </p> <p>For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use evaluate. </p> <p>I quickly came up with a little sed expression to get it out of the pom which uses pipes and...
45,692
1,813,687
2023-07-06 12:54:19
58,333,393
11
2019-10-11 02:16:45
9,254,190
2019-10-11 02:16:45
https://stackoverflow.com/q/42568201
https://stackoverflow.com/a/58333393
<p>I know this kind of late answer, but whoever you who needs the solution without eval you can use <code>/bin/bash -c "script"</code> to make pipe works</p> <pre><code>script { POM_VERSION = sh(script: "/bin/bash -c 'sed -n \'/&lt;version&gt;/,/&lt;version/p\' pom.xml | head -1 | sed \'s/[[:blank:]]*&lt;\/*versio...
<p>I know this kind of late answer, but whoever you who needs the solution without eval you can use <code>/bin/bash -c "script"</code> to make pipe works</p> <pre><code>script { POM_VERSION = sh(script: "/bin/bash -c 'sed -n \'/&lt;version&gt;/,/&lt;version/p\' pom.xml | head -1 | sed \'s/[[:blank:]]*&lt;\/*versio...
5813, 57788, 64999, 118285
jenkins, jenkins-pipeline, pipe, subshell
<h1>Jenkins pipeline sh does not seem to respect pipe in shell command</h1> <p>I am using a Jenkinsfile in a pipeline on version 2.32.2. </p> <p>For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use evaluate. </p> <p>I quickly came u...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,178
bash
# Jenkins pipeline sh does not seem to respect pipe in shell command I am using a Jenkinsfile in a pipeline on version 2.32.2. For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use evaluate. I quickly came up with a little sed express...
I know this kind of late answer, but whoever you who needs the solution without eval you can use `/bin/bash -c "script"` to make pipe works ``` script { POM_VERSION = sh(script: "/bin/bash -c 'sed -n \'/<version>/,/<version/p\' pom.xml | head -1 | sed \'s/[[:blank:]]*<\/*version>//g\'\''", returnStdout: true) ...
202432
How to best capture and log scp output?
26
2008-10-14 19:08:52
<p>I am trying to capture output from an install script (that uses scp) and log it. However, I am not getting everything that scp is printing out, namely, the progress bar. </p> <p>screen output:</p> <blockquote> <p>Copying /user2/cdb/builds/tmp/uat/myfiles/* to server /users/myfiles as cdb</p> <p>cdb@se...
77,493
807
2024-07-11 14:17:56
202,479
11
2008-10-14 19:21:37
27,653
2008-10-14 19:21:37
https://stackoverflow.com/q/202432
https://stackoverflow.com/a/202479
<p>It looks like your just missing whether the scp was succesful or not from the log. </p> <p>I'm guessing the scroll bar doesn't print to stdout and uses ncurses or some other kind of TUI?</p> <p>You could just look at the return value of scp to see whether it was successful. Like </p> <pre><code>scp myfile user@ho...
<p>It looks like your just missing whether the scp was succesful or not from the log. </p> <p>I'm guessing the scroll bar doesn't print to stdout and uses ncurses or some other kind of TUI?</p> <p>You could just look at the return value of scp to see whether it was successful. Like </p> <pre><code>scp myfile user@ho...
390, 942, 3149
logging, scp, shell
<h1>How to best capture and log scp output?</h1> <p>I am trying to capture output from an install script (that uses scp) and log it. However, I am not getting everything that scp is printing out, namely, the progress bar. </p> <p>screen output:</p> <blockquote> <p>Copying /user2/cdb/builds/tmp/uat/myfiles/* to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,179
bash
# How to best capture and log scp output? I am trying to capture output from an install script (that uses scp) and log it. However, I am not getting everything that scp is printing out, namely, the progress bar. screen output: > Copying > /user2/cdb/builds/tmp/uat/myfiles/* to > server /users/myfiles as cdb > > cdb@...
It looks like your just missing whether the scp was succesful or not from the log. I'm guessing the scroll bar doesn't print to stdout and uses ncurses or some other kind of TUI? You could just look at the return value of scp to see whether it was successful. Like ``` scp myfile user@host.com:. && echo success! ``` ...
30568727
Enter-PSSession to remote server fails with "cannot find the computer"
25
2015-06-01 08:19:24
<p>My desktop is win7 and I am trying to connect to a server 2012.<br> Both hosts are on the same domain. </p> <p>If I do:</p> <pre><code>Enter-PSSession -ComputerName *ServerName*** </code></pre> <p>I get the following failure message from winrm </p> <blockquote> <p>Enter-PSSession : Connecting to remote ser...
77,931
4,960,470
2023-02-13 08:54:58
30,747,948
11
2015-06-10 05:41:23
4,960,470
2015-06-10 05:41:23
https://stackoverflow.com/q/30568727
https://stackoverflow.com/a/30747948
<p>After talking to our domain admin I think I found the cause of the problem.<br> The server is in a resource domain which only has a one way trust to the main OU.<br> This explains why I can do PS remoting from the server to the clients but not vice versa.<br> I found that I can use the IP address with the <code>-Cre...
<p>After talking to our domain admin I think I found the cause of the problem.<br> The server is in a resource domain which only has a one way trust to the main OU.<br> This explains why I can do PS remoting from the server to the clients but not vice versa.<br> I found that I can use the IP address with the <code>-Cre...
63177, 73157
powershell-3.0, powershell-remoting
<h1>Enter-PSSession to remote server fails with "cannot find the computer"</h1> <p>My desktop is win7 and I am trying to connect to a server 2012.<br> Both hosts are on the same domain. </p> <p>If I do:</p> <pre><code>Enter-PSSession -ComputerName *ServerName*** </code></pre> <p>I get the following failure messag...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,180
bash
# Enter-PSSession to remote server fails with "cannot find the computer" My desktop is win7 and I am trying to connect to a server 2012. Both hosts are on the same domain. If I do: ``` Enter-PSSession -ComputerName *ServerName*** ``` I get the following failure message from winrm > Enter-PSSession : Connecting t...
After talking to our domain admin I think I found the cause of the problem. The server is in a resource domain which only has a one way trust to the main OU. This explains why I can do PS remoting from the server to the clients but not vice versa. I found that I can use the IP address with the `-Credential` optio...
27458502
How to run interactive shell command inside node.js?
25
2014-12-13 11:54:31
<p>I have to run some interactive shell command inside node.js. Lets our interactive shell be <code>$ python</code>:</p> <pre><code>var cp = require('child_process'); var pythonChildProcess = cp.spawn('python'); pythonChildProcess.stdout.on("data", function(data) { console.log('data successfully written!', data); /...
33,342
2,685,677
2019-03-07 13:09:17
27,459,402
11
2014-12-13 13:36:15
1,233,251
2014-12-13 14:52:06
https://stackoverflow.com/q/27458502
https://stackoverflow.com/a/27459402
<p>First and foremost, one of the things preventing node from interfacing with other interactive shells is that the child application must keep its "interactive" behavior, even when <code>stdin</code> doesn't look like a terminal. <code>python</code> here knew that its <code>stdin</code> wasn't a terminal, so it refuse...
<p>First and foremost, one of the things preventing node from interfacing with other interactive shells is that the child application must keep its "interactive" behavior, even when <code>stdin</code> doesn't look like a terminal. <code>python</code> here knew that its <code>stdin</code> wasn't a terminal, so it refuse...
3, 390, 46426
javascript, node.js, shell
<h1>How to run interactive shell command inside node.js?</h1> <p>I have to run some interactive shell command inside node.js. Lets our interactive shell be <code>$ python</code>:</p> <pre><code>var cp = require('child_process'); var pythonChildProcess = cp.spawn('python'); pythonChildProcess.stdout.on("data", functio...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,181
bash
# How to run interactive shell command inside node.js? I have to run some interactive shell command inside node.js. Lets our interactive shell be `$ python`: ``` var cp = require('child_process'); var pythonChildProcess = cp.spawn('python'); pythonChildProcess.stdout.on("data", function(data) { console.log('data s...
First and foremost, one of the things preventing node from interfacing with other interactive shells is that the child application must keep its "interactive" behavior, even when `stdin` doesn't look like a terminal. `python` here knew that its `stdin` wasn't a terminal, so it refused to work. This can be overridden by...
20602675
trapping signal from "docker stop" in bash
25
2013-12-16 02:47:01
<p>i have an entry point script in a docker container that looks something like the following:</p> <pre><code>#!/bin/bash echo starting up function shut_down() { echo shutting down pid=$(ps -e | grep myapp | awk '{print $1}') kill -SIGTERM $pid exit } trap "shut_down" SIGKILL SIGTERM SIGHUP SIGIN...
20,564
2,341,555
2023-01-22 17:10:39
20,606,897
11
2013-12-16 09:05:06
467,255
2015-12-14 19:25:46
https://stackoverflow.com/q/20602675
https://stackoverflow.com/a/20606897
<p>Have a look at <a href="https://github.com/lgierth/docker-exec/blob/master/docker-exec" rel="noreferrer">this</a>, could be inspiring :-)</p> <p><strong>UPDATE:</strong></p> <p>@nick-humrich here it is is my lamer copy &amp; past (credit goes to the original author <a href="https://github.com/lgierth" rel="norefer...
<p>Have a look at <a href="https://github.com/lgierth/docker-exec/blob/master/docker-exec" rel="noreferrer">this</a>, could be inspiring :-)</p> <p><strong>UPDATE:</strong></p> <p>@nick-humrich here it is is my lamer copy &amp; past (credit goes to the original author <a href="https://github.com/lgierth" rel="norefer...
387, 90304
bash, docker
<h1>trapping signal from "docker stop" in bash</h1> <p>i have an entry point script in a docker container that looks something like the following:</p> <pre><code>#!/bin/bash echo starting up function shut_down() { echo shutting down pid=$(ps -e | grep myapp | awk '{print $1}') kill -SIGTERM $pid e...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,182
bash
# trapping signal from "docker stop" in bash i have an entry point script in a docker container that looks something like the following: ``` #!/bin/bash echo starting up function shut_down() { echo shutting down pid=$(ps -e | grep myapp | awk '{print $1}') kill -SIGTERM $pid exit } trap "shut_do...
Have a look at [this](https://github.com/lgierth/docker-exec/blob/master/docker-exec), could be inspiring :-) **UPDATE:** @nick-humrich here it is is my lamer copy & past (credit goes to the original author <https://github.com/lgierth> ) ``` #!/bin/bash function ensure_started_container { exists=`docker ps -q | g...
7338395
Is it possible to reset the runspace in Powershell ISE?
25
2011-09-07 18:00:33
<p>One of the features of <a href="http://powergui.org/index.jspa" rel="noreferrer">PowerGUI</a> is the ability to reset the <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.runspace.aspx" rel="noreferrer">Powershell Runspace</a> as demonstrated in <a href="http://dmitrysotnikov.w...
25,762
95,195
2013-06-24 09:33:03
7,341,211
11
2011-09-07 22:23:54
6,920
2013-06-24 09:33:03
https://stackoverflow.com/q/7338395
https://stackoverflow.com/a/7341211
<p>I wrote a module called "ISE Session Tools" to do this a few months back. Essentially the runspace in ISE is equated to a "Tab" container, of which its child documents share the runspace. My script looks at the current open files, remembers them, creates a new Tab (runspace) and closes the old one, then adds the fil...
<p>I wrote a module called "ISE Session Tools" to do this a few months back. Essentially the runspace in ISE is equated to a "Tab" container, of which its child documents share the runspace. My script looks at the current open files, remembers them, creates a new Tab (runspace) and closes the old one, then adds the fil...
526, 22864
powershell, powershell-ise
<h1>Is it possible to reset the runspace in Powershell ISE?</h1> <p>One of the features of <a href="http://powergui.org/index.jspa" rel="noreferrer">PowerGUI</a> is the ability to reset the <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.runspace.aspx" rel="noreferrer">Powershell...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,183
bash
# Is it possible to reset the runspace in Powershell ISE? One of the features of [PowerGUI](http://powergui.org/index.jspa) is the ability to reset the [Powershell Runspace](http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.runspace.aspx) as demonstrated in [this article](http://dmitrysotn...
I wrote a module called "ISE Session Tools" to do this a few months back. Essentially the runspace in ISE is equated to a "Tab" container, of which its child documents share the runspace. My script looks at the current open files, remembers them, creates a new Tab (runspace) and closes the old one, then adds the files ...
39878202
powershell mandatory parameter with default value shown
24
2016-10-05 15:33:07
<p>I am looking for a way to have an PowerShell script ask for an parameter which needs to be mandatory, but shown with an default value, e.g.:</p> <pre><code> .\psscript Supply values for the following parameters: parameter1[default value]: parameter2[1234]: </code></pre> <p>I want to ask for input bu...
81,418
6,927,276
2020-11-09 18:35:41
39,881,126
11
2016-10-05 18:19:55
3,776,535
2016-10-05 18:19:55
https://stackoverflow.com/q/39878202
https://stackoverflow.com/a/39881126
<p>Here's a <em>short</em> example that might help: </p> <pre><code> [CmdletBinding()] Param( $SqlServiceAccount = (Read-Host -prompt "SqlServiceAccount ($($env:computername + "_sa"))"), $SqlServiceAccountPwd = (Read-Host -prompt "SqlServiceAccountPwd") ) if (!$SqlServiceAccount) { $Sql...
<p>Here's a <em>short</em> example that might help: </p> <pre><code> [CmdletBinding()] Param( $SqlServiceAccount = (Read-Host -prompt "SqlServiceAccount ($($env:computername + "_sa"))"), $SqlServiceAccountPwd = (Read-Host -prompt "SqlServiceAccountPwd") ) if (!$SqlServiceAccount) { $Sql...
360, 526
parameters, powershell
<h1>powershell mandatory parameter with default value shown</h1> <p>I am looking for a way to have an PowerShell script ask for an parameter which needs to be mandatory, but shown with an default value, e.g.:</p> <pre><code> .\psscript Supply values for the following parameters: parameter1[default value]: ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,184
bash
# powershell mandatory parameter with default value shown I am looking for a way to have an PowerShell script ask for an parameter which needs to be mandatory, but shown with an default value, e.g.: ``` .\psscript Supply values for the following parameters: parameter1[default value]: parameter2[1234]:...
Here's a *short* example that might help: ``` [CmdletBinding()] Param( $SqlServiceAccount = (Read-Host -prompt "SqlServiceAccount ($($env:computername + "_sa"))"), $SqlServiceAccountPwd = (Read-Host -prompt "SqlServiceAccountPwd") ) if (!$SqlServiceAccount) { $SqlServiceAccount = $env:C...
8094562
How to run BASH script in my Android?
24
2011-11-11 13:20:00
<p>My same BASH script is working in Fedora/CentOS.</p> <p>But I am testing one <code>Android eee pad transformer</code>. <img src="https://i.sstatic.net/8dvzw.jpg" alt="enter image description here"></p> <p>Where i have terminal access and i wrote a small test script. But its not working, how can i fix it? what am ...
121,059
null
2024-11-15 19:52:24
8,094,664
11
2011-11-11 13:30:07
1,023,544
2011-11-11 14:09:27
https://stackoverflow.com/q/8094562
https://stackoverflow.com/a/8094664
<p>May be it will work when calling interpreter with a script?</p> <pre><code>$ bash ./test.sh </code></pre> <p>I saw, that although it is specified <code>#!/bin/bash</code> error was posted by <code>sh</code> - may be it do wrong.</p> <p>UPD</p> <pre><code>$ sh ./test.sh </code></pre>
<p>May be it will work when calling interpreter with a script?</p> <pre><code>$ bash ./test.sh </code></pre> <p>I saw, that although it is specified <code>#!/bin/bash</code> error was posted by <code>sh</code> - may be it do wrong.</p> <p>UPD</p> <pre><code>$ sh ./test.sh </code></pre>
58, 387, 1386, 5430, 29051
android, bash, bash4, fedora, linux
<h1>How to run BASH script in my Android?</h1> <p>My same BASH script is working in Fedora/CentOS.</p> <p>But I am testing one <code>Android eee pad transformer</code>. <img src="https://i.sstatic.net/8dvzw.jpg" alt="enter image description here"></p> <p>Where i have terminal access and i wrote a small test script. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,185
bash
# How to run BASH script in my Android? My same BASH script is working in Fedora/CentOS. But I am testing one `Android eee pad transformer`. ![enter image description here](https://i.sstatic.net/8dvzw.jpg) Where i have terminal access and i wrote a small test script. But its not working, how can i fix it? what am i ...
May be it will work when calling interpreter with a script? ``` $ bash ./test.sh ``` I saw, that although it is specified `#!/bin/bash` error was posted by `sh` - may be it do wrong. UPD ``` $ sh ./test.sh ```
2458793
How to disable editing my history in bash
23
2010-03-16 23:02:55
<p>In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. I can't put my finger on how this ha...
4,271
116,281
2019-12-17 17:26:48
51,427,080
11
2018-07-19 15:53:24
179,850
2018-07-19 15:59:56
https://stackoverflow.com/q/2458793
https://stackoverflow.com/a/51427080
<blockquote> <p>I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. </p> </blockquote> <p>Right. If you go back in your history and edit the line <em>without</em> pressing return to execute the command but instead moving to another history entry, you've just ...
<blockquote> <p>I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. </p> </blockquote> <p>Right. If you go back in your history and edit the line <em>without</em> pressing return to execute the command but instead moving to another history entry, you've just ...
58, 387, 390, 1231
bash, command-line, linux, shell
<h1>How to disable editing my history in bash</h1> <p>In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command ba...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,186
bash
# How to disable editing my history in bash In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command back in his...
> I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. Right. If you go back in your history and edit the line *without* pressing return to execute the command but instead moving to another history entry, you've just *edited* the history entry. If you then list y...
40910296
Decoding JSON and a base64-encoded value in a shell script
23
2016-12-01 12:08:58
<p>I have a JSON and I need to extract a base64-encoded value by particular key and decode it.</p> <p>JSON has the following structure:</p> <pre><code>[ { "LockIndex": 0, "Key": "Arul/key1", "Flags": 0, "Value": "MzAKCg==", "CreateIndex": 369, "ModifyIndex": 554 } ] </code></pre> <p>In th...
45,513
6,779,170
2025-06-22 19:42:48
40,913,567
11
2016-12-01 14:47:48
1,646,322
2016-12-01 14:47:48
https://stackoverflow.com/q/40910296
https://stackoverflow.com/a/40913567
<p>Using <a href="https://stedolan.github.com/jq/" rel="noreferrer">jq</a> and <a href="https://linux.die.net/man/1/base64" rel="noreferrer"><code>base64</code></a>:</p> <pre><code>jq -r '.[].Value' &lt; file.json | base64 --decode </code></pre>
<p>Using <a href="https://stedolan.github.com/jq/" rel="noreferrer">jq</a> and <a href="https://linux.die.net/man/1/base64" rel="noreferrer"><code>base64</code></a>:</p> <pre><code>jq -r '.[].Value' &lt; file.json | base64 --decode </code></pre>
390, 1011, 1508, 4387
base64, decode, json, shell
<h1>Decoding JSON and a base64-encoded value in a shell script</h1> <p>I have a JSON and I need to extract a base64-encoded value by particular key and decode it.</p> <p>JSON has the following structure:</p> <pre><code>[ { "LockIndex": 0, "Key": "Arul/key1", "Flags": 0, "Value": "MzAKCg==", "Cre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,187
bash
# Decoding JSON and a base64-encoded value in a shell script I have a JSON and I need to extract a base64-encoded value by particular key and decode it. JSON has the following structure: ``` [ { "LockIndex": 0, "Key": "Arul/key1", "Flags": 0, "Value": "MzAKCg==", "CreateIndex": 369, "Modify...
Using [jq](https://stedolan.github.com/jq/) and [`base64`](https://linux.die.net/man/1/base64): ``` jq -r '.[].Value' < file.json | base64 --decode ```
19059394
PowerShell Connect to FTP server and get files
23
2013-09-27 20:18:32
<pre><code>$ftpServer = "ftp.example.com" $username ="validUser" $password ="myPassword" $localToFTPPath = "C:\ToFTP" $localFromFTPPath = "C:\FromFTP" $remotePickupDir = "/Inbox" $remoteDropDir = "/Outbox" $SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText $ftp = new-object "AlexPilotti.FTPS.Client.FTPSCli...
207,093
2,744,565
2022-06-01 08:26:27
19,063,042
11
2013-09-28 03:53:09
2,820,200
2017-05-02 12:12:34
https://stackoverflow.com/q/19059394
https://stackoverflow.com/a/19063042
<p>Remote pick directory path should be the exact path on the ftp server you are tryng to access.. here is the script to download files from the server.. you can add or modify with SSLMode..</p> <pre><code>#ftp server $ftp = "ftp://example.com/" $user = "XX" $pass = "XXX" $SetType = "bin" $remotePickupDir = Get-C...
<p>Remote pick directory path should be the exact path on the ftp server you are tryng to access.. here is the script to download files from the server.. you can add or modify with SSLMode..</p> <pre><code>#ftp server $ftp = "ftp://example.com/" $user = "XX" $pass = "XXX" $SetType = "bin" $remotePickupDir = Get-C...
261, 526
ftp, powershell
<h1>PowerShell Connect to FTP server and get files</h1> <pre><code>$ftpServer = "ftp.example.com" $username ="validUser" $password ="myPassword" $localToFTPPath = "C:\ToFTP" $localFromFTPPath = "C:\FromFTP" $remotePickupDir = "/Inbox" $remoteDropDir = "/Outbox" $SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::Clea...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,188
bash
# PowerShell Connect to FTP server and get files ``` $ftpServer = "ftp.example.com" $username ="validUser" $password ="myPassword" $localToFTPPath = "C:\ToFTP" $localFromFTPPath = "C:\FromFTP" $remotePickupDir = "/Inbox" $remoteDropDir = "/Outbox" $SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText $ftp = ...
Remote pick directory path should be the exact path on the ftp server you are tryng to access.. here is the script to download files from the server.. you can add or modify with SSLMode.. ``` #ftp server $ftp = "ftp://example.com/" $user = "XX" $pass = "XXX" $SetType = "bin" $remotePickupDir = Get-ChildItem 'c:\t...
1636352
Using regular expressions in shell script
23
2009-10-28 10:21:59
<p>What is the correct way to parse a string using regular expressions in a linux shell script? I wrote the following script to print my SO rep on the console using <code>curl</code> and <code>sed</code> (not solely because I'm rep-crazy - I'm trying to learn some shell scripting and regex before switching to linux).</...
70,797
165,297
2017-04-08 21:31:02
1,636,391
11
2009-10-28 10:28:58
14,860
2014-02-26 10:11:08
https://stackoverflow.com/q/1636352
https://stackoverflow.com/a/1636391
<p>The <code>grep</code> command will select the desired line(s) from many but it will not directly manipulate the line. For that, you use <code>sed</code> in a pipeline:</p> <pre><code>someCommand | grep 'Amarghosh' | sed -e 's/foo/bar/g' </code></pre> <p>Alternatively, <code>awk</code> (or <code>perl</code> if avai...
<p>The <code>grep</code> command will select the desired line(s) from many but it will not directly manipulate the line. For that, you use <code>sed</code> in a pipeline:</p> <pre><code>someCommand | grep 'Amarghosh' | sed -e 's/foo/bar/g' </code></pre> <p>Alternatively, <code>awk</code> (or <code>perl</code> if avai...
18, 58, 390
linux, regex, shell
<h1>Using regular expressions in shell script</h1> <p>What is the correct way to parse a string using regular expressions in a linux shell script? I wrote the following script to print my SO rep on the console using <code>curl</code> and <code>sed</code> (not solely because I'm rep-crazy - I'm trying to learn some shel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,189
bash
# Using regular expressions in shell script What is the correct way to parse a string using regular expressions in a linux shell script? I wrote the following script to print my SO rep on the console using `curl` and `sed` (not solely because I'm rep-crazy - I'm trying to learn some shell scripting and regex before sw...
The `grep` command will select the desired line(s) from many but it will not directly manipulate the line. For that, you use `sed` in a pipeline: ``` someCommand | grep 'Amarghosh' | sed -e 's/foo/bar/g' ``` Alternatively, `awk` (or `perl` if available) can be used. It's a far more powerful text processing tool than ...
52114730
Is it possible to set Environment variables in Makefile - to be used after
22
2018-08-31 11:42:09
<p>I am trying to set an Environment variable in a Makefile, so it can be used in another program running in the sam shell as <code>make</code>, but after <code>make</code> has run.</p> <p>Update: This is not possible according to accepted answer with comments.</p> <p>Steps:</p> <ol> <li>run <code>make test</code> ...
50,966
699,215
2023-06-02 10:43:35
52,115,997
11
2018-08-31 12:57:56
1,773,798
2023-06-02 10:43:35
https://stackoverflow.com/q/52114730
https://stackoverflow.com/a/52115997
<p>If you want the environment variables to be exported to the shell from which you invoked make things are a bit difficult because, as explained by ネロク, you cannot directly export environment variables from a child process (<code>make</code>) to its parent process (the shell from which you invoke <code>make</code>). B...
<p>If you want the environment variables to be exported to the shell from which you invoked make things are a bit difficult because, as explained by ネロク, you cannot directly export environment variables from a child process (<code>make</code>) to its parent process (the shell from which you invoke <code>make</code>). B...
387, 4301, 13213
bash, gnu-make, makefile
<h1>Is it possible to set Environment variables in Makefile - to be used after</h1> <p>I am trying to set an Environment variable in a Makefile, so it can be used in another program running in the sam shell as <code>make</code>, but after <code>make</code> has run.</p> <p>Update: This is not possible according to acc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,190
bash
# Is it possible to set Environment variables in Makefile - to be used after I am trying to set an Environment variable in a Makefile, so it can be used in another program running in the sam shell as `make`, but after `make` has run. Update: This is not possible according to accepted answer with comments. Steps: 1....
If you want the environment variables to be exported to the shell from which you invoked make things are a bit difficult because, as explained by ネロク, you cannot directly export environment variables from a child process (`make`) to its parent process (the shell from which you invoke `make`). But if you accept to invok...
40089631
Replacing only the first occurrence of a word in a string
22
2016-10-17 14:55:07
<p>I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word in a string with another word but not replace any other o...
37,003
4,900,678
2022-07-09 01:08:21
40,089,770
11
2016-10-17 15:02:02
1,163,423
2022-07-09 01:08:21
https://stackoverflow.com/q/40089631
https://stackoverflow.com/a/40089770
<p>You could capture everything before and behind and replace it:</p> <pre><code>'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2' </code></pre>
<p>You could capture everything before and behind and replace it:</p> <pre><code>'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2' </code></pre>
526
powershell
<h1>Replacing only the first occurrence of a word in a string</h1> <p>I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,191
bash
# Replacing only the first occurrence of a word in a string I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word...
You could capture everything before and behind and replace it: ``` 'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2' ```
28504847
PowerShell's pipe adds linefeed
22
2015-02-13 17:03:47
<p>I'm trying to pipe a string into a program's STDIN <em>without</em> any trailing linefeeds (unless that string itself actually ends in a linefeed). I tried googling around, but I only found people trying to print to the <em>console</em> without a trailing linefeed, in which case <code>Write-Host</code> takes a param...
5,961
1,633,117
2020-07-07 19:55:17
32,981,504
11
2015-10-06 23:39:33
4,424,236
2015-10-07 09:38:12
https://stackoverflow.com/q/28504847
https://stackoverflow.com/a/32981504
<h2>Introduction</h2> <p>Here is my <code>Invoke-RawPipeline</code> function (get latest version from <a href="https://gist.github.com/beatcracker/931613a94a1988d17b31" rel="noreferrer">this Gist)</a>.</p> <p>Use it to pipe binary data between processes' Standard Output and Standard Input streams. It can read input str...
<h2>Introduction</h2> <p>Here is my <code>Invoke-RawPipeline</code> function (get latest version from <a href="https://gist.github.com/beatcracker/931613a94a1988d17b31" rel="noreferrer">this Gist)</a>.</p> <p>Use it to pipe binary data between processes' Standard Output and Standard Input streams. It can read input str...
526, 1701, 26698, 47852
io-redirection, linefeed, powershell, stdin
<h1>PowerShell's pipe adds linefeed</h1> <p>I'm trying to pipe a string into a program's STDIN <em>without</em> any trailing linefeeds (unless that string itself actually ends in a linefeed). I tried googling around, but I only found people trying to print to the <em>console</em> without a trailing linefeed, in which c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,192
bash
# PowerShell's pipe adds linefeed I'm trying to pipe a string into a program's STDIN *without* any trailing linefeeds (unless that string itself actually ends in a linefeed). I tried googling around, but I only found people trying to print to the *console* without a trailing linefeed, in which case `Write-Host` takes ...
## Introduction Here is my `Invoke-RawPipeline` function (get latest version from [this Gist)](https://gist.github.com/beatcracker/931613a94a1988d17b31). Use it to pipe binary data between processes' Standard Output and Standard Input streams. It can read input stream from file/pipeline and save resulting output stre...
11744547
SFTP to send file with bash script
21
2012-07-31 16:14:07
<p>I'm using key authentication, so password is not an issue. I have a file whose name I know and I simply want to send it to another machine over sftp.</p> <p>I tried searching but couldn't find this (seemingly simple) question anywhere. Perhaps my Google-fu is simply failing me today.</p> <p>In short: I'm on my l...
84,622
713,874
2020-10-06 20:29:13
11,744,766
11
2012-07-31 16:26:17
1,032,785
2012-07-31 16:26:17
https://stackoverflow.com/q/11744547
https://stackoverflow.com/a/11744766
<p>You said that you are not interested in other tools, but <code>scp</code> is a much better choice for unattended file transfers. Here is an scp example:</p> <pre><code>scp test.txt root@remote:/root/dropoff </code></pre>
<p>You said that you are not interested in other tools, but <code>scp</code> is a much better choice for unattended file transfers. Here is an scp example:</p> <pre><code>scp test.txt root@remote:/root/dropoff </code></pre>
387, 1290, 5310, 15398
bash, file, send, sftp
<h1>SFTP to send file with bash script</h1> <p>I'm using key authentication, so password is not an issue. I have a file whose name I know and I simply want to send it to another machine over sftp.</p> <p>I tried searching but couldn't find this (seemingly simple) question anywhere. Perhaps my Google-fu is simply fai...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,193
bash
# SFTP to send file with bash script I'm using key authentication, so password is not an issue. I have a file whose name I know and I simply want to send it to another machine over sftp. I tried searching but couldn't find this (seemingly simple) question anywhere. Perhaps my Google-fu is simply failing me today. In...
You said that you are not interested in other tools, but `scp` is a much better choice for unattended file transfers. Here is an scp example: ``` scp test.txt root@remote:/root/dropoff ```
9258387
Bash & (ampersand) operator
21
2012-02-13 09:46:12
<p>I'm trying to run 3 commands in parallel in bash shell:</p> <pre><code>$ (first command) &amp; (second command) &amp; (third command) &amp; wait </code></pre> <p>The problem with this is that if <code>first command</code> fails, for example, the exit code is <code>0</code> (I guess because <code>wait</code> succee...
38,534
247,243
2020-08-10 12:24:06
9,258,753
11
2012-02-13 10:16:20
650,405
2012-02-13 10:16:20
https://stackoverflow.com/q/9258387
https://stackoverflow.com/a/9258753
<p>the best I can think of is:</p> <pre><code>first &amp; p1=$! second &amp; p2=$! ... wait $p1 &amp;&amp; wait $p2 &amp;&amp; .. </code></pre> <p>or</p> <pre><code>wait $p1 || ( kill $p2 $p3 &amp;&amp; exit 1 ) ... </code></pre> <p>however this still enforces an order for the check of processes, so if the third f...
<p>the best I can think of is:</p> <pre><code>first &amp; p1=$! second &amp; p2=$! ... wait $p1 &amp;&amp; wait $p2 &amp;&amp; .. </code></pre> <p>or</p> <pre><code>wait $p1 || ( kill $p2 $p3 &amp;&amp; exit 1 ) ... </code></pre> <p>however this still enforces an order for the check of processes, so if the third f...
387, 10021, 15292
background-process, bash, exit-code
<h1>Bash & (ampersand) operator</h1> <p>I'm trying to run 3 commands in parallel in bash shell:</p> <pre><code>$ (first command) &amp; (second command) &amp; (third command) &amp; wait </code></pre> <p>The problem with this is that if <code>first command</code> fails, for example, the exit code is <code>0</code> (I g...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,194
bash
# Bash & (ampersand) operator I'm trying to run 3 commands in parallel in bash shell: ``` $ (first command) & (second command) & (third command) & wait ``` The problem with this is that if `first command` fails, for example, the exit code is `0` (I guess because `wait` succeeds). The desired behavior is that if one...
the best I can think of is: ``` first & p1=$! second & p2=$! ... wait $p1 && wait $p2 && .. ``` or ``` wait $p1 || ( kill $p2 $p3 && exit 1 ) ... ``` however this still enforces an order for the check of processes, so if the third fails immediately you won't notice it until the first and second finishes.
8841116
Vim not recognizing aliases when in interactive mode?
21
2012-01-12 19:29:49
<p>Same question as <a href="https://stackoverflow.com/questions/4642822/commands-executed-from-vim-are-not-recognizing-bash-command-aliases">this</a>, however the solution there didn't work.</p> <p>I set these variables in my ~/.vimrc:</p> <pre><code>set shellcmdflag=-ic set shell=/bin/bash\ -i </code></pre> <p>and...
10,121
82,668
2020-01-17 13:07:47
9,014,154
11
2012-01-26 05:05:17
1,040,358
2012-02-09 15:58:26
https://stackoverflow.com/q/8841116
https://stackoverflow.com/a/9014154
<p>I got this to work, via the man page for <code>bash</code>:</p> <pre><code>set shell=/bin/bash\ --rcfile\ ~/.bash_profile </code></pre> <p>Similarly, <code>--init-file</code> works. </p> <p>Note that <code>\ -i</code> <strong>is not necessary</strong>, though it can be added to the command:</p> <pre><code>set sh...
<p>I got this to work, via the man page for <code>bash</code>:</p> <pre><code>set shell=/bin/bash\ --rcfile\ ~/.bash_profile </code></pre> <p>Similarly, <code>--init-file</code> works. </p> <p>Note that <code>\ -i</code> <strong>is not necessary</strong>, though it can be added to the command:</p> <pre><code>set sh...
370, 387
bash, vim
<h1>Vim not recognizing aliases when in interactive mode?</h1> <p>Same question as <a href="https://stackoverflow.com/questions/4642822/commands-executed-from-vim-are-not-recognizing-bash-command-aliases">this</a>, however the solution there didn't work.</p> <p>I set these variables in my ~/.vimrc:</p> <pre><code>set...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,195
bash
# Vim not recognizing aliases when in interactive mode? Same question as [this](https://stackoverflow.com/questions/4642822/commands-executed-from-vim-are-not-recognizing-bash-command-aliases), however the solution there didn't work. I set these variables in my ~/.vimrc: ``` set shellcmdflag=-ic set shell=/bin/bash\...
I got this to work, via the man page for `bash`: ``` set shell=/bin/bash\ --rcfile\ ~/.bash_profile ``` Similarly, `--init-file` works. Note that `\ -i` **is not necessary**, though it can be added to the command: ``` set shell=/bin/bash\ --rcfile\ ~/.bash_profile\ -i ``` *Example*: `~/.bash_profile` contains ``...
1007538
Check if a function exists from a bash script
21
2009-06-17 14:50:16
<p>How can I determine if a function is already defined in a bash script?</p> <p>I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. </p> <p>I want to add <code>__git_ps1()</code> to <code>PS1</code> only if that function exists on that syst...
18,354
19,839
2017-10-18 19:16:51
1,007,605
11
2009-06-17 15:00:56
47,529
2012-07-20 03:51:49
https://stackoverflow.com/q/1007538
https://stackoverflow.com/a/1007605
<pre><code>if type __git_ps1 | grep -q '^function$' 2&gt;/dev/null; then PS1=whatever fi </code></pre>
<pre><code>if type __git_ps1 | grep -q '^function$' 2&gt;/dev/null; then PS1=whatever fi </code></pre>
387, 5569
bash, function
<h1>Check if a function exists from a bash script</h1> <p>How can I determine if a function is already defined in a bash script?</p> <p>I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. </p> <p>I want to add <code>__git_ps1()</code> to <co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,196
bash
# Check if a function exists from a bash script How can I determine if a function is already defined in a bash script? I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. I want to add `__git_ps1()` to `PS1` only if that function exists on ...
``` if type __git_ps1 | grep -q '^function$' 2>/dev/null; then PS1=whatever fi ```
24683539
How can I alias a PowerShell function?
20
2014-07-10 18:11:39
<p>The aim is to call the function <code>hello</code> by calling <code>hello</code> or alias <code>helloworld</code>.</p> <p><strong>Code:</strong></p> <pre><code>function hello() { param( [string] $name ) Write-Host &quot;Hello $name!&quot; } hello &quot;Utrecht&quot; helloworld &quot;Utreg&quot;...
19,361
2,777,965
2025-06-08 15:44:20
24,683,609
11
2014-07-10 18:16:30
1,324,345
2024-06-18 12:50:42
https://stackoverflow.com/q/24683539
https://stackoverflow.com/a/24683609
<p>Use the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias" rel="nofollow noreferrer"><code>set-alias</code></a> cmdlet.</p> <pre><code>set-alias -name helloworld -value hello </code></pre> <p>It should be noted though that your function name does not follow the Power...
<p>Use the <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias" rel="nofollow noreferrer"><code>set-alias</code></a> cmdlet.</p> <pre><code>set-alias -name helloworld -value hello </code></pre> <p>It should be noted though that your function name does not follow the Power...
526
powershell
<h1>How can I alias a PowerShell function?</h1> <p>The aim is to call the function <code>hello</code> by calling <code>hello</code> or alias <code>helloworld</code>.</p> <p><strong>Code:</strong></p> <pre><code>function hello() { param( [string] $name ) Write-Host &quot;Hello $name!&quot; } hello ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,197
bash
# How can I alias a PowerShell function? The aim is to call the function `hello` by calling `hello` or alias `helloworld`. **Code:** ``` function hello() { param( [string] $name ) Write-Host "Hello $name!" } hello "Utrecht" helloworld "Utreg" ``` Expected outcome: ``` Hello Utrecht! Hello Utr...
Use the [`set-alias`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias) cmdlet. ``` set-alias -name helloworld -value hello ``` It should be noted though that your function name does not follow the PowerShell convention and may be confusing to someone more accustomed to using...
20433932
Determine XML Node Exists
20
2013-12-06 21:31:39
<p>This is probably simple, but I'm trying to determine if a node exists in an XML document. I thought I found an answer in this post, <a href="https://stackoverflow.com/questions/13031110/how-to-check-whether-a-node-exists-or-not-using-powershell-without-getting-excep">How to check whether a node exists or not using p...
59,392
1,558,132
2023-08-04 19:45:06
20,475,810
11
2013-12-09 16:41:10
1,558,132
2013-12-09 16:41:10
https://stackoverflow.com/q/20433932
https://stackoverflow.com/a/20475810
<p>It appears that I was using the wrong syntax for SelectSingleNode. Here is a working example.</p> <pre><code>[xml]$xml = @' &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Vendors we will send and retreive files from Get-Send means we will get a file and send them a file Send means we will only send them a...
<p>It appears that I was using the wrong syntax for SelectSingleNode. Here is a working example.</p> <pre><code>[xml]$xml = @' &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Vendors we will send and retreive files from Get-Send means we will get a file and send them a file Send means we will only send them a...
19, 526, 24067
powershell, powershell-2.0, xml
<h1>Determine XML Node Exists</h1> <p>This is probably simple, but I'm trying to determine if a node exists in an XML document. I thought I found an answer in this post, <a href="https://stackoverflow.com/questions/13031110/how-to-check-whether-a-node-exists-or-not-using-powershell-without-getting-excep">How to check w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,198
bash
# Determine XML Node Exists This is probably simple, but I'm trying to determine if a node exists in an XML document. I thought I found an answer in this post, [How to check whether a node exists or not using powershell without getting exception?](https://stackoverflow.com/questions/13031110/how-to-check-whether-a-nod...
It appears that I was using the wrong syntax for SelectSingleNode. Here is a working example. ``` [xml]$xml = @' <?xml version="1.0" encoding="UTF-8"?> <!-- Vendors we will send and retreive files from Get-Send means we will get a file and send them a file Send means we will only send them a file--> <Vendors> ...
23591273
Is it possible to use comments when the line is split with backslashes?
19
2014-05-11 10:05:48
<p>I’d like to embed comments like this</p> <pre><code>ls -l \ -a \ # comment here -h \ -t . </code></pre> <p>But it seems that’s not possible. Maybe some other variant does exist? Putting a comment right after the backslash or ending a comment with a backslash doesn’t help.</p>
5,542
685,107
2018-10-24 19:49:45
23,591,495
11
2014-05-11 10:29:46
1,248,449
2014-05-11 12:34:50
https://stackoverflow.com/q/23591273
https://stackoverflow.com/a/23591495
<p>As far as I know, it is not possible, for Bash tries to follow to POSIX guidelines and other standards. Especially:</p> <blockquote> <p>If a <code>&lt;newline&gt;</code> follows the backslash, the shell shall interpret this as line continuation. The backslash and <code>&lt;newline&gt;</code>s shall be removed bef...
<p>As far as I know, it is not possible, for Bash tries to follow to POSIX guidelines and other standards. Especially:</p> <blockquote> <p>If a <code>&lt;newline&gt;</code> follows the backslash, the shell shall interpret this as line continuation. The backslash and <code>&lt;newline&gt;</code>s shall be removed bef...
387, 390, 10327
bash, sh, shell
<h1>Is it possible to use comments when the line is split with backslashes?</h1> <p>I’d like to embed comments like this</p> <pre><code>ls -l \ -a \ # comment here -h \ -t . </code></pre> <p>But it seems that’s not possible. Maybe some other variant does exist? Putting a comment right after the backslash or ending a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,199
bash
# Is it possible to use comments when the line is split with backslashes? I’d like to embed comments like this ``` ls -l \ -a \ # comment here -h \ -t . ``` But it seems that’s not possible. Maybe some other variant does exist? Putting a comment right after the backslash or ending a comment with a backslash doesn’t ...
As far as I know, it is not possible, for Bash tries to follow to POSIX guidelines and other standards. Especially: > If a `<newline>` follows the backslash, the shell shall interpret this as line continuation. The backslash and `<newline>`s shall be removed before splitting the input into tokens. Since the escaped `<...
21252824
How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7?
19
2014-01-21 08:29:58
<p>The situation. On a Windows 7 SP1 machine, I have updated with Windows6.1-KB2819745-x64-MultiPkg.msu. Furthermore, in PowerShell $PSVersionTable now reports ‘PSVersion 4.0’.</p> <p>At present, my conclusion is that many PowerShell 4 cmdlets such Test-NetConnection, will only work on Windows 8.1. However, I was wo...
74,344
200,586
2020-08-20 07:48:57
21,256,909
11
2014-01-21 11:31:16
3,093,031
2019-11-13 09:56:03
https://stackoverflow.com/q/21252824
https://stackoverflow.com/a/21256909
<p>You cannot. They rely on the underlying features of the newer OS (8.0 or 8.1) and cannot be ported back to Windows&nbsp;7 . The alternative is to write your own functions / modules to replicate the new cmdlets using .NET framework methods.</p> <p>For instance, the <a href="https://learn.microsoft.com/en-us/powershe...
<p>You cannot. They rely on the underlying features of the newer OS (8.0 or 8.1) and cannot be ported back to Windows&nbsp;7 . The alternative is to write your own functions / modules to replicate the new cmdlets using .NET framework methods.</p> <p>For instance, the <a href="https://learn.microsoft.com/en-us/powershe...
526, 34595, 95686
powershell, powershell-4.0, windows-7
<h1>How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7?</h1> <p>The situation. On a Windows 7 SP1 machine, I have updated with Windows6.1-KB2819745-x64-MultiPkg.msu. Furthermore, in PowerShell $PSVersionTable now reports ‘PSVersion 4.0’.</p> <p>At present, my conclusion is that many Po...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,200
bash
# How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7? The situation. On a Windows 7 SP1 machine, I have updated with Windows6.1-KB2819745-x64-MultiPkg.msu. Furthermore, in PowerShell $PSVersionTable now reports ‘PSVersion 4.0’. At present, my conclusion is that many PowerShell 4 cmdlets...
You cannot. They rely on the underlying features of the newer OS (8.0 or 8.1) and cannot be ported back to Windows 7 . The alternative is to write your own functions / modules to replicate the new cmdlets using .NET framework methods. For instance, the [Get-FileHash](https://learn.microsoft.com/en-us/powershell/module...
12700507
Proper way of printing out an error message
19
2012-10-03 00:48:51
<p>Is this line the best way to print out an error message in Bash?</p> <pre><code>echo 'Error: banana' &gt;&amp;2 </code></pre> <p>I need to update tens of Bash scripts which use all different ways of logging errors and I might as well choose the "right" way to do this and adhere to a standard as I do it...</p>
23,803
916,332
2019-04-15 19:44:06
12,700,524
11
2012-10-03 00:51:38
85,371
2012-10-03 00:51:38
https://stackoverflow.com/q/12700507
https://stackoverflow.com/a/12700524
<p>On linux, I'd prefer to say</p> <pre><code>echo "Some error message" &gt;&gt; /dev/stderr </code></pre> <p>This will effectively do the same, of course, since <code>/dev/stderr</code> symlinks to <code>/proc/$PID/fd/2</code></p>
<p>On linux, I'd prefer to say</p> <pre><code>echo "Some error message" &gt;&gt; /dev/stderr </code></pre> <p>This will effectively do the same, of course, since <code>/dev/stderr</code> symlinks to <code>/proc/$PID/fd/2</code></p>
387
bash
<h1>Proper way of printing out an error message</h1> <p>Is this line the best way to print out an error message in Bash?</p> <pre><code>echo 'Error: banana' &gt;&amp;2 </code></pre> <p>I need to update tens of Bash scripts which use all different ways of logging errors and I might as well choose the "right" way to do...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,201
bash
# Proper way of printing out an error message Is this line the best way to print out an error message in Bash? ``` echo 'Error: banana' >&2 ``` I need to update tens of Bash scripts which use all different ways of logging errors and I might as well choose the "right" way to do this and adhere to a standard as I do i...
On linux, I'd prefer to say ``` echo "Some error message" >> /dev/stderr ``` This will effectively do the same, of course, since `/dev/stderr` symlinks to `/proc/$PID/fd/2`
7034838
Exit a bash switch statement
19
2011-08-12 01:44:33
<p>I've written a menu driven bash script that uses a <code>switch case</code> inside of a <code>while</code> loop to perform the various menu options. Everything works just fine. Now I'm trying to improve the program by performing error testing on the user input, but I cannot seem to make it work... </p> <p>The probl...
57,062
406,543
2023-07-14 04:46:25
7,038,081
11
2011-08-12 09:23:23
7,552
2011-08-12 09:23:23
https://stackoverflow.com/q/7034838
https://stackoverflow.com/a/7038081
<p>Move the body of that <code>case</code> into a function, and you can <code>return</code> from the function at will.</p> <pre><code>do_A_stuff() { echo "Choose a month" read monthVal if [ "$monthVal" -lt 13 ] then cal "$monthVal" else return fi further tests ... } </code></...
<p>Move the body of that <code>case</code> into a function, and you can <code>return</code> from the function at will.</p> <pre><code>do_A_stuff() { echo "Choose a month" read monthVal if [ "$monthVal" -lt 13 ] then cal "$monthVal" else return fi further tests ... } </code></...
387
bash
<h1>Exit a bash switch statement</h1> <p>I've written a menu driven bash script that uses a <code>switch case</code> inside of a <code>while</code> loop to perform the various menu options. Everything works just fine. Now I'm trying to improve the program by performing error testing on the user input, but I cannot seem...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,202
bash
# Exit a bash switch statement I've written a menu driven bash script that uses a `switch case` inside of a `while` loop to perform the various menu options. Everything works just fine. Now I'm trying to improve the program by performing error testing on the user input, but I cannot seem to make it work... The proble...
Move the body of that `case` into a function, and you can `return` from the function at will. ``` do_A_stuff() { echo "Choose a month" read monthVal if [ "$monthVal" -lt 13 ] then cal "$monthVal" else return fi further tests ... } ``` Then ``` case $whatever in a|A) do_A_st...
3632603
bash variable capture stderr and stdout separately or get exit value
19
2010-09-03 02:03:29
<p>I need to capture the output and error of a command in my bash script and know whether the command succeeded or not.</p> <p>At the moment, I am capturing both like this:</p> <pre><code>output=$(mycommand 2&gt;&amp;1) </code></pre> <p>I then need to check the exit value of mycommand. If it failed, I need to do som...
11,104
263,328
2016-08-09 04:09:23
3,632,669
11
2010-09-03 02:19:24
14,860
2010-09-03 02:19:24
https://stackoverflow.com/q/3632603
https://stackoverflow.com/a/3632669
<p>What version of <code>bash</code> are you using? The capture of the output has <em>zero</em> effect on the return code with my version, <code>4.1.5</code>:</p> <pre><code>pax&gt; false; echo $? 1 pax&gt; echo $? 0 pax&gt; x=$(false 2&gt;&amp;1) ; echo $? 1 </code></pre> <p>It's not always a good idea to rely on st...
<p>What version of <code>bash</code> are you using? The capture of the output has <em>zero</em> effect on the return code with my version, <code>4.1.5</code>:</p> <pre><code>pax&gt; false; echo $? 1 pax&gt; echo $? 0 pax&gt; x=$(false 2&gt;&amp;1) ; echo $? 1 </code></pre> <p>It's not always a good idea to rely on st...
276, 387, 4867, 13261, 19156
bash, capture, stderr, stdout, variables
<h1>bash variable capture stderr and stdout separately or get exit value</h1> <p>I need to capture the output and error of a command in my bash script and know whether the command succeeded or not.</p> <p>At the moment, I am capturing both like this:</p> <pre><code>output=$(mycommand 2&gt;&amp;1) </code></pre> <p>I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,203
bash
# bash variable capture stderr and stdout separately or get exit value I need to capture the output and error of a command in my bash script and know whether the command succeeded or not. At the moment, I am capturing both like this: ``` output=$(mycommand 2>&1) ``` I then need to check the exit value of mycommand....
What version of `bash` are you using? The capture of the output has *zero* effect on the return code with my version, `4.1.5`: ``` pax> false; echo $? 1 pax> echo $? 0 pax> x=$(false 2>&1) ; echo $? 1 ``` It's not always a good idea to rely on standard error being non-empty to detect errors. Many programs don't outpu...
44693485
Where do I set environment variables for Django?
18
2017-06-22 07:57:34
<p>everyone!</p> <p>Django 1.11 + PostgreSQL 9.6 + Gunicorn + Ubuntu 16.04 in AWS</p> <p>I want to set environment variables for sensitive info.(django secret key, DB password...) </p> <p>I studied many articles about setting ways. </p> <p>But when I tried os.environ['env_name'], </p> <ol> <li><p>.bashrc: Not work...
46,430
3,586,239
2022-08-02 05:15:52
44,693,580
11
2017-06-22 08:01:43
7,925,166
2017-06-22 08:01:43
https://stackoverflow.com/q/44693485
https://stackoverflow.com/a/44693580
<p>create a file called .bashrc in your server</p> <pre><code>export('the_name_in_bashrc', some_value) </code></pre> <p>then in the <code>settings.py</code></p> <pre><code>import os some_variable = os.environ.get('the_name_in_bashrc') </code></pre>
<p>create a file called .bashrc in your server</p> <pre><code>export('the_name_in_bashrc', some_value) </code></pre> <p>then in the <code>settings.py</code></p> <pre><code>import os some_variable = os.environ.get('the_name_in_bashrc') </code></pre>
243, 387, 549, 9013
bash, django, environment-variables, ubuntu
<h1>Where do I set environment variables for Django?</h1> <p>everyone!</p> <p>Django 1.11 + PostgreSQL 9.6 + Gunicorn + Ubuntu 16.04 in AWS</p> <p>I want to set environment variables for sensitive info.(django secret key, DB password...) </p> <p>I studied many articles about setting ways. </p> <p>But when I tried o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,204
bash
# Where do I set environment variables for Django? everyone! Django 1.11 + PostgreSQL 9.6 + Gunicorn + Ubuntu 16.04 in AWS I want to set environment variables for sensitive info.(django secret key, DB password...) I studied many articles about setting ways. But when I tried os.environ['env_name'], 1. .bashrc: Not...
create a file called .bashrc in your server ``` export('the_name_in_bashrc', some_value) ``` then in the `settings.py` ``` import os some_variable = os.environ.get('the_name_in_bashrc') ```
38269209
Using Get-ChildItem -Exclude or -Include returns nothing
18
2016-07-08 14:31:09
<p>I have a list in my C: directory that has many files. If I try to run an <code>-Exclude</code> on it, I get no returns. Same with <code>-Include</code>. If I use <code>-Filter</code>, it returns what I expected to get back. Am I not understanding what it should be doing?</p> <p>Here is an example of what I am runnin...
15,725
568,352
2025-01-06 21:53:56
38,269,316
11
2016-07-08 14:37:08
2,486,496
2016-07-08 14:37:08
https://stackoverflow.com/q/38269209
https://stackoverflow.com/a/38269316
<pre><code>Get-ChildItem -Path "C:\*" -Include "*.txt" </code></pre> <p>This example, of how <code>-Include</code> should work, will give you the results you were expecting. Note that I provided a wildcard in the path parameter as well, to explicitly define the path as "any file in the root C:" as opposed to "C:" its...
<pre><code>Get-ChildItem -Path "C:\*" -Include "*.txt" </code></pre> <p>This example, of how <code>-Include</code> should work, will give you the results you were expecting. Note that I provided a wildcard in the path parameter as well, to explicitly define the path as "any file in the root C:" as opposed to "C:" its...
526, 3889, 5997, 95686
glob, powershell, powershell-4.0, wildcard
<h1>Using Get-ChildItem -Exclude or -Include returns nothing</h1> <p>I have a list in my C: directory that has many files. If I try to run an <code>-Exclude</code> on it, I get no returns. Same with <code>-Include</code>. If I use <code>-Filter</code>, it returns what I expected to get back. Am I not understanding what...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,205
bash
# Using Get-ChildItem -Exclude or -Include returns nothing I have a list in my C: directory that has many files. If I try to run an `-Exclude` on it, I get no returns. Same with `-Include`. If I use `-Filter`, it returns what I expected to get back. Am I not understanding what it should be doing? Here is an example o...
``` Get-ChildItem -Path "C:\*" -Include "*.txt" ``` This example, of how `-Include` should work, will give you the results you were expecting. Note that I provided a wildcard in the path parameter as well, to explicitly define the path as "any file in the root C:" as opposed to "C:" itself. Source: <https://technet.m...
32443522
Triangular background for bash PS1 prompt
18
2015-09-07 17:22:48
<p>I am trying to get a triangular background for bash PS1 prompt. <a href="https://i.sstatic.net/g9rGk.png" rel="noreferrer"><img src="https://i.sstatic.net/g9rGk.png" alt="as shown here"></a></p> <p>I have tried the existing library called <code>powerline</code> but it seems to be heavy for my ageing laptop. I have ...
14,712
2,005,559
2025-01-19 15:06:34
32,445,282
11
2015-09-07 19:56:22
3,503,302
2020-06-08 08:26:28
https://stackoverflow.com/q/32443522
https://stackoverflow.com/a/32445282
<p>You need to have powerline patched fonts installed. <a href="https://github.com/powerline/fonts" rel="nofollow noreferrer">Get them here</a></p> <p>And you need to configure your terminal to use them. (this ofc depends on your terminal but probably something like settings -> appearance -> fonts) </p> <p>I've done ...
<p>You need to have powerline patched fonts installed. <a href="https://github.com/powerline/fonts" rel="nofollow noreferrer">Get them here</a></p> <p>And you need to configure your terminal to use them. (this ofc depends on your terminal but probably something like settings -> appearance -> fonts) </p> <p>I've done ...
387, 5003, 53034
bash, prompt, ps1
<h1>Triangular background for bash PS1 prompt</h1> <p>I am trying to get a triangular background for bash PS1 prompt. <a href="https://i.sstatic.net/g9rGk.png" rel="noreferrer"><img src="https://i.sstatic.net/g9rGk.png" alt="as shown here"></a></p> <p>I have tried the existing library called <code>powerline</code> but...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,206
bash
# Triangular background for bash PS1 prompt I am trying to get a triangular background for bash PS1 prompt. [![as shown here](https://i.sstatic.net/g9rGk.png)](https://i.sstatic.net/g9rGk.png) I have tried the existing library called `powerline` but it seems to be heavy for my ageing laptop. I have managed to get the...
You need to have powerline patched fonts installed. [Get them here](https://github.com/powerline/fonts) And you need to configure your terminal to use them. (this ofc depends on your terminal but probably something like settings -> appearance -> fonts) I've done something similar if you want a startingpoint: [sbp](ht...
22389570
let vs expr vs double parenthesis arithmetic in shell
18
2014-03-13 19:58:35
<p>When I was first learning shell scripting, a lot of examples I saw used <code>let</code> for basic arithmetic, but later I found out that some environments don't present <code>let</code> as a built-in, but support use of <code>expr</code> instead (though it's significantly slower).</p> <p>However, it is also possib...
5,200
2,187,548
2016-06-08 03:26:20
22,389,873
11
2014-03-13 20:13:20
1,126,841
2014-03-13 20:13:20
https://stackoverflow.com/q/22389570
https://stackoverflow.com/a/22389873
<p><code>$(( ... ))</code> is defined in the POSIX standard, which is probably as portable as you need to be.</p>
<p><code>$(( ... ))</code> is defined in the POSIX standard, which is probably as portable as you need to be.</p>
259, 390, 5481
arithmetic-expressions, math, shell
<h1>let vs expr vs double parenthesis arithmetic in shell</h1> <p>When I was first learning shell scripting, a lot of examples I saw used <code>let</code> for basic arithmetic, but later I found out that some environments don't present <code>let</code> as a built-in, but support use of <code>expr</code> instead (though...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,207
bash
# let vs expr vs double parenthesis arithmetic in shell When I was first learning shell scripting, a lot of examples I saw used `let` for basic arithmetic, but later I found out that some environments don't present `let` as a built-in, but support use of `expr` instead (though it's significantly slower). However, it ...
`$(( ... ))` is defined in the POSIX standard, which is probably as portable as you need to be.
22045175
Remove non printing chars from bash variable
18
2014-02-26 14:59:54
<p>I have some variable <code>$a</code>. This variable have non printing characters (carriage return ^M).</p> <pre><code>&gt;echo $a some words for compgen &gt;a+="END" &gt;echo $a ENDe words for compgen </code></pre> <p>How I can remove that char? I know that <code>echo "$a"</code> display it correct. But it's not ...
35,640
1,864,033
2021-12-19 23:57:37
22,046,839
11
2014-02-26 16:06:29
1,126,841
2014-02-26 16:06:29
https://stackoverflow.com/q/22045175
https://stackoverflow.com/a/22046839
<p>To remove just the trailing carriage return from <code>a</code>, use</p> <pre><code>a=${a%$'\r'} </code></pre>
<p>To remove just the trailing carriage return from <code>a</code>, use</p> <pre><code>a=${a%$'\r'} </code></pre>
276, 387
bash, variables
<h1>Remove non printing chars from bash variable</h1> <p>I have some variable <code>$a</code>. This variable have non printing characters (carriage return ^M).</p> <pre><code>&gt;echo $a some words for compgen &gt;a+="END" &gt;echo $a ENDe words for compgen </code></pre> <p>How I can remove that char? I know that <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,208
bash
# Remove non printing chars from bash variable I have some variable `$a`. This variable have non printing characters (carriage return ^M). ``` >echo $a some words for compgen >a+="END" >echo $a ENDe words for compgen ``` How I can remove that char? I know that `echo "$a"` display it correct. But it's not a solution ...
To remove just the trailing carriage return from `a`, use ``` a=${a%$'\r'} ```
20961063
Passing through -Verbose status to module cmdlets
18
2014-01-06 23:14:13
<p>I have a PowerShell module that encapsulates a number of commonly-used business functions. It's not generally called from the console; rather, its functions are called by automated deployment and management scripts that import the module.</p> <p>The module incorporates a logging function that writes to both a centr...
15,530
907,901
2018-12-16 16:06:20
20,961,341
11
2014-01-06 23:37:30
1,105,996
2018-12-16 16:00:56
https://stackoverflow.com/q/20961063
https://stackoverflow.com/a/20961341
<p>There is a variable named $VerbosePreference you can check to see how Verbose output should be handled. However, scripts loaded into a separate scope is giving you the issues. If you read the <code>Get-Help about_scopes</code>, you'll see:</p> <blockquote> <p>Script: <br/> The scope that is created while a sc...
<p>There is a variable named $VerbosePreference you can check to see how Verbose output should be handled. However, scripts loaded into a separate scope is giving you the issues. If you read the <code>Get-Help about_scopes</code>, you'll see:</p> <blockquote> <p>Script: <br/> The scope that is created while a sc...
526, 67488
powershell, powershell-module
<h1>Passing through -Verbose status to module cmdlets</h1> <p>I have a PowerShell module that encapsulates a number of commonly-used business functions. It's not generally called from the console; rather, its functions are called by automated deployment and management scripts that import the module.</p> <p>The module ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,209
bash
# Passing through -Verbose status to module cmdlets I have a PowerShell module that encapsulates a number of commonly-used business functions. It's not generally called from the console; rather, its functions are called by automated deployment and management scripts that import the module. The module incorporates a l...
There is a variable named $VerbosePreference you can check to see how Verbose output should be handled. However, scripts loaded into a separate scope is giving you the issues. If you read the `Get-Help about_scopes`, you'll see: > Script: > The scope that is created while a script file runs. > Only the commands in ...
15139552
Save hash table in PowerShell object notation (PSON)
18
2013-02-28 15:37:17
<p>The question <a href="https://stackoverflow.com/questions/10743892/loading-a-powershell-hashtable-from-a-file">Loading a PowerShell hashtable from a file?</a> documents how to load a file that contains a hashtable in PSON format into a variable, but how does one save a hashtable to a file in PSON format?</p> <p>Has...
12,332
134,367
2022-08-31 06:35:17
15,140,028
11
2013-02-28 16:00:49
9,833
2013-02-28 16:00:49
https://stackoverflow.com/q/15139552
https://stackoverflow.com/a/15140028
<p>Try the <code>*-CliXml</code> cmdlets. To save the object:</p> <pre><code>@{ "name" = "report 0" "parameters" = @( @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4}, @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'} ) } | Export-Clixml -Pat...
<p>Try the <code>*-CliXml</code> cmdlets. To save the object:</p> <pre><code>@{ "name" = "report 0" "parameters" = @( @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4}, @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'} ) } | Export-Clixml -Pat...
526, 1125, 2095, 24067
expression, powershell, powershell-2.0, serialization
<h1>Save hash table in PowerShell object notation (PSON)</h1> <p>The question <a href="https://stackoverflow.com/questions/10743892/loading-a-powershell-hashtable-from-a-file">Loading a PowerShell hashtable from a file?</a> documents how to load a file that contains a hashtable in PSON format into a variable, but how d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,210
bash
# Save hash table in PowerShell object notation (PSON) The question [Loading a PowerShell hashtable from a file?](https://stackoverflow.com/questions/10743892/loading-a-powershell-hashtable-from-a-file) documents how to load a file that contains a hashtable in PSON format into a variable, but how does one save a hasht...
Try the `*-CliXml` cmdlets. To save the object: ``` @{ "name" = "report 0" "parameters" = @( @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4}, @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'} ) } | Export-Clixml -Path c:\hash.xml ``` To rea...
4468824
"Command not found" when attempting integer equality in bash
18
2010-12-17 08:35:15
<p>Ok, this is probably going to be ultra obvious to anyone that has spent more time with bash than I have.</p> <p>I'm trying to run this code:</p> <pre><code>#!/bin/bash if ["1" -eq "2"] then echo "True" else echo "False" fi </code></pre> <p>but when I execute the file, it sends back </p> <pre><code>./te...
47,706
27,290
2013-04-02 23:50:08
4,468,835
11
2010-12-17 08:38:08
169,442
2010-12-17 08:38:08
https://stackoverflow.com/q/4468824
https://stackoverflow.com/a/4468835
<p>yep eq is used only for arithmetic comparaisons. </p> <p>for string comparison you have to use <code>=</code></p> <pre><code>#!/bin/bash if [ "1" = "2" ] then echo "True" else echo "False" fi </code></pre> <p>plus you need some space around the brackets. </p>
<p>yep eq is used only for arithmetic comparaisons. </p> <p>for string comparison you have to use <code>=</code></p> <pre><code>#!/bin/bash if [ "1" = "2" ] then echo "True" else echo "False" fi </code></pre> <p>plus you need some space around the brackets. </p>
387
bash
<h1>"Command not found" when attempting integer equality in bash</h1> <p>Ok, this is probably going to be ultra obvious to anyone that has spent more time with bash than I have.</p> <p>I'm trying to run this code:</p> <pre><code>#!/bin/bash if ["1" -eq "2"] then echo "True" else echo "False" fi </code></pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,211
bash
# "Command not found" when attempting integer equality in bash Ok, this is probably going to be ultra obvious to anyone that has spent more time with bash than I have. I'm trying to run this code: ``` #!/bin/bash if ["1" -eq "2"] then echo "True" else echo "False" fi ``` but when I execute the file, it se...
yep eq is used only for arithmetic comparaisons. for string comparison you have to use `=` ``` #!/bin/bash if [ "1" = "2" ] then echo "True" else echo "False" fi ``` plus you need some space around the brackets.
3341482
In a makefile, how to get the relative path from one absolute path to another?
18
2010-07-27 07:25:36
<p>An example to illustrate my question:</p> <p>Top level makefile</p> <pre><code>rootdir = $(realpath .) export includedir = $(rootdir)/include default: @$(MAKE) --directory=$(rootdir)/src/libs/libfoo </code></pre> <p>Makefile for src/libfoo</p> <pre><code>currentdir = $(realpath .) includedir = $(function or ...
45,194
331,024
2022-07-30 19:13:18
3,342,259
11
2010-07-27 09:29:15
212,063
2010-07-27 09:29:15
https://stackoverflow.com/q/3341482
https://stackoverflow.com/a/3342259
<p>Doing what you want does not look easy. It may be possible using a lot of combined <code>$(if</code> in the makefile but not portable (gmake only) and cumbersome.</p> <p>IMHO, you are trying to solve a problem that you create yourself. Why don't you send the correct value of <code>includedir</code> as a relative pa...
<p>Doing what you want does not look easy. It may be possible using a lot of combined <code>$(if</code> in the makefile but not portable (gmake only) and cumbersome.</p> <p>IMHO, you are trying to solve a problem that you create yourself. Why don't you send the correct value of <code>includedir</code> as a relative pa...
18, 390, 4301, 6268
makefile, path, regex, shell
<h1>In a makefile, how to get the relative path from one absolute path to another?</h1> <p>An example to illustrate my question:</p> <p>Top level makefile</p> <pre><code>rootdir = $(realpath .) export includedir = $(rootdir)/include default: @$(MAKE) --directory=$(rootdir)/src/libs/libfoo </code></pre> <p>Makefi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,212
bash
# In a makefile, how to get the relative path from one absolute path to another? An example to illustrate my question: Top level makefile ``` rootdir = $(realpath .) export includedir = $(rootdir)/include default: @$(MAKE) --directory=$(rootdir)/src/libs/libfoo ``` Makefile for src/libfoo ``` currentdir = $(re...
Doing what you want does not look easy. It may be possible using a lot of combined `$(if` in the makefile but not portable (gmake only) and cumbersome. IMHO, you are trying to solve a problem that you create yourself. Why don't you send the correct value of `includedir` as a relative path from the Top-level Makefile? ...
63732583
Warning about Breaking changes in the cmdlet 'Get-AzKeyVaultSecret' SecretValueText deprecated Az4.6.1
17
2020-09-03 22:43:11
<p>I upgraded Az Powershell to 4.6.1 today and started seeing the below warning. The question I have is what I am supposed to do about this warning? I could mute the warning but that wouldn't help me prepare for this breaking change at all. I checked the Az 4.6.1 <a href="https://learn.microsoft.com/en-us/powershell/mo...
11,171
3,577,083
2021-01-25 19:52:12
64,879,647
11
2020-11-17 16:50:19
14,656,459
2020-11-17 16:50:19
https://stackoverflow.com/q/63732583
https://stackoverflow.com/a/64879647
<p>Microsoft documentation has now been updated This example is taken from the latest <a href="https://learn.microsoft.com/en-us/powershell/module/az.keyvault/get-azkeyvaultsecret?view=azps-5.0.0&amp;viewFallbackFrom=azps-4.6.1#example-5--get-the-plain-text-value-of-the-current-version-of-a-specific-secret" rel="norefe...
<p>Microsoft documentation has now been updated This example is taken from the latest <a href="https://learn.microsoft.com/en-us/powershell/module/az.keyvault/get-azkeyvaultsecret?view=azps-5.0.0&amp;viewFallbackFrom=azps-4.6.1#example-5--get-the-plain-text-value-of-the-current-version-of-a-specific-secret" rel="norefe...
14158, 81879
azure, azure-powershell
<h1>Warning about Breaking changes in the cmdlet 'Get-AzKeyVaultSecret' SecretValueText deprecated Az4.6.1</h1> <p>I upgraded Az Powershell to 4.6.1 today and started seeing the below warning. The question I have is what I am supposed to do about this warning? I could mute the warning but that wouldn't help me prepare ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,213
bash
# Warning about Breaking changes in the cmdlet 'Get-AzKeyVaultSecret' SecretValueText deprecated Az4.6.1 I upgraded Az Powershell to 4.6.1 today and started seeing the below warning. The question I have is what I am supposed to do about this warning? I could mute the warning but that wouldn't help me prepare for this ...
Microsoft documentation has now been updated This example is taken from the latest [docs](https://learn.microsoft.com/en-us/powershell/module/az.keyvault/get-azkeyvaultsecret?view=azps-5.0.0&viewFallbackFrom=azps-4.6.1#example-5--get-the-plain-text-value-of-the-current-version-of-a-specific-secret) ``` $secret = Get-A...
54411218
Docker why isn't $USER environment variable set
17
2019-01-28 22:28:34
<p>I'm doing a simple docker build where the image runs a script that assumes <code>$USER</code> is set, like it normally is in a bash shell.</p> <p>However, <code>$USER</code> is not set, when using <code>/bin/bash</code> or <code>/bin/bash --login</code>. Very easy to demonstrate using the latest <code>ubuntu</code...
18,104
659,866
2019-01-29 00:13:24
54,411,828
11
2019-01-28 23:34:08
10,008,173
2019-01-28 23:34:08
https://stackoverflow.com/q/54411218
https://stackoverflow.com/a/54411828
<p><a href="https://docs.docker.com/engine/reference/run/#env-environment-variables" rel="noreferrer">The only environment variables documented to be set</a> are <code>$HOME</code>, <code>$HOSTNAME</code>, <code>$PATH</code>, and (maybe) <code>$TERM</code>. (A <code>docker build</code> <code>RUN</code> step internally...
<p><a href="https://docs.docker.com/engine/reference/run/#env-environment-variables" rel="noreferrer">The only environment variables documented to be set</a> are <code>$HOME</code>, <code>$HOSTNAME</code>, <code>$PATH</code>, and (maybe) <code>$TERM</code>. (A <code>docker build</code> <code>RUN</code> step internally...
387, 549, 90304
bash, docker, ubuntu
<h1>Docker why isn't $USER environment variable set</h1> <p>I'm doing a simple docker build where the image runs a script that assumes <code>$USER</code> is set, like it normally is in a bash shell.</p> <p>However, <code>$USER</code> is not set, when using <code>/bin/bash</code> or <code>/bin/bash --login</code>. Ver...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,214
bash
# Docker why isn't $USER environment variable set I'm doing a simple docker build where the image runs a script that assumes `$USER` is set, like it normally is in a bash shell. However, `$USER` is not set, when using `/bin/bash` or `/bin/bash --login`. Very easy to demonstrate using the latest `ubuntu` ``` $ docker...
[The only environment variables documented to be set](https://docs.docker.com/engine/reference/run/#env-environment-variables) are `$HOME`, `$HOSTNAME`, `$PATH`, and (maybe) `$TERM`. (A `docker build` `RUN` step internally does the equivalent of `docker run`.) If you need other variables set you can use the `ENV` direc...
44642227
How do I resolve ffmpeg concat command error "unknown keyword..."?
17
2017-06-20 01:10:17
<p>I am trying to concatenate two video files using ffmpeg, and I am receiving an error.</p> <p>To eliminate compatibility issues between the two videos, I have been concatenating the same video with itself, and the same error persists.</p> <pre><code>ffmpeg \ -f concat \ -safe 0 \ -i intro_prepped.avi intro_prep...
41,664
3,321,579
2023-12-06 08:28:28
44,687,573
11
2017-06-21 23:07:38
7,705,781
2022-02-22 00:13:43
https://stackoverflow.com/q/44642227
https://stackoverflow.com/a/44687573
<p>Docs for several ways of concatenating files: <a href="https://trac.ffmpeg.org/wiki/Concatenate" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Concatenate</a></p> <p>Here's a command I use to concatenate videos:</p> <pre><code>ffmpeg \ -i &quot;concat:input1.avi|input2.avi|input3.avi&quot; \ -c:a copy \...
<p>Docs for several ways of concatenating files: <a href="https://trac.ffmpeg.org/wiki/Concatenate" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Concatenate</a></p> <p>Here's a command I use to concatenate videos:</p> <pre><code>ffmpeg \ -i &quot;concat:input1.avi|input2.avi|input3.avi&quot; \ -c:a copy \...
390, 1231, 3847, 6050
command-line, concatenation, ffmpeg, shell
<h1>How do I resolve ffmpeg concat command error "unknown keyword..."?</h1> <p>I am trying to concatenate two video files using ffmpeg, and I am receiving an error.</p> <p>To eliminate compatibility issues between the two videos, I have been concatenating the same video with itself, and the same error persists.</p> <pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,215
bash
# How do I resolve ffmpeg concat command error "unknown keyword..."? I am trying to concatenate two video files using ffmpeg, and I am receiving an error. To eliminate compatibility issues between the two videos, I have been concatenating the same video with itself, and the same error persists. ``` ffmpeg \ -f con...
Docs for several ways of concatenating files: <https://trac.ffmpeg.org/wiki/Concatenate> Here's a command I use to concatenate videos: ``` ffmpeg \ -i "concat:input1.avi|input2.avi|input3.avi" \ -c:a copy \ -c:v copy \ output.avi ```
34901807
What pattern does .gitignore follow?
17
2016-01-20 13:47:19
<p>Here is the content of my current directory.</p> <pre><code>$ ls foo.foo $ ls -a . .. .bar.foo .foo foo.foo .gitignore </code></pre> <p>Then I turn this directory into a git repository.</p> <pre><code>$ git init Initialized empty Git repository in /home/lone/foo/.git/ $ ls -a . .. .bar.foo .foo foo.foo ...
1,617
1,175,080
2016-01-29 09:00:18
34,960,504
11
2016-01-23 06:44:34
6,309
2016-01-29 09:00:18
https://stackoverflow.com/q/34901807
https://stackoverflow.com/a/34960504
<p><code>gitignore</code> use of '<code>*</code>' follows the <a href="https://github.com/git/git/blob/3ee1e0fe11e2eb617170d0487fccfffc67f2b82b/Documentation/glossary-content.txt#L358-L383" rel="noreferrer">glob convention</a>:</p> <blockquote> <p>Git treats the pattern as a shell glob suitable for consumption by <stro...
<p><code>gitignore</code> use of '<code>*</code>' follows the <a href="https://github.com/git/git/blob/3ee1e0fe11e2eb617170d0487fccfffc67f2b82b/Documentation/glossary-content.txt#L358-L383" rel="noreferrer">glob convention</a>:</p> <blockquote> <p>Git treats the pattern as a shell glob suitable for consumption by <stro...
119, 390, 3889
git, glob, shell
<h1>What pattern does .gitignore follow?</h1> <p>Here is the content of my current directory.</p> <pre><code>$ ls foo.foo $ ls -a . .. .bar.foo .foo foo.foo .gitignore </code></pre> <p>Then I turn this directory into a git repository.</p> <pre><code>$ git init Initialized empty Git repository in /home/lone/foo/...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,216
bash
# What pattern does .gitignore follow? Here is the content of my current directory. ``` $ ls foo.foo $ ls -a . .. .bar.foo .foo foo.foo .gitignore ``` Then I turn this directory into a git repository. ``` $ git init Initialized empty Git repository in /home/lone/foo/.git/ $ ls -a . .. .bar.foo .foo foo.foo...
`gitignore` use of '`*`' follows the [glob convention](https://github.com/git/git/blob/3ee1e0fe11e2eb617170d0487fccfffc67f2b82b/Documentation/glossary-content.txt#L358-L383): > Git treats the pattern as a shell glob suitable for consumption by **[`fnmatch`(3)](http://linux.die.net/man/3/fnmatch)** with the **[`FNM_PAT...
32906767
How to group Get-ChildItem -Recurse results in one output table?
17
2015-10-02 12:02:40
<p>I'm using the following Powershell command:</p> <pre><code>Get-ChildItem -Recurse *.txt </code></pre> <p>But if there's multiple results the output will be like this:</p> <pre class="lang-none prettyprint-override"><code> Directory: C:\TestFolder\myfolder\ Mode LastWriteTime Length Name ---- ...
9,596
419,956
2017-09-09 11:17:05
32,907,515
11
2015-10-02 12:46:41
3,829,407
2015-10-02 13:14:35
https://stackoverflow.com/q/32906767
https://stackoverflow.com/a/32907515
<p>PowerShell has its own way of displaying <code>System.IO.DirectoryInfo</code> and <code>System.IO.FileInfo</code> objects. If you don't want to see that then you just need to use <code>Select-Object</code>.</p> <pre><code>Get-ChildItem -Recurse c:\temp | select Mode,LastWriteTime,Length,Directory,Name </code></pre>...
<p>PowerShell has its own way of displaying <code>System.IO.DirectoryInfo</code> and <code>System.IO.FileInfo</code> objects. If you don't want to see that then you just need to use <code>Select-Object</code>.</p> <pre><code>Get-ChildItem -Recurse c:\temp | select Mode,LastWriteTime,Length,Directory,Name </code></pre>...
526
powershell
<h1>How to group Get-ChildItem -Recurse results in one output table?</h1> <p>I'm using the following Powershell command:</p> <pre><code>Get-ChildItem -Recurse *.txt </code></pre> <p>But if there's multiple results the output will be like this:</p> <pre class="lang-none prettyprint-override"><code> Directory: C:...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,217
bash
# How to group Get-ChildItem -Recurse results in one output table? I'm using the following Powershell command: ``` Get-ChildItem -Recurse *.txt ``` But if there's multiple results the output will be like this: ``` Directory: C:\TestFolder\myfolder\ Mode LastWriteTime Length Name ---- ------...
PowerShell has its own way of displaying `System.IO.DirectoryInfo` and `System.IO.FileInfo` objects. If you don't want to see that then you just need to use `Select-Object`. ``` Get-ChildItem -Recurse c:\temp | select Mode,LastWriteTime,Length,Directory,Name ``` `Group-Object` is completely unnecessary. Given your ne...
19536241
Calling Excel macros from PowerShell with arguments
17
2013-10-23 08:11:20
<p>Using Powershell it's rather easy to call Excel macro's from a script, for example with a script like <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/01/13/how-do-i-run-an-office-excel-macro-on-multiple-workbooks.aspx?Redirected=true" rel="noreferrer">this</a>:</p> <pre><code>$excel = new-object -c...
47,510
862,288
2016-05-24 21:14:24
19,537,999
11
2013-10-23 09:31:53
1,630,171
2013-10-23 09:31:53
https://stackoverflow.com/q/19536241
https://stackoverflow.com/a/19537999
<p>You can run a macro with arguments like this:</p> <pre><code>$excel.Run('CreateChart', 'arg1', 'arg2', ...) </code></pre>
<p>You can run a macro with arguments like this:</p> <pre><code>$excel.Run('CreateChart', 'arg1', 'arg2', ...) </code></pre>
522, 526, 1449
excel, powershell, vba
<h1>Calling Excel macros from PowerShell with arguments</h1> <p>Using Powershell it's rather easy to call Excel macro's from a script, for example with a script like <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2009/01/13/how-do-i-run-an-office-excel-macro-on-multiple-workbooks.aspx?Redirected=true" rel=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,218
bash
# Calling Excel macros from PowerShell with arguments Using Powershell it's rather easy to call Excel macro's from a script, for example with a script like [this](http://blogs.technet.com/b/heyscriptingguy/archive/2009/01/13/how-do-i-run-an-office-excel-macro-on-multiple-workbooks.aspx?Redirected=true): ``` $excel = ...
You can run a macro with arguments like this: ``` $excel.Run('CreateChart', 'arg1', 'arg2', ...) ```
12413848
what does $* mean in a shell script
17
2012-09-13 19:57:21
<p>What does <code>$*</code> exactly mean in a shell script?</p> <p>For example consider the following code snippet</p> <pre><code>$JAVA_HOME/bin/java/com/test/Testclass $* </code></pre>
22,336
1,163,452
2016-05-12 02:42:24
12,413,891
11
2012-09-13 20:00:23
20,862
2012-09-13 20:00:23
https://stackoverflow.com/q/12413848
https://stackoverflow.com/a/12413891
<p>It means all the arguments passed to the script or function, split by word.</p> <p>It is usually wrong and should be replaced by <code>"$@"</code>, which separates the arguments properly.</p>
<p>It means all the arguments passed to the script or function, split by word.</p> <p>It is usually wrong and should be replaced by <code>"$@"</code>, which separates the arguments properly.</p>
34, 58, 387, 390, 12725
bash, linux, shell, special-characters, unix
<h1>what does $* mean in a shell script</h1> <p>What does <code>$*</code> exactly mean in a shell script?</p> <p>For example consider the following code snippet</p> <pre><code>$JAVA_HOME/bin/java/com/test/Testclass $* </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,219
bash
# what does $* mean in a shell script What does `$*` exactly mean in a shell script? For example consider the following code snippet ``` $JAVA_HOME/bin/java/com/test/Testclass $* ```
It means all the arguments passed to the script or function, split by word. It is usually wrong and should be replaced by `"$@"`, which separates the arguments properly.
10062420
Pass multi-word arguments to a bash function
17
2012-04-08 11:21:27
<p>Inside a bash script function, I need to work with the command-line arguments of the script, and also with another list of arguments. So I'm trying to pass two argument lists to a function, the problem is that multi-word arguments get split.</p> <pre><code>function params() { for PARAM in $1; do echo "$...
22,154
1,088,790
2018-11-09 14:40:27
10,062,775
11
2012-04-08 12:25:40
313,821
2012-04-08 12:42:38
https://stackoverflow.com/q/10062420
https://stackoverflow.com/a/10062775
<pre><code>function params() { arg=("$@") for ((i=1;i&lt;=$1;i++)) ;do echo "${arg[i]}" done echo . for ((;i&lt;=$#-$1+2;i++)) ;do echo "${arg[i]}" done } items=(w x 'z t') params $# "$@" "${items[@]}" </code></pre> <p>Assuming you call your script with args <code>a b 'c d'</code>, ...
<pre><code>function params() { arg=("$@") for ((i=1;i&lt;=$1;i++)) ;do echo "${arg[i]}" done echo . for ((;i&lt;=$#-$1+2;i++)) ;do echo "${arg[i]}" done } items=(w x 'z t') params $# "$@" "${items[@]}" </code></pre> <p>Assuming you call your script with args <code>a b 'c d'</code>, ...
360, 387, 2193, 11402
bash, cpu-word, parameters, split
<h1>Pass multi-word arguments to a bash function</h1> <p>Inside a bash script function, I need to work with the command-line arguments of the script, and also with another list of arguments. So I'm trying to pass two argument lists to a function, the problem is that multi-word arguments get split.</p> <pre><code>funct...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,220
bash
# Pass multi-word arguments to a bash function Inside a bash script function, I need to work with the command-line arguments of the script, and also with another list of arguments. So I'm trying to pass two argument lists to a function, the problem is that multi-word arguments get split. ``` function params() { f...
``` function params() { arg=("$@") for ((i=1;i<=$1;i++)) ;do echo "${arg[i]}" done echo . for ((;i<=$#-$1+2;i++)) ;do echo "${arg[i]}" done } items=(w x 'z t') params $# "$@" "${items[@]}" ``` Assuming you call your script with args `a b 'c d'`, the output is: ``` a b c d . x y z t...
2900707
Lazy Evaluation in Bash
17
2010-05-24 22:16:11
<p>Is there more elegant way of doing lazy evaluation than the following:</p> <pre> pattern='$x and $y' x=1 y=2 eval "echo $pattern" </pre> <p>results:</p> <pre> 1 and 2 </pre> <p>It works but <code>eval "echo ..."</code> just feels sloppy and may be insecure in some way. Is there a better way to do this in Bash?<...
14,965
125,380
2024-10-28 04:32:16
2,959,276
11
2010-06-02 15:45:27
188,031
2019-12-12 18:20:48
https://stackoverflow.com/q/2900707
https://stackoverflow.com/a/2959276
<p>You can use the command <a href="https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html" rel="noreferrer">envsubst</a> from <a href="https://www.gnu.org/software/gettext/" rel="noreferrer">gettext</a>, for example:</p> <pre><code>$ pattern='x=$x and y=$y' $ x=1 y=2 envsubst &lt;&lt;&lt; $pat...
<p>You can use the command <a href="https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html" rel="noreferrer">envsubst</a> from <a href="https://www.gnu.org/software/gettext/" rel="noreferrer">gettext</a>, for example:</p> <pre><code>$ pattern='x=$x and y=$y' $ x=1 y=2 envsubst &lt;&lt;&lt; $pat...
387, 13918
bash, lazy-evaluation
<h1>Lazy Evaluation in Bash</h1> <p>Is there more elegant way of doing lazy evaluation than the following:</p> <pre> pattern='$x and $y' x=1 y=2 eval "echo $pattern" </pre> <p>results:</p> <pre> 1 and 2 </pre> <p>It works but <code>eval "echo ..."</code> just feels sloppy and may be insecure in some way. Is there ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,221
bash
# Lazy Evaluation in Bash Is there more elegant way of doing lazy evaluation than the following: ``` pattern='$x and $y' x=1 y=2 eval "echo $pattern" ``` results: ``` 1 and 2 ``` It works but `eval "echo ..."` just feels sloppy and may be insecure in some way. Is there a better way to do this in Bash?
You can use the command [envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) from [gettext](https://www.gnu.org/software/gettext/), for example: ``` $ pattern='x=$x and y=$y' $ x=1 y=2 envsubst <<< $pattern x=1 and y=2 ```
1461331
Writing my own shell... stuck on pipes?
17
2009-09-22 17:06:29
<p>For the past few days I have been attempting to write my own shell implementation but I seem to have gotten stuck on getting pipes to work properly. I am able to parse a line and fork off the commands between the pipes (ex: ls | sort) individually but can't seem to get them to pipe input from one into the other.</p...
20,923
14,013
2015-01-09 15:52:33
1,469,750
11
2009-09-24 04:17:14
25,507
2009-09-24 04:17:14
https://stackoverflow.com/q/1461331
https://stackoverflow.com/a/1469750
<p>First suggestion: Symbolic constants are better than magic numbers.</p> <pre><code>const int PIPE_READ = 0; const int PIPE_WRITE = 1; int fd[2]; pipe(fd); // Now you can refer to fd[PIPE_READ] and fd[PIPE_WRITE]. </code></pre> <p>Second suggestion: Take a step back and think about what you're trying to accomplis...
<p>First suggestion: Symbolic constants are better than magic numbers.</p> <pre><code>const int PIPE_READ = 0; const int PIPE_WRITE = 1; int fd[2]; pipe(fd); // Now you can refer to fd[PIPE_READ] and fd[PIPE_WRITE]. </code></pre> <p>Second suggestion: Take a step back and think about what you're trying to accomplis...
10, 34, 390, 5813
c++, pipe, shell, unix
<h1>Writing my own shell... stuck on pipes?</h1> <p>For the past few days I have been attempting to write my own shell implementation but I seem to have gotten stuck on getting pipes to work properly. I am able to parse a line and fork off the commands between the pipes (ex: ls | sort) individually but can't seem to g...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,222
bash
# Writing my own shell... stuck on pipes? For the past few days I have been attempting to write my own shell implementation but I seem to have gotten stuck on getting pipes to work properly. I am able to parse a line and fork off the commands between the pipes (ex: ls | sort) individually but can't seem to get them to...
First suggestion: Symbolic constants are better than magic numbers. ``` const int PIPE_READ = 0; const int PIPE_WRITE = 1; int fd[2]; pipe(fd); // Now you can refer to fd[PIPE_READ] and fd[PIPE_WRITE]. ``` Second suggestion: Take a step back and think about what you're trying to accomplish. You want to spawn two pro...
49594391
Aws Ec2 run script program at startup
16
2018-04-01 03:01:55
<p>There is a method to setup an EC2 machine to execute Kafka starting script on startup? I use also java Aws SDK, so I accept both solution for a program java that run command on EC2 instance and solutions for a bash script mode that run kafka script at startup.</p>
60,757
7,809,340
2022-03-15 12:48:11
49,594,897
11
2018-04-01 04:45:48
174,777
2018-04-01 04:45:48
https://stackoverflow.com/q/49594391
https://stackoverflow.com/a/49594897
<p>A script can be passed in the <strong>User Data</strong> property.</p> <p>If you are using the Amazon Linux AMI, and the first line of the script begins with <code>#!</code>, then the script will be executed <strong>the first time that the instance is started</strong>.</p> <p>For details, see: <a href="https://doc...
<p>A script can be passed in the <strong>User Data</strong> property.</p> <p>If you are using the Amazon Linux AMI, and the first line of the script begins with <code>#!</code>, then the script will be executed <strong>the first time that the instance is started</strong>.</p> <p>For details, see: <a href="https://doc...
387, 7457, 12375, 33388
amazon-ec2, amazon-web-services, bash, startup
<h1>Aws Ec2 run script program at startup</h1> <p>There is a method to setup an EC2 machine to execute Kafka starting script on startup? I use also java Aws SDK, so I accept both solution for a program java that run command on EC2 instance and solutions for a bash script mode that run kafka script at startup.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,223
bash
# Aws Ec2 run script program at startup There is a method to setup an EC2 machine to execute Kafka starting script on startup? I use also java Aws SDK, so I accept both solution for a program java that run command on EC2 instance and solutions for a bash script mode that run kafka script at startup.
A script can be passed in the **User Data** property. If you are using the Amazon Linux AMI, and the first line of the script begins with `#!`, then the script will be executed **the first time that the instance is started**. For details, see: [Running Commands on Your Linux Instance at Launch](https://docs.aws.amazo...
42218009
How to tell if any command in bash script failed (non-zero exit status)
16
2017-02-14 04:42:58
<p>I want to know whether any commands in a bash script exited with a non-zero status.</p> <p>I want something similar to <code>set -e</code> functionality, except that I don't want it to exit when a command exits with a non-zero status. I want it to run the whole script, and then I want to know that either:</p> <p>...
9,778
875,915
2022-11-10 18:01:41
42,219,754
11
2017-02-14 06:57:06
140,750
2022-11-10 18:01:41
https://stackoverflow.com/q/42218009
https://stackoverflow.com/a/42219754
<p>Set a trap on ERR:</p> <pre><code>#!/bin/bash err=0 trap 'err=1' ERR command1 command2 command3 test $err = 0 # Return non-zero if any command failed </code></pre> <p>You might even throw in a little introspection to get data about where the error occurred:</p> <pre><code>#!/bin/bash for i in 1 2 3; do eva...
<p>Set a trap on ERR:</p> <pre><code>#!/bin/bash err=0 trap 'err=1' ERR command1 command2 command3 test $err = 0 # Return non-zero if any command failed </code></pre> <p>You might even throw in a little introspection to get data about where the error occurred:</p> <pre><code>#!/bin/bash for i in 1 2 3; do eva...
387, 10021, 10327, 54576
bash, exit-code, exitstatus, sh
<h1>How to tell if any command in bash script failed (non-zero exit status)</h1> <p>I want to know whether any commands in a bash script exited with a non-zero status.</p> <p>I want something similar to <code>set -e</code> functionality, except that I don't want it to exit when a command exits with a non-zero status. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,224
bash
# How to tell if any command in bash script failed (non-zero exit status) I want to know whether any commands in a bash script exited with a non-zero status. I want something similar to `set -e` functionality, except that I don't want it to exit when a command exits with a non-zero status. I want it to run the whole ...
Set a trap on ERR: ``` #!/bin/bash err=0 trap 'err=1' ERR command1 command2 command3 test $err = 0 # Return non-zero if any command failed ``` You might even throw in a little introspection to get data about where the error occurred: ``` #!/bin/bash for i in 1 2 3; do eval "command$i() { echo command$i; te...
37567596
How do you check to see if Hyper-V is enabled using PowerShell?
16
2016-06-01 11:40:14
<p>I am trying to write a PowerShell script that checks the Windows Optional Features to see if Hyper-V is installed. However, my code is not working. Even when Hyper-V is disabled, the script outputs that it is already enabled.</p> <pre><code>#Requires -RunAsAdministrator # Get the Hyper-V feature and store it in $h...
55,031
6,409,103
2022-08-10 04:45:16
37,567,812
11
2016-06-01 11:49:45
978,511
2016-06-01 11:49:45
https://stackoverflow.com/q/37567596
https://stackoverflow.com/a/37567812
<p>I believe it has to do with your <code>if</code> condition, try this:</p> <pre><code>if($hyperv.State -eq "Enabled") </code></pre> <p>The <code>=</code> sign is not going to work, you need to do it PowerShell way</p>
<p>I believe it has to do with your <code>if</code> condition, try this:</p> <pre><code>if($hyperv.State -eq "Enabled") </code></pre> <p>The <code>=</code> sign is not going to work, you need to do it PowerShell way</p>
64, 526, 3055
hyper-v, powershell, windows
<h1>How do you check to see if Hyper-V is enabled using PowerShell?</h1> <p>I am trying to write a PowerShell script that checks the Windows Optional Features to see if Hyper-V is installed. However, my code is not working. Even when Hyper-V is disabled, the script outputs that it is already enabled.</p> <pre><code>#R...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,225
bash
# How do you check to see if Hyper-V is enabled using PowerShell? I am trying to write a PowerShell script that checks the Windows Optional Features to see if Hyper-V is installed. However, my code is not working. Even when Hyper-V is disabled, the script outputs that it is already enabled. ``` #Requires -RunAsAdmini...
I believe it has to do with your `if` condition, try this: ``` if($hyperv.State -eq "Enabled") ``` The `=` sign is not going to work, you need to do it PowerShell way
36746272
powershell extract text between two strings
16
2016-04-20 14:03:09
<p>I know this question has been asked before but I can't get any of the answers I have looked at to work. I have a JSON file which has thousands of lines and want to simply extract the text between two strings every time they appear (which is a lot).</p> <p>As a simple example my JSON would look like this:</p> <pre>...
75,888
5,296,090
2022-11-16 15:51:59
36,746,933
11
2016-04-20 14:26:24
2,064,981
2016-04-20 14:26:24
https://stackoverflow.com/q/36746272
https://stackoverflow.com/a/36746933
<p>The quick answer is - change your greedy capture <code>(.*)</code> to non greedy - <code>(.*?)</code>. That should do it.</p> <pre><code>customfield_11301(.*?)customfield_10730 </code></pre> <p>Otherwise the capture will eat as much as it can, resulting in it continuing 'til the last <code>customfield_10730</code>...
<p>The quick answer is - change your greedy capture <code>(.*)</code> to non greedy - <code>(.*?)</code>. That should do it.</p> <pre><code>customfield_11301(.*?)customfield_10730 </code></pre> <p>Otherwise the capture will eat as much as it can, resulting in it continuing 'til the last <code>customfield_10730</code>...
18, 526
powershell, regex
<h1>powershell extract text between two strings</h1> <p>I know this question has been asked before but I can't get any of the answers I have looked at to work. I have a JSON file which has thousands of lines and want to simply extract the text between two strings every time they appear (which is a lot).</p> <p>As a si...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,226
bash
# powershell extract text between two strings I know this question has been asked before but I can't get any of the answers I have looked at to work. I have a JSON file which has thousands of lines and want to simply extract the text between two strings every time they appear (which is a lot). As a simple example my ...
The quick answer is - change your greedy capture `(.*)` to non greedy - `(.*?)`. That should do it. ``` customfield_11301(.*?)customfield_10730 ``` Otherwise the capture will eat as much as it can, resulting in it continuing 'til the last `customfield_10730`. Regards
33961229
How to source additional file when launching bash
16
2015-11-27 16:12:12
<p>Bash will source automatic profiles such as <code>.bashrc</code>. <code>--rcfile</code> option can be used to override the automatic script. But I need to source <em>additional</em> personalized file (that's the automatic script plus another file) when launching the bash shell <strong>without touching ANY files in <...
13,669
2,175,604
2025-12-15 13:58:28
33,961,855
11
2015-11-27 16:55:10
675,568
2015-11-27 16:55:10
https://stackoverflow.com/q/33961229
https://stackoverflow.com/a/33961855
<p>Okay, so you want to run the user's normal <code>.bashrc</code>, followed by your own script, and you want to trigger this behavior in the way that <code>bash</code> is called, correct?</p> <p>The call:</p> <pre><code>/bin/bash --rcfile myscript </code></pre> <p>First line of <code>myscript</code>:</p> <pre><cod...
<p>Okay, so you want to run the user's normal <code>.bashrc</code>, followed by your own script, and you want to trigger this behavior in the way that <code>bash</code> is called, correct?</p> <p>The call:</p> <pre><code>/bin/bash --rcfile myscript </code></pre> <p>First line of <code>myscript</code>:</p> <pre><cod...
387
bash
<h1>How to source additional file when launching bash</h1> <p>Bash will source automatic profiles such as <code>.bashrc</code>. <code>--rcfile</code> option can be used to override the automatic script. But I need to source <em>additional</em> personalized file (that's the automatic script plus another file) when launc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,227
bash
# How to source additional file when launching bash Bash will source automatic profiles such as `.bashrc`. `--rcfile` option can be used to override the automatic script. But I need to source *additional* personalized file (that's the automatic script plus another file) when launching the bash shell **without touching...
Okay, so you want to run the user's normal `.bashrc`, followed by your own script, and you want to trigger this behavior in the way that `bash` is called, correct? The call: ``` /bin/bash --rcfile myscript ``` First line of `myscript`: ``` source $HOME/.bashrc ```
22783099
Unknown command: shell_plus and --settings
16
2014-04-01 10:24:55
<p>I try to run some</p> <pre><code>python manage.py shell_plus --notebook --settings=my_app.settings.andi </code></pre> <p>But it fails with error:</p> <pre><code>Unknown command: 'shell_plus' Type 'manage.py help' for usage. </code></pre> <p>I have ipython and shell_plus installed (from my pip freeze)</p> <pre><...
17,960
953,553
2019-05-27 01:39:17
22,783,238
11
2014-04-01 10:30:54
870,505
2014-04-01 10:37:02
https://stackoverflow.com/q/22783099
https://stackoverflow.com/a/22783238
<p>According to <a href="https://bitbucket.org/schinckel/django-shell/" rel="noreferrer">documentation</a>, you need to call it as <code>./manage.py shell+</code>.</p> <p>Probably you've mixed up this command with <a href="https://github.com/django-extensions/django-extensions/blob/master/docs/shell_plus.rst" rel="nor...
<p>According to <a href="https://bitbucket.org/schinckel/django-shell/" rel="noreferrer">documentation</a>, you need to call it as <code>./manage.py shell+</code>.</p> <p>Probably you've mixed up this command with <a href="https://github.com/django-extensions/django-extensions/blob/master/docs/shell_plus.rst" rel="nor...
16, 243, 55804
django, django-shell, python
<h1>Unknown command: shell_plus and --settings</h1> <p>I try to run some</p> <pre><code>python manage.py shell_plus --notebook --settings=my_app.settings.andi </code></pre> <p>But it fails with error:</p> <pre><code>Unknown command: 'shell_plus' Type 'manage.py help' for usage. </code></pre> <p>I have ipython and s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,228
bash
# Unknown command: shell_plus and --settings I try to run some ``` python manage.py shell_plus --notebook --settings=my_app.settings.andi ``` But it fails with error: ``` Unknown command: 'shell_plus' Type 'manage.py help' for usage. ``` I have ipython and shell_plus installed (from my pip freeze) ``` django-shel...
According to [documentation](https://bitbucket.org/schinckel/django-shell/), you need to call it as `./manage.py shell+`. Probably you've mixed up this command with [`shell_plus`](https://github.com/django-extensions/django-extensions/blob/master/docs/shell_plus.rst) from [`django-extensions`](https://github.com/djang...
20147878
How to sort,uniq and display line that appear more than X times
16
2013-11-22 14:58:08
<p>I have a file like this:</p> <pre><code>80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.1 80.13.178.3 80.13.178.3 80.13.178.3 80.13.178.4 80.13.178.4 80.13.178.7 </code></pre> <p>I need to display unique entries for repeated line (similar to uniq -d) but only entries that occur <em>more</em> than just tw...
12,412
3,022,172
2013-11-22 17:17:58
20,147,970
11
2013-11-22 15:03:03
171,318
2013-11-22 15:03:03
https://stackoverflow.com/q/20147878
https://stackoverflow.com/a/20147970
<p>With pure <code>awk</code>:</p> <pre><code>awk '{a[$0]++}END{for(i in a){if(a[i] &gt; 2){print i}}}' a.txt </code></pre> <p>It iterates over the file and counts the occurances of every IP. At the end of the file it outputs every IP which occurs more than 2 times.</p>
<p>With pure <code>awk</code>:</p> <pre><code>awk '{a[$0]++}END{for(i in a){if(a[i] &gt; 2){print i}}}' a.txt </code></pre> <p>It iterates over the file and counts the occurances of every IP. At the end of the file it outputs every IP which occurs more than 2 times.</p>
134, 387, 35617
bash, sorting, uniq
<h1>How to sort,uniq and display line that appear more than X times</h1> <p>I have a file like this:</p> <pre><code>80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.1 80.13.178.3 80.13.178.3 80.13.178.3 80.13.178.4 80.13.178.4 80.13.178.7 </code></pre> <p>I need to display unique entries for repeated line (s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,229
bash
# How to sort,uniq and display line that appear more than X times I have a file like this: ``` 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.1 80.13.178.3 80.13.178.3 80.13.178.3 80.13.178.4 80.13.178.4 80.13.178.7 ``` I need to display unique entries for repeated line (similar to uniq -d) but only entri...
With pure `awk`: ``` awk '{a[$0]++}END{for(i in a){if(a[i] > 2){print i}}}' a.txt ``` It iterates over the file and counts the occurances of every IP. At the end of the file it outputs every IP which occurs more than 2 times.
15430877
bash: xargs passing variable
16
2013-03-15 11:11:09
<p>How can a global script variable be passed to the command of xargs? I tried it this way:</p> <pre><code>TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test=$TEST' sh </code></pre> <p>Output:</p> <pre><code>passed=hallo test= </code></pre> <p>I know I could use the <code>{}</code> token but I need to do i...
47,391
1,110,642
2018-11-29 18:10:28
15,431,066
11
2013-03-15 11:20:16
1,386,359
2013-03-15 12:23:08
https://stackoverflow.com/q/15430877
https://stackoverflow.com/a/15431066
<p>Take variable <code>$TEST</code> out from the quotes:</p> <pre><code> TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test='$TEST sh </code></pre>
<p>Take variable <code>$TEST</code> out from the quotes:</p> <pre><code> TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test='$TEST sh </code></pre>
58, 276, 387, 10326
bash, linux, variables, xargs
<h1>bash: xargs passing variable</h1> <p>How can a global script variable be passed to the command of xargs? I tried it this way:</p> <pre><code>TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test=$TEST' sh </code></pre> <p>Output:</p> <pre><code>passed=hallo test= </code></pre> <p>I know I could use the <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,230
bash
# bash: xargs passing variable How can a global script variable be passed to the command of xargs? I tried it this way: ``` TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test=$TEST' sh ``` Output: ``` passed=hallo test= ``` I know I could use the `{}` token but I need to do it this way! I'm using `bash`.
Take variable `$TEST` out from the quotes: ``` TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test='$TEST sh ```
10679188
Casing arrow keys in bash
16
2012-05-21 03:25:31
<p>Is it possible to case arrow keys in a bash script to run a certain set of commands if the up/left arrow keys are pressed, and a certain set if the down/right arrow keys are pressed? I am trying to have a way to switch between users quickly by using the arrow keys while it is displaying the data, using this script t...
34,147
772,202
2022-10-28 03:44:20
10,680,015
11
2012-05-21 05:44:59
26,428
2012-05-21 05:44:59
https://stackoverflow.com/q/10679188
https://stackoverflow.com/a/10680015
<p>You can use <code>read -n 1</code> to read one character then use a <code>case</code> statement to choose an action to take based on the key.</p> <p>On problem is that arrow keys output more than one character and the sequence (and its length) varies from terminal to terminal.</p> <p>For example, on the terminal I...
<p>You can use <code>read -n 1</code> to read one character then use a <code>case</code> statement to choose an action to take based on the key.</p> <p>On problem is that arrow keys output more than one character and the sequence (and its length) varies from terminal to terminal.</p> <p>For example, on the terminal I...
387
bash
<h1>Casing arrow keys in bash</h1> <p>Is it possible to case arrow keys in a bash script to run a certain set of commands if the up/left arrow keys are pressed, and a certain set if the down/right arrow keys are pressed? I am trying to have a way to switch between users quickly by using the arrow keys while it is displ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,231
bash
# Casing arrow keys in bash Is it possible to case arrow keys in a bash script to run a certain set of commands if the up/left arrow keys are pressed, and a certain set if the down/right arrow keys are pressed? I am trying to have a way to switch between users quickly by using the arrow keys while it is displaying the...
You can use `read -n 1` to read one character then use a `case` statement to choose an action to take based on the key. On problem is that arrow keys output more than one character and the sequence (and its length) varies from terminal to terminal. For example, on the terminal I'm using, the right arrow outputs `^[[C...
9600549
Using a caret(^) when using Git for Windows in PowerShell
16
2012-03-07 11:24:58
<p>I'm using git at the command line with PowerShell, and I'm trying to use something like</p> <pre><code>git difftool HEAD^ </code></pre> <p>Powershell seems to treat this as if I typed</p> <pre><code>git difftool HEAD </code></pre> <p>so the caret symbol is gone. If I use multiple copies of the caret, I get a wei...
4,701
203,723
2012-03-08 10:14:04
9,615,922
11
2012-03-08 10:12:37
203,723
2012-03-08 10:12:37
https://stackoverflow.com/q/9600549
https://stackoverflow.com/a/9615922
<p>I found the problem, and it was with my setup :(</p> <p>I'm using Git for Windows, which provides <code>git.exe</code> in a /bin folder and <code>git.cmd</code> in a /cmd folder. <code>git.cmd</code> is a batch script which wraps <code>git.exe</code> and does some other stuff.</p> <p>Both of these directories were...
<p>I found the problem, and it was with my setup :(</p> <p>I'm using Git for Windows, which provides <code>git.exe</code> in a /bin folder and <code>git.cmd</code> in a /cmd folder. <code>git.cmd</code> is a batch script which wraps <code>git.exe</code> and does some other stuff.</p> <p>Both of these directories were...
64, 119, 526
git, powershell, windows
<h1>Using a caret(^) when using Git for Windows in PowerShell</h1> <p>I'm using git at the command line with PowerShell, and I'm trying to use something like</p> <pre><code>git difftool HEAD^ </code></pre> <p>Powershell seems to treat this as if I typed</p> <pre><code>git difftool HEAD </code></pre> <p>so the caret...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,232
bash
# Using a caret(^) when using Git for Windows in PowerShell I'm using git at the command line with PowerShell, and I'm trying to use something like ``` git difftool HEAD^ ``` Powershell seems to treat this as if I typed ``` git difftool HEAD ``` so the caret symbol is gone. If I use multiple copies of the caret, I...
I found the problem, and it was with my setup :( I'm using Git for Windows, which provides `git.exe` in a /bin folder and `git.cmd` in a /cmd folder. `git.cmd` is a batch script which wraps `git.exe` and does some other stuff. Both of these directories were in my PATH, with /cmd coming first, so when I typed `git`, `...
6216007
Graphical debugger for bash
16
2011-06-02 14:36:57
<p>Is it there any graphical debugger for bash on mac os x or linux? I mean something in the same fashion that the debugging mode of Visual Studio or Eclipse, where one can stop the program hover the mouse pointer over variables and get instantly values, modify them and go backwards and try modifications without the ne...
10,788
171,546
2018-02-15 16:40:39
6,216,213
11
2011-06-02 14:53:19
490,400
2011-06-02 14:58:20
https://stackoverflow.com/q/6216007
https://stackoverflow.com/a/6216213
<p>for debugging execute your script with: </p> <pre><code>bash -x &lt;scriptname&gt; </code></pre> <p>gui debugger: <a href="http://bashdb.sourceforge.net/">http://bashdb.sourceforge.net/</a></p>
<p>for debugging execute your script with: </p> <pre><code>bash -x &lt;scriptname&gt; </code></pre> <p>gui debugger: <a href="http://bashdb.sourceforge.net/">http://bashdb.sourceforge.net/</a></p>
110, 277, 369, 387
bash, debugging, ide, macos
<h1>Graphical debugger for bash</h1> <p>Is it there any graphical debugger for bash on mac os x or linux? I mean something in the same fashion that the debugging mode of Visual Studio or Eclipse, where one can stop the program hover the mouse pointer over variables and get instantly values, modify them and go backwards...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,233
bash
# Graphical debugger for bash Is it there any graphical debugger for bash on mac os x or linux? I mean something in the same fashion that the debugging mode of Visual Studio or Eclipse, where one can stop the program hover the mouse pointer over variables and get instantly values, modify them and go backwards and try ...
for debugging execute your script with: ``` bash -x <scriptname> ``` gui debugger: <http://bashdb.sourceforge.net/>
194725
How can I make the "find" Command on OS X default to the current directory?
16
2008-10-11 22:10:24
<p>I am a heavy command line user and use the <code>find</code> command extensively in my build system scripts. However on Mac OS X when I am not concentrating I often get output like this:</p> <pre><code>$ find -name \*.plist find: illegal option -- n find: illegal option -- a find: illegal option -- m find: illegal ...
17,004
6,444
2019-01-18 02:58:58
194,883
11
2008-10-12 00:14:57
15,168
2008-10-12 00:21:18
https://stackoverflow.com/q/194725
https://stackoverflow.com/a/194883
<p>If you can't discipline yourself to use <code>find</code> 'correctly', then why not install GNU <code>find</code> (from <code>findutils</code>) in a directory on your PATH ahead of the system <code>find</code> command.</p> <p>I used to have my own private variant of <code>cp</code> that would copy files to the curr...
<p>If you can't discipline yourself to use <code>find</code> 'correctly', then why not install GNU <code>find</code> (from <code>findutils</code>) in a directory on your PATH ahead of the system <code>find</code> command.</p> <p>I used to have my own private variant of <code>cp</code> that would copy files to the curr...
369, 387, 1231, 10193
bash, command-line, find, macos
<h1>How can I make the "find" Command on OS X default to the current directory?</h1> <p>I am a heavy command line user and use the <code>find</code> command extensively in my build system scripts. However on Mac OS X when I am not concentrating I often get output like this:</p> <pre><code>$ find -name \*.plist find: i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,234
bash
# How can I make the "find" Command on OS X default to the current directory? I am a heavy command line user and use the `find` command extensively in my build system scripts. However on Mac OS X when I am not concentrating I often get output like this: ``` $ find -name \*.plist find: illegal option -- n find: illega...
If you can't discipline yourself to use `find` 'correctly', then why not install GNU `find` (from `findutils`) in a directory on your PATH ahead of the system `find` command. I used to have my own private variant of `cp` that would copy files to the current directory if the last item in the list was not a directory. I...
60104778
Change and update the size of the cursor in Windows 10 via PowerShell
15
2020-02-06 22:55:23
<p>I've written the code below to affect (what I think) are the only reg keys responsible for the size of the cursor and pointer in Windows 10.</p> <p>Here's the code I have so far (Some additional comments within):</p> <pre><code>$RegConnect = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft....
10,045
8,262,102
2022-02-22 16:10:53
69,687,213
11
2021-10-23 10:24:55
5,988,940
2021-10-23 10:24:55
https://stackoverflow.com/q/60104778
https://stackoverflow.com/a/69687213
<p>So after a bit of hacking about SystemSettings.exe with cheat engine I found how MS sets the cursor size. It ends up still using SystemParametersInfo but with some undocumented arguments. Try the following :)</p> <pre><code>SystemParametersInfo(0x2029, 0, 16, 0x01); </code></pre> <p>to set a cursor size of 16. yup y...
<p>So after a bit of hacking about SystemSettings.exe with cheat engine I found how MS sets the cursor size. It ends up still using SystemParametersInfo but with some undocumented arguments. Try the following :)</p> <pre><code>SystemParametersInfo(0x2029, 0, 16, 0x01); </code></pre> <p>to set a cursor size of 16. yup y...
526, 889
powershell, winapi
<h1>Change and update the size of the cursor in Windows 10 via PowerShell</h1> <p>I've written the code below to affect (what I think) are the only reg keys responsible for the size of the cursor and pointer in Windows 10.</p> <p>Here's the code I have so far (Some additional comments within):</p> <pre><code>$RegCon...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,235
bash
# Change and update the size of the cursor in Windows 10 via PowerShell I've written the code below to affect (what I think) are the only reg keys responsible for the size of the cursor and pointer in Windows 10. Here's the code I have so far (Some additional comments within): ``` $RegConnect = [Microsof...
So after a bit of hacking about SystemSettings.exe with cheat engine I found how MS sets the cursor size. It ends up still using SystemParametersInfo but with some undocumented arguments. Try the following :) ``` SystemParametersInfo(0x2029, 0, 16, 0x01); ``` to set a cursor size of 16. yup you can go below their min...
33225082
Relative shebang: How to write an executable script running portable interpreter which comes with it
15
2015-10-19 22:35:34
<p>Let's say we have a program/package which comes along with its own interpreter and a set of scripts which should invoke it on their execution (using shebang).</p> <p>And let's say we want to keep it portable, so it remains functioning even if simply copied to a different location (different machines) without invoki...
7,365
2,527,797
2025-02-26 09:43:54
33,225,083
11
2015-10-19 22:35:34
2,527,797
2025-02-26 09:43:54
https://stackoverflow.com/q/33225082
https://stackoverflow.com/a/33225083
<p>The relative path written directly in a shebang is treated relative to the current working directory, so something like <code>#!../bin/python2.7</code> will not work for any other working directory except few.</p> <p>Since OS does not support it, why not to use external program like using <code>env</code> for <code>...
<p>The relative path written directly in a shebang is treated relative to the current working directory, so something like <code>#!../bin/python2.7</code> will not work for any other working directory except few.</p> <p>Since OS does not support it, why not to use external program like using <code>env</code> for <code>...
16, 34, 58, 390, 8780
linux, python, shebang, shell, unix
<h1>Relative shebang: How to write an executable script running portable interpreter which comes with it</h1> <p>Let's say we have a program/package which comes along with its own interpreter and a set of scripts which should invoke it on their execution (using shebang).</p> <p>And let's say we want to keep it portabl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,236
bash
# Relative shebang: How to write an executable script running portable interpreter which comes with it Let's say we have a program/package which comes along with its own interpreter and a set of scripts which should invoke it on their execution (using shebang). And let's say we want to keep it portable, so it remains...
The relative path written directly in a shebang is treated relative to the current working directory, so something like `#!../bin/python2.7` will not work for any other working directory except few. Since OS does not support it, why not to use external program like using `env` for `PATH` lookup. But I know no speciali...
27658147
Download private file from S3 using bash
15
2014-12-26 14:03:24
<p>I am trying to get the following bash script to work (copied from <a href="http://curl.haxx.se/mail/archive-2014-10/0006.html#replies" rel="noreferrer">http://curl.haxx.se/mail/archive-2014-10/0006.html#replies</a>): </p> <pre><code>#!/bin/sh file=path/to/file bucket=your-bucket resource="/${bucket}/${file}" co...
19,603
2,271,675
2017-04-27 09:30:34
27,677,146
11
2014-12-28 14:06:39
2,271,675
2014-12-28 14:06:39
https://stackoverflow.com/q/27658147
https://stackoverflow.com/a/27677146
<p>After way too much time spent on this I finally got it to work:</p> <p>This line:</p> <pre><code>signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` </code></pre> <p>is missing an 'e':</p> <pre><code>signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} ...
<p>After way too much time spent on this I finally got it to work:</p> <p>This line:</p> <pre><code>signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` </code></pre> <p>is missing an 'e':</p> <pre><code>signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} ...
387, 531, 11444
amazon-s3, bash, scripting
<h1>Download private file from S3 using bash</h1> <p>I am trying to get the following bash script to work (copied from <a href="http://curl.haxx.se/mail/archive-2014-10/0006.html#replies" rel="noreferrer">http://curl.haxx.se/mail/archive-2014-10/0006.html#replies</a>): </p> <pre><code>#!/bin/sh file=path/to/file buc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,237
bash
# Download private file from S3 using bash I am trying to get the following bash script to work (copied from <http://curl.haxx.se/mail/archive-2014-10/0006.html#replies>): ``` #!/bin/sh file=path/to/file bucket=your-bucket resource="/${bucket}/${file}" contentType="application/x-compressed-tar" dateValue="`date ...
After way too much time spent on this I finally got it to work: This line: ``` signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` ``` is missing an 'e': ``` signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` ``` In other words, charac...
26849247
What is the POSIX shell equivalent of bash <<<
15
2014-11-10 17:16:30
<p>I have a variable that looks sort of like this:</p> <pre><code>msg="newton apple tree" </code></pre> <p>I want to assign each of these words into separate variables. This is easy to do in bash:</p> <pre><code>read a b c &lt;&lt;&lt; $msg </code></pre> <p>Is there a compact, readable way to do this in POSIX shel...
5,018
1,660,508
2014-11-10 18:18:02
26,849,455
11
2014-11-10 17:29:10
1,899,640
2014-11-10 17:29:10
https://stackoverflow.com/q/26849247
https://stackoverflow.com/a/26849455
<p>To write idiomatic scripts, you can't just look at each individual syntax element and try to find a POSIX equivalent. That's like translating text by replacing each individual word with its entry in the dictionary.</p> <p>The POSIX way of splitting a string known to have three words into three arguments, similar bu...
<p>To write idiomatic scripts, you can't just look at each individual syntax element and try to find a POSIX equivalent. That's like translating text by replacing each individual word with its entry in the dictionary.</p> <p>The POSIX way of splitting a string known to have three words into three arguments, similar bu...
387, 10327
bash, sh
<h1>What is the POSIX shell equivalent of bash <<<</h1> <p>I have a variable that looks sort of like this:</p> <pre><code>msg="newton apple tree" </code></pre> <p>I want to assign each of these words into separate variables. This is easy to do in bash:</p> <pre><code>read a b c &lt;&lt;&lt; $msg </code></pre> <p>I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,238
bash
# What is the POSIX shell equivalent of bash <<< I have a variable that looks sort of like this: ``` msg="newton apple tree" ``` I want to assign each of these words into separate variables. This is easy to do in bash: ``` read a b c <<< $msg ``` Is there a compact, readable way to do this in POSIX shell?
To write idiomatic scripts, you can't just look at each individual syntax element and try to find a POSIX equivalent. That's like translating text by replacing each individual word with its entry in the dictionary. The POSIX way of splitting a string known to have three words into three arguments, similar but not iden...
25730978
PowerShell Add-Type : Cannot add type. already exist
15
2014-09-08 18:42:08
<p>I'm using PowerShell script to run C# code directly in the script. I've run in to an error a particular error a few times. If I make any changes to the C# code in the PowerShell ISE and try to run it again I get the following error.</p> <pre><code>Add-Type : Cannot add type. The type name 'AlertsOnOff10.onOff' alre...
30,733
2,655,116
2024-10-22 17:51:02
25,731,143
11
2014-09-08 18:52:01
3,905,079
2022-07-21 15:40:53
https://stackoverflow.com/q/25730978
https://stackoverflow.com/a/25731143
<p>To my knowledge there is no way to remove a type from a PowerShell session once it has been added.</p> <p>The (annoying) workaround I would suggest is to write your code in one ISE session, and execute it in a completely different session (separate console window or separate ISE if you want to be able to debug).</p>...
<p>To my knowledge there is no way to remove a type from a PowerShell session once it has been added.</p> <p>The (annoying) workaround I would suggest is to write your code in one ISE session, and execute it in a completely different session (separate console window or separate ISE if you want to be able to debug).</p>...
9, 526, 3981
c#, powershell, runtime-error
<h1>PowerShell Add-Type : Cannot add type. already exist</h1> <p>I'm using PowerShell script to run C# code directly in the script. I've run in to an error a particular error a few times. If I make any changes to the C# code in the PowerShell ISE and try to run it again I get the following error.</p> <pre><code>Add-Ty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,239
bash
# PowerShell Add-Type : Cannot add type. already exist I'm using PowerShell script to run C# code directly in the script. I've run in to an error a particular error a few times. If I make any changes to the C# code in the PowerShell ISE and try to run it again I get the following error. ``` Add-Type : Cannot add type...
To my knowledge there is no way to remove a type from a PowerShell session once it has been added. The (annoying) workaround I would suggest is to write your code in one ISE session, and execute it in a completely different session (separate console window or separate ISE if you want to be able to debug). This only m...
20856634
Nested ForEach() in PowerShell
15
2013-12-31 11:27:02
<p>I'm having some troubles with nested ForEach loops in Powershell. First, I need to iterate through list 1. For every object in list 1, I need to iterate through list 2. When I found the resembling object in list 2, I want to go to the next object in list 1. </p> <p>I've tried break, i've tried continue, but it won'...
90,601
2,912,774
2016-02-22 01:54:52
20,856,788
11
2013-12-31 11:39:12
503,046
2013-12-31 11:39:12
https://stackoverflow.com/q/20856634
https://stackoverflow.com/a/20856788
<p>Use a label as described in <code>get-help about_break</code>:</p> <pre><code>A Break statement can include a label. If you use the Break keyword with a label, Windows PowerShell exits the labeled loop instead of exiting the current loop </code></pre> <p>Like so,</p> <pre><code>foreach ($objectA in @("a", "e", "i...
<p>Use a label as described in <code>get-help about_break</code>:</p> <pre><code>A Break statement can include a label. If you use the Break keyword with a label, Windows PowerShell exits the labeled loop instead of exiting the current loop </code></pre> <p>Like so,</p> <pre><code>foreach ($objectA in @("a", "e", "i...
526, 631, 13056
break, foreach, powershell
<h1>Nested ForEach() in PowerShell</h1> <p>I'm having some troubles with nested ForEach loops in Powershell. First, I need to iterate through list 1. For every object in list 1, I need to iterate through list 2. When I found the resembling object in list 2, I want to go to the next object in list 1. </p> <p>I've tried...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,240
bash
# Nested ForEach() in PowerShell I'm having some troubles with nested ForEach loops in Powershell. First, I need to iterate through list 1. For every object in list 1, I need to iterate through list 2. When I found the resembling object in list 2, I want to go to the next object in list 1. I've tried break, i've trie...
Use a label as described in `get-help about_break`: ``` A Break statement can include a label. If you use the Break keyword with a label, Windows PowerShell exits the labeled loop instead of exiting the current loop ``` Like so, ``` foreach ($objectA in @("a", "e", "i")) { "objectA: $objectA" :outer fore...
19093208
Powershell - Conditionally add parameter/argument to cmdlet
15
2013-09-30 11:35:43
<p>Suppose I have a Powershell script similar to this:</p> <pre><code>$par = [...] New-Connection ` -Server $par.Server ` -User $par.User ` -Pwd $par.Pwd ` - [...] </code></pre> <p>If <code>$par.Pwd</code> is empty or null, <code>New-Connection</code> will throw an error.</p> <p>So, I only want to include this ...
10,161
2,060,966
2022-05-03 08:47:35
19,094,107
11
2013-09-30 12:18:07
1,035,521
2013-09-30 12:44:29
https://stackoverflow.com/q/19093208
https://stackoverflow.com/a/19094107
<p>How about using the hashtable approach to creating new objects:</p> <pre><code>$Object = New-Object PSObject -Property @{ Name = $obj.Name OptValue1 = $obj.OptValue1 OptValue2 = $obj.OptValue2 OptValue3 = $null OptValue4 = "MyValue" } $Ob...
<p>How about using the hashtable approach to creating new objects:</p> <pre><code>$Object = New-Object PSObject -Property @{ Name = $obj.Name OptValue1 = $obj.OptValue1 OptValue2 = $obj.OptValue2 OptValue3 = $null OptValue4 = "MyValue" } $Ob...
360, 526, 10355, 14155
optional-parameters, parameter-passing, parameters, powershell
<h1>Powershell - Conditionally add parameter/argument to cmdlet</h1> <p>Suppose I have a Powershell script similar to this:</p> <pre><code>$par = [...] New-Connection ` -Server $par.Server ` -User $par.User ` -Pwd $par.Pwd ` - [...] </code></pre> <p>If <code>$par.Pwd</code> is empty or null, <code>New-Connectio...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,241
bash
# Powershell - Conditionally add parameter/argument to cmdlet Suppose I have a Powershell script similar to this: ``` $par = [...] New-Connection ` -Server $par.Server ` -User $par.User ` -Pwd $par.Pwd ` - [...] ``` If `$par.Pwd` is empty or null, `New-Connection` will throw an error. So, I only want to inc...
How about using the hashtable approach to creating new objects: ``` $Object = New-Object PSObject -Property @{ Name = $obj.Name OptValue1 = $obj.OptValue1 OptValue2 = $obj.OptValue2 OptValue3 = $null OptValue4 = "MyValue" } $Object ``` **Up...
19046882
Shell commands are written in what language?
15
2013-09-27 09:06:57
<p>There are many shell commands, like </p> <blockquote> <p>ls, cd, cat etc. </p> </blockquote> <p>what programming language is used in writing these commands? How are they compiled?</p> <p>My understanding:</p> <pre><code>Shell is a program which takes command; ** does this mean that it interprets those command...
9,983
3,086,011
2019-09-03 09:05:36
19,049,281
11
2013-09-27 11:11:32
2,602,508
2013-09-27 11:20:00
https://stackoverflow.com/q/19046882
https://stackoverflow.com/a/19049281
<p>Most of the basic utilities in linux are written in <code>C</code> .This u can verify in <code>busybox source code</code> which supports most of basic linux command utility which are written in <code>C</code>. So command like ls,cd ...etc are in <code>c</code></p> <p>How shell will interpret check in below link </p...
<p>Most of the basic utilities in linux are written in <code>C</code> .This u can verify in <code>busybox source code</code> which supports most of basic linux command utility which are written in <code>C</code>. So command like ls,cd ...etc are in <code>c</code></p> <p>How shell will interpret check in below link </p...
58, 387, 390, 2035
bash, kernel, linux, shell
<h1>Shell commands are written in what language?</h1> <p>There are many shell commands, like </p> <blockquote> <p>ls, cd, cat etc. </p> </blockquote> <p>what programming language is used in writing these commands? How are they compiled?</p> <p>My understanding:</p> <pre><code>Shell is a program which takes comma...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,242
bash
# Shell commands are written in what language? There are many shell commands, like > ls, cd, cat etc. what programming language is used in writing these commands? How are they compiled? My understanding: ``` Shell is a program which takes command; ** does this mean that it interprets those commands(like ls is inte...
Most of the basic utilities in linux are written in `C` .This u can verify in `busybox source code` which supports most of basic linux command utility which are written in `C`. So command like ls,cd ...etc are in `c` How shell will interpret check in below link in an operating system there is a special program called...
10937065
Signtool allows me to sign code but Set-AuthenticodeSignature says the "certificate is not suitable for code signing"
15
2012-06-07 17:47:35
<p>I have a self-signed code signing certificate, made with the directions from <a href="https://stackoverflow.com/a/201277/80274">this answer</a>, that works fine when used with <code>signtool.exe</code>, however if I try to sign using <code>Set-AuthenticodeSignature</code>, it fails.</p> <p>Why can I sign using <cod...
20,782
80,274
2023-04-21 05:11:38
18,583,725
11
2013-09-03 03:42:41
1,579,659
2013-09-03 03:42:41
https://stackoverflow.com/q/10937065
https://stackoverflow.com/a/18583725
<p>I had the same problem and the answer I figured out was that I had to <a href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" rel="noreferrer">create two certificates</a>. First, a trusted root certificate authority using</p> <pre><code>makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1...
<p>I had the same problem and the answer I figured out was that I had to <a href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" rel="noreferrer">create two certificates</a>. First, a trusted root certificate authority using</p> <pre><code>makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1...
526, 5953, 50005
code-signing, powershell, signtool
<h1>Signtool allows me to sign code but Set-AuthenticodeSignature says the "certificate is not suitable for code signing"</h1> <p>I have a self-signed code signing certificate, made with the directions from <a href="https://stackoverflow.com/a/201277/80274">this answer</a>, that works fine when used with <code>signtoo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,243
bash
# Signtool allows me to sign code but Set-AuthenticodeSignature says the "certificate is not suitable for code signing" I have a self-signed code signing certificate, made with the directions from [this answer](https://stackoverflow.com/a/201277/80274), that works fine when used with `signtool.exe`, however if I try t...
I had the same problem and the answer I figured out was that I had to [create two certificates](http://www.hanselman.com/blog/SigningPowerShellScripts.aspx). First, a trusted root certificate authority using ``` makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer ...
7313491
Variables getting reset after the while read loop that reads from a pipeline
15
2011-09-05 23:13:29
<pre><code>initiate () { read -p "Location(s) to look for .bsp files in? " loc find $loc -name "*.bsp" | while read do if [ -f "$loc.bz2" ] then continue else filcount=$[$filcount+1] bzip $loc fi if [ "$scan" == "1" ]; then bzipint $loc fi echo $filcount #Correct c...
7,847
null
2024-11-14 20:42:20
7,313,558
11
2011-09-05 23:28:02
450,128
2011-09-05 23:28:02
https://stackoverflow.com/q/7313491
https://stackoverflow.com/a/7313558
<p>I ran into this problem yesterday.</p> <p>The trouble is that you're doing <code>find $loc -name "*.bsp" | while read</code>. Because this involves a pipe, the <code>while read</code> loop can't actually be running in the same bash process as the rest of your script; bash has to spawn off a subprocess so that it ca...
<p>I ran into this problem yesterday.</p> <p>The trouble is that you're doing <code>find $loc -name "*.bsp" | while read</code>. Because this involves a pipe, the <code>while read</code> loop can't actually be running in the same bash process as the rest of your script; bash has to spawn off a subprocess so that it ca...
387, 390, 17310, 57788
bash, shell, subshell, while-loop
<h1>Variables getting reset after the while read loop that reads from a pipeline</h1> <pre><code>initiate () { read -p "Location(s) to look for .bsp files in? " loc find $loc -name "*.bsp" | while read do if [ -f "$loc.bz2" ] then continue else filcount=$[$filcount+1] bzip $loc f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,244
bash
# Variables getting reset after the while read loop that reads from a pipeline ``` initiate () { read -p "Location(s) to look for .bsp files in? " loc find $loc -name "*.bsp" | while read do if [ -f "$loc.bz2" ] then continue else filcount=$[$filcount+1] bzip $loc fi if [ "$...
I ran into this problem yesterday. The trouble is that you're doing `find $loc -name "*.bsp" | while read`. Because this involves a pipe, the `while read` loop can't actually be running in the same bash process as the rest of your script; bash has to spawn off a subprocess so that it can connect the the stdout of `fin...
3474318
shell/ batch scripting to direct commands to adb shell
15
2010-08-13 06:11:35
<p>I am trying to write a batch(for win) and a shell script for linux to automate key and touch events on a android UI. At the moment in a windows batch file I am starting a adb shell for each event for eg</p> <pre><code> :again adb shell am start -a android.intent.action.MAIN -n com.q.me.fui.activity/.InitActivit...
64,133
414,752
2017-03-02 14:06:00
3,474,643
11
2010-08-13 07:09:12
306,602
2016-03-19 02:21:23
https://stackoverflow.com/q/3474318
https://stackoverflow.com/a/3474643
<p>I don't know much about batch scripting or shell scripting, but I was able to quickly write a java program to do this:</p> <pre><code>import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class AndroidShell { private ProcessBuilder builder; private Process adb; priva...
<p>I don't know much about batch scripting or shell scripting, but I was able to quickly write a java program to do this:</p> <pre><code>import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class AndroidShell { private ProcessBuilder builder; private Process adb; priva...
390, 1386, 7002, 22975
adb, android, batch-file, shell
<h1>shell/ batch scripting to direct commands to adb shell</h1> <p>I am trying to write a batch(for win) and a shell script for linux to automate key and touch events on a android UI. At the moment in a windows batch file I am starting a adb shell for each event for eg</p> <pre><code> :again adb shell am start -a ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,245
bash
# shell/ batch scripting to direct commands to adb shell I am trying to write a batch(for win) and a shell script for linux to automate key and touch events on a android UI. At the moment in a windows batch file I am starting a adb shell for each event for eg ``` :again adb shell am start -a android.intent.actio...
I don't know much about batch scripting or shell scripting, but I was able to quickly write a java program to do this: ``` import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class AndroidShell { private ProcessBuilder builder; private Process adb; private static fina...
1491647
Grep ignore multiple lines
15
2009-09-29 10:06:14
<p>Is there a way with Grep to use the -v switch to ignore a line and the next number of lines after it. Its basically to filter exceptions from a log file i.e.</p> <pre><code>Valid log entry 1 Exception exceptionname at a.b.c at d.e.f ... Valid log entry 2 </code></pre> <p>grep it to produce : </p> <pre...
7,919
181,023
2016-04-27 22:44:07
1,492,538
11
2009-09-29 13:25:13
7,552
2009-09-29 13:25:13
https://stackoverflow.com/q/1491647
https://stackoverflow.com/a/1492538
<p>Try awk:</p> <pre><code>awk -v nlines=2 '/^Exception/ {for (i=0; i&lt;nlines; i++) {getline}; next} 1' </code></pre>
<p>Try awk:</p> <pre><code>awk -v nlines=2 '/^Exception/ {for (i=0; i&lt;nlines; i++) {getline}; next} 1' </code></pre>
390, 1271
grep, shell
<h1>Grep ignore multiple lines</h1> <p>Is there a way with Grep to use the -v switch to ignore a line and the next number of lines after it. Its basically to filter exceptions from a log file i.e.</p> <pre><code>Valid log entry 1 Exception exceptionname at a.b.c at d.e.f ... Valid log entry 2 </code></pre>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,246
bash
# Grep ignore multiple lines Is there a way with Grep to use the -v switch to ignore a line and the next number of lines after it. Its basically to filter exceptions from a log file i.e. ``` Valid log entry 1 Exception exceptionname at a.b.c at d.e.f ... Valid log entry 2 ``` grep it to produce : ``` Va...
Try awk: ``` awk -v nlines=2 '/^Exception/ {for (i=0; i<nlines; i++) {getline}; next} 1' ```
574695
How does "while (sleep 100 &!) do; done" work in zsh, and how could it be replicated in bash?
15
2009-02-22 10:20:44
<p>According to <a href="http://en.wikipedia.org/wiki/Fork_bomb" rel="noreferrer">Wikipedia</a>, the forkbomb <code>:(){ :|:&amp; };:</code> can be stopped with the zsh command <code>while (sleep 100 &amp;!) do; done</code>, which will supposedly spawn sleep 100 processes until all the forkbomb processes are gone. Thi...
5,622
null
2013-11-12 01:49:22
574,811
11
2009-02-22 12:02:45
67,829
2009-02-22 12:02:45
https://stackoverflow.com/q/574695
https://stackoverflow.com/a/574811
<p>The reason that a fork-bomb works is because there is a finite limit to the number of processes that can be running at any one time, and a fork-bomb is designed to fill this limit.</p> <p>Because the forkbomb code you provided dies if it cannot spawn a child process, the parent processes do not actually hang around...
<p>The reason that a fork-bomb works is because there is a finite limit to the number of processes that can be running at any one time, and a fork-bomb is designed to fill this limit.</p> <p>Because the forkbomb code you provided dies if it cannot spawn a child process, the parent processes do not actually hang around...
58, 387, 390, 3791
bash, linux, shell, zsh
<h1>How does "while (sleep 100 &!) do; done" work in zsh, and how could it be replicated in bash?</h1> <p>According to <a href="http://en.wikipedia.org/wiki/Fork_bomb" rel="noreferrer">Wikipedia</a>, the forkbomb <code>:(){ :|:&amp; };:</code> can be stopped with the zsh command <code>while (sleep 100 &amp;!) do; done<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,247
bash
# How does "while (sleep 100 &!) do; done" work in zsh, and how could it be replicated in bash? According to [Wikipedia](http://en.wikipedia.org/wiki/Fork_bomb), the forkbomb `:(){ :|:& };:` can be stopped with the zsh command `while (sleep 100 &!) do; done`, which will supposedly spawn sleep 100 processes until all t...
The reason that a fork-bomb works is because there is a finite limit to the number of processes that can be running at any one time, and a fork-bomb is designed to fill this limit. Because the forkbomb code you provided dies if it cannot spawn a child process, the parent processes do not actually hang around, but the ...
44081972
Windows 10 Gradle: JAVA_HOME is set to an invalid directory
14
2017-05-20 04:41:02
<p>I was trying to run <code>./gradlew bootRun</code> in both <strong>Git Bash</strong> and <strong>PowerShell</strong>, and got this error: <code>ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121</code></p> <p>The <strong>gradlew</strong> file is inside the project directory that clo...
41,320
3,261,923
2023-09-06 15:47:20
44,082,086
11
2017-05-20 04:59:11
5,761,558
2017-05-20 04:59:11
https://stackoverflow.com/q/44081972
https://stackoverflow.com/a/44082086
<p>Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you're talking about Gradle, you're surely trying to build/compile code.</p> <p>If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with "jdk". Otherwise, you have to install...
<p>Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you're talking about Gradle, you're surely trying to build/compile code.</p> <p>If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with "jdk". Otherwise, you have to install...
17, 1211, 32307, 61874
git-bash, gradle, java, spring
<h1>Windows 10 Gradle: JAVA_HOME is set to an invalid directory</h1> <p>I was trying to run <code>./gradlew bootRun</code> in both <strong>Git Bash</strong> and <strong>PowerShell</strong>, and got this error: <code>ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121</code></p> <p>The <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,248
bash
# Windows 10 Gradle: JAVA_HOME is set to an invalid directory I was trying to run `./gradlew bootRun` in both **Git Bash** and **PowerShell**, and got this error: `ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121` The **gradlew** file is inside the project directory that cloned from...
Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you're talking about Gradle, you're surely trying to build/compile code. If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with "jdk". Otherwise, you have to install a Java De...
30942021
powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment
14
2015-06-19 15:33:34
<p>I'm running into a strange behavior with a powershell Start-Process call. </p> <p>Here is the call:</p> <pre><code>$process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -Credential $defaultCredential ` -Wait ` -WorkingDirectory "C:\somepath" ` -LoadUserProfile if ($process.E...
8,931
4,306,452
2016-06-06 06:48:52
30,985,036
11
2015-06-22 16:21:50
1,687,106
2015-06-22 16:21:50
https://stackoverflow.com/q/30942021
https://stackoverflow.com/a/30985036
<p><code>start-process</code> is an 'alias' for <code>System.Diagnostics.Process.Start()</code>, so yes, it does make use of <code>CreateProcessWithLogonW()</code>. As noted, this method can't be called from a service process, it can only be called from an 'interactive' process. The caveat to that "only" is the one you...
<p><code>start-process</code> is an 'alias' for <code>System.Diagnostics.Process.Start()</code>, so yes, it does make use of <code>CreateProcessWithLogonW()</code>. As noted, this method can't be called from a service process, it can only be called from an 'interactive' process. The caveat to that "only" is the one you...
526, 5357, 26462
credentials, powershell, start-process
<h1>powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment</h1> <p>I'm running into a strange behavior with a powershell Start-Process call. </p> <p>Here is the call:</p> <pre><code>$process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -C...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,249
bash
# powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment I'm running into a strange behavior with a powershell Start-Process call. Here is the call: ``` $process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -Credential $defaultCredential ...
`start-process` is an 'alias' for `System.Diagnostics.Process.Start()`, so yes, it does make use of `CreateProcessWithLogonW()`. As noted, this method can't be called from a service process, it can only be called from an 'interactive' process. The caveat to that "only" is the one you've discovered - that when you aren'...
21742227
RedHat daemon function usage
14
2014-02-12 23:32:36
<p>I'm working on an init script for Jetty on RHEL. Trying to use the <code>daemon</code> function provided by the init library (<code>/etc/rc.d/init.d/functions</code>).</p> <p>I found <a href="http://www.sensi.org/~alec/unix/redhat/sysvinit.html">this terse documentation</a>, and <a href="http://bitten.edgewall.org/...
30,569
680,920
2019-08-09 18:33:41
28,113,403
11
2015-01-23 15:40:44
125,048
2019-08-09 18:33:41
https://stackoverflow.com/q/21742227
https://stackoverflow.com/a/28113403
<p>To answer the question you guess that you have, is that <code>--pidfile</code> is used to check whether the daemon process is already running. On RHEL (and derivates) the <code>daemon</code> function won't write the pidfile.</p> <p>In the case that the program stays in the foreground it has to be explicitly sent to...
<p>To answer the question you guess that you have, is that <code>--pidfile</code> is used to check whether the daemon process is already running. On RHEL (and derivates) the <code>daemon</code> function won't write the pidfile.</p> <p>In the case that the program stays in the foreground it has to be explicitly sent to...
58, 387, 2205, 2510, 7280
bash, daemon, init, linux, redhat
<h1>RedHat daemon function usage</h1> <p>I'm working on an init script for Jetty on RHEL. Trying to use the <code>daemon</code> function provided by the init library (<code>/etc/rc.d/init.d/functions</code>).</p> <p>I found <a href="http://www.sensi.org/~alec/unix/redhat/sysvinit.html">this terse documentation</a>, an...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,250
bash
# RedHat daemon function usage I'm working on an init script for Jetty on RHEL. Trying to use the `daemon` function provided by the init library (`/etc/rc.d/init.d/functions`). I found [this terse documentation](http://www.sensi.org/~alec/unix/redhat/sysvinit.html), and [an online example](http://bitten.edgewall.org/...
To answer the question you guess that you have, is that `--pidfile` is used to check whether the daemon process is already running. On RHEL (and derivates) the `daemon` function won't write the pidfile. In the case that the program stays in the foreground it has to be explicitly sent to the background by appending `&`...
26861118
Rounding Numbers with bc in Bash
14
2014-11-11 09:04:59
<p>I want to compute an average with 3 decimal figures, rounded to nearest, using <code>bc</code>.</p> <p>For example:</p> <blockquote> <p>average of 3, 3 and 5 should yield 3.667</p> </blockquote> <p>and</p> <blockquote> <p>average of 3, 3 and 4 should yield 3.333</p> </blockquote> <p>I tried:</p> <pre><code...
26,074
4,238,839
2019-05-28 20:02:37
26,864,946
11
2014-11-11 12:28:37
1,815,797
2014-11-11 12:46:04
https://stackoverflow.com/q/26861118
https://stackoverflow.com/a/26864946
<p>Your trick to add <code>0.0005</code> is not a bad idea. Though, it doesn't quite work that way. <code>scale</code> is used internally when <code>bc</code> performs some operations (like divisions).</p> <p>In your case, it would be better to perform the division first, maybe using a large <code>scale</code> or the ...
<p>Your trick to add <code>0.0005</code> is not a bad idea. Though, it doesn't quite work that way. <code>scale</code> is used internally when <code>bc</code> performs some operations (like divisions).</p> <p>In your case, it would be better to perform the division first, maybe using a large <code>scale</code> or the ...
58, 387, 34696
bash, bc, linux
<h1>Rounding Numbers with bc in Bash</h1> <p>I want to compute an average with 3 decimal figures, rounded to nearest, using <code>bc</code>.</p> <p>For example:</p> <blockquote> <p>average of 3, 3 and 5 should yield 3.667</p> </blockquote> <p>and</p> <blockquote> <p>average of 3, 3 and 4 should yield 3.333</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,251
bash
# Rounding Numbers with bc in Bash I want to compute an average with 3 decimal figures, rounded to nearest, using `bc`. For example: > average of 3, 3 and 5 should yield 3.667 and > average of 3, 3 and 4 should yield 3.333 I tried: ``` echo "scale=3; $sum/$n+0.0005" | bc ``` but `scale` doesn't behave as I expe...
Your trick to add `0.0005` is not a bad idea. Though, it doesn't quite work that way. `scale` is used internally when `bc` performs some operations (like divisions). In your case, it would be better to perform the division first, maybe using a large `scale` or the `-l` switch to `bc`1 (if your version supports it), th...
21771313
Git diff - ignore reorder
14
2014-02-14 05:11:45
<p>git diff numbers</p> <pre><code>diff --git a/numbers b/numbers index 5f5fbe7..d184fef 100644 --- a/numbers +++ b/numbers @@ -1,3 +1,3 @@ -1 +4 +3 2 -3 </code></pre> <p>Number 3 is repeated but the order is changed. Any way to ignore the reorder in git or any grep solution? I want the result of only added and dele...
2,497
2,553,035
2019-05-23 10:56:48
21,779,343
11
2014-02-14 12:23:55
3,099,074
2014-02-14 12:31:26
https://stackoverflow.com/q/21771313
https://stackoverflow.com/a/21779343
<p>The diffing tools are usually implemented in terms of the Myers' diff algorithm. There isn't much that you can do to control the behaviour of GNU/git/diff. (There are a couple of switches that you can pass to diff to affect the behaviour, but in your case they are irrelevant.)</p> <p>You could simply post-process t...
<p>The diffing tools are usually implemented in terms of the Myers' diff algorithm. There isn't much that you can do to control the behaviour of GNU/git/diff. (There are a couple of switches that you can pass to diff to affect the behaviour, but in your case they are irrelevant.)</p> <p>You could simply post-process t...
119, 387, 390, 606, 10327
bash, diff, git, sh, shell
<h1>Git diff - ignore reorder</h1> <p>git diff numbers</p> <pre><code>diff --git a/numbers b/numbers index 5f5fbe7..d184fef 100644 --- a/numbers +++ b/numbers @@ -1,3 +1,3 @@ -1 +4 +3 2 -3 </code></pre> <p>Number 3 is repeated but the order is changed. Any way to ignore the reorder in git or any grep solution? I wan...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,252
bash
# Git diff - ignore reorder git diff numbers ``` diff --git a/numbers b/numbers index 5f5fbe7..d184fef 100644 --- a/numbers +++ b/numbers @@ -1,3 +1,3 @@ -1 +4 +3 2 -3 ``` Number 3 is repeated but the order is changed. Any way to ignore the reorder in git or any grep solution? I want the result of only added and de...
The diffing tools are usually implemented in terms of the Myers' diff algorithm. There isn't much that you can do to control the behaviour of GNU/git/diff. (There are a couple of switches that you can pass to diff to affect the behaviour, but in your case they are irrelevant.) You could simply post-process the output ...
21218074
How to just input 'y' without having to press ENTER?
14
2014-01-19 14:35:26
<p>Using this portion of a bash script as an example</p> <pre><code>{ read -p "Do you want to update the tv feed? [y/n/q] " ynq case $ynq in [Yy]* ) rm ~/cron/beeb.txt; /usr/bin/get-iplayer --type tv&gt;&gt;~/cron/beeb.txt;; [Nn]* ) echo;; [Qq]* ) exit;; * ) echo "Please answer yes or no. "...
11,061
2,513,103
2021-11-14 22:37:33
21,218,201
11
2014-01-19 14:46:47
89,817
2014-01-19 14:58:54
https://stackoverflow.com/q/21218074
https://stackoverflow.com/a/21218201
<p>Add <code>-n 1</code> to the <code>read</code> command's options. From the bash manpage:</p> <pre><code>-n nchars read returns after reading nchars characters rather than waiting for a complete line of input. </code></pre> <p>BTW, you should also double-quote <code>"$ynq"</code> -- sometimes users <em>wil...
<p>Add <code>-n 1</code> to the <code>read</code> command's options. From the bash manpage:</p> <pre><code>-n nchars read returns after reading nchars characters rather than waiting for a complete line of input. </code></pre> <p>BTW, you should also double-quote <code>"$ynq"</code> -- sometimes users <em>wil...
387
bash
<h1>How to just input 'y' without having to press ENTER?</h1> <p>Using this portion of a bash script as an example</p> <pre><code>{ read -p "Do you want to update the tv feed? [y/n/q] " ynq case $ynq in [Yy]* ) rm ~/cron/beeb.txt; /usr/bin/get-iplayer --type tv&gt;&gt;~/cron/beeb.txt;; [Nn]* ) echo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,253
bash
# How to just input 'y' without having to press ENTER? Using this portion of a bash script as an example ``` { read -p "Do you want to update the tv feed? [y/n/q] " ynq case $ynq in [Yy]* ) rm ~/cron/beeb.txt; /usr/bin/get-iplayer --type tv>>~/cron/beeb.txt;; [Nn]* ) echo;; [Qq]* ) exit;; ...
Add `-n 1` to the `read` command's options. From the bash manpage: ``` -n nchars read returns after reading nchars characters rather than waiting for a complete line of input. ``` BTW, you should also double-quote `"$ynq"` -- sometimes users *will* just press return, which can cause weird behavior if the var...
19901906
Detect daylight saving time in bash
14
2013-11-11 08:31:44
<p>I want to detect if I'm in winter or summer time. My current approach is:</p> <pre><code>if date +%Z | grep -e CET -e EST; then # I'm in winter time else # I'm in summer time fi </code></pre> <p>which have obvious drawback as you have to know all the timezone names.</p>
18,717
2,229,885
2024-09-20 09:45:09
19,902,806
11
2013-11-11 09:24:41
1,030,675
2024-09-20 09:45:09
https://stackoverflow.com/q/19901906
https://stackoverflow.com/a/19902806
<p>Perl to the rescue:</p> <pre><code>if perl -e 'exit ((localtime)[8])' ; then echo winter else echo summer fi </code></pre> <p>That's because <a href="https://perldoc.pl/perlfunc#localtime" rel="nofollow noreferrer">localtime</a> returns the following list:</p> <pre class="lang-perl prettyprint-override"><cod...
<p>Perl to the rescue:</p> <pre><code>if perl -e 'exit ((localtime)[8])' ; then echo winter else echo summer fi </code></pre> <p>That's because <a href="https://perldoc.pl/perlfunc#localtime" rel="nofollow noreferrer">localtime</a> returns the following list:</p> <pre class="lang-perl prettyprint-override"><cod...
387, 5002, 33279
bash, date, dst
<h1>Detect daylight saving time in bash</h1> <p>I want to detect if I'm in winter or summer time. My current approach is:</p> <pre><code>if date +%Z | grep -e CET -e EST; then # I'm in winter time else # I'm in summer time fi </code></pre> <p>which have obvious drawback as you have to know all the timezone names....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,254
bash
# Detect daylight saving time in bash I want to detect if I'm in winter or summer time. My current approach is: ``` if date +%Z | grep -e CET -e EST; then # I'm in winter time else # I'm in summer time fi ``` which have obvious drawback as you have to know all the timezone names.
Perl to the rescue: ``` if perl -e 'exit ((localtime)[8])' ; then echo winter else echo summer fi ``` That's because [localtime](https://perldoc.pl/perlfunc#localtime) returns the following list: ``` # 0 1 2 3 4 5 6 7 8 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)...
18410785
Bash script containing binary executable
14
2013-08-23 19:51:01
<p>Is it possible to write a bash script, which would contain a binary executable program inside?</p> <p>I mean a script, which would contain a dump of an executable in a textual form, which will be dumped back to an executable by this script when it is executed?</p> <p>I would love to know a solution, which will wor...
27,754
2,427,895
2023-06-25 01:23:43
18,410,939
11
2013-08-23 20:02:22
1,525,291
2013-09-03 19:18:57
https://stackoverflow.com/q/18410785
https://stackoverflow.com/a/18410939
<p>i never done something like this before ;) this will compile some c source, create a <code>b.bash</code> script containing the binary (and the original script for simple development)</p> <p>(a.bash)</p> <pre><code>#!/bin/bash if [ "$0" == "b.bash" ];then tail -n +$[ `grep -n '^BINARY' $0|cut -d ':' -f 1` + 1 ] ...
<p>i never done something like this before ;) this will compile some c source, create a <code>b.bash</code> script containing the binary (and the original script for simple development)</p> <p>(a.bash)</p> <pre><code>#!/bin/bash if [ "$0" == "b.bash" ];then tail -n +$[ `grep -n '^BINARY' $0|cut -d ':' -f 1` + 1 ] ...
34, 368, 387, 4779
bash, binary, dump, unix
<h1>Bash script containing binary executable</h1> <p>Is it possible to write a bash script, which would contain a binary executable program inside?</p> <p>I mean a script, which would contain a dump of an executable in a textual form, which will be dumped back to an executable by this script when it is executed?</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,255
bash
# Bash script containing binary executable Is it possible to write a bash script, which would contain a binary executable program inside? I mean a script, which would contain a dump of an executable in a textual form, which will be dumped back to an executable by this script when it is executed? I would love to know...
i never done something like this before ;) this will compile some c source, create a `b.bash` script containing the binary (and the original script for simple development) (a.bash) ``` #!/bin/bash if [ "$0" == "b.bash" ];then tail -n +$[ `grep -n '^BINARY' $0|cut -d ':' -f 1` + 1 ] $0 | base64 -d > a2.out chmod ...
17130299
What's the difference between "grep -e" and "grep -E"
14
2013-06-16 04:50:18
<p>I have a file <code>test.txt</code>, in which there are some formatted phone numbers. I'm trying to use <code>grep</code> to find the lines containing a phone number.</p> <p>It seems that <code>grep -e "[0-9]{3}-[0-9]{3}-[0-9]{4}" test.txt</code> doesn't work and gives no results. But <code>grep -E "[0-9]{3}-[0-9]{...
36,633
2,440,712
2013-06-16 05:16:04
17,130,319
11
2013-06-16 04:54:27
2,000,867
2013-06-16 05:16:04
https://stackoverflow.com/q/17130299
https://stackoverflow.com/a/17130319
<p>As you mentioned, <code>grep -E</code> is for extended regular expressions <strike>whereas <code>-e</code> is for basic regular expressions</strike>. From the man page:</p> <p>EDIT: As Jonathan pointed out below, <code>grep -e</code> "specifies that the following argument is (one of) the regular expression(s) to be...
<p>As you mentioned, <code>grep -E</code> is for extended regular expressions <strike>whereas <code>-e</code> is for basic regular expressions</strike>. From the man page:</p> <p>EDIT: As Jonathan pointed out below, <code>grep -e</code> "specifies that the following argument is (one of) the regular expression(s) to be...
58, 390, 1271
grep, linux, shell
<h1>What's the difference between "grep -e" and "grep -E"</h1> <p>I have a file <code>test.txt</code>, in which there are some formatted phone numbers. I'm trying to use <code>grep</code> to find the lines containing a phone number.</p> <p>It seems that <code>grep -e "[0-9]{3}-[0-9]{3}-[0-9]{4}" test.txt</code> doesn'...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,256
bash
# What's the difference between "grep -e" and "grep -E" I have a file `test.txt`, in which there are some formatted phone numbers. I'm trying to use `grep` to find the lines containing a phone number. It seems that `grep -e "[0-9]{3}-[0-9]{3}-[0-9]{4}" test.txt` doesn't work and gives no results. But `grep -E "[0-9]{...
As you mentioned, `grep -E` is for extended regular expressions whereas `-e` is for basic regular expressions. From the man page: EDIT: As Jonathan pointed out below, `grep -e` "specifies that the following argument is (one of) the regular expression(s) to be matched." > ### Basic vs Extended Regular Expressions > > ...
10187837
Granting SeServiceLogonRight to a user from PowerShell
14
2012-04-17 08:38:25
<p>In a script I'm currently writing, I create a dedicated user for starting some windows services that we internally developed. In order to start those services, our "dedicated" user needs the SeServiceLogonRight privilege. Currently, I'm assigning that privilege using ntrights.exe with the following call from my Powe...
37,494
311,712
2025-02-11 18:20:48
10,188,472
11
2012-04-17 09:19:10
251,123
2012-04-17 09:39:50
https://stackoverflow.com/q/10187837
https://stackoverflow.com/a/10188472
<p>This worked for me. You can decide which is cleaner ;-) The key is the LsaAddAccountRights windows API function.</p> <pre><code>Add-Type @' using System; using System.Collections.Generic; using System.Text; namespace MyLsaWrapper { using System.Runtime.InteropServices; using System.Security; using Syst...
<p>This worked for me. You can decide which is cleaner ;-) The key is the LsaAddAccountRights windows API function.</p> <pre><code>Add-Type @' using System; using System.Collections.Generic; using System.Text; namespace MyLsaWrapper { using System.Runtime.InteropServices; using System.Security; using Syst...
526
powershell
<h1>Granting SeServiceLogonRight to a user from PowerShell</h1> <p>In a script I'm currently writing, I create a dedicated user for starting some windows services that we internally developed. In order to start those services, our "dedicated" user needs the SeServiceLogonRight privilege. Currently, I'm assigning that p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,257
bash
# Granting SeServiceLogonRight to a user from PowerShell In a script I'm currently writing, I create a dedicated user for starting some windows services that we internally developed. In order to start those services, our "dedicated" user needs the SeServiceLogonRight privilege. Currently, I'm assigning that privilege ...
This worked for me. You can decide which is cleaner ;-) The key is the LsaAddAccountRights windows API function. ``` Add-Type @' using System; using System.Collections.Generic; using System.Text; namespace MyLsaWrapper { using System.Runtime.InteropServices; using System.Security; using System.Management;...
8590872
Pipe emacs shell output to a new buffer
14
2011-12-21 13:52:46
<p>For example, I want to be able to type something like:</p> <pre><code>$ git diff | tempbuffer </code></pre> <p>and have the diff opened in a new, unsaved buffer.</p>
8,794
1,109,968
2018-01-18 11:41:48
8,591,023
11
2011-12-21 14:04:00
324,105
2011-12-21 14:04:00
https://stackoverflow.com/q/8590872
https://stackoverflow.com/a/8591023
<p>You can just use <kbd>M-!</kbd> -- it will run the command within the same cwd as your shell buffer, and output the results to a <code>*Shell Command Output*</code> buffer.</p> <p>Note that if the results are brief, that buffer will not be raised and the output will be copied to the echo area; however the buffer <e...
<p>You can just use <kbd>M-!</kbd> -- it will run the command within the same cwd as your shell buffer, and output the results to a <code>*Shell Command Output*</code> buffer.</p> <p>Note that if the results are brief, that buffer will not be raised and the output will be copied to the echo area; however the buffer <e...
371, 390
emacs, shell
<h1>Pipe emacs shell output to a new buffer</h1> <p>For example, I want to be able to type something like:</p> <pre><code>$ git diff | tempbuffer </code></pre> <p>and have the diff opened in a new, unsaved buffer.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,258
bash
# Pipe emacs shell output to a new buffer For example, I want to be able to type something like: ``` $ git diff | tempbuffer ``` and have the diff opened in a new, unsaved buffer.
You can just use `M-!` -- it will run the command within the same cwd as your shell buffer, and output the results to a `*Shell Command Output*` buffer. Note that if the results are brief, that buffer will not be raised and the output will be copied to the echo area; however the buffer *is* still used and available. `...
5317315
Executing a Powershell script from PHP
14
2011-03-15 20:01:16
<p>I'm trying to execute a powershell script from PHP, but it does not seem to work.</p> <p>The script 'newEvent.ps1' creates an event on the Exchange server.</p> <pre><code>$psPath = "powershell.exe"; $psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\"; $psScript = "newEvent.ps1"; $runScript = $psDIR. $psScript; $runCMD = $...
80,950
638,077
2024-02-29 17:48:18
5,319,219
11
2011-03-15 23:19:58
125,356
2021-08-03 14:01:47
https://stackoverflow.com/q/5317315
https://stackoverflow.com/a/5319219
<p>It looks like your command is surrounded by single-quotes. I think if you remove them, your command should run.</p> <p><code>shell_exec</code> returns the output from the command you run. To further diagnose, store the output in a variable, then print it out:</p> <pre><code>$output = shell_exec($runCMD); echo '&lt...
<p>It looks like your command is surrounded by single-quotes. I think if you remove them, your command should run.</p> <p><code>shell_exec</code> returns the output from the command you run. To further diagnose, store the output in a variable, then print it out:</p> <pre><code>$output = shell_exec($runCMD); echo '&lt...
5, 526, 2060, 8646
exchange-server, php, powershell, shell-exec
<h1>Executing a Powershell script from PHP</h1> <p>I'm trying to execute a powershell script from PHP, but it does not seem to work.</p> <p>The script 'newEvent.ps1' creates an event on the Exchange server.</p> <pre><code>$psPath = "powershell.exe"; $psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\"; $psScript = "newEvent.p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,259
bash
# Executing a Powershell script from PHP I'm trying to execute a powershell script from PHP, but it does not seem to work. The script 'newEvent.ps1' creates an event on the Exchange server. ``` $psPath = "powershell.exe"; $psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\"; $psScript = "newEvent.ps1"; $runScript = $psDIR. $...
It looks like your command is surrounded by single-quotes. I think if you remove them, your command should run. `shell_exec` returns the output from the command you run. To further diagnose, store the output in a variable, then print it out: ``` $output = shell_exec($runCMD); echo '<pre>' . $output . '</pre>'; ``` M...
2674117
How to sort output of "s3cmd ls"
14
2010-04-20 10:01:56
<p>Amazon "s3cmd ls" takes like this output:<br></p> <pre><code>2010-02-20 21:01 1458414588 s3://file1.tgz.00&lt;br&gt; 2010-02-20 21:10 1458414527 s3://file1.tgz.01&lt;br&gt; 2010-02-20 22:01 1458414588 s3://file2.tgz.00&lt;br&gt; 2010-02-20 23:10 1458414527 s3://file2.tgz.01&lt;br&gt; 2010-02-20 23:20 145841...
14,052
273,408
2020-07-15 23:05:06
2,688,207
11
2010-04-22 04:14:51
312,172
2010-04-22 04:14:51
https://stackoverflow.com/q/2674117
https://stackoverflow.com/a/2688207
<pre><code>DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}') s3cmd ls | grep $DATE </code></pre> <p>sorting as a number schould put youngest dates last. Tail -n1 takes the last line, awk cuts the first word which is the date. Use that to get all entries of that date. </p> <p>But maybe I didn't understand the...
<pre><code>DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}') s3cmd ls | grep $DATE </code></pre> <p>sorting as a number schould put youngest dates last. Tail -n1 takes the last line, awk cuts the first word which is the date. Use that to get all entries of that date. </p> <p>But maybe I didn't understand the...
18, 134, 387, 3589
bash, ls, regex, sorting
<h1>How to sort output of "s3cmd ls"</h1> <p>Amazon "s3cmd ls" takes like this output:<br></p> <pre><code>2010-02-20 21:01 1458414588 s3://file1.tgz.00&lt;br&gt; 2010-02-20 21:10 1458414527 s3://file1.tgz.01&lt;br&gt; 2010-02-20 22:01 1458414588 s3://file2.tgz.00&lt;br&gt; 2010-02-20 23:10 1458414527 s3://file...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,260
bash
# How to sort output of "s3cmd ls" Amazon "s3cmd ls" takes like this output: ``` 2010-02-20 21:01 1458414588 s3://file1.tgz.00<br> 2010-02-20 21:10 1458414527 s3://file1.tgz.01<br> 2010-02-20 22:01 1458414588 s3://file2.tgz.00<br> 2010-02-20 23:10 1458414527 s3://file2.tgz.01<br> 2010-02-20 23:20 1458414588 ...
``` DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}') s3cmd ls | grep $DATE ``` sorting as a number schould put youngest dates last. Tail -n1 takes the last line, awk cuts the first word which is the date. Use that to get all entries of that date. But maybe I didn't understand the question - so you have to re...
2379514
PowerShell, formatting values in another culture
14
2010-03-04 13:21:58
<p>Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses <code>.</code> as a decimal separator, while PowerShell honors my locale settings (<code>de-DE</code>) when converting floating-point numbers to string...
24,642
73,070
2022-09-04 00:50:39
2,380,257
11
2010-03-04 15:04:28
153,982
2010-03-04 15:04:28
https://stackoverflow.com/q/2379514
https://stackoverflow.com/a/2380257
<p>This is a PowerShell function I use for testing script in other cultures. I believe it could be used for what you are after:</p> <pre><code>function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"), [ScriptBlock]...
<p>This is a PowerShell function I use for testing script in other cultures. I believe it could be used for what you are after:</p> <pre><code>function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"), [ScriptBlock]...
526, 1921, 33053
locale, number-formatting, powershell
<h1>PowerShell, formatting values in another culture</h1> <p>Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses <code>.</code> as a decimal separator, while PowerShell honors my locale settings (<code>de-D...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,261
bash
# PowerShell, formatting values in another culture Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses `.` as a decimal separator, while PowerShell honors my locale settings (`de-DE`) when converting float...
This is a PowerShell function I use for testing script in other cultures. I believe it could be used for what you are after: ``` function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"), [ScriptBlock]$script=(throw...
1355700
Proper use of Invoke-Expression?
14
2009-08-31 03:47:58
<p>I've just recently completed my first nightly build script (first significant anything script, really) in powershell. I seem to have things working well, if not yet robustly (I haven't handled significant error-checking yet), but I found myself falling into an idiom around the <code>Invoke-Expression</code> cmdlet,...
19,604
6,932
2011-11-28 00:12:32
1,355,829
11
2009-08-31 04:46:24
74,439
2011-11-28 00:12:32
https://stackoverflow.com/q/1355700
https://stackoverflow.com/a/1355829
<p>Looks fine to me. Only thing I'd change is to use more Powershell features in place of fragile assumptions. E.g.:</p> <ul> <li><p>use Join-Path instead of string concatenation</p></li> <li><p>use the <code>Env:\</code> provider to look up the <code>%programfiles(x86)%</code> dir (or better yet, use the <code>HKML...
<p>Looks fine to me. Only thing I'd change is to use more Powershell features in place of fragile assumptions. E.g.:</p> <ul> <li><p>use Join-Path instead of string concatenation</p></li> <li><p>use the <code>Env:\</code> provider to look up the <code>%programfiles(x86)%</code> dir (or better yet, use the <code>HKML...
526, 531
powershell, scripting
<h1>Proper use of Invoke-Expression?</h1> <p>I've just recently completed my first nightly build script (first significant anything script, really) in powershell. I seem to have things working well, if not yet robustly (I haven't handled significant error-checking yet), but I found myself falling into an idiom around ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,262
bash
# Proper use of Invoke-Expression? I've just recently completed my first nightly build script (first significant anything script, really) in powershell. I seem to have things working well, if not yet robustly (I haven't handled significant error-checking yet), but I found myself falling into an idiom around the `Invok...
Looks fine to me. Only thing I'd change is to use more Powershell features in place of fragile assumptions. E.g.: - use Join-Path instead of string concatenation - use the `Env:\` provider to look up the `%programfiles(x86)%` dir (or better yet, use the `HKML:\` provider to find the path - it's in SOFTWARE\Microsoft\V...
58313106
Create RS256 JWT in bash
13
2019-10-09 22:30:59
<p>I'm trying to construct an RS256 JWT token using only bash and openSSL (I have limited development tools at my disposal).</p> <p>I've devised a script which takes the header and payload from txt files (stripping out newlines etc), base-64URL encodes them and concatenates them together with a '.' separator.</p> <p>...
13,070
1,125,133
2020-06-29 21:15:36
58,326,090
11
2019-10-10 15:10:48
1,125,133
2019-10-10 15:10:48
https://stackoverflow.com/q/58313106
https://stackoverflow.com/a/58326090
<p>Successfully resolved this. It was caused by a couple of issues:</p> <ol> <li>openssl base64 inserts carriage returns every 70-odd characters by default. I believe you can override this, but just using the <code>base64</code> command instead solved that.</li> <li><p>My signing step was wrong. I replaced <code>rs...
<p>Successfully resolved this. It was caused by a couple of issues:</p> <ol> <li>openssl base64 inserts carriage returns every 70-odd characters by default. I believe you can override this, but just using the <code>base64</code> command instead solved that.</li> <li><p>My signing step was wrong. I replaced <code>rs...
369, 387, 1999, 65223
bash, jwt, macos, openssl
<h1>Create RS256 JWT in bash</h1> <p>I'm trying to construct an RS256 JWT token using only bash and openSSL (I have limited development tools at my disposal).</p> <p>I've devised a script which takes the header and payload from txt files (stripping out newlines etc), base-64URL encodes them and concatenates them toget...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,263
bash
# Create RS256 JWT in bash I'm trying to construct an RS256 JWT token using only bash and openSSL (I have limited development tools at my disposal). I've devised a script which takes the header and payload from txt files (stripping out newlines etc), base-64URL encodes them and concatenates them together with a '.' s...
Successfully resolved this. It was caused by a couple of issues: 1. openssl base64 inserts carriage returns every 70-odd characters by default. I believe you can override this, but just using the `base64` command instead solved that. 2. My signing step was wrong. I replaced `rsautl` with `dgst` as follows: openssl...
54383290
Jenkins "file not found" error with existing Bash script
13
2019-01-26 22:13:00
<p>My goal is to have Jenkins 2 execute alpha integration tests between an express js app and a postgres db. I am to spin up containerized resources locally and test successfully with bash scripts that employ <code>docker-compose</code>. The relevant bash script is <code>scripts/docker/dockerRunTest.sh</code>.</p> <p>...
12,521
4,723,005
2019-11-11 12:55:58
54,389,281
11
2019-01-27 14:39:20
1,421,222
2019-01-27 17:01:06
https://stackoverflow.com/q/54383290
https://stackoverflow.com/a/54389281
<p><code>tmaier/docker-compose</code> image doesn't have <code>/bin/bash</code> interpreter installed by default since <code>latest</code> tag is an <code>alpine</code> image [1, 2]. This can be confirmed by running:</p> <pre><code>$ docker run -it --rm tmaier/docker-compose bash /usr/local/bin/docker-entrypoint.sh: e...
<p><code>tmaier/docker-compose</code> image doesn't have <code>/bin/bash</code> interpreter installed by default since <code>latest</code> tag is an <code>alpine</code> image [1, 2]. This can be confirmed by running:</p> <pre><code>$ docker run -it --rm tmaier/docker-compose bash /usr/local/bin/docker-entrypoint.sh: e...
387, 64999, 90304, 110604
bash, docker, docker-compose, jenkins
<h1>Jenkins "file not found" error with existing Bash script</h1> <p>My goal is to have Jenkins 2 execute alpha integration tests between an express js app and a postgres db. I am to spin up containerized resources locally and test successfully with bash scripts that employ <code>docker-compose</code>. The relevant bas...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,264
bash
# Jenkins "file not found" error with existing Bash script My goal is to have Jenkins 2 execute alpha integration tests between an express js app and a postgres db. I am to spin up containerized resources locally and test successfully with bash scripts that employ `docker-compose`. The relevant bash script is `scripts...
`tmaier/docker-compose` image doesn't have `/bin/bash` interpreter installed by default since `latest` tag is an `alpine` image [1, 2]. This can be confirmed by running: ``` $ docker run -it --rm tmaier/docker-compose bash /usr/local/bin/docker-entrypoint.sh: exec: line 35: bash: not found ``` To get the script worki...
48119289
How to get environment variables in live Heroku dyno
13
2018-01-05 18:28:14
<p>There is a <code>heroku config</code> command but that apparently just shows me what the current setting is. I want to confirm in a dyno what my application is actually seeing in the running environment.</p> <p>I tried <code>heroku ps:exec -a &lt;app&gt; -d &lt;dyno_instance&gt; --ssh env</code>and this has some ge...
5,966
2,340,636
2021-03-13 21:41:36
48,750,460
11
2018-02-12 15:56:49
5,955,911
2018-02-12 15:56:49
https://stackoverflow.com/q/48119289
https://stackoverflow.com/a/48750460
<p>Try <code>heroku run env</code> instead. </p> <p>According to the <a href="https://devcenter.heroku.com/articles/exec#environment-variables" rel="noreferrer">documentation</a>: "The SSH session created by Heroku Exec will not have the config vars set as environment variables (i.e., env in a session will not list c...
<p>Try <code>heroku run env</code> instead. </p> <p>According to the <a href="https://devcenter.heroku.com/articles/exec#environment-variables" rel="noreferrer">documentation</a>: "The SSH session created by Heroku Exec will not have the config vars set as environment variables (i.e., env in a session will not list c...
387, 8279
bash, heroku
<h1>How to get environment variables in live Heroku dyno</h1> <p>There is a <code>heroku config</code> command but that apparently just shows me what the current setting is. I want to confirm in a dyno what my application is actually seeing in the running environment.</p> <p>I tried <code>heroku ps:exec -a &lt;app&gt;...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,265
bash
# How to get environment variables in live Heroku dyno There is a `heroku config` command but that apparently just shows me what the current setting is. I want to confirm in a dyno what my application is actually seeing in the running environment. I tried `heroku ps:exec -a <app> -d <dyno_instance> --ssh env`and this...
Try `heroku run env` instead. According to the [documentation](https://devcenter.heroku.com/articles/exec#environment-variables): "The SSH session created by Heroku Exec will not have the config vars set as environment variables (i.e., env in a session will not list config vars set by `heroku config:set`)."
46946888
What happens when reading into a variable in a pipeline?
13
2017-10-26 06:03:56
<pre><code>echo hello | read str echo $str </code></pre> <p>This <code>read</code> is executed after the pipeline, which means that the output of the <code>echo</code> gets read into <code>str</code> - but because it is after a pipe, the contents of <code>str</code> are now in a subshell that cannot be read by the pare...
1,956
824,282
2021-12-27 05:03:39
46,947,363
11
2017-10-26 06:36:02
2,088,135
2017-10-26 06:36:02
https://stackoverflow.com/q/46946888
https://stackoverflow.com/a/46947363
<p>In your example, <code>$str</code> exists inside a subshell and by default, it disappears once the line has finished. A child process cannot modify its parent.</p> <p>Aside from changing the shell option <code>lastpipe</code>, you can also change the code to avoid using a pipe. In this case, you could use:</p> <pr...
<p>In your example, <code>$str</code> exists inside a subshell and by default, it disappears once the line has finished. A child process cannot modify its parent.</p> <p>Aside from changing the shell option <code>lastpipe</code>, you can also change the code to avoid using a pipe. In this case, you could use:</p> <pr...
387, 2844, 57788
bash, pipeline, subshell
<h1>What happens when reading into a variable in a pipeline?</h1> <pre><code>echo hello | read str echo $str </code></pre> <p>This <code>read</code> is executed after the pipeline, which means that the output of the <code>echo</code> gets read into <code>str</code> - but because it is after a pipe, the contents of <cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,266
bash
# What happens when reading into a variable in a pipeline? ``` echo hello | read str echo $str ``` This `read` is executed after the pipeline, which means that the output of the `echo` gets read into `str` - but because it is after a pipe, the contents of `str` are now in a subshell that cannot be read by the parent ...
In your example, `$str` exists inside a subshell and by default, it disappears once the line has finished. A child process cannot modify its parent. Aside from changing the shell option `lastpipe`, you can also change the code to avoid using a pipe. In this case, you could use: ``` read str < <(your command) # or st...
18302856
Removing files interactively with find and xargs
13
2013-08-18 19:24:38
<p>I'm trying to pipe some files from the find command to the interactive remove command, so that I can double check the files I'm removing, but I've run into some trouble.</p> <pre><code>find -name '#*#' -print0 | xargs -0 rm -i </code></pre> <p>I thought the above would work, but instead I just get a string of <cod...
9,473
2,007,537
2021-10-27 11:04:45
42,119,953
11
2017-02-08 17:36:45
423,105
2018-07-09 14:48:05
https://stackoverflow.com/q/18302856
https://stackoverflow.com/a/42119953
<blockquote> <p><em>Can someone explain to me what's exactly is happening,</em></p> </blockquote> <p>As the <a href="http://man7.org/linux/man-pages/man1/xargs.1.html" rel="noreferrer">man page for xargs</a> says (under the <code>-a</code> option): "If you use this option, stdin remains unchanged <strong>when comman...
<blockquote> <p><em>Can someone explain to me what's exactly is happening,</em></p> </blockquote> <p>As the <a href="http://man7.org/linux/man-pages/man1/xargs.1.html" rel="noreferrer">man page for xargs</a> says (under the <code>-a</code> option): "If you use this option, stdin remains unchanged <strong>when comman...
390, 5610, 10326
rm, shell, xargs
<h1>Removing files interactively with find and xargs</h1> <p>I'm trying to pipe some files from the find command to the interactive remove command, so that I can double check the files I'm removing, but I've run into some trouble.</p> <pre><code>find -name '#*#' -print0 | xargs -0 rm -i </code></pre> <p>I thought the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,267
bash
# Removing files interactively with find and xargs I'm trying to pipe some files from the find command to the interactive remove command, so that I can double check the files I'm removing, but I've run into some trouble. ``` find -name '#*#' -print0 | xargs -0 rm -i ``` I thought the above would work, but instead I ...
> *Can someone explain to me what's exactly is happening,* As the [man page for xargs](http://man7.org/linux/man-pages/man1/xargs.1.html) says (under the `-a` option): "If you use this option, stdin remains unchanged **when commands are run**. Otherwise, **stdin is redirected from /dev/null**." Since you're not using...
40455673
Using Windows Subsystem for Linux (WSL) from Sublime Text
13
2016-11-06 23:18:30
<p>I wanted to use <code>gcc</code>, <code>g++</code> and <code>make</code> from Sublime Text to be able to compile C and C++ code to Linux runnables on Windows. I couldn't run <code>bash.exe</code> from Sublime Text, as many other users on Stack Overflow.</p>
19,353
3,137,420
2025-02-24 07:20:37
40,458,143
11
2016-11-07 05:02:03
3,137,420
2019-02-12 14:19:21
https://stackoverflow.com/q/40455673
https://stackoverflow.com/a/40458143
<ol> <li><p>You have to copy the <code>C:\Windows\System32\bash.exe</code> file to the <code>C:\Windows\SysWOW64\</code> directory. Required because of the <a href="https://msdn.microsoft.com/es-es/library/windows/desktop/aa384187(v=vs.85).aspx" rel="noreferrer">WoW64 file system redirection</a> (Thanks <a href="https:...
<ol> <li><p>You have to copy the <code>C:\Windows\System32\bash.exe</code> file to the <code>C:\Windows\SysWOW64\</code> directory. Required because of the <a href="https://msdn.microsoft.com/es-es/library/windows/desktop/aa384187(v=vs.85).aspx" rel="noreferrer">WoW64 file system redirection</a> (Thanks <a href="https:...
58, 64, 387, 72788, 119526
bash, linux, sublimetext, windows, windows-subsystem-for-linux
<h1>Using Windows Subsystem for Linux (WSL) from Sublime Text</h1> <p>I wanted to use <code>gcc</code>, <code>g++</code> and <code>make</code> from Sublime Text to be able to compile C and C++ code to Linux runnables on Windows. I couldn't run <code>bash.exe</code> from Sublime Text, as many other users on Stack Overfl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,268
bash
# Using Windows Subsystem for Linux (WSL) from Sublime Text I wanted to use `gcc`, `g++` and `make` from Sublime Text to be able to compile C and C++ code to Linux runnables on Windows. I couldn't run `bash.exe` from Sublime Text, as many other users on Stack Overflow.
1. You have to copy the `C:\Windows\System32\bash.exe` file to the `C:\Windows\SysWOW64\` directory. Required because of the [WoW64 file system redirection](https://msdn.microsoft.com/es-es/library/windows/desktop/aa384187(v=vs.85).aspx) (Thanks [Martin](https://stackoverflow.com/questions/40455673/using-windows-sub...
39104275
Replace a character with new line
13
2016-08-23 14:43:20
<p><code>Powershell ver 4. Windows 7</code></p> <p>I wanted to replace <code>,</code> with new lines in a text file. I tried the script below</p> <pre><code>(Get-Content C:\Test\test.txt).Replace(',','`n') | Set-Content C:\Test\testv2.txt </code></pre> <p>but when I see the output file I see <code>,</code> replaced ...
31,085
6,748,422
2018-02-23 06:15:04
39,104,508
11
2016-08-23 14:54:11
5,615,788
2016-08-23 14:54:11
https://stackoverflow.com/q/39104275
https://stackoverflow.com/a/39104508
<p>Try this:</p> <pre><code>[IO.File]::ReadAllText(C:\Test\test.txt) -replace ',',"`r`n" | Out-File C:\Test\testv2.txt </code></pre> <p>P.S. Sorry that don't have time to explain it, now.</p>
<p>Try this:</p> <pre><code>[IO.File]::ReadAllText(C:\Test\test.txt) -replace ',',"`r`n" | Out-File C:\Test\testv2.txt </code></pre> <p>P.S. Sorry that don't have time to explain it, now.</p>
526, 95686
powershell, powershell-4.0
<h1>Replace a character with new line</h1> <p><code>Powershell ver 4. Windows 7</code></p> <p>I wanted to replace <code>,</code> with new lines in a text file. I tried the script below</p> <pre><code>(Get-Content C:\Test\test.txt).Replace(',','`n') | Set-Content C:\Test\testv2.txt </code></pre> <p>but when I see the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,269
bash
# Replace a character with new line `Powershell ver 4. Windows 7` I wanted to replace `,` with new lines in a text file. I tried the script below ``` (Get-Content C:\Test\test.txt).Replace(',','`n') | Set-Content C:\Test\testv2.txt ``` but when I see the output file I see `,` replaced with '`n' instead of new line....
Try this: ``` [IO.File]::ReadAllText(C:\Test\test.txt) -replace ',',"`r`n" | Out-File C:\Test\testv2.txt ``` P.S. Sorry that don't have time to explain it, now.
35212701
How can I display unique words contained in a Bash string?
13
2016-02-04 22:14:34
<p>I have a string that has duplicate words. I would like to display only the unique words. The string is:</p> <pre><code>variable="alpha bravo charlie alpha delta echo charlie" </code></pre> <p>I know several tools that can do this together. This is what I figured out:</p> <pre><code>echo $variable | tr " " "\n" | ...
14,130
4,515,565
2023-06-30 04:41:48
35,214,172
11
2016-02-05 00:16:15
1,301,972
2016-02-05 01:13:07
https://stackoverflow.com/q/35212701
https://stackoverflow.com/a/35214172
<h2>Use a Bash Substitution Expansion</h2> <p>The following <a href="https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion" rel="noreferrer">shell parameter expansion</a> will substitute spaces with newlines, and then pass the results into the <em>sort</em> utility...
<h2>Use a Bash Substitution Expansion</h2> <p>The following <a href="https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion" rel="noreferrer">shell parameter expansion</a> will substitute spaces with newlines, and then pass the results into the <em>sort</em> utility...
58, 139, 387, 12147
bash, duplicates, linux, string
<h1>How can I display unique words contained in a Bash string?</h1> <p>I have a string that has duplicate words. I would like to display only the unique words. The string is:</p> <pre><code>variable="alpha bravo charlie alpha delta echo charlie" </code></pre> <p>I know several tools that can do this together. This is...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,270
bash
# How can I display unique words contained in a Bash string? I have a string that has duplicate words. I would like to display only the unique words. The string is: ``` variable="alpha bravo charlie alpha delta echo charlie" ``` I know several tools that can do this together. This is what I figured out: ``` echo $v...
## Use a Bash Substitution Expansion The following [shell parameter expansion](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion) will substitute spaces with newlines, and then pass the results into the *sort* utility to return only the unique words. ``` $ ech...
34340706
Incorrect results with bash process substitution and tail?
13
2015-12-17 17:27:29
<p>Using bash process substitution, I want to run two different commands on a file simultaneously. In this example it is not necessary but imagine that "cat /usr/share/dict/words" was a very expensive operation such as uncompressing a 50gb file.</p> <pre><code>cat /usr/share/dict/words | tee &gt;(head -1 &gt; h.txt) ...
769
1,218,704
2017-11-13 15:51:57
34,342,525
11
2015-12-17 19:17:59
4,687,135
2017-11-13 15:51:57
https://stackoverflow.com/q/34340706
https://stackoverflow.com/a/34342525
<p>Ok, what seems to happen is that once the <code>head -1</code> command finishes it exits and that causes <code>tee</code> to get a SIGPIPE it tries to write to the named pipe that the process substitution setup which generates an <code>EPIPE</code> and according to <code>man 2 write</code> will also generate <code>S...
<p>Ok, what seems to happen is that once the <code>head -1</code> command finishes it exits and that causes <code>tee</code> to get a SIGPIPE it tries to write to the named pipe that the process substitution setup which generates an <code>EPIPE</code> and according to <code>man 2 write</code> will also generate <code>S...
387, 5813, 7896, 22055
bash, pipe, tail, tee
<h1>Incorrect results with bash process substitution and tail?</h1> <p>Using bash process substitution, I want to run two different commands on a file simultaneously. In this example it is not necessary but imagine that "cat /usr/share/dict/words" was a very expensive operation such as uncompressing a 50gb file.</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,271
bash
# Incorrect results with bash process substitution and tail? Using bash process substitution, I want to run two different commands on a file simultaneously. In this example it is not necessary but imagine that "cat /usr/share/dict/words" was a very expensive operation such as uncompressing a 50gb file. ``` cat /usr/s...
Ok, what seems to happen is that once the `head -1` command finishes it exits and that causes `tee` to get a SIGPIPE it tries to write to the named pipe that the process substitution setup which generates an `EPIPE` and according to `man 2 write` will also generate `SIGPIPE` in the writing process, which causes `tee` t...
34012095
How to rename an annotated tag in Git
13
2015-12-01 03:30:45
<p>How can an existing annotated tag be renamed in Git?</p> <p>I have almost a hundred tags representing version numbers on a repository, and each tag is annotated with a useful description about what was changed that version. I'd like to change the naming style I've used for these tags, and recording the tag message,...
7,822
1,772,838
2017-01-16 13:46:58
34,012,542
11
2015-12-01 04:20:29
1,256,452
2015-12-01 05:40:47
https://stackoverflow.com/q/34012095
https://stackoverflow.com/a/34012542
<p>The bad news is that the name of an annotated tag object is embedded inside that annotated tag object. So if you want to be totally thorough, you'll need to replace those tag objects:</p> <ul> <li><p>If they're <em>signed</em> tags you will need to regenerate them with new signatures.</p></li> <li><p>Otherwise, it...
<p>The bad news is that the name of an annotated tag object is embedded inside that annotated tag object. So if you want to be totally thorough, you'll need to replace those tag objects:</p> <ul> <li><p>If they're <em>signed</em> tags you will need to regenerate them with new signatures.</p></li> <li><p>Otherwise, it...
115, 119, 61874
git, git-bash, tags
<h1>How to rename an annotated tag in Git</h1> <p>How can an existing annotated tag be renamed in Git?</p> <p>I have almost a hundred tags representing version numbers on a repository, and each tag is annotated with a useful description about what was changed that version. I'd like to change the naming style I've used...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,272
bash
# How to rename an annotated tag in Git How can an existing annotated tag be renamed in Git? I have almost a hundred tags representing version numbers on a repository, and each tag is annotated with a useful description about what was changed that version. I'd like to change the naming style I've used for these tags,...
The bad news is that the name of an annotated tag object is embedded inside that annotated tag object. So if you want to be totally thorough, you'll need to replace those tag objects: - If they're *signed* tags you will need to regenerate them with new signatures. - Otherwise, it's possible to copy the tag objects to ...
32069885
Exit tcsh script if error
13
2015-08-18 10:30:11
<p>I am tryin to write a tcsh script. I need the script exit if any of its commands fails. </p> <p>In shell I use <code>set -e</code> but I don't know its equivalent in tcsh</p> <pre><code>#!/usr/bin/env tcsh set NAME=aaaa set VERSION=6.1 #set -e equivalent #do somthing </code></pre> <p>Thanks </p>
11,823
1,955,287
2017-02-17 15:03:33
32,073,958
11
2015-08-18 13:34:45
660,921
2017-02-17 15:03:33
https://stackoverflow.com/q/32069885
https://stackoverflow.com/a/32073958
<p>In (t)csh, <code>set</code> is used to define a variable; <code>set foo = bar</code> will assign the value <code>bar</code> to the variable <code>foo</code> (like <code>foo=bar</code> does in Bourne shell scripting).</p> <p>In any case, from <code>tcsh(1)</code>:</p> <pre><code>Argument list processing If the f...
<p>In (t)csh, <code>set</code> is used to define a variable; <code>set foo = bar</code> will assign the value <code>bar</code> to the variable <code>foo</code> (like <code>foo=bar</code> does in Bourne shell scripting).</p> <p>In any case, from <code>tcsh(1)</code>:</p> <pre><code>Argument list processing If the f...
390, 8599
shell, tcsh
<h1>Exit tcsh script if error</h1> <p>I am tryin to write a tcsh script. I need the script exit if any of its commands fails. </p> <p>In shell I use <code>set -e</code> but I don't know its equivalent in tcsh</p> <pre><code>#!/usr/bin/env tcsh set NAME=aaaa set VERSION=6.1 #set -e equivalent #do somthing </code></...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,273
bash
# Exit tcsh script if error I am tryin to write a tcsh script. I need the script exit if any of its commands fails. In shell I use `set -e` but I don't know its equivalent in tcsh ``` #!/usr/bin/env tcsh set NAME=aaaa set VERSION=6.1 #set -e equivalent #do somthing ``` Thanks
In (t)csh, `set` is used to define a variable; `set foo = bar` will assign the value `bar` to the variable `foo` (like `foo=bar` does in Bourne shell scripting). In any case, from `tcsh(1)`: ``` Argument list processing If the first argument (argument 0) to the shell is `-' then it is a login shell. A logi...
30656618
AWS Powershell to retrieve AWS account number
13
2015-06-05 00:52:59
<p>Does anyone know how to get AWS account number using AWS Powershell? Doesn't look like there's an API available for that.</p>
7,662
4,625,498
2021-10-08 07:28:37
30,656,826
11
2015-06-05 01:18:07
775,544
2015-06-05 01:18:07
https://stackoverflow.com/q/30656618
https://stackoverflow.com/a/30656826
<p>Not directly. However, your Account ID is a part of the <a href="http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html" rel="noreferrer">Arn</a> of resources that you create... and those that are automatically created for you. Some resources will also list you as an OwnerId. </p> <p>The <a hre...
<p>Not directly. However, your Account ID is a part of the <a href="http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html" rel="noreferrer">Arn</a> of resources that you create... and those that are automatically created for you. Some resources will also list you as an OwnerId. </p> <p>The <a hre...
526, 33388, 100823
amazon-web-services, aws-powershell, powershell
<h1>AWS Powershell to retrieve AWS account number</h1> <p>Does anyone know how to get AWS account number using AWS Powershell? Doesn't look like there's an API available for that.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,274
bash
# AWS Powershell to retrieve AWS account number Does anyone know how to get AWS account number using AWS Powershell? Doesn't look like there's an API available for that.
Not directly. However, your Account ID is a part of the [Arn](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of resources that you create... and those that are automatically created for you. Some resources will also list you as an OwnerId. The [Default Security Group](http://docs.aws.amazon...