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
17583373
Selecting attributes in xml using xpath in powershell
24
2013-07-11 00:56:29
<p>I am trying to use powershell and XPath to select the name attribute shown in the below xml example.</p> <pre><code> $xml_peoples= $file.SelectNodes("//people") foreach ($person in $xml_peoples){ echo $person.attributes #echo $person.attributes.name } </code></pre> <p>Above i...
105,840
1,044,585
2017-08-22 16:43:26
17,583,851
16
2013-07-11 01:58:04
1,248,365
2013-07-11 01:58:04
https://stackoverflow.com/q/17583373
https://stackoverflow.com/a/17583851
<p>I'm not sure what <strong>$hub</strong> is, and you started your code from the middle so it's not clear if you properly set <strong>$file</strong> to an XmlDocument object, but I think this is what you want:</p> <pre><code>[System.Xml.XmlDocument]$file = new-object System.Xml.XmlDocument $file.load(&lt;path to XML ...
<p>I'm not sure what <strong>$hub</strong> is, and you started your code from the middle so it's not clear if you properly set <strong>$file</strong> to an XmlDocument object, but I think this is what you want:</p> <pre><code>[System.Xml.XmlDocument]$file = new-object System.Xml.XmlDocument $file.load(&lt;path to XML ...
19, 526, 531, 1227
powershell, scripting, xml, xpath
<h1>Selecting attributes in xml using xpath in powershell</h1> <p>I am trying to use powershell and XPath to select the name attribute shown in the below xml example.</p> <pre><code> $xml_peoples= $file.SelectNodes("//people") foreach ($person in $xml_peoples){ echo $person.attributes ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,661
bash
# Selecting attributes in xml using xpath in powershell I am trying to use powershell and XPath to select the name attribute shown in the below xml example. ``` $xml_peoples= $file.SelectNodes("//people") foreach ($person in $xml_peoples){ echo $person.attributes #echo $person.attri...
I'm not sure what **$hub** is, and you started your code from the middle so it's not clear if you properly set **$file** to an XmlDocument object, but I think this is what you want: ``` [System.Xml.XmlDocument]$file = new-object System.Xml.XmlDocument $file.load(<path to XML file>) $xml_peoples= $file.SelectNodes("/pe...
21475639
Wait until service starts in bash-script
23
2014-01-31 08:43:01
<p>I've a bash-script that starts some service in background. After this service successfully starts it prints "Server is active" to the stdout. I need to wait until this string appears and then continue executing my script. How can I achieve this?</p>
38,070
1,773,534
2020-05-05 23:05:44
21,480,316
16
2014-01-31 12:39:04
1,190,965
2014-01-31 12:39:04
https://stackoverflow.com/q/21475639
https://stackoverflow.com/a/21480316
<p>I would do in this way.</p> <pre><code>./server &gt; /tmp/server-log.txt &amp; sleep 1 while ! grep -m1 'Server is active' &lt; /tmp/server-log.txt; do sleep 1 done echo Continue </code></pre> <p>Here <code>-m1</code> tells <code>grep(1)</code> to quit at the first match.</p> <p>I veryfied my answer with my ...
<p>I would do in this way.</p> <pre><code>./server &gt; /tmp/server-log.txt &amp; sleep 1 while ! grep -m1 'Server is active' &lt; /tmp/server-log.txt; do sleep 1 done echo Continue </code></pre> <p>Here <code>-m1</code> tells <code>grep(1)</code> to quit at the first match.</p> <p>I veryfied my answer with my ...
58, 387
bash, linux
<h1>Wait until service starts in bash-script</h1> <p>I've a bash-script that starts some service in background. After this service successfully starts it prints "Server is active" to the stdout. I need to wait until this string appears and then continue executing my script. How can I achieve this?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,662
bash
# Wait until service starts in bash-script I've a bash-script that starts some service in background. After this service successfully starts it prints "Server is active" to the stdout. I need to wait until this string appears and then continue executing my script. How can I achieve this?
I would do in this way. ``` ./server > /tmp/server-log.txt & sleep 1 while ! grep -m1 'Server is active' < /tmp/server-log.txt; do sleep 1 done echo Continue ``` Here `-m1` tells `grep(1)` to quit at the first match. I veryfied my answer with my toy "service" below: ``` #! /bin/bash trap "echo 'YOU killed me ...
8604150
With $TERM='screen-256color' under tmux, HOME and END keys don't work. Why?
23
2011-12-22 12:54:02
<p>I have tmux set up with <code>$TERM</code> being set to <code>screen-256color</code> correctly. This works fine, and colours are set correctly, however it prevents me from sending <code>HOME</code> and <code>END</code> keys to the terminal, which are instead printed as <code>F\n</code> and <code>H\n</code>. </p> <p...
6,872
781,909
2014-01-21 08:04:14
9,674,158
16
2012-03-12 20:17:02
895,931
2012-03-12 20:17:02
https://stackoverflow.com/q/8604150
https://stackoverflow.com/a/9674158
<p>The above mapping solution doesn't affect the command mode or visual mode. The following is a more ideal solution until either tmux or vim fixes the bug (put in your <strong>.vimrc</strong>):</p> <pre><code>"""""""""""""" " tmux fixes " """""""""""""" " Handle tmux $TERM quirks in vim if $TERM =~ '^screen-256color...
<p>The above mapping solution doesn't affect the command mode or visual mode. The following is a more ideal solution until either tmux or vim fixes the bug (put in your <strong>.vimrc</strong>):</p> <pre><code>"""""""""""""" " tmux fixes " """""""""""""" " Handle tmux $TERM quirks in vim if $TERM =~ '^screen-256color...
387, 391, 60238
bash, terminal, tmux
<h1>With $TERM='screen-256color' under tmux, HOME and END keys don't work. Why?</h1> <p>I have tmux set up with <code>$TERM</code> being set to <code>screen-256color</code> correctly. This works fine, and colours are set correctly, however it prevents me from sending <code>HOME</code> and <code>END</code> keys to the t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,663
bash
# With $TERM='screen-256color' under tmux, HOME and END keys don't work. Why? I have tmux set up with `$TERM` being set to `screen-256color` correctly. This works fine, and colours are set correctly, however it prevents me from sending `HOME` and `END` keys to the terminal, which are instead printed as `F\n` and `H\n`...
The above mapping solution doesn't affect the command mode or visual mode. The following is a more ideal solution until either tmux or vim fixes the bug (put in your **.vimrc**): ``` """""""""""""" " tmux fixes " """""""""""""" " Handle tmux $TERM quirks in vim if $TERM =~ '^screen-256color' map <Esc>OH <Home> ...
20891710
What magic prevents Tkinter programs from blocking in interactive shell?
22
2014-01-02 20:56:49
<p><em>Note: This is somewhat a follow-up on the question: <a href="https://stackoverflow.com/questions/8683217/tkinter-when-do-i-need-to-call-mainloop">Tkinter - when do I need to call mainloop?</a></em></p> <p>Usually when using <a href="http://docs.python.org/3/library/tkinter.html" rel="noreferrer">Tkinter</a>, yo...
4,276
216,074
2014-01-02 22:09:36
20,892,684
16
2014-01-02 21:57:19
908,494
2014-01-02 22:09:36
https://stackoverflow.com/q/20891710
https://stackoverflow.com/a/20892684
<p>It's actually not being an interactive interpreter that matters here, but waiting for input on a TTY. You can get the same behavior from a script like this:</p> <pre><code>import tkinter t = tkinter.Tk() input() </code></pre> <p>(On Windows, you may have to run the script in pythonw.exe instead of python.exe, but ...
<p>It's actually not being an interactive interpreter that matters here, but waiting for input on a TTY. You can get the same behavior from a script like this:</p> <pre><code>import tkinter t = tkinter.Tk() input() </code></pre> <p>(On Windows, you may have to run the script in pythonw.exe instead of python.exe, but ...
16, 5323, 68237
interactive-shell, python, tkinter
<h1>What magic prevents Tkinter programs from blocking in interactive shell?</h1> <p><em>Note: This is somewhat a follow-up on the question: <a href="https://stackoverflow.com/questions/8683217/tkinter-when-do-i-need-to-call-mainloop">Tkinter - when do I need to call mainloop?</a></em></p> <p>Usually when using <a hre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,664
bash
# What magic prevents Tkinter programs from blocking in interactive shell? *Note: This is somewhat a follow-up on the question: [Tkinter - when do I need to call mainloop?](https://stackoverflow.com/questions/8683217/tkinter-when-do-i-need-to-call-mainloop)* Usually when using [Tkinter](http://docs.python.org/3/libra...
It's actually not being an interactive interpreter that matters here, but waiting for input on a TTY. You can get the same behavior from a script like this: ``` import tkinter t = tkinter.Tk() input() ``` (On Windows, you may have to run the script in pythonw.exe instead of python.exe, but otherwise, you don't have t...
19742062
Why are "declare -f" and "declare -a" needed in bash scripts?
22
2013-11-02 12:50:01
<p>Sorry for the innocent question - I'm just trying to understand...</p> <p>For example - I have:</p> <pre><code>$ cat test.sh #!/bin/bash declare -f testfunct testfunct () { echo &quot;I'm function&quot; } testfunct declare -a testarr testarr=([1]=arr1 [2]=arr2 [3]=arr3) echo ${testarr[@]} </code></pre> <p>And w...
15,831
2,720,802
2020-12-03 20:12:41
19,742,317
16
2013-11-02 13:21:15
1,815,797
2013-11-02 13:26:57
https://stackoverflow.com/q/19742062
https://stackoverflow.com/a/19742317
<p><code>declare -f functionname</code> is used to output the definition of the function <code>functionname</code>, if it exists, and absolutely not to <em>declare</em> that <code>functionname</code> is/will be a function. Look:</p> <pre><code>$ unset -f a # unsetting the function a, if it existed $ declare -f a $ # n...
<p><code>declare -f functionname</code> is used to output the definition of the function <code>functionname</code>, if it exists, and absolutely not to <em>declare</em> that <code>functionname</code> is/will be a function. Look:</p> <pre><code>$ unset -f a # unsetting the function a, if it existed $ declare -f a $ # n...
387, 5569, 16655
bash, declare, function
<h1>Why are "declare -f" and "declare -a" needed in bash scripts?</h1> <p>Sorry for the innocent question - I'm just trying to understand...</p> <p>For example - I have:</p> <pre><code>$ cat test.sh #!/bin/bash declare -f testfunct testfunct () { echo &quot;I'm function&quot; } testfunct declare -a testarr testarr=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,665
bash
# Why are "declare -f" and "declare -a" needed in bash scripts? Sorry for the innocent question - I'm just trying to understand... For example - I have: ``` $ cat test.sh #!/bin/bash declare -f testfunct testfunct () { echo "I'm function" } testfunct declare -a testarr testarr=([1]=arr1 [2]=arr2 [3]=arr3) echo ...
`declare -f functionname` is used to output the definition of the function `functionname`, if it exists, and absolutely not to *declare* that `functionname` is/will be a function. Look: ``` $ unset -f a # unsetting the function a, if it existed $ declare -f a $ # nothing output and look at the exit code: $ echo $? 1 $...
2520085
How do I conditionally redirect the output of a command to /dev/null?
22
2010-03-25 23:11:17
<p>I have a script. I would like to give this script a quiet mode and a verbose mode.</p> <p>This is the equivalent of:</p> <pre><code>if $verbose then redirect="&gt; /dev/null" fi echo "Verbose mode enabled" $redirect # This doesn't work because the redirect isn't evaluated. </code></pre> <p>I'd really like a be...
7,509
1,512
2020-09-21 17:35:20
2,520,269
16
2010-03-25 23:52:02
119,963
2020-09-21 17:35:20
https://stackoverflow.com/q/2520085
https://stackoverflow.com/a/2520269
<p>You could write a wrapper function:</p> <pre><code>redirect_cmd() { # write your test however you want; this just tests if SILENT is non-empty if [ -n &quot;$SILENT&quot; ]; then &quot;$@&quot; &gt; /dev/null else &quot;$@&quot; fi } </code></pre> <p>You can then use it to run any com...
<p>You could write a wrapper function:</p> <pre><code>redirect_cmd() { # write your test however you want; this just tests if SILENT is non-empty if [ -n &quot;$SILENT&quot; ]; then &quot;$@&quot; &gt; /dev/null else &quot;$@&quot; fi } </code></pre> <p>You can then use it to run any com...
387, 31901
bash, http-redirect
<h1>How do I conditionally redirect the output of a command to /dev/null?</h1> <p>I have a script. I would like to give this script a quiet mode and a verbose mode.</p> <p>This is the equivalent of:</p> <pre><code>if $verbose then redirect="&gt; /dev/null" fi echo "Verbose mode enabled" $redirect # This doesn't wo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,666
bash
# How do I conditionally redirect the output of a command to /dev/null? I have a script. I would like to give this script a quiet mode and a verbose mode. This is the equivalent of: ``` if $verbose then redirect="> /dev/null" fi echo "Verbose mode enabled" $redirect # This doesn't work because the redirect isn't ...
You could write a wrapper function: ``` redirect_cmd() { # write your test however you want; this just tests if SILENT is non-empty if [ -n "$SILENT" ]; then "$@" > /dev/null else "$@" fi } ``` You can then use it to run any command with the redirect: ``` redirect_cmd echo "unsilenced...
56962129
How to get original location of script used for SLURM job?
21
2019-07-10 00:55:05
<p>I'm starting the SLURM job with script and script must work depending on it's location which is obtained inside of script itself with <code>SCRIPT_LOCATION=$(realpath $0)</code>. But SLURM copies script to <code>slurmd</code> folder and starts job from there and it screws up further actions.</p> <p>Are there any op...
9,437
7,447,867
2024-02-19 14:01:28
56,991,068
16
2019-07-11 14:03:27
1,763,614
2023-09-07 06:51:46
https://stackoverflow.com/q/56962129
https://stackoverflow.com/a/56991068
<p>You can get the initial (i.e. at submit time) location of the submission script from <code>scontrol</code> like this:</p> <pre><code>scontrol show job &quot;$SLURM_JOB_ID&quot; | awk -F= '/Command=/{print $2}' </code></pre> <p>So you can replace the <code>realpath $0</code> part with the above. This will only work w...
<p>You can get the initial (i.e. at submit time) location of the submission script from <code>scontrol</code> like this:</p> <pre><code>scontrol show job &quot;$SLURM_JOB_ID&quot; | awk -F= '/Command=/{print $2}' </code></pre> <p>So you can replace the <code>realpath $0</code> part with the above. This will only work w...
276, 387, 6268, 97759
bash, path, slurm, variables
<h1>How to get original location of script used for SLURM job?</h1> <p>I'm starting the SLURM job with script and script must work depending on it's location which is obtained inside of script itself with <code>SCRIPT_LOCATION=$(realpath $0)</code>. But SLURM copies script to <code>slurmd</code> folder and starts job f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,667
bash
# How to get original location of script used for SLURM job? I'm starting the SLURM job with script and script must work depending on it's location which is obtained inside of script itself with `SCRIPT_LOCATION=$(realpath $0)`. But SLURM copies script to `slurmd` folder and starts job from there and it screws up furt...
You can get the initial (i.e. at submit time) location of the submission script from `scontrol` like this: ``` scontrol show job "$SLURM_JOB_ID" | awk -F= '/Command=/{print $2}' ``` So you can replace the `realpath $0` part with the above. This will only work within a Slurm allocation of course. So if you want the sc...
36858588
Exit a PowerShell function but continue the script
21
2016-04-26 07:50:24
<p>This might seem like a very very stupid question, but I can't really figure it out. I'm trying to have the function stop when it finds its first hit (match) and then continue with the rest of the script.</p> <p><strong>Code:</strong></p> <pre><code>Function Get-Foo { [CmdLetBinding()] Param () 1..6 | ...
60,162
2,304,170
2021-11-25 20:49:26
36,858,941
16
2016-04-26 08:07:19
978,511
2016-04-26 08:07:19
https://stackoverflow.com/q/36858588
https://stackoverflow.com/a/36858941
<p>As was mentioned, <code>Foreach-object</code> is a function of its own. Use regular <code>foreach</code></p> <pre><code>Function Get-Foo { [CmdLetBinding()] Param () $a = 1..6 foreach($b in $a) { Write-Verbose $b if ($b -eq 3) { Write-Output 'We found it' break } elseif ($b -eq 5) ...
<p>As was mentioned, <code>Foreach-object</code> is a function of its own. Use regular <code>foreach</code></p> <pre><code>Function Get-Foo { [CmdLetBinding()] Param () $a = 1..6 foreach($b in $a) { Write-Verbose $b if ($b -eq 3) { Write-Output 'We found it' break } elseif ($b -eq 5) ...
526, 5569, 10871
exit, function, powershell
<h1>Exit a PowerShell function but continue the script</h1> <p>This might seem like a very very stupid question, but I can't really figure it out. I'm trying to have the function stop when it finds its first hit (match) and then continue with the rest of the script.</p> <p><strong>Code:</strong></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
8,668
bash
# Exit a PowerShell function but continue the script This might seem like a very very stupid question, but I can't really figure it out. I'm trying to have the function stop when it finds its first hit (match) and then continue with the rest of the script. **Code:** ``` Function Get-Foo { [CmdLetBinding()] P...
As was mentioned, `Foreach-object` is a function of its own. Use regular `foreach` ``` Function Get-Foo { [CmdLetBinding()] Param () $a = 1..6 foreach($b in $a) { Write-Verbose $b if ($b -eq 3) { Write-Output 'We found it' break } elseif ($b -eq 5) { Write-Output 'We found it'...
1860344
Use UFormat to get unix time
21
2009-12-07 14:34:50
<p>I can use following to append a date to a text:</p> <pre><code>"Foo {0:G} Foo" -f (date) #returns "Foo 2009-12-07 15:34:16 Foo" </code></pre> <p>But I want the time in Unix format. I can get it by <code>date -UFormat %s</code>, but can I use the same syntax?</p> <p>When I use <code>-UFormat %s</code> I get <e...
46,342
198,145
2026-01-17 01:46:30
1,860,511
16
2009-12-07 15:02:37
153,982
2009-12-09 02:21:03
https://stackoverflow.com/q/1860344
https://stackoverflow.com/a/1860511
<p>Just cast the result to an int like so:</p> <pre><code>PS&gt; [int][double]::Parse((Get-Date -UFormat %s)) 1260172909 PS&gt; "Foo {0:G} Foo" -f [int][double]::Parse((Get-Date -UFormat %s)) Foo 1260172997 Foo </code></pre> <p>Using the Parse method means the string is parsed "culture aware" such that the appropria...
<p>Just cast the result to an int like so:</p> <pre><code>PS&gt; [int][double]::Parse((Get-Date -UFormat %s)) 1260172909 PS&gt; "Foo {0:G} Foo" -f [int][double]::Parse((Get-Date -UFormat %s)) Foo 1260172997 Foo </code></pre> <p>Using the Parse method means the string is parsed "culture aware" such that the appropria...
526
powershell
<h1>Use UFormat to get unix time</h1> <p>I can use following to append a date to a text:</p> <pre><code>"Foo {0:G} Foo" -f (date) #returns "Foo 2009-12-07 15:34:16 Foo" </code></pre> <p>But I want the time in Unix format. I can get it by <code>date -UFormat %s</code>, but can I use the same syntax?</p> <p>When I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,669
bash
# Use UFormat to get unix time I can use following to append a date to a text: ``` "Foo {0:G} Foo" -f (date) #returns "Foo 2009-12-07 15:34:16 Foo" ``` But I want the time in Unix format. I can get it by `date -UFormat %s`, but can I use the same syntax? When I use `-UFormat %s` I get *1260199855,65625*, how do...
Just cast the result to an int like so: ``` PS> [int][double]::Parse((Get-Date -UFormat %s)) 1260172909 PS> "Foo {0:G} Foo" -f [int][double]::Parse((Get-Date -UFormat %s)) Foo 1260172997 Foo ``` Using the Parse method means the string is parsed "culture aware" such that the appropriate decimal separator character is...
10002356
What does "set keymap vi" do?
20
2012-04-03 22:27:47
<p>I wanted vim-like navigation for my terminal, so I added:</p> <pre><code>set editing-mode vi set keymap vi </code></pre> <p>To my <code>.inputrc</code> file based on <a href="http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal">this</a>. <code>editing-mode vi</code> adds vi navigation. What does <code>keymap vi...
32,043
139,117
2016-08-17 06:31:19
38,989,262
16
2016-08-17 06:13:06
5,353,461
2016-08-17 06:31:19
https://stackoverflow.com/q/10002356
https://stackoverflow.com/a/38989262
<p><strong>TL;DR</strong></p> <p>If you don't want to change/add bindings in the default keymaps, you don't need the line <code>keymap vi</code>.</p> <p>What <code>keymap vi</code> does is state that any bindings listed after that point apply to that keymap (which is <em>exactly</em> the same keymap as <code>vi-command...
<p><strong>TL;DR</strong></p> <p>If you don't want to change/add bindings in the default keymaps, you don't need the line <code>keymap vi</code>.</p> <p>What <code>keymap vi</code> does is state that any bindings listed after that point apply to that keymap (which is <em>exactly</em> the same keymap as <code>vi-command...
387, 390
bash, shell
<h1>What does "set keymap vi" do?</h1> <p>I wanted vim-like navigation for my terminal, so I added:</p> <pre><code>set editing-mode vi set keymap vi </code></pre> <p>To my <code>.inputrc</code> file based on <a href="http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal">this</a>. <code>editing-mode vi</code> adds v...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,670
bash
# What does "set keymap vi" do? I wanted vim-like navigation for my terminal, so I added: ``` set editing-mode vi set keymap vi ``` To my `.inputrc` file based on [this](http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal). `editing-mode vi` adds vi navigation. What does `keymap vi` do, and why do I need it?
**TL;DR** If you don't want to change/add bindings in the default keymaps, you don't need the line `keymap vi`. What `keymap vi` does is state that any bindings listed after that point apply to that keymap (which is *exactly* the same keymap as `vi-command` and `vi-move`). If you want to change the insertion keymap ...
8061475
Split one file into multiple files based on pattern
20
2011-11-09 07:05:50
<p>I have a binary file which I convert into a regular file using hexdump and few awk and sed commands. The output file looks something like this - </p> <pre><code>$cat temp 3d3d01f87347545002f1d5b2be4ee4d700010100018000cc57e5820000000000000000000 000000087d3f513000000000000000000000000000000000001001001010f0000000000...
40,821
970,195
2019-06-05 23:05:08
8,061,558
16
2011-11-09 07:18:26
77,567
2011-11-09 07:18:26
https://stackoverflow.com/q/8061475
https://stackoverflow.com/a/8061558
<pre><code>#!/usr/bin/perl undef $/; $_ = &lt;&gt;; $n = 0; for $match (split(/(?=3d3d)/)) { open(O, '&gt;temp' . ++$n); print O $match; close(O); } </code></pre>
<pre><code>#!/usr/bin/perl undef $/; $_ = &lt;&gt;; $n = 0; for $match (split(/(?=3d3d)/)) { open(O, '&gt;temp' . ++$n); print O $match; close(O); } </code></pre>
387, 990, 2193, 5282
awk, bash, sed, split
<h1>Split one file into multiple files based on pattern</h1> <p>I have a binary file which I convert into a regular file using hexdump and few awk and sed commands. The output file looks something like this - </p> <pre><code>$cat temp 3d3d01f87347545002f1d5b2be4ee4d700010100018000cc57e5820000000000000000000 000000087d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,671
bash
# Split one file into multiple files based on pattern I have a binary file which I convert into a regular file using hexdump and few awk and sed commands. The output file looks something like this - ``` $cat temp 3d3d01f87347545002f1d5b2be4ee4d700010100018000cc57e5820000000000000000000 000000087d3f5130000000000000000...
``` #!/usr/bin/perl undef $/; $_ = <>; $n = 0; for $match (split(/(?=3d3d)/)) { open(O, '>temp' . ++$n); print O $match; close(O); } ```
2552402
cat file | ... vs ... <file
20
2010-03-31 11:21:56
<p>Is there a case of <code>...</code> or context where <code>cat file | ...</code> behaves differently than <code>... &lt;file</code>?</p>
4,661
34,596
2018-01-18 15:11:50
2,552,464
16
2010-03-31 11:30:47
12,274
2010-03-31 15:35:44
https://stackoverflow.com/q/2552402
https://stackoverflow.com/a/2552464
<p>When reading from a regular file, <code>cat</code> is in charge of reading the data, performs it as it pleases, and might constrain it in the way it writes it to the pipeline. Obviously, the contents themselves are preserved, but anything else could be tainted. For example: block size and data arrival timing. Add...
<p>When reading from a regular file, <code>cat</code> is in charge of reading the data, performs it as it pleases, and might constrain it in the way it writes it to the pipeline. Obviously, the contents themselves are preserved, but anything else could be tainted. For example: block size and data arrival timing. Add...
34, 205, 390, 5813
pipe, puzzle, shell, unix
<h1>cat file | ... vs ... <file</h1> <p>Is there a case of <code>...</code> or context where <code>cat file | ...</code> behaves differently than <code>... &lt;file</code>?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,672
bash
# cat file | ... vs ... Is there a case of `...` or context where `cat file | ...` behaves differently than `... <file`?
When reading from a regular file, `cat` is in charge of reading the data, performs it as it pleases, and might constrain it in the way it writes it to the pipeline. Obviously, the contents themselves are preserved, but anything else could be tainted. For example: block size and data arrival timing. Additionally, the pi...
1330136
Script to recursively delete CVS directory on server
20
2009-08-25 18:32:25
<p>So far I've come up with this:</p> <pre><code>find . -name 'CVS' -type d -exec rm -rf {} \; </code></pre> <p>It's worked locally thus far, can anyone see any potential issues? I want this to basically recursively delete 'CVS' directories accidently uploaded on to a server. </p> <p>Also, how can I make it a script...
11,720
145,190
2015-04-29 08:06:06
1,330,210
16
2009-08-25 18:46:22
27,727
2015-04-29 08:06:06
https://stackoverflow.com/q/1330136
https://stackoverflow.com/a/1330210
<p>Well, the obvious caveat: It'll delete directories named CVS, regardless of if they're CVS directories or not.</p> <p>You can turn it into a script fairly easily:</p> <pre><code>#!/bin/sh if [ -z "$1" ]; then echo "Usage: $0 path" exit 1 fi find "$1" -name 'CVS' -type d -print0 | xargs -0 rm -Rf # or fin...
<p>Well, the obvious caveat: It'll delete directories named CVS, regardless of if they're CVS directories or not.</p> <p>You can turn it into a script fairly easily:</p> <pre><code>#!/bin/sh if [ -z "$1" ]; then echo "Usage: $0 path" exit 1 fi find "$1" -name 'CVS' -type d -print0 | xargs -0 rm -Rf # or fin...
34, 387
bash, unix
<h1>Script to recursively delete CVS directory on server</h1> <p>So far I've come up with this:</p> <pre><code>find . -name 'CVS' -type d -exec rm -rf {} \; </code></pre> <p>It's worked locally thus far, can anyone see any potential issues? I want this to basically recursively delete 'CVS' directories accidently uplo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,673
bash
# Script to recursively delete CVS directory on server So far I've come up with this: ``` find . -name 'CVS' -type d -exec rm -rf {} \; ``` It's worked locally thus far, can anyone see any potential issues? I want this to basically recursively delete 'CVS' directories accidently uploaded on to a server. Also, how c...
Well, the obvious caveat: It'll delete directories named CVS, regardless of if they're CVS directories or not. You can turn it into a script fairly easily: ``` #!/bin/sh if [ -z "$1" ]; then echo "Usage: $0 path" exit 1 fi find "$1" -name 'CVS' -type d -print0 | xargs -0 rm -Rf # or find … -exec like you ha...
251851
Using PowerShell to add an extension to files
20
2008-10-30 21:30:23
<p>I have a directory of files that I'd like to append file extension to as long as they don't have an existing, specified extension. So add .txt to all file names that don't end in .xyz. PowerShell seems like a good candidate for this, but I don't know anything about it. How would I go about it?</p>
48,557
1,786
2015-05-16 21:37:38
251,886
16
2008-10-30 21:48:32
615
2008-10-30 21:48:32
https://stackoverflow.com/q/251851
https://stackoverflow.com/a/251886
<p>+1 to EBGreen, except that (at least on XP) the "-exclude" parameter to get-childitem doesn't seem to work. The help text (gci -?) actually says "this parameter does not work properly in this cmdlet"!</p> <p>So you can filter manually like this:</p> <pre><code>gci | ?{ !$_.PSIsContainer -and !$_.Name.EndsWith("...
<p>+1 to EBGreen, except that (at least on XP) the "-exclude" parameter to get-childitem doesn't seem to work. The help text (gci -?) actually says "this parameter does not work properly in this cmdlet"!</p> <p>So you can filter manually like this:</p> <pre><code>gci | ?{ !$_.PSIsContainer -and !$_.Name.EndsWith("...
526
powershell
<h1>Using PowerShell to add an extension to files</h1> <p>I have a directory of files that I'd like to append file extension to as long as they don't have an existing, specified extension. So add .txt to all file names that don't end in .xyz. PowerShell seems like a good candidate for this, but I don't know anything ab...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,674
bash
# Using PowerShell to add an extension to files I have a directory of files that I'd like to append file extension to as long as they don't have an existing, specified extension. So add .txt to all file names that don't end in .xyz. PowerShell seems like a good candidate for this, but I don't know anything about it. H...
+1 to EBGreen, except that (at least on XP) the "-exclude" parameter to get-childitem doesn't seem to work. The help text (gci -?) actually says "this parameter does not work properly in this cmdlet"! So you can filter manually like this: ``` gci | ?{ !$_.PSIsContainer -and !$_.Name.EndsWith(".xyz") } | %{ ren ...
53771022
How to create and install X.509 self signed certificates in Windows 10 without user interaction?
19
2018-12-13 22:33:52
<h2>The problem</h2> <ul> <li><strong>Create and install</strong> temporary certificates to sign code in my development environment.</li> <li>This has to be done with an <strong>unattended</strong> script (without user interaction).</li> </ul> <h2>The legacy script</h2> <p>Right now, I have this script that creates the...
19,655
623,913
2018-12-22 16:44:01
53,869,276
16
2018-12-20 13:01:52
2,678,467
2018-12-22 09:56:23
https://stackoverflow.com/q/53771022
https://stackoverflow.com/a/53869276
<p>I just tested your code with the signtool.exe coming from my Visual Studio 2017 installation and things seems to work.</p> <p>So I would really like to see the code / command you use for signing the files. Even more I would like to see the real output from the error that you are seeing. Could you try your signing p...
<p>I just tested your code with the signtool.exe coming from my Visual Studio 2017 installation and things seems to work.</p> <p>So I would really like to see the code / command you use for signing the files. Even more I would like to see the real output from the error that you are seeing. Could you try your signing p...
526, 24008, 30841, 42181, 107329
powershell, unattended-processing, windows-10, x509, x509certificate
<h1>How to create and install X.509 self signed certificates in Windows 10 without user interaction?</h1> <h2>The problem</h2> <ul> <li><strong>Create and install</strong> temporary certificates to sign code in my development environment.</li> <li>This has to be done with an <strong>unattended</strong> script (without ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,675
bash
# How to create and install X.509 self signed certificates in Windows 10 without user interaction? ## The problem - **Create and install** temporary certificates to sign code in my development environment. - This has to be done with an **unattended** script (without user interaction). ## The legacy script Right...
I just tested your code with the signtool.exe coming from my Visual Studio 2017 installation and things seems to work. So I would really like to see the code / command you use for signing the files. Even more I would like to see the real output from the error that you are seeing. Could you try your signing process man...
43626779
Get-AzureStorageBlob : Could not get the storage context. Please pass in a storage context or set the current storage context
19
2017-04-26 06:40:17
<p>I am using powershell with Azure cmdlets to try and simply see items in blob storage</p> <pre><code> $StorageContext = New-AzureStorageContext -StorageAccountName 'myblobname' -StorageAccountKey '2341231234asdff2352354345==' $Container = Get-AzureStorageContainer -Name 'mycontainer' -Context $StorageContext ...
33,578
1,514,111
2017-04-26 06:44:50
43,626,846
16
2017-04-26 06:44:50
188,096
2017-04-26 06:44:50
https://stackoverflow.com/q/43626779
https://stackoverflow.com/a/43626846
<p>You would need to include <code>StorageContext</code> here as well:</p> <pre><code>$blobs = Get-AzureStorageBlob -Container $Container </code></pre> <p>So your code would be:</p> <pre><code>$blobs = Get-AzureStorageBlob -Container $Container -Context $StorageContext </code></pre>
<p>You would need to include <code>StorageContext</code> here as well:</p> <pre><code>$blobs = Get-AzureStorageBlob -Container $Container </code></pre> <p>So your code would be:</p> <pre><code>$blobs = Get-AzureStorageBlob -Container $Container -Context $StorageContext </code></pre>
526, 3883, 14158, 114615
azure, azure-blob-storage, blob, powershell
<h1>Get-AzureStorageBlob : Could not get the storage context. Please pass in a storage context or set the current storage context</h1> <p>I am using powershell with Azure cmdlets to try and simply see items in blob storage</p> <pre><code> $StorageContext = New-AzureStorageContext -StorageAccountName 'myblobname' -Sto...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,676
bash
# Get-AzureStorageBlob : Could not get the storage context. Please pass in a storage context or set the current storage context I am using powershell with Azure cmdlets to try and simply see items in blob storage ``` $StorageContext = New-AzureStorageContext -StorageAccountName 'myblobname' -StorageAccountKey '2341...
You would need to include `StorageContext` here as well: ``` $blobs = Get-AzureStorageBlob -Container $Container ``` So your code would be: ``` $blobs = Get-AzureStorageBlob -Container $Container -Context $StorageContext ```
20176640
Syntax error: operand expected (error token is "+")
19
2013-11-24 16:03:06
<p>I'm writing a script in bash and I get this error:</p> <pre><code>./P4.1: line 10: +: syntax error: operand expected (error token is "+") </code></pre> <p>And this is my code:</p> <pre><code>#!/bin/bash read string echo $string &gt;| temp num1= cut -d" " -f1 temp num2= cut -d" " -f2 temp num3= cut -d" " -f3 temp ...
158,066
2,513,747
2025-07-21 23:13:45
20,176,956
16
2013-11-24 16:32:52
2,180,567
2013-11-24 16:32:52
https://stackoverflow.com/q/20176640
https://stackoverflow.com/a/20176956
<p>Combination of ceving and Tomek's:</p> <pre><code>#!/bin/bash read num1 num2 num3 while [ $num1 -lt $num3 ] do echo $num1 num1=$((num1+num2)) done </code></pre>
<p>Combination of ceving and Tomek's:</p> <pre><code>#!/bin/bash read num1 num2 num3 while [ $num1 -lt $num3 ] do echo $num1 num1=$((num1+num2)) done </code></pre>
34, 387
bash, unix
<h1>Syntax error: operand expected (error token is "+")</h1> <p>I'm writing a script in bash and I get this error:</p> <pre><code>./P4.1: line 10: +: syntax error: operand expected (error token is "+") </code></pre> <p>And this is my code:</p> <pre><code>#!/bin/bash read string echo $string &gt;| temp num1= cut -d" ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,677
bash
# Syntax error: operand expected (error token is "+") I'm writing a script in bash and I get this error: ``` ./P4.1: line 10: +: syntax error: operand expected (error token is "+") ``` And this is my code: ``` #!/bin/bash read string echo $string >| temp num1= cut -d" " -f1 temp num2= cut -d" " -f2 temp num3= cut -...
Combination of ceving and Tomek's: ``` #!/bin/bash read num1 num2 num3 while [ $num1 -lt $num3 ] do echo $num1 num1=$((num1+num2)) done ```
18890926
How to get the Java version in PowerShell
19
2013-09-19 09:25:34
<p>I'm trying to get the Java version in PowerShell. The version string is printed to <strong>stderr</strong>, so I'm trying to redirect it to stdout and assign it to a string variable.</p> <p>I get the following strange error:</p> <pre><code>PS P:\&gt; &amp; java -version 2&gt;&amp;1 java.exe : java version "1.7.0_2...
85,985
902,415
2018-07-24 01:08:02
18,891,102
16
2013-09-19 09:32:50
520,612
2014-12-01 00:19:52
https://stackoverflow.com/q/18890926
https://stackoverflow.com/a/18891102
<p>One way is using <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" rel="noreferrer">WMI</a>:</p> <pre><code>$javaver = Get-WmiObject -Class Win32_Product -Filter "Name like 'Java(TM)%'" | Select -Expand Version </code></pre> <p>Another one is redirect to a file with start-process:</p> <pr...
<p>One way is using <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" rel="noreferrer">WMI</a>:</p> <pre><code>$javaver = Get-WmiObject -Class Win32_Product -Filter "Name like 'Java(TM)%'" | Select -Expand Version </code></pre> <p>Another one is redirect to a file with start-process:</p> <pr...
17, 526, 5792
java, powershell, version
<h1>How to get the Java version in PowerShell</h1> <p>I'm trying to get the Java version in PowerShell. The version string is printed to <strong>stderr</strong>, so I'm trying to redirect it to stdout and assign it to a string variable.</p> <p>I get the following strange error:</p> <pre><code>PS P:\&gt; &amp; java -v...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,678
bash
# How to get the Java version in PowerShell I'm trying to get the Java version in PowerShell. The version string is printed to **stderr**, so I'm trying to redirect it to stdout and assign it to a string variable. I get the following strange error: ``` PS P:\> & java -version 2>&1 java.exe : java version "1.7.0_25" ...
One way is using [WMI](http://en.wikipedia.org/wiki/Windows_Management_Instrumentation): ``` $javaver = Get-WmiObject -Class Win32_Product -Filter "Name like 'Java(TM)%'" | Select -Expand Version ``` Another one is redirect to a file with start-process: ``` start-process java -ArgumentList "-version" -NoNewWindow...
7271945
logrotate compress files after the postrotate script
19
2011-09-01 14:39:45
<p>I have an application generating a really heavy big log file every days (~800MB a day), thus I need to compress them but since the compression takes time, I want that logrotate compress the file after reloading/sending HUP signal to the application.</p> <pre><code>/var/log/myapp.log { rotate 7 size 500M ...
49,184
311,288
2025-05-09 09:58:12
7,272,035
16
2011-09-01 14:46:02
20,270
2011-09-01 14:46:02
https://stackoverflow.com/q/7271945
https://stackoverflow.com/a/7272035
<p>The <code>postrotate</code> script does run before compression occurs: from the man page for <a href="http://linuxcommand.org/man_pages/logrotate8.html">logrotate</a></p> <blockquote> <p>The next section of the config files defined how to handle the log file /var/log/messages. The log will go through fiv...
<p>The <code>postrotate</code> script does run before compression occurs: from the man page for <a href="http://linuxcommand.org/man_pages/logrotate8.html">logrotate</a></p> <blockquote> <p>The next section of the config files defined how to handle the log file /var/log/messages. The log will go through fiv...
58, 76, 390, 942, 5877
compression, linux, logging, logrotate, shell
<h1>logrotate compress files after the postrotate script</h1> <p>I have an application generating a really heavy big log file every days (~800MB a day), thus I need to compress them but since the compression takes time, I want that logrotate compress the file after reloading/sending HUP signal to the application.</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,679
bash
# logrotate compress files after the postrotate script I have an application generating a really heavy big log file every days (~800MB a day), thus I need to compress them but since the compression takes time, I want that logrotate compress the file after reloading/sending HUP signal to the application. ``` /var/log/...
The `postrotate` script does run before compression occurs: from the man page for [logrotate](http://linuxcommand.org/man_pages/logrotate8.html) > The next section of the config files defined how to handle the log file > /var/log/messages. The log will go through five weekly rotations before > being removed. After the...
6628066
Default values for the arguments to a Unix shell script?
19
2011-07-08 17:22:31
<p>Normally when a parameter is passed to a shell script, the value goes into ${1} for the first parameter, ${2} for the second, etc.</p> <p>How can I set the default values for these parameters, so that if no parameter is passed to the script, we can use a default value for ${1}?</p>
13,123
835,380
2022-05-10 21:56:12
6,628,093
16
2011-07-08 17:25:33
742,469
2011-07-08 17:25:33
https://stackoverflow.com/q/6628066
https://stackoverflow.com/a/6628093
<p>You can't, but you can assign to a local variable like this: <code>${parameter:-word}</code> or use the same construct in the place you need $1. this menas use <em>word</em> if _paramater is null or unset</p> <p>Note, this works in <em>bash</em>, check your shell for the syntax of <em>default values</em></p>
<p>You can't, but you can assign to a local variable like this: <code>${parameter:-word}</code> or use the same construct in the place you need $1. this menas use <em>word</em> if _paramater is null or unset</p> <p>Note, this works in <em>bash</em>, check your shell for the syntax of <em>default values</em></p>
34, 58, 390, 531
linux, scripting, shell, unix
<h1>Default values for the arguments to a Unix shell script?</h1> <p>Normally when a parameter is passed to a shell script, the value goes into ${1} for the first parameter, ${2} for the second, etc.</p> <p>How can I set the default values for these parameters, so that if no parameter is passed to the script, we can us...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,680
bash
# Default values for the arguments to a Unix shell script? Normally when a parameter is passed to a shell script, the value goes into ${1} for the first parameter, ${2} for the second, etc. How can I set the default values for these parameters, so that if no parameter is passed to the script, we can use a default val...
You can't, but you can assign to a local variable like this: `${parameter:-word}` or use the same construct in the place you need $1. this menas use *word* if _paramater is null or unset Note, this works in *bash*, check your shell for the syntax of *default values*
4432549
What's the difference between the `USER` and `USERNAME` environment variables?
19
2010-12-13 19:10:35
<p>I'm not entirely sure which one to use.</p>
12,229
139,089
2020-07-27 06:44:34
4,432,617
16
2010-12-13 19:21:03
369,789
2020-07-27 06:44:34
https://stackoverflow.com/q/4432549
https://stackoverflow.com/a/4432617
<ul> <li><p><strong>On windows:</strong> <code>ENV['username']</code> will output the current username.</p> </li> <li><p><strong>On linux:</strong> If the script is run through <code>sudo</code>, <code>&quot;USER&quot;</code> will be the <code>sudo</code>-ed-to user (usually <code>root</code>) and &quot;USERNAME&quot; ...
<ul> <li><p><strong>On windows:</strong> <code>ENV['username']</code> will output the current username.</p> </li> <li><p><strong>On linux:</strong> If the script is run through <code>sudo</code>, <code>&quot;USER&quot;</code> will be the <code>sudo</code>-ed-to user (usually <code>root</code>) and &quot;USERNAME&quot; ...
390, 9013
environment-variables, shell
<h1>What's the difference between the `USER` and `USERNAME` environment variables?</h1> <p>I'm not entirely sure which one to use.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,681
bash
# What's the difference between the `USER` and `USERNAME` environment variables? I'm not entirely sure which one to use.
- **On windows:** `ENV['username']` will output the current username. - **On linux:** If the script is run through `sudo`, `"USER"` will be the `sudo`-ed-to user (usually `root`) and "USERNAME" will be the user who ran sudo. - **On Mac :** only USER exists (on MacOS 10.15. To be confirmed on previous versions) Here's ...
750449
Converting xml from UTF-16 to UTF-8 using PowerShell
19
2009-04-15 05:45:07
<p>What's the easiest way to convert XML from UTF16 to a UTF8 encoded file?</p>
27,287
25,702
2012-10-21 11:41:39
750,453
16
2009-04-15 05:49:54
2,918
2012-06-08 05:12:05
https://stackoverflow.com/q/750449
https://stackoverflow.com/a/750453
<p>This may not be the most optimal, but it works. Simply load the xml and push it back out to a file. the xml heading is lost though, so this has to be re-added.</p> <pre><code>$files = get-ChildItem "*.xml" foreach ( $file in $files ) { [System.Xml.XmlDocument]$doc = new-object System.Xml.XmlDocument; $doc....
<p>This may not be the most optimal, but it works. Simply load the xml and push it back out to a file. the xml heading is lost though, so this has to be re-added.</p> <pre><code>$files = get-ChildItem "*.xml" foreach ( $file in $files ) { [System.Xml.XmlDocument]$doc = new-object System.Xml.XmlDocument; $doc....
19, 526, 8944, 10016
powershell, utf-16, utf-8, xml
<h1>Converting xml from UTF-16 to UTF-8 using PowerShell</h1> <p>What's the easiest way to convert XML from UTF16 to a UTF8 encoded file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,682
bash
# Converting xml from UTF-16 to UTF-8 using PowerShell What's the easiest way to convert XML from UTF16 to a UTF8 encoded file?
This may not be the most optimal, but it works. Simply load the xml and push it back out to a file. the xml heading is lost though, so this has to be re-added. ``` $files = get-ChildItem "*.xml" foreach ( $file in $files ) { [System.Xml.XmlDocument]$doc = new-object System.Xml.XmlDocument; $doc.set_PreserveWhi...
15062
How do I do a string replacement in a PowerShell function?
19
2008-08-18 18:40:34
<p>How do I convert function input parameters to the right type?</p> <p>I want to return a string that has part of the URL passed into it removed.</p> <p><strong>This works, but it uses a hard-coded string:</strong></p> <pre><code>function CleanUrl($input) { $x = "http://google.com".Replace("http://", "") re...
54,760
636
2015-07-13 13:17:04
15,136
16
2008-08-18 19:50:39
1,233
2015-07-13 13:17:04
https://stackoverflow.com/q/15062
https://stackoverflow.com/a/15136
<p>The concept here is correct.</p> <p>The problem is with the variable name you have chosen. $input is a reserved variable used by PowerShell to represent an array of pipeline input. If you change your variable name, you should not have any problem.</p> <p>PowerShell does have <a href="https://technet.microsoft.com/...
<p>The concept here is correct.</p> <p>The problem is with the variable name you have chosen. $input is a reserved variable used by PowerShell to represent an array of pipeline input. If you change your variable name, you should not have any problem.</p> <p>PowerShell does have <a href="https://technet.microsoft.com/...
139, 526, 2498, 5569
function, powershell, replace, string
<h1>How do I do a string replacement in a PowerShell function?</h1> <p>How do I convert function input parameters to the right type?</p> <p>I want to return a string that has part of the URL passed into it removed.</p> <p><strong>This works, but it uses a hard-coded string:</strong></p> <pre><code>function CleanUrl(...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,683
bash
# How do I do a string replacement in a PowerShell function? How do I convert function input parameters to the right type? I want to return a string that has part of the URL passed into it removed. **This works, but it uses a hard-coded string:** ``` function CleanUrl($input) { $x = "http://google.com".Replace(...
The concept here is correct. The problem is with the variable name you have chosen. $input is a reserved variable used by PowerShell to represent an array of pipeline input. If you change your variable name, you should not have any problem. PowerShell does have [a replace operator](https://technet.microsoft.com/en-us...
40547032
bash read returns with exit code 1 even though it runs as expected
18
2016-11-11 11:28:04
<p>I have this construct to initialize a variable with the contents of a file:</p> <pre><code>echo "yyy" &gt; xxx read -r -d '' PAYLOAD &lt;&lt;&lt; $(cat xxx) echo $? echo $PAYLOAD </code></pre> <p>This results in:</p> <pre><code>1 yyy </code></pre> <p>Why is read returning 1? This is breaking my script, because I...
8,307
647,991
2023-08-06 23:49:39
40,547,123
16
2016-11-11 11:33:15
548,225
2016-11-11 11:33:15
https://stackoverflow.com/q/40547032
https://stackoverflow.com/a/40547123
<p><code>read</code> is returning 1 because it returns <code>0</code> only when end-of-file is not encountered.</p> <p>As per <code>help read</code>:</p> <pre><code>Exit Status: The return code is zero, unless end-of-file is encountered </code></pre> <p>You don't even need a <code>read</code> here, just use <code>$(...
<p><code>read</code> is returning 1 because it returns <code>0</code> only when end-of-file is not encountered.</p> <p>As per <code>help read</code>:</p> <pre><code>Exit Status: The return code is zero, unless end-of-file is encountered </code></pre> <p>You don't even need a <code>read</code> here, just use <code>$(...
58, 387
bash, linux
<h1>bash read returns with exit code 1 even though it runs as expected</h1> <p>I have this construct to initialize a variable with the contents of a file:</p> <pre><code>echo "yyy" &gt; xxx read -r -d '' PAYLOAD &lt;&lt;&lt; $(cat xxx) echo $? echo $PAYLOAD </code></pre> <p>This results in:</p> <pre><code>1 yyy </co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,684
bash
# bash read returns with exit code 1 even though it runs as expected I have this construct to initialize a variable with the contents of a file: ``` echo "yyy" > xxx read -r -d '' PAYLOAD <<< $(cat xxx) echo $? echo $PAYLOAD ``` This results in: ``` 1 yyy ``` Why is read returning 1? This is breaking my script, be...
`read` is returning 1 because it returns `0` only when end-of-file is not encountered. As per `help read`: ``` Exit Status: The return code is zero, unless end-of-file is encountered ``` You don't even need a `read` here, just use `$(<file)` to read the file content into a variable: ``` echo "yyy" > xxx payload=$(<...
37328327
Apply regex on JQ
18
2016-05-19 15:51:37
<p>I´m using jq to get a json and get some values.</p> <p>I have this string </p> <pre><code> "arn:aws:ecs:eu-west-1:foo:task/blablabla" </code></pre> <p>And I want to get the substring from task/ and then return just blablabla</p> <p>For now I have this regex.</p> <pre><code> (.*task?)\/(.*$) </code></pre> <p>...
16,259
854,207
2016-05-19 20:47:28
37,329,187
16
2016-05-19 16:33:30
null
2016-05-19 16:33:30
https://stackoverflow.com/q/37328327
https://stackoverflow.com/a/37329187
<p>On jq 1.5, you can pass the regex to <code>match</code> and then get the <code>string</code> property of <code>captures</code>' second element.</p> <pre><code>jq 'match("(.*task?)\/(.*$)").captures[1].string' </code></pre>
<p>On jq 1.5, you can pass the regex to <code>match</code> and then get the <code>string</code> property of <code>captures</code>' second element.</p> <pre><code>jq 'match("(.*task?)\/(.*$)").captures[1].string' </code></pre>
18, 387, 105170
bash, jq, regex
<h1>Apply regex on JQ</h1> <p>I´m using jq to get a json and get some values.</p> <p>I have this string </p> <pre><code> "arn:aws:ecs:eu-west-1:foo:task/blablabla" </code></pre> <p>And I want to get the substring from task/ and then return just blablabla</p> <p>For now I have this regex.</p> <pre><code> (.*task?...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,685
bash
# Apply regex on JQ I´m using jq to get a json and get some values. I have this string ``` "arn:aws:ecs:eu-west-1:foo:task/blablabla" ``` And I want to get the substring from task/ and then return just blablabla For now I have this regex. ``` (.*task?)\/(.*$) ``` Which give me two groups. Any idea how using...
On jq 1.5, you can pass the regex to `match` and then get the `string` property of `captures`' second element. ``` jq 'match("(.*task?)\/(.*$)").captures[1].string' ```
30146466
Command substitution with string substitution
18
2015-05-10 00:32:25
<p>Is it possible to do something along the lines of:</p> <pre><code>echo ${$(ls)/foo/bar} </code></pre> <p>I'm pretty sure i saw somewhere working example of something like that but this results in "bad substitution" error.</p> <p>I know that there are other methods to do that but such a short oneliner would be use...
9,222
3,665,534
2019-09-11 10:53:25
30,147,156
16
2015-05-10 02:40:09
45,375
2015-05-10 02:45:23
https://stackoverflow.com/q/30146466
https://stackoverflow.com/a/30147156
<p><strong>Syntax <code>${...}</code></strong> only allows <strong>referencing a <em>variable</em> (or positional parameter), optionally combined with <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a></strong>.</p> <p><strong>Syntax <code>$(...)</code></strong> (or, less prefera...
<p><strong>Syntax <code>${...}</code></strong> only allows <strong>referencing a <em>variable</em> (or positional parameter), optionally combined with <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a></strong>.</p> <p><strong>Syntax <code>$(...)</code></strong> (or, less prefera...
387, 77246
bash, command-substitution
<h1>Command substitution with string substitution</h1> <p>Is it possible to do something along the lines of:</p> <pre><code>echo ${$(ls)/foo/bar} </code></pre> <p>I'm pretty sure i saw somewhere working example of something like that but this results in "bad substitution" error.</p> <p>I know that there are other me...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,686
bash
# Command substitution with string substitution Is it possible to do something along the lines of: ``` echo ${$(ls)/foo/bar} ``` I'm pretty sure i saw somewhere working example of something like that but this results in "bad substitution" error. I know that there are other methods to do that but such a short onelin...
**Syntax `${...}`** only allows **referencing a *variable* (or positional parameter), optionally combined with [parameter expansion](http://wiki.bash-hackers.org/syntax/pe)**. **Syntax `$(...)`** (or, less preferably, its old-style equivalent, `` `...` ``), performs **[command substitution](http://mywiki.wooledge.org/...
12282842
How to login to website with basic authentication using Powershell
18
2012-09-05 13:41:24
<p>I am trying to use PowerShell to log into a website and download a file.</p> <p>However I can't get PS to pass the credentials properly.</p> <p>Here is my PS:</p> <pre><code>$webclient = new-object System.Net.WebClient $webclient.Credentials = new-object System.Net.NetworkCredential("username","password","domain"...
72,625
55,718
2021-01-26 20:44:14
12,284,255
16
2012-09-05 14:56:16
55,718
2012-09-05 14:56:16
https://stackoverflow.com/q/12282842
https://stackoverflow.com/a/12284255
<p>This is what I got to work. I believe the key part is the "Basic" in the CredentialCache</p> <pre><code>$webclient = new-object System.Net.WebClient $credCache = new-object System.Net.CredentialCache $creds = new-object System.Net.NetworkCredential("un","pw") $credCache.Add("url", "Basic", $creds) $webclient.Crede...
<p>This is what I got to work. I believe the key part is the "Basic" in the CredentialCache</p> <pre><code>$webclient = new-object System.Net.WebClient $credCache = new-object System.Net.CredentialCache $creds = new-object System.Net.NetworkCredential("un","pw") $credCache.Add("url", "Basic", $creds) $webclient.Crede...
526
powershell
<h1>How to login to website with basic authentication using Powershell</h1> <p>I am trying to use PowerShell to log into a website and download a file.</p> <p>However I can't get PS to pass the credentials properly.</p> <p>Here is my PS:</p> <pre><code>$webclient = new-object System.Net.WebClient $webclient.Credenti...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,687
bash
# How to login to website with basic authentication using Powershell I am trying to use PowerShell to log into a website and download a file. However I can't get PS to pass the credentials properly. Here is my PS: ``` $webclient = new-object System.Net.WebClient $webclient.Credentials = new-object System.Net.Networ...
This is what I got to work. I believe the key part is the "Basic" in the CredentialCache ``` $webclient = new-object System.Net.WebClient $credCache = new-object System.Net.CredentialCache $creds = new-object System.Net.NetworkCredential("un","pw") $credCache.Add("url", "Basic", $creds) $webclient.Credentials = $credC...
12176492
shell: delete the last line of a huge text log file
18
2012-08-29 11:04:40
<p>I asked a <a href="https://stackoverflow.com/questions/12175344/php-pop-the-last-line-of-huge-text-log-file">question</a> regarding popping the last line of a text file in PHP, and now, is it possible to re-write the logic in shell script?</p> <p>I tried this to obtain the last line:</p> <pre><code>tail -n 1 my_lo...
22,964
188,331
2012-08-29 15:51:46
12,176,634
16
2012-08-29 11:13:42
115,845
2012-08-29 15:51:46
https://stackoverflow.com/q/12176492
https://stackoverflow.com/a/12176634
<p><em>(Solution is based on <a href="https://stackoverflow.com/questions/12176492/shell-delete-the-last-line-of-a-huge-text-log-file/12177339#12177339">sch's answer</a> so credit should go to him/her)</em></p> <p>This approach will allow you to efficiently retrieve the last line of the file and truncate the file to r...
<p><em>(Solution is based on <a href="https://stackoverflow.com/questions/12176492/shell-delete-the-last-line-of-a-huge-text-log-file/12177339#12177339">sch's answer</a> so credit should go to him/her)</em></p> <p>This approach will allow you to efficiently retrieve the last line of the file and truncate the file to r...
390, 7896
shell, tail
<h1>shell: delete the last line of a huge text log file</h1> <p>I asked a <a href="https://stackoverflow.com/questions/12175344/php-pop-the-last-line-of-huge-text-log-file">question</a> regarding popping the last line of a text file in PHP, and now, is it possible to re-write the logic in shell script?</p> <p>I tried ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,688
bash
# shell: delete the last line of a huge text log file I asked a [question](https://stackoverflow.com/questions/12175344/php-pop-the-last-line-of-huge-text-log-file) regarding popping the last line of a text file in PHP, and now, is it possible to re-write the logic in shell script? I tried this to obtain the last lin...
*(Solution is based on [sch's answer](https://stackoverflow.com/questions/12176492/shell-delete-the-last-line-of-a-huge-text-log-file/12177339#12177339) so credit should go to him/her)* This approach will allow you to efficiently retrieve the last line of the file and truncate the file to remove that line. This can be...
11035905
Display current time with time zone in PowerShell
18
2012-06-14 15:00:05
<p>I'm trying to display the local time on my system with the TimeZone. How can I display time in this format the simplest way possible on any system?:</p> <p>Time: 8:00:34 AM EST</p> <p>I'm currently using the following script:</p> <pre><code>$localtz = [System.TimeZoneInfo]::Local | Select-Object -expandproperty I...
106,408
544,864
2023-03-21 07:00:40
11,040,329
16
2012-06-14 19:48:46
430,067
2012-06-14 19:58:22
https://stackoverflow.com/q/11035905
https://stackoverflow.com/a/11040329
<p>While this is a bit ... naive perhaps, it's one way to get <em>an</em> abbreviation without a switch statement:</p> <pre><code>[Regex]::Replace([System.TimeZoneInfo]::Local.StandardName, '([A-Z])\w+\s*', '$1') </code></pre> <p>My regular expression probably leaves something to be desired.</p> <p>The output of the...
<p>While this is a bit ... naive perhaps, it's one way to get <em>an</em> abbreviation without a switch statement:</p> <pre><code>[Regex]::Replace([System.TimeZoneInfo]::Local.StandardName, '([A-Z])\w+\s*', '$1') </code></pre> <p>My regular expression probably leaves something to be desired.</p> <p>The output of the...
526, 603, 982
powershell, time, timezone
<h1>Display current time with time zone in PowerShell</h1> <p>I'm trying to display the local time on my system with the TimeZone. How can I display time in this format the simplest way possible on any system?:</p> <p>Time: 8:00:34 AM EST</p> <p>I'm currently using the following script:</p> <pre><code>$localtz = [Sy...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,689
bash
# Display current time with time zone in PowerShell I'm trying to display the local time on my system with the TimeZone. How can I display time in this format the simplest way possible on any system?: Time: 8:00:34 AM EST I'm currently using the following script: ``` $localtz = [System.TimeZoneInfo]::Local | Select...
While this is a bit ... naive perhaps, it's one way to get *an* abbreviation without a switch statement: ``` [Regex]::Replace([System.TimeZoneInfo]::Local.StandardName, '([A-Z])\w+\s*', '$1') ``` My regular expression probably leaves something to be desired. The output of the above for my time zone is `EST`. I did s...
7897549
make ignores my python bash alias
18
2011-10-26 00:47:05
<p>My CentOS 5.5 server has both Python 2.4 and Python 2.7 installed (to <code>/opt/python2.7.2</code>). In my <code>~/.bash_profile</code> I have two aliases pointing to my Python 2.7 install and my <code>PATH</code> configured as:</p> <pre> alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bi...
14,554
419
2017-01-17 14:28:17
7,897,614
16
2011-10-26 00:59:40
377,270
2011-10-26 00:59:40
https://stackoverflow.com/q/7897549
https://stackoverflow.com/a/7897614
<p>From <code>bash(1)</code>:</p> <pre><code> Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below). </code></pre> <p>While you might be able to use something like <code>SHELL=/...
<p>From <code>bash(1)</code>:</p> <pre><code> Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below). </code></pre> <p>While you might be able to use something like <code>SHELL=/...
387, 4301
bash, makefile
<h1>make ignores my python bash alias</h1> <p>My CentOS 5.5 server has both Python 2.4 and Python 2.7 installed (to <code>/opt/python2.7.2</code>). In my <code>~/.bash_profile</code> I have two aliases pointing to my Python 2.7 install and my <code>PATH</code> configured as:</p> <pre> alias python=/opt/python2.7.2/bin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,690
bash
# make ignores my python bash alias My CentOS 5.5 server has both Python 2.4 and Python 2.7 installed (to `/opt/python2.7.2`). In my `~/.bash_profile` I have two aliases pointing to my Python 2.7 install and my `PATH` configured as: ``` alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bin/pyt...
From `bash(1)`: ``` Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below). ``` While you might be able to use something like `SHELL=/bin/bash -O expand_aliases` in your `Makefi...
7069482
Get a list of running VMs using VBoxManage
18
2011-08-15 19:11:11
<p>I want to loop through my running VM's and return only what is between quotes.</p> <p>So this command:</p> <pre><code>VBoxManage list runningvms </code></pre> <p>returns:</p> <pre><code>"UbuntuServer" {7ef01f8d-a7d5-4405-af42-94d85f999dff} </code></pre> <p>And I only want it to return:</p> <pre><code>UbuntuSer...
27,098
442,580
2024-09-29 21:25:27
7,069,536
16
2011-08-15 19:14:43
635,608
2018-01-17 19:23:17
https://stackoverflow.com/q/7069482
https://stackoverflow.com/a/7069536
<p>Warning: all of this is is risky if your VM names have shell glob characters in them, or contain spaces.</p> <hr> <p>You can do something like this if there is only one running VM:</p> <pre><code>read machine stuff &lt;&lt;&lt; $(VBoxManage list runningvms) echo "$machine" </code></pre> <p>Alternative with bash ...
<p>Warning: all of this is is risky if your VM names have shell glob characters in them, or contain spaces.</p> <hr> <p>You can do something like this if there is only one running VM:</p> <pre><code>read machine stuff &lt;&lt;&lt; $(VBoxManage list runningvms) echo "$machine" </code></pre> <p>Alternative with bash ...
387, 2447
bash, virtualbox
<h1>Get a list of running VMs using VBoxManage</h1> <p>I want to loop through my running VM's and return only what is between quotes.</p> <p>So this command:</p> <pre><code>VBoxManage list runningvms </code></pre> <p>returns:</p> <pre><code>"UbuntuServer" {7ef01f8d-a7d5-4405-af42-94d85f999dff} </code></pre> <p>And...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,691
bash
# Get a list of running VMs using VBoxManage I want to loop through my running VM's and return only what is between quotes. So this command: ``` VBoxManage list runningvms ``` returns: ``` "UbuntuServer" {7ef01f8d-a7d5-4405-af42-94d85f999dff} ``` And I only want it to return: ``` UbuntuServer ``` This is what i...
Warning: all of this is is risky if your VM names have shell glob characters in them, or contain spaces. --- You can do something like this if there is only one running VM: ``` read machine stuff <<< $(VBoxManage list runningvms) echo "$machine" ``` Alternative with bash arrays (same condition): ``` vbm=($(VBoxMan...
4909944
How to escape single quotes while setting aliases
18
2011-02-05 21:55:31
<p>I want to create an alias of this command:</p> <pre class="lang-none prettyprint-override"><code>find . -name '*.sh' -exec chmod a+x '{}' \; </code></pre> <p>And I am not able to escape the single quotes while setting the alias:</p> <pre class="lang-none prettyprint-override"><code>alias mx='find . -name '*.sh' -exe...
7,510
547,417
2023-08-19 21:33:25
4,909,957
16
2011-02-05 21:58:26
553,707
2023-08-19 21:20:50
https://stackoverflow.com/q/4909944
https://stackoverflow.com/a/4909957
<p>You could just use double quotes:</p> <pre><code>alias mx=&quot;find . -name '*.sh' -exec chmod a+x {} \;&quot; </code></pre> <p>Also, the single quotes <code>'</code> around the <code>{}</code> are not necessary.</p>
<p>You could just use double quotes:</p> <pre><code>alias mx=&quot;find . -name '*.sh' -exec chmod a+x {} \;&quot; </code></pre> <p>Also, the single quotes <code>'</code> around the <code>{}</code> are not necessary.</p>
387
bash
<h1>How to escape single quotes while setting aliases</h1> <p>I want to create an alias of this command:</p> <pre class="lang-none prettyprint-override"><code>find . -name '*.sh' -exec chmod a+x '{}' \; </code></pre> <p>And I am not able to escape the single quotes while setting the alias:</p> <pre class="lang-none pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,692
bash
# How to escape single quotes while setting aliases I want to create an alias of this command: ``` find . -name '*.sh' -exec chmod a+x '{}' \; ``` And I am not able to escape the single quotes while setting the alias: ``` alias mx='find . -name '*.sh' -exec chmod a+x '{}' \;' ```
You could just use double quotes: ``` alias mx="find . -name '*.sh' -exec chmod a+x {} \;" ``` Also, the single quotes `'` around the `{}` are not necessary.
4307770
Regular Expressions for file name matching
18
2010-11-29 20:25:59
<p>In Bash, how does one match a regular expression with multiple criteria against a file name? For example, I'd like to match against all the files with .txt or .log endings.</p> <p>I know how to match one type of criteria:</p> <pre><code>for file in *.log do echo "${file}" done </code></pre> <p>What's the ...
54,153
385,897
2010-11-30 06:12:15
4,307,812
16
2010-11-29 20:30:10
68,587
2010-11-29 20:30:10
https://stackoverflow.com/q/4307770
https://stackoverflow.com/a/4307812
<p>Do it the same way you'd invoke <code>ls</code>. You can specify multiple wildcards one after the other:</p> <pre><code>for file in *.log *.txt </code></pre>
<p>Do it the same way you'd invoke <code>ls</code>. You can specify multiple wildcards one after the other:</p> <pre><code>for file in *.log *.txt </code></pre>
18, 387
bash, regex
<h1>Regular Expressions for file name matching</h1> <p>In Bash, how does one match a regular expression with multiple criteria against a file name? For example, I'd like to match against all the files with .txt or .log endings.</p> <p>I know how to match one type of criteria:</p> <pre><code>for file in *.log do ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,693
bash
# Regular Expressions for file name matching In Bash, how does one match a regular expression with multiple criteria against a file name? For example, I'd like to match against all the files with .txt or .log endings. I know how to match one type of criteria: ``` for file in *.log do echo "${file}" done ``` ...
Do it the same way you'd invoke `ls`. You can specify multiple wildcards one after the other: ``` for file in *.log *.txt ```
2722996
Is there a gentle way of stopping processes using Windows PowerShell?
18
2010-04-27 16:24:58
<p>I have to stop a browser from a PowerShell script, which I do by piping it into</p> <pre><code>Stop-Process -Force </code></pre> <p>However, this is very abrupt. When the browser is restarted, it detects that it didn't shut down cleanly, and tries to restart the previous session. Is there some way I can tell it to...
8,749
11,677
2015-11-06 20:20:41
2,723,188
16
2010-04-27 16:50:23
153,982
2010-04-27 16:50:23
https://stackoverflow.com/q/2722996
https://stackoverflow.com/a/2723188
<p>Try this to simulate the user closing the app:</p> <pre><code>(Get-Process -Id 10024).CloseMainWindow() </code></pre>
<p>Try this to simulate the user closing the app:</p> <pre><code>(Get-Process -Id 10024).CloseMainWindow() </code></pre>
526
powershell
<h1>Is there a gentle way of stopping processes using Windows PowerShell?</h1> <p>I have to stop a browser from a PowerShell script, which I do by piping it into</p> <pre><code>Stop-Process -Force </code></pre> <p>However, this is very abrupt. When the browser is restarted, it detects that it didn't shut down cleanly...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,694
bash
# Is there a gentle way of stopping processes using Windows PowerShell? I have to stop a browser from a PowerShell script, which I do by piping it into ``` Stop-Process -Force ``` However, this is very abrupt. When the browser is restarted, it detects that it didn't shut down cleanly, and tries to restart the previo...
Try this to simulate the user closing the app: ``` (Get-Process -Id 10024).CloseMainWindow() ```
1344519
How do I add a PowerShell cmdlet or function to my machine so that it is always available?
18
2009-08-28 01:03:03
<p>If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine?</p> <ul> <li>Do I copy it to a particular folder?</li> <li>Do I put its content in a particular file?</li> <li>Do I need to authorize it, or sign it, or give it permission in some way?</li> </ul> <p>I don't want to use it i...
26,216
49
2014-11-30 22:46:09
1,344,771
16
2009-08-28 02:41:41
153,982
2009-08-28 16:50:14
https://stackoverflow.com/q/1344519
https://stackoverflow.com/a/1344771
<p>As Alex mentions, any function defined in your profile or in a script that gets "dotted" into your profile will always be available. The same goes if you use Add-PSSnapin in your profile to add a snapin. The cmdlets in the snapin will always be available. For more information about profiles check out the help top...
<p>As Alex mentions, any function defined in your profile or in a script that gets "dotted" into your profile will always be available. The same goes if you use Add-PSSnapin in your profile to add a snapin. The cmdlets in the snapin will always be available. For more information about profiles check out the help top...
403, 526, 153947
powershell, powershell-cmdlet, profile
<h1>How do I add a PowerShell cmdlet or function to my machine so that it is always available?</h1> <p>If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine?</p> <ul> <li>Do I copy it to a particular folder?</li> <li>Do I put its content in a particular file?</li> <li>Do I need to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,695
bash
# How do I add a PowerShell cmdlet or function to my machine so that it is always available? If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine? - Do I copy it to a particular folder? - Do I put its content in a particular file? - Do I need to authorize it, or sign it, or give ...
As Alex mentions, any function defined in your profile or in a script that gets "dotted" into your profile will always be available. The same goes if you use Add-PSSnapin in your profile to add a snapin. The cmdlets in the snapin will always be available. For more information about profiles check out the help topic: `...
65662031
Firebase app distribution via Fastlane "the server responded with status 403"
17
2021-01-11 06:03:05
<p>I setup Firebase app distribution feature in Fastlane Fastfile to distribute beta version of my iOS app. It was working fine but It suddenly started showing errors.</p> <p>This is how my lane looks like.</p> <pre><code>lane :distribute_beta do |options| sync_code_signing_adhoc() update_build...
15,435
5,886,270
2023-11-07 14:16:06
65,693,239
16
2021-01-12 22:51:22
1,403,997
2021-01-12 22:51:22
https://stackoverflow.com/q/65662031
https://stackoverflow.com/a/65693239
<p>Usually, when you get <em>that</em> specific message it means that the Firebase Refresh Token is no longer valid.</p> <p>So, when you submit the app, at some point, you have to specify the Firebase Refresh Token:</p> <pre><code>... firebase_app_distrubution( ... firebase_cli_token: &quot;&lt;YourFirebaseRefreshT...
<p>Usually, when you get <em>that</em> specific message it means that the Firebase Refresh Token is no longer valid.</p> <p>So, when you submit the app, at some point, you have to specify the Firebase Refresh Token:</p> <pre><code>... firebase_app_distrubution( ... firebase_cli_token: &quot;&lt;YourFirebaseRefreshT...
387, 113585, 140355
bash, fastlane, firebase-app-distribution
<h1>Firebase app distribution via Fastlane "the server responded with status 403"</h1> <p>I setup Firebase app distribution feature in Fastlane Fastfile to distribute beta version of my iOS app. It was working fine but It suddenly started showing errors.</p> <p>This is how my lane looks like.</p> <pre><code>lane :distr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,696
bash
# Firebase app distribution via Fastlane "the server responded with status 403" I setup Firebase app distribution feature in Fastlane Fastfile to distribute beta version of my iOS app. It was working fine but It suddenly started showing errors. This is how my lane looks like. ``` lane :distribute_beta do |options| ...
Usually, when you get *that* specific message it means that the Firebase Refresh Token is no longer valid. So, when you submit the app, at some point, you have to specify the Firebase Refresh Token: ``` ... firebase_app_distrubution( ... firebase_cli_token: "<YourFirebaseRefreshToken>" ) ... ``` You can get this...
53867043
What are the limits to JShell?
17
2018-12-20 10:41:46
<p>I found <a href="https://stackoverflow.com/q/48063408/262852">this</a> question, and this <a href="https://stackoverflow.com/q/48896013/262852">other</a>, so intriguing that it begs several questions, at least for me: </p> <p>Rather open-ended question, but where is <code>jshell</code> <em>confined</em> to? Obvio...
2,409
262,852
2019-01-02 13:52:38
53,868,224
16
2018-12-20 11:55:58
15,472
2018-12-20 12:09:31
https://stackoverflow.com/q/53867043
https://stackoverflow.com/a/53868224
<p><strong>Answering the updated question</strong></p> <p>All problems can be solved with snippets (and with a sufficiently complicated shell script, too). But JShell is best used to debug and learn java - a full-fledged program is much more flexible for all other use-cases.</p> <p><strong>JShell, .jsh and <code>java...
<p><strong>Answering the updated question</strong></p> <p>All problems can be solved with snippets (and with a sufficiently complicated shell script, too). But JShell is best used to debug and learn java - a full-fledged program is much more flexible for all other use-cases.</p> <p><strong>JShell, .jsh and <code>java...
17, 531, 2149, 4658, 116030
java, jshell, jvm, scripting, system-administration
<h1>What are the limits to JShell?</h1> <p>I found <a href="https://stackoverflow.com/q/48063408/262852">this</a> question, and this <a href="https://stackoverflow.com/q/48896013/262852">other</a>, so intriguing that it begs several questions, at least for me: </p> <p>Rather open-ended question, but where is <code>js...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,697
bash
# What are the limits to JShell? I found [this](https://stackoverflow.com/q/48063408/262852) question, and this [other](https://stackoverflow.com/q/48896013/262852), so intriguing that it begs several questions, at least for me: Rather open-ended question, but where is `jshell` *confined* to? Obviously, GUI apps aren...
**Answering the updated question** All problems can be solved with snippets (and with a sufficiently complicated shell script, too). But JShell is best used to debug and learn java - a full-fledged program is much more flexible for all other use-cases. **JShell, .jsh and `java MyClass.java`** [JShell](https://docs.o...
53585993
How can I check if Bash POSIX Mode is enabled?
17
2018-12-03 00:29:27
<p><a href="https://www.gnu.org/software/bash/manual/bash.html#Bash-POSIX-Mode" rel="noreferrer">Bash Reference Manual</a>:</p> <blockquote> <p>Starting Bash with the --posix command-line option or executing ‘set -o posix’ while Bash is running will cause Bash to conform more closely to the POSIX standard by changin...
3,430
9,350,434
2018-12-21 10:40:07
53,586,013
16
2018-12-03 00:31:44
14,122
2018-12-03 00:31:44
https://stackoverflow.com/q/53585993
https://stackoverflow.com/a/53586013
<p>For interactive use,</p> <pre><code>set -o | grep posix </code></pre> <p>...will emit something like:</p> <pre><code>posix off </code></pre> <p>For programmatic use, just enable or disable it (with <code>set -o posix</code> or <code>set +o posix</code> respectively) as suits your needs; there's little ...
<p>For interactive use,</p> <pre><code>set -o | grep posix </code></pre> <p>...will emit something like:</p> <pre><code>posix off </code></pre> <p>For programmatic use, just enable or disable it (with <code>set -o posix</code> or <code>set +o posix</code> respectively) as suits your needs; there's little ...
387
bash
<h1>How can I check if Bash POSIX Mode is enabled?</h1> <p><a href="https://www.gnu.org/software/bash/manual/bash.html#Bash-POSIX-Mode" rel="noreferrer">Bash Reference Manual</a>:</p> <blockquote> <p>Starting Bash with the --posix command-line option or executing ‘set -o posix’ while Bash is running will cause Bash ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,698
bash
# How can I check if Bash POSIX Mode is enabled? [Bash Reference Manual](https://www.gnu.org/software/bash/manual/bash.html#Bash-POSIX-Mode): > Starting Bash with the --posix command-line option or executing ‘set -o posix’ while Bash is running will cause Bash to conform more closely to the POSIX standard by changing...
For interactive use, ``` set -o | grep posix ``` ...will emit something like: ``` posix off ``` For programmatic use, just enable or disable it (with `set -o posix` or `set +o posix` respectively) as suits your needs; there's little reason to ever check the prior value. That said, if you **really** want t...
43662591
wget using --timeout and --tries together
17
2017-04-27 15:57:25
<p>How long would you expect this command to take before exiting?</p> <p><code>wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"</code></p> <p>I would expect a timeout of 1 seconds and 2 tries would mean 2 seconds, but it takes 6.025 seconds</p> <pre><code>wget --timeout=1 --tries=2 "http://www.google....
39,851
1,196,369
2021-04-30 15:04:58
43,664,731
16
2017-04-27 17:50:29
6,770,384
2021-04-30 15:04:58
https://stackoverflow.com/q/43662591
https://stackoverflow.com/a/43664731
<h1>Wrong Number of Retries</h1> <p>Your wget seems to resolve the URL to multiple IP addresses as seen in the second line of your <code>wget</code>'s output. Each IP is then tested with the specified timeout. Unfortunately I haven't found any options to limit the DNS lookup to one address or set a total timeout for al...
<h1>Wrong Number of Retries</h1> <p>Your wget seems to resolve the URL to multiple IP addresses as seen in the second line of your <code>wget</code>'s output. Each IP is then tested with the specified timeout. Unfortunately I haven't found any options to limit the DNS lookup to one address or set a total timeout for al...
58, 387, 5583
bash, linux, wget
<h1>wget using --timeout and --tries together</h1> <p>How long would you expect this command to take before exiting?</p> <p><code>wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"</code></p> <p>I would expect a timeout of 1 seconds and 2 tries would mean 2 seconds, but it takes 6.025 seconds</p> <pre><...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,699
bash
# wget using --timeout and --tries together How long would you expect this command to take before exiting? `wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"` I would expect a timeout of 1 seconds and 2 tries would mean 2 seconds, but it takes 6.025 seconds ``` wget --timeout=1 --tries=2 "http://www.g...
# Wrong Number of Retries Your wget seems to resolve the URL to multiple IP addresses as seen in the second line of your `wget`'s output. Each IP is then tested with the specified timeout. Unfortunately I haven't found any options to limit the DNS lookup to one address or set a total timeout for all IPs together. But ...
37772712
zsh: how to make tab completion need no space to next word after cursor?
17
2016-06-12 09:31:37
<p>There is an annoying difference between <code>zsh</code> and <code>bash</code> tab completion:</p> <p>Imagine you write some command and want to add something at the beginning of the line:</p> <pre><code>$ compute --some --stuff </code></pre> <p>then you jump to the beginning of the line and line and start to wri...
2,892
1,668,622
2016-06-12 09:39:43
37,772,771
16
2016-06-12 09:39:43
887,539
2016-06-12 09:39:43
https://stackoverflow.com/q/37772712
https://stackoverflow.com/a/37772771
<p>Just looked around in my <code>.zshrc</code> file and I think this is what you want:</p> <pre><code>bindkey '^i' expand-or-complete-prefix </code></pre> <p>Where <code>^i</code> is <code>&lt;Ctrl-I&gt;</code> which is usually tab.</p>
<p>Just looked around in my <code>.zshrc</code> file and I think this is what you want:</p> <pre><code>bindkey '^i' expand-or-complete-prefix </code></pre> <p>Where <code>^i</code> is <code>&lt;Ctrl-I&gt;</code> which is usually tab.</p>
387, 3791, 4682, 12891
autocomplete, bash, tab-completion, zsh
<h1>zsh: how to make tab completion need no space to next word after cursor?</h1> <p>There is an annoying difference between <code>zsh</code> and <code>bash</code> tab completion:</p> <p>Imagine you write some command and want to add something at the beginning of the line:</p> <pre><code>$ compute --some --stuff </co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,700
bash
# zsh: how to make tab completion need no space to next word after cursor? There is an annoying difference between `zsh` and `bash` tab completion: Imagine you write some command and want to add something at the beginning of the line: ``` $ compute --some --stuff ``` then you jump to the beginning of the line and l...
Just looked around in my `.zshrc` file and I think this is what you want: ``` bindkey '^i' expand-or-complete-prefix ``` Where `^i` is `<Ctrl-I>` which is usually tab.
21000989
How can I create a PowerShell "main" function?
17
2014-01-08 16:18:05
<p>I've used many scripting languages in the past, and am now learning PowerShell. In these other languages I typically define my main logic prior to defining my functions, so someone reading the code will focus on the main logic first. Often this takes the form of creating a "main" function or class at the top of the ...
44,497
7,432
2024-12-12 01:24:50
21,001,364
16
2014-01-08 16:36:06
702,944
2016-06-17 10:52:18
https://stackoverflow.com/q/21000989
https://stackoverflow.com/a/21001364
<p>Scripts are read from the top to the bottom, so you can't use any references before they are initiated. You could however create a script/scriptblock that simulates how programming languages work.</p> <p>In programming languages like c#, the <code>main</code> part is a function. When the app is done loading the nec...
<p>Scripts are read from the top to the bottom, so you can't use any references before they are initiated. You could however create a script/scriptblock that simulates how programming languages work.</p> <p>In programming languages like c#, the <code>main</code> part is a function. When the app is done loading the nec...
526
powershell
<h1>How can I create a PowerShell "main" function?</h1> <p>I've used many scripting languages in the past, and am now learning PowerShell. In these other languages I typically define my main logic prior to defining my functions, so someone reading the code will focus on the main logic first. Often this takes the form o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,701
bash
# How can I create a PowerShell "main" function? I've used many scripting languages in the past, and am now learning PowerShell. In these other languages I typically define my main logic prior to defining my functions, so someone reading the code will focus on the main logic first. Often this takes the form of creatin...
Scripts are read from the top to the bottom, so you can't use any references before they are initiated. You could however create a script/scriptblock that simulates how programming languages work. In programming languages like c#, the `main` part is a function. When the app is done loading the necessary parts(like cor...
19961319
reading in from stdin from a command executed with xargs
17
2013-11-13 18:15:06
<p>Using <code>xargs</code> did something I didn't quite expect, though I guess it sort of makes sense. This is not what I did, but this is an example which should show what happened.</p> <h1>fn.sh</h1> <pre><code>#!/usr/bin/bash index=1 for arg in &quot;$@&quot;; do echo &quot;Arg #$index = '$arg'&quot;; let ++index;...
8,109
1,366,368
2017-12-17 20:21:47
19,963,123
16
2013-11-13 19:56:13
1,566,221
2013-11-13 19:56:13
https://stackoverflow.com/q/19961319
https://stackoverflow.com/a/19963123
<p>I've never used cygwin, but normally I'd do something like this:</p> <pre><code>xargs -a &lt;(echo boo hoo) ./fn.sh </code></pre> <p><code>-a</code> tells xargs to read from a file, and the <code>&lt;( )</code> syntax (which might or might not work with cygwin) is process substitution, which effectively creates a ...
<p>I've never used cygwin, but normally I'd do something like this:</p> <pre><code>xargs -a &lt;(echo boo hoo) ./fn.sh </code></pre> <p><code>-a</code> tells xargs to read from a file, and the <code>&lt;( )</code> syntax (which might or might not work with cygwin) is process substitution, which effectively creates a ...
387, 1731, 10326
bash, cygwin, xargs
<h1>reading in from stdin from a command executed with xargs</h1> <p>Using <code>xargs</code> did something I didn't quite expect, though I guess it sort of makes sense. This is not what I did, but this is an example which should show what happened.</p> <h1>fn.sh</h1> <pre><code>#!/usr/bin/bash index=1 for arg in &quo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,702
bash
# reading in from stdin from a command executed with xargs Using `xargs` did something I didn't quite expect, though I guess it sort of makes sense. This is not what I did, but this is an example which should show what happened. # fn.sh ``` #!/usr/bin/bash index=1 for arg in "$@"; do echo "Arg #$index = '$arg'"; let...
I've never used cygwin, but normally I'd do something like this: ``` xargs -a <(echo boo hoo) ./fn.sh ``` `-a` tells xargs to read from a file, and the `<( )` syntax (which might or might not work with cygwin) is process substitution, which effectively creates a named object (either a named pipe or a path starting `/...
11450153
Powershell analogue of Bash's `set -e`
17
2012-07-12 10:44:48
<p>How can I make Powershell behave like Bash with its flag <code>set -e</code>? <code>set -o errexit</code> makes a Bash script "Exit immediately if a simple command exits with a non-zero status". </p> <p>I thought I could do this by setting <code>$ErrorActionPreference="Stop"</code> but this doesn't seem to work. Su...
5,755
284,795
2024-08-07 18:52:16
11,450,852
16
2012-07-12 11:28:32
73,070
2021-02-24 15:17:20
https://stackoverflow.com/q/11450153
https://stackoverflow.com/a/11450852
<p><code>$ErrorActionPreference</code> works as intended, it's just that exit codes from native programs are not nearly as well-behaved as PowerShell cmdlets.</p> <p>For a <code>cmdlet</code> the error condition is fairly easy to determine: Did an exception happen or not? So the following would not reach the <code>Writ...
<p><code>$ErrorActionPreference</code> works as intended, it's just that exit codes from native programs are not nearly as well-behaved as PowerShell cmdlets.</p> <p>For a <code>cmdlet</code> the error condition is fairly easy to determine: Did an exception happen or not? So the following would not reach the <code>Writ...
1, 387, 526
.net, bash, powershell
<h1>Powershell analogue of Bash's `set -e`</h1> <p>How can I make Powershell behave like Bash with its flag <code>set -e</code>? <code>set -o errexit</code> makes a Bash script "Exit immediately if a simple command exits with a non-zero status". </p> <p>I thought I could do this by setting <code>$ErrorActionPreference...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,703
bash
# Powershell analogue of Bash's `set -e` How can I make Powershell behave like Bash with its flag `set -e`? `set -o errexit` makes a Bash script "Exit immediately if a simple command exits with a non-zero status". I thought I could do this by setting `$ErrorActionPreference="Stop"` but this doesn't seem to work. Supp...
`$ErrorActionPreference` works as intended, it's just that exit codes from native programs are not nearly as well-behaved as PowerShell cmdlets. For a `cmdlet` the error condition is fairly easy to determine: Did an exception happen or not? So the following would not reach the `Write-Host` statement with `$ErrorAction...
11302297
Automate import of Java (Android) projects into Eclipse workspace through commandline
17
2012-07-02 22:59:20
<p>I'm trying to automate importing projects to an Eclipse workspace via commandline (using a bash script). I have seen many posts suggesting using the CDT headless build even for non-C/C++ projects, but I want to avoid having to download CDT as my projects are all Java/Android projects and I want to be able to automat...
5,282
1,426,725
2014-03-25 12:48:19
11,435,911
16
2012-07-11 15:18:27
398,309
2014-03-25 12:48:19
https://stackoverflow.com/q/11302297
https://stackoverflow.com/a/11435911
<p>Unfortunately, JDT distribution doesn't have any application that would support <strong>-import</strong> argument, like CDT's <code>org.eclipse.cdt.managedbuilder.core.headlessbuild</code>. But you can easily write a simple one:</p> <pre><code>package test.myapp; import java.util.LinkedList; import java.util.List;...
<p>Unfortunately, JDT distribution doesn't have any application that would support <strong>-import</strong> argument, like CDT's <code>org.eclipse.cdt.managedbuilder.core.headlessbuild</code>. But you can easily write a simple one:</p> <pre><code>package test.myapp; import java.util.LinkedList; import java.util.List;...
17, 53, 387, 531, 1386
android, bash, eclipse, java, scripting
<h1>Automate import of Java (Android) projects into Eclipse workspace through commandline</h1> <p>I'm trying to automate importing projects to an Eclipse workspace via commandline (using a bash script). I have seen many posts suggesting using the CDT headless build even for non-C/C++ projects, but I want to avoid havin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,704
bash
# Automate import of Java (Android) projects into Eclipse workspace through commandline I'm trying to automate importing projects to an Eclipse workspace via commandline (using a bash script). I have seen many posts suggesting using the CDT headless build even for non-C/C++ projects, but I want to avoid having to down...
Unfortunately, JDT distribution doesn't have any application that would support **-import** argument, like CDT's `org.eclipse.cdt.managedbuilder.core.headlessbuild`. But you can easily write a simple one: ``` package test.myapp; import java.util.LinkedList; import java.util.List; import org.eclipse.core.resources.IP...
9047930
How to uninstall own app from /system/app?
17
2012-01-28 19:32:09
<p>I'm able to install own application into /system/app using adb shell commands. But how to uninstall it? Is there any commands to do it? My phone is rooted.</p>
49,815
991,737
2020-04-18 16:32:42
9,048,026
16
2012-01-28 19:46:43
991,737
2018-11-16 11:05:22
https://stackoverflow.com/q/9047930
https://stackoverflow.com/a/9048026
<p>Manual uninstall using ADB :<br> <a href="http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/" rel="nofollow noreferrer">http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/</a></p> <p>During website downtime (like now) see crawled snapshot here:<br> <a href="https://web.a...
<p>Manual uninstall using ADB :<br> <a href="http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/" rel="nofollow noreferrer">http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/</a></p> <p>During website downtime (like now) see crawled snapshot here:<br> <a href="https://web.a...
390, 1386, 14038
android, shell, uninstallation
<h1>How to uninstall own app from /system/app?</h1> <p>I'm able to install own application into /system/app using adb shell commands. But how to uninstall it? Is there any commands to do it? My phone is rooted.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,705
bash
# How to uninstall own app from /system/app? I'm able to install own application into /system/app using adb shell commands. But how to uninstall it? Is there any commands to do it? My phone is rooted.
Manual uninstall using ADB : <http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/> During website downtime (like now) see crawled snapshot here: <https://web.archive.org/web/20180222063358/http://www.careace.net/2010/05/12/how-to-remove-android-apps-through-adb/> Programmatically: ``` p...
7154800
What is the Bash Escape Character "\c"?
17
2011-08-22 23:33:21
<p>What is the name and function of the <code>\c</code> escape character in Bash? What is its numeric value? I have seen that <code>\cx</code> is a control character, but what about plain <code>\c</code>? It seems that:</p> <pre><code>echo -e "Hello World\c" </code></pre> <p>and</p> <pre><code>echo -en "Hello World"...
29,915
834,176
2021-07-30 08:02:57
7,154,820
16
2011-08-22 23:37:18
14,860
2011-08-22 23:47:08
https://stackoverflow.com/q/7154800
https://stackoverflow.com/a/7154820
<p>That's actually specific to some versions of <code>echo</code> (I'm pretty sure that <code>\c</code> came from SysV while the <code>-n</code> version was a BSD-ism).</p> <p>It simply means don't output the trailing newline.</p>
<p>That's actually specific to some versions of <code>echo</code> (I'm pretty sure that <code>\c</code> came from SysV while the <code>-n</code> version was a BSD-ism).</p> <p>It simply means don't output the trailing newline.</p>
34, 387, 4804, 13824
bash, echo, escaping, unix
<h1>What is the Bash Escape Character "\c"?</h1> <p>What is the name and function of the <code>\c</code> escape character in Bash? What is its numeric value? I have seen that <code>\cx</code> is a control character, but what about plain <code>\c</code>? It seems that:</p> <pre><code>echo -e "Hello World\c" </code></pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,706
bash
# What is the Bash Escape Character "\c"? What is the name and function of the `\c` escape character in Bash? What is its numeric value? I have seen that `\cx` is a control character, but what about plain `\c`? It seems that: ``` echo -e "Hello World\c" ``` and ``` echo -en "Hello World" ``` are equivalent. Howeve...
That's actually specific to some versions of `echo` (I'm pretty sure that `\c` came from SysV while the `-n` version was a BSD-ism). It simply means don't output the trailing newline.
6931873
Powershell: how to implement standard switches?
17
2011-08-03 19:06:26
<p>For things like -WhatIf, we have $PSCmdlet.ShouldProcess() given to us by the [CmdletBinding] attribute. Are there other such tools or practices for implementing common command line arguments such as -Verbose, -Debug, -PassThru, etc?</p>
2,448
307,163
2011-08-04 12:47:09
6,933,098
16
2011-08-03 20:48:29
291,709
2011-08-04 12:47:09
https://stackoverflow.com/q/6931873
https://stackoverflow.com/a/6933098
<p><code>Write-Debug</code> and <code>Write-Verbose</code> handle the <code>-Debug</code> and <code>-Verbose</code> parameters automatically.</p> <p><code>-PassThru</code> isn't technically a common parameter, but you can implement it like:</p> <pre><code>function PassTest { param( [switch] $PassThru ...
<p><code>Write-Debug</code> and <code>Write-Verbose</code> handle the <code>-Debug</code> and <code>-Verbose</code> parameters automatically.</p> <p><code>-PassThru</code> isn't technically a common parameter, but you can implement it like:</p> <pre><code>function PassTest { param( [switch] $PassThru ...
277, 526, 28622, 31134, 35061
command-line-arguments, debugging, passthru, powershell, verbose
<h1>Powershell: how to implement standard switches?</h1> <p>For things like -WhatIf, we have $PSCmdlet.ShouldProcess() given to us by the [CmdletBinding] attribute. Are there other such tools or practices for implementing common command line arguments such as -Verbose, -Debug, -PassThru, etc?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,707
bash
# Powershell: how to implement standard switches? For things like -WhatIf, we have $PSCmdlet.ShouldProcess() given to us by the [CmdletBinding] attribute. Are there other such tools or practices for implementing common command line arguments such as -Verbose, -Debug, -PassThru, etc?
`Write-Debug` and `Write-Verbose` handle the `-Debug` and `-Verbose` parameters automatically. `-PassThru` isn't technically a common parameter, but you can implement it like: ``` function PassTest { param( [switch] $PassThru ) process { if($PassThru) {$_} } } 1..10|PassTest -PassThru...
5130190
Force a shell script to fflush
17
2011-02-26 22:40:52
<p>I was wondering if it was possible to tell bash that all calls to <code>echo</code> or <code>printf</code> should be followed up by a subsequent call to <code>fflush()</code> on stdout/stderr respectively?</p> <p>A quick and dirty solution would be to write my own printf implementation that did this and use it in l...
30,382
null
2017-09-24 16:22:43
5,140,923
16
2011-02-28 10:42:24
4,421
2017-09-24 16:22:43
https://stackoverflow.com/q/5130190
https://stackoverflow.com/a/5140923
<p>If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line <a href="http://www.pixelbeat.org/programming/stdio_buffering/" rel="noreferrer">http://www.pixelbeat.org/programming/stdio_buffering/</a></p> <p>tl;dr: ins...
<p>If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line <a href="http://www.pixelbeat.org/programming/stdio_buffering/" rel="noreferrer">http://www.pixelbeat.org/programming/stdio_buffering/</a></p> <p>tl;dr: ins...
58, 387, 390
bash, linux, shell
<h1>Force a shell script to fflush</h1> <p>I was wondering if it was possible to tell bash that all calls to <code>echo</code> or <code>printf</code> should be followed up by a subsequent call to <code>fflush()</code> on stdout/stderr respectively?</p> <p>A quick and dirty solution would be to write my own printf impl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,708
bash
# Force a shell script to fflush I was wondering if it was possible to tell bash that all calls to `echo` or `printf` should be followed up by a subsequent call to `fflush()` on stdout/stderr respectively? A quick and dirty solution would be to write my own printf implementation that did this and use it in lieu of ei...
If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line <http://www.pixelbeat.org/programming/stdio_buffering/> tl;dr: instead of `printf ...` try to put to the script `stdbuf -o0 printf ..`, or `stdbuf -oL printf ....
4547789
command line arguments in bash to Rscript
17
2010-12-28 17:05:08
<p>I have a bash script that creates a csv file and an R file that creates graphs from that.</p> <p>At the end of the bash script I call <code>Rscript Graphs.R 10</code></p> <p>The response I get is as follows:</p> <pre><code>Error in is.vector(X) : subscript out of bounds Calls: print ... &lt;Anonymous&gt; -&gt; la...
20,340
556,211
2012-11-29 06:11:03
4,574,903
16
2011-01-01 17:27:30
89,806
2011-01-02 22:20:14
https://stackoverflow.com/q/4547789
https://stackoverflow.com/a/4574903
<p>With the following in args.R</p> <pre><code>print(commandArgs(TRUE)[1]) </code></pre> <p>and the following in args.sh</p> <pre><code>Rscript args.R 10 </code></pre> <p>I get the following output from <code>bash args.sh</code></p> <pre><code>[1] "10" </code></pre> <p>and no error. If necessary, convert to a num...
<p>With the following in args.R</p> <pre><code>print(commandArgs(TRUE)[1]) </code></pre> <p>and the following in args.sh</p> <pre><code>Rscript args.R 10 </code></pre> <p>I get the following output from <code>bash args.sh</code></p> <pre><code>[1] "10" </code></pre> <p>and no error. If necessary, convert to a num...
387, 2313, 4452
arguments, bash, r
<h1>command line arguments in bash to Rscript</h1> <p>I have a bash script that creates a csv file and an R file that creates graphs from that.</p> <p>At the end of the bash script I call <code>Rscript Graphs.R 10</code></p> <p>The response I get is as follows:</p> <pre><code>Error in is.vector(X) : subscript out of...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,709
bash
# command line arguments in bash to Rscript I have a bash script that creates a csv file and an R file that creates graphs from that. At the end of the bash script I call `Rscript Graphs.R 10` The response I get is as follows: ``` Error in is.vector(X) : subscript out of bounds Calls: print ... <Anonymous> -> lappl...
With the following in args.R ``` print(commandArgs(TRUE)[1]) ``` and the following in args.sh ``` Rscript args.R 10 ``` I get the following output from `bash args.sh` ``` [1] "10" ``` and no error. If necessary, convert to a numberic type using `as.numeric(commandArgs(TRUE)[1])`.
1510481
How can I detect that emacs-server is running from a shell prompt?
17
2009-10-02 16:06:54
<p>I want to have my .bashrc detect if running emacsclient would work in lieu of running emacs. Basically:</p> <pre><code>if emacs_server_is_running; then EDITOR=emacsclient VISUAL=emacsclient else EDITOR=emacs VISUAL=emacs fi </code></pre> <p>What would I put in the <code>emacs_server_is_running</co...
9,280
23,309
2021-03-04 05:10:46
1,510,753
16
2009-10-02 17:03:11
32,538
2009-10-02 17:03:11
https://stackoverflow.com/q/1510481
https://stackoverflow.com/a/1510753
<p>You're making this too hard. From the the <code>emacsclient(1)</code> man page:</p> <blockquote> -a, --alternate-editor=EDITOR if the Emacs server is not running, run the specified editor instead. This can also be specified via the `ALTERNATE_EDITOR' environment variable. If the value of EDITOR is the empty str...
<p>You're making this too hard. From the the <code>emacsclient(1)</code> man page:</p> <blockquote> -a, --alternate-editor=EDITOR if the Emacs server is not running, run the specified editor instead. This can also be specified via the `ALTERNATE_EDITOR' environment variable. If the value of EDITOR is the empty str...
387, 390
bash, shell
<h1>How can I detect that emacs-server is running from a shell prompt?</h1> <p>I want to have my .bashrc detect if running emacsclient would work in lieu of running emacs. Basically:</p> <pre><code>if emacs_server_is_running; then EDITOR=emacsclient VISUAL=emacsclient else EDITOR=emacs VISUAL=emacs fi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,710
bash
# How can I detect that emacs-server is running from a shell prompt? I want to have my .bashrc detect if running emacsclient would work in lieu of running emacs. Basically: ``` if emacs_server_is_running; then EDITOR=emacsclient VISUAL=emacsclient else EDITOR=emacs VISUAL=emacs fi ``` What would I pu...
You're making this too hard. From the the `emacsclient(1)` man page: > -a, --alternate-editor=EDITOR > if the Emacs server is not running, run the specified editor instead. This can also be specified via the `ALTERNATE_EDITOR' environment variable. > If the value of EDITOR is the empty string, then Emacs is started in...
25360470
ffmpeg capture current frame and overwrite the image output file
16
2014-08-18 09:48:39
<p>I am trying to extract the image file from a RTSP stream url every second (could be every 1 min also) and overwrite this image file.</p> <p>my below code works but it outputs to multiple image jpg files: <code>img1.jpg, img2.jpg, img3.jpg...</code></p> <pre><code>ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -r 1...
49,500
1,217,856
2022-05-17 05:52:00
25,379,282
16
2014-08-19 08:53:11
928,492
2014-08-19 08:53:11
https://stackoverflow.com/q/25360470
https://stackoverflow.com/a/25379282
<p>Following command line should work for you. </p> <pre><code>ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -updatefirst 1 img.jpg </code></pre>
<p>Following command line should work for you. </p> <pre><code>ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -updatefirst 1 img.jpg </code></pre>
387, 3847
bash, ffmpeg
<h1>ffmpeg capture current frame and overwrite the image output file</h1> <p>I am trying to extract the image file from a RTSP stream url every second (could be every 1 min also) and overwrite this image file.</p> <p>my below code works but it outputs to multiple image jpg files: <code>img1.jpg, img2.jpg, img3.jpg...<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,711
bash
# ffmpeg capture current frame and overwrite the image output file I am trying to extract the image file from a RTSP stream url every second (could be every 1 min also) and overwrite this image file. my below code works but it outputs to multiple image jpg files: `img1.jpg, img2.jpg, img3.jpg...` ``` ffmpeg -i rtsp:...
Following command line should work for you. ``` ffmpeg -i rtsp://IP_ADDRESS/live.sdp -f image2 -updatefirst 1 img.jpg ```
14859148
How to set a conditional newline in PS1?
16
2013-02-13 17:17:15
<p>I am trying to set <code>PS1</code> so that it prints out something just right after login, but preceded with a newline later.</p> <p>Suppose <code>export PS1="\h:\W \u\$ "</code>, so first time (i.e., right after login) you get:</p> <pre><code>hostname:~ username$ </code></pre> <p>I’ve been trying something lik...
8,110
11,895
2021-11-09 16:39:50
14,859,615
16
2013-02-13 17:40:24
7,412
2013-02-13 17:40:24
https://stackoverflow.com/q/14859148
https://stackoverflow.com/a/14859615
<p>Try the following:</p> <pre><code>function __ps1_newline_login { if [[ -z "${PS1_NEWLINE_LOGIN}" ]]; then PS1_NEWLINE_LOGIN=true else printf '\n' fi } PROMPT_COMMAND='__ps1_newline_login' export PS1="\h:\W \u\$ " </code></pre> <p>Explanation:</p> <ul> <li><code>PROMPT_COMMAND</code> is a special ba...
<p>Try the following:</p> <pre><code>function __ps1_newline_login { if [[ -z "${PS1_NEWLINE_LOGIN}" ]]; then PS1_NEWLINE_LOGIN=true else printf '\n' fi } PROMPT_COMMAND='__ps1_newline_login' export PS1="\h:\W \u\$ " </code></pre> <p>Explanation:</p> <ul> <li><code>PROMPT_COMMAND</code> is a special ba...
387, 390, 53034
bash, ps1, shell
<h1>How to set a conditional newline in PS1?</h1> <p>I am trying to set <code>PS1</code> so that it prints out something just right after login, but preceded with a newline later.</p> <p>Suppose <code>export PS1="\h:\W \u\$ "</code>, so first time (i.e., right after login) you get:</p> <pre><code>hostname:~ username$...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,712
bash
# How to set a conditional newline in PS1? I am trying to set `PS1` so that it prints out something just right after login, but preceded with a newline later. Suppose `export PS1="\h:\W \u\$ "`, so first time (i.e., right after login) you get: ``` hostname:~ username$ ``` I’ve been trying something like in my `~/.b...
Try the following: ``` function __ps1_newline_login { if [[ -z "${PS1_NEWLINE_LOGIN}" ]]; then PS1_NEWLINE_LOGIN=true else printf '\n' fi } PROMPT_COMMAND='__ps1_newline_login' export PS1="\h:\W \u\$ " ``` Explanation: - `PROMPT_COMMAND` is a special bash variable which is executed every time before t...
11673287
How to remove a word prefix using grep?
16
2012-07-26 15:56:29
<p>How can I remove the beginning of a word using grep? For example, I have a file that contains this:</p> <pre><code>www.abc.com </code></pre> <p>I only need the this part:</p> <pre><code>abc.com </code></pre> <p>Sorry for the basic question, but I have no experience with Linux.</p>
62,608
1,476,749
2023-07-15 20:07:41
11,673,362
16
2012-07-26 16:01:34
25,450
2012-07-27 12:30:24
https://stackoverflow.com/q/11673287
https://stackoverflow.com/a/11673362
<p>You don't edit strings with <code>grep</code> in Unix shell, <code>grep</code> is usually used to find or remove some lines from the text. You'd rather use <code>sed</code> instead:</p> <pre><code>$ echo www.example.com | sed 's/^[^\.]\+\.//' example.com </code></pre> <p>You'll need to learn regular expressions <a...
<p>You don't edit strings with <code>grep</code> in Unix shell, <code>grep</code> is usually used to find or remove some lines from the text. You'd rather use <code>sed</code> instead:</p> <pre><code>$ echo www.example.com | sed 's/^[^\.]\+\.//' example.com </code></pre> <p>You'll need to learn regular expressions <a...
18, 58, 390, 5282
linux, regex, sed, shell
<h1>How to remove a word prefix using grep?</h1> <p>How can I remove the beginning of a word using grep? For example, I have a file that contains this:</p> <pre><code>www.abc.com </code></pre> <p>I only need the this part:</p> <pre><code>abc.com </code></pre> <p>Sorry for the basic question, but I have no experience wi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,713
bash
# How to remove a word prefix using grep? How can I remove the beginning of a word using grep? For example, I have a file that contains this: ``` www.abc.com ``` I only need the this part: ``` abc.com ``` Sorry for the basic question, but I have no experience with Linux.
You don't edit strings with `grep` in Unix shell, `grep` is usually used to find or remove some lines from the text. You'd rather use `sed` instead: ``` $ echo www.example.com | sed 's/^[^\.]\+\.//' example.com ``` You'll need to learn regular expressions [to use it effectively](http://www.grymoire.com/Unix/Sed.html)...
8627819
How to print result of shell script in CMake?
16
2011-12-25 01:39:53
<p>If I want to check currently exported environment variables, I do this in shell.</p> <pre><code>export </code></pre> <p>In CMake, I do this to print something.</p> <pre><code>MESSAGE ("This is message.") </code></pre> <p>How can I print former one with CMake?</p> <p>I know that CMake is stand for cross-platform...
32,048
246,776
2011-12-25 09:25:04
8,628,994
16
2011-12-25 09:25:04
13,051
2011-12-25 09:25:04
https://stackoverflow.com/q/8627819
https://stackoverflow.com/a/8628994
<p>If you want to know the value of a specific variable, you can use <code>$ENV{varname}</code>:</p> <pre><code>message(STATUS $ENV{PATH}) </code></pre> <p>If you want to see <strong>all</strong> variables, you probably need to resort to invoking an external command such as <code>env</code> (on Unix) or <code>set</co...
<p>If you want to know the value of a specific variable, you can use <code>$ENV{varname}</code>:</p> <pre><code>message(STATUS $ENV{PATH}) </code></pre> <p>If you want to see <strong>all</strong> variables, you probably need to resort to invoking an external command such as <code>env</code> (on Unix) or <code>set</co...
87, 390, 8822, 9013
cmake, environment-variables, printing, shell
<h1>How to print result of shell script in CMake?</h1> <p>If I want to check currently exported environment variables, I do this in shell.</p> <pre><code>export </code></pre> <p>In CMake, I do this to print something.</p> <pre><code>MESSAGE ("This is message.") </code></pre> <p>How can I print former one with CMake...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,714
bash
# How to print result of shell script in CMake? If I want to check currently exported environment variables, I do this in shell. ``` export ``` In CMake, I do this to print something. ``` MESSAGE ("This is message.") ``` How can I print former one with CMake? I know that CMake is stand for cross-platform building...
If you want to know the value of a specific variable, you can use `$ENV{varname}`: ``` message(STATUS $ENV{PATH}) ``` If you want to see **all** variables, you probably need to resort to invoking an external command such as `env` (on Unix) or `set` (on Windows): ``` # Windows execute_process(COMMAND cmd /c set OUTPU...
5265890
Writing to error stream in Powershell using Write-Error
16
2011-03-10 21:04:03
<p>Why isn't Powershell's <a href="http://technet.microsoft.com/en-us/library/dd315265.aspx" rel="noreferrer"><code>Write-Error</code></a> cmdlet working for me? My output doesn't look like the examples in the documentation:</p> <pre><code>PS C:\&gt; Write-Error "This is an error" Write-Error "This is an error" : This...
58,161
111,327
2021-10-29 17:52:14
5,654,822
16
2011-04-13 19:53:31
24,315
2011-04-13 20:00:13
https://stackoverflow.com/q/5265890
https://stackoverflow.com/a/5654822
<p>To get output similar to write-warning, you can do this:</p> <pre><code>$Host.UI.WriteErrorLine("This is an error") </code></pre> <p>(props to Chris Sears for this answer)</p>
<p>To get output similar to write-warning, you can do this:</p> <pre><code>$Host.UI.WriteErrorLine("This is an error") </code></pre> <p>(props to Chris Sears for this answer)</p>
526, 66845
powershell, write-error
<h1>Writing to error stream in Powershell using Write-Error</h1> <p>Why isn't Powershell's <a href="http://technet.microsoft.com/en-us/library/dd315265.aspx" rel="noreferrer"><code>Write-Error</code></a> cmdlet working for me? My output doesn't look like the examples in the documentation:</p> <pre><code>PS C:\&gt; Wri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,715
bash
# Writing to error stream in Powershell using Write-Error Why isn't Powershell's [`Write-Error`](http://technet.microsoft.com/en-us/library/dd315265.aspx) cmdlet working for me? My output doesn't look like the examples in the documentation: ``` PS C:\> Write-Error "This is an error" Write-Error "This is an error" : T...
To get output similar to write-warning, you can do this: ``` $Host.UI.WriteErrorLine("This is an error") ``` (props to Chris Sears for this answer)
2640374
bash "map" equivalent: run command on each file
16
2010-04-14 19:25:11
<p>I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this? </p> <p>For example, say I have a program <code>data</code> which outputs an important number about a file:</p> <pre><code>./data foo 137 ./data bar 42 </code></pre> <p>I want t...
14,302
15,055
2015-08-16 23:34:33
2,657,287
16
2010-04-17 04:53:48
317,052
2010-04-17 04:53:48
https://stackoverflow.com/q/2640374
https://stackoverflow.com/a/2657287
<p>If you are just trying to execute your <code>data</code> program on a bunch of files, the easiest/least complicated way is to use <code>-exec</code> in <code>find</code>.</p> <p>Say you wanted to execute <code>data</code> on all txt files in the current directory (and subdirectories). This is all you'd need:</p> <...
<p>If you are just trying to execute your <code>data</code> program on a bunch of files, the easiest/least complicated way is to use <code>-exec</code> in <code>find</code>.</p> <p>Say you wanted to execute <code>data</code> on all txt files in the current directory (and subdirectories). This is all you'd need:</p> <...
387, 390, 1834
bash, dictionary, shell
<h1>bash "map" equivalent: run command on each file</h1> <p>I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this? </p> <p>For example, say I have a program <code>data</code> which outputs an important number about a file:</p> <pre><cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,716
bash
# bash "map" equivalent: run command on each file I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this? For example, say I have a program `data` which outputs an important number about a file: ``` ./data foo 137 ./data bar 42 ``` I w...
If you are just trying to execute your `data` program on a bunch of files, the easiest/least complicated way is to use `-exec` in `find`. Say you wanted to execute `data` on all txt files in the current directory (and subdirectories). This is all you'd need: ``` find . -name "*.txt" -exec data {} \; ``` If you wante...
1603389
Shell: simple way to get all lines before first blank line
16
2009-10-21 20:26:37
<p>What's the best shell command to output the lines of a file until you encounter the first blank line? For example:</p> <pre><code>output these lines but do not output anything after the above blank line (or the blank line itself) </code></pre> <p>awk? something else?</p>
14,111
157,237
2009-10-22 13:20:09
1,603,436
16
2009-10-21 20:33:03
42,706
2009-10-21 20:33:03
https://stackoverflow.com/q/1603389
https://stackoverflow.com/a/1603436
<pre><code>sed -e '/^$/,$d' &lt;&lt;EOF this is text so is this but not this or this EOF </code></pre>
<pre><code>sed -e '/^$/,$d' &lt;&lt;EOF this is text so is this but not this or this EOF </code></pre>
390, 990
awk, shell
<h1>Shell: simple way to get all lines before first blank line</h1> <p>What's the best shell command to output the lines of a file until you encounter the first blank line? For example:</p> <pre><code>output these lines but do not output anything after the above blank line (or the blank line itself) </code></pre> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,717
bash
# Shell: simple way to get all lines before first blank line What's the best shell command to output the lines of a file until you encounter the first blank line? For example: ``` output these lines but do not output anything after the above blank line (or the blank line itself) ``` awk? something else?
``` sed -e '/^$/,$d' <<EOF this is text so is this but not this or this EOF ```
54607309
How to detect OS and load ZSH settings conditionally?
15
2019-02-09 14:45:01
<p>I use several different OS's at home and work and I want to be able to load platorm-specific ZSH settings conditionally, depending on which OS I'm using at the given moment.</p> <p>I tried this but it doesn't load everything I expect:</p> <pre><code># Condtitional loading of zsh settings per platform if command a...
9,378
327,619
2023-02-09 03:08:42
54,618,022
16
2019-02-10 15:37:10
4,432,299
2023-02-09 03:08:42
https://stackoverflow.com/q/54607309
https://stackoverflow.com/a/54618022
<h2>Revised Answer (2020-Feb-09)</h2> <p>Thanks to @Cyberbeni for reminding me that <code>apt</code> on macOS would incorrectly match the system Java runtime's <strong>A</strong>nnotation <strong>P</strong>rocessing <strong>T</strong>ool. Rolling up the necessary changes, we now have:</p> <pre class="lang-bash prettypr...
<h2>Revised Answer (2020-Feb-09)</h2> <p>Thanks to @Cyberbeni for reminding me that <code>apt</code> on macOS would incorrectly match the system Java runtime's <strong>A</strong>nnotation <strong>P</strong>rocessing <strong>T</strong>ool. Rolling up the necessary changes, we now have:</p> <pre class="lang-bash prettypr...
58, 387, 390, 3791, 93854
bash, linux, oh-my-zsh, shell, zsh
<h1>How to detect OS and load ZSH settings conditionally?</h1> <p>I use several different OS's at home and work and I want to be able to load platorm-specific ZSH settings conditionally, depending on which OS I'm using at the given moment.</p> <p>I tried this but it doesn't load everything I expect:</p> <pre><code># ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,718
bash
# How to detect OS and load ZSH settings conditionally? I use several different OS's at home and work and I want to be able to load platorm-specific ZSH settings conditionally, depending on which OS I'm using at the given moment. I tried this but it doesn't load everything I expect: ``` # Condtitional loading of zsh...
## Revised Answer (2020-Feb-09) Thanks to @Cyberbeni for reminding me that `apt` on macOS would incorrectly match the system Java runtime's **A**nnotation **P**rocessing **T**ool. Rolling up the necessary changes, we now have: ``` # What OS are we running? if [[ $(uname) == "Darwin" ]]; then source "$ZSH_CUSTOM"/...
42822661
oh-my-zsh: git maximum nested function level reached
15
2017-03-15 23:29:22
<p>Get an error when I use standard git command:</p> <pre><code>[~/site]$ git branch git:1: maximum nested function level reached </code></pre> <p>.zshrc:</p> <pre><code>plugins=(git osx colored-man gem brew go bundler rake rails) source $ZSH/oh-my-zsh.sh </code></pre>
26,523
5,225,464
2024-06-26 16:10:48
42,822,796
16
2017-03-15 23:42:49
5,225,464
2017-03-15 23:42:49
https://stackoverflow.com/q/42822661
https://stackoverflow.com/a/42822796
<p>My mistake, I moved bash function to zsh:</p> <pre><code>gr() { git rebase -i HEAD~$1 } </code></pre> <p>Solution:</p> <pre><code>function gr() { git rebase -i HEAD~$1 } </code></pre>
<p>My mistake, I moved bash function to zsh:</p> <pre><code>gr() { git rebase -i HEAD~$1 } </code></pre> <p>Solution:</p> <pre><code>function gr() { git rebase -i HEAD~$1 } </code></pre>
387, 390, 391, 3791, 93854
bash, oh-my-zsh, shell, terminal, zsh
<h1>oh-my-zsh: git maximum nested function level reached</h1> <p>Get an error when I use standard git command:</p> <pre><code>[~/site]$ git branch git:1: maximum nested function level reached </code></pre> <p>.zshrc:</p> <pre><code>plugins=(git osx colored-man gem brew go bundler rake rails) source $ZSH/oh-my-zsh.sh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,720
bash
# oh-my-zsh: git maximum nested function level reached Get an error when I use standard git command: ``` [~/site]$ git branch git:1: maximum nested function level reached ``` .zshrc: ``` plugins=(git osx colored-man gem brew go bundler rake rails) source $ZSH/oh-my-zsh.sh ```
My mistake, I moved bash function to zsh: ``` gr() { git rebase -i HEAD~$1 } ``` Solution: ``` function gr() { git rebase -i HEAD~$1 } ```
38135995
how to open a gnome terminal to execute a command with gnome-terminal, constantly?
15
2016-07-01 02:15:58
<p>I have a sh file which includes those lines:</p> <pre><code>gnome-terminal\ --tab\ --title="ElasticSearch"\ --working-directory="/home/username/program/bin"\ -e "bash -c './somecommand'"\ </code></pre> <p>when I run it, a gnome terminal will open and run a command for me. The problem is, when I pres...
26,535
6,151,945
2019-07-22 10:19:24
38,137,852
16
2016-07-01 05:44:29
5,291,015
2016-07-01 05:44:29
https://stackoverflow.com/q/38135995
https://stackoverflow.com/a/38137852
<p>Your command works fine but the <code>gnome-terminal</code> closes after the <code>somecommand</code> terminates, the reason being <code>gnome-terminal</code> not running the <code>bash</code> as it's default shell.</p> <p>To get the bash prompt(<code>$</code>) after the command command completes, you need to trigg...
<p>Your command works fine but the <code>gnome-terminal</code> closes after the <code>somecommand</code> terminates, the reason being <code>gnome-terminal</code> not running the <code>bash</code> as it's default shell.</p> <p>To get the bash prompt(<code>$</code>) after the command command completes, you need to trigg...
387, 32965
bash, gnome-terminal
<h1>how to open a gnome terminal to execute a command with gnome-terminal, constantly?</h1> <p>I have a sh file which includes those lines:</p> <pre><code>gnome-terminal\ --tab\ --title="ElasticSearch"\ --working-directory="/home/username/program/bin"\ -e "bash -c './somecommand'"\ </code></pre> <p>when...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,721
bash
# how to open a gnome terminal to execute a command with gnome-terminal, constantly? I have a sh file which includes those lines: ``` gnome-terminal\ --tab\ --title="ElasticSearch"\ --working-directory="/home/username/program/bin"\ -e "bash -c './somecommand'"\ ``` when I run it, a gnome terminal will ...
Your command works fine but the `gnome-terminal` closes after the `somecommand` terminates, the reason being `gnome-terminal` not running the `bash` as it's default shell. To get the bash prompt(`$`) after the command command completes, you need to trigger it back. ``` -e "bash -c ./somecommand;bash"\ ```
34252265
How to start MingW Console (GitBash) from Command Line on Windows?
15
2015-12-13 14:40:31
<p>I'm trying to automate my work environment set up using a batch file. I'm stuck at a point where I am not able to start the MingW64 Console from command line.</p> <p><code>start "" "%ProgramFiles%\Git\bin\sh.exe" --login</code> works fine but it seems to open a different shell window than that I am looking for. I'l...
31,307
205,024
2023-07-18 04:15:08
34,252,558
16
2015-12-13 15:10:42
6,309
2015-12-14 18:33:36
https://stackoverflow.com/q/34252265
https://stackoverflow.com/a/34252558
<p><code>git-bash.exe -i -c "/bin/bash"</code> seems to work better.<br> <a href="https://github.com/Maximus5/ConEmu/issues/176" rel="noreferrer">This issue</a> illustrates various other ways to call <code>git-bash.exe</code>, but concludes:</p> <blockquote> <p>Preferred way to run git-for-windows is using <code>git...
<p><code>git-bash.exe -i -c "/bin/bash"</code> seems to work better.<br> <a href="https://github.com/Maximus5/ConEmu/issues/176" rel="noreferrer">This issue</a> illustrates various other ways to call <code>git-bash.exe</code>, but concludes:</p> <blockquote> <p>Preferred way to run git-for-windows is using <code>git...
64, 1231, 7002, 61874
batch-file, command-line, git-bash, windows
<h1>How to start MingW Console (GitBash) from Command Line on Windows?</h1> <p>I'm trying to automate my work environment set up using a batch file. I'm stuck at a point where I am not able to start the MingW64 Console from command line.</p> <p><code>start "" "%ProgramFiles%\Git\bin\sh.exe" --login</code> works fine b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,722
bash
# How to start MingW Console (GitBash) from Command Line on Windows? I'm trying to automate my work environment set up using a batch file. I'm stuck at a point where I am not able to start the MingW64 Console from command line. `start "" "%ProgramFiles%\Git\bin\sh.exe" --login` works fine but it seems to open a diffe...
`git-bash.exe -i -c "/bin/bash"` seems to work better. [This issue](https://github.com/Maximus5/ConEmu/issues/176) illustrates various other ways to call `git-bash.exe`, but concludes: > Preferred way to run git-for-windows is using `git-cmd.exe`: ``` c:\git\git-cmd.exe --command=usr/bin/bash.exe -l -i ``` That ho...
33434465
What does a | (pipe character) do in a shell (bash) command?
15
2015-10-30 11:03:11
<p>I have to run this command to install NPM. What does it do? What is the | at the end?</p> <pre><code>curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash </code></pre> <p>Also, am I running UNIX-like commands in Bash? Why does this work? Is it that Bash is a UNIX-command compatible inter...
16,649
2,714,301
2023-11-25 15:34:17
33,436,245
16
2015-10-30 12:41:59
2,052,623
2023-11-25 15:34:17
https://stackoverflow.com/q/33434465
https://stackoverflow.com/a/33436245
<p>In Bash (and most *nix shells), the <code>|</code> (pipe) metacharacter¹ causes the shell to take the output from one command and uses it as the input for the next command.</p> <p>What you are doing here is using <code>curl</code> to retrieve the <code>install.sh</code> file and then output its contents into <code>b...
<p>In Bash (and most *nix shells), the <code>|</code> (pipe) metacharacter¹ causes the shell to take the output from one command and uses it as the input for the next command.</p> <p>What you are doing here is using <code>curl</code> to retrieve the <code>install.sh</code> file and then output its contents into <code>b...
387
bash
<h1>What does a | (pipe character) do in a shell (bash) command?</h1> <p>I have to run this command to install NPM. What does it do? What is the | at the end?</p> <pre><code>curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash </code></pre> <p>Also, am I running UNIX-like commands in Bash? ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,723
bash
# What does a | (pipe character) do in a shell (bash) command? I have to run this command to install NPM. What does it do? What is the | at the end? ``` curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash ``` Also, am I running UNIX-like commands in Bash? Why does this work? Is it that Ba...
In Bash (and most *nix shells), the `|` (pipe) metacharacter¹ causes the shell to take the output from one command and uses it as the input for the next command. What you are doing here is using `curl` to retrieve the `install.sh` file and then output its contents into `bash`, which is a shell that will execute the co...
27846505
How to add properties to a PowerShell object from an array
15
2015-01-08 17:54:45
<p>I have a two-dimensional array of property names and values, which I need to add to a PowerShell object.</p> <p>I have NO issues creating and displaying an object like this using <a href="http://technet.microsoft.com/en-us/library/hh849885.aspx" rel="noreferrer">New-Object</a> and <a href="https://technet.microsoft...
109,387
2,277,753
2017-01-23 18:24:04
27,850,741
16
2015-01-08 22:32:46
3,829,407
2017-01-23 18:24:04
https://stackoverflow.com/q/27846505
https://stackoverflow.com/a/27850741
<p>I am still not sure completely, but if you are just focusing on the <code>Add-Member</code> then consider the following.</p> <pre><code>$fieldsarray = "ID", "ContentTypeID", "ContentType", "Title", "Modified" $itemki = "1", "0x0108007345CD807822EA4E85691E5C642F3A27", "", "Task0", "11/24/2014 12:29:30 PM" $itemobj =...
<p>I am still not sure completely, but if you are just focusing on the <code>Add-Member</code> then consider the following.</p> <pre><code>$fieldsarray = "ID", "ContentTypeID", "ContentType", "Title", "Modified" $itemki = "1", "0x0108007345CD807822EA4E85691E5C642F3A27", "", "Task0", "11/24/2014 12:29:30 PM" $itemobj =...
526, 4898, 6981, 22864
object, powershell, powershell-ise, properties
<h1>How to add properties to a PowerShell object from an array</h1> <p>I have a two-dimensional array of property names and values, which I need to add to a PowerShell object.</p> <p>I have NO issues creating and displaying an object like this using <a href="http://technet.microsoft.com/en-us/library/hh849885.aspx" re...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,724
bash
# How to add properties to a PowerShell object from an array I have a two-dimensional array of property names and values, which I need to add to a PowerShell object. I have NO issues creating and displaying an object like this using [New-Object](http://technet.microsoft.com/en-us/library/hh849885.aspx) and [Add-Membe...
I am still not sure completely, but if you are just focusing on the `Add-Member` then consider the following. ``` $fieldsarray = "ID", "ContentTypeID", "ContentType", "Title", "Modified" $itemki = "1", "0x0108007345CD807822EA4E85691E5C642F3A27", "", "Task0", "11/24/2014 12:29:30 PM" $itemobj = New-Object pscustomobjec...
24806598
copying last bash command into clipboard
15
2014-07-17 14:41:26
<p>Sometimes I need to save the last typed shell command into the clipboard. I can do something like this:</p> <pre><code>echo !! | xsel --clipboard </code></pre> <p>Which works successfully.</p> <p>But when I try to alias the above command:</p> <pre><code>alias echoxs='echo !! | xsel --clipboard' </code></pre> <p>Thin...
7,017
1,941,755
2024-07-13 20:53:17
24,807,390
16
2014-07-17 15:13:25
2,679,935
2014-07-17 15:13:25
https://stackoverflow.com/q/24806598
https://stackoverflow.com/a/24807390
<p>I'm not sure to understand what you said about "failing when attempting to modify the output of history", so I hope my solution will suit you. I'm using <code>fc</code> to get the last command:</p> <pre><code>fc -ln -1 | xsel --clipboard </code></pre> <p>Here are the meaning of the options:</p> <ul> <li><code>l</...
<p>I'm not sure to understand what you said about "failing when attempting to modify the output of history", so I hope my solution will suit you. I'm using <code>fc</code> to get the last command:</p> <pre><code>fc -ln -1 | xsel --clipboard </code></pre> <p>Here are the meaning of the options:</p> <ul> <li><code>l</...
387, 390, 1318
bash, history, shell
<h1>copying last bash command into clipboard</h1> <p>Sometimes I need to save the last typed shell command into the clipboard. I can do something like this:</p> <pre><code>echo !! | xsel --clipboard </code></pre> <p>Which works successfully.</p> <p>But when I try to alias the above command:</p> <pre><code>alias echoxs=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,725
bash
# copying last bash command into clipboard Sometimes I need to save the last typed shell command into the clipboard. I can do something like this: ``` echo !! | xsel --clipboard ``` Which works successfully. But when I try to alias the above command: ``` alias echoxs='echo !! | xsel --clipboard' ``` Things do not...
I'm not sure to understand what you said about "failing when attempting to modify the output of history", so I hope my solution will suit you. I'm using `fc` to get the last command: ``` fc -ln -1 | xsel --clipboard ``` Here are the meaning of the options: - `l` is to use the standard output - `n` is to hide the com...
17365784
how to silently disable xtrace in a shell script?
15
2013-06-28 13:25:30
<p>I'm writing a shell script that loops over some values and run a long command line for each value. I'd like to print out these commands along the way, just like <code>make</code> does when running a makefile. I know I could just "echo" all commands before running them, but it feels inelegant. So I'm looking at <code...
7,810
117,814
2023-06-19 13:42:16
17,366,594
16
2013-06-28 14:06:32
14,122
2013-06-28 14:29:51
https://stackoverflow.com/q/17365784
https://stackoverflow.com/a/17366594
<p>Sandbox it in a subshell:</p> <pre><code>(set -x; do_thing_you_want_traced) </code></pre> <p>Of course, changes to variables or the environment made in that subshell will be lost.</p> <p>If you REALLY care about this, you could also use a DEBUG trap (using <code>set -T</code> to cause it to be inherited by functi...
<p>Sandbox it in a subshell:</p> <pre><code>(set -x; do_thing_you_want_traced) </code></pre> <p>Of course, changes to variables or the environment made in that subshell will be lost.</p> <p>If you REALLY care about this, you could also use a DEBUG trap (using <code>set -T</code> to cause it to be inherited by functi...
390
shell
<h1>how to silently disable xtrace in a shell script?</h1> <p>I'm writing a shell script that loops over some values and run a long command line for each value. I'd like to print out these commands along the way, just like <code>make</code> does when running a makefile. I know I could just "echo" all commands before ru...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,726
bash
# how to silently disable xtrace in a shell script? I'm writing a shell script that loops over some values and run a long command line for each value. I'd like to print out these commands along the way, just like `make` does when running a makefile. I know I could just "echo" all commands before running them, but it f...
Sandbox it in a subshell: ``` (set -x; do_thing_you_want_traced) ``` Of course, changes to variables or the environment made in that subshell will be lost. If you REALLY care about this, you could also use a DEBUG trap (using `set -T` to cause it to be inherited by functions) to implement your own `set -x` equivalen...
14193207
Registering custom shell function in system (OSX)
15
2013-01-07 09:35:11
<p>today I wanted to write a function which will deploy my blog page (developed in nanoc) to github pages automatically - here's the script:</p> <pre><code>function cmit() { nanoc compile; git add .; git commit -am $1; git push origin source; cd output; git add .; git commit -am $1; git push origin maste...
16,127
1,004,946
2013-01-07 09:47:50
14,193,272
16
2013-01-07 09:40:02
1,066,031
2013-01-07 09:47:50
https://stackoverflow.com/q/14193207
https://stackoverflow.com/a/14193272
<p>Just added it to the bottom of your <code>~/.bashrc</code> file then you will be able to use <code>cmit</code> like a regular command, you will need to refresh your current shell to pick up the changes so run <code>source ~/.bashrc</code>. If you have the function saved in a file <code>cmit</code> just do <code>cat ...
<p>Just added it to the bottom of your <code>~/.bashrc</code> file then you will be able to use <code>cmit</code> like a regular command, you will need to refresh your current shell to pick up the changes so run <code>source ~/.bashrc</code>. If you have the function saved in a file <code>cmit</code> just do <code>cat ...
387, 390, 5569
bash, function, shell
<h1>Registering custom shell function in system (OSX)</h1> <p>today I wanted to write a function which will deploy my blog page (developed in nanoc) to github pages automatically - here's the script:</p> <pre><code>function cmit() { nanoc compile; git add .; git commit -am $1; git push origin source; cd outp...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,727
bash
# Registering custom shell function in system (OSX) today I wanted to write a function which will deploy my blog page (developed in nanoc) to github pages automatically - here's the script: ``` function cmit() { nanoc compile; git add .; git commit -am $1; git push origin source; cd output; git add .; git...
Just added it to the bottom of your `~/.bashrc` file then you will be able to use `cmit` like a regular command, you will need to refresh your current shell to pick up the changes so run `source ~/.bashrc`. If you have the function saved in a file `cmit` just do `cat cmit >> ~/.bashrc` to append the function to the end...
13602751
git - checkout single file under bare repository
15
2012-11-28 10:19:46
<p>On the server I have bare repository which is origin for development process and to simplify deployment to QA environment.</p> <p>So in <code>post-receive</code> it simply does</p> <pre><code>GIT_WORK_TREE=/home/dev git checkout -f </code></pre> <p>But as product gets more complicated there are some other things ...
6,717
1,297,136
2018-03-05 03:48:45
13,603,029
16
2012-11-28 10:35:25
6,309
2012-11-28 13:23:24
https://stackoverflow.com/q/13602751
https://stackoverflow.com/a/13603029
<p>As I explain in "<a href="https://stackoverflow.com/a/2467629/6309">checkout only one file from git</a>", you cannot checkout just one file without cloning or fetching first. </p> <p>But you <a href="https://stackoverflow.com/questions/610208/how-to-retrieve-a-single-file-from-specific-revision-in-git"><code>git s...
<p>As I explain in "<a href="https://stackoverflow.com/a/2467629/6309">checkout only one file from git</a>", you cannot checkout just one file without cloning or fetching first. </p> <p>But you <a href="https://stackoverflow.com/questions/610208/how-to-retrieve-a-single-file-from-specific-revision-in-git"><code>git s...
119, 10327, 43087
git, githooks, sh
<h1>git - checkout single file under bare repository</h1> <p>On the server I have bare repository which is origin for development process and to simplify deployment to QA environment.</p> <p>So in <code>post-receive</code> it simply does</p> <pre><code>GIT_WORK_TREE=/home/dev git checkout -f </code></pre> <p>But as ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,728
bash
# git - checkout single file under bare repository On the server I have bare repository which is origin for development process and to simplify deployment to QA environment. So in `post-receive` it simply does ``` GIT_WORK_TREE=/home/dev git checkout -f ``` But as product gets more complicated there are some other ...
As I explain in "[checkout only one file from git](https://stackoverflow.com/a/2467629/6309)", you cannot checkout just one file without cloning or fetching first. But you [`git show` that file](https://stackoverflow.com/questions/610208/how-to-retrieve-a-single-file-from-specific-revision-in-git), which means you can...
9851005
How do you clone ( duplicate ) a MongoDB object in a collection of the same db?
15
2012-03-24 10:33:46
<p>I need to duplicate (clone) an object in the collection via dbshell. Having something like this :</p> <pre><code>&gt; db.users.distinct( 'nickname' ) [ "user1", "user2", "user3", "user4" ] &gt; </code></pre> <p>where user1 select a complex object in <strong>users</strong> collection...
15,099
467,255
2017-07-08 07:58:59
9,852,223
16
2012-03-24 13:43:04
396,862
2014-04-22 14:22:53
https://stackoverflow.com/q/9851005
https://stackoverflow.com/a/9852223
<p><strong>Code</strong> </p> <pre><code>&gt; user = db.users.findOne({'nickname': 'user1'}) &gt; user.nickname = 'userX' &gt; delete user['_id'] &gt; db.users.insert(user) </code></pre> <p><strong>Description</strong></p> <p>You need to find user object and put it into the variable. Than you need to modify the prop...
<p><strong>Code</strong> </p> <pre><code>&gt; user = db.users.findOne({'nickname': 'user1'}) &gt; user.nickname = 'userX' &gt; delete user['_id'] &gt; db.users.insert(user) </code></pre> <p><strong>Description</strong></p> <p>You need to find user object and put it into the variable. Than you need to modify the prop...
30, 390, 30073, 35037
database, mongodb, nosql, shell
<h1>How do you clone ( duplicate ) a MongoDB object in a collection of the same db?</h1> <p>I need to duplicate (clone) an object in the collection via dbshell. Having something like this :</p> <pre><code>&gt; db.users.distinct( 'nickname' ) [ "user1", "user2", "user3", "user4" ] &gt; <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,729
bash
# How do you clone ( duplicate ) a MongoDB object in a collection of the same db? I need to duplicate (clone) an object in the collection via dbshell. Having something like this : ``` > db.users.distinct( 'nickname' ) [ "user1", "user2", "user3", "user4" ] > ``` where user1 select a c...
**Code** ``` > user = db.users.findOne({'nickname': 'user1'}) > user.nickname = 'userX' > delete user['_id'] > db.users.insert(user) ``` **Description** You need to find user object and put it into the variable. Than you need to modify the property you want and than you need to insert the whole object as new one. To...
8973577
Commandline syntax to prevent wrapping in PowerShell output file?
15
2012-01-23 14:55:54
<p>The following command wraps the output to the width of the window from which the script was called. That is, the output file is "word"-wrapped. How can I prevent this wrapping in the output file w/o modifying the script?</p> <pre><code>PS C:\Users\User1&gt; &amp; '\\fileServer\c$\PowerShell Scripts\herScript.ps1' &...
27,502
116,895
2016-02-17 16:48:06
8,973,693
16
2012-01-23 15:05:02
520,612
2012-01-23 15:05:02
https://stackoverflow.com/q/8973577
https://stackoverflow.com/a/8973693
<p>Try this (I can't test it)</p> <pre><code>&amp; '\\fileServer\c$\PowerShell Scripts\herScript.ps1' | out-string -width 4096 | out-file c:\output.txt </code></pre>
<p>Try this (I can't test it)</p> <pre><code>&amp; '\\fileServer\c$\PowerShell Scripts\herScript.ps1' | out-string -width 4096 | out-file c:\output.txt </code></pre>
526, 1231, 19508, 31901, 34595
command-line, http-redirect, powershell, windows-7, word-wrap
<h1>Commandline syntax to prevent wrapping in PowerShell output file?</h1> <p>The following command wraps the output to the width of the window from which the script was called. That is, the output file is "word"-wrapped. How can I prevent this wrapping in the output file w/o modifying the script?</p> <pre><code>PS C:...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,730
bash
# Commandline syntax to prevent wrapping in PowerShell output file? The following command wraps the output to the width of the window from which the script was called. That is, the output file is "word"-wrapped. How can I prevent this wrapping in the output file w/o modifying the script? ``` PS C:\Users\User1> & '\\f...
Try this (I can't test it) ``` & '\\fileServer\c$\PowerShell Scripts\herScript.ps1' | out-string -width 4096 | out-file c:\output.txt ```
3643436
bash script to extract ALL matches of a regex pattern
15
2010-09-04 18:16:20
<p>I found this but it assumes the words are space separated.</p> <pre><code>result="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg" for word in $result do if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)' then match="$match $word" fi done </code></pre> <p>POST EDITED</p> <p>Re-nam...
30,585
311,362
2025-09-03 09:20:27
3,643,504
16
2010-09-04 18:37:25
26,428
2020-08-04 07:43:39
https://stackoverflow.com/q/3643436
https://stackoverflow.com/a/3643504
<p><strong>Edit: answer to edited question:</strong></p> <pre class="lang-sh prettyprint-override"><code>for string in &quot;$(echo $result | grep -Po &quot;ADDNAME[0-9]{2}.*?HELLO&quot;)&quot;; do match=&quot;${match:+$match }$string&quot; done </code></pre> <p><strong>Original answer:</strong></p> <p>If you're usin...
<p><strong>Edit: answer to edited question:</strong></p> <pre class="lang-sh prettyprint-override"><code>for string in &quot;$(echo $result | grep -Po &quot;ADDNAME[0-9]{2}.*?HELLO&quot;)&quot;; do match=&quot;${match:+$match }$string&quot; done </code></pre> <p><strong>Original answer:</strong></p> <p>If you're usin...
387, 390
bash, shell
<h1>bash script to extract ALL matches of a regex pattern</h1> <p>I found this but it assumes the words are space separated.</p> <pre><code>result="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg" for word in $result do if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)' then match="$match ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,731
bash
# bash script to extract ALL matches of a regex pattern I found this but it assumes the words are space separated. ``` result="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg" for word in $result do if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)' then match="$match $word" fi done `...
**Edit: answer to edited question:** ``` for string in "$(echo $result | grep -Po "ADDNAME[0-9]{2}.*?HELLO")"; do match="${match:+$match }$string" done ``` **Original answer:** If you're using Bash version 3.2 or higher, you can use its regex matching. ``` string="string to search 99 with 88 some 42 numbers" patt...
3348614
How to flush a pipe using bash
15
2010-07-27 22:43:35
<p>I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script?</p>
15,859
125,380
2025-02-26 19:58:48
3,348,779
16
2010-07-27 23:26:00
371,793
2010-07-27 23:26:00
https://stackoverflow.com/q/3348614
https://stackoverflow.com/a/3348779
<p>I think <code>dd</code> is your friend:</p> <pre><code>dd if=myfifo iflag=nonblock of=/dev/null </code></pre> <p>strace shows</p> <pre><code>open("myfifo", O_RDONLY|O_NONBLOCK) </code></pre> <p>and indeed doesn't even block on an empty fifo.</p>
<p>I think <code>dd</code> is your friend:</p> <pre><code>dd if=myfifo iflag=nonblock of=/dev/null </code></pre> <p>strace shows</p> <pre><code>open("myfifo", O_RDONLY|O_NONBLOCK) </code></pre> <p>and indeed doesn't even block on an empty fifo.</p>
387, 11366
bash, named-pipes
<h1>How to flush a pipe using bash</h1> <p>I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script?...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,732
bash
# How to flush a pipe using bash I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script?
I think `dd` is your friend: ``` dd if=myfifo iflag=nonblock of=/dev/null ``` strace shows ``` open("myfifo", O_RDONLY|O_NONBLOCK) ``` and indeed doesn't even block on an empty fifo.
3297884
Using output of previous commands in bash
15
2010-07-21 09:30:56
<p>In Mathematica, it is possible to reuse the output of the previous command by using %.</p> <p>Is something similar possible for bash (or some other shell)?</p> <p>For example, I run a make which gives warnings, but I want to find all warnings. So, I type </p> <pre><code>make | grep "warning" </code></pre> <p>but...
22,139
390,321
2019-11-29 23:11:48
3,297,911
16
2010-07-21 09:35:44
172,211
2010-07-21 09:35:44
https://stackoverflow.com/q/3297884
https://stackoverflow.com/a/3297911
<p>Since the amount of output is indeterminate, it doesn't make sense for <code>bash</code> to store it for you for re-display. But there's an alternate solution to your problem:</p> <p>The <code>tee</code> command allows you to duplicate an output stream to a file. So if you're willing to use a file for temporary sto...
<p>Since the amount of output is indeterminate, it doesn't make sense for <code>bash</code> to store it for you for re-display. But there's an alternate solution to your problem:</p> <p>The <code>tee</code> command allows you to duplicate an output stream to a file. So if you're willing to use a file for temporary sto...
58, 387, 390
bash, linux, shell
<h1>Using output of previous commands in bash</h1> <p>In Mathematica, it is possible to reuse the output of the previous command by using %.</p> <p>Is something similar possible for bash (or some other shell)?</p> <p>For example, I run a make which gives warnings, but I want to find all warnings. So, I type </p> <pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,733
bash
# Using output of previous commands in bash In Mathematica, it is possible to reuse the output of the previous command by using %. Is something similar possible for bash (or some other shell)? For example, I run a make which gives warnings, but I want to find all warnings. So, I type ``` make | grep "warning" ``` ...
Since the amount of output is indeterminate, it doesn't make sense for `bash` to store it for you for re-display. But there's an alternate solution to your problem: The `tee` command allows you to duplicate an output stream to a file. So if you're willing to use a file for temporary storage, you can do something like ...
2162914
Why do I have to press Ctrl+D twice to close stdin?
15
2010-01-29 15:27:55
<p>I have the following Python script that reads numbers and outputs an error if the input is not a number.</p> <pre><code>import fileinput import sys for line in (txt.strip() for txt in fileinput.input()): if not line.isdigit(): sys.stderr.write("ERROR: not a number: %s\n" % line) </code></pre> <p>If I g...
7,914
46,821
2015-02-11 01:21:03
2,164,353
16
2010-01-29 18:52:52
94,977
2015-02-11 01:21:03
https://stackoverflow.com/q/2162914
https://stackoverflow.com/a/2164353
<p>In Python 3, this was due to <a href="http://bugs.python.org/issue5505" rel="noreferrer">a bug in Python's standard I/O library</a>. The bug was fixed in Python 3.3.</p> <hr> <p>In a Unix terminal, typing Ctrl+D doesn't actually close the process's stdin. But typing either Enter or Ctrl+D does cause the OS <code>r...
<p>In Python 3, this was due to <a href="http://bugs.python.org/issue5505" rel="noreferrer">a bug in Python's standard I/O library</a>. The bug was fixed in Python 3.3.</p> <hr> <p>In a Unix terminal, typing Ctrl+D doesn't actually close the process's stdin. But typing either Enter or Ctrl+D does cause the OS <code>r...
16, 387, 1701
bash, python, stdin
<h1>Why do I have to press Ctrl+D twice to close stdin?</h1> <p>I have the following Python script that reads numbers and outputs an error if the input is not a number.</p> <pre><code>import fileinput import sys for line in (txt.strip() for txt in fileinput.input()): if not line.isdigit(): sys.stderr.write...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,734
bash
# Why do I have to press Ctrl+D twice to close stdin? I have the following Python script that reads numbers and outputs an error if the input is not a number. ``` import fileinput import sys for line in (txt.strip() for txt in fileinput.input()): if not line.isdigit(): sys.stderr.write("ERROR: not a numbe...
In Python 3, this was due to [a bug in Python's standard I/O library](http://bugs.python.org/issue5505). The bug was fixed in Python 3.3. --- In a Unix terminal, typing Ctrl+D doesn't actually close the process's stdin. But typing either Enter or Ctrl+D does cause the OS `read` system call to return right away. So: ...
55473913
Write-Verbose vs Write-Host in powershell
14
2019-04-02 11:39:27
<p>While I am using <code>Write-Verbose</code> in powershell command window I'm not getting anything in the console. However it is used by devops engineers in my team for continuous integration, build scripts.</p> <p>What is the difference between <code>Write-Verbose</code> and <code>Write-Host</code></p>
24,024
7,441,056
2020-04-20 12:05:56
55,474,264
16
2019-04-02 11:59:26
8,188,846
2019-04-02 15:51:26
https://stackoverflow.com/q/55473913
https://stackoverflow.com/a/55474264
<p>The difference between the cmdlets (as of <a href="/questions/tagged/powershell-v5.0" class="post-tag" title="show questions tagged &#39;powershell-v5.0&#39;" rel="tag">powershell-v5.0</a>) is which stream they use to display information. By default, the Verbose stream (4) is not visible <em>unless</em> you specify...
<p>The difference between the cmdlets (as of <a href="/questions/tagged/powershell-v5.0" class="post-tag" title="show questions tagged &#39;powershell-v5.0&#39;" rel="tag">powershell-v5.0</a>) is which stream they use to display information. By default, the Verbose stream (4) is not visible <em>unless</em> you specify...
526, 73157
powershell, powershell-3.0
<h1>Write-Verbose vs Write-Host in powershell</h1> <p>While I am using <code>Write-Verbose</code> in powershell command window I'm not getting anything in the console. However it is used by devops engineers in my team for continuous integration, build scripts.</p> <p>What is the difference between <code>Write-Verbose<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,735
bash
# Write-Verbose vs Write-Host in powershell While I am using `Write-Verbose` in powershell command window I'm not getting anything in the console. However it is used by devops engineers in my team for continuous integration, build scripts. What is the difference between `Write-Verbose` and `Write-Host`
The difference between the cmdlets (as of [powershell-v5.0](/questions/tagged/powershell-v5.0 "show questions tagged 'powershell-v5.0'")) is which stream they use to display information. By default, the Verbose stream (4) is not visible *unless* you specify `-Verbose`, add `-Verbose` using the `$PSDefaultParameterValue...
51301508
Is there a way to know how the user invoked a program from bash?
14
2018-07-12 09:07:47
<p>Here's the problem: I have this script <code>foo.py</code>, and if the user invokes it without the <code>--bar</code> option, I'd like to display the following error message:</p> <pre><code>Please add the --bar option to your command, like so: python foo.py --bar </code></pre> <p>Now, the tricky part is that t...
783
7,581
2018-12-20 18:27:14
51,411,924
16
2018-07-18 22:36:42
14,122
2018-07-19 16:55:00
https://stackoverflow.com/q/51301508
https://stackoverflow.com/a/51411924
<h3>No, there is no way to see the original text (before aliases/functions/etc).</h3> <p>Starting a program in UNIX is done as follows at the underlying syscall level:</p> <pre><code>int execve(const char *path, char *const argv[], char *const envp[]); </code></pre> <p>Notably, there are three arguments:</p> <ul> <...
<h3>No, there is no way to see the original text (before aliases/functions/etc).</h3> <p>Starting a program in UNIX is done as follows at the underlying syscall level:</p> <pre><code>int execve(const char *path, char *const argv[], char *const envp[]); </code></pre> <p>Notably, there are three arguments:</p> <ul> <...
58, 387, 11225
bash, command-line-interface, linux
<h1>Is there a way to know how the user invoked a program from bash?</h1> <p>Here's the problem: I have this script <code>foo.py</code>, and if the user invokes it without the <code>--bar</code> option, I'd like to display the following error message:</p> <pre><code>Please add the --bar option to your command, like so...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,736
bash
# Is there a way to know how the user invoked a program from bash? Here's the problem: I have this script `foo.py`, and if the user invokes it without the `--bar` option, I'd like to display the following error message: ``` Please add the --bar option to your command, like so: python foo.py --bar ``` Now, the tr...
### No, there is no way to see the original text (before aliases/functions/etc). Starting a program in UNIX is done as follows at the underlying syscall level: ``` int execve(const char *path, char *const argv[], char *const envp[]); ``` Notably, there are three arguments: - The path to the executable - An argv arr...
42963661
Use PowerShell to search for string in registry keys and values
14
2017-03-22 22:15:07
<p>I'd like to use PowerShell to find all registry keys and values within a particular hive that contain a string <code>foo</code>, possibly embedded within a longer string. Finding the keys is not hard:</p> <pre><code>Get-ChildItem -path hkcu:\ -recurse -ErrorAction SilentlyContinue | Where-Object {$_.Name -like "*fo...
119,229
523,124
2025-05-27 08:26:44
42,965,635
16
2017-03-23 01:29:54
3,874,447
2025-05-27 08:26:44
https://stackoverflow.com/q/42963661
https://stackoverflow.com/a/42965635
<p>Each key has a <code>GetValueNames()</code>, <code>GetValueKind()</code>, and <code>GetValue()</code> method that let you enumerate child values. You can also use the <code>GetSubKeyNames()</code> instead of depending on <code>Get-ChildItem -Recurse</code> to enumerate keys.</p> <p>To answer your question about sear...
<p>Each key has a <code>GetValueNames()</code>, <code>GetValueKind()</code>, and <code>GetValue()</code> method that let you enumerate child values. You can also use the <code>GetSubKeyNames()</code> instead of depending on <code>Get-ChildItem -Recurse</code> to enumerate keys.</p> <p>To answer your question about sear...
526
powershell
<h1>Use PowerShell to search for string in registry keys and values</h1> <p>I'd like to use PowerShell to find all registry keys and values within a particular hive that contain a string <code>foo</code>, possibly embedded within a longer string. Finding the keys is not hard:</p> <pre><code>Get-ChildItem -path hkcu:\ ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,737
bash
# Use PowerShell to search for string in registry keys and values I'd like to use PowerShell to find all registry keys and values within a particular hive that contain a string `foo`, possibly embedded within a longer string. Finding the keys is not hard: ``` Get-ChildItem -path hkcu:\ -recurse -ErrorAction SilentlyC...
Each key has a `GetValueNames()`, `GetValueKind()`, and `GetValue()` method that let you enumerate child values. You can also use the `GetSubKeyNames()` instead of depending on `Get-ChildItem -Recurse` to enumerate keys. To answer your question about searching multiple hives: if you start with `Get-ChildItem Registry:...
38178112
Can I add changes to staging area from another branch?
14
2016-07-04 06:27:53
<p>I have two branch,</p> <ul> <li>master</li> <li>new-features</li> </ul> <p>New features have a commit I want to add to master but I want the control how much I want to merge.</p> <p>I would like the option to add/reject changes for each line. Similar I can do with <code>git add -p</code> </p> <p>I have searched ...
6,286
550,907
2016-12-03 19:00:12
38,178,762
16
2016-07-04 07:09:44
6,394,138
2016-07-04 07:17:14
https://stackoverflow.com/q/38178112
https://stackoverflow.com/a/38178762
<p>Use <code>git cherry-pick</code> with the <code>-n|--no-commit</code> option and then interactively select what to commit:</p> <blockquote> <p><strong>git cherry-pick</strong></p> <p>...</p> <p><code>-n</code>, <code>--no-commit</code></p> <p>Usually <code>git cherry-pick</code> automatically creat...
<p>Use <code>git cherry-pick</code> with the <code>-n|--no-commit</code> option and then interactively select what to commit:</p> <blockquote> <p><strong>git cherry-pick</strong></p> <p>...</p> <p><code>-n</code>, <code>--no-commit</code></p> <p>Usually <code>git cherry-pick</code> automatically creat...
119, 390, 456, 3346
dvcs, git, shell, version-control
<h1>Can I add changes to staging area from another branch?</h1> <p>I have two branch,</p> <ul> <li>master</li> <li>new-features</li> </ul> <p>New features have a commit I want to add to master but I want the control how much I want to merge.</p> <p>I would like the option to add/reject changes for each line. Similar...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,738
bash
# Can I add changes to staging area from another branch? I have two branch, - master - new-features New features have a commit I want to add to master but I want the control how much I want to merge. I would like the option to add/reject changes for each line. Similar I can do with `git add -p` I have searched a l...
Use `git cherry-pick` with the `-n|--no-commit` option and then interactively select what to commit: > **git cherry-pick** > > ... > > `-n`, `--no-commit` > > Usually `git cherry-pick` automatically creates a sequence of commits. This > flag applies the changes necessary to cherry-pick each named commit to your > work...
37838273
Evaluating bash "&&" exit codes behaviour
14
2016-06-15 14:26:58
<p>We had a recent experience with bash that even we found a solution, it keeps twisting my mind. How does bash evaluates the <code>&amp;&amp;</code> expression in terms of return codes?</p> <p>Executing this script, that should fail because <code>myrandomcommand</code> does not exist:</p> <pre><code>#!/bin/bash set...
3,904
60,511
2016-06-15 14:40:09
37,838,575
16
2016-06-15 14:40:09
2,545,194
2016-06-15 14:40:09
https://stackoverflow.com/q/37838273
https://stackoverflow.com/a/37838575
<p>You can read in the man pages of <strong>bash</strong>:</p> <pre><code>-e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of th...
<p>You can read in the man pages of <strong>bash</strong>:</p> <pre><code>-e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of th...
387, 4705, 9206
bash, return, return-value
<h1>Evaluating bash "&&" exit codes behaviour</h1> <p>We had a recent experience with bash that even we found a solution, it keeps twisting my mind. How does bash evaluates the <code>&amp;&amp;</code> expression in terms of return codes?</p> <p>Executing this script, that should fail because <code>myrandomcommand</cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,739
bash
# Evaluating bash "&&" exit codes behaviour We had a recent experience with bash that even we found a solution, it keeps twisting my mind. How does bash evaluates the `&&` expression in terms of return codes? Executing this script, that should fail because `myrandomcommand` does not exist: ``` #!/bin/bash set -e e...
You can read in the man pages of **bash**: ``` -e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statem...
28865473
Setting environment variable to a large value -> "Argument list too long"
14
2015-03-04 21:36:09
<p>Inside a bash script, I set an environment variable to contain a string of 1 million characters. I do so like this:</p> <pre><code>export LG=XXXXXXX # ... 1 million X's </code></pre> <p>Immediately after this, I am able to echo it back without a problem, i.e.</p> <pre><code>echo $LG </code></pre> <p>However, any...
10,250
1,420,590
2015-03-04 22:10:15
28,865,503
16
2015-03-04 21:37:40
14,122
2015-03-04 22:10:15
https://stackoverflow.com/q/28865473
https://stackoverflow.com/a/28865503
<p>Command-line arguments and environment variables both come out of the same pool of space. Set environment variables too long, and you no longer have space for command-line arguments -- and even <code>xargs</code>, which breaks command line invocations down into smaller groupings to fit inside the pool where possible...
<p>Command-line arguments and environment variables both come out of the same pool of space. Set environment variables too long, and you no longer have space for command-line arguments -- and even <code>xargs</code>, which breaks command line invocations down into smaller groupings to fit inside the pool where possible...
58, 387, 390, 9013
bash, environment-variables, linux, shell
<h1>Setting environment variable to a large value -> "Argument list too long"</h1> <p>Inside a bash script, I set an environment variable to contain a string of 1 million characters. I do so like this:</p> <pre><code>export LG=XXXXXXX # ... 1 million X's </code></pre> <p>Immediately after this, I am able to echo it b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,740
bash
# Setting environment variable to a large value -> "Argument list too long" Inside a bash script, I set an environment variable to contain a string of 1 million characters. I do so like this: ``` export LG=XXXXXXX # ... 1 million X's ``` Immediately after this, I am able to echo it back without a problem, i.e. ``` ...
Command-line arguments and environment variables both come out of the same pool of space. Set environment variables too long, and you no longer have space for command-line arguments -- and even `xargs`, which breaks command line invocations down into smaller groupings to fit inside the pool where possible, can't operat...
21876431
Replace text between two strings in file using linux bash
14
2014-02-19 09:39:01
<p>i have file "acl.txt"</p> <pre><code> 192.168.0.1 192.168.4.5 #start_exceptions 192.168.3.34 192.168.6.78 #end_exceptions 192.168.5.55 </code></pre> <p>and another file "exceptions"</p> <pre><code> 192.168.88.88 192.168.76.6 </code></pre> <p>I need to replace everything between #start_exceptions and #end_...
11,247
1,908,352
2017-09-26 08:42:28
21,876,700
16
2014-02-19 09:48:47
2,836,621
2014-02-21 17:00:43
https://stackoverflow.com/q/21876431
https://stackoverflow.com/a/21876700
<p><strong>EDITED</strong>:</p> <p>Ok, if you want to retain the #start and #stop, I will revert to awk:</p> <pre><code>awk ' BEGIN {p=1} /^#start/ {print;system("cat exceptions");p=0} /^#end/ {p=1} p' acl.txt </code></pre> <p>Thanks to @fedorqui for tweaks in comments below.</p> <p>Outp...
<p><strong>EDITED</strong>:</p> <p>Ok, if you want to retain the #start and #stop, I will revert to awk:</p> <pre><code>awk ' BEGIN {p=1} /^#start/ {print;system("cat exceptions");p=0} /^#end/ {p=1} p' acl.txt </code></pre> <p>Thanks to @fedorqui for tweaks in comments below.</p> <p>Outp...
58, 387, 5282
bash, linux, sed
<h1>Replace text between two strings in file using linux bash</h1> <p>i have file "acl.txt"</p> <pre><code> 192.168.0.1 192.168.4.5 #start_exceptions 192.168.3.34 192.168.6.78 #end_exceptions 192.168.5.55 </code></pre> <p>and another file "exceptions"</p> <pre><code> 192.168.88.88 192.168.76.6 </code></pre> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,741
bash
# Replace text between two strings in file using linux bash i have file "acl.txt" ``` 192.168.0.1 192.168.4.5 #start_exceptions 192.168.3.34 192.168.6.78 #end_exceptions 192.168.5.55 ``` and another file "exceptions" ``` 192.168.88.88 192.168.76.6 ``` I need to replace everything between #start_exceptions...
**EDITED**: Ok, if you want to retain the #start and #stop, I will revert to awk: ``` awk ' BEGIN {p=1} /^#start/ {print;system("cat exceptions");p=0} /^#end/ {p=1} p' acl.txt ``` Thanks to @fedorqui for tweaks in comments below. Output: ``` 192.168.0.1 192.168.4.5 #start_exceptions 192...
18527121
What is EOF!! in the bash script?
14
2013-08-30 07:19:17
<p>There is a command I don't understand:</p> <pre><code>custom_command &lt;&lt; EOF!! </code></pre> <p>I want to ask what EOF!! is in the bash script. I did find EOF with google, but google will ignore the "!!" automatically, so I cannot find EOF!!. </p> <p>I know the end of the file token, but I don't exactly know...
87,159
2,288,882
2013-08-30 07:52:36
18,527,367
16
2013-08-30 07:33:27
1,030,675
2013-08-30 07:50:28
https://stackoverflow.com/q/18527121
https://stackoverflow.com/a/18527367
<p>On the command line, <code>!!</code> would be expanded to the last command executed. Bash will print the line for you:</p> <pre><code>$ ls a.txt b.txt $ cat &lt;&lt;EOF!! cat &lt;&lt;EOFls &gt; </code></pre> <p>In a script, though, history expansion is disabled by default, so the exclamation marks are part of the...
<p>On the command line, <code>!!</code> would be expanded to the last command executed. Bash will print the line for you:</p> <pre><code>$ ls a.txt b.txt $ cat &lt;&lt;EOF!! cat &lt;&lt;EOFls &gt; </code></pre> <p>In a script, though, history expansion is disabled by default, so the exclamation marks are part of the...
34, 58, 387, 390
bash, linux, shell, unix
<h1>What is EOF!! in the bash script?</h1> <p>There is a command I don't understand:</p> <pre><code>custom_command &lt;&lt; EOF!! </code></pre> <p>I want to ask what EOF!! is in the bash script. I did find EOF with google, but google will ignore the "!!" automatically, so I cannot find EOF!!. </p> <p>I know the end ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,742
bash
# What is EOF!! in the bash script? There is a command I don't understand: ``` custom_command << EOF!! ``` I want to ask what EOF!! is in the bash script. I did find EOF with google, but google will ignore the "!!" automatically, so I cannot find EOF!!. I know the end of the file token, but I don't exactly know wha...
On the command line, `!!` would be expanded to the last command executed. Bash will print the line for you: ``` $ ls a.txt b.txt $ cat <<EOF!! cat <<EOFls > ``` In a script, though, history expansion is disabled by default, so the exclamation marks are part of the word. ``` #! /bin/bash ls cat <<EOF!! echo 1 EOFls ...
17214038
pipe each line of a file to a command
14
2013-06-20 12:47:36
<p>I have a text file which each line is a one word coded base64 separely. Now I want to decode it. I'm trying to use base64 command line, but I'm getting all the words in only one line, I want one per line.</p> <p>For example, my file is:</p> <pre><code>Y2F0Cg== ZG9nCg== aG91c2UK </code></pre> <p>I want as result:<...
16,008
1,431,685
2023-12-27 15:52:01
17,214,061
16
2013-06-20 12:49:19
1,983,854
2018-08-09 07:27:53
https://stackoverflow.com/q/17214038
https://stackoverflow.com/a/17214061
<p>Use <code>base64 --decode</code> together with a loop:</p> <pre><code>$ while IFS= read -r line; do echo "$line" | base64 --decode; done &lt; file cat dog house </code></pre>
<p>Use <code>base64 --decode</code> together with a loop:</p> <pre><code>$ while IFS= read -r line; do echo "$line" | base64 --decode; done &lt; file cat dog house </code></pre>
390, 1011, 1231, 10326
base64, command-line, shell, xargs
<h1>pipe each line of a file to a command</h1> <p>I have a text file which each line is a one word coded base64 separely. Now I want to decode it. I'm trying to use base64 command line, but I'm getting all the words in only one line, I want one per line.</p> <p>For example, my file is:</p> <pre><code>Y2F0Cg== ZG9nCg=...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,743
bash
# pipe each line of a file to a command I have a text file which each line is a one word coded base64 separely. Now I want to decode it. I'm trying to use base64 command line, but I'm getting all the words in only one line, I want one per line. For example, my file is: ``` Y2F0Cg== ZG9nCg== aG91c2UK ``` I want as r...
Use `base64 --decode` together with a loop: ``` $ while IFS= read -r line; do echo "$line" | base64 --decode; done < file cat dog house ```
12393999
Using a Variable (PowerShell) inside of a command
14
2012-09-12 18:11:21
<pre><code>$computer = gc env:computername # Argument /RU '$computer'\admin isn't working. SchTasks /create /SC Daily /tn "Image Verification" /ST 18:00:00 /TR C:\bdr\ImageVerification\ImageVerification.exe /RU '$computer'\admin /RP password </code></pre> <p>Basically I need to provide the computer name in the schedu...
39,474
1,231,701
2021-11-19 21:54:52
12,394,041
16
2012-09-12 18:14:27
153,982
2012-09-12 18:14:27
https://stackoverflow.com/q/12393999
https://stackoverflow.com/a/12394041
<p>Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.:</p> <pre><code>"$computer\admin" </code></pre>
<p>Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.:</p> <pre><code>"$computer\admin" </code></pre>
276, 526, 10804, 25968
powershell, quoting, string-interpolation, variables
<h1>Using a Variable (PowerShell) inside of a command</h1> <pre><code>$computer = gc env:computername # Argument /RU '$computer'\admin isn't working. SchTasks /create /SC Daily /tn "Image Verification" /ST 18:00:00 /TR C:\bdr\ImageVerification\ImageVerification.exe /RU '$computer'\admin /RP password </code></pre> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,744
bash
# Using a Variable (PowerShell) inside of a command ``` $computer = gc env:computername # Argument /RU '$computer'\admin isn't working. SchTasks /create /SC Daily /tn "Image Verification" /ST 18:00:00 /TR C:\bdr\ImageVerification\ImageVerification.exe /RU '$computer'\admin /RP password ``` Basically I need to provid...
Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.: ``` "$computer\admin" ```
11468984
How to give sudo access to a bash script?
14
2012-07-13 10:47:22
<p>I have a bash script (<code>chbr.sh</code>) to change my display brightness from terminal as my brightness keys doesn't work.</p> <pre><code>sudo setpci -s 00:02.0 F4.B=30` </code></pre> <p>Now, every time I run that script it asks for my password, which I don't like. So, I googled a little and found out that one ca...
30,656
933,999
2024-01-04 14:15:10
11,469,022
16
2012-07-13 10:50:50
1,458,569
2024-01-04 13:39:43
https://stackoverflow.com/q/11468984
https://stackoverflow.com/a/11469022
<p>Your script is entirely correct, but you need to execute it with the full path:</p> <pre><code>$ sudo /home/ronnie/chbr.sh </code></pre>
<p>Your script is entirely correct, but you need to execute it with the full path:</p> <pre><code>$ sudo /home/ronnie/chbr.sh </code></pre>
387, 1674, 34284
bash, sudo, sudoers
<h1>How to give sudo access to a bash script?</h1> <p>I have a bash script (<code>chbr.sh</code>) to change my display brightness from terminal as my brightness keys doesn't work.</p> <pre><code>sudo setpci -s 00:02.0 F4.B=30` </code></pre> <p>Now, every time I run that script it asks for my password, which I don't lik...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,745
bash
# How to give sudo access to a bash script? I have a bash script (`chbr.sh`) to change my display brightness from terminal as my brightness keys doesn't work. ``` sudo setpci -s 00:02.0 F4.B=30` ``` Now, every time I run that script it asks for my password, which I don't like. So, I googled a little and found out th...
Your script is entirely correct, but you need to execute it with the full path: ``` $ sudo /home/ronnie/chbr.sh ```
9439210
How can I make this PowerShell script parse large files faster?
14
2012-02-24 22:56:09
<p>I have the following PowerShell script that will parse some very large file for <a href="https://en.wikipedia.org/wiki/Extract,_transform,_load" rel="nofollow noreferrer">ETL</a> purposes. For starters my test file is ~ 30&nbsp;MB. Larger files around 200&nbsp;MB are expected. So I have a few questions.</p> <p>The ...
42,595
652,261
2016-12-13 20:07:41
9,439,750
16
2012-02-24 23:56:32
574,168
2016-12-13 20:07:41
https://stackoverflow.com/q/9439210
https://stackoverflow.com/a/9439750
<p>Your script reads one line at a time (slow!) and stores almost the entire file in memory (big!).</p> <p>Try this (not tested extensively):</p> <pre><code>$path = "E:\Documents\Projects\ESPS\Dev\DataFiles\DimProductionOrderOperation" $infile = "14SEP11_ProdOrderOperations.txt" $outfile = "PROCESSED_14SEP11_ProdOrde...
<p>Your script reads one line at a time (slow!) and stores almost the entire file in memory (big!).</p> <p>Try this (not tested extensively):</p> <pre><code>$path = "E:\Documents\Projects\ESPS\Dev\DataFiles\DimProductionOrderOperation" $infile = "14SEP11_ProdOrderOperations.txt" $outfile = "PROCESSED_14SEP11_ProdOrde...
526
powershell
<h1>How can I make this PowerShell script parse large files faster?</h1> <p>I have the following PowerShell script that will parse some very large file for <a href="https://en.wikipedia.org/wiki/Extract,_transform,_load" rel="nofollow noreferrer">ETL</a> purposes. For starters my test file is ~ 30&nbsp;MB. Larger files...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,746
bash
# How can I make this PowerShell script parse large files faster? I have the following PowerShell script that will parse some very large file for [ETL](https://en.wikipedia.org/wiki/Extract,_transform,_load) purposes. For starters my test file is ~ 30 MB. Larger files around 200 MB are expected. So I have a few questi...
Your script reads one line at a time (slow!) and stores almost the entire file in memory (big!). Try this (not tested extensively): ``` $path = "E:\Documents\Projects\ESPS\Dev\DataFiles\DimProductionOrderOperation" $infile = "14SEP11_ProdOrderOperations.txt" $outfile = "PROCESSED_14SEP11_ProdOrderOperations.txt" $ba...
7861886
how to get file properties?
14
2011-10-22 18:58:37
<p>I want an application which displays the some file properties of a mediafile if available, like (don't know the exact english words used in windows for it) FileName, Length/Duration, FileType(.avi .mp3 etc.) I tried taglib and windowsapishell but I dont get a working result (references are good)</p> <pre><code>She...
100,440
1,008,817
2020-01-28 13:17:23
7,861,915
16
2011-10-22 19:02:47
899,271
2020-01-28 13:17:23
https://stackoverflow.com/q/7861886
https://stackoverflow.com/a/7861915
<p>When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code:</p> <pre><code>FileInfo oFileInfo = new FileInfo(strFilename); if (oFileInfo != null || oFileInfo.Length == 0) { MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\""); // ...
<p>When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code:</p> <pre><code>FileInfo oFileInfo = new FileInfo(strFilename); if (oFileInfo != null || oFileInfo.Length == 0) { MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\""); // ...
9, 8123, 9322, 14319, 44420
c#, getproperties, taglib, windows-api-code-pack, windows-shell
<h1>how to get file properties?</h1> <p>I want an application which displays the some file properties of a mediafile if available, like (don't know the exact english words used in windows for it) FileName, Length/Duration, FileType(.avi .mp3 etc.) I tried taglib and windowsapishell but I dont get a working result (ref...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,747
bash
# how to get file properties? I want an application which displays the some file properties of a mediafile if available, like (don't know the exact english words used in windows for it) FileName, Length/Duration, FileType(.avi .mp3 etc.) I tried taglib and windowsapishell but I dont get a working result (references ar...
When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code: ``` FileInfo oFileInfo = new FileInfo(strFilename); if (oFileInfo != null || oFileInfo.Length == 0) { MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\""); // For calculatin...
6781225
How do I check if a directory has child directories?
14
2011-07-21 18:57:17
<p>Using bash, how do I write an if statement that checks if a certain directory, stored in the a script variable named "$DIR", contains child directories that are not "." or ".."?</p> <p>Thanks, - Dave</p>
22,942
623,658
2022-03-21 18:12:32
6,781,343
16
2011-07-21 19:07:13
157,770
2020-07-21 18:24:53
https://stackoverflow.com/q/6781225
https://stackoverflow.com/a/6781343
<p>As the comments have pointed out, things have changed in the last 9 years! The dot dirs are no longer returned as part of find and instead the directory specified in the <code>find</code> command is.</p> <p>So, if you want to stay with this approach:</p> <pre><code>#!/bin/bash subdircount=$(find /tmp/test -maxdepth ...
<p>As the comments have pointed out, things have changed in the last 9 years! The dot dirs are no longer returned as part of find and instead the directory specified in the <code>find</code> command is.</p> <p>So, if you want to stay with this approach:</p> <pre><code>#!/bin/bash subdircount=$(find /tmp/test -maxdepth ...
34, 387, 531
bash, scripting, unix
<h1>How do I check if a directory has child directories?</h1> <p>Using bash, how do I write an if statement that checks if a certain directory, stored in the a script variable named "$DIR", contains child directories that are not "." or ".."?</p> <p>Thanks, - Dave</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,748
bash
# How do I check if a directory has child directories? Using bash, how do I write an if statement that checks if a certain directory, stored in the a script variable named "$DIR", contains child directories that are not "." or ".."? Thanks, - Dave
As the comments have pointed out, things have changed in the last 9 years! The dot dirs are no longer returned as part of find and instead the directory specified in the `find` command is. So, if you want to stay with this approach: ``` #!/bin/bash subdircount=$(find /tmp/test -maxdepth 1 -type d | wc -l) if [[ "$su...
2797974
Testing a shellcode
14
2010-05-09 14:49:17
<p>I have this piece of code to test a shellcode but I don't understand it so can anyone explain it to me?</p> <p>Forget about the assembly shellcode, what I want to understand is the C code,</p> <pre><code>char shellcode[] = "..."; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) shellcode; ...
9,001
324,894
2014-08-19 07:31:17
2,798,070
16
2010-05-09 15:15:03
58,100
2010-05-09 15:15:03
https://stackoverflow.com/q/2797974
https://stackoverflow.com/a/2798070
<pre><code>int (*func)(); </code></pre> <p>This is a declaration of a function pointer. A function pointer is essentially a variable that holds the address of a function. In this case, the type of function that <code>func</code> points to is a one that takes no arguments and returns an <code>int</code>. You can assign...
<pre><code>int (*func)(); </code></pre> <p>This is a declaration of a function pointer. A function pointer is essentially a variable that holds the address of a function. In this case, the type of function that <code>func</code> points to is a one that takes no arguments and returns an <code>int</code>. You can assign...
8, 78469
c, shellcode
<h1>Testing a shellcode</h1> <p>I have this piece of code to test a shellcode but I don't understand it so can anyone explain it to me?</p> <p>Forget about the assembly shellcode, what I want to understand is the C code,</p> <pre><code>char shellcode[] = "..."; int main(int argc, char **argv) { int (*func)(); fu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,749
bash
# Testing a shellcode I have this piece of code to test a shellcode but I don't understand it so can anyone explain it to me? Forget about the assembly shellcode, what I want to understand is the C code, ``` char shellcode[] = "..."; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) shellcode; ...
``` int (*func)(); ``` This is a declaration of a function pointer. A function pointer is essentially a variable that holds the address of a function. In this case, the type of function that `func` points to is a one that takes no arguments and returns an `int`. You can assign the address of a function to this variabl...
26123
Accessing .NET components from Powershell
14
2008-08-25 14:33:18
<p>I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work. This is in place of writing a small console app to tie the calls together. My question is where I would find a good source of documentation or tutorial material to help me fast track this?</p>
7,486
1,535
2016-11-15 13:51:52
26,135
16
2008-08-25 14:38:13
1,233
2015-09-25 17:33:00
https://stackoverflow.com/q/26123
https://stackoverflow.com/a/26135
<p>If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly.</p> <pre><code>[void][System.Reflection.Assembly]::LoadFrom(PathToYourAssembly) </code></pre> <p>After you load your assembly, you can call static methods and create new instances of a class. </p> <p>A goo...
<p>If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly.</p> <pre><code>[void][System.Reflection.Assembly]::LoadFrom(PathToYourAssembly) </code></pre> <p>After you load your assembly, you can call static methods and create new instances of a class. </p> <p>A goo...
526, 1649
components, powershell
<h1>Accessing .NET components from Powershell</h1> <p>I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work. This is in place of writing a small console app to tie the calls together. My question is where I would find a good source of documentation or tutorial ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,750
bash
# Accessing .NET components from Powershell I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work. This is in place of writing a small console app to tie the calls together. My question is where I would find a good source of documentation or tutorial material to...
If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly. ``` [void][System.Reflection.Assembly]::LoadFrom(PathToYourAssembly) ``` After you load your assembly, you can call static methods and create new instances of a class. A good tutorial can be found [here](http:...
64436812
Write-Information does not appear to work in powershell foreach-object -parallel
13
2020-10-20 00:24:23
<p>I am new to powershell and just learning it. I have some experience in C#. I am trying to use the foreach-object -Parallel option but cant get all the Write-* functions to work.</p> <pre><code>function writeTest { 1..1 | ForEach-Object -Parallel { Write-Host &quot;host&quot; Write-O...
6,770
14,481,723
2020-10-20 20:32:48
64,437,919
16
2020-10-20 03:11:21
45,375
2020-10-20 20:32:48
https://stackoverflow.com/q/64436812
https://stackoverflow.com/a/64437919
<p><strong>You're seeing a <em>bug</em></strong> in <code>ForEach-Object -Parallel</code> / <code>Start-ThreadJob</code>, present up to at least PowerShell Core 7.0:</p> <p>Your <code>Write-Information</code> output <em>should</em> show, because you've used <code>-InformationAction Continue</code> to turn it on; while ...
<p><strong>You're seeing a <em>bug</em></strong> in <code>ForEach-Object -Parallel</code> / <code>Start-ThreadJob</code>, present up to at least PowerShell Core 7.0:</p> <p>Your <code>Write-Information</code> output <em>should</em> show, because you've used <code>-InformationAction Continue</code> to turn it on; while ...
353, 526, 84917, 136520, 144089
foreach-object, output, parallel-processing, powershell, powershell-7.0
<h1>Write-Information does not appear to work in powershell foreach-object -parallel</h1> <p>I am new to powershell and just learning it. I have some experience in C#. I am trying to use the foreach-object -Parallel option but cant get all the Write-* functions to work.</p> <pre><code>function writeTest { 1.....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,751
bash
# Write-Information does not appear to work in powershell foreach-object -parallel I am new to powershell and just learning it. I have some experience in C#. I am trying to use the foreach-object -Parallel option but cant get all the Write-* functions to work. ``` function writeTest { 1..1 | ForEach-Object -P...
**You're seeing a *bug*** in `ForEach-Object -Parallel` / `Start-ThreadJob`, present up to at least PowerShell Core 7.0: Your `Write-Information` output *should* show, because you've used `-InformationAction Continue` to turn it on; while your `Write-Verbose` output not showing is expected, because you didn't turn it ...
56691220
Set-AzContext works in Azure Cloud Shell but doesn't in Azure PowerShell
13
2019-06-20 17:34:17
<p>When i execute following command </p> <pre><code>Clear-AzureProfile Connect-AzAccount -TenantID xxxxxxxxxxxxxxxxxxx Set-AzContext -SubscriptionId xxxxxxxxxxxxxxxxxxx </code></pre> <p>in <code>Azure PowerShell</code> i get this error. </p> <pre><code>Set-AzContext : Please provide a valid tenant or a valid subscri...
21,287
3,355,307
2023-07-31 14:41:35
56,700,929
16
2019-06-21 09:47:51
9,455,659
2019-06-21 09:47:51
https://stackoverflow.com/q/56691220
https://stackoverflow.com/a/56700929
<p>Close your powershell and open a new one, or use <code>Clear-AzContext</code>, not <code>Clear-AzureProfile</code>. Then use <code>Connect-AzAccount -Tenant xxxxx -Subscription xxxxx</code>, it should work.</p>
<p>Close your powershell and open a new one, or use <code>Clear-AzContext</code>, not <code>Clear-AzureProfile</code>. Then use <code>Connect-AzAccount -Tenant xxxxx -Subscription xxxxx</code>, it should work.</p>
526, 14158, 81879, 126343
azure, azure-cloud-shell, azure-powershell, powershell
<h1>Set-AzContext works in Azure Cloud Shell but doesn't in Azure PowerShell</h1> <p>When i execute following command </p> <pre><code>Clear-AzureProfile Connect-AzAccount -TenantID xxxxxxxxxxxxxxxxxxx Set-AzContext -SubscriptionId xxxxxxxxxxxxxxxxxxx </code></pre> <p>in <code>Azure PowerShell</code> i get this error....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,752
bash
# Set-AzContext works in Azure Cloud Shell but doesn't in Azure PowerShell When i execute following command ``` Clear-AzureProfile Connect-AzAccount -TenantID xxxxxxxxxxxxxxxxxxx Set-AzContext -SubscriptionId xxxxxxxxxxxxxxxxxxx ``` in `Azure PowerShell` i get this error. ``` Set-AzContext : Please provide a valid ...
Close your powershell and open a new one, or use `Clear-AzContext`, not `Clear-AzureProfile`. Then use `Connect-AzAccount -Tenant xxxxx -Subscription xxxxx`, it should work.
56586562
How to source an entry point script with Docker?
13
2019-06-13 18:26:18
<p>I have an Docker image and I can run it:</p> <pre><code>docker run -it --entrypoint="/bin/bash" gcr.io/docker:tag </code></pre> <p>Then I can source a script in the following way:</p> <pre><code>root@86bfac2f6ccc:/# source entrypoint.sh </code></pre> <p>The script looks like that:</p> <pre><code>more entrypoint...
54,406
6,430,839
2020-03-12 14:55:00
56,587,335
16
2019-06-13 19:24:56
10,008,173
2019-06-13 19:24:56
https://stackoverflow.com/q/56586562
https://stackoverflow.com/a/56587335
<p>When Docker launches a container, there are two parts, the “entrypoint” and the “command”. When both are specified, the “command” part is passed as command-line arguments to the “entrypoint” part.</p> <p>In particular, the script you show has a very typical pattern for an entrypoint script:</p> <pre><code>#!/bin/...
<p>When Docker launches a container, there are two parts, the “entrypoint” and the “command”. When both are specified, the “command” part is passed as command-line arguments to the “entrypoint” part.</p> <p>In particular, the script you show has a very typical pattern for an entrypoint script:</p> <pre><code>#!/bin/...
387, 31391, 90304, 96537
bash, conda, docker, entry-point
<h1>How to source an entry point script with Docker?</h1> <p>I have an Docker image and I can run it:</p> <pre><code>docker run -it --entrypoint="/bin/bash" gcr.io/docker:tag </code></pre> <p>Then I can source a script in the following way:</p> <pre><code>root@86bfac2f6ccc:/# source entrypoint.sh </code></pre> <p>T...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,753
bash
# How to source an entry point script with Docker? I have an Docker image and I can run it: ``` docker run -it --entrypoint="/bin/bash" gcr.io/docker:tag ``` Then I can source a script in the following way: ``` root@86bfac2f6ccc:/# source entrypoint.sh ``` The script looks like that: ``` more entrypoint.sh #!/bin...
When Docker launches a container, there are two parts, the “entrypoint” and the “command”. When both are specified, the “command” part is passed as command-line arguments to the “entrypoint” part. In particular, the script you show has a very typical pattern for an entrypoint script: ``` #!/bin/sh # ... do some setup...
44894652
How do I insert text to the 1st line of a file using sed?
13
2017-07-03 22:40:57
<p>Hi I'm trying to add text to the 1st line of a file using sed so far iv'e tried</p> <pre><code>#!/bin/bash touch test sed -i -e '1i/etc/example/live/example.com/fullchain.pem;\' test </code></pre> <p>And this dosn't work also tried </p> <pre><code>#!/bin/bash touch test sed -i "1i ssl_certificate /etc/example/li...
29,201
3,700,919
2021-11-11 22:31:36
44,894,788
16
2017-07-03 23:00:10
404,556
2017-07-03 23:14:18
https://stackoverflow.com/q/44894652
https://stackoverflow.com/a/44894788
<p>Suppose you have a <code>file</code> like this:</p> <pre><code>one two </code></pre> <p>Then to append to the first line:</p> <pre><code>$ sed '1 s_$_/etc/example/live/example.com/fullchain.pem;_' file one/etc/example/live/example.com/fullchain.pem; two </code></pre> <p>To insert before the first line:</p> <pre...
<p>Suppose you have a <code>file</code> like this:</p> <pre><code>one two </code></pre> <p>Then to append to the first line:</p> <pre><code>$ sed '1 s_$_/etc/example/live/example.com/fullchain.pem;_' file one/etc/example/live/example.com/fullchain.pem; two </code></pre> <p>To insert before the first line:</p> <pre...
58, 387, 390, 531, 5282
bash, linux, scripting, sed, shell
<h1>How do I insert text to the 1st line of a file using sed?</h1> <p>Hi I'm trying to add text to the 1st line of a file using sed so far iv'e tried</p> <pre><code>#!/bin/bash touch test sed -i -e '1i/etc/example/live/example.com/fullchain.pem;\' test </code></pre> <p>And this dosn't work also tried </p> <pre><cod...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,754
bash
# How do I insert text to the 1st line of a file using sed? Hi I'm trying to add text to the 1st line of a file using sed so far iv'e tried ``` #!/bin/bash touch test sed -i -e '1i/etc/example/live/example.com/fullchain.pem;\' test ``` And this dosn't work also tried ``` #!/bin/bash touch test sed -i "1i ssl_certif...
Suppose you have a `file` like this: ``` one two ``` Then to append to the first line: ``` $ sed '1 s_$_/etc/example/live/example.com/fullchain.pem;_' file one/etc/example/live/example.com/fullchain.pem; two ``` To insert before the first line: ``` $ sed '1 i /etc/example/live/example.com/fullchain.pem;' file /etc...
40231125
Appium Doctor - unable to set $JAVA_HOME/bin into PATH variable on MacOS 10.12
13
2016-10-25 03:56:08
<p>Installed appium doctor with npm on MacOS 10.12, and it gives me one error: </p> <pre><code>WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set. </code></pre> <p>I've tried everything I could so far, please help. Here is my .bash_profile:</p> <pre><code>export ANDROID_HOME="/Users/sergei/Library/Android/s...
39,822
5,917,497
2021-09-22 09:07:24
40,276,857
16
2016-10-27 05:35:02
5,917,497
2016-10-27 05:35:02
https://stackoverflow.com/q/40231125
https://stackoverflow.com/a/40276857
<p>I removed double quotes from the paths and slashes from the end This is working fine for me now: </p> <pre><code>export ANDROID_HOME=/Users/sergei/Library/Android/sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112....
<p>I removed double quotes from the paths and slashes from the end This is working fine for me now: </p> <pre><code>export ANDROID_HOME=/Users/sergei/Library/Android/sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112....
17, 387, 6268, 26220, 90230
appium, bash, java, java-home, path
<h1>Appium Doctor - unable to set $JAVA_HOME/bin into PATH variable on MacOS 10.12</h1> <p>Installed appium doctor with npm on MacOS 10.12, and it gives me one error: </p> <pre><code>WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set. </code></pre> <p>I've tried everything I could so far, please help. Here i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,755
bash
# Appium Doctor - unable to set $JAVA_HOME/bin into PATH variable on MacOS 10.12 Installed appium doctor with npm on MacOS 10.12, and it gives me one error: ``` WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set. ``` I've tried everything I could so far, please help. Here is my .bash_profile: ``` export AN...
I removed double quotes from the paths and slashes from the end This is working fine for me now: ``` export ANDROID_HOME=/Users/sergei/Library/Android/sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Ho...
35544015
How to freeze brew requirements like pip?
13
2016-02-22 00:35:25
<p>Is there a way or a special command in brew to freeze the installed packages into a requirements.txt file, just like you can with pip in python? And then to quickly reinstall them all from that file?</p>
6,853
2,039,597
2016-02-22 11:14:19
35,544,150
16
2016-02-22 00:52:01
162,768
2016-02-22 01:33:59
https://stackoverflow.com/q/35544015
https://stackoverflow.com/a/35544150
<p>Edit to answer question w/o version freezing.</p> <pre><code>brew list &gt;brew.txt &lt;brew.txt xargs brew install </code></pre> <p>--</p> <p>Homebrew is designed to give you the latest versions of packages. Freezing versions is not its strong point.</p> <p>There are two features that get you part of the way. <...
<p>Edit to answer question w/o version freezing.</p> <pre><code>brew list &gt;brew.txt &lt;brew.txt xargs brew install </code></pre> <p>--</p> <p>Homebrew is designed to give you the latest versions of packages. Freezing versions is not its strong point.</p> <p>There are two features that get you part of the way. <...
16, 390, 529, 1067, 1796
command, homebrew, installation, python, shell
<h1>How to freeze brew requirements like pip?</h1> <p>Is there a way or a special command in brew to freeze the installed packages into a requirements.txt file, just like you can with pip in python? And then to quickly reinstall them all from that file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,756
bash
# How to freeze brew requirements like pip? Is there a way or a special command in brew to freeze the installed packages into a requirements.txt file, just like you can with pip in python? And then to quickly reinstall them all from that file?
Edit to answer question w/o version freezing. ``` brew list >brew.txt <brew.txt xargs brew install ``` -- Homebrew is designed to give you the latest versions of packages. Freezing versions is not its strong point. There are two features that get you part of the way. `brew list --versions` will print a list of pack...
26304266
BASH printf array with field separator and newline on last entry
13
2014-10-10 16:47:43
<p>How can I print out an array in BASH with a field separator between each value and a newline at the end.</p> <p>The closest I can get with a single printf is <code>printf '%s|' "${arr1[@]}"</code> where | is the field separator. The problem with this is there is no line break at the end. Any combination of \n I tr...
27,061
2,255,594
2024-05-11 19:31:01
26,304,373
16
2014-10-10 16:55:16
14,122
2014-10-10 16:55:16
https://stackoverflow.com/q/26304266
https://stackoverflow.com/a/26304373
<p>Yes, you need two commands for this. <code>printf '%s|' "${array[@]}"; echo</code> is perfectly conventional.</p> <p>Alternately, if you don't want the trailing <code>|</code>, you can temporarily modify <code>IFS</code> to use your chosen separator as its first character, and use <code>"${array[*]}"</code>:</p> <...
<p>Yes, you need two commands for this. <code>printf '%s|' "${array[@]}"; echo</code> is perfectly conventional.</p> <p>Alternately, if you don't want the trailing <code>|</code>, you can temporarily modify <code>IFS</code> to use your chosen separator as its first character, and use <code>"${array[*]}"</code>:</p> <...
387, 1156
bash, printf
<h1>BASH printf array with field separator and newline on last entry</h1> <p>How can I print out an array in BASH with a field separator between each value and a newline at the end.</p> <p>The closest I can get with a single printf is <code>printf '%s|' "${arr1[@]}"</code> where | is the field separator. The problem ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,757
bash
# BASH printf array with field separator and newline on last entry How can I print out an array in BASH with a field separator between each value and a newline at the end. The closest I can get with a single printf is `printf '%s|' "${arr1[@]}"` where | is the field separator. The problem with this is there is no lin...
Yes, you need two commands for this. `printf '%s|' "${array[@]}"; echo` is perfectly conventional. Alternately, if you don't want the trailing `|`, you can temporarily modify `IFS` to use your chosen separator as its first character, and use `"${array[*]}"`: ``` IFS="|$IFS"; printf '%s\n' "${array[*]}"; IFS="${IFS:1}...
22402054
What is the simplest way to delete the contents of a file in BASH?
13
2014-03-14 10:14:37
<p>I need to delete all lines in a file, but leave essentially an empty file with no content and no lines. As best I know, one can do this:</p> <pre><code>rm file.txt 2&gt; /dev/null touch file.txt </code></pre> <p>However, is there a simpler, more canonical solution in BASH?</p>
18,645
834,616
2014-03-14 12:29:31
22,402,310
16
2014-03-14 10:24:31
480,641
2014-03-14 10:24:31
https://stackoverflow.com/q/22402054
https://stackoverflow.com/a/22402310
<p>You can use truncate.</p> <pre><code>truncate -s 0 filename </code></pre>
<p>You can use truncate.</p> <pre><code>truncate -s 0 filename </code></pre>
387
bash
<h1>What is the simplest way to delete the contents of a file in BASH?</h1> <p>I need to delete all lines in a file, but leave essentially an empty file with no content and no lines. As best I know, one can do this:</p> <pre><code>rm file.txt 2&gt; /dev/null touch file.txt </code></pre> <p>However, is there a simpler...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,758
bash
# What is the simplest way to delete the contents of a file in BASH? I need to delete all lines in a file, but leave essentially an empty file with no content and no lines. As best I know, one can do this: ``` rm file.txt 2> /dev/null touch file.txt ``` However, is there a simpler, more canonical solution in BASH?
You can use truncate. ``` truncate -s 0 filename ```
22187834
gnu parallel: output each job to a different file
13
2014-03-05 03:20:29
<p>I am trying to process so text files with <code>awk</code> using the <code>parallel</code> command as a shell script, but haven't been able to get it to output each job to a different file</p> <p>If i try:</p> <pre><code>seq 10 | parallel awk \''{ if ( $5 &gt; 0.4 ) print $2}'\' file{}.txt &gt; file{}.out </code><...
9,665
2,341,679
2022-11-30 16:47:23
22,188,070
16
2014-03-05 03:43:40
2,341,679
2014-03-05 03:43:40
https://stackoverflow.com/q/22187834
https://stackoverflow.com/a/22188070
<p>It turns out I needed to quote out the redirect, because it was being processed outside of <code>parallel</code>:</p> <pre><code>seq 10 | parallel awk \''{...}'\' file{}.txt "&gt;" file{}.out </code></pre>
<p>It turns out I needed to quote out the redirect, because it was being processed outside of <code>parallel</code>:</p> <pre><code>seq 10 | parallel awk \''{...}'\' file{}.txt "&gt;" file{}.out </code></pre>
387, 82247
bash, gnu-parallel
<h1>gnu parallel: output each job to a different file</h1> <p>I am trying to process so text files with <code>awk</code> using the <code>parallel</code> command as a shell script, but haven't been able to get it to output each job to a different file</p> <p>If i try:</p> <pre><code>seq 10 | parallel awk \''{ if ( $5 ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,759
bash
# gnu parallel: output each job to a different file I am trying to process so text files with `awk` using the `parallel` command as a shell script, but haven't been able to get it to output each job to a different file If i try: ``` seq 10 | parallel awk \''{ if ( $5 > 0.4 ) print $2}'\' file{}.txt > file{}.out ``` ...
It turns out I needed to quote out the redirect, because it was being processed outside of `parallel`: ``` seq 10 | parallel awk \''{...}'\' file{}.txt ">" file{}.out ```
17743430
Error: Could not find or load main class xxx Linux
13
2013-07-19 10:05:30
<p>I am very new to linux environment.</p> <p>I am trying to run an simple hello world java class in linux environment.</p> <h1>Hello .java</h1> <pre><code> package com.util; public class Hello { /** * @param args */ public static void main(String[] args) { System....
65,907
1,660,325
2022-10-16 00:31:07
17,743,942
16
2013-07-19 10:30:47
112,500
2013-07-19 10:35:54
https://stackoverflow.com/q/17743430
https://stackoverflow.com/a/17743942
<p>navigate to /home/scripts using terminal</p> <pre><code>javac com/util/Hello.java </code></pre> <p>then</p> <pre><code>cd /home/scripts java -cp . com.util.Hello </code></pre> <p>Or,</p> <pre><code>java -cp "/home/scripts" com.util.Hello </code></pre>
<p>navigate to /home/scripts using terminal</p> <pre><code>javac com/util/Hello.java </code></pre> <p>then</p> <pre><code>cd /home/scripts java -cp . com.util.Hello </code></pre> <p>Or,</p> <pre><code>java -cp "/home/scripts" com.util.Hello </code></pre>
17, 58, 390
java, linux, shell
<h1>Error: Could not find or load main class xxx Linux</h1> <p>I am very new to linux environment.</p> <p>I am trying to run an simple hello world java class in linux environment.</p> <h1>Hello .java</h1> <pre><code> package com.util; public class Hello { /** * @param args */ ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,760
bash
# Error: Could not find or load main class xxx Linux I am very new to linux environment. I am trying to run an simple hello world java class in linux environment. # Hello .java ``` package com.util; public class Hello { /** * @param args */ public static void main(String[] a...
navigate to /home/scripts using terminal ``` javac com/util/Hello.java ``` then ``` cd /home/scripts java -cp . com.util.Hello ``` Or, ``` java -cp "/home/scripts" com.util.Hello ```
12945987
recursively rename directories in bash
13
2012-10-18 01:54:09
<p>I'd like to recursively rename all directories containing the string <em>foo</em> by replacing that part of the string with <em>Bar</em>. I've got something like this so far, but it doesn't quite work. I'd also like <em>foo</em> to be searched <strong>case-insensitive</strong>.</p> <p><code>find . -type d -exec b...
10,321
332,913
2023-10-13 18:24:07
12,946,034
16
2012-10-18 02:03:11
465,183
2023-10-13 18:24:07
https://stackoverflow.com/q/12945987
https://stackoverflow.com/a/12946034
<p>Try the following code using <em>parameter expansion</em></p> <pre><code>find . -type d -iname '*foo*' -depth -exec bash -c ' echo mv &quot;$1&quot; &quot;${1//[Ff][Oo][Oo]/BAr}&quot; ' -- {} \; </code></pre> <p>But your best bet will be using <a href="https://unix.stackexchange.com/questions/730894/what-about-r...
<p>Try the following code using <em>parameter expansion</em></p> <pre><code>find . -type d -iname '*foo*' -depth -exec bash -c ' echo mv &quot;$1&quot; &quot;${1//[Ff][Oo][Oo]/BAr}&quot; ' -- {} \; </code></pre> <p>But your best bet will be using <a href="https://unix.stackexchange.com/questions/730894/what-about-r...
387
bash
<h1>recursively rename directories in bash</h1> <p>I'd like to recursively rename all directories containing the string <em>foo</em> by replacing that part of the string with <em>Bar</em>. I've got something like this so far, but it doesn't quite work. I'd also like <em>foo</em> to be searched <strong>case-insensitiv...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,761
bash
# recursively rename directories in bash I'd like to recursively rename all directories containing the string *foo* by replacing that part of the string with *Bar*. I've got something like this so far, but it doesn't quite work. I'd also like *foo* to be searched **case-insensitive**. `find . -type d -exec bash -c 'm...
Try the following code using *parameter expansion* ``` find . -type d -iname '*foo*' -depth -exec bash -c ' echo mv "$1" "${1//[Ff][Oo][Oo]/BAr}" ' -- {} \; ``` But your best bet will be using [Perl's `rename`](https://unix.stackexchange.com/questions/730894/what-about-rename-different-versions-and-usage-what-is-...