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
6517783
Remove files when first two characters are ZZ
9
2011-06-29 08:34:24
<p>I want to delete all the files when the first two characters are equal to <code>zz</code> or <code>ZZ</code>. How can I do it?</p>
8,570
799,383
2019-05-25 13:41:20
6,520,504
13
2011-06-29 12:18:04
9,833
2011-06-29 13:19:49
https://stackoverflow.com/q/6517783
https://stackoverflow.com/a/6520504
<p>Get all objects (including hidden, recursively) from a path with names starting with 'zz', filter out directory objects and delete the items.</p> <pre><code>Get-ChildItem &lt;path&gt; -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item </code></pre>
<p>Get all objects (including hidden, recursively) from a path with names starting with 'zz', filter out directory objects and delete the items.</p> <pre><code>Get-ChildItem &lt;path&gt; -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item </code></pre>
64, 526, 896
desktop, powershell, windows
<h1>Remove files when first two characters are ZZ</h1> <p>I want to delete all the files when the first two characters are equal to <code>zz</code> or <code>ZZ</code>. How can I do it?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,369
bash
# Remove files when first two characters are ZZ I want to delete all the files when the first two characters are equal to `zz` or `ZZ`. How can I do it?
Get all objects (including hidden, recursively) from a path with names starting with 'zz', filter out directory objects and delete the items. ``` Get-ChildItem <path> -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item ```
5622746
Power shell: Import-Module
9
2011-04-11 14:26:19
<p>I have been trying to us the app fabric caching on a win2008 standard server. When I execute the follwowing command I get: Import-Module DistributedCacheAdministration Import-Module : The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was found in any module directory....
7,568
188,577
2013-08-07 09:03:03
5,623,399
13
2011-04-11 15:11:33
662,388
2011-08-23 18:58:16
https://stackoverflow.com/q/5622746
https://stackoverflow.com/a/5623399
<p>Modules and their commands is a feature in Powershell 2 only, so you can be quite certain you're running this version. I guess you're confused because the Powershell.exe is located in a "1.0" directory; that's only to make version 2.0 backwards compatible.</p> <p>You need to specify the exact location of the module...
<p>Modules and their commands is a feature in Powershell 2 only, so you can be quite certain you're running this version. I guess you're confused because the Powershell.exe is located in a "1.0" directory; that's only to make version 2.0 backwards compatible.</p> <p>You need to specify the exact location of the module...
9, 526, 1763, 44344
appfabric, c#, caching, powershell
<h1>Power shell: Import-Module</h1> <p>I have been trying to us the app fabric caching on a win2008 standard server. When I execute the follwowing command I get: Import-Module DistributedCacheAdministration Import-Module : The specified module 'DistributedCacheAdministration' was not loaded because no valid module fil...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,370
bash
# Power shell: Import-Module I have been trying to us the app fabric caching on a win2008 standard server. When I execute the follwowing command I get: Import-Module DistributedCacheAdministration Import-Module : The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was foun...
Modules and their commands is a feature in Powershell 2 only, so you can be quite certain you're running this version. I guess you're confused because the Powershell.exe is located in a "1.0" directory; that's only to make version 2.0 backwards compatible. You need to specify the exact location of the module to load: ...
4696128
Bash script — determine if file modified?
9
2011-01-14 21:26:41
<p>I have a Bash script that repeatedly copies files every 5 seconds. But this is a touch overkill as usually there is no change.</p> <p>I know about the Linux command <code>watch</code> but as this script will be used on OS X computers (which don’t have <code>watch</code>, and I don’t want to make everyone install ma...
14,680
211,327
2011-12-08 01:24:00
4,696,191
13
2011-01-14 21:34:19
241,148
2011-01-15 02:32:54
https://stackoverflow.com/q/4696128
https://stackoverflow.com/a/4696191
<p>I tend to agree with the <code>rsync</code> answer if you have big trees of files to manage, but you can use the -u (--update) flag to cp to copy the file(s) over only if the source is newer than the destination.</p> <p>cp -u </p> <p><strong>Edit</strong></p> <p>Since you've updated the question to indicate that...
<p>I tend to agree with the <code>rsync</code> answer if you have big trees of files to manage, but you can use the -u (--update) flag to cp to copy the file(s) over only if the source is newer than the destination.</p> <p>cp -u </p> <p><strong>Edit</strong></p> <p>Since you've updated the question to indicate that...
369, 387
bash, macos
<h1>Bash script — determine if file modified?</h1> <p>I have a Bash script that repeatedly copies files every 5 seconds. But this is a touch overkill as usually there is no change.</p> <p>I know about the Linux command <code>watch</code> but as this script will be used on OS X computers (which don’t have <code>watch</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,371
bash
# Bash script — determine if file modified? I have a Bash script that repeatedly copies files every 5 seconds. But this is a touch overkill as usually there is no change. I know about the Linux command `watch` but as this script will be used on OS X computers (which don’t have `watch`, and I don’t want to make everyo...
I tend to agree with the `rsync` answer if you have big trees of files to manage, but you can use the -u (--update) flag to cp to copy the file(s) over only if the source is newer than the destination. cp -u **Edit** Since you've updated the question to indicate that you'd like to take some additional actions, you'l...
4600226
Shell Scripts in Mac OS X run from home directory?
9
2011-01-05 02:04:40
<p>I'm a longtime Windows and Linux user and have had some weird experiences writing shell scripts on Mac OS X. In particular, I can write the scripts just fine and run them from the terminal, but every time I try running one from a Finder window it always executes from the user's home directory rather than the direct...
7,600
501,557
2018-11-30 03:00:48
4,600,238
13
2011-01-05 02:08:20
182,327
2011-01-06 01:23:26
https://stackoverflow.com/q/4600226
https://stackoverflow.com/a/4600238
<p>The behaviour seems consistent to me. It inherits your finder instances environment, which would be rooted at your home directory.</p> <p>However, it's not too hard to fix.</p> <pre><code>cd "$(dirname "$0")" </code></pre> <p>Ought to do the trick ala:</p> <pre><code>richh-desktop % fullname.sh /home/richh/bin ...
<p>The behaviour seems consistent to me. It inherits your finder instances environment, which would be rooted at your home directory.</p> <p>However, it's not too hard to fix.</p> <pre><code>cd "$(dirname "$0")" </code></pre> <p>Ought to do the trick ala:</p> <pre><code>richh-desktop % fullname.sh /home/richh/bin ...
369, 390
macos, shell
<h1>Shell Scripts in Mac OS X run from home directory?</h1> <p>I'm a longtime Windows and Linux user and have had some weird experiences writing shell scripts on Mac OS X. In particular, I can write the scripts just fine and run them from the terminal, but every time I try running one from a Finder window it always ex...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,372
bash
# Shell Scripts in Mac OS X run from home directory? I'm a longtime Windows and Linux user and have had some weird experiences writing shell scripts on Mac OS X. In particular, I can write the scripts just fine and run them from the terminal, but every time I try running one from a Finder window it always executes fro...
The behaviour seems consistent to me. It inherits your finder instances environment, which would be rooted at your home directory. However, it's not too hard to fix. ``` cd "$(dirname "$0")" ``` Ought to do the trick ala: ``` richh-desktop % fullname.sh /home/richh/bin richh-desktop % cd .. richh-desktop % fullna...
3693852
Extract IP from netstat output
9
2010-09-12 05:17:22
<p>The netstat output contains thing like...</p> <pre><code>tcp 0 0 0.0.0.0:80 221.126.149.99:51973 ESTABLISHED 23879/apache2 tcp 0 0 0.0.0.0:80 66.249.68.154:40883 ESTABLISHED 23899/apache2 tcp 0 0 0.0.0.0:80 66.249.68.81:41200 ESTABLISHED 23892/apach...
17,285
365,256
2012-09-05 06:26:18
3,701,097
13
2010-09-13 13:57:08
437,095
2010-09-13 13:57:08
https://stackoverflow.com/q/3693852
https://stackoverflow.com/a/3701097
<p>This will return a list of unique IP address you're connected too:</p> <pre><code>netstat -anpt | grep apache2 |grep ESTABLISHED | awk '{ print $5 }' | cut -d: -f1 | sort -u </code></pre> <p>Well I think I need to change my glasses also =P</p>
<p>This will return a list of unique IP address you're connected too:</p> <pre><code>netstat -anpt | grep apache2 |grep ESTABLISHED | awk '{ print $5 }' | cut -d: -f1 | sort -u </code></pre> <p>Well I think I need to change my glasses also =P</p>
390, 990, 2198
awk, netstat, shell
<h1>Extract IP from netstat output</h1> <p>The netstat output contains thing like...</p> <pre><code>tcp 0 0 0.0.0.0:80 221.126.149.99:51973 ESTABLISHED 23879/apache2 tcp 0 0 0.0.0.0:80 66.249.68.154:40883 ESTABLISHED 23899/apache2 tcp 0 0 0.0.0.0:80 66.249....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,373
bash
# Extract IP from netstat output The netstat output contains thing like... ``` tcp 0 0 0.0.0.0:80 221.126.149.99:51973 ESTABLISHED 23879/apache2 tcp 0 0 0.0.0.0:80 66.249.68.154:40883 ESTABLISHED 23899/apache2 tcp 0 0 0.0.0.0:80 66.249.68.81:41200 EST...
This will return a list of unique IP address you're connected too: ``` netstat -anpt | grep apache2 |grep ESTABLISHED | awk '{ print $5 }' | cut -d: -f1 | sort -u ``` Well I think I need to change my glasses also =P
3511006
How to compare versions of some products in unix ksh shell?
9
2010-08-18 10:16:27
<p>Format of versions - X.X.X.X.<br> Where X - number.<br> What is the best way to compare two versions?<br> I use following code: </p> <pre><code>compareVersions() { VER_1=$1 VER_2=$2 print -R "$VER_1"| IFS=. read v1_1 v1_2 v1_3 v1_4 print -R "$VER_2"| IFS=. read v2_1 v2_2 v2_3 v2_4 RESULT="0" if [[ "...
4,212
167,739
2020-01-23 15:28:27
3,511,118
13
2010-08-18 10:32:39
57,457
2010-08-20 07:21:40
https://stackoverflow.com/q/3511006
https://stackoverflow.com/a/3511118
<p>Pure Bash / Ksh:</p> <pre><code>compareVersions () { typeset IFS='.' typeset -a v1=( $1 ) typeset -a v2=( $2 ) typeset n diff for (( n=0; n&lt;4; n+=1 )); do diff=$((v1[n]-v2[n])) if [ $diff -ne 0 ] ; then [ $diff -le 0 ] &amp;&amp; echo '-1' || echo '1' return fi done e...
<p>Pure Bash / Ksh:</p> <pre><code>compareVersions () { typeset IFS='.' typeset -a v1=( $1 ) typeset -a v2=( $2 ) typeset n diff for (( n=0; n&lt;4; n+=1 )); do diff=$((v1[n]-v2[n])) if [ $diff -ne 0 ] ; then [ $diff -le 0 ] &amp;&amp; echo '-1' || echo '1' return fi done e...
34, 390, 1964
ksh, shell, unix
<h1>How to compare versions of some products in unix ksh shell?</h1> <p>Format of versions - X.X.X.X.<br> Where X - number.<br> What is the best way to compare two versions?<br> I use following code: </p> <pre><code>compareVersions() { VER_1=$1 VER_2=$2 print -R "$VER_1"| IFS=. read v1_1 v1_2 v1_3 v1_4 print...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,374
bash
# How to compare versions of some products in unix ksh shell? Format of versions - X.X.X.X. Where X - number. What is the best way to compare two versions? I use following code: ``` compareVersions() { VER_1=$1 VER_2=$2 print -R "$VER_1"| IFS=. read v1_1 v1_2 v1_3 v1_4 print -R "$VER_2"| IFS=. read v2_...
Pure Bash / Ksh: ``` compareVersions () { typeset IFS='.' typeset -a v1=( $1 ) typeset -a v2=( $2 ) typeset n diff for (( n=0; n<4; n+=1 )); do diff=$((v1[n]-v2[n])) if [ $diff -ne 0 ] ; then [ $diff -le 0 ] && echo '-1' || echo '1' return fi done echo '0' } # ---------- ...
2838475
How do I get the name of the newest file via the Terminal?
9
2010-05-15 00:58:33
<p>I'm trying to create a macro for <a href="http://www.keyboardmaestro.com/main/" rel="noreferrer">Keyboard Maestro</a> for OS X doing the following:</p> <ol> <li>Get name of newest file in a directory on my disk based on date created;</li> <li>Paste the text "newest file: " plus the name of the newest file.</li> </o...
32,624
115,681
2017-12-13 15:52:15
2,838,491
13
2010-05-15 01:07:18
275,737
2010-05-15 01:07:18
https://stackoverflow.com/q/2838475
https://stackoverflow.com/a/2838491
<p>Since you're already using pipes, just throw another one in there:</p> <pre><code>ls -t | head -n1 |awk '{printf("newest file: %s",$0)}' </code></pre> <p>(Note that the "printf" does not include a '\n' at the end; that gets rid of the linebreak) </p> <p>Edit:</p> <p>With Arkku's suggestion to exit awk after the ...
<p>Since you're already using pipes, just throw another one in there:</p> <pre><code>ls -t | head -n1 |awk '{printf("newest file: %s",$0)}' </code></pre> <p>(Note that the "printf" does not include a '\n' at the end; that gets rid of the linebreak) </p> <p>Edit:</p> <p>With Arkku's suggestion to exit awk after the ...
390, 1231, 108212
command-line, keyboard-maestro, shell
<h1>How do I get the name of the newest file via the Terminal?</h1> <p>I'm trying to create a macro for <a href="http://www.keyboardmaestro.com/main/" rel="noreferrer">Keyboard Maestro</a> for OS X doing the following:</p> <ol> <li>Get name of newest file in a directory on my disk based on date created;</li> <li>Paste...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,375
bash
# How do I get the name of the newest file via the Terminal? I'm trying to create a macro for [Keyboard Maestro](http://www.keyboardmaestro.com/main/) for OS X doing the following: 1. Get name of newest file in a directory on my disk based on date created; 2. Paste the text "newest file: " plus the name of the newest...
Since you're already using pipes, just throw another one in there: ``` ls -t | head -n1 |awk '{printf("newest file: %s",$0)}' ``` (Note that the "printf" does not include a '\n' at the end; that gets rid of the linebreak) Edit: With Arkku's suggestion to exit awk after the first line, it looks like: ``` ls -t | aw...
2816225
How can I (from a script) add something to the zsh command history?
9
2010-05-12 05:22:56
<p>I'd like to be able to look through my command history and know the context from which I issued various commands--in other words, "what directory was I in?" There are various ways I could achieve this, but all of them (that I can think of) would require manipulating the zsh history to add (for instance) a commented...
3,994
241,142
2010-05-12 07:34:33
2,816,792
13
2010-05-12 07:34:33
26,428
2010-05-12 07:34:33
https://stackoverflow.com/q/2816225
https://stackoverflow.com/a/2816792
<p>You can use the <code>print -s</code> command (see <code>man zshbuiltins</code>) to add anything you want to the history. There's also a hook function you can create called <code>zshaddhistory</code> (see <code>man zshmisc</code>) that can manipulate history contents as they are created.</p> <p>See <a href="https:/...
<p>You can use the <code>print -s</code> command (see <code>man zshbuiltins</code>) to add anything you want to the history. There's also a hook function you can create called <code>zshaddhistory</code> (see <code>man zshmisc</code>) that can manipulate history contents as they are created.</p> <p>See <a href="https:/...
390, 1318, 3791
history, shell, zsh
<h1>How can I (from a script) add something to the zsh command history?</h1> <p>I'd like to be able to look through my command history and know the context from which I issued various commands--in other words, "what directory was I in?" There are various ways I could achieve this, but all of them (that I can think of)...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,376
bash
# How can I (from a script) add something to the zsh command history? I'd like to be able to look through my command history and know the context from which I issued various commands--in other words, "what directory was I in?" There are various ways I could achieve this, but all of them (that I can think of) would req...
You can use the `print -s` command (see `man zshbuiltins`) to add anything you want to the history. There's also a hook function you can create called `zshaddhistory` (see `man zshmisc`) that can manipulate history contents as they are created. See [my Bash history logging functions](https://stackoverflow.com/question...
2674427
Writing " to a file in bash
9
2010-04-20 10:54:49
<p>Simply I need to write</p> <pre><code>"echo" t${count} = "$"t${count}" </code></pre> <p>To a text file, including all the So the output would be something like:</p> <pre><code>echo " t1 = $t1" </code></pre> <p>With " as they are. So I have tried:</p> <pre><code>count=1 saveIFS="$IFS" IFS=$'\n' array=($(&lt;TE...
17,319
311,963
2010-04-20 12:02:51
2,674,454
13
2010-04-20 10:59:09
46,991
2010-04-20 10:59:09
https://stackoverflow.com/q/2674427
https://stackoverflow.com/a/2674454
<p>There's actually no wrapping in double quotes for variables, first quote starts, the second quote ends the quoted string. You may however concatenate strings however you want, so <code>"$"t${count}""</code> will actually be equivalent to <code>"$"t${count}</code>, beginning with a quoted $-sign, followed by 't', fol...
<p>There's actually no wrapping in double quotes for variables, first quote starts, the second quote ends the quoted string. You may however concatenate strings however you want, so <code>"$"t${count}""</code> will actually be equivalent to <code>"$"t${count}</code>, beginning with a quoted $-sign, followed by 't', fol...
387
bash
<h1>Writing " to a file in bash</h1> <p>Simply I need to write</p> <pre><code>"echo" t${count} = "$"t${count}" </code></pre> <p>To a text file, including all the So the output would be something like:</p> <pre><code>echo " t1 = $t1" </code></pre> <p>With " as they are. So I have tried:</p> <pre><code>count=1 sav...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,377
bash
# Writing " to a file in bash Simply I need to write ``` "echo" t${count} = "$"t${count}" ``` To a text file, including all the So the output would be something like: ``` echo " t1 = $t1" ``` With " as they are. So I have tried: ``` count=1 saveIFS="$IFS" IFS=$'\n' array=($(<TEST.txt)) IFS="$saveIFS" for i in "...
There's actually no wrapping in double quotes for variables, first quote starts, the second quote ends the quoted string. You may however concatenate strings however you want, so `"$"t${count}""` will actually be equivalent to `"$"t${count}`, beginning with a quoted $-sign, followed by 't', followed by the count-variab...
2450224
Insert copyright message into multiple files
9
2010-03-15 20:24:34
<p>How would you insert a copyright message at the very top of every file?</p>
3,236
253,470
2018-01-18 14:11:40
2,450,245
13
2010-03-15 20:27:50
220,299
2010-03-15 20:38:20
https://stackoverflow.com/q/2450224
https://stackoverflow.com/a/2450245
<pre><code>#!/bin/bash for file in *; do echo "Copyright" &gt; tempfile; cat $file &gt;&gt; tempfile; mv tempfile $file; done </code></pre> <p>Recursive solution (finds all <code>.txt</code> files in all subdirectories):</p> <pre><code>#!/bin/bash for file in $(find . -type f -name \*.txt); do echo "Copyright...
<pre><code>#!/bin/bash for file in *; do echo "Copyright" &gt; tempfile; cat $file &gt;&gt; tempfile; mv tempfile $file; done </code></pre> <p>Recursive solution (finds all <code>.txt</code> files in all subdirectories):</p> <pre><code>#!/bin/bash for file in $(find . -type f -name \*.txt); do echo "Copyright...
34, 390, 531
scripting, shell, unix
<h1>Insert copyright message into multiple files</h1> <p>How would you insert a copyright message at the very top of every file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,378
bash
# Insert copyright message into multiple files How would you insert a copyright message at the very top of every file?
``` #!/bin/bash for file in *; do echo "Copyright" > tempfile; cat $file >> tempfile; mv tempfile $file; done ``` Recursive solution (finds all `.txt` files in all subdirectories): ``` #!/bin/bash for file in $(find . -type f -name \*.txt); do echo "Copyright" > copyright-file.txt; echo "" >> copyright-file...
1862554
Get-ChildItem recurse as a parameter in PowerShell
9
2009-12-07 20:09:09
<p>I am looking to create a function that could toggle the ability to recurse in <a href="http://technet.microsoft.com/en-us/scriptcenter/dd772285.aspx" rel="noreferrer">cmdlet</a> <a href="http://technet.microsoft.com/en-us/library/ee176841.aspx" rel="noreferrer">Get-ChildItem</a>.</p> <p>As a very basic example:</p>...
6,482
203,493
2014-12-10 18:48:07
1,862,699
13
2009-12-07 20:31:12
153,982
2009-12-07 20:31:12
https://stackoverflow.com/q/1862554
https://stackoverflow.com/a/1862699
<p>A couple of things here. First, you don't want to use [boolean] for the type of the recurse parameter. That requires that you pass an argument for the Recurse parameter on your script e.g. <code>-Recurse $true</code>. What you want is a [switch] parameter as shown below. Also, when you forward the switch value to ...
<p>A couple of things here. First, you don't want to use [boolean] for the type of the recurse parameter. That requires that you pass an argument for the Recurse parameter on your script e.g. <code>-Recurse $true</code>. What you want is a [switch] parameter as shown below. Also, when you forward the switch value to ...
526, 24068
powershell, powershell-1.0
<h1>Get-ChildItem recurse as a parameter in PowerShell</h1> <p>I am looking to create a function that could toggle the ability to recurse in <a href="http://technet.microsoft.com/en-us/scriptcenter/dd772285.aspx" rel="noreferrer">cmdlet</a> <a href="http://technet.microsoft.com/en-us/library/ee176841.aspx" rel="norefer...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,379
bash
# Get-ChildItem recurse as a parameter in PowerShell I am looking to create a function that could toggle the ability to recurse in [cmdlet](http://technet.microsoft.com/en-us/scriptcenter/dd772285.aspx) [Get-ChildItem](http://technet.microsoft.com/en-us/library/ee176841.aspx). As a very basic example: ``` ... param...
A couple of things here. First, you don't want to use [boolean] for the type of the recurse parameter. That requires that you pass an argument for the Recurse parameter on your script e.g. `-Recurse $true`. What you want is a [switch] parameter as shown below. Also, when you forward the switch value to the -Recurse par...
74862849
Powershell ConvertTo-SecureString not recognised if run script inline from cmd
8
2022-12-20 12:06:09
<p>When running from cmd.exe</p> <pre><code>powershell .\scripts\scriptname.ps1 </code></pre> <p>Which has a line to convert plain text to secure string</p> <pre><code>[securestring]$secString = ConvertTo-SecureString $SampleString -AsPlainText -Force </code></pre> <p>I get error:</p> <pre><code>ConvertTo-SecureString ...
7,119
6,948,066
2025-07-06 07:15:15
74,869,395
13
2022-12-20 22:12:56
45,375
2024-02-17 16:05:45
https://stackoverflow.com/q/74862849
https://stackoverflow.com/a/74869395
<p>The symptom of your call to <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe" rel="nofollow noreferrer"><code>powershell.exe</code></a>, the <em>Windows PowerShell</em> CLI, from <code>cmd.exe</code> (or a batch file) implies that you've launched <cod...
<p>The symptom of your call to <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe" rel="nofollow noreferrer"><code>powershell.exe</code></a>, the <em>Windows PowerShell</em> CLI, from <code>cmd.exe</code> (or a batch file) implies that you've launched <cod...
526
powershell
<h1>Powershell ConvertTo-SecureString not recognised if run script inline from cmd</h1> <p>When running from cmd.exe</p> <pre><code>powershell .\scripts\scriptname.ps1 </code></pre> <p>Which has a line to convert plain text to secure string</p> <pre><code>[securestring]$secString = ConvertTo-SecureString $SampleString ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,380
bash
# Powershell ConvertTo-SecureString not recognised if run script inline from cmd When running from cmd.exe ``` powershell .\scripts\scriptname.ps1 ``` Which has a line to convert plain text to secure string ``` [securestring]$secString = ConvertTo-SecureString $SampleString -AsPlainText -Force ``` I get error: ``...
The symptom of your call to [`powershell.exe`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe), the *Windows PowerShell* CLI, from `cmd.exe` (or a batch file) implies that you've launched `cmd.exe` *from [PowerShell (Core) 7+](https://github.com/PowerShell/Power...
68928409
How to remove environment prefix in Powershell console
8
2021-08-25 18:51:43
<p>Does anybody knows how I can remove (venv) prefix that is displayed in my Powershell Terminal window? I know that this is purely cosmetic, but I'd love to remove it since I'm using Oh My Posh.</p> <p>I've attached screenshot.<a href="https://i.sstatic.net/U3oFK.jpg" rel="noreferrer"><img src="https://i.sstatic.net/U...
1,870
13,020,973
2022-06-22 12:54:58
72,715,907
13
2022-06-22 12:54:58
13,020,973
2022-06-22 12:54:58
https://stackoverflow.com/q/68928409
https://stackoverflow.com/a/72715907
<p>I've found the best solution (for my case at least).</p> <p>Simply add: <code>$env:VIRTUAL_ENV_DISABLE_PROMPT = 1</code> to $PROFILE</p>
<p>I've found the best solution (for my case at least).</p> <p>Simply add: <code>$env:VIRTUAL_ENV_DISABLE_PROMPT = 1</code> to $PROFILE</p>
391, 526, 152427
oh-my-posh, powershell, terminal
<h1>How to remove environment prefix in Powershell console</h1> <p>Does anybody knows how I can remove (venv) prefix that is displayed in my Powershell Terminal window? I know that this is purely cosmetic, but I'd love to remove it since I'm using Oh My Posh.</p> <p>I've attached screenshot.<a href="https://i.sstatic.n...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,381
bash
# How to remove environment prefix in Powershell console Does anybody knows how I can remove (venv) prefix that is displayed in my Powershell Terminal window? I know that this is purely cosmetic, but I'd love to remove it since I'm using Oh My Posh. I've attached screenshot.[![enter image description here](https://i....
I've found the best solution (for my case at least). Simply add: `$env:VIRTUAL_ENV_DISABLE_PROMPT = 1` to $PROFILE
69731154
Different results from Invoke-WebRequest and Invoke-RestMethod
8
2021-10-26 23:52:02
<p>I am trying to call Azure Rest API and get Schedules of DevTestLabs. I tried Invoke-RestMethod, but it doesn't give <strong>value</strong> on <strong>&quot;dailyRecurrence&quot;</strong> key. But Invoke-WebRequest does.</p> <p>What would be the reason for that?</p> <p><strong>URL</strong></p> <pre><code>$url = &quot...
7,815
4,692,384
2024-02-14 11:55:34
69,731,637
13
2021-10-27 01:16:42
45,375
2023-03-13 13:57:01
https://stackoverflow.com/q/69731154
https://stackoverflow.com/a/69731637
<p>The problem:</p> <ul> <li><p>is merely a <em>display</em> problem,</p> </li> <li><p>albeit one that exposes a long-standing <em>bug</em>, still present as of PowerShell Core 7.3.3, namely that <code>[pscustomobject]</code> instances mistakenly stringify to the <em>empty string</em> - see <a href="https://github.com...
<p>The problem:</p> <ul> <li><p>is merely a <em>display</em> problem,</p> </li> <li><p>albeit one that exposes a long-standing <em>bug</em>, still present as of PowerShell Core 7.3.3, namely that <code>[pscustomobject]</code> instances mistakenly stringify to the <em>empty string</em> - see <a href="https://github.com...
526, 134943, 138645, 145532
azure-rest-api, invoke-restmethod, invoke-webrequest, powershell
<h1>Different results from Invoke-WebRequest and Invoke-RestMethod</h1> <p>I am trying to call Azure Rest API and get Schedules of DevTestLabs. I tried Invoke-RestMethod, but it doesn't give <strong>value</strong> on <strong>&quot;dailyRecurrence&quot;</strong> key. But Invoke-WebRequest does.</p> <p>What would be the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,382
bash
# Different results from Invoke-WebRequest and Invoke-RestMethod I am trying to call Azure Rest API and get Schedules of DevTestLabs. I tried Invoke-RestMethod, but it doesn't give **value** on **"dailyRecurrence"** key. But Invoke-WebRequest does. What would be the reason for that? **URL** ``` $url = "https://mana...
The problem: - is merely a *display* problem, - albeit one that exposes a long-standing *bug*, still present as of PowerShell Core 7.3.3, namely that `[pscustomobject]` instances mistakenly stringify to the *empty string* - see [GitHub issue #6163](https://github.com/PowerShell/PowerShell/issues/6163). In short: - T...
65782810
How to conditionally add a pipeline element in bash
8
2021-01-18 22:18:14
<p>I need to form a pipeline of various commands. Some elements of the pipeline, or sequences of elements, are only relevant when some condition holds. Now, I could write:</p> <pre><code>if [[ $whatever ]]; then cmd1 | cmd2 | cmd3 | cmd4 else cmd1 | cmd4 fi </code></pre> <p>but that means repeating <code>cmd1</co...
862
1,593,077
2021-01-18 22:52:38
65,783,008
13
2021-01-18 22:37:22
8,133,920
2021-01-18 22:37:22
https://stackoverflow.com/q/65782810
https://stackoverflow.com/a/65783008
<p>Your attempt fails because special symbols lose their syntactical value after expansion. <code>eval</code> is a way, but as we know it is prone to code injection so it is best avoided. We can try</p> <pre><code>cmd1 | if [ condition ]; then cmd2 | cmd3 else cat fi | cmd4 </code></pre> <p>Though I'd love to sk...
<p>Your attempt fails because special symbols lose their syntactical value after expansion. <code>eval</code> is a way, but as we know it is prone to code injection so it is best avoided. We can try</p> <pre><code>cmd1 | if [ condition ]; then cmd2 | cmd3 else cat fi | cmd4 </code></pre> <p>Though I'd love to sk...
387, 2844, 5813, 53502
bash, conditional-execution, pipe, pipeline
<h1>How to conditionally add a pipeline element in bash</h1> <p>I need to form a pipeline of various commands. Some elements of the pipeline, or sequences of elements, are only relevant when some condition holds. Now, I could write:</p> <pre><code>if [[ $whatever ]]; then cmd1 | cmd2 | cmd3 | cmd4 else cmd1 | cmd...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,383
bash
# How to conditionally add a pipeline element in bash I need to form a pipeline of various commands. Some elements of the pipeline, or sequences of elements, are only relevant when some condition holds. Now, I could write: ``` if [[ $whatever ]]; then cmd1 | cmd2 | cmd3 | cmd4 else cmd1 | cmd4 fi ``` but that ...
Your attempt fails because special symbols lose their syntactical value after expansion. `eval` is a way, but as we know it is prone to code injection so it is best avoided. We can try ``` cmd1 | if [ condition ]; then cmd2 | cmd3 else cat fi | cmd4 ``` Though I'd love to skip `cat`, I couldn't find a way. Rea...
65707623
Export environment variables to JSON in Bash
8
2021-01-13 18:16:08
<p>The environment variables can be printed by using <code>export</code> or <code>printenv</code> in bash, but how can we convert the output into JSON format and then store them in a variable.</p>
3,403
7,338,180
2024-03-28 16:10:43
65,707,749
13
2021-01-13 18:24:55
10,248,678
2024-03-28 16:10:43
https://stackoverflow.com/q/65707623
https://stackoverflow.com/a/65707749
<p>JQ does that for you and populates an internal variable called <code>ENV</code> with the result, which can be exported to a shell variable like so:</p> <pre><code>var=$(jq -n '$ENV') </code></pre> <p>To remove junk variables like <code>_</code>, <code>SHLVL</code>, etc. from the list you can use the <a href="https:/...
<p>JQ does that for you and populates an internal variable called <code>ENV</code> with the result, which can be exported to a shell variable like so:</p> <pre><code>var=$(jq -n '$ENV') </code></pre> <p>To remove junk variables like <code>_</code>, <code>SHLVL</code>, etc. from the list you can use the <a href="https:/...
387, 1508, 9013, 105170
bash, environment-variables, jq, json
<h1>Export environment variables to JSON in Bash</h1> <p>The environment variables can be printed by using <code>export</code> or <code>printenv</code> in bash, but how can we convert the output into JSON format and then store them in a variable.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,384
bash
# Export environment variables to JSON in Bash The environment variables can be printed by using `export` or `printenv` in bash, but how can we convert the output into JSON format and then store them in a variable.
JQ does that for you and populates an internal variable called `ENV` with the result, which can be exported to a shell variable like so: ``` var=$(jq -n '$ENV') ``` To remove junk variables like `_`, `SHLVL`, etc. from the list you can use the [`del`](https://stedolan.github.io/jq/manual/#del(path_expression)) functi...
63474689
How do I upload a file to Azurite from terminal?
8
2020-08-18 18:34:51
<p>I'm using Azurite and wish to create a container/upload a blob etc from the bash terminal!</p> <p>I've tried using the Azure CLI like this::</p> <pre><code>az storage container create --account-name devstoreaccount1 --account-key Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGM...
5,547
4,908,657
2024-08-01 15:49:38
63,496,841
13
2020-08-20 00:47:50
10,505,040
2020-08-20 00:47:50
https://stackoverflow.com/q/63474689
https://stackoverflow.com/a/63496841
<p>According to my test, when we account key and account name with Azure CLI to create blob container, cli will use <code>https</code> protocol to connect Azurite. But, in default, Azurite just support <code>http</code> protocol. For more details, please refer to <a href="https://github.com/Azure/Azurite" rel="noreferr...
<p>According to my test, when we account key and account name with Azure CLI to create blob container, cli will use <code>https</code> protocol to connect Azurite. But, in default, Azurite just support <code>http</code> protocol. For more details, please refer to <a href="https://github.com/Azure/Azurite" rel="noreferr...
387, 391, 14158, 108105
azure, azure-cli, bash, terminal
<h1>How do I upload a file to Azurite from terminal?</h1> <p>I'm using Azurite and wish to create a container/upload a blob etc from the bash terminal!</p> <p>I've tried using the Azure CLI like this::</p> <pre><code>az storage container create --account-name devstoreaccount1 --account-key Eby8vdM02xNOcqFlqUwJPLlmEt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,385
bash
# How do I upload a file to Azurite from terminal? I'm using Azurite and wish to create a container/upload a blob etc from the bash terminal! I've tried using the Azure CLI like this:: ``` az storage container create --account-name devstoreaccount1 --account-key Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2...
According to my test, when we account key and account name with Azure CLI to create blob container, cli will use `https` protocol to connect Azurite. But, in default, Azurite just support `http` protocol. For more details, please refer to [here](https://github.com/Azure/Azurite) [![enter image description here](https...
59911669
Proper way to use a trap to exit a shell-script in ZSH?
8
2020-01-25 17:26:04
<p>I'm having trouble getting a trap function in a Zshell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using ^C, and when I do I want the trap to change the cursor status in the terminal. </p> <p>My syntax is:</p> <p>#!/bin/zsh</p> <pre><code>trap 'tpu...
6,489
10,425,369
2020-01-27 04:26:25
59,925,138
13
2020-01-27 04:26:25
11,865,893
2020-01-27 04:26:25
https://stackoverflow.com/q/59911669
https://stackoverflow.com/a/59925138
<h2>Handling Signals With Trap</h2> <pre class="lang-sh prettyprint-override"><code>TRAPINT() { echo "TRAPINT() called: ^C was pressed" } TRAPQUIT() { echo "TRAPQUIT() called: ^\\ was pressed" } TRAPTERM() { echo "TRAPTERM() called: a 'kill' command was aimed at this program's process ID" } TRAPEXIT() {...
<h2>Handling Signals With Trap</h2> <pre class="lang-sh prettyprint-override"><code>TRAPINT() { echo "TRAPINT() called: ^C was pressed" } TRAPQUIT() { echo "TRAPQUIT() called: ^\\ was pressed" } TRAPTERM() { echo "TRAPTERM() called: a 'kill' command was aimed at this program's process ID" } TRAPEXIT() {...
390, 531, 1231, 3791
command-line, scripting, shell, zsh
<h1>Proper way to use a trap to exit a shell-script in ZSH?</h1> <p>I'm having trouble getting a trap function in a Zshell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using ^C, and when I do I want the trap to change the cursor status in the terminal. </...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,386
bash
# Proper way to use a trap to exit a shell-script in ZSH? I'm having trouble getting a trap function in a Zshell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using ^C, and when I do I want the trap to change the cursor status in the terminal. My syntax ...
## Handling Signals With Trap ``` TRAPINT() { echo "TRAPINT() called: ^C was pressed" } TRAPQUIT() { echo "TRAPQUIT() called: ^\\ was pressed" } TRAPTERM() { echo "TRAPTERM() called: a 'kill' command was aimed at this program's process ID" } TRAPEXIT() { echo "TRAPEXIT() called: happens at the end o...
55191548
Write-Information does not show in a file transcribed by Start-Transcript
8
2019-03-15 22:40:11
<p>I'm using PowerShell 5.1 and I am trying to determine why <code>Write-Information</code> messages do not show in the transcript log created by <code>Start-Transcript</code> unless I set <code>$InformationPreference</code> to <code>SilentlyContinue</code>. I want to both display the messages in the console <em>and</e...
3,687
8,517,394
2025-03-28 23:57:56
55,198,981
13
2019-03-16 16:28:55
45,375
2025-03-28 23:57:56
https://stackoverflow.com/q/55191548
https://stackoverflow.com/a/55198981
<p>What you're seeing is a <strong><em>bug</em> in <em>Windows PowerShell</em></strong> that has been <strong>fixed in <a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core) 7</em></a></strong> (though note that <em>other</em> transcript-related problems...
<p>What you're seeing is a <strong><em>bug</em> in <em>Windows PowerShell</em></strong> that has been <strong>fixed in <a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core) 7</em></a></strong> (though note that <em>other</em> transcript-related problems...
526, 942, 134758, 153947
logging, powershell, powershell-cmdlet, powershell-v5.1
<h1>Write-Information does not show in a file transcribed by Start-Transcript</h1> <p>I'm using PowerShell 5.1 and I am trying to determine why <code>Write-Information</code> messages do not show in the transcript log created by <code>Start-Transcript</code> unless I set <code>$InformationPreference</code> to <code>Sil...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,387
bash
# Write-Information does not show in a file transcribed by Start-Transcript I'm using PowerShell 5.1 and I am trying to determine why `Write-Information` messages do not show in the transcript log created by `Start-Transcript` unless I set `$InformationPreference` to `SilentlyContinue`. I want to both display the mess...
What you're seeing is a ***bug* in *Windows PowerShell*** that has been **fixed in [*PowerShell (Core) 7*](https://github.com/PowerShell/PowerShell/blob/master/README.md)** (though note that *other* transcript-related problems persist; see [GitHub issue #4645](https://github.com/PowerShell/PowerShell/issues/4645)). Gi...
54169151
du: Follow symlinks if symlink points to outside directories, don't follow otherwise
8
2019-01-13 13:04:50
<p>I wonder whether there's some rather simple shell incantation to calculate the disk usage of a directory (using the <code>du</code> command) but with the following requirements: symlinks that point to files/subdirectories inside the directory should not be followed, but symlinks to outside files/subdirectories shoul...
13,842
10,814,896
2019-01-13 15:28:21
54,170,336
13
2019-01-13 15:28:21
9,288,200
2019-01-13 15:28:21
https://stackoverflow.com/q/54169151
https://stackoverflow.com/a/54170336
<p>Unless I have missed something in your question, <code>du</code> already does that when instructed to follow symlinks (<code>-L</code>).</p> <p>I got two trees:</p> <p><code>tree1/</code>:</p> <pre><code>├── dir1 │   └── file ├── dirA -&gt; ../tree2/dirA └── link1 -&gt; dir1 </code></pre> <p>and <code>tree2/</co...
<p>Unless I have missed something in your question, <code>du</code> already does that when instructed to follow symlinks (<code>-L</code>).</p> <p>I got two trees:</p> <p><code>tree1/</code>:</p> <pre><code>├── dir1 │   └── file ├── dirA -&gt; ../tree2/dirA └── link1 -&gt; dir1 </code></pre> <p>and <code>tree2/</co...
387, 580
bash, perl
<h1>du: Follow symlinks if symlink points to outside directories, don't follow otherwise</h1> <p>I wonder whether there's some rather simple shell incantation to calculate the disk usage of a directory (using the <code>du</code> command) but with the following requirements: symlinks that point to files/subdirectories i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,388
bash
# du: Follow symlinks if symlink points to outside directories, don't follow otherwise I wonder whether there's some rather simple shell incantation to calculate the disk usage of a directory (using the `du` command) but with the following requirements: symlinks that point to files/subdirectories inside the directory ...
Unless I have missed something in your question, `du` already does that when instructed to follow symlinks (`-L`). I got two trees: `tree1/`: ``` ├── dir1 │   └── file ├── dirA -> ../tree2/dirA └── link1 -> dir1 ``` and `tree2/`: ``` . └── dirA └── file ``` File is in both cases 1MB in size. Now run `du -shL...
52879234
Bash format string. Substitute placeholders with values.
8
2018-10-18 17:09:52
<p>I would like to format string using linux bash:</p> <pre><code>"&lt;username&gt;{0}&lt;/username&gt;&lt;password&gt;{1}&lt;/password&gt;".format("user", "pass") </code></pre> <p>Output:</p> <pre><code>&lt;username&gt;user&lt;/username&gt;&lt;password&gt;pass&lt;/password&gt; </code></pre> <p>What is the correct ...
11,532
3,014,866
2018-10-18 18:55:13
52,879,336
13
2018-10-18 17:17:25
10,248,678
2018-10-18 18:55:13
https://stackoverflow.com/q/52879234
https://stackoverflow.com/a/52879336
<p>From <code>printf --help</code>:</p> <blockquote> <p><strong>-v <em>var</em></strong> &nbsp; &nbsp;assign the output to shell variable VAR rather than display it on the standard output</p> </blockquote> <p>So, what you need to do is just:</p> <pre><code>FMT='&lt;username&gt;%s&lt;/username&gt;&lt;password&gt;%s...
<p>From <code>printf --help</code>:</p> <blockquote> <p><strong>-v <em>var</em></strong> &nbsp; &nbsp;assign the output to shell variable VAR rather than display it on the standard output</p> </blockquote> <p>So, what you need to do is just:</p> <pre><code>FMT='&lt;username&gt;%s&lt;/username&gt;&lt;password&gt;%s...
139, 387, 10232
bash, string, string-formatting
<h1>Bash format string. Substitute placeholders with values.</h1> <p>I would like to format string using linux bash:</p> <pre><code>"&lt;username&gt;{0}&lt;/username&gt;&lt;password&gt;{1}&lt;/password&gt;".format("user", "pass") </code></pre> <p>Output:</p> <pre><code>&lt;username&gt;user&lt;/username&gt;&lt;passwo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,389
bash
# Bash format string. Substitute placeholders with values. I would like to format string using linux bash: ``` "<username>{0}</username><password>{1}</password>".format("user", "pass") ``` Output: ``` <username>user</username><password>pass</password> ``` What is the correct command to do this? I can use any other...
From `printf --help`: > **-v *var***    assign the output to shell variable VAR rather than display it on the standard output So, what you need to do is just: ``` FMT='<username>%s</username><password>%s</password>' printf -v VAR "$FMT" user pass ```
52065016
How to replace "\n" string with a new line in Unix Bash script
8
2018-08-28 19:29:36
<p>Cannot seem to find an answer to this one online...</p> <p>I have a string variable (externally sourced) with new lines <code>"\n"</code> encoded as strings.</p> <p>I want to replace those strings with actual new line carriage returns. The code below can achieve this...</p> <pre><code>echo $EXT_DESCR | sed 's/\\...
19,003
1,148,545
2018-08-28 19:55:22
52,065,116
13
2018-08-28 19:37:31
6,176,817
2018-08-28 19:37:31
https://stackoverflow.com/q/52065016
https://stackoverflow.com/a/52065116
<p>No need for <code>sed</code>, using <a href="https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion" rel="noreferrer">parameter expansion</a>:</p> <pre><code>$ foo='1\n2\n3'; echo "${foo//'\n'/$'\n'}" 1 2 3 </code></pre> <hr> <p>With <code>bash 4.4</code> or newer, you can use the <code>E<...
<p>No need for <code>sed</code>, using <a href="https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion" rel="noreferrer">parameter expansion</a>:</p> <pre><code>$ foo='1\n2\n3'; echo "${foo//'\n'/$'\n'}" 1 2 3 </code></pre> <hr> <p>With <code>bash 4.4</code> or newer, you can use the <code>E<...
34, 276, 387, 390
bash, shell, unix, variables
<h1>How to replace "\n" string with a new line in Unix Bash script</h1> <p>Cannot seem to find an answer to this one online...</p> <p>I have a string variable (externally sourced) with new lines <code>"\n"</code> encoded as strings.</p> <p>I want to replace those strings with actual new line carriage returns. The co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,390
bash
# How to replace "\n" string with a new line in Unix Bash script Cannot seem to find an answer to this one online... I have a string variable (externally sourced) with new lines `"\n"` encoded as strings. I want to replace those strings with actual new line carriage returns. The code below can achieve this... ``` e...
No need for `sed`, using [parameter expansion](https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion): ``` $ foo='1\n2\n3'; echo "${foo//'\n'/$'\n'}" 1 2 3 ``` --- With `bash 4.4` or newer, you can use the `E` operator in [`${parameter@operator}`](https://www.gnu.org/software/bash/manual/htm...
49583470
Block a file with Powershell
8
2018-03-31 01:57:47
<p>I want to block (not unblock) a file with Powershell. I want to cause Windows to believe that a file on disk was downloaded from the internet, or whatever other scenario exists such that files become blocked. I need this to test how some software I'm developing behaves in the presence of a blocked file.</p>
4,779
356,790
2019-07-05 01:51:08
49,584,424
13
2018-03-31 05:03:02
1,029,145
2018-03-31 05:03:02
https://stackoverflow.com/q/49583470
https://stackoverflow.com/a/49584424
<p>If you're just trying to add the zone identifier you could try something like this:</p> <pre class="lang-bsh prettyprint-override"><code>$data = "[ZoneTransfer] ZoneId=3" Set-Content example.txt -Stream "Zone.Identifier" -Value $data </code></pre>
<p>If you're just trying to add the zone identifier you could try something like this:</p> <pre class="lang-bsh prettyprint-override"><code>$data = "[ZoneTransfer] ZoneId=3" Set-Content example.txt -Stream "Zone.Identifier" -Value $data </code></pre>
64, 526, 5310, 65946, 95686
alternate-data-stream, file, powershell, powershell-4.0, windows
<h1>Block a file with Powershell</h1> <p>I want to block (not unblock) a file with Powershell. I want to cause Windows to believe that a file on disk was downloaded from the internet, or whatever other scenario exists such that files become blocked. I need this to test how some software I'm developing behaves in the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,391
bash
# Block a file with Powershell I want to block (not unblock) a file with Powershell. I want to cause Windows to believe that a file on disk was downloaded from the internet, or whatever other scenario exists such that files become blocked. I need this to test how some software I'm developing behaves in the presence of...
If you're just trying to add the zone identifier you could try something like this: ``` $data = "[ZoneTransfer] ZoneId=3" Set-Content example.txt -Stream "Zone.Identifier" -Value $data ```
46538973
How to use Test-Path on a directory containing square brackets in the name
8
2017-10-03 07:10:01
<p>I have a series of directories that have been created with square brackets in their name. For some inexplicable reason, the <code>Test-Path</code> command returns <code>$false</code> when I run it against these directories, but returns <code>$true</code> if I run the same command against a directory without square ...
3,535
3,354,235
2017-10-03 07:46:38
46,539,377
13
2017-10-03 07:33:09
2,796,058
2017-10-03 07:46:38
https://stackoverflow.com/q/46538973
https://stackoverflow.com/a/46539377
<p>You can use the <code>-LiteralPath</code> parameter for this:</p> <pre><code>Test-Path -LiteralPath '[s]50AF43AF' </code></pre> <p>Which is probably a better option than adding backticks if you're processing more than one path:</p> <pre><code>'[s]4343224D','[s]50AF43AF' | ForEach-Object { Test-Path -LiteralPath $...
<p>You can use the <code>-LiteralPath</code> parameter for this:</p> <pre><code>Test-Path -LiteralPath '[s]50AF43AF' </code></pre> <p>Which is probably a better option than adding backticks if you're processing more than one path:</p> <pre><code>'[s]4343224D','[s]50AF43AF' | ForEach-Object { Test-Path -LiteralPath $...
526
powershell
<h1>How to use Test-Path on a directory containing square brackets in the name</h1> <p>I have a series of directories that have been created with square brackets in their name. For some inexplicable reason, the <code>Test-Path</code> command returns <code>$false</code> when I run it against these directories, but retu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,392
bash
# How to use Test-Path on a directory containing square brackets in the name I have a series of directories that have been created with square brackets in their name. For some inexplicable reason, the `Test-Path` command returns `$false` when I run it against these directories, but returns `$true` if I run the same co...
You can use the `-LiteralPath` parameter for this: ``` Test-Path -LiteralPath '[s]50AF43AF' ``` Which is probably a better option than adding backticks if you're processing more than one path: ``` '[s]4343224D','[s]50AF43AF' | ForEach-Object { Test-Path -LiteralPath $_ } ```
45201225
What is the difference between base64 and MIME base 64?
8
2017-07-19 21:20:07
<p>I just spent way too much time banging my head against an SMTP server because it didn't like the base64 encoded credentials I was using. Turns out that when I chose NOT to use <code>perl</code> like so many instructions on the internet say to use, I was making a big mistake. Why is this? I thought base64 was a singl...
5,572
117,471
2018-01-18 00:50:26
45,201,330
13
2017-07-19 21:27:40
744,178
2017-07-19 21:27:40
https://stackoverflow.com/q/45201225
https://stackoverflow.com/a/45201330
<p>This is not a Perl vs. everyone else thing; this is a "using Bash's <code>&lt;&lt;&lt;</code> construct" vs. "not doing that" thing. Though not explicitly documented (at least not in the manpage on Ubuntu Xenial), <a href="https://unix.stackexchange.com/q/20157/11006">Bash appends a newline to herestrings (the <cod...
<p>This is not a Perl vs. everyone else thing; this is a "using Bash's <code>&lt;&lt;&lt;</code> construct" vs. "not doing that" thing. Though not explicitly documented (at least not in the manpage on Ubuntu Xenial), <a href="https://unix.stackexchange.com/q/20157/11006">Bash appends a newline to herestrings (the <cod...
16, 58, 390, 580, 1492
linux, mime, perl, python, shell
<h1>What is the difference between base64 and MIME base 64?</h1> <p>I just spent way too much time banging my head against an SMTP server because it didn't like the base64 encoded credentials I was using. Turns out that when I chose NOT to use <code>perl</code> like so many instructions on the internet say to use, I wa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,393
bash
# What is the difference between base64 and MIME base 64? I just spent way too much time banging my head against an SMTP server because it didn't like the base64 encoded credentials I was using. Turns out that when I chose NOT to use `perl` like so many instructions on the internet say to use, I was making a big mista...
This is not a Perl vs. everyone else thing; this is a "using Bash's `<<<` construct" vs. "not doing that" thing. Though not explicitly documented (at least not in the manpage on Ubuntu Xenial), [Bash appends a newline to herestrings (the `<<<` thing) when passing them to commands](https://unix.stackexchange.com/q/20157...
44524190
Iterate over $PATH variable using shell script
8
2017-06-13 14:19:28
<p>If I type <code>echo $PATH</code> in the terminal I get the following result:</p> <pre><code>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/fnorbert/.local/bin:/home/fnorbert/bin </code></pre> <p>I want to iterate over these paths using a shell script, but I do not know how to do that.<br> I tried the fol...
2,590
5,574,096
2020-12-01 07:50:29
44,524,309
13
2017-06-13 14:25:10
548,225
2017-06-13 14:31:14
https://stackoverflow.com/q/44524190
https://stackoverflow.com/a/44524309
<p>You can use <code>read</code> with delimiter set as <code>:</code></p> <pre><code>while read -d ':' p; do echo "$p" done &lt;&lt;&lt; "$PATH:" </code></pre>
<p>You can use <code>read</code> with delimiter set as <code>:</code></p> <pre><code>while read -d ':' p; do echo "$p" done &lt;&lt;&lt; "$PATH:" </code></pre>
34, 58, 387, 390
bash, linux, shell, unix
<h1>Iterate over $PATH variable using shell script</h1> <p>If I type <code>echo $PATH</code> in the terminal I get the following result:</p> <pre><code>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/fnorbert/.local/bin:/home/fnorbert/bin </code></pre> <p>I want to iterate over these paths using a shell scrip...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,394
bash
# Iterate over $PATH variable using shell script If I type `echo $PATH` in the terminal I get the following result: ``` /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/fnorbert/.local/bin:/home/fnorbert/bin ``` I want to iterate over these paths using a shell script, but I do not know how to do that. I tri...
You can use `read` with delimiter set as `:` ``` while read -d ':' p; do echo "$p" done <<< "$PATH:" ```
42966665
Multiple shebangs to work for different OS
8
2017-03-23 03:21:54
<p>Is there a way I can have multiple shebangs?</p> <p>So I can call <code>#!/usr/bin/env python3</code> on Ubuntu, but MacOS doesn't seem to have an equivalent, and I would like to call <code>#!/usr/bin/python3</code> instead on it.</p> <p>So is it possible to do something like:</p> <pre><code>#!/usr/bin/env python...
5,587
6,554,121
2018-10-18 04:22:56
42,966,709
13
2017-03-23 03:25:28
6,862,601
2018-10-18 04:20:49
https://stackoverflow.com/q/42966665
https://stackoverflow.com/a/42966709
<p>We can't have multiple shebang lines - there can only be one and it should always be the first line.</p> <p>If you need to support multiple versions of Python based on OS, it is best to write a small shell wrapper that invokes your python script with the right interpreter, probably with an <code>exec</code>.</p> <...
<p>We can't have multiple shebang lines - there can only be one and it should always be the first line.</p> <p>If you need to support multiple versions of Python based on OS, it is best to write a small shell wrapper that invokes your python script with the right interpreter, probably with an <code>exec</code>.</p> <...
16, 58, 369, 390, 8780
linux, macos, python, shebang, shell
<h1>Multiple shebangs to work for different OS</h1> <p>Is there a way I can have multiple shebangs?</p> <p>So I can call <code>#!/usr/bin/env python3</code> on Ubuntu, but MacOS doesn't seem to have an equivalent, and I would like to call <code>#!/usr/bin/python3</code> instead on it.</p> <p>So is it possible to do s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,395
bash
# Multiple shebangs to work for different OS Is there a way I can have multiple shebangs? So I can call `#!/usr/bin/env python3` on Ubuntu, but MacOS doesn't seem to have an equivalent, and I would like to call `#!/usr/bin/python3` instead on it. So is it possible to do something like: ``` #!/usr/bin/env python3 #!...
We can't have multiple shebang lines - there can only be one and it should always be the first line. If you need to support multiple versions of Python based on OS, it is best to write a small shell wrapper that invokes your python script with the right interpreter, probably with an `exec`. macOS does have `/usr/bin/...
42142263
Keep SSH running on Windows 10 Bash
8
2017-02-09 16:44:26
<p>I am having a problem keeping SSH running on the Windows Subsystem for Linux. It seems that if a shell is not open and running bash, all processes in the subsystem are killed. Is there a way to stop this? </p> <p>I have tried to create a service using nssm but have not be able to get it working. Now I am attempting...
6,933
7,250,252
2018-09-04 10:39:03
42,798,671
13
2017-03-14 23:51:25
229,232
2018-02-07 01:08:32
https://stackoverflow.com/q/42142263
https://stackoverflow.com/a/42798671
<p>You have to keep at least one bash console open in order for background tasks to keep running: As soon as you close your last open bash console, WSL tears-down all running processes.</p> <p>And, yes, we're working on improving this scenario in the future ;)</p> <h2>Update 2018-02-06</h2> <p>In recent Windows 10 I...
<p>You have to keep at least one bash console open in order for background tasks to keep running: As soon as you close your last open bash console, WSL tears-down all running processes.</p> <p>And, yes, we're working on improving this scenario in the future ;)</p> <h2>Update 2018-02-06</h2> <p>In recent Windows 10 I...
58, 64, 386, 387, 119526
bash, linux, ssh, windows, windows-subsystem-for-linux
<h1>Keep SSH running on Windows 10 Bash</h1> <p>I am having a problem keeping SSH running on the Windows Subsystem for Linux. It seems that if a shell is not open and running bash, all processes in the subsystem are killed. Is there a way to stop this? </p> <p>I have tried to create a service using nssm but have not b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,396
bash
# Keep SSH running on Windows 10 Bash I am having a problem keeping SSH running on the Windows Subsystem for Linux. It seems that if a shell is not open and running bash, all processes in the subsystem are killed. Is there a way to stop this? I have tried to create a service using nssm but have not be able to get it ...
You have to keep at least one bash console open in order for background tasks to keep running: As soon as you close your last open bash console, WSL tears-down all running processes. And, yes, we're working on improving this scenario in the future ;) ## Update 2018-02-06 In recent Windows 10 Insider builds, we added...
41899075
Running sed on string, benefit of using "echo" + "pipe" over "<<<"
8
2017-01-27 16:52:27
<p>Commonly I see people manipulating strings using sed as follows:</p> <pre><code>echo "./asdf" | sed -n -e "s%./%%p" </code></pre> <p>I recently learned I can also do:</p> <pre><code>sed -n -e "s%./%%p" &lt;&lt;&lt; "./asdf" </code></pre> <p>Is there a reason to avoid the latter? For instance, is it bash-specific...
7,522
4,039,619
2017-01-27 17:31:58
41,899,209
13
2017-01-27 16:59:05
14,122
2017-01-27 17:31:58
https://stackoverflow.com/q/41899075
https://stackoverflow.com/a/41899209
<h3>How should I trim <code>./</code> from the beginning of a path (or perform other simple string manipulations)?</h3> <p>Bash's built-in syntax for this is called <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a>. <code>${s#./}</code> will expand <code>$s</code> with any leadi...
<h3>How should I trim <code>./</code> from the beginning of a path (or perform other simple string manipulations)?</h3> <p>Bash's built-in syntax for this is called <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a>. <code>${s#./}</code> will expand <code>$s</code> with any leadi...
345, 387, 5282
bash, io, sed
<h1>Running sed on string, benefit of using "echo" + "pipe" over "<<<"</h1> <p>Commonly I see people manipulating strings using sed as follows:</p> <pre><code>echo "./asdf" | sed -n -e "s%./%%p" </code></pre> <p>I recently learned I can also do:</p> <pre><code>sed -n -e "s%./%%p" &lt;&lt;&lt; "./asdf" </code></pre> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,397
bash
# Running sed on string, benefit of using "echo" + "pipe" over "<<<" Commonly I see people manipulating strings using sed as follows: ``` echo "./asdf" | sed -n -e "s%./%%p" ``` I recently learned I can also do: ``` sed -n -e "s%./%%p" <<< "./asdf" ``` Is there a reason to avoid the latter? For instance, is it bas...
### How should I trim `./` from the beginning of a path (or perform other simple string manipulations)? Bash's built-in syntax for this is called [parameter expansion](http://wiki.bash-hackers.org/syntax/pe). `${s#./}` will expand `$s` with any leading `./` trimmed internal to the shell, with no subprocess or other ov...
40794622
Azure: Powershell: Set-AzureRmWebApp: How to set the "alwaysOn" property
8
2016-11-24 21:18:48
<p>I am running Powershell 5 and trying to manipulate my Azure WebApp object using <strong>Set-AzureRmWebApp</strong> (and NOT Set-AzureResource) to set the "Always On" property of the web app.</p> <p>My basic code snippet starts with a running web app named <strong>"myWebApp"</strong>, and looks like this:</p> <pre...
7,063
33,890
2016-11-25 15:31:45
40,798,208
13
2016-11-25 05:22:14
7,005,159
2016-11-25 05:22:14
https://stackoverflow.com/q/40794622
https://stackoverflow.com/a/40798208
<p><strong>"Always On"</strong> is not supported if WebApp is in a free Service Plan tier. If the WebApp is in a free tier, please scale up the App Service Plan. Please refer to the <a href="https://learn.microsoft.com/en-us/azure/app-service/azure-web-sites-web-hosting-plans-in-depth-overview#scale-an-app-service-plan...
<p><strong>"Always On"</strong> is not supported if WebApp is in a free Service Plan tier. If the WebApp is in a free tier, please scale up the App Service Plan. Please refer to the <a href="https://learn.microsoft.com/en-us/azure/app-service/azure-web-sites-web-hosting-plans-in-depth-overview#scale-an-app-service-plan...
14158, 81879, 108005
azure, azure-powershell, azure-resource-manager
<h1>Azure: Powershell: Set-AzureRmWebApp: How to set the "alwaysOn" property</h1> <p>I am running Powershell 5 and trying to manipulate my Azure WebApp object using <strong>Set-AzureRmWebApp</strong> (and NOT Set-AzureResource) to set the "Always On" property of the web app.</p> <p>My basic code snippet starts with a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,398
bash
# Azure: Powershell: Set-AzureRmWebApp: How to set the "alwaysOn" property I am running Powershell 5 and trying to manipulate my Azure WebApp object using **Set-AzureRmWebApp** (and NOT Set-AzureResource) to set the "Always On" property of the web app. My basic code snippet starts with a running web app named **"myWe...
**"Always On"** is not supported if WebApp is in a free Service Plan tier. If the WebApp is in a free tier, please scale up the App Service Plan. Please refer to the [document](https://learn.microsoft.com/en-us/azure/app-service/azure-web-sites-web-hosting-plans-in-depth-overview#scale-an-app-service-plan) for more inf...
40450238
Parse a changelog and extract changes for a version
8
2016-11-06 14:08:31
<p>I have a changelog file in markdown which contains all changes between each version of my app like that : </p> <pre><code>## Version 1.0.6 * first change * second change * third change ## Version 1.0.5 * first foo change * second foo change ## Version 1.0.4 * and so on... </code></pre> <p>What I want is to ex...
5,604
3,084,502
2022-10-20 16:51:26
40,450,360
13
2016-11-06 14:21:37
45,375
2021-11-09 12:37:08
https://stackoverflow.com/q/40450238
https://stackoverflow.com/a/40450360
<p>A slightly more elaborate <code>awk</code> solution, which</p> <ul> <li>exits once the block of interest has been printed,</li> <li>ignores blank lines,</li> <li>doesn't include the header line.</li> </ul> <pre><code>awk -v ver=1.0.5 ' /^## Version / { if (p) { exit }; if ($3 == ver) { p=1; next } } p &amp;&amp; N...
<p>A slightly more elaborate <code>awk</code> solution, which</p> <ul> <li>exits once the block of interest has been printed,</li> <li>ignores blank lines,</li> <li>doesn't include the header line.</li> </ul> <pre><code>awk -v ver=1.0.5 ' /^## Version / { if (p) { exit }; if ($3 == ver) { p=1; next } } p &amp;&amp; N...
387, 390, 990, 5282, 10327
awk, bash, sed, sh, shell
<h1>Parse a changelog and extract changes for a version</h1> <p>I have a changelog file in markdown which contains all changes between each version of my app like that : </p> <pre><code>## Version 1.0.6 * first change * second change * third change ## Version 1.0.5 * first foo change * second foo change ## Version...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,399
bash
# Parse a changelog and extract changes for a version I have a changelog file in markdown which contains all changes between each version of my app like that : ``` ## Version 1.0.6 * first change * second change * third change ## Version 1.0.5 * first foo change * second foo change ## Version 1.0.4 * and so on.....
A slightly more elaborate `awk` solution, which - exits once the block of interest has been printed, - ignores blank lines, - doesn't include the header line. ``` awk -v ver=1.0.5 ' /^## Version / { if (p) { exit }; if ($3 == ver) { p=1; next } } p && NF ' file ``` --- As script `getVersionChanges`: ``` #!/usr/bi...
35658769
"cat /dev/random" versus "tail -f /dev/random"
8
2016-02-26 18:09:16
<p>Statement </p> <pre><code>cat /dev/random </code></pre> <p>keeps producing output, as expected, but </p> <pre><code>tail -f /dev/random </code></pre> <p>hangs (at least on OSX and SUSE). Why the latter statement hangs?</p>
2,764
2,506,597
2016-02-26 18:14:24
35,658,808
13
2016-02-26 18:11:41
14,122
2016-02-26 18:11:41
https://stackoverflow.com/q/35658769
https://stackoverflow.com/a/35658808
<p><code>tail -f</code> does several things:</p> <ol> <li>Find the end of the stream, either by reading until reaching an EOF or by doing a seek to the end (an operation not available on <code>/dev/random</code>).</li> <li>Back up a certain length (possibly by retaining a buffer of an appropriate length of contents re...
<p><code>tail -f</code> does several things:</p> <ol> <li>Find the end of the stream, either by reading until reaching an EOF or by doing a seek to the end (an operation not available on <code>/dev/random</code>).</li> <li>Back up a certain length (possibly by retaining a buffer of an appropriate length of contents re...
34, 58, 197, 390, 7896
linux, random, shell, tail, unix
<h1>"cat /dev/random" versus "tail -f /dev/random"</h1> <p>Statement </p> <pre><code>cat /dev/random </code></pre> <p>keeps producing output, as expected, but </p> <pre><code>tail -f /dev/random </code></pre> <p>hangs (at least on OSX and SUSE). Why the latter statement hangs?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,400
bash
# "cat /dev/random" versus "tail -f /dev/random" Statement ``` cat /dev/random ``` keeps producing output, as expected, but ``` tail -f /dev/random ``` hangs (at least on OSX and SUSE). Why the latter statement hangs?
`tail -f` does several things: 1. Find the end of the stream, either by reading until reaching an EOF or by doing a seek to the end (an operation not available on `/dev/random`). 2. Back up a certain length (possibly by retaining a buffer of an appropriate length of contents recently read, possibly by retaining a list...
33338128
netcat with milliseconds interval
8
2015-10-26 03:41:09
<p>I am trying to use netcat to read a line in a file every few milliseconds, and send it to a port..</p> <p>So far I know from netcat documentation that it can insert a time interval between each line sent:</p> <p>This is from netcat help manual:</p> <blockquote> <p><code>-i</code> secs Delay interval for...
11,060
703,139
2015-10-28 09:25:49
33,357,493
13
2015-10-26 23:41:05
2,975,998
2015-10-28 09:25:49
https://stackoverflow.com/q/33338128
https://stackoverflow.com/a/33357493
<p>Using sleep from GNU coreutils allows to sleep for fractions of a second. So you can try:</p> <pre><code>while read -r line ; do echo "$line"; sleep 0.001; done &lt; "/path/to/file" | nc host port </code></pre> <p>In each loop the variable "line" holds one line of your file, which gets sent through netcat to the h...
<p>Using sleep from GNU coreutils allows to sleep for fractions of a second. So you can try:</p> <pre><code>while read -r line ; do echo "$line"; sleep 0.001; done &lt; "/path/to/file" | nc host port </code></pre> <p>In each loop the variable "line" holds one line of your file, which gets sent through netcat to the h...
58, 390, 5813, 24801
linux, netcat, pipe, shell
<h1>netcat with milliseconds interval</h1> <p>I am trying to use netcat to read a line in a file every few milliseconds, and send it to a port..</p> <p>So far I know from netcat documentation that it can insert a time interval between each line sent:</p> <p>This is from netcat help manual:</p> <blockquote> <p><cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,402
bash
# netcat with milliseconds interval I am trying to use netcat to read a line in a file every few milliseconds, and send it to a port.. So far I know from netcat documentation that it can insert a time interval between each line sent: This is from netcat help manual: > `-i` secs Delay interval for lines sent, ports ...
Using sleep from GNU coreutils allows to sleep for fractions of a second. So you can try: ``` while read -r line ; do echo "$line"; sleep 0.001; done < "/path/to/file" | nc host port ``` In each loop the variable "line" holds one line of your file, which gets sent through netcat to the host "host" on port "port". Aft...
32273721
Edit Git alias in command line
8
2015-08-28 14:45:18
<p>I am using Git for windows.</p> <p>Right after installation, I setup some Git alias on Git bash command line. I used: <code>git config --global alias.st status</code></p> <p>But now, I want to change the alias to diff --stat. Then, on Git bash, I typed <code>git config --global alias.st diff --stat</code>, but it ...
10,437
2,979,932
2015-08-28 19:45:09
32,278,739
13
2015-08-28 19:45:09
1,157,054
2015-08-28 19:45:09
https://stackoverflow.com/q/32273721
https://stackoverflow.com/a/32278739
<p>As with any other config option you can set the value, replacing the old one, by running <code>git config --global alias.st &lt;value here&gt;</code>. The problem you're running into is that when you want spaces in the value you're setting, you need to use quotes:</p> <pre><code>git config --global alias.st "diff -...
<p>As with any other config option you can set the value, replacing the old one, by running <code>git config --global alias.st &lt;value here&gt;</code>. The problem you're running into is that when you want spaces in the value you're setting, you need to use quotes:</p> <pre><code>git config --global alias.st "diff -...
119, 387, 1448
alias, bash, git
<h1>Edit Git alias in command line</h1> <p>I am using Git for windows.</p> <p>Right after installation, I setup some Git alias on Git bash command line. I used: <code>git config --global alias.st status</code></p> <p>But now, I want to change the alias to diff --stat. Then, on Git bash, I typed <code>git config --glo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,403
bash
# Edit Git alias in command line I am using Git for windows. Right after installation, I setup some Git alias on Git bash command line. I used: `git config --global alias.st status` But now, I want to change the alias to diff --stat. Then, on Git bash, I typed `git config --global alias.st diff --stat`, but it seems...
As with any other config option you can set the value, replacing the old one, by running `git config --global alias.st <value here>`. The problem you're running into is that when you want spaces in the value you're setting, you need to use quotes: ``` git config --global alias.st "diff --stat" ``` Unfortunately, if y...
31695600
BASH_REMATCH doesn't capture
8
2015-07-29 08:49:43
<p>I'm trying to capture a part of a path in bash:</p> <p>Input: <code>/Users/foo/.virtualenvs/venv-test-server</code></p> <p>Code:</p> <pre><code>#!/bin/zsh regex="^.*\/venv-(.*)$" if [[ $VIRTUAL_ENV =~ $regex ]] ; then echo "Matched!" echo ${BASH_REMATCH[1]} fi </code></pre> <p>Output: <code>Matched!</code></...
6,437
270,265
2015-07-29 17:08:53
31,695,639
13
2015-07-29 08:51:36
2,225,682
2015-07-29 08:51:36
https://stackoverflow.com/q/31695600
https://stackoverflow.com/a/31695639
<p>The script is specifying <code>zsh</code> instead of <code>bash</code>:</p> <pre><code>#!/bin/bash ^^^^ </code></pre> <p>If you want to use <code>zsh</code>, you need to set <code>BASH_REMATCH</code> option before using <code>=~</code>:</p> <pre><code>setopt KSH_ARRAYS BASH_REMATCH </code></pre>
<p>The script is specifying <code>zsh</code> instead of <code>bash</code>:</p> <pre><code>#!/bin/bash ^^^^ </code></pre> <p>If you want to use <code>zsh</code>, you need to set <code>BASH_REMATCH</code> option before using <code>=~</code>:</p> <pre><code>setopt KSH_ARRAYS BASH_REMATCH </code></pre>
18, 387, 3791
bash, regex, zsh
<h1>BASH_REMATCH doesn't capture</h1> <p>I'm trying to capture a part of a path in bash:</p> <p>Input: <code>/Users/foo/.virtualenvs/venv-test-server</code></p> <p>Code:</p> <pre><code>#!/bin/zsh regex="^.*\/venv-(.*)$" if [[ $VIRTUAL_ENV =~ $regex ]] ; then echo "Matched!" echo ${BASH_REMATCH[1]} fi </code></pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,404
bash
# BASH_REMATCH doesn't capture I'm trying to capture a part of a path in bash: Input: `/Users/foo/.virtualenvs/venv-test-server` Code: ``` #!/bin/zsh regex="^.*\/venv-(.*)$" if [[ $VIRTUAL_ENV =~ $regex ]] ; then echo "Matched!" echo ${BASH_REMATCH[1]} fi ``` Output: `Matched!` But the match isn't printed. Wh...
The script is specifying `zsh` instead of `bash`: ``` #!/bin/bash ^^^^ ``` If you want to use `zsh`, you need to set `BASH_REMATCH` option before using `=~`: ``` setopt KSH_ARRAYS BASH_REMATCH ```
30431979
Need to concatenate a string to each line of ls command output in unix
8
2015-05-25 05:52:00
<p>I am a beginer in Shell script. Below is my requirement in UNIX Korn Shell.</p> <h3>Example:</h3> <p>When we list files using <code>ls</code> command redirect to a file the file names will be stored as below.</p> <pre><code>$ ls FILE*&gt;FLIST.TXT $ cat FLIST.TXT FILE1 FILE2 FILE3 </code></pre> <p>But I need output ...
15,016
3,611,976
2015-05-25 06:15:44
30,432,166
13
2015-05-25 06:08:59
908,939
2015-05-25 06:13:30
https://stackoverflow.com/q/30431979
https://stackoverflow.com/a/30432166
<p>You can't use <code>ls</code> alone to append data before each file. <code>ls</code> exists to list files.<br> You will need to use other tools along side <code>ls</code>. </p> <p>You can append to the front of each line using the <code>sed</code> command: </p> <pre><code>cat FLIST.TXT | sed 's/^/STR,/' </code>...
<p>You can't use <code>ls</code> alone to append data before each file. <code>ls</code> exists to list files.<br> You will need to use other tools along side <code>ls</code>. </p> <p>You can append to the front of each line using the <code>sed</code> command: </p> <pre><code>cat FLIST.TXT | sed 's/^/STR,/' </code>...
34, 390
shell, unix
<h1>Need to concatenate a string to each line of ls command output in unix</h1> <p>I am a beginer in Shell script. Below is my requirement in UNIX Korn Shell.</p> <h3>Example:</h3> <p>When we list files using <code>ls</code> command redirect to a file the file names will be stored as below.</p> <pre><code>$ ls FILE*&gt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,405
bash
# Need to concatenate a string to each line of ls command output in unix I am a beginer in Shell script. Below is my requirement in UNIX Korn Shell. ### Example: When we list files using `ls` command redirect to a file the file names will be stored as below. ``` $ ls FILE*>FLIST.TXT $ cat FLIST.TXT FILE1 FILE2 FILE...
You can't use `ls` alone to append data before each file. `ls` exists to list files. You will need to use other tools along side `ls`. You can append to the front of each line using the `sed` command: ``` cat FLIST.TXT | sed 's/^/STR,/' ``` This will send the changes to `stdout`. --- If you'd like to change the ...
29792850
Get certificate expiry date from the embedded.mobileprovision provisioning profile
8
2015-04-22 09:13:32
<p>I need to get the expiry date of our iOS enterprise certificate used in an ipa's embedded.mobileprovision file using the command line.</p> <p>I've got this so far:</p> <pre><code>security cms -D -i Payload/*.app/embedded.mobileprovision &gt; tmp.plist &amp;&amp; /usr/libexec/PlistBuddy -c 'Print :DeveloperCertific...
2,953
224,571
2015-04-28 06:01:29
29,840,111
13
2015-04-24 06:23:06
224,571
2015-04-24 06:54:33
https://stackoverflow.com/q/29792850
https://stackoverflow.com/a/29840111
<p>I've successfully been able to get to the certificate information.</p> <p>The problem was that my PlistBuddy command was wrong. I should have used 'DeveloperCertificates:0' instead of ':DeveloperCertificates'.</p> <p>I also did not need the base64 stuff.</p> <p>So the working commandline to get the info from the ...
<p>I've successfully been able to get to the certificate information.</p> <p>The problem was that my PlistBuddy command was wrong. I should have used 'DeveloperCertificates:0' instead of ':DeveloperCertificates'.</p> <p>I also did not need the base64 stuff.</p> <p>So the working commandline to get the info from the ...
387, 58338, 66776
bash, ios, provisioning-profile
<h1>Get certificate expiry date from the embedded.mobileprovision provisioning profile</h1> <p>I need to get the expiry date of our iOS enterprise certificate used in an ipa's embedded.mobileprovision file using the command line.</p> <p>I've got this so far:</p> <pre><code>security cms -D -i Payload/*.app/embedded.mo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,406
bash
# Get certificate expiry date from the embedded.mobileprovision provisioning profile I need to get the expiry date of our iOS enterprise certificate used in an ipa's embedded.mobileprovision file using the command line. I've got this so far: ``` security cms -D -i Payload/*.app/embedded.mobileprovision > tmp.plist &...
I've successfully been able to get to the certificate information. The problem was that my PlistBuddy command was wrong. I should have used 'DeveloperCertificates:0' instead of ':DeveloperCertificates'. I also did not need the base64 stuff. So the working commandline to get the info from the enterprise certificate i...
29724851
Empty parameter is not Null in function
8
2015-04-19 01:34:59
<p>Given this basic function:</p> <pre><code>Function TestFunction { Param ( [int]$Par1, [string]$Par2, [string]$Par3 ) If ($Par1 -ne $Null) { Write-Output "Par1 = $Par1" } If ($Par2 -ne $Null -or $Par2 -ne '') { Write-Output "Par2 = $Par2" } If ($Par3 -ne $Null) { Write-Output "Par3 = $Par3" } } TestF...
47,547
4,805,877
2018-04-11 11:17:12
29,724,864
13
2015-04-19 01:37:38
null
2015-04-19 02:12:14
https://stackoverflow.com/q/29724851
https://stackoverflow.com/a/29724864
<p>You have a logic error in your program: <code>$Par2</code> will <em>always</em> be not equal to <code>$null</code> <strong>or</strong> not equal to <code>''</code>.</p> <p>To fix the logic, you should use <code>-and</code> instead of <code>-or</code> here:</p> <pre class="lang-powershell prettyprint-override"><...
<p>You have a logic error in your program: <code>$Par2</code> will <em>always</em> be not equal to <code>$null</code> <strong>or</strong> not equal to <code>''</code>.</p> <p>To fix the logic, you should use <code>-and</code> instead of <code>-or</code> here:</p> <pre class="lang-powershell prettyprint-override"><...
526, 2773, 5569
function, if-statement, powershell
<h1>Empty parameter is not Null in function</h1> <p>Given this basic function:</p> <pre><code>Function TestFunction { Param ( [int]$Par1, [string]$Par2, [string]$Par3 ) If ($Par1 -ne $Null) { Write-Output "Par1 = $Par1" } If ($Par2 -ne $Null -or $Par2 -ne '') { Write-Output "Par2 = $Par2" } If ($Par3 -...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,407
bash
# Empty parameter is not Null in function Given this basic function: ``` Function TestFunction { Param ( [int]$Par1, [string]$Par2, [string]$Par3 ) If ($Par1 -ne $Null) { Write-Output "Par1 = $Par1" } If ($Par2 -ne $Null -or $Par2 -ne '') { Write-Output "Par2 = $Par2" } If ($Par3 -ne $Null) { Write-Ou...
You have a logic error in your program: `$Par2` will *always* be not equal to `$null` **or** not equal to `''`. To fix the logic, you should use `-and` instead of `-or` here: ``` If ($Par2 -ne $Null -and $Par2 -ne '') { Write-Output "Par2 = $Par2" } ``` However, because you casted the `$Par2` argument to a string in...
29608797
How can I extract only an inode number for a file in Linux?
8
2015-04-13 15:09:24
<p>just a quick question. I want to use my inode number in my bash script however, I need some help.</p> <p>I'm using command <code>ls -i "filename"</code>, which echoes "inode number" "filename". The problem is, I only need inode number. Is there a way, where i can "slice" the output?</p>
9,850
4,233,553
2025-11-07 00:57:09
29,608,905
13
2015-04-13 15:14:48
1,275,169
2015-04-13 15:18:05
https://stackoverflow.com/q/29608797
https://stackoverflow.com/a/29608905
<p>You can use <code>stat</code> command with <code>%i</code> to get only inode nuymbers:</p> <pre><code>stat -c '%i' * </code></pre> <p>Most of the utilities/commands use to get inode use <code>lstat</code> system call which is the one used by <code>stat</code> command too.</p>
<p>You can use <code>stat</code> command with <code>%i</code> to get only inode nuymbers:</p> <pre><code>stat -c '%i' * </code></pre> <p>Most of the utilities/commands use to get inode use <code>lstat</code> system call which is the one used by <code>stat</code> command too.</p>
58, 387
bash, linux
<h1>How can I extract only an inode number for a file in Linux?</h1> <p>just a quick question. I want to use my inode number in my bash script however, I need some help.</p> <p>I'm using command <code>ls -i "filename"</code>, which echoes "inode number" "filename". The problem is, I only need inode number. Is there a ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,408
bash
# How can I extract only an inode number for a file in Linux? just a quick question. I want to use my inode number in my bash script however, I need some help. I'm using command `ls -i "filename"`, which echoes "inode number" "filename". The problem is, I only need inode number. Is there a way, where i can "slice" th...
You can use `stat` command with `%i` to get only inode nuymbers: ``` stat -c '%i' * ``` Most of the utilities/commands use to get inode use `lstat` system call which is the one used by `stat` command too.
28436651
Replacing last occurrence of substring in string
8
2015-02-10 16:25:42
<p>How can you replace the <em>last</em> occurrence of a substring in a string?</p>
19,609
1,907,604
2021-06-07 13:21:24
28,437,855
13
2015-02-10 17:20:33
3,829,407
2016-09-20 20:21:23
https://stackoverflow.com/q/28436651
https://stackoverflow.com/a/28437855
<p>Regular Expressions can also perform this task. Here is an example of one that would work. It will replace the last occurrence of "Aquarius" with "Bumblebee Joe"</p> <pre><code>$text = "This is the dawning of the age of Aquarius. The age of Aquarius, Aquarius, Aquarius, Aquarius, Aquarius" $text -replace "(.*)Aquar...
<p>Regular Expressions can also perform this task. Here is an example of one that would work. It will replace the last occurrence of "Aquarius" with "Bumblebee Joe"</p> <pre><code>$text = "This is the dawning of the age of Aquarius. The age of Aquarius, Aquarius, Aquarius, Aquarius, Aquarius" $text -replace "(.*)Aquar...
526, 2498
powershell, replace
<h1>Replacing last occurrence of substring in string</h1> <p>How can you replace the <em>last</em> occurrence of a substring in a string?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,409
bash
# Replacing last occurrence of substring in string How can you replace the *last* occurrence of a substring in a string?
Regular Expressions can also perform this task. Here is an example of one that would work. It will replace the last occurrence of "Aquarius" with "Bumblebee Joe" ``` $text = "This is the dawning of the age of Aquarius. The age of Aquarius, Aquarius, Aquarius, Aquarius, Aquarius" $text -replace "(.*)Aquarius(.*)", '$1B...
27300416
PowerShell shortest syntax to create a new PSObject using Property?
8
2014-12-04 17:36:33
<p>I use the following very often:</p> <pre><code>New-Object psobject -Property @{a=1; b=2; c=3; d=4} </code></pre> <p>I would like to make this as short as possible, perhaps even 1 character? What's the shortest way to create a new psobject using the properties above?</p> <p>My desire is that I could do it with a s...
3,237
1,131,254
2014-12-04 20:00:49
27,300,904
13
2014-12-04 18:04:05
3,067,642
2014-12-04 20:00:49
https://stackoverflow.com/q/27300416
https://stackoverflow.com/a/27300904
<p>PowerShell 3 and later support this syntax:</p> <pre><code>[pscustomobject]@{a=1; b=2; c=3; d=4} </code></pre> <p>One of the added benefits is that the properties are ordered, unlike a standard call to New-Object.</p> <p>You add overhead, but presumably you could <a href="http://blogs.technet.com/b/heyscriptinggu...
<p>PowerShell 3 and later support this syntax:</p> <pre><code>[pscustomobject]@{a=1; b=2; c=3; d=4} </code></pre> <p>One of the added benefits is that the properties are ordered, unlike a standard call to New-Object.</p> <p>You add overhead, but presumably you could <a href="http://blogs.technet.com/b/heyscriptinggu...
526, 4954
code-golf, powershell
<h1>PowerShell shortest syntax to create a new PSObject using Property?</h1> <p>I use the following very often:</p> <pre><code>New-Object psobject -Property @{a=1; b=2; c=3; d=4} </code></pre> <p>I would like to make this as short as possible, perhaps even 1 character? What's the shortest way to create a new psobject...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,410
bash
# PowerShell shortest syntax to create a new PSObject using Property? I use the following very often: ``` New-Object psobject -Property @{a=1; b=2; c=3; d=4} ``` I would like to make this as short as possible, perhaps even 1 character? What's the shortest way to create a new psobject using the properties above? My ...
PowerShell 3 and later support this syntax: ``` [pscustomobject]@{a=1; b=2; c=3; d=4} ``` One of the added benefits is that the properties are ordered, unlike a standard call to New-Object. You add overhead, but presumably you could [create your own type accelerator](http://blogs.technet.com/b/heyscriptingguy/archiv...
25274752
gdb how to execute target program from script
8
2014-08-12 21:58:22
<p>I want to debug a program, using gdb. But I invoke that program through a script.</p> <p>How can I use gdb? The script is long and its not possible for me to invoke the program directly using command line arguments from gdb.</p> <p>Also the process that is created when the script starts is short lived so can't att...
5,391
1,874,105
2014-08-14 02:51:13
25,299,071
13
2014-08-14 02:20:58
1,442,050
2014-08-14 02:20:58
https://stackoverflow.com/q/25274752
https://stackoverflow.com/a/25299071
<p>There are several ways.</p> <p>The truly old-school way is to hack a loop into your program's <code>main</code> like:</p> <pre><code>volatile int zzz; ... int main() { while (!zzz) sleep (1); </code></pre> <p>Then, run your script. In a separate window, run gdb on the program you want to debug, and use <code>a...
<p>There are several ways.</p> <p>The truly old-school way is to hack a loop into your program's <code>main</code> like:</p> <pre><code>volatile int zzz; ... int main() { while (!zzz) sleep (1); </code></pre> <p>Then, run your script. In a separate window, run gdb on the program you want to debug, and use <code>a...
58, 277, 390, 1962
debugging, gdb, linux, shell
<h1>gdb how to execute target program from script</h1> <p>I want to debug a program, using gdb. But I invoke that program through a script.</p> <p>How can I use gdb? The script is long and its not possible for me to invoke the program directly using command line arguments from gdb.</p> <p>Also the process that is cre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,411
bash
# gdb how to execute target program from script I want to debug a program, using gdb. But I invoke that program through a script. How can I use gdb? The script is long and its not possible for me to invoke the program directly using command line arguments from gdb. Also the process that is created when the script st...
There are several ways. The truly old-school way is to hack a loop into your program's `main` like: ``` volatile int zzz; ... int main() { while (!zzz) sleep (1); ``` Then, run your script. In a separate window, run gdb on the program you want to debug, and use `attach` to attach to the sleeping program. Then you ...
24236362
Bash alias create file with current timestamp in filename
8
2014-06-16 03:40:26
<p>I am trying to create a bash alias that will print the current UNIX timestamp every time the alias is called. I have the following in my bash profile:</p> <pre><code>alias unix="echo "$(date +%s)"" </code></pre> <p>However, it seems that the current unix timestamp is being stored as soon as the bash profile is so...
6,190
736,864
2016-04-12 04:49:21
24,236,390
13
2014-06-16 03:44:48
3,531,387
2015-01-06 16:04:28
https://stackoverflow.com/q/24236362
https://stackoverflow.com/a/24236390
<p>Use single quotes to prevent immediate expansion.</p> <pre><code>alias unix='echo $(date +%s)' </code></pre> <p>Update: While I'm happy to have been able to explain the different expansion behavior between single and double quotes, please also see the other answer, by Robby Cornelissen, for a more efficient way to...
<p>Use single quotes to prevent immediate expansion.</p> <pre><code>alias unix='echo $(date +%s)' </code></pre> <p>Update: While I'm happy to have been able to explain the different expansion behavior between single and double quotes, please also see the other answer, by Robby Cornelissen, for a more efficient way to...
34, 58, 387, 390
bash, linux, shell, unix
<h1>Bash alias create file with current timestamp in filename</h1> <p>I am trying to create a bash alias that will print the current UNIX timestamp every time the alias is called. I have the following in my bash profile:</p> <pre><code>alias unix="echo "$(date +%s)"" </code></pre> <p>However, it seems that the curre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,412
bash
# Bash alias create file with current timestamp in filename I am trying to create a bash alias that will print the current UNIX timestamp every time the alias is called. I have the following in my bash profile: ``` alias unix="echo "$(date +%s)"" ``` However, it seems that the current unix timestamp is being stored ...
Use single quotes to prevent immediate expansion. ``` alias unix='echo $(date +%s)' ``` Update: While I'm happy to have been able to explain the different expansion behavior between single and double quotes, please also see the other answer, by Robby Cornelissen, for a more efficient way to get the same result. The `...
22199868
Loop through variable 2 elements at a time in bash
8
2014-03-05 13:58:28
<p>I have a bash variable which is a white-space separated list of strings and would like a loop that iterates 2 elements at a time from that list. I've made sure the length of the list is divisible by 2. So I want something like:</p> <pre><code>x="a bb cccc d" while read first second; do echo "($first,$second)" d...
5,550
null
2014-08-19 16:56:34
22,201,477
13
2014-03-05 15:04:51
1,566,221
2014-03-05 15:32:56
https://stackoverflow.com/q/22199868
https://stackoverflow.com/a/22201477
<p>Depending on what you want to do with the values, you could do something like this:</p> <pre><code>$ x="one two buckle myShoe" $ xargs -n 2 printf "(%s,%s)\n" &lt;&lt;&lt;$x (one,two) (buckle,myShoe) </code></pre> <p>I assume that you really want to assign the values to shell variables, though, and that the body o...
<p>Depending on what you want to do with the values, you could do something like this:</p> <pre><code>$ x="one two buckle myShoe" $ xargs -n 2 printf "(%s,%s)\n" &lt;&lt;&lt;$x (one,two) (buckle,myShoe) </code></pre> <p>I assume that you really want to assign the values to shell variables, though, and that the body o...
387, 2314
bash, loops
<h1>Loop through variable 2 elements at a time in bash</h1> <p>I have a bash variable which is a white-space separated list of strings and would like a loop that iterates 2 elements at a time from that list. I've made sure the length of the list is divisible by 2. So I want something like:</p> <pre><code>x="a bb cccc ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,413
bash
# Loop through variable 2 elements at a time in bash I have a bash variable which is a white-space separated list of strings and would like a loop that iterates 2 elements at a time from that list. I've made sure the length of the list is divisible by 2. So I want something like: ``` x="a bb cccc d" while read first ...
Depending on what you want to do with the values, you could do something like this: ``` $ x="one two buckle myShoe" $ xargs -n 2 printf "(%s,%s)\n" <<<$x (one,two) (buckle,myShoe) ``` I assume that you really want to assign the values to shell variables, though, and that the body of your anticipated loop is more comp...
21107098
How do I get the opposite of the if construct in Bash?
8
2014-01-14 06:10:46
<p><code>if date -d "2012010123"</code> runs if the date command returns a zero exit code. How do I get the opposite to occur? In other words, how can I get the if statement to run if the exit code is 1? </p>
10,124
1,119,779
2021-09-16 21:44:34
21,107,121
13
2014-01-14 06:13:07
2,235,132
2021-09-16 21:44:34
https://stackoverflow.com/q/21107098
https://stackoverflow.com/a/21107121
<p>Negate it:</p> <pre><code>if ! date -d &quot;2012010123&quot;; then # do something here (date returned with non-zero exit code) fi </code></pre> <p><code>if</code> takes a command pipeline (or a list thereof), and of pipelines <code>man bash</code> says this:</p> <blockquote> <p>The return status of a pipeline i...
<p>Negate it:</p> <pre><code>if ! date -d &quot;2012010123&quot;; then # do something here (date returned with non-zero exit code) fi </code></pre> <p><code>if</code> takes a command pipeline (or a list thereof), and of pipelines <code>man bash</code> says this:</p> <blockquote> <p>The return status of a pipeline i...
387
bash
<h1>How do I get the opposite of the if construct in Bash?</h1> <p><code>if date -d "2012010123"</code> runs if the date command returns a zero exit code. How do I get the opposite to occur? In other words, how can I get the if statement to run if the exit code is 1? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,414
bash
# How do I get the opposite of the if construct in Bash? `if date -d "2012010123"` runs if the date command returns a zero exit code. How do I get the opposite to occur? In other words, how can I get the if statement to run if the exit code is 1?
Negate it: ``` if ! date -d "2012010123"; then # do something here (date returned with non-zero exit code) fi ``` `if` takes a command pipeline (or a list thereof), and of pipelines `man bash` says this: > The return status of a pipeline is the exit status of the last command[...] If the reserved word `!` precedes...
21052812
Difference between dates using PowerShell
8
2014-01-10 19:29:18
<p>I am learning Windows PowerShell, and I am trying to get the months difference given two dates:</p> <pre><code>For example: end: 2014-06-01 now: 2014-01-10 answer: 6 months $now = get-date $date = $end -as [DateTime]; if (!$date) { 'You entered an invalid date' } else { $nts = (...
56,720
255,391
2022-02-01 09:50:30
21,053,007
13
2014-01-10 19:40:03
574,168
2014-01-10 19:40:03
https://stackoverflow.com/q/21052812
https://stackoverflow.com/a/21053007
<p>Something like this?</p> <pre><code>$begin = [datetime]'02/10/2011' $end = [datetime]'01/10/2013' $monthdiff = $end.month - $begin.month + (($end.Year - $begin.year) * 12) $monthdiff 23 </code></pre>
<p>Something like this?</p> <pre><code>$begin = [datetime]'02/10/2011' $end = [datetime]'01/10/2013' $monthdiff = $end.month - $begin.month + (($end.Year - $begin.year) * 12) $monthdiff 23 </code></pre>
526
powershell
<h1>Difference between dates using PowerShell</h1> <p>I am learning Windows PowerShell, and I am trying to get the months difference given two dates:</p> <pre><code>For example: end: 2014-06-01 now: 2014-01-10 answer: 6 months $now = get-date $date = $end -as [DateTime]; if (!$date) { 'You entered a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,415
bash
# Difference between dates using PowerShell I am learning Windows PowerShell, and I am trying to get the months difference given two dates: ``` For example: end: 2014-06-01 now: 2014-01-10 answer: 6 months $now = get-date $date = $end -as [DateTime]; if (!$date) { 'You entered an invalid date' ...
Something like this? ``` $begin = [datetime]'02/10/2011' $end = [datetime]'01/10/2013' $monthdiff = $end.month - $begin.month + (($end.Year - $begin.year) * 12) $monthdiff 23 ```
16579013
Perl - DBI and .pgpass
8
2013-05-16 04:28:27
<p>I can successfully create a connection to a Postgres db using the following: </p> <pre><code>my $settings = { host =&gt; 'myhost', db =&gt; 'mydb', user =&gt; 'myuser', passwd =&gt; 'mypasswd' }; my $connection = DBI-&gt;connect( 'DBI:Pg:dbname=' . $settings-&gt;{'db'} . ';host=' . $settings-&g...
2,596
751,863
2013-11-14 14:29:40
19,980,156
13
2013-11-14 14:24:34
2,863,726
2013-11-14 14:29:40
https://stackoverflow.com/q/16579013
https://stackoverflow.com/a/19980156
<p>YES! There <strong>IS</strong> a better way.</p> <p>Change between test &amp; live servers easily.</p> <ul> <li>keep passwords in <code>~/.pgpass</code> (for <code>psql</code> &amp; <code>pg_dump</code>)</li> <li>other config info in <code>~/.pg_service.conf</code> (or <code>/etc/pg_service.conf</code>)</li> </ul>...
<p>YES! There <strong>IS</strong> a better way.</p> <p>Change between test &amp; live servers easily.</p> <ul> <li>keep passwords in <code>~/.pgpass</code> (for <code>psql</code> &amp; <code>pg_dump</code>)</li> <li>other config info in <code>~/.pg_service.conf</code> (or <code>/etc/pg_service.conf</code>)</li> </ul>...
34, 256, 387, 580, 12262
bash, dbi, perl, postgresql, unix
<h1>Perl - DBI and .pgpass</h1> <p>I can successfully create a connection to a Postgres db using the following: </p> <pre><code>my $settings = { host =&gt; 'myhost', db =&gt; 'mydb', user =&gt; 'myuser', passwd =&gt; 'mypasswd' }; my $connection = DBI-&gt;connect( 'DBI:Pg:dbname=' . $settings-&gt;...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,416
bash
# Perl - DBI and .pgpass I can successfully create a connection to a Postgres db using the following: ``` my $settings = { host => 'myhost', db => 'mydb', user => 'myuser', passwd => 'mypasswd' }; my $connection = DBI->connect( 'DBI:Pg:dbname=' . $settings->{'db'} . ';host=' . $settings->{'host'}...
YES! There **IS** a better way. Change between test & live servers easily. - keep passwords in `~/.pgpass` (for `psql` & `pg_dump`) - other config info in `~/.pg_service.conf` (or `/etc/pg_service.conf`) e.g: ``` #!/usr/bin/perl -T use strict; use warnings; use DBI; my $dbh = DBI->connect ( #"dbi:Pg:service=li...
19573844
PowerShell Script Arguments Passed as Array
8
2013-10-24 18:33:12
<p><strong>EDIT:</strong> I've changed the code here to a simple test case, rather than the full implementation where this problem is arising.</p> <p>I am trying to call one Powershell script from another, but things aren't working out as I'm expecting. As I understand things, the "&amp;" operator is supposed to expan...
9,121
707,095
2013-11-03 23:57:59
19,759,742
13
2013-11-03 23:57:59
2,495
2013-11-03 23:57:59
https://stackoverflow.com/q/19573844
https://stackoverflow.com/a/19759742
<p>When invoking a native command, a call like <code>&amp; $program $programargs</code> will correctly escape the array of arguments so that it is parsed correctly by the executable. However, for a PowerShell cmdlet, script, or function, there is no external programming requiring a serialize/parse round-trip, so the ar...
<p>When invoking a native command, a call like <code>&amp; $program $programargs</code> will correctly escape the array of arguments so that it is parsed correctly by the executable. However, for a PowerShell cmdlet, script, or function, there is no external programming requiring a serialize/parse round-trip, so the ar...
526
powershell
<h1>PowerShell Script Arguments Passed as Array</h1> <p><strong>EDIT:</strong> I've changed the code here to a simple test case, rather than the full implementation where this problem is arising.</p> <p>I am trying to call one Powershell script from another, but things aren't working out as I'm expecting. As I underst...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,417
bash
# PowerShell Script Arguments Passed as Array **EDIT:** I've changed the code here to a simple test case, rather than the full implementation where this problem is arising. I am trying to call one Powershell script from another, but things aren't working out as I'm expecting. As I understand things, the "&" operator ...
When invoking a native command, a call like `& $program $programargs` will correctly escape the array of arguments so that it is parsed correctly by the executable. However, for a PowerShell cmdlet, script, or function, there is no external programming requiring a serialize/parse round-trip, so the array is passed as-i...
19025763
linux script running c program
8
2013-09-26 10:30:35
<p>i tried to run a script in linux to run a c program the script was as follows</p> <pre><code>#!/bin/bash `gcc odd.c -o odd222` `chmod +x odd222` echo `./odd222` </code></pre> <p>and odd.c is</p> <pre><code>main() { int i; printf("enter the no."); scanf("%d",&amp;i); printf("shiv"); } </code></pre> <p>but the pro...
44,335
2,809,547
2018-07-13 03:19:05
19,026,219
13
2013-09-26 10:52:20
68,587
2013-09-26 10:58:26
https://stackoverflow.com/q/19025763
https://stackoverflow.com/a/19026219
<p>Get rid of the backticks, the chmod, and the <code>echo</code>. All you need to do is run <code>gcc</code>, then run your program.</p> <pre><code>#!/bin/bash gcc odd.c -o odd222 ./odd222 </code></pre> <p>It'd also be good to only try to run the program if it compiles successfully. You can make it conditional by us...
<p>Get rid of the backticks, the chmod, and the <code>echo</code>. All you need to do is run <code>gcc</code>, then run your program.</p> <pre><code>#!/bin/bash gcc odd.c -o odd222 ./odd222 </code></pre> <p>It'd also be good to only try to run the program if it compiles successfully. You can make it conditional by us...
8, 58, 387
bash, c, linux
<h1>linux script running c program</h1> <p>i tried to run a script in linux to run a c program the script was as follows</p> <pre><code>#!/bin/bash `gcc odd.c -o odd222` `chmod +x odd222` echo `./odd222` </code></pre> <p>and odd.c is</p> <pre><code>main() { int i; printf("enter the no."); scanf("%d",&amp;i); printf(...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,418
bash
# linux script running c program i tried to run a script in linux to run a c program the script was as follows ``` #!/bin/bash `gcc odd.c -o odd222` `chmod +x odd222` echo `./odd222` ``` and odd.c is ``` main() { int i; printf("enter the no."); scanf("%d",&i); printf("shiv"); } ``` but the problem is that when i r...
Get rid of the backticks, the chmod, and the `echo`. All you need to do is run `gcc`, then run your program. ``` #!/bin/bash gcc odd.c -o odd222 ./odd222 ``` It'd also be good to only try to run the program if it compiles successfully. You can make it conditional by using `&&`. ``` #!/bin/bash gcc odd.c -o odd222 &&...
18858221
How do I change directory and run a file in that directory in powershell?
8
2013-09-17 19:24:30
<p>For example, i want to run cygwin.bat which is located in the c:/cygwin/ directory...</p> <p>I tried the following but got an error: </p> <blockquote> <p>cd c:/cygwin ./cygwin.bat </p> </blockquote>
17,476
2,788,932
2013-10-18 16:46:21
18,858,647
13
2013-09-17 19:48:10
775,544
2013-09-17 19:48:10
https://stackoverflow.com/q/18858221
https://stackoverflow.com/a/18858647
<p><code>cd c:/cygwin</code> and <code>./cygwin.bat</code> are two different statements. You can execute them from the interactive console like so: </p> <pre><code>PS C:\&gt; cd c:/cygwin PS C:\cygwin&gt; ./cygwin.bat </code></pre> <p>Or, if you really want to do it on the same line, then use a <code>;</code>...
<p><code>cd c:/cygwin</code> and <code>./cygwin.bat</code> are two different statements. You can execute them from the interactive console like so: </p> <pre><code>PS C:\&gt; cd c:/cygwin PS C:\cygwin&gt; ./cygwin.bat </code></pre> <p>Or, if you really want to do it on the same line, then use a <code>;</code>...
526, 1796, 24067
command, powershell, powershell-2.0
<h1>How do I change directory and run a file in that directory in powershell?</h1> <p>For example, i want to run cygwin.bat which is located in the c:/cygwin/ directory...</p> <p>I tried the following but got an error: </p> <blockquote> <p>cd c:/cygwin ./cygwin.bat </p> </blockquote>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,419
bash
# How do I change directory and run a file in that directory in powershell? For example, i want to run cygwin.bat which is located in the c:/cygwin/ directory... I tried the following but got an error: > cd c:/cygwin ./cygwin.bat
`cd c:/cygwin` and `./cygwin.bat` are two different statements. You can execute them from the interactive console like so: ``` PS C:\> cd c:/cygwin PS C:\cygwin> ./cygwin.bat ``` Or, if you really want to do it on the same line, then use a `;` between them to indicate separate statements. ``` cd c:/cygwin ; ....
18204670
Connect to a VPN Connection in Ubuntu in bash
8
2013-08-13 08:53:44
<p>How can I connect to a <code>VPN Connection</code> when I can use only bash (terminal)?</p> <p>I create a connection but I want to connect or disconnect using remote ssh connection </p>
13,587
1,385,652
2018-01-02 06:57:55
18,204,671
13
2013-08-13 08:53:44
1,385,652
2013-08-13 08:53:44
https://stackoverflow.com/q/18204670
https://stackoverflow.com/a/18204671
<p>you can use <code>nmcli</code> to do that. this program is use for network management.</p> <pre><code>nmcli con up id &lt;name_of_connection&gt; </code></pre> <p>you need to save the password of that connection before you use this command. For more information, try <code>man nmcli</code></p> <p>any help on how to...
<p>you can use <code>nmcli</code> to do that. this program is use for network management.</p> <pre><code>nmcli con up id &lt;name_of_connection&gt; </code></pre> <p>you need to save the password of that connection before you use this command. For more information, try <code>man nmcli</code></p> <p>any help on how to...
58, 387, 633
bash, linux, vpn
<h1>Connect to a VPN Connection in Ubuntu in bash</h1> <p>How can I connect to a <code>VPN Connection</code> when I can use only bash (terminal)?</p> <p>I create a connection but I want to connect or disconnect using remote ssh connection </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,420
bash
# Connect to a VPN Connection in Ubuntu in bash How can I connect to a `VPN Connection` when I can use only bash (terminal)? I create a connection but I want to connect or disconnect using remote ssh connection
you can use `nmcli` to do that. this program is use for network management. ``` nmcli con up id <name_of_connection> ``` you need to save the password of that connection before you use this command. For more information, try `man nmcli` any help on how to create VPN_CONNECTION in bash and how to manage them will app...
16229582
Continue execution on Exception
8
2013-04-26 05:51:21
<p>Below is the script I want to execute. The issue here is once an exception occurs it stops executing, I used <code>continue</code> in the catch block but that did not work. How do I get it working even after an exception occurs it should loop in <code>foreach</code>.</p> <p>I also used a <code>while($true)</code> l...
85,106
243,680
2019-08-16 20:48:01
16,231,327
13
2013-04-26 07:51:07
1,630,171
2013-04-26 07:51:07
https://stackoverflow.com/q/16229582
https://stackoverflow.com/a/16231327
<p>You use <code>try {...} catch {...}</code> when you want to handle errors. If you want to ignore them, you should set <code>$ErrorActionPreference = "Continue"</code> (or <code>"SilentlyContinue"</code>) as @C.B. suggested, or use <code>-ErrorAction "SilentlyContinue"</code> for the particular operation raising the ...
<p>You use <code>try {...} catch {...}</code> when you want to handle errors. If you want to ignore them, you should set <code>$ErrorActionPreference = "Continue"</code> (or <code>"SilentlyContinue"</code>) as @C.B. suggested, or use <code>-ErrorAction "SilentlyContinue"</code> for the particular operation raising the ...
379, 526, 4650
continue, error-handling, powershell
<h1>Continue execution on Exception</h1> <p>Below is the script I want to execute. The issue here is once an exception occurs it stops executing, I used <code>continue</code> in the catch block but that did not work. How do I get it working even after an exception occurs it should loop in <code>foreach</code>.</p> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,421
bash
# Continue execution on Exception Below is the script I want to execute. The issue here is once an exception occurs it stops executing, I used `continue` in the catch block but that did not work. How do I get it working even after an exception occurs it should loop in `foreach`. I also used a `while($true)` loop but ...
You use `try {...} catch {...}` when you want to handle errors. If you want to ignore them, you should set `$ErrorActionPreference = "Continue"` (or `"SilentlyContinue"`) as @C.B. suggested, or use `-ErrorAction "SilentlyContinue"` for the particular operation raising the error. If you want to handle errors from a cert...
14878684
How to send a sequence of AT commands to a serial port in bash?
8
2013-02-14 15:50:09
<p>In Linux I need to send a sequence of AT commands to a serial port on e.g. <code>/dev/ttyS0</code>, which has to wait for an <code>OK</code> answer before the next command is sent. I could imagine doing something like</p> <pre><code>echo 'AT' &gt; /dev/ttyS0 echo 'ATS0=0' &gt; dev/ttyS0 ... </code></pre> <p>but th...
35,268
1,581,090
2021-01-14 10:52:27
14,878,820
13
2013-02-14 15:57:44
521,034
2013-02-14 16:06:26
https://stackoverflow.com/q/14878684
https://stackoverflow.com/a/14878820
<p>If you install the PPP package you can use the <code>chat</code> program that comes with it. Or you can use <code>kermit</code>. Or the <code>cu</code> program that comes with uucp. But to do it with pure shell is trickier. You might be able to use the read and printf functions, with stdio redirected to the port. <...
<p>If you install the PPP package you can use the <code>chat</code> program that comes with it. Or you can use <code>kermit</code>. Or the <code>cu</code> program that comes with uucp. But to do it with pure shell is trickier. You might be able to use the read and printf functions, with stdio redirected to the port. <...
58, 387, 3716, 30895
at-command, bash, linux, serial-port
<h1>How to send a sequence of AT commands to a serial port in bash?</h1> <p>In Linux I need to send a sequence of AT commands to a serial port on e.g. <code>/dev/ttyS0</code>, which has to wait for an <code>OK</code> answer before the next command is sent. I could imagine doing something like</p> <pre><code>echo 'AT' ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,422
bash
# How to send a sequence of AT commands to a serial port in bash? In Linux I need to send a sequence of AT commands to a serial port on e.g. `/dev/ttyS0`, which has to wait for an `OK` answer before the next command is sent. I could imagine doing something like ``` echo 'AT' > /dev/ttyS0 echo 'ATS0=0' > dev/ttyS0 ......
If you install the PPP package you can use the `chat` program that comes with it. Or you can use `kermit`. Or the `cu` program that comes with uucp. But to do it with pure shell is trickier. You might be able to use the read and printf functions, with stdio redirected to the port. some snippet: ``` stty -F /dev/ttyS0...
14601430
How to run a c program in bash script and give it 2 arguments?
8
2013-01-30 10:13:23
<p>I have a program in C, which takes 2 arguments, filename and text. I want to write a script in bash, which also take 2 arguments, path and file extension, will iterate through all files in given path and give to my program in C as argument files with the givenextension only and text.</p> <p>Heres my program in C, n...
45,061
1,612,090
2013-01-30 10:15:57
14,601,483
13
2013-01-30 10:15:51
440,558
2013-01-30 10:15:51
https://stackoverflow.com/q/14601430
https://stackoverflow.com/a/14601483
<p>Right now you're not actually passing any arguments to the program in your script.</p> <p>Just pass the arguments normally:</p> <pre><code>./app "$file" "$text" </code></pre> <p>I put the arguments in double-quotes to make the shell see the variables as single arguments, in case they contain spaces.</p>
<p>Right now you're not actually passing any arguments to the program in your script.</p> <p>Just pass the arguments normally:</p> <pre><code>./app "$file" "$text" </code></pre> <p>I put the arguments in double-quotes to make the shell see the variables as single arguments, in case they contain spaces.</p>
8, 387, 390
bash, c, shell
<h1>How to run a c program in bash script and give it 2 arguments?</h1> <p>I have a program in C, which takes 2 arguments, filename and text. I want to write a script in bash, which also take 2 arguments, path and file extension, will iterate through all files in given path and give to my program in C as argument files...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,423
bash
# How to run a c program in bash script and give it 2 arguments? I have a program in C, which takes 2 arguments, filename and text. I want to write a script in bash, which also take 2 arguments, path and file extension, will iterate through all files in given path and give to my program in C as argument files with the...
Right now you're not actually passing any arguments to the program in your script. Just pass the arguments normally: ``` ./app "$file" "$text" ``` I put the arguments in double-quotes to make the shell see the variables as single arguments, in case they contain spaces.
14081799
CLI shell script code generation from compiled executable?
8
2012-12-29 12:43:01
<h1>Question, topic of discussion</h1> <p>I am very interested in generation of command line shell scripting source code from code written in a more robustness-promoting, well-performant and platform-independent compiled language (OCaml, for instance). Basically, you would program in a compiled language to perform any...
973
1,175,508
2016-03-24 11:38:02
14,084,654
13
2012-12-29 18:26:05
1,026,598
2012-12-29 18:55:40
https://stackoverflow.com/q/14081799
https://stackoverflow.com/a/14084654
<p>There are no Haskell libraries for this, but you can implement this using abstract syntax trees. I'll build up a simple toy example that builds an abstract language-independent syntax tree and then applies a back-end that converts the tree into the equivalent Bash script.</p> <p>I will use two tricks for modelli...
<p>There are no Haskell libraries for this, but you can implement this using abstract syntax trees. I'll build up a simple toy example that builds an abstract language-independent syntax tree and then applies a back-end that converts the tree into the equivalent Bash script.</p> <p>I will use two tricks for modelli...
390, 991, 1808, 1925, 12664
haskell, ocaml, robustness, scheme, shell
<h1>CLI shell script code generation from compiled executable?</h1> <h1>Question, topic of discussion</h1> <p>I am very interested in generation of command line shell scripting source code from code written in a more robustness-promoting, well-performant and platform-independent compiled language (OCaml, for instance)...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,424
bash
# CLI shell script code generation from compiled executable? # Question, topic of discussion I am very interested in generation of command line shell scripting source code from code written in a more robustness-promoting, well-performant and platform-independent compiled language (OCaml, for instance). Basically, you...
There are no Haskell libraries for this, but you can implement this using abstract syntax trees. I'll build up a simple toy example that builds an abstract language-independent syntax tree and then applies a back-end that converts the tree into the equivalent Bash script. I will use two tricks for modelling syntax tre...
12905180
How to Get SharePoint PowerShell to use .NET 2
8
2012-10-15 22:57:46
<p>I'm having a couple of problems with PowerShell. First, the PS configuration installed by SharePoint 2010 keeps popping this message: </p> <p>The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.</p> <p>I've googled that, and given everybody and their second cousin Sharepoint_Shell...
7,536
16,851
2016-10-25 14:33:33
12,906,632
13
2012-10-16 02:17:47
6,920
2012-10-16 02:48:31
https://stackoverflow.com/q/12905180
https://stackoverflow.com/a/12906632
<p>When you install powershell v3, version 2 is still available in side by side mode. In order to use the SharePoint snapin, you must launch v2 like this:</p> <pre><code>powershell -v 2 </code></pre> <p>Then you can load the snapin for SharePoint. </p> <p>For reference, here is the output from invoking PowerShell v2...
<p>When you install powershell v3, version 2 is still available in side by side mode. In order to use the SharePoint snapin, you must launch v2 like this:</p> <pre><code>powershell -v 2 </code></pre> <p>Then you can load the snapin for SharePoint. </p> <p>For reference, here is the output from invoking PowerShell v2...
526, 669, 3574
config, powershell, sharepoint
<h1>How to Get SharePoint PowerShell to use .NET 2</h1> <p>I'm having a couple of problems with PowerShell. First, the PS configuration installed by SharePoint 2010 keeps popping this message: </p> <p>The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.</p> <p>I've googled that, and ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,425
bash
# How to Get SharePoint PowerShell to use .NET 2 I'm having a couple of problems with PowerShell. First, the PS configuration installed by SharePoint 2010 keeps popping this message: The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. I've googled that, and given everybody and thei...
When you install powershell v3, version 2 is still available in side by side mode. In order to use the SharePoint snapin, you must launch v2 like this: ``` powershell -v 2 ``` Then you can load the snapin for SharePoint. For reference, here is the output from invoking PowerShell v2 from Windows 8 cmd.exe: ``` C:\Wi...
10987468
cursor blinking removal in terminal, how to?
8
2012-06-11 21:00:59
<p>I use the following lines to output my simulation's progress info in my c++ program,</p> <pre><code>double N=0; double percent=0; double total = 1000000; for (int i; i&lt;total; ++i) { percent = 100*i/total; printf("\r[%6.4f%%]",percent); } </code></pre> <p>It works fine!</p> <p>But the problem is I see t...
17,505
650,718
2021-12-28 19:50:26
10,988,079
13
2012-06-11 21:55:29
600,135
2012-06-11 22:25:17
https://stackoverflow.com/q/10987468
https://stackoverflow.com/a/10988079
<p>Just a guess: try to use a proper number of '\b' (backspace) characters instead of '\r'. </p> <p>== EDIT ==</p> <p>I'm not a Linux shell wizard, but this may work:</p> <pre><code>system("setterm -cursor off"); // ...display percentages... system("setterm -cursor on"); </code></pre> <p>Don't forget to <code>#incl...
<p>Just a guess: try to use a proper number of '\b' (backspace) characters instead of '\r'. </p> <p>== EDIT ==</p> <p>I'm not a Linux shell wizard, but this may work:</p> <pre><code>system("setterm -cursor off"); // ...display percentages... system("setterm -cursor on"); </code></pre> <p>Don't forget to <code>#incl...
10, 390, 391, 143847
c++, shell, terminal, text-cursor
<h1>cursor blinking removal in terminal, how to?</h1> <p>I use the following lines to output my simulation's progress info in my c++ program,</p> <pre><code>double N=0; double percent=0; double total = 1000000; for (int i; i&lt;total; ++i) { percent = 100*i/total; printf("\r[%6.4f%%]",percent); } </code></pre>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,426
bash
# cursor blinking removal in terminal, how to? I use the following lines to output my simulation's progress info in my c++ program, ``` double N=0; double percent=0; double total = 1000000; for (int i; i<total; ++i) { percent = 100*i/total; printf("\r[%6.4f%%]",percent); } ``` It works fine! But the problem...
Just a guess: try to use a proper number of '\b' (backspace) characters instead of '\r'. == EDIT == I'm not a Linux shell wizard, but this may work: ``` system("setterm -cursor off"); // ...display percentages... system("setterm -cursor on"); ``` Don't forget to `#include <cstdlib>` or `<iostream>`.
10472670
shell_exec not running in background?
8
2012-05-06 17:31:45
<p>I have the following which executes perfectly but NOT in the background as it should? It actually stops the page loading until it finishes which is not good.</p> <pre><code>shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &amp;"); </code></pre> <p>I also trie...
9,995
973,552
2020-05-12 08:25:53
10,473,110
13
2012-05-06 18:34:01
1,344,637
2020-05-12 08:25:53
https://stackoverflow.com/q/10472670
https://stackoverflow.com/a/10473110
<pre><code>exec(sprintf("%s &gt; %s 2&gt;&amp;1 &amp; echo $! &gt;&gt; %s", $cmd, $outputfile, $pidfile)); </code></pre> <p><a href="https://stackoverflow.com/questions/45953/php-execute-a-background-process">php execute a background process</a></p> <pre><code>exec("/usr/bin/php /path/background.php &gt; /dev/null 2&...
<pre><code>exec(sprintf("%s &gt; %s 2&gt;&amp;1 &amp; echo $! &gt;&gt; %s", $cmd, $outputfile, $pidfile)); </code></pre> <p><a href="https://stackoverflow.com/questions/45953/php-execute-a-background-process">php execute a background process</a></p> <pre><code>exec("/usr/bin/php /path/background.php &gt; /dev/null 2&...
5, 7932, 8646, 15292
background-process, exec, php, shell-exec
<h1>shell_exec not running in background?</h1> <p>I have the following which executes perfectly but NOT in the background as it should? It actually stops the page loading until it finishes which is not good.</p> <pre><code>shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$use...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,427
bash
# shell_exec not running in background? I have the following which executes perfectly but NOT in the background as it should? It actually stops the page loading until it finishes which is not good. ``` shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &"); ``` I...
``` exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile)); ``` [php execute a background process](https://stackoverflow.com/questions/45953/php-execute-a-background-process) ``` exec("/usr/bin/php /path/background.php > /dev/null 2>&1 &"); ```
9813141
How to list all binary file extensions within a directory tree?
8
2012-03-21 21:27:31
<p>I need to build a list of all the file extensions of binary files located within a directory tree. </p> <p>The main question would need to be how to distinguish a text file from a binary one, and the rest should be cake.</p> <p><strong>EDIT</strong>: This is the closest I got, any better ideas?</p> <pre><code>fin...
11,051
156,257
2015-06-01 22:26:05
9,818,717
13
2012-03-22 08:32:13
1,271,502
2012-03-22 08:32:13
https://stackoverflow.com/q/9813141
https://stackoverflow.com/a/9818717
<p>Here's a trick to find the binary files:</p> <pre><code>grep -r -m 1 "^" &lt;Your Root&gt; | grep "^Binary file" </code></pre> <p>The -m 1 makes grep not read all the file.</p>
<p>Here's a trick to find the binary files:</p> <pre><code>grep -r -m 1 "^" &lt;Your Root&gt; | grep "^Binary file" </code></pre> <p>The -m 1 makes grep not read all the file.</p>
58, 99, 387
bash, filesystems, linux
<h1>How to list all binary file extensions within a directory tree?</h1> <p>I need to build a list of all the file extensions of binary files located within a directory tree. </p> <p>The main question would need to be how to distinguish a text file from a binary one, and the rest should be cake.</p> <p><strong>EDIT</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,428
bash
# How to list all binary file extensions within a directory tree? I need to build a list of all the file extensions of binary files located within a directory tree. The main question would need to be how to distinguish a text file from a binary one, and the rest should be cake. **EDIT**: This is the closest I got, a...
Here's a trick to find the binary files: ``` grep -r -m 1 "^" <Your Root> | grep "^Binary file" ``` The -m 1 makes grep not read all the file.
8805647
How to update node.js and CoffeeScript version via terminal on mac?
8
2012-01-10 15:21:19
<p>My system node.js version is v0.6.1 but the current stable version is v0.6.7. My system CoffeeScript version is v1.1.2 but the current stable version is v1.2.0</p> <p>How could I update the node.js and CoffeeScript via terminal on mac( using mac )? I am pretty good with command line but I do need some help get st...
17,994
836,083
2014-02-05 08:30:07
8,806,011
13
2012-01-10 15:43:44
66,226
2013-10-15 22:49:24
https://stackoverflow.com/q/8805647
https://stackoverflow.com/a/8806011
<p>I'm a fan of Homebrew. Once you have it installed, you can just do</p> <pre><code>brew install node </code></pre> <p>then install npm with</p> <pre><code>curl http://npmjs.org/install.sh | sh </code></pre> <p>then use it to install CoffeeScript with</p> <pre><code>npm install -g coffee-script </code></pre> <p>...
<p>I'm a fan of Homebrew. Once you have it installed, you can just do</p> <pre><code>brew install node </code></pre> <p>then install npm with</p> <pre><code>curl http://npmjs.org/install.sh | sh </code></pre> <p>then use it to install CoffeeScript with</p> <pre><code>npm install -g coffee-script </code></pre> <p>...
387, 391, 46426, 57129
bash, coffeescript, node.js, terminal
<h1>How to update node.js and CoffeeScript version via terminal on mac?</h1> <p>My system node.js version is v0.6.1 but the current stable version is v0.6.7. My system CoffeeScript version is v1.1.2 but the current stable version is v1.2.0</p> <p>How could I update the node.js and CoffeeScript via terminal on mac( u...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,429
bash
# How to update node.js and CoffeeScript version via terminal on mac? My system node.js version is v0.6.1 but the current stable version is v0.6.7. My system CoffeeScript version is v1.1.2 but the current stable version is v1.2.0 How could I update the node.js and CoffeeScript via terminal on mac( using mac )? I am p...
I'm a fan of Homebrew. Once you have it installed, you can just do ``` brew install node ``` then install npm with ``` curl http://npmjs.org/install.sh | sh ``` then use it to install CoffeeScript with ``` npm install -g coffee-script ``` If you don't have Homebrew or don't want to bother with it, replace the fir...
8566704
Windows / Powershell version of the Unix 'which' Utility
8
2011-12-19 19:52:00
<p>The 'which' utility, when run with a parameter naming an executable, will tell you the first executable with that name it finds in your path, if found at all. This gives a good idea which version of the executable will be run. (Forgive me if this description is incomplete, but it conveys the general idea)</p> <p>I'...
941
3,805
2021-01-21 18:22:43
8,566,744
13
2011-12-19 19:55:26
995,351
2011-12-19 20:03:55
https://stackoverflow.com/q/8566704
https://stackoverflow.com/a/8566744
<p>You can use <code>Get-Command &lt;command&gt;</code>, or shorten it to <code>gcm</code>.</p>
<p>You can use <code>Get-Command &lt;command&gt;</code>, or shorten it to <code>gcm</code>.</p>
64, 526
powershell, windows
<h1>Windows / Powershell version of the Unix 'which' Utility</h1> <p>The 'which' utility, when run with a parameter naming an executable, will tell you the first executable with that name it finds in your path, if found at all. This gives a good idea which version of the executable will be run. (Forgive me if this desc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,430
bash
# Windows / Powershell version of the Unix 'which' Utility The 'which' utility, when run with a parameter naming an executable, will tell you the first executable with that name it finds in your path, if found at all. This gives a good idea which version of the executable will be run. (Forgive me if this description i...
You can use `Get-Command <command>`, or shorten it to `gcm`.
7528646
In bash, how can I have a set of arguments in any random order? Like a key-value pair?
8
2011-09-23 12:02:41
<p><strong>Example:</strong> </p> <pre><code>./myscript --ip 192.168.1.1 --port 1985 </code></pre> <p><strong>or another possible</strong></p> <pre><code>./myscript --port 1985 --ip 192.168.1.1 </code></pre> <p><strong>I want to allow my script to take a set of arguments, in any order</strong></p> <pre><code>./mys...
12,782
745,835
2018-01-25 03:58:33
7,528,700
13
2011-09-23 12:08:01
329,407
2011-09-23 12:08:01
https://stackoverflow.com/q/7528646
https://stackoverflow.com/a/7528700
<p>take a look at <a href="http://wiki.bash-hackers.org/howto/getopts_tutorial" rel="noreferrer"><code>getopts</code></a></p> <blockquote> <p><strong>getopts</strong>: getopts optstring name [arg]<br> Parse option arguments.</p> <p>Getopts is used by shell procedures to parse positional parameters as...
<p>take a look at <a href="http://wiki.bash-hackers.org/howto/getopts_tutorial" rel="noreferrer"><code>getopts</code></a></p> <blockquote> <p><strong>getopts</strong>: getopts optstring name [arg]<br> Parse option arguments.</p> <p>Getopts is used by shell procedures to parse positional parameters as...
387
bash
<h1>In bash, how can I have a set of arguments in any random order? Like a key-value pair?</h1> <p><strong>Example:</strong> </p> <pre><code>./myscript --ip 192.168.1.1 --port 1985 </code></pre> <p><strong>or another possible</strong></p> <pre><code>./myscript --port 1985 --ip 192.168.1.1 </code></pre> <p><strong>I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,431
bash
# In bash, how can I have a set of arguments in any random order? Like a key-value pair? **Example:** ``` ./myscript --ip 192.168.1.1 --port 1985 ``` **or another possible** ``` ./myscript --port 1985 --ip 192.168.1.1 ``` **I want to allow my script to take a set of arguments, in any order** ``` ./myscript a b c ...
take a look at [`getopts`](http://wiki.bash-hackers.org/howto/getopts_tutorial) > **getopts**: getopts optstring name [arg] > Parse option arguments. > > Getopts is used by shell procedures to parse positional parameters > as options. > > *`OPTSTRING`* contains the option letters to be recognized; if a letter > is f...
6844228
Passing arguments to octave function from within bash script
8
2011-07-27 12:24:10
<p>I wrote a function in Octave that takes in a line read from a file (one line at a time) as input argument. I use a bash script to read a line at a time from the file and then pass that as argument to the octave function from within the script. </p> <p>My bash script looks like so: </p> <pre><code>#!/bin/bash ...
13,188
350,685
2011-07-27 13:05:24
6,844,791
13
2011-07-27 13:05:24
7,552
2011-07-27 13:05:24
https://stackoverflow.com/q/6844228
https://stackoverflow.com/a/6844791
<p>The single quotes are preventing the shell from substituting the variable:</p> <pre><code>octave --silent --eval "myOctaveFunc(\"$line\")" </code></pre> <p>If octave lets you use single quotes to quote strings, it will look a little cleaner (inside double quotes, single quotes have no special meaning):</p> <pre><...
<p>The single quotes are preventing the shell from substituting the variable:</p> <pre><code>octave --silent --eval "myOctaveFunc(\"$line\")" </code></pre> <p>If octave lets you use single quotes to quote strings, it will look a little cleaner (inside double quotes, single quotes have no special meaning):</p> <pre><...
387, 531, 1231, 11891
bash, command-line, octave, scripting
<h1>Passing arguments to octave function from within bash script</h1> <p>I wrote a function in Octave that takes in a line read from a file (one line at a time) as input argument. I use a bash script to read a line at a time from the file and then pass that as argument to the octave function from within the script. </...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,432
bash
# Passing arguments to octave function from within bash script I wrote a function in Octave that takes in a line read from a file (one line at a time) as input argument. I use a bash script to read a line at a time from the file and then pass that as argument to the octave function from within the script. My bash scr...
The single quotes are preventing the shell from substituting the variable: ``` octave --silent --eval "myOctaveFunc(\"$line\")" ``` If octave lets you use single quotes to quote strings, it will look a little cleaner (inside double quotes, single quotes have no special meaning): ``` octave --silent --eval "myOctaveF...
6547408
Start external app with ShellExecuteEx and wait until it become initialized
8
2011-07-01 11:33:31
<p>I have an application which needs to run several other applications in chain. I am running them via <code>ShellExecuteEx</code>. The order of running each of the apps is very important cause they are dependant on each other. For example:</p> <pre><code>Start(App1); If App1.IsRunning then Start(App2); If App2.IsR...
3,876
110,603
2011-07-01 13:18:01
6,547,526
13
2011-07-01 11:44:57
505,088
2011-07-01 11:44:57
https://stackoverflow.com/q/6547408
https://stackoverflow.com/a/6547526
<p>You can probably achieve what you need by calling <a href="http://msdn.microsoft.com/en-us/library/ms687022%28v=VS.85%29.aspx" rel="noreferrer"><code>WaitForInputIdle()</code></a> on each process handle returned by <code>ShellExecute()</code>. </p> <blockquote> <p>Waits until the specified process has finished pr...
<p>You can probably achieve what you need by calling <a href="http://msdn.microsoft.com/en-us/library/ms687022%28v=VS.85%29.aspx" rel="noreferrer"><code>WaitForInputIdle()</code></a> on each process handle returned by <code>ShellExecute()</code>. </p> <blockquote> <p>Waits until the specified process has finished pr...
64, 118, 889, 48069
delphi, shellexecuteex, winapi, windows
<h1>Start external app with ShellExecuteEx and wait until it become initialized</h1> <p>I have an application which needs to run several other applications in chain. I am running them via <code>ShellExecuteEx</code>. The order of running each of the apps is very important cause they are dependant on each other. For exa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,433
bash
# Start external app with ShellExecuteEx and wait until it become initialized I have an application which needs to run several other applications in chain. I am running them via `ShellExecuteEx`. The order of running each of the apps is very important cause they are dependant on each other. For example: ``` Start(App...
You can probably achieve what you need by calling [`WaitForInputIdle()`](http://msdn.microsoft.com/en-us/library/ms687022%28v=VS.85%29.aspx) on each process handle returned by `ShellExecute()`. > Waits until the specified process has finished processing its initial input and is waiting for user input with no input pen...
6034054
How to Edit .csproj files with PowerShell - Visual Studio 2010
8
2011-05-17 16:27:14
<p>I need some help editing a csproj file using PowerShell. I basically need to select a node and alter it. </p> <p>Example:</p> <pre><code>&lt;None Include="T4\WebConfigSettingGeneratorScript.tt"&gt; &lt;Generator&gt;TextTemplatingFileGenerator&lt;/Generator&gt; &lt;LastGenOutput&gt;WebConfigSettingGeneratorScr...
6,618
441,862
2018-08-20 09:22:27
6,034,606
13
2011-05-17 17:17:44
153,982
2018-08-20 09:22:27
https://stackoverflow.com/q/6034054
https://stackoverflow.com/a/6034606
<p>I do this kind of thing a lot. I keep around a set of helper functions for manipulating XML files - particular C# project files. Try this out:</p> <pre><code>param($path) $MsbNS = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} function RemoveElement([xml]$Project, [string]$XPath, [switch]$SingleNod...
<p>I do this kind of thing a lot. I keep around a set of helper functions for manipulating XML files - particular C# project files. Try this out:</p> <pre><code>param($path) $MsbNS = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} function RemoveElement([xml]$Project, [string]$XPath, [switch]$SingleNod...
526, 14456
powershell, visual-studio-2010
<h1>How to Edit .csproj files with PowerShell - Visual Studio 2010</h1> <p>I need some help editing a csproj file using PowerShell. I basically need to select a node and alter it. </p> <p>Example:</p> <pre><code>&lt;None Include="T4\WebConfigSettingGeneratorScript.tt"&gt; &lt;Generator&gt;TextTemplatingFileGenerat...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,434
bash
# How to Edit .csproj files with PowerShell - Visual Studio 2010 I need some help editing a csproj file using PowerShell. I basically need to select a node and alter it. Example: ``` <None Include="T4\WebConfigSettingGeneratorScript.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>WebConfig...
I do this kind of thing a lot. I keep around a set of helper functions for manipulating XML files - particular C# project files. Try this out: ``` param($path) $MsbNS = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'} function RemoveElement([xml]$Project, [string]$XPath, [switch]$SingleNode) { $node...
5862396
Powershell Get-ChildItem progress question
8
2011-05-02 20:57:35
<p>So, I've got a set of directories 00-99 in a folder. Each of those directories has 100 subdirectories, 00-99. Each of those subdirectories has thousands of images.</p> <p>What I'm attempting to do is basically get a progress report while it's computing the average file size, but I can't get that to work. Here's my c...
12,064
148,004
2023-09-12 14:17:28
5,862,553
13
2011-05-02 21:12:55
526,535
2011-05-02 21:12:55
https://stackoverflow.com/q/5862396
https://stackoverflow.com/a/5862553
<p>Something like this?</p> <pre><code>get-childitem -recurse -filter *.exe | %{Write-Host Examining file: $_.fullname; $_} | measure-object -Property length -Average </code></pre>
<p>Something like this?</p> <pre><code>get-childitem -recurse -filter *.exe | %{Write-Host Examining file: $_.fullname; $_} | measure-object -Property length -Average </code></pre>
526, 598, 2844, 7060, 29006
get-childitem, performance, pipeline, powershell, progress
<h1>Powershell Get-ChildItem progress question</h1> <p>So, I've got a set of directories 00-99 in a folder. Each of those directories has 100 subdirectories, 00-99. Each of those subdirectories has thousands of images.</p> <p>What I'm attempting to do is basically get a progress report while it's computing the average ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,435
bash
# Powershell Get-ChildItem progress question So, I've got a set of directories 00-99 in a folder. Each of those directories has 100 subdirectories, 00-99. Each of those subdirectories has thousands of images. What I'm attempting to do is basically get a progress report while it's computing the average file size, but ...
Something like this? ``` get-childitem -recurse -filter *.exe | %{Write-Host Examining file: $_.fullname; $_} | measure-object -Property length -Average ```
5521112
Using RVM in eshell of Emacs
8
2011-04-02 04:16:14
<p>Using RVM in eshell of emacs, I am not able to set the ruby version. Why? Environment : Ubuntu 9.10</p> <pre><code>/media/Work/rubyworkspace $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] /media/Work/rubyworkspace $ rvm use 1.9.2 Using /usr/local/rvm/gems/ruby-1.9.2-p180 /media/Work/rubyworkspace $ ...
1,801
178,975
2012-03-10 15:40:14
5,521,368
13
2011-04-02 05:27:23
229,602
2011-04-02 05:27:23
https://stackoverflow.com/q/5521112
https://stackoverflow.com/a/5521368
<p>As far as I can tell, RVM relies on the shell being a "regular" UNIX shell. Selection of the correct interpreter etc. is done using shell variables and these don't apply to eshell which has it's own way of configuring stuff. </p> <p>One solution is to use <kbd>M</kbd>-<kbd>X</kbd> <code>term</code> and then use a r...
<p>As far as I can tell, RVM relies on the shell being a "regular" UNIX shell. Selection of the correct interpreter etc. is done using shell variables and these don't apply to eshell which has it's own way of configuring stuff. </p> <p>One solution is to use <kbd>M</kbd>-<kbd>X</kbd> <code>term</code> and then use a r...
12, 371, 549, 32732, 46495
emacs, eshell, ruby, rvm, ubuntu
<h1>Using RVM in eshell of Emacs</h1> <p>Using RVM in eshell of emacs, I am not able to set the ruby version. Why? Environment : Ubuntu 9.10</p> <pre><code>/media/Work/rubyworkspace $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] /media/Work/rubyworkspace $ rvm use 1.9.2 Using /usr/local/rvm/gems/ruby-1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,436
bash
# Using RVM in eshell of Emacs Using RVM in eshell of emacs, I am not able to set the ruby version. Why? Environment : Ubuntu 9.10 ``` /media/Work/rubyworkspace $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] /media/Work/rubyworkspace $ rvm use 1.9.2 Using /usr/local/rvm/gems/ruby-1.9.2-p180 /media/Wor...
As far as I can tell, RVM relies on the shell being a "regular" UNIX shell. Selection of the correct interpreter etc. is done using shell variables and these don't apply to eshell which has it's own way of configuring stuff. One solution is to use `M`-`X` `term` and then use a regular shell inside that. The other is t...
5142729
grep for expression containing variable
8
2011-02-28 13:43:04
<p>I want to add this command <strong>grep -co '\b5\b' $INFILE</strong> in a bash script. The problem is that instead of 5 i want to use a variable in its place so i write:</p> <pre><code>V=`grep -co '\b$L\b' $INFILE` </code></pre> <p>but it does not work since the $ is used to describe internally the end of line in ...
5,634
466,825
2022-06-01 17:31:41
5,142,743
13
2011-02-28 13:44:12
616,700
2015-07-29 13:24:00
https://stackoverflow.com/q/5142729
https://stackoverflow.com/a/5142743
<p>Use <code>"</code> instead of <code>'</code> to allow expansion of your <code>$L</code> variable.</p>
<p>Use <code>"</code> instead of <code>'</code> to allow expansion of your <code>$L</code> variable.</p>
387
bash
<h1>grep for expression containing variable</h1> <p>I want to add this command <strong>grep -co '\b5\b' $INFILE</strong> in a bash script. The problem is that instead of 5 i want to use a variable in its place so i write:</p> <pre><code>V=`grep -co '\b$L\b' $INFILE` </code></pre> <p>but it does not work since the $ i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,437
bash
# grep for expression containing variable I want to add this command **grep -co '\b5\b' $INFILE** in a bash script. The problem is that instead of 5 i want to use a variable in its place so i write: ``` V=`grep -co '\b$L\b' $INFILE` ``` but it does not work since the $ is used to describe internally the end of line ...
Use `"` instead of `'` to allow expansion of your `$L` variable.
4569149
Bash: How to escape $@?
8
2010-12-31 09:07:52
<p>I need to write a bash script that, among other things, should pass all its arguments intact to another program.</p> <p>Minimal example:</p> <pre> $ cat >proxy.sh #!/bin/bash ./script.sh $@ ^D $ chmod +x proxy.sh $ cat >script.sh #!/bin/bash echo one $1 echo two $2 echo three $3 ^D $ chmod +x script.sh <...
2,279
6,236
2012-02-14 19:00:48
4,569,168
13
2010-12-31 09:11:24
89,806
2010-12-31 09:11:24
https://stackoverflow.com/q/4569149
https://stackoverflow.com/a/4569168
<p>Quote <code>$@</code>, making it <code>"$@"</code>:</p> <pre><code>$ cat &gt;proxy.sh #!/bin/bash ./script.sh "$@" ^D </code></pre> <p>Then it retains the original quotes:</p> <pre><code>one a b two c three </code></pre>
<p>Quote <code>$@</code>, making it <code>"$@"</code>:</p> <pre><code>$ cat &gt;proxy.sh #!/bin/bash ./script.sh "$@" ^D </code></pre> <p>Then it retains the original quotes:</p> <pre><code>one a b two c three </code></pre>
387, 4804, 31134
bash, command-line-arguments, escaping
<h1>Bash: How to escape $@?</h1> <p>I need to write a bash script that, among other things, should pass all its arguments intact to another program.</p> <p>Minimal example:</p> <pre> $ cat >proxy.sh #!/bin/bash ./script.sh $@ ^D $ chmod +x proxy.sh $ cat >script.sh #!/bin/bash echo one $1 echo two $2 echo thre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,438
bash
# Bash: How to escape $@? I need to write a bash script that, among other things, should pass all its arguments intact to another program. Minimal example: ``` $ cat >proxy.sh #!/bin/bash ./script.sh $@ ^D $ chmod +x proxy.sh $ cat >script.sh #!/bin/bash echo one $1 echo two $2 echo three $3 ^D $ chmod +x s...
Quote `$@`, making it `"$@"`: ``` $ cat >proxy.sh #!/bin/bash ./script.sh "$@" ^D ``` Then it retains the original quotes: ``` one a b two c three ```
4467376
how to passing arguments to an alias
8
2010-12-17 03:22:51
<p>i add an alias in .bashrc</p> <p>alias sr='sudo /etc/rc.d/[parameter?] restart'</p> <p>sr network -> sudo /etc/rc.d/network restart</p> <p>sr sshd -> sudo /etc/rc.d/sshd restart</p> <p>could it be achieved, thanks!</p>
7,037
538,888
2018-10-16 03:50:01
4,467,413
13
2010-12-17 03:31:28
90,848
2010-12-17 03:31:28
https://stackoverflow.com/q/4467376
https://stackoverflow.com/a/4467413
<p>Use a shell function instead. eg:</p> <pre><code>function sr () { sudo /etc/rc.d/"$1" restart } </code></pre>
<p>Use a shell function instead. eg:</p> <pre><code>function sr () { sudo /etc/rc.d/"$1" restart } </code></pre>
387, 1448
alias, bash
<h1>how to passing arguments to an alias</h1> <p>i add an alias in .bashrc</p> <p>alias sr='sudo /etc/rc.d/[parameter?] restart'</p> <p>sr network -> sudo /etc/rc.d/network restart</p> <p>sr sshd -> sudo /etc/rc.d/sshd restart</p> <p>could it be achieved, thanks!</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,439
bash
# how to passing arguments to an alias i add an alias in .bashrc alias sr='sudo /etc/rc.d/[parameter?] restart' sr network -> sudo /etc/rc.d/network restart sr sshd -> sudo /etc/rc.d/sshd restart could it be achieved, thanks!
Use a shell function instead. eg: ``` function sr () { sudo /etc/rc.d/"$1" restart } ```
3075227
sequentially executing background processes unix
8
2010-06-19 10:53:37
<p>I have two scripts say 'S1' and 'S2'. I execute these scripts as,</p> <blockquote> <p>nohup S1 &amp; </p> <p>nohup S2 &amp;</p> </blockquote> <p>But I would like them to execute sequentially. ie., S2 should execute only on successful completion of S1. How should I go about doing this?. How can I know when S...
5,029
368,995
2010-06-19 11:32:07
3,075,234
13
2010-06-19 10:56:46
303,180
2010-06-19 11:32:07
https://stackoverflow.com/q/3075227
https://stackoverflow.com/a/3075234
<p>You can execute them, sequentially, like this:</p> <pre><code>(nohup S1 &amp;&amp; nohup S2) &amp; </code></pre> <p>Try</p> <pre><code>(echo 1 &amp;&amp; sleep 1 &amp;&amp; echo 2) &amp; </code></pre> <p>The <a href="http://www.devshed.com/c/a/BrainDump/Better-Command-Execution-with-bash/" rel="noreferrer">doubl...
<p>You can execute them, sequentially, like this:</p> <pre><code>(nohup S1 &amp;&amp; nohup S2) &amp; </code></pre> <p>Try</p> <pre><code>(echo 1 &amp;&amp; sleep 1 &amp;&amp; echo 2) &amp; </code></pre> <p>The <a href="http://www.devshed.com/c/a/BrainDump/Better-Command-Execution-with-bash/" rel="noreferrer">doubl...
34, 58, 390, 989, 15292
aix, background-process, linux, shell, unix
<h1>sequentially executing background processes unix</h1> <p>I have two scripts say 'S1' and 'S2'. I execute these scripts as,</p> <blockquote> <p>nohup S1 &amp; </p> <p>nohup S2 &amp;</p> </blockquote> <p>But I would like them to execute sequentially. ie., S2 should execute only on successful completion of S1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,440
bash
# sequentially executing background processes unix I have two scripts say 'S1' and 'S2'. I execute these scripts as, > nohup S1 & > > nohup S2 & But I would like them to execute sequentially. ie., S2 should execute only on successful completion of S1. How should I go about doing this?. How can I know when S1 finishe...
You can execute them, sequentially, like this: ``` (nohup S1 && nohup S2) & ``` Try ``` (echo 1 && sleep 1 && echo 2) & ``` The [double ampersand operator is described here](http://www.devshed.com/c/a/BrainDump/Better-Command-Execution-with-bash/). Note that when using `&&`, `S2` only runs if `S1` finishes "succes...
2902874
Input encoding : accepting UTF-8
8
2010-05-25 07:47:40
<p>I need to get output of native application under PowerShell. The problem is, output is encoded with UTF-8 (no BOM), which PowerShell does not recognize and just converts those funky UTF chars directly into Unicode.</p> <p>I've found PowerShell has <code>$OutputEncoding</code> variable, but it does not seem to affec...
6,555
199,621
2010-05-26 06:55:51
2,905,884
13
2010-05-25 15:04:01
153,982
2010-05-25 20:01:45
https://stackoverflow.com/q/2902874
https://stackoverflow.com/a/2905884
<p>I see the issue now with the program below (stdout.cpp - cl stdout.cpp):</p> <pre><code>#include &lt;stdio.h&gt; void main() { char bytes[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0xE1, 0xBE, 0xB9}; for (i...
<p>I see the issue now with the program below (stdout.cpp - cl stdout.cpp):</p> <pre><code>#include &lt;stdio.h&gt; void main() { char bytes[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0xE1, 0xBE, 0xB9}; for (i...
526, 1124
encoding, powershell
<h1>Input encoding : accepting UTF-8</h1> <p>I need to get output of native application under PowerShell. The problem is, output is encoded with UTF-8 (no BOM), which PowerShell does not recognize and just converts those funky UTF chars directly into Unicode.</p> <p>I've found PowerShell has <code>$OutputEncoding</cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,441
bash
# Input encoding : accepting UTF-8 I need to get output of native application under PowerShell. The problem is, output is encoded with UTF-8 (no BOM), which PowerShell does not recognize and just converts those funky UTF chars directly into Unicode. I've found PowerShell has `$OutputEncoding` variable, but it does no...
I see the issue now with the program below (stdout.cpp - cl stdout.cpp): ``` #include <stdio.h> void main() { char bytes[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0xE1, 0xBE, 0xB9}; for (int i = 0; i < 15; i+...
2587709
Automatically execute commands on launching python shell
8
2010-04-06 19:36:09
<p>I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. I would like to automatically import some modules so I don't have to type the whole shebang everytime I hop into the shell.</p> <p>Thanks, </p>
961
278,205
2010-04-07 17:09:33
2,587,733
13
2010-04-06 19:39:01
9,453
2010-04-06 19:39:01
https://stackoverflow.com/q/2587709
https://stackoverflow.com/a/2587733
<p>Yup you can use the <code>PYTHONSTARTUP</code> environment variable to do this as outlined <a href="http://docs.python.org/tutorial/interpreter.html#the-interactive-startup-file" rel="noreferrer">here</a></p>
<p>Yup you can use the <code>PYTHONSTARTUP</code> environment variable to do this as outlined <a href="http://docs.python.org/tutorial/interpreter.html#the-interactive-startup-file" rel="noreferrer">here</a></p>
16, 390
python, shell
<h1>Automatically execute commands on launching python shell</h1> <p>I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. I would like to automatically import some modules so I don't have to type the whole shebang...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,442
bash
# Automatically execute commands on launching python shell I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. I would like to automatically import some modules so I don't have to type the whole shebang everytim...
Yup you can use the `PYTHONSTARTUP` environment variable to do this as outlined [here](http://docs.python.org/tutorial/interpreter.html#the-interactive-startup-file)
2439948
Better way to make a bash script self-tracing?
8
2010-03-13 20:40:46
<p>I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I am currently doing:</p> <pre><code>#!/bin/bash # if last...
2,256
14,028
2013-09-27 17:04:56
2,440,092
13
2010-03-13 21:27:39
99,692
2010-03-13 21:27:39
https://stackoverflow.com/q/2439948
https://stackoverflow.com/a/2440092
<pre><code>#!/bin/bash exec &gt;&gt;log_file 2&gt;&amp;1 echo Hello world date </code></pre> <p><code>exec</code> has a magic behavior regarding redirections: “If <em>command</em> is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the ...
<pre><code>#!/bin/bash exec &gt;&gt;log_file 2&gt;&amp;1 echo Hello world date </code></pre> <p><code>exec</code> has a magic behavior regarding redirections: “If <em>command</em> is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the ...
387, 942, 1441
bash, logging, trace
<h1>Better way to make a bash script self-tracing?</h1> <p>I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,443
bash
# Better way to make a bash script self-tracing? I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I am current...
``` #!/bin/bash exec >>log_file 2>&1 echo Hello world date ``` `exec` has a magic behavior regarding redirections: “If *command* is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1.” Also, regarding your original sol...
2435386
read the contents of a directory using shell script
8
2010-03-12 19:47:17
<p>I'm trying to get the contents of a directory using shell script.</p> <p>My script is:</p> <pre><code>for entry in `ls`; do echo $entry done </code></pre> <p>However, my current directory contains many files with whitespaces in their names. In that case, this script fails.</p> <p>What is the correct way to l...
24,712
2,119,053
2013-10-31 08:28:39
2,435,393
13
2010-03-12 19:48:43
20,862
2010-03-12 19:48:43
https://stackoverflow.com/q/2435386
https://stackoverflow.com/a/2435393
<pre><code>for entry in * do echo "$entry" done </code></pre>
<pre><code>for entry in * do echo "$entry" done </code></pre>
390, 9873
directory-listing, shell
<h1>read the contents of a directory using shell script</h1> <p>I'm trying to get the contents of a directory using shell script.</p> <p>My script is:</p> <pre><code>for entry in `ls`; do echo $entry done </code></pre> <p>However, my current directory contains many files with whitespaces in their names. In that ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,444
bash
# read the contents of a directory using shell script I'm trying to get the contents of a directory using shell script. My script is: ``` for entry in `ls`; do echo $entry done ``` However, my current directory contains many files with whitespaces in their names. In that case, this script fails. What is the co...
``` for entry in * do echo "$entry" done ```
2426993
Run a batch file every x number of seconds using PowerShell
8
2010-03-11 16:59:31
<p>I'd like to use a windows PowerShell script to run a batch file every x number of seconds. So it's the same batch file being run over and over again.</p> <p>I've done some looking, but can't find what I'm looking for. It's for something that I want to run on a Windows&nbsp;XP machine. I've used Windows Scheduler a...
14,632
102,312
2014-11-10 22:38:13
2,427,246
13
2010-03-11 17:35:16
153,982
2010-03-11 17:35:16
https://stackoverflow.com/q/2426993
https://stackoverflow.com/a/2427246
<p>Just put the call to the batch file in a while loop e.g.:</p> <pre><code>$period = [timespan]::FromSeconds(45) $lastRunTime = [DateTime]::MinValue while (1) { # If the next period isn't here yet, sleep so we don't consume CPU while ((Get-Date) - $lastRunTime -lt $period) { Start-Sleep -Millisecond...
<p>Just put the call to the batch file in a while loop e.g.:</p> <pre><code>$period = [timespan]::FromSeconds(45) $lastRunTime = [DateTime]::MinValue while (1) { # If the next period isn't here yet, sleep so we don't consume CPU while ((Get-Date) - $lastRunTime -lt $period) { Start-Sleep -Millisecond...
64, 526
powershell, windows
<h1>Run a batch file every x number of seconds using PowerShell</h1> <p>I'd like to use a windows PowerShell script to run a batch file every x number of seconds. So it's the same batch file being run over and over again.</p> <p>I've done some looking, but can't find what I'm looking for. It's for something that I wa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,445
bash
# Run a batch file every x number of seconds using PowerShell I'd like to use a windows PowerShell script to run a batch file every x number of seconds. So it's the same batch file being run over and over again. I've done some looking, but can't find what I'm looking for. It's for something that I want to run on a Wi...
Just put the call to the batch file in a while loop e.g.: ``` $period = [timespan]::FromSeconds(45) $lastRunTime = [DateTime]::MinValue while (1) { # If the next period isn't here yet, sleep so we don't consume CPU while ((Get-Date) - $lastRunTime -lt $period) { Start-Sleep -Milliseconds 500 } ...
2102852
What is the PowerShell equivalent to this grep+xargs command?
8
2010-01-20 16:13:53
<p>I'm trying to create a <a href="http://en.wikipedia.org/wiki/Command-line_interface" rel="nofollow noreferrer">CLI</a> command to have <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server" rel="nofollow noreferrer">TFS</a> check out all files that have a particular string in them. I primarily use <a href="ht...
10,187
1,409
2025-07-24 11:52:51
2,102,917
13
2010-01-20 16:21:33
153,982
2015-05-28 08:48:38
https://stackoverflow.com/q/2102852
https://stackoverflow.com/a/2102917
<p>Using some UNIX aliases in PowerShell (like ls):</p> <pre><code>ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path} </code></pre> <p>or in a more canonical Powershell form:</p> <pre><code>Get-ChildItem -Recurse | Select-String 'SomeSearchString' | Foreach {tf edit $_.Path} </code></pre> <p>...
<p>Using some UNIX aliases in PowerShell (like ls):</p> <pre><code>ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path} </code></pre> <p>or in a more canonical Powershell form:</p> <pre><code>Get-ChildItem -Recurse | Select-String 'SomeSearchString' | Foreach {tf edit $_.Path} </code></pre> <p>...
526, 1271, 10326
grep, powershell, xargs
<h1>What is the PowerShell equivalent to this grep+xargs command?</h1> <p>I'm trying to create a <a href="http://en.wikipedia.org/wiki/Command-line_interface" rel="nofollow noreferrer">CLI</a> command to have <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server" rel="nofollow noreferrer">TFS</a> check out all f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,446
bash
# What is the PowerShell equivalent to this grep+xargs command? I'm trying to create a [CLI](http://en.wikipedia.org/wiki/Command-line_interface) command to have [TFS](http://en.wikipedia.org/wiki/Team_Foundation_Server) check out all files that have a particular string in them. I primarily use [Cygwin](http://en.wiki...
Using some UNIX aliases in PowerShell (like ls): ``` ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path} ``` or in a more canonical Powershell form: ``` Get-ChildItem -Recurse | Select-String 'SomeSearchString' | Foreach {tf edit $_.Path} ``` and using PowerShell aliases: ``` gci -r | sls 'So...
2057631
Must PowerShell scripts be called using only a single line?
8
2010-01-13 15:09:38
<p>I have some PowerShell scripts that accept many long parameters, like,</p> <pre><code>myScript.ps1 -completePathToFile "C:\...\...\...\file.txt" -completePathForOutput "C:\...\...\...\output.log" -recipients ("me@me.com") -etc. </code></pre> <p>I can't seem to make PowerShell run such scripts unless all the parame...
4,863
52,225
2010-01-13 17:31:28
2,057,670
13
2010-01-13 15:14:13
153,982
2010-01-13 17:31:28
https://stackoverflow.com/q/2057631
https://stackoverflow.com/a/2057670
<p>PowerShell thinks the command is complete at the end of the line unless it sees certain characters like a pipe, open paren or open curly. Just put a line continuation character `` ` at the end of each line but make sure there are no spaces after that continuation character:</p> <pre><code>myScript.ps1 ` -complet...
<p>PowerShell thinks the command is complete at the end of the line unless it sees certain characters like a pipe, open paren or open curly. Just put a line continuation character `` ` at the end of each line but make sure there are no spaces after that continuation character:</p> <pre><code>myScript.ps1 ` -complet...
360, 526, 1231
command-line, parameters, powershell
<h1>Must PowerShell scripts be called using only a single line?</h1> <p>I have some PowerShell scripts that accept many long parameters, like,</p> <pre><code>myScript.ps1 -completePathToFile "C:\...\...\...\file.txt" -completePathForOutput "C:\...\...\...\output.log" -recipients ("me@me.com") -etc. </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
10,447
bash
# Must PowerShell scripts be called using only a single line? I have some PowerShell scripts that accept many long parameters, like, ``` myScript.ps1 -completePathToFile "C:\...\...\...\file.txt" -completePathForOutput "C:\...\...\...\output.log" -recipients ("me@me.com") -etc. ``` I can't seem to make PowerShell ru...
PowerShell thinks the command is complete at the end of the line unless it sees certain characters like a pipe, open paren or open curly. Just put a line continuation character `` ` at the end of each line but make sure there are no spaces after that continuation character: ``` myScript.ps1 ` -completePathToFile "C:...
1608506
Powershell script to enable 'IIS Management Scripts and Tools'
8
2009-10-22 16:45:24
<p>After looking around (for not terribly long I have to admit) I wonder if anyone can point me to a Powershell script that checks if 'IIS Management Scripts and Tools' is enabled and if its not then it enables it like you would from Add Windows features.</p> <p>I checked poshcode.org and powershell.com and couldnt fi...
18,404
162,325
2010-01-22 16:34:24
1,612,561
13
2009-10-23 10:23:54
26,478
2009-10-23 10:23:54
https://stackoverflow.com/q/1608506
https://stackoverflow.com/a/1612561
<p>Would that be for Windows 2008 or Windows Server 2008 R2?</p> <p>Server 2008R2:</p> <p>-To query:</p> <pre><code>PS&gt; get-windowsfeature|where{$_.name -eq "Web-Scripting-Tools"} Display Name Name ------------ ---- [X]...
<p>Would that be for Windows 2008 or Windows Server 2008 R2?</p> <p>Server 2008R2:</p> <p>-To query:</p> <pre><code>PS&gt; get-windowsfeature|where{$_.name -eq "Web-Scripting-Tools"} Display Name Name ------------ ---- [X]...
487, 526, 34595
build-automation, powershell, windows-7
<h1>Powershell script to enable 'IIS Management Scripts and Tools'</h1> <p>After looking around (for not terribly long I have to admit) I wonder if anyone can point me to a Powershell script that checks if 'IIS Management Scripts and Tools' is enabled and if its not then it enables it like you would from Add Windows fe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,448
bash
# Powershell script to enable 'IIS Management Scripts and Tools' After looking around (for not terribly long I have to admit) I wonder if anyone can point me to a Powershell script that checks if 'IIS Management Scripts and Tools' is enabled and if its not then it enables it like you would from Add Windows features. ...
Would that be for Windows 2008 or Windows Server 2008 R2? Server 2008R2: -To query: ``` PS> get-windowsfeature|where{$_.name -eq "Web-Scripting-Tools"} Display Name Name ------------ ---- [X] IIS Management Scripts and Too...
157342
bash script runs from shell but not from cron job
8
2008-10-01 12:32:13
<p>Cron installation is vixie-cron</p> <p><code>/etc/cron.daily/rmspam.cron</code></p> <pre><code>#!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; </code></pre> <p>I Have this simple bash script that I want to add to a cron job (also includes spam learning commands before) but this part always fails with "Fil...
10,404
4,275
2011-01-18 12:19:56
157,369
13
2008-10-01 12:38:11
7,256
2008-10-12 06:24:41
https://stackoverflow.com/q/157342
https://stackoverflow.com/a/157369
<p>If there are no files in the directory, then the wildcard will not be expanded and will be passed to the command directly. There is no file called "*", and then the command fails with "File or directory not found." Try this instead:</p> <pre><code>if [ -f /home/user/Maildir/.SPAM/cur/* ]; then rm /home/user/M...
<p>If there are no files in the directory, then the wildcard will not be expanded and will be passed to the command directly. There is no file called "*", and then the command fails with "File or directory not found." Try this instead:</p> <pre><code>if [ -f /home/user/Maildir/.SPAM/cur/* ]; then rm /home/user/M...
58, 387, 601
bash, cron, linux
<h1>bash script runs from shell but not from cron job</h1> <p>Cron installation is vixie-cron</p> <p><code>/etc/cron.daily/rmspam.cron</code></p> <pre><code>#!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; </code></pre> <p>I Have this simple bash script that I want to add to a cron job (also includes spam lea...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,449
bash
# bash script runs from shell but not from cron job Cron installation is vixie-cron `/etc/cron.daily/rmspam.cron` ``` #!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; ``` I Have this simple bash script that I want to add to a cron job (also includes spam learning commands before) but this part always fails w...
If there are no files in the directory, then the wildcard will not be expanded and will be passed to the command directly. There is no file called "*", and then the command fails with "File or directory not found." Try this instead: ``` if [ -f /home/user/Maildir/.SPAM/cur/* ]; then rm /home/user/Maildir/.SPAM/cur...
50312
Get CPU usage in shell script?
8
2008-09-08 18:05:34
<p>I'm running some <a href="http://jakarta.apache.org/jmeter/" rel="noreferrer">JMeter</a> tests against a Java process to determine how responsive a web application is under load (500+ users). JMeter will give the response time for each web request, and I've written a script to ping the Tomcat Manager every X seconds...
30,237
4,249
2021-01-28 13:19:18
50,334
13
2008-09-08 18:21:06
3,279
2008-09-08 18:21:06
https://stackoverflow.com/q/50312
https://stackoverflow.com/a/50334
<p>Use <code>top -b</code> (and other switches if you want different outputs). It will just dump to stdout instead of jumping into a curses window.</p>
<p>Use <code>top -b</code> (and other switches if you want different outputs). It will just dump to stdout instead of jumping into a curses window.</p>
58, 390, 531
linux, scripting, shell
<h1>Get CPU usage in shell script?</h1> <p>I'm running some <a href="http://jakarta.apache.org/jmeter/" rel="noreferrer">JMeter</a> tests against a Java process to determine how responsive a web application is under load (500+ users). JMeter will give the response time for each web request, and I've written a script to...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,450
bash
# Get CPU usage in shell script? I'm running some [JMeter](http://jakarta.apache.org/jmeter/) tests against a Java process to determine how responsive a web application is under load (500+ users). JMeter will give the response time for each web request, and I've written a script to ping the Tomcat Manager every X seco...
Use `top -b` (and other switches if you want different outputs). It will just dump to stdout instead of jumping into a curses window.
66924725
How to exit from powershell function from function's statements
7
2021-04-02 20:11:38
<p>I expect that the return from the function statement (<code>begin</code>, <code>process</code>, <code>end</code>) should also terminate all its statements, but this does not happen.</p> <p>I have a test function like this:</p> <pre><code>function test($a) { begin { Write-Host 'begin ' -NoNewline ...
10,213
11,469,204
2024-01-23 16:18:00
66,924,946
13
2021-04-02 20:34:48
45,375
2024-01-23 16:18:00
https://stackoverflow.com/q/66924725
https://stackoverflow.com/a/66924946
<p>Your function is an <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Functions_Advanced" rel="noreferrer"><em>advanced</em></a> function, and therefore uses <code>begin</code>, <code>process</code> and <code>end</code> blocks.</p> <p>In a <em>simple</em> (non-advance...
<p>Your function is an <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Functions_Advanced" rel="noreferrer"><em>advanced</em></a> function, and therefore uses <code>begin</code>, <code>process</code> and <code>end</code> blocks.</p> <p>In a <em>simple</em> (non-advance...
526
powershell
<h1>How to exit from powershell function from function's statements</h1> <p>I expect that the return from the function statement (<code>begin</code>, <code>process</code>, <code>end</code>) should also terminate all its statements, but this does not happen.</p> <p>I have a test function like this:</p> <pre><code>functi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,451
bash
# How to exit from powershell function from function's statements I expect that the return from the function statement (`begin`, `process`, `end`) should also terminate all its statements, but this does not happen. I have a test function like this: ``` function test($a) { begin { Write-Host 'begin ' -No...
Your function is an [*advanced*](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Functions_Advanced) function, and therefore uses `begin`, `process` and `end` blocks. In a *simple* (non-advanced) function, in the *absence* of such blocks, `return` would indeed instantly exit t...
62036686
How can I remove the "SC2154" warning for environment variables
7
2020-05-27 06:23:47
<p>How can I remove shellcheck's warning "SC2154" when linting the shell script?</p> <pre><code>#!/bin/bash set -euo pipefail IFS=$'\n\t' echo "proxy=$http_proxy" | sudo tee -a /etc/test.txt </code></pre> <p>The warning is "SC2154: http_proxy is referenced but not assigned." </p> <p>EDIT: I want to write the envir...
5,867
5,580,578
2025-07-09 07:21:43
62,036,949
13
2020-05-27 06:42:59
6,770,384
2023-07-18 08:29:56
https://stackoverflow.com/q/62036686
https://stackoverflow.com/a/62036949
<p><sub>In general, the better solution would be to stick to the convention and name <em>your</em> environment variables in ALL_CAPS. However, in this case I understand that <code>http_proxy</code> is not <em>your</em> environment variable, but is dictated by programs like <code>curl</code>, <code>wget</code>, and so o...
<p><sub>In general, the better solution would be to stick to the convention and name <em>your</em> environment variables in ALL_CAPS. However, in this case I understand that <code>http_proxy</code> is not <em>your</em> environment variable, but is dictated by programs like <code>curl</code>, <code>wget</code>, and so o...
387, 390, 3452, 117067
bash, lint, shell, shellcheck
<h1>How can I remove the "SC2154" warning for environment variables</h1> <p>How can I remove shellcheck's warning "SC2154" when linting the shell script?</p> <pre><code>#!/bin/bash set -euo pipefail IFS=$'\n\t' echo "proxy=$http_proxy" | sudo tee -a /etc/test.txt </code></pre> <p>The warning is "SC2154: http_proxy i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,452
bash
# How can I remove the "SC2154" warning for environment variables How can I remove shellcheck's warning "SC2154" when linting the shell script? ``` #!/bin/bash set -euo pipefail IFS=$'\n\t' echo "proxy=$http_proxy" | sudo tee -a /etc/test.txt ``` The warning is "SC2154: http_proxy is referenced but not assigned." ...
In general, the better solution would be to stick to the convention and name *your* environment variables in ALL_CAPS. However, in this case I understand that `http_proxy` is not *your* environment variable, but is dictated by programs like `curl`, `wget`, and so on, so you cannot simply rename it. --- You can [suppr...
58574397
How can I change the PowerShell prompt to show just the parent directory and current directory?
7
2019-10-26 20:18:43
<p>I would like to shorten my PowerShell prompt so that it just shows the parent directory and the current directory. For example, if the pwd is</p> <pre><code>C:\Users\ndunn\OneDrive\Documents\Webucator\ClassFiles\python-basics\Demos </code></pre> <p>I want the prompt to be:</p> <pre><code>PS ..\python-basics\Demos...
4,600
5,128,561
2025-11-23 19:13:07
58,575,183
13
2019-10-26 22:23:43
45,375
2025-11-23 19:13:07
https://stackoverflow.com/q/58574397
https://stackoverflow.com/a/58575183
<p>Try the following function, which should work on Windows and Unix-like platforms (in PowerShell <em>Core</em>) alike:</p> <pre><code>function global:prompt { $dirSep = [IO.Path]::DirectorySeparatorChar $pathComponents = $PWD.Path.Split($dirSep) $displayPath = if ($pathComponents.Count -le 3) { $PWD.Path ...
<p>Try the following function, which should work on Windows and Unix-like platforms (in PowerShell <em>Core</em>) alike:</p> <pre><code>function global:prompt { $dirSep = [IO.Path]::DirectorySeparatorChar $pathComponents = $PWD.Path.Split($dirSep) $displayPath = if ($pathComponents.Count -le 3) { $PWD.Path ...
526, 9938
command-prompt, powershell
<h1>How can I change the PowerShell prompt to show just the parent directory and current directory?</h1> <p>I would like to shorten my PowerShell prompt so that it just shows the parent directory and the current directory. For example, if the pwd is</p> <pre><code>C:\Users\ndunn\OneDrive\Documents\Webucator\ClassFiles...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,453
bash
# How can I change the PowerShell prompt to show just the parent directory and current directory? I would like to shorten my PowerShell prompt so that it just shows the parent directory and the current directory. For example, if the pwd is ``` C:\Users\ndunn\OneDrive\Documents\Webucator\ClassFiles\python-basics\Demos...
Try the following function, which should work on Windows and Unix-like platforms (in PowerShell *Core*) alike: ``` function global:prompt { $dirSep = [IO.Path]::DirectorySeparatorChar $pathComponents = $PWD.Path.Split($dirSep) $displayPath = if ($pathComponents.Count -le 3) { $PWD.Path } else { '…{0}{1...
54131197
Find files with non-printing characters (null bytes)
7
2019-01-10 14:49:29
<p>I have got the log of my application with a field that contains strange characters. I see these characters only when I use <code>less</code> command.</p> <p>I tried to copy the result of my line of code in a text file and what I see is </p> <pre><code>CTP_OUT=^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^...
11,846
7,193,776
2024-10-07 18:11:40
54,133,873
13
2019-01-10 17:20:23
8,344,060
2024-10-07 18:11:40
https://stackoverflow.com/q/54131197
https://stackoverflow.com/a/54133873
<p>I hardly believe it, I might write an answer involving <code>cat</code>!</p> <p>The characters you are observing are <em>non-printable</em> characters which are often written in <a href="https://en.wikipedia.org/wiki/Caret_notation" rel="nofollow noreferrer">Caret notation</a>. The Caret notation of a character is a...
<p>I hardly believe it, I might write an answer involving <code>cat</code>!</p> <p>The characters you are observing are <em>non-printable</em> characters which are often written in <a href="https://en.wikipedia.org/wiki/Caret_notation" rel="nofollow noreferrer">Caret notation</a>. The Caret notation of a character is a...
34, 58, 387, 1271
bash, grep, linux, unix
<h1>Find files with non-printing characters (null bytes)</h1> <p>I have got the log of my application with a field that contains strange characters. I see these characters only when I use <code>less</code> command.</p> <p>I tried to copy the result of my line of code in a text file and what I see is </p> <pre><code>C...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,454
bash
# Find files with non-printing characters (null bytes) I have got the log of my application with a field that contains strange characters. I see these characters only when I use `less` command. I tried to copy the result of my line of code in a text file and what I see is ``` CTP_OUT=^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@...
I hardly believe it, I might write an answer involving `cat`! The characters you are observing are *non-printable* characters which are often written in [Caret notation](https://en.wikipedia.org/wiki/Caret_notation). The Caret notation of a character is a way to visualize non-printable characters. As mentioned in the ...
53544617
How can I bypass execution policy when running scripts from Powershell ISE
7
2018-11-29 17:33:26
<p>So I can write a script in Powershell ISE, not save it, and it will run (F5/green arrow on the ISE). Once I save it, I get the error saying I can't run saved scripts. If I open a Powershell window in the directory the saved script exists, I can run it with</p> <p><code>powershell -ExecutionPolicy ByPass -File scrip...
14,376
2,868,510
2021-02-02 09:22:57
53,544,848
13
2018-11-29 17:48:18
2,868,510
2018-11-29 17:48:18
https://stackoverflow.com/q/53544617
https://stackoverflow.com/a/53544848
<p>Ok so I just found out you can set Execution Policy for yourself (current user) without having admin rights. So if you're coming here from google do this:</p> <p><code>Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"</code></p>
<p>Ok so I just found out you can set Execution Policy for yourself (current user) without having admin rights. So if you're coming here from google do this:</p> <p><code>Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"</code></p>
526
powershell
<h1>How can I bypass execution policy when running scripts from Powershell ISE</h1> <p>So I can write a script in Powershell ISE, not save it, and it will run (F5/green arrow on the ISE). Once I save it, I get the error saying I can't run saved scripts. If I open a Powershell window in the directory the saved script ex...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,455
bash
# How can I bypass execution policy when running scripts from Powershell ISE So I can write a script in Powershell ISE, not save it, and it will run (F5/green arrow on the ISE). Once I save it, I get the error saying I can't run saved scripts. If I open a Powershell window in the directory the saved script exists, I c...
Ok so I just found out you can set Execution Policy for yourself (current user) without having admin rights. So if you're coming here from google do this: `Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"`
53303222
Powershell Script to run exe file with parameters
7
2018-11-14 15:06:21
<p>I need script to run exe file with parameters. That's what I wrote, if there's a better way to do it?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$Command = "\\Networ...
21,964
10,646,087
2021-10-19 15:05:08
53,304,607
13
2018-11-14 16:20:09
8,188,846
2021-10-19 15:05:08
https://stackoverflow.com/q/53303222
https://stackoverflow.com/a/53304607
<p>You have a couple options when running an external executable.</p> <hr /> <h1><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1" rel="noreferrer">Splatting</a></h1> <pre><code>$command = '\\netpath\restart.exe' $params = '/t:21600', '/m:3...
<p>You have a couple options when running an external executable.</p> <hr /> <h1><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1" rel="noreferrer">Splatting</a></h1> <pre><code>$command = '\\netpath\restart.exe' $params = '/t:21600', '/m:3...
64, 526, 531, 3727
exe, powershell, scripting, windows
<h1>Powershell Script to run exe file with parameters</h1> <p>I need script to run exe file with parameters. That's what I wrote, if there's a better way to do it?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,456
bash
# Powershell Script to run exe file with parameters I need script to run exe file with parameters. That's what I wrote, if there's a better way to do it? ``` $Command = "\\Networkpath\Restart.exe" $Parms = "/t:21600 /m:360 /r /f" $Prms = $Parms.Split(" ") & "$Command" $Prms ``` thanks
You have a couple options when running an external executable. --- # [Splatting](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1) ``` $command = '\\netpath\restart.exe' $params = '/t:21600', '/m:360', '/r', '/f' & $command @params ``` This meth...
52787180
Parse value from JSON when key contains dot (period) in Powershell
7
2018-10-12 21:24:53
<p><a href="https://i.sstatic.net/79dRd.jpg" rel="noreferrer"><img src="https://i.sstatic.net/79dRd.jpg" alt="enter image description here"></a></p> <p>In the above example, I would like to get the value "Bug" from "System.WorkItemType"</p> <p>using </p> <pre><code>$response = Invoke-RestMethod -Url $someUri -Method...
6,998
1,611,821
2018-10-13 01:58:33
52,787,376
13
2018-10-12 21:46:24
4,991,132
2018-10-13 01:58:33
https://stackoverflow.com/q/52787180
https://stackoverflow.com/a/52787376
<p>If you put the property names in <code>""</code> or <code>''</code>, you should be able to get what you are looking for: </p> <pre><code>$json= @' { "id" : 9983, "rev" : 17, "fields" :{ "System.AreaPath":"Cloud\\Dev Blue Team", "System.TeamProject":"Cloud" } } '@ $j = $Json | convertfrom-json ...
<p>If you put the property names in <code>""</code> or <code>''</code>, you should be able to get what you are looking for: </p> <pre><code>$json= @' { "id" : 9983, "rev" : 17, "fields" :{ "System.AreaPath":"Cloud\\Dev Blue Team", "System.TeamProject":"Cloud" } } '@ $j = $Json | convertfrom-json ...
526, 1508, 30161
json, jsonpath, powershell
<h1>Parse value from JSON when key contains dot (period) in Powershell</h1> <p><a href="https://i.sstatic.net/79dRd.jpg" rel="noreferrer"><img src="https://i.sstatic.net/79dRd.jpg" alt="enter image description here"></a></p> <p>In the above example, I would like to get the value "Bug" from "System.WorkItemType"</p> <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,457
bash
# Parse value from JSON when key contains dot (period) in Powershell [![enter image description here](https://i.sstatic.net/79dRd.jpg)](https://i.sstatic.net/79dRd.jpg) In the above example, I would like to get the value "Bug" from "System.WorkItemType" using ``` $response = Invoke-RestMethod -Url $someUri -Method ...
If you put the property names in `""` or `''`, you should be able to get what you are looking for: ``` $json= @' { "id" : 9983, "rev" : 17, "fields" :{ "System.AreaPath":"Cloud\\Dev Blue Team", "System.TeamProject":"Cloud" } } '@ $j = $Json | convertfrom-json $j.fields."System.AreaPath" $J.fields...
52374260
bash variable changes in loop with ffmpeg
7
2018-09-17 19:05:26
<p>I wrote a skript to quickly create short preview clips from vides I recorded on timestamps that I found worth checking out later for cutting. My file with the timestamps is written like this</p> <pre><code>FILE_NAME1#MM:SS MM:SS FILE_NAME2#MM:SS MM:SS MM:SS MM:SS </code></pre> <p>example:</p> <pre><code>MAH01728...
1,548
2,470,901
2018-09-17 19:19:04
52,374,405
13
2018-09-17 19:19:04
1,126,841
2018-09-17 19:19:04
https://stackoverflow.com/q/52374260
https://stackoverflow.com/a/52374405
<p><code>ffmpeg</code> reads from standard input, consuming data from <code>$1</code> that was intended for the <code>read</code> command at the top of the loop. Redirect its standard input from <code>/dev/null</code>:</p> <pre><code>while IFS="#" read file timestamps; do filename="$file.MP4" for time in $timestam...
<p><code>ffmpeg</code> reads from standard input, consuming data from <code>$1</code> that was intended for the <code>read</code> command at the top of the loop. Redirect its standard input from <code>/dev/null</code>:</p> <pre><code>while IFS="#" read file timestamps; do filename="$file.MP4" for time in $timestam...
387, 2314, 3847
bash, ffmpeg, loops
<h1>bash variable changes in loop with ffmpeg</h1> <p>I wrote a skript to quickly create short preview clips from vides I recorded on timestamps that I found worth checking out later for cutting. My file with the timestamps is written like this</p> <pre><code>FILE_NAME1#MM:SS MM:SS FILE_NAME2#MM:SS MM:SS MM:SS MM:SS ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,458
bash
# bash variable changes in loop with ffmpeg I wrote a skript to quickly create short preview clips from vides I recorded on timestamps that I found worth checking out later for cutting. My file with the timestamps is written like this ``` FILE_NAME1#MM:SS MM:SS FILE_NAME2#MM:SS MM:SS MM:SS MM:SS ``` example: ``` MA...
`ffmpeg` reads from standard input, consuming data from `$1` that was intended for the `read` command at the top of the loop. Redirect its standard input from `/dev/null`: ``` while IFS="#" read file timestamps; do filename="$file.MP4" for time in $timestamps; do ffmpeg -ss 00:${time}.0 -i "orig/${filename}" \...
49399984
Parsing .ini file in bash
7
2018-03-21 06:53:19
<p>I have a below properties file and would like to parse it as mentioned below. Please help in doing this.</p> <p>.ini file which I created :</p> <pre><code>[Machine1] app=version1 [Machine2] app=version1 app=version2 [Machine3] app=version1 app=version3 </code></pre> <p>I am looking for a solution in which ...
12,290
8,000,076
2024-02-27 17:11:40
49,400,353
13
2018-03-21 07:17:25
3,030,305
2018-03-21 07:48:52
https://stackoverflow.com/q/49399984
https://stackoverflow.com/a/49400353
<p>Try:</p> <pre><code>$ awk '/\[/{prefix=$0; next} $1{print prefix $0}' file.ini [Machine1]app=version1 [Machine2]app=version1 [Machine2]app=version2 [Machine3]app=version1 [Machine3]app=version3 </code></pre> <p>How it works</p> <ul> <li><p><code>/\[/{prefix=$0; next}</code></p> <p>If any line begins with <code>[...
<p>Try:</p> <pre><code>$ awk '/\[/{prefix=$0; next} $1{print prefix $0}' file.ini [Machine1]app=version1 [Machine2]app=version1 [Machine2]app=version2 [Machine3]app=version1 [Machine3]app=version3 </code></pre> <p>How it works</p> <ul> <li><p><code>/\[/{prefix=$0; next}</code></p> <p>If any line begins with <code>[...
387, 996
bash, ini
<h1>Parsing .ini file in bash</h1> <p>I have a below properties file and would like to parse it as mentioned below. Please help in doing this.</p> <p>.ini file which I created :</p> <pre><code>[Machine1] app=version1 [Machine2] app=version1 app=version2 [Machine3] app=version1 app=version3 </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
10,459
bash
# Parsing .ini file in bash I have a below properties file and would like to parse it as mentioned below. Please help in doing this. .ini file which I created : ``` [Machine1] app=version1 [Machine2] app=version1 app=version2 [Machine3] app=version1 app=version3 ``` I am looking for a solution in which ini f...
Try: ``` $ awk '/\[/{prefix=$0; next} $1{print prefix $0}' file.ini [Machine1]app=version1 [Machine2]app=version1 [Machine2]app=version2 [Machine3]app=version1 [Machine3]app=version3 ``` How it works - `/\[/{prefix=$0; next}` If any line begins with `[`, we save the line in the variable `prefix` and then we skip ...
48322960
How to convert a string to a stream object in Powershell?
7
2018-01-18 13:52:32
<p>I want to make a string fit for consumption as a stream, by e.g. <code>Get-FileHash</code> command (using its <code>-InputStream</code> parameter).</p> <p>The reason I want this is that I need to digest a string, and not contents of a file. I do not want to temporarily store said string in a file just to digest it.<...
9,985
254,343
2022-10-07 10:12:51
48,323,225
13
2018-01-18 14:08:27
6,579,295
2018-01-18 14:08:27
https://stackoverflow.com/q/48322960
https://stackoverflow.com/a/48323225
<p>You can use some .NET functions:</p> <pre><code>$stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes("Quick brown fox jumps over the lazy dog.")) Get-FileHash -InputStream $stream -Algorithm SHA512 </code></pre>
<p>You can use some .NET functions:</p> <pre><code>$stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes("Quick brown fox jumps over the lazy dog.")) Get-FileHash -InputStream $stream -Algorithm SHA512 </code></pre>
526
powershell
<h1>How to convert a string to a stream object in Powershell?</h1> <p>I want to make a string fit for consumption as a stream, by e.g. <code>Get-FileHash</code> command (using its <code>-InputStream</code> parameter).</p> <p>The reason I want this is that I need to digest a string, and not contents of a file. I do not ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,460
bash
# How to convert a string to a stream object in Powershell? I want to make a string fit for consumption as a stream, by e.g. `Get-FileHash` command (using its `-InputStream` parameter). The reason I want this is that I need to digest a string, and not contents of a file. I do not want to temporarily store said string...
You can use some .NET functions: ``` $stream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes("Quick brown fox jumps over the lazy dog.")) Get-FileHash -InputStream $stream -Algorithm SHA512 ```
46400234
Encrypt String with the Machine Key in Powershell?
7
2017-09-25 08:00:55
<p>I want to Encrypt a password in Powershell to save it to a file. The <code>ConvertTo-SecureString</code> uses the current credentials to encrypt and decrypt the string.</p> <p>I want to encrypt it with the local machine key (probably the SYSTEM account credentials) so every username on the same computer will be abl...
4,272
288,280
2017-09-25 17:28:13
46,400,268
13
2017-09-25 08:02:49
288,280
2017-09-25 08:02:49
https://stackoverflow.com/q/46400234
https://stackoverflow.com/a/46400268
<p>It's possible to use the <code>[Security.Cryptography.ProtectedData]::Protect</code> function along with <code>[Security.Cryptography.DataProtectionScope]::LocalMachine</code> as the entity.</p> <p>Code example:</p> <pre><code>Function Encrypt-WithMachineKey($s) { Add-Type -AssemblyName System.Security $b...
<p>It's possible to use the <code>[Security.Cryptography.ProtectedData]::Protect</code> function along with <code>[Security.Cryptography.DataProtectionScope]::LocalMachine</code> as the entity.</p> <p>Code example:</p> <pre><code>Function Encrypt-WithMachineKey($s) { Add-Type -AssemblyName System.Security $b...
526, 2387, 33800, 108010
cryptography, password-encryption, powershell, powershell-5.0
<h1>Encrypt String with the Machine Key in Powershell?</h1> <p>I want to Encrypt a password in Powershell to save it to a file. The <code>ConvertTo-SecureString</code> uses the current credentials to encrypt and decrypt the string.</p> <p>I want to encrypt it with the local machine key (probably the SYSTEM account cre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,461
bash
# Encrypt String with the Machine Key in Powershell? I want to Encrypt a password in Powershell to save it to a file. The `ConvertTo-SecureString` uses the current credentials to encrypt and decrypt the string. I want to encrypt it with the local machine key (probably the SYSTEM account credentials) so every username...
It's possible to use the `[Security.Cryptography.ProtectedData]::Protect` function along with `[Security.Cryptography.DataProtectionScope]::LocalMachine` as the entity. Code example: ``` Function Encrypt-WithMachineKey($s) { Add-Type -AssemblyName System.Security $bytes = [System.Text.Encoding]::Unicode.GetB...
45744569
how to handle bash with multiple arguments for multiple options
7
2017-08-17 20:37:34
<p>I need to download chart data from poloniex rest client with multiple options using bash only. I tried getopts but couldn't really find a way to use mutliple options with multiple parameters.</p> <p>here is what I want to achieve</p> <pre><code>./getdata.sh -c currency1 currency2 ... -p period1 period2 ... </code...
38,984
944,768
2017-08-17 23:59:48
45,744,742
13
2017-08-17 20:49:19
5,395,709
2017-08-17 23:59:48
https://stackoverflow.com/q/45744569
https://stackoverflow.com/a/45744742
<p>Could something like this work for you?</p> <pre><code>#!/bin/bash while getopts ":a:p:" opt; do case $opt in a) arg1="$OPTARG" ;; p) arg2="$OPTARG" ;; \?) echo "Invalid option -$OPTARG" &gt;&amp;2 ;; esac done printf "Argument 1 is %s\n" "$arg1" printf "Argument 2 is %s\n" "$arg2" </c...
<p>Could something like this work for you?</p> <pre><code>#!/bin/bash while getopts ":a:p:" opt; do case $opt in a) arg1="$OPTARG" ;; p) arg2="$OPTARG" ;; \?) echo "Invalid option -$OPTARG" &gt;&amp;2 ;; esac done printf "Argument 1 is %s\n" "$arg1" printf "Argument 2 is %s\n" "$arg2" </c...
58, 369, 387, 120795
bash, linux, macos, poloniex
<h1>how to handle bash with multiple arguments for multiple options</h1> <p>I need to download chart data from poloniex rest client with multiple options using bash only. I tried getopts but couldn't really find a way to use mutliple options with multiple parameters.</p> <p>here is what I want to achieve</p> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,462
bash
# how to handle bash with multiple arguments for multiple options I need to download chart data from poloniex rest client with multiple options using bash only. I tried getopts but couldn't really find a way to use mutliple options with multiple parameters. here is what I want to achieve ``` ./getdata.sh -c currency...
Could something like this work for you? ``` #!/bin/bash while getopts ":a:p:" opt; do case $opt in a) arg1="$OPTARG" ;; p) arg2="$OPTARG" ;; \?) echo "Invalid option -$OPTARG" >&2 ;; esac done printf "Argument 1 is %s\n" "$arg1" printf "Argument 2 is %s\n" "$arg2" ``` You can then call y...
45350837
cut : use "/" as a delimiter
7
2017-07-27 12:28:24
<p>I am trying to use the cut command in my bash script. I need to get the name of a rpm package containing 'sys' in its name, without its full path. So I tried this:</p> <pre><code>packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d "\/" -f 3) </code></pre> <p>I thought this way could return the package...
9,943
8,343,342
2019-05-17 22:14:31
45,350,955
13
2017-07-27 12:33:49
1,030,675
2017-07-27 12:33:49
https://stackoverflow.com/q/45350837
https://stackoverflow.com/a/45350955
<p><code>"\/"</code> doesn't expand to <code>/</code>, so <code>cut</code> complains:</p> <pre><code>cut: the delimiter must be a single character </code></pre> <p>Use plain <code>/</code> instead:</p> <pre><code>packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d/ -f3) </code></pre>
<p><code>"\/"</code> doesn't expand to <code>/</code>, so <code>cut</code> complains:</p> <pre><code>cut: the delimiter must be a single character </code></pre> <p>Use plain <code>/</code> instead:</p> <pre><code>packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d/ -f3) </code></pre>
387, 4257
bash, cut
<h1>cut : use "/" as a delimiter</h1> <p>I am trying to use the cut command in my bash script. I need to get the name of a rpm package containing 'sys' in its name, without its full path. So I tried this:</p> <pre><code>packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d "\/" -f 3) </code></pre> <p>I tho...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,463
bash
# cut : use "/" as a delimiter I am trying to use the cut command in my bash script. I need to get the name of a rpm package containing 'sys' in its name, without its full path. So I tried this: ``` packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d "\/" -f 3) ``` I thought this way could return the pa...
`"\/"` doesn't expand to `/`, so `cut` complains: ``` cut: the delimiter must be a single character ``` Use plain `/` instead: ``` packageName=$(find temp/noarch/ -name '*sys*noarch.rpm' | cut -d/ -f3) ```
44034124
Escaping slash "\" in grep
7
2017-05-17 20:21:25
<p>I have file with line: </p> <pre><code>"H:\Check\WP_20140511_029.mp4" </code></pre> <p>along with other lines. I want to remove such lines indicating directory at <code>H:\Check</code>. I tried</p> <pre><code>grep -v ".*H:\\Check.*" testout.txt &gt; testout2.txt </code></pre> <p>But it did not delete those lines...
18,995
1,317,018
2017-05-20 07:39:07
44,034,170
13
2017-05-17 20:25:15
548,225
2017-05-17 20:35:35
https://stackoverflow.com/q/44034124
https://stackoverflow.com/a/44034170
<p>You can use:</p> <pre><code>grep -v 'H:\\Check' testout.txt &gt; testout2.txt </code></pre> <p>It is important to use single quotes to avoid excessive escaping of backslash.</p> <p>Using double quotes equivalent command will be this:</p> <pre><code>grep -v "H:\\\Check" testout.txt &gt; testout2.txt </code></pre>...
<p>You can use:</p> <pre><code>grep -v 'H:\\Check' testout.txt &gt; testout2.txt </code></pre> <p>It is important to use single quotes to avoid excessive escaping of backslash.</p> <p>Using double quotes equivalent command will be this:</p> <pre><code>grep -v "H:\\\Check" testout.txt &gt; testout2.txt </code></pre>...
18, 58, 387, 390, 1271
bash, grep, linux, regex, shell
<h1>Escaping slash "\" in grep</h1> <p>I have file with line: </p> <pre><code>"H:\Check\WP_20140511_029.mp4" </code></pre> <p>along with other lines. I want to remove such lines indicating directory at <code>H:\Check</code>. I tried</p> <pre><code>grep -v ".*H:\\Check.*" testout.txt &gt; testout2.txt </code></pre> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,464
bash
# Escaping slash "\" in grep I have file with line: ``` "H:\Check\WP_20140511_029.mp4" ``` along with other lines. I want to remove such lines indicating directory at `H:\Check`. I tried ``` grep -v ".*H:\\Check.*" testout.txt > testout2.txt ``` But it did not delete those lines. Whats wrong with my regex `.*H:\\C...
You can use: ``` grep -v 'H:\\Check' testout.txt > testout2.txt ``` It is important to use single quotes to avoid excessive escaping of backslash. Using double quotes equivalent command will be this: ``` grep -v "H:\\\Check" testout.txt > testout2.txt ``` --- **EDIT:** `\\` in double quotes is equivalent of a si...
43413203
How to pass all but the first argument to a second bash script?
7
2017-04-14 14:07:37
<p>I'm trying to write a bash script that executes another bash script with all but the first argument, so I can't use: </p> <blockquote> <p>bash abc.sh "$@"</p> </blockquote> <p>because it will also pass the first argument which I don't want. How can i remove the first argument?</p>
1,943
7,867,665
2017-04-14 14:20:28
43,413,218
13
2017-04-14 14:08:27
1,084,774
2017-04-14 14:20:28
https://stackoverflow.com/q/43413203
https://stackoverflow.com/a/43413218
<p>You can remove the first argument with a <code>shift</code>:</p> <pre><code>shift #same as: shift 1 bash abc.sh "$@" </code></pre> <p>(In <code>bash</code>, <code>ksh</code>, and <code>zsh</code>, you can also use <code>"${@:2}"</code> without modifying the <code>"$@"</code> array, but <code>shift</code> will work...
<p>You can remove the first argument with a <code>shift</code>:</p> <pre><code>shift #same as: shift 1 bash abc.sh "$@" </code></pre> <p>(In <code>bash</code>, <code>ksh</code>, and <code>zsh</code>, you can also use <code>"${@:2}"</code> without modifying the <code>"$@"</code> array, but <code>shift</code> will work...
387
bash
<h1>How to pass all but the first argument to a second bash script?</h1> <p>I'm trying to write a bash script that executes another bash script with all but the first argument, so I can't use: </p> <blockquote> <p>bash abc.sh "$@"</p> </blockquote> <p>because it will also pass the first argument which I don't want....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,465
bash
# How to pass all but the first argument to a second bash script? I'm trying to write a bash script that executes another bash script with all but the first argument, so I can't use: > bash abc.sh "$@" because it will also pass the first argument which I don't want. How can i remove the first argument?
You can remove the first argument with a `shift`: ``` shift #same as: shift 1 bash abc.sh "$@" ``` (In `bash`, `ksh`, and `zsh`, you can also use `"${@:2}"` without modifying the `"$@"` array, but `shift` will work in any POSIX shell.)
41871596
Why isn't tilde (~) expanding inside double quotes?
7
2017-01-26 10:38:09
<p>I want to check whether or not the hidden <code>.git</code> folder exists. First thought was to use:</p> <pre><code>if [ -d "~/.git" ]; then echo "Do stuff" fi </code></pre> <p>But the <code>-d</code> apparently does not look for hidden folders.</p>
1,554
4,342,608
2023-01-17 20:52:29
41,871,651
13
2017-01-26 10:41:03
1,983,854
2023-01-17 20:52:29
https://stackoverflow.com/q/41871596
https://stackoverflow.com/a/41871651
<p>The problem has to do with the tilde being within double quotes.</p> <p>To get it expanded, you need to put the tilde outside the quotes:</p> <pre><code>if [ -d ~/&quot;.git&quot; ]; then # note tilde outside double quotes! echo &quot;Do stuff&quot; fi </code></pre> <p>Or, alternatively, as commented below by h...
<p>The problem has to do with the tilde being within double quotes.</p> <p>To get it expanded, you need to put the tilde outside the quotes:</p> <pre><code>if [ -d ~/&quot;.git&quot; ]; then # note tilde outside double quotes! echo &quot;Do stuff&quot; fi </code></pre> <p>Or, alternatively, as commented below by h...
387, 40596, 63342
bash, double-quotes, tilde-expansion
<h1>Why isn't tilde (~) expanding inside double quotes?</h1> <p>I want to check whether or not the hidden <code>.git</code> folder exists. First thought was to use:</p> <pre><code>if [ -d "~/.git" ]; then echo "Do stuff" fi </code></pre> <p>But the <code>-d</code> apparently does not look for hidden folders.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,466
bash
# Why isn't tilde (~) expanding inside double quotes? I want to check whether or not the hidden `.git` folder exists. First thought was to use: ``` if [ -d "~/.git" ]; then echo "Do stuff" fi ``` But the `-d` apparently does not look for hidden folders.
The problem has to do with the tilde being within double quotes. To get it expanded, you need to put the tilde outside the quotes: ``` if [ -d ~/".git" ]; then # note tilde outside double quotes! echo "Do stuff" fi ``` Or, alternatively, as commented below by hek2mgl, use `$HOME` instead of `~`: ``` if [ -d "$...
41179883
"Are you sure?" via a messagebox in powershell
7
2016-12-16 08:08:58
<p>Goodmorning developers,</p> <p>I am trying to make a delete function in powershell. I want to have something like this:</p> <pre><code> function deleteEnv(){ $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?''Yes', 'No' 'Info') if(yes){ //Delete } else { //do nothing } } </code></pre>...
15,271
6,280,280
2024-02-26 09:44:16
41,179,942
13
2016-12-16 08:14:08
6,067,741
2016-12-16 08:14:08
https://stackoverflow.com/q/41179883
https://stackoverflow.com/a/41179942
<pre><code>[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?' , "Info" , 4) if ($result -eq 'Yes') { do stuff } </code></pre> <p>Additional reading: <a href="http://powershell-tips.blogspot.com.by/2012/02/display-messagebox-wi...
<pre><code>[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?' , "Info" , 4) if ($result -eq 'Yes') { do stuff } </code></pre> <p>Additional reading: <a href="http://powershell-tips.blogspot.com.by/2012/02/display-messagebox-wi...
49, 526, 1117
forms, powershell, xaml
<h1>"Are you sure?" via a messagebox in powershell</h1> <p>Goodmorning developers,</p> <p>I am trying to make a delete function in powershell. I want to have something like this:</p> <pre><code> function deleteEnv(){ $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?''Yes', 'No' 'Info') if(yes)...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,467
bash
# "Are you sure?" via a messagebox in powershell Goodmorning developers, I am trying to make a delete function in powershell. I want to have something like this: ``` function deleteEnv(){ $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?''Yes', 'No' 'Info') if(yes){ //Delete } else { /...
``` [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $result = [System.Windows.Forms.MessageBox]::Show('Are you sure?' , "Info" , 4) if ($result -eq 'Yes') { do stuff } ``` Additional reading: <http://powershell-tips.blogspot.com.by/2012/02/display-messagebox-with-powershell.html>
38469234
How to Source all powershell scripts from a directory
7
2016-07-19 21:59:23
<p>Can not dot source all PowerShell scripts from directory tried:</p> <pre><code>. .\*.ps1 </code></pre> <p>Returns this:</p> <pre><code>&gt; : The term '.\*.ps1' is not recognized as the name of a cmdlet, &gt; function, script file, or operable program. Check the spelling of the &gt; name, or if a path was includ...
6,734
1,179,340
2018-06-25 20:05:17
38,469,310
13
2016-07-19 22:06:14
712,649
2018-06-25 20:05:17
https://stackoverflow.com/q/38469234
https://stackoverflow.com/a/38469310
<p>Use <code>Get-ChildItem</code> to grab all <code>*.ps1</code> files, then loop through them with <code>ForEach-Object</code> and dot-source them individually</p> <pre><code>$Path = "C:\Scripts\Directory" Get-ChildItem -Path $Path -Filter *.ps1 |ForEach-Object { . $_.FullName } </code></pre> <hr> <p>If you put...
<p>Use <code>Get-ChildItem</code> to grab all <code>*.ps1</code> files, then loop through them with <code>ForEach-Object</code> and dot-source them individually</p> <pre><code>$Path = "C:\Scripts\Directory" Get-ChildItem -Path $Path -Filter *.ps1 |ForEach-Object { . $_.FullName } </code></pre> <hr> <p>If you put...
526
powershell
<h1>How to Source all powershell scripts from a directory</h1> <p>Can not dot source all PowerShell scripts from directory tried:</p> <pre><code>. .\*.ps1 </code></pre> <p>Returns this:</p> <pre><code>&gt; : The term '.\*.ps1' is not recognized as the name of a cmdlet, &gt; function, script file, or operable progra...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,468
bash
# How to Source all powershell scripts from a directory Can not dot source all PowerShell scripts from directory tried: ``` . .\*.ps1 ``` Returns this: ``` > : The term '.\*.ps1' is not recognized as the name of a cmdlet, > function, script file, or operable program. Check the spelling of the > name, or if a path ...
Use `Get-ChildItem` to grab all `*.ps1` files, then loop through them with `ForEach-Object` and dot-source them individually ``` $Path = "C:\Scripts\Directory" Get-ChildItem -Path $Path -Filter *.ps1 |ForEach-Object { . $_.FullName } ``` --- If you put the above in a script, and the script itself is located in `...
38316422
How to capture actual response code and response body with HTTPie in bash script?
7
2016-07-11 21:21:11
<p>I have a bash script to call several APIs using HTTPie. I want to capture both the response body AND the HTTP status code.</p> <p>Here is the best I have managed so far:</p> <pre><code>rspBody=$( http $URL --check-status --ignore-stdin ) statusCode=$? </code></pre> <p>Command substitution lets me get the body, an...
6,281
6,576,482
2020-04-22 11:03:53
38,338,811
13
2016-07-12 21:01:19
380,625
2019-07-19 09:53:17
https://stackoverflow.com/q/38316422
https://stackoverflow.com/a/38338811
<p>There's no ready-made solution as such for this but it's achievable with a bit of scripting. For example:</p> <pre><code>STATUS=$(http -hdo ./body httpbin.org/get 2&gt;&amp;1 | grep HTTP/ | cut -d ' ' -f 2) BODY=$(cat ./body) rm ./body echo $STATUS # 200 echo $BODY # { "args": {}, "headers": { "Accept": "*/*", "Ac...
<p>There's no ready-made solution as such for this but it's achievable with a bit of scripting. For example:</p> <pre><code>STATUS=$(http -hdo ./body httpbin.org/get 2&gt;&amp;1 | grep HTTP/ | cut -d ' ' -f 2) BODY=$(cat ./body) rm ./body echo $STATUS # 200 echo $BODY # { "args": {}, "headers": { "Accept": "*/*", "Ac...
387, 84690
bash, httpie
<h1>How to capture actual response code and response body with HTTPie in bash script?</h1> <p>I have a bash script to call several APIs using HTTPie. I want to capture both the response body AND the HTTP status code.</p> <p>Here is the best I have managed so far:</p> <pre><code>rspBody=$( http $URL --check-status --i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,469
bash
# How to capture actual response code and response body with HTTPie in bash script? I have a bash script to call several APIs using HTTPie. I want to capture both the response body AND the HTTP status code. Here is the best I have managed so far: ``` rspBody=$( http $URL --check-status --ignore-stdin ) statusCode=$?...
There's no ready-made solution as such for this but it's achievable with a bit of scripting. For example: ``` STATUS=$(http -hdo ./body httpbin.org/get 2>&1 | grep HTTP/ | cut -d ' ' -f 2) BODY=$(cat ./body) rm ./body echo $STATUS # 200 echo $BODY # { "args": {}, "headers": { "Accept": "*/*", "Accept-Encoding": "iden...