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
11523150
How Do You Monitor The CPU Utilization of a Process Using PowerShell?
13
2012-07-17 13:06:31
<p>I'm trying to write a PowerShell script to monitor % CPU utilization of a SQL Server process. I'd like to record snapshots of this number every day so we can monitor it over time and watch for trends.</p> <p>My research online said this WMI query should give me what I want:</p> <pre><code>Get-WmiObject -Query "SEL...
29,759
1,066,291
2012-09-03 14:58:48
11,565,773
16
2012-07-19 16:59:49
1,066,291
2012-08-22 17:24:53
https://stackoverflow.com/q/11523150
https://stackoverflow.com/a/11565773
<p>Everything I've learned about WMI and performance counters over the last couple of days.</p> <p>WMI stands for Windows Management Instrumentation. WMI is a collection of classes registered with the WMI system and the Windows COM subsystem. These classes are known as providers and have any number of public propertie...
<p>Everything I've learned about WMI and performance counters over the last couple of days.</p> <p>WMI stands for Windows Management Instrumentation. WMI is a collection of classes registered with the WMI system and the Windows COM subsystem. These classes are known as providers and have any number of public propertie...
72, 526, 680
powershell, sql-server, wmi
<h1>How Do You Monitor The CPU Utilization of a Process Using PowerShell?</h1> <p>I'm trying to write a PowerShell script to monitor % CPU utilization of a SQL Server process. I'd like to record snapshots of this number every day so we can monitor it over time and watch for trends.</p> <p>My research online said this ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,762
bash
# How Do You Monitor The CPU Utilization of a Process Using PowerShell? I'm trying to write a PowerShell script to monitor % CPU utilization of a SQL Server process. I'd like to record snapshots of this number every day so we can monitor it over time and watch for trends. My research online said this WMI query should...
Everything I've learned about WMI and performance counters over the last couple of days. WMI stands for Windows Management Instrumentation. WMI is a collection of classes registered with the WMI system and the Windows COM subsystem. These classes are known as providers and have any number of public properties that ret...
6362428
How do I determine if a shell script is running with root permissions?
13
2011-06-15 18:21:14
<p>I've got a script I want to require be run with su privileges, but the interesting scripted command that will fail comes very late in the script, so I'd like a clean test up front to determine if the scrip will fail without SU capabilities.</p> <p>What is a good way to do this for bash, sh, and/or csh?</p>
10,584
523,113
2019-10-21 06:20:07
6,362,604
16
2011-06-15 18:36:54
530,160
2019-10-21 06:20:07
https://stackoverflow.com/q/6362428
https://stackoverflow.com/a/6362604
<p>bash/sh:</p> <pre><code>#!/usr/bin/env bash # (Use #!/bin/sh for sh) if [ `id -u` = 0 ] ; then echo "I AM ROOT, HEAR ME ROAR" fi </code></pre> <p>csh:</p> <pre><code>#!/bin/csh if ( `id -u` == "0" ) then echo "I AM ROOT, HEAR ME ROAR" endif </code></pre>
<p>bash/sh:</p> <pre><code>#!/usr/bin/env bash # (Use #!/bin/sh for sh) if [ `id -u` = 0 ] ; then echo "I AM ROOT, HEAR ME ROAR" fi </code></pre> <p>csh:</p> <pre><code>#!/bin/csh if ( `id -u` == "0" ) then echo "I AM ROOT, HEAR ME ROAR" endif </code></pre>
359, 390, 1674
permissions, shell, sudo
<h1>How do I determine if a shell script is running with root permissions?</h1> <p>I've got a script I want to require be run with su privileges, but the interesting scripted command that will fail comes very late in the script, so I'd like a clean test up front to determine if the scrip will fail without SU capabiliti...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,763
bash
# How do I determine if a shell script is running with root permissions? I've got a script I want to require be run with su privileges, but the interesting scripted command that will fail comes very late in the script, so I'd like a clean test up front to determine if the scrip will fail without SU capabilities. What...
bash/sh: ``` #!/usr/bin/env bash # (Use #!/bin/sh for sh) if [ `id -u` = 0 ] ; then echo "I AM ROOT, HEAR ME ROAR" fi ``` csh: ``` #!/bin/csh if ( `id -u` == "0" ) then echo "I AM ROOT, HEAR ME ROAR" endif ```
4926060
PowerShell: Runspace problem with DownloadFileAsync
13
2011-02-07 20:16:13
<p>I needed to download file using <code>WebClient</code> in PowerShell 2.0, and I wanted to show download progress, so I did it this way:</p> <pre><code>$activity = "Downloading" $client = New-Object System.Net.WebClient $urlAsUri = New-Object System.Uri($url) $event = New-Object System.Threading.ManualResetEvent($...
8,540
39,068
2013-03-18 08:49:02
4,927,295
16
2011-02-07 22:16:44
6,920
2013-03-18 08:49:02
https://stackoverflow.com/q/4926060
https://stackoverflow.com/a/4927295
<p>Thanks stej for the nod. </p> <p>Andrey, powershell has its own threadpool and each service thread keeps a threadstatic pointer to a runspace (the System.Management.Automation.Runspaces.Runspace.DefaultRunspace static member exposes this - and would be a null ref in your callbacks.) Ultimately this means it's diffi...
<p>Thanks stej for the nod. </p> <p>Andrey, powershell has its own threadpool and each service thread keeps a threadstatic pointer to a runspace (the System.Management.Automation.Runspaces.Runspace.DefaultRunspace static member exposes this - and would be a null ref in your callbacks.) Ultimately this means it's diffi...
526, 1381
multithreading, powershell
<h1>PowerShell: Runspace problem with DownloadFileAsync</h1> <p>I needed to download file using <code>WebClient</code> in PowerShell 2.0, and I wanted to show download progress, so I did it this way:</p> <pre><code>$activity = "Downloading" $client = New-Object System.Net.WebClient $urlAsUri = New-Object System.Uri($...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,764
bash
# PowerShell: Runspace problem with DownloadFileAsync I needed to download file using `WebClient` in PowerShell 2.0, and I wanted to show download progress, so I did it this way: ``` $activity = "Downloading" $client = New-Object System.Net.WebClient $urlAsUri = New-Object System.Uri($url) $event = New-Object Syste...
Thanks stej for the nod. Andrey, powershell has its own threadpool and each service thread keeps a threadstatic pointer to a runspace (the System.Management.Automation.Runspaces.Runspace.DefaultRunspace static member exposes this - and would be a null ref in your callbacks.) Ultimately this means it's difficult - espe...
3927062
Problem with backticks in shellscript
13
2010-10-13 19:00:51
<p>I am having a problem getting my shellscript working using backticks. Here is an example version of the script I am having an issue with:</p> <pre><code>#!/bin/sh ECHO_TEXT="Echo this" ECHO_CMD="echo ${ECHO_TEXT} | awk -F' ' '{print \$1}'" result=`${ECHO_CMD}`; echo $result; result=`echo ${ECHO_TEXT} | awk -F' ...
26,687
45,129
2010-10-13 20:45:35
3,927,167
16
2010-10-13 19:14:18
227,665
2010-10-13 19:19:19
https://stackoverflow.com/q/3927062
https://stackoverflow.com/a/3927167
<p>You need to use <code>eval</code> to get it working</p> <pre><code>result=`eval ${ECHO_CMD}`; </code></pre> <p>in place of</p> <pre><code>result=`${ECHO_CMD}`; </code></pre> <p>Without <code>eval</code> </p> <pre><code>${ECHO_TEXT} | awk -F' ' '{print \$1} </code></pre> <p>which will be expanded to</p> <pre><...
<p>You need to use <code>eval</code> to get it working</p> <pre><code>result=`eval ${ECHO_CMD}`; </code></pre> <p>in place of</p> <pre><code>result=`${ECHO_CMD}`; </code></pre> <p>Without <code>eval</code> </p> <pre><code>${ECHO_TEXT} | awk -F' ' '{print \$1} </code></pre> <p>which will be expanded to</p> <pre><...
390, 28438
backticks, shell
<h1>Problem with backticks in shellscript</h1> <p>I am having a problem getting my shellscript working using backticks. Here is an example version of the script I am having an issue with:</p> <pre><code>#!/bin/sh ECHO_TEXT="Echo this" ECHO_CMD="echo ${ECHO_TEXT} | awk -F' ' '{print \$1}'" result=`${ECHO_CMD}`; echo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,765
bash
# Problem with backticks in shellscript I am having a problem getting my shellscript working using backticks. Here is an example version of the script I am having an issue with: ``` #!/bin/sh ECHO_TEXT="Echo this" ECHO_CMD="echo ${ECHO_TEXT} | awk -F' ' '{print \$1}'" result=`${ECHO_CMD}`; echo $result; result=`ec...
You need to use `eval` to get it working ``` result=`eval ${ECHO_CMD}`; ``` in place of ``` result=`${ECHO_CMD}`; ``` Without `eval` ``` ${ECHO_TEXT} | awk -F' ' '{print \$1} ``` which will be expanded to ``` Echo this | awk -F' ' '{print \$1} ``` will be treated as argument to `echo` and will be output verbati...
3605522
how to iterate over files with powershell?
13
2010-08-31 01:54:10
<p>I want to iterate over files in a folder using powershell script;</p>
12,311
161,758
2013-02-13 15:30:26
3,605,532
16
2010-08-31 02:00:14
73,070
2013-02-13 15:30:26
https://stackoverflow.com/q/3605522
https://stackoverflow.com/a/3605532
<pre><code>Get-ChildItem | ForEach-Object { &lt;# do what you need to do #&gt; } </code></pre> <p>or shorter:</p> <pre><code>gci | % { &lt;# ... #&gt; } </code></pre> <p>or if you want an explicit looping construct:</p> <pre><code>foreach ($file in Get-ChildItem) { # ... } </code></pre> <p>Note however, that <...
<pre><code>Get-ChildItem | ForEach-Object { &lt;# do what you need to do #&gt; } </code></pre> <p>or shorter:</p> <pre><code>gci | % { &lt;# ... #&gt; } </code></pre> <p>or if you want an explicit looping construct:</p> <pre><code>foreach ($file in Get-ChildItem) { # ... } </code></pre> <p>Note however, that <...
526
powershell
<h1>how to iterate over files with powershell?</h1> <p>I want to iterate over files in a folder using powershell script;</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,766
bash
# how to iterate over files with powershell? I want to iterate over files in a folder using powershell script;
``` Get-ChildItem | ForEach-Object { <# do what you need to do #> } ``` or shorter: ``` gci | % { <# ... #> } ``` or if you want an explicit looping construct: ``` foreach ($file in Get-ChildItem) { # ... } ``` Note however, that `foreach` will only run once all output from `Get-ChildItem` is collected. In my ...
1831527
Simple way to colour alternate output lines in bash
13
2009-12-02 08:46:09
<p>I have need to grep an entire directory for a string, and I get about 50 results. I would like to colour each second line, either text colour or background colour. Best would be a script that I can pipe the output of any command to, and so that it spits out the same (albeit coloured) output.</p>
9,872
210,945
2014-08-14 21:57:41
1,831,633
16
2009-12-02 09:04:58
180,174
2014-08-14 21:57:41
https://stackoverflow.com/q/1831527
https://stackoverflow.com/a/1831633
<p>Not very pretty but does the trick:</p> <p>(save this to <code>foo.bash</code> and do <code>grep whatever wherever | ./foo.bash</code>)</p> <pre><code>#!/bin/bash while read line do echo -e "\e[1;31m$line" read line echo -e "\e[1;32m$line" done echo -en "\e[0m" </code></pre> <p>Here you can find the <a href...
<p>Not very pretty but does the trick:</p> <p>(save this to <code>foo.bash</code> and do <code>grep whatever wherever | ./foo.bash</code>)</p> <pre><code>#!/bin/bash while read line do echo -e "\e[1;31m$line" read line echo -e "\e[1;32m$line" done echo -en "\e[0m" </code></pre> <p>Here you can find the <a href...
387, 390, 1231, 6439
bash, colors, command-line, shell
<h1>Simple way to colour alternate output lines in bash</h1> <p>I have need to grep an entire directory for a string, and I get about 50 results. I would like to colour each second line, either text colour or background colour. Best would be a script that I can pipe the output of any command to, and so that it spits ou...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,767
bash
# Simple way to colour alternate output lines in bash I have need to grep an entire directory for a string, and I get about 50 results. I would like to colour each second line, either text colour or background colour. Best would be a script that I can pipe the output of any command to, and so that it spits out the sam...
Not very pretty but does the trick: (save this to `foo.bash` and do `grep whatever wherever | ./foo.bash`) ``` #!/bin/bash while read line do echo -e "\e[1;31m$line" read line echo -e "\e[1;32m$line" done echo -en "\e[0m" ``` Here you can find the [list of color codes in bash](http://wiki.archlinux.org/index.p...
803653
bash completion for certain types of files in a special directory
13
2009-04-29 18:32:58
<p>I have a list of unison profiles which exists in <code>~/.unison/*.prf</code>.</p> <p>I'd like to have bash completion so that when I type <code>unison</code> or <code>unison-gtk</code> and hit tab it would list the <code>.prf</code> files from that folder without the <code>.prf</code> part.</p> <p>Perhaps an exam...
2,086
95,818
2009-04-29 19:34:22
803,714
16
2009-04-29 18:46:26
69,952
2009-04-29 19:34:22
https://stackoverflow.com/q/803653
https://stackoverflow.com/a/803714
<p>If you are running debian/ubuntu or possibly other GNU/Linux distros, there should be examples of this type of completion in your /etc/bash_completion.d/ directory. Here is an example of how you might set up a completion script for unison:</p> <pre><code>have unison &amp;&amp; _unison_show() { local cur ...
<p>If you are running debian/ubuntu or possibly other GNU/Linux distros, there should be examples of this type of completion in your /etc/bash_completion.d/ directory. Here is an example of how you might set up a completion script for unison:</p> <pre><code>have unison &amp;&amp; _unison_show() { local cur ...
387, 4682
autocomplete, bash
<h1>bash completion for certain types of files in a special directory</h1> <p>I have a list of unison profiles which exists in <code>~/.unison/*.prf</code>.</p> <p>I'd like to have bash completion so that when I type <code>unison</code> or <code>unison-gtk</code> and hit tab it would list the <code>.prf</code> files f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,768
bash
# bash completion for certain types of files in a special directory I have a list of unison profiles which exists in `~/.unison/*.prf`. I'd like to have bash completion so that when I type `unison` or `unison-gtk` and hit tab it would list the `.prf` files from that folder without the `.prf` part. Perhaps an example...
If you are running debian/ubuntu or possibly other GNU/Linux distros, there should be examples of this type of completion in your /etc/bash_completion.d/ directory. Here is an example of how you might set up a completion script for unison: ``` have unison && _unison_show() { local cur COMPREPLY=() ...
497681
Using mplayer to determine length of audio/video file
13
2009-01-30 23:27:49
<p>The following works very nicely to determine the length of various audio/video files:</p> <pre><code>mplayer -identify file.ogg 2&gt;/dev/null | grep ID_LENGTH </code></pre> <p>However, I want to kill mplayer's output so I can determine the length of many files more efficiently. How do I do that?</p>
16,857
null
2020-04-08 13:05:49
498,138
16
2009-01-31 03:09:17
20,713
2009-01-31 03:09:17
https://stackoverflow.com/q/497681
https://stackoverflow.com/a/498138
<p>The <code>MPlayer</code> source ships with a sample script called <code>midentify</code>, which looks like this:</p> <pre><code>#!/bin/sh # # This is a wrapper around the -identify functionality. # It is supposed to escape the output properly, so it can be easily # used in shellscripts by 'eval'ing the output of th...
<p>The <code>MPlayer</code> source ships with a sample script called <code>midentify</code>, which looks like this:</p> <pre><code>#!/bin/sh # # This is a wrapper around the -identify functionality. # It is supposed to escape the output properly, so it can be easily # used in shellscripts by 'eval'ing the output of th...
390
shell
<h1>Using mplayer to determine length of audio/video file</h1> <p>The following works very nicely to determine the length of various audio/video files:</p> <pre><code>mplayer -identify file.ogg 2&gt;/dev/null | grep ID_LENGTH </code></pre> <p>However, I want to kill mplayer's output so I can determine the length of m...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,769
bash
# Using mplayer to determine length of audio/video file The following works very nicely to determine the length of various audio/video files: ``` mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH ``` However, I want to kill mplayer's output so I can determine the length of many files more efficiently. How do I...
The `MPlayer` source ships with a sample script called `midentify`, which looks like this: ``` #!/bin/sh # # This is a wrapper around the -identify functionality. # It is supposed to escape the output properly, so it can be easily # used in shellscripts by 'eval'ing the output of this script. # # Written by Tobias Die...
240661
What's the best practice for changing working directories inside scripts?
13
2008-10-27 17:09:55
<p>Do you think changing directories inside bash or Perl scripts is acceptable? Or should one avoid doing this at all costs?</p> <p>What is the best practice for this issue?</p>
20,272
13,523
2008-10-28 04:06:35
240,703
16
2008-10-27 17:19:16
972
2008-10-27 17:19:16
https://stackoverflow.com/q/240661
https://stackoverflow.com/a/240703
<p>The current working directory is local to the executing shell, so you can't affect the user unless he is "dotting" (running it in the current shell, as opposed to running it normally creating a new shell process) your script.</p> <p>A very good way of doing this is to use subshells, which i often do in aliases.</p>...
<p>The current working directory is local to the executing shell, so you can't affect the user unless he is "dotting" (running it in the current shell, as opposed to running it normally creating a new shell process) your script.</p> <p>A very good way of doing this is to use subshells, which i often do in aliases.</p>...
387, 390, 580, 3791
bash, perl, shell, zsh
<h1>What's the best practice for changing working directories inside scripts?</h1> <p>Do you think changing directories inside bash or Perl scripts is acceptable? Or should one avoid doing this at all costs?</p> <p>What is the best practice for this issue?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,770
bash
# What's the best practice for changing working directories inside scripts? Do you think changing directories inside bash or Perl scripts is acceptable? Or should one avoid doing this at all costs? What is the best practice for this issue?
The current working directory is local to the executing shell, so you can't affect the user unless he is "dotting" (running it in the current shell, as opposed to running it normally creating a new shell process) your script. A very good way of doing this is to use subshells, which i often do in aliases. ``` alias bu...
67852305
How to prepend to a file in PowerShell?
12
2021-06-05 17:37:28
<p>I'm generating two files, <code>userscript.meta.js</code> and <code>userscript.user.js</code>. I need the output of <code>userscript.meta.js</code> to be placed at the very beginning of <code>userscript.user.js</code>.</p> <p><code>Add-Content</code> doesn't seem to accept a parameter to prepend and <code>Get-Conten...
5,452
5,083,247
2023-01-05 12:47:12
67,852,426
16
2021-06-05 17:52:52
15,339,544
2023-01-05 12:47:12
https://stackoverflow.com/q/67852305
https://stackoverflow.com/a/67852426
<p>The <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2#subexpression-operator--" rel="noreferrer">Subexpression operator <code>$( )</code></a> can evaluate both <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powers...
<p>The <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2#subexpression-operator--" rel="noreferrer">Subexpression operator <code>$( )</code></a> can evaluate both <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powers...
526, 33096, 130616
powershell, powershell-core, prepend
<h1>How to prepend to a file in PowerShell?</h1> <p>I'm generating two files, <code>userscript.meta.js</code> and <code>userscript.user.js</code>. I need the output of <code>userscript.meta.js</code> to be placed at the very beginning of <code>userscript.user.js</code>.</p> <p><code>Add-Content</code> doesn't seem to a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,771
bash
# How to prepend to a file in PowerShell? I'm generating two files, `userscript.meta.js` and `userscript.user.js`. I need the output of `userscript.meta.js` to be placed at the very beginning of `userscript.user.js`. `Add-Content` doesn't seem to accept a parameter to prepend and `Get-Content | Set-Content` will fail...
The [Subexpression operator `$( )`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2#subexpression-operator--) can evaluate both [`Get-Content`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=pow...
65346260
Get real architecture of M1 Mac regardless of Rosetta
12
2020-12-17 18:19:26
<p>I need to retrieve the real architecture of a Mac regardless of if the process is running through Rosetta or not.</p> <p>Right now in Node.js, <code>process.arch</code> returns <code>x64</code> and in shell, <code>uname -m</code> returns <code>x86_64</code>.</p>
6,704
864,101
2021-12-17 22:11:52
65,347,893
16
2020-12-17 20:28:28
864,101
2020-12-17 20:28:28
https://stackoverflow.com/q/65346260
https://stackoverflow.com/a/65347893
<p>Thanks to @Ouroborus, <a href="https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845" rel="noreferrer">this note</a> describes how to figure out if your app is translated.</p> <p>If it's translated:</p> <pre class="lang-sh prettyprint-override"><code>$ sysctl sysct...
<p>Thanks to @Ouroborus, <a href="https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845" rel="noreferrer">this note</a> describes how to figure out if your app is translated.</p> <p>If it's translated:</p> <pre class="lang-sh prettyprint-override"><code>$ sysctl sysct...
3, 369, 390, 46426, 54021
javascript, macos, node.js, rosetta, shell
<h1>Get real architecture of M1 Mac regardless of Rosetta</h1> <p>I need to retrieve the real architecture of a Mac regardless of if the process is running through Rosetta or not.</p> <p>Right now in Node.js, <code>process.arch</code> returns <code>x64</code> and in shell, <code>uname -m</code> returns <code>x86_64</co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,772
bash
# Get real architecture of M1 Mac regardless of Rosetta I need to retrieve the real architecture of a Mac regardless of if the process is running through Rosetta or not. Right now in Node.js, `process.arch` returns `x64` and in shell, `uname -m` returns `x86_64`.
Thanks to @Ouroborus, [this note](https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845) describes how to figure out if your app is translated. If it's translated: ``` $ sysctl sysctl.proc_translated sysctl.proc_translated: 1 ``` If not: ``` $ sysctl sysctl.proc_t...
63629990
Set KUBECONFIG environment variable dynamically
12
2020-08-28 08:15:59
<p>I am quite new to Bash and working on multiple kubernetes cluster. I wanted some kind of utility wherein I can set my KUBECONFIG variable dynamically as I work on multiple clusters. My kubeconfig file lies in multiple folders. What I want is to find all the kubeconfig files , get the paths and concatenate the paths ...
50,524
9,311,364
2020-08-28 13:23:28
63,634,642
16
2020-08-28 13:23:28
13,891,405
2020-08-28 13:23:28
https://stackoverflow.com/q/63629990
https://stackoverflow.com/a/63634642
<p>You can try something like that:</p> <pre><code>export KUBECONFIG=$(for i in $(find /Users/anandabhishe/gitlab/ -iname 'kubeconfig.yaml') ; do echo -n &quot;:$i&quot;; done | cut -c 2-) </code></pre>
<p>You can try something like that:</p> <pre><code>export KUBECONFIG=$(for i in $(find /Users/anandabhishe/gitlab/ -iname 'kubeconfig.yaml') ; do echo -n &quot;:$i&quot;; done | cut -c 2-) </code></pre>
387, 390, 10193
bash, find, shell
<h1>Set KUBECONFIG environment variable dynamically</h1> <p>I am quite new to Bash and working on multiple kubernetes cluster. I wanted some kind of utility wherein I can set my KUBECONFIG variable dynamically as I work on multiple clusters. My kubeconfig file lies in multiple folders. What I want is to find all the ku...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,773
bash
# Set KUBECONFIG environment variable dynamically I am quite new to Bash and working on multiple kubernetes cluster. I wanted some kind of utility wherein I can set my KUBECONFIG variable dynamically as I work on multiple clusters. My kubeconfig file lies in multiple folders. What I want is to find all the kubeconfig ...
You can try something like that: ``` export KUBECONFIG=$(for i in $(find /Users/anandabhishe/gitlab/ -iname 'kubeconfig.yaml') ; do echo -n ":$i"; done | cut -c 2-) ```
55423220
Can't get all excel processes to stop when closing through Powershell
12
2019-03-29 18:04:11
<p>With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, leave it open, end the script, and then manually close excel later, there are n...
6,081
11,096,683
2024-09-17 16:30:17
55,423,449
16
2019-03-29 18:19:53
45,375
2024-09-17 16:30:17
https://stackoverflow.com/q/55423220
https://stackoverflow.com/a/55423449
<p><strong>tl;dr</strong></p> <p>Use the following <strong>idiom</strong> to ensure that all references to COM objects are released, which, in combination with calling <code>$excel.Quit()</code>, ensures that the Excel process (eventually) terminates:</p> <pre class="lang-bash prettyprint-override"><code>&amp; { # Cr...
<p><strong>tl;dr</strong></p> <p>Use the following <strong>idiom</strong> to ensure that all references to COM objects are released, which, in combination with calling <code>$excel.Quit()</code>, ensures that the Excel process (eventually) terminates:</p> <pre class="lang-bash prettyprint-override"><code>&amp; { # Cr...
162, 522, 526, 865, 24034
com, excel, powershell, rcw, user-interface
<h1>Can't get all excel processes to stop when closing through Powershell</h1> <p>With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,774
bash
# Can't get all excel processes to stop when closing through Powershell With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, leave it ...
**tl;dr** Use the following **idiom** to ensure that all references to COM objects are released, which, in combination with calling `$excel.Quit()`, ensures that the Excel process (eventually) terminates: ``` & { # Create a temporary child scope. $excel = New-Object -ComObject excel.application # create excel obj...
51861707
Error parsing parameter '--expression-attribute-values': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
12
2018-08-15 15:24:50
<p>I am running the following query</p> <pre><code>aws dynamodb query ` --table-name user` --key-condition-expression "datecreated = :d" ` --expression-attribute-values "{ ':d': { 'S': '2018-08-15' } }" --endpoint-url http://localhost:8000 </code></pre> <p>Does dynamodb even understand what a double quote is?</p> <o...
24,575
2,462,878
2025-05-30 14:50:11
51,861,924
16
2018-08-15 15:38:40
45,375
2021-11-27 13:40:26
https://stackoverflow.com/q/51861707
https://stackoverflow.com/a/51861924
<p>There are two immediate problems:</p> <ul> <li><p><strong><code>'</code> (single quotes) aren't valid string delimiters</strong> in JSON; you <strong>must use <code>&quot;</code></strong> (double quotes):</p> </li> <li><p>Sadly, as of v7.2 <strong>PowerShell requires you to <code>\</code>-escape argument-internal <c...
<p>There are two immediate problems:</p> <ul> <li><p><strong><code>'</code> (single quotes) aren't valid string delimiters</strong> in JSON; you <strong>must use <code>&quot;</code></strong> (double quotes):</p> </li> <li><p>Sadly, as of v7.2 <strong>PowerShell requires you to <code>\</code>-escape argument-internal <c...
526, 33388, 76578, 99166
amazon-dynamodb, amazon-web-services, aws-cli, powershell
<h1>Error parsing parameter '--expression-attribute-values': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)</h1> <p>I am running the following query</p> <pre><code>aws dynamodb query ` --table-name user` --key-condition-expression "datecreated = :d" ` --expression-attribute-v...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,775
bash
# Error parsing parameter '--expression-attribute-values': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 3 (char 2) I am running the following query ``` aws dynamodb query ` --table-name user` --key-condition-expression "datecreated = :d" ` --expression-attribute-values "{ ':d': { 'S'...
There are two immediate problems: - **`'` (single quotes) aren't valid string delimiters** in JSON; you **must use `"`** (double quotes): - Sadly, as of v7.2 **PowerShell requires you to `\`-escape argument-internal `"` characters *when calling external programs***, *even though that **shouldn't be necessary***. - ...
49480275
Add SSL Certificate to Windows Docker Container
12
2018-03-25 19:53:30
<p>How can I add a <em>.cer</em>-Certificate inside a Docker container? It has to be done via powershell since the container has no interface to open <code>mms.exe</code>.</p> <p><a href="http://colmprunty1.azurewebsites.net/2017/06/07/import-and-bind-an-ssl-cert-in-windows-container/" rel="noreferrer">This</a> is a g...
18,491
2,470,546
2018-03-27 15:51:22
49,517,359
16
2018-03-27 15:51:22
2,470,546
2018-03-27 15:51:22
https://stackoverflow.com/q/49480275
https://stackoverflow.com/a/49517359
<p>The problem does not appear when importing to the LocalMachine folder: </p> <p><code>Import-Certificate -FilePath C:\myCertificateToAdd.cert -CertStoreLocation Cert:\LocalMachine\Root\</code></p> <p>Like this, the certificate is importet to every "CurrentUser" on the machine. If this is ok, as for the typical Dock...
<p>The problem does not appear when importing to the LocalMachine folder: </p> <p><code>Import-Certificate -FilePath C:\myCertificateToAdd.cert -CertStoreLocation Cert:\LocalMachine\Root\</code></p> <p>Like this, the certificate is importet to every "CurrentUser" on the machine. If this is ok, as for the typical Dock...
64, 526, 14423, 90304
docker, powershell, ssl-certificate, windows
<h1>Add SSL Certificate to Windows Docker Container</h1> <p>How can I add a <em>.cer</em>-Certificate inside a Docker container? It has to be done via powershell since the container has no interface to open <code>mms.exe</code>.</p> <p><a href="http://colmprunty1.azurewebsites.net/2017/06/07/import-and-bind-an-ssl-cer...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,776
bash
# Add SSL Certificate to Windows Docker Container How can I add a *.cer*-Certificate inside a Docker container? It has to be done via powershell since the container has no interface to open `mms.exe`. [This](http://colmprunty1.azurewebsites.net/2017/06/07/import-and-bind-an-ssl-cert-in-windows-container/) is a good t...
The problem does not appear when importing to the LocalMachine folder: `Import-Certificate -FilePath C:\myCertificateToAdd.cert -CertStoreLocation Cert:\LocalMachine\Root\` Like this, the certificate is importet to every "CurrentUser" on the machine. If this is ok, as for the typical DockerContainer, the problem is s...
46313746
IFS=: leads to different behavior while looping over colon-separated values
12
2017-09-20 05:11:40
<h3>Experiment 1</h3> <p>Here is my first script in file named <code>foo.sh</code>.</p> <pre><code>IFS=: for i in foo:bar:baz do echo $i done </code></pre> <p>This produces the following output.</p> <pre><code>$ bash foo.sh foo bar baz </code></pre> <h3>Experiment 2</h3> <p>This is my second script.</p> <pre...
437
1,175,080
2018-03-22 04:13:52
46,633,130
16
2017-10-08 16:01:10
641,955
2017-10-08 18:21:41
https://stackoverflow.com/q/46313746
https://stackoverflow.com/a/46633130
<p>I found this a very interesting experiment. Thank you for that.</p> <hr> <p>To understand what is going on, the relevant section from <code>man bash</code> is this:</p> <blockquote> <pre> Word Splitting The shell scans the results of parameter expansion, command substitu- tion, and arithmetic expan...
<p>I found this a very interesting experiment. Thank you for that.</p> <hr> <p>To understand what is going on, the relevant section from <code>man bash</code> is this:</p> <blockquote> <pre> Word Splitting The shell scans the results of parameter expansion, command substitu- tion, and arithmetic expan...
387, 390, 2531, 26793
bash, for-loop, ifs, shell
<h1>IFS=: leads to different behavior while looping over colon-separated values</h1> <h3>Experiment 1</h3> <p>Here is my first script in file named <code>foo.sh</code>.</p> <pre><code>IFS=: for i in foo:bar:baz do echo $i done </code></pre> <p>This produces the following output.</p> <pre><code>$ bash foo.sh foo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,777
bash
# IFS=: leads to different behavior while looping over colon-separated values ### Experiment 1 Here is my first script in file named `foo.sh`. ``` IFS=: for i in foo:bar:baz do echo $i done ``` This produces the following output. ``` $ bash foo.sh foo bar baz ``` ### Experiment 2 This is my second script. `...
I found this a very interesting experiment. Thank you for that. --- To understand what is going on, the relevant section from `man bash` is this: > ``` > Word Splitting > The shell scans the results of parameter expansion, command substitu- > tion, and arithmetic expansion that did not occur within d...
45422255
Determine if windows is currently playing sound
12
2017-07-31 17:48:45
<p>So I've been pondering on this problem for a while and I can't figure out what the right way to go about this is. I want to determine if Windows is outputting sound at a certain time using a <code>Powershell</code> script. I can determine whether or not the audio driver has an error, but I cannot for the life of me ...
6,991
7,195,907
2017-08-08 21:08:23
45,493,621
16
2017-08-03 20:04:29
5,229,138
2017-08-06 22:35:37
https://stackoverflow.com/q/45422255
https://stackoverflow.com/a/45493621
<p>Here's how to use the code that Simon Mourier provided.</p> <p>Run the code below:</p> <pre><code>Add-Type -TypeDefinition @' using System; using System.Runtime.InteropServices; namespace Foo { public class Bar { public static bool IsWindowsPlayingSound() { IMMDeviceEnumerator ...
<p>Here's how to use the code that Simon Mourier provided.</p> <p>Run the code below:</p> <pre><code>Add-Type -TypeDefinition @' using System; using System.Runtime.InteropServices; namespace Foo { public class Bar { public static bool IsWindowsPlayingSound() { IMMDeviceEnumerator ...
1, 64, 526, 24067, 34595
.net, powershell, powershell-2.0, windows, windows-7
<h1>Determine if windows is currently playing sound</h1> <p>So I've been pondering on this problem for a while and I can't figure out what the right way to go about this is. I want to determine if Windows is outputting sound at a certain time using a <code>Powershell</code> script. I can determine whether or not the au...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,778
bash
# Determine if windows is currently playing sound So I've been pondering on this problem for a while and I can't figure out what the right way to go about this is. I want to determine if Windows is outputting sound at a certain time using a `Powershell` script. I can determine whether or not the audio driver has an er...
Here's how to use the code that Simon Mourier provided. Run the code below: ``` Add-Type -TypeDefinition @' using System; using System.Runtime.InteropServices; namespace Foo { public class Bar { public static bool IsWindowsPlayingSound() { IMMDeviceEnumerator enumerator = (IMMDevi...
40894631
How does one enter a Python virtualenv when executing a bashscript?
12
2016-11-30 17:30:59
<p>If one defines which version of python to use in a bash script, it would be </p> <pre><code>export PYTHON = "/path/python/python-3.5.1/bin/python" </code></pre> <p>But for Python virtualenv's, one executes these commands in the command line</p> <pre><code>cd /path/pathto/virtualenv source activate cd another_dire...
19,883
4,596,596
2025-03-04 12:52:00
40,896,676
16
2016-11-30 19:33:04
674,064
2019-08-12 14:49:59
https://stackoverflow.com/q/40894631
https://stackoverflow.com/a/40896676
<p>We have to distinguish two cases here:</p> <ol> <li>You want to use/call python (or python-based tools) in your bash script, but python or those tools should be taken from and run in a virtualenv</li> <li>You want a script that, amongst other things, lets the shell from which you call it enter the virtualenv, so th...
<p>We have to distinguish two cases here:</p> <ol> <li>You want to use/call python (or python-based tools) in your bash script, but python or those tools should be taken from and run in a virtualenv</li> <li>You want a script that, amongst other things, lets the shell from which you call it enter the virtualenv, so th...
16, 387, 14529
bash, python, virtualenv
<h1>How does one enter a Python virtualenv when executing a bashscript?</h1> <p>If one defines which version of python to use in a bash script, it would be </p> <pre><code>export PYTHON = "/path/python/python-3.5.1/bin/python" </code></pre> <p>But for Python virtualenv's, one executes these commands in the command li...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,779
bash
# How does one enter a Python virtualenv when executing a bashscript? If one defines which version of python to use in a bash script, it would be ``` export PYTHON = "/path/python/python-3.5.1/bin/python" ``` But for Python virtualenv's, one executes these commands in the command line ``` cd /path/pathto/virtualenv...
We have to distinguish two cases here: 1. You want to use/call python (or python-based tools) in your bash script, but python or those tools should be taken from and run in a virtualenv 2. You want a script that, amongst other things, lets the shell from which you call it enter the virtualenv, so that you can interact...
40787766
`Add-Type` C# 6+ features throwing errors
12
2016-11-24 13:33:21
<p>I am trying to compile <a href="/questions/tagged/c%23" class="post-tag" title="show questions tagged &#39;c#&#39;" rel="tag">c#</a> source code in <a href="/questions/tagged/powershell" class="post-tag" title="show questions tagged &#39;powershell&#39;" rel="tag">powershell</a> by using this command:</p> <pre><cod...
5,124
960,055
2023-10-21 13:03:57
40,789,694
16
2016-11-24 15:10:11
993,547
2016-11-24 15:10:11
https://stackoverflow.com/q/40787766
https://stackoverflow.com/a/40789694
<p><a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/add-type" rel="noreferrer">Powershell uses <code>CodeDomProvider</code> to compile their assemblies.</a> The version provided with the framework just supports C# 5, so no new features are available by default.</p> <p>How...
<p><a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/add-type" rel="noreferrer">Powershell uses <code>CodeDomProvider</code> to compile their assemblies.</a> The version provided with the framework just supports C# 5, so no new features are available by default.</p> <p>How...
9, 526, 74656
c#, powershell, roslyn
<h1>`Add-Type` C# 6+ features throwing errors</h1> <p>I am trying to compile <a href="/questions/tagged/c%23" class="post-tag" title="show questions tagged &#39;c#&#39;" rel="tag">c#</a> source code in <a href="/questions/tagged/powershell" class="post-tag" title="show questions tagged &#39;powershell&#39;" rel="tag">p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,780
bash
# `Add-Type` C# 6+ features throwing errors I am trying to compile [c#](/questions/tagged/c%23 "show questions tagged 'c#'") source code in [powershell](/questions/tagged/powershell "show questions tagged 'powershell'") by using this command: ``` Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source ``` ...
[Powershell uses `CodeDomProvider` to compile their assemblies.](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/add-type) The version provided with the framework just supports C# 5, so no new features are available by default. However, if you provide another `CodeDomProvider`, y...
36733777
Error on "docker-compose" when I use by pipe with sh ( echo "docker-compose... " | sh )
12
2016-04-20 04:23:42
<p>I've a application which has multi container. to easy installation, I decide to use packaging image. what I expected is like below</p> <pre><code>$ docker run my_application install | sh </code></pre> <p>-> pull all related images from registry</p> <pre><code>$ docker run my_application up | sh </code></pre> <...
9,484
6,228,117
2018-08-10 12:18:13
37,782,095
16
2016-06-13 05:00:36
10,831
2016-06-13 05:00:36
https://stackoverflow.com/q/36733777
https://stackoverflow.com/a/37782095
<p>This is an <a href="https://github.com/docker/compose/issues/3352" rel="noreferrer">open bug</a> in docker-compose.</p> <p>As a workaround, you can pass the <code>-T</code> option to <code>docker-compose exec</code>:</p> <pre><code>$ docker-compose exec --help [...] -T Disable pseudo-tty allocation....
<p>This is an <a href="https://github.com/docker/compose/issues/3352" rel="noreferrer">open bug</a> in docker-compose.</p> <p>As a workaround, you can pass the <code>-T</code> option to <code>docker-compose exec</code>:</p> <pre><code>$ docker-compose exec --help [...] -T Disable pseudo-tty allocation....
16, 5813, 10327, 90304, 110604
docker, docker-compose, pipe, python, sh
<h1>Error on "docker-compose" when I use by pipe with sh ( echo "docker-compose... " | sh )</h1> <p>I've a application which has multi container. to easy installation, I decide to use packaging image. what I expected is like below</p> <pre><code>$ docker run my_application install | sh </code></pre> <p>-> pull all ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,781
bash
# Error on "docker-compose" when I use by pipe with sh ( echo "docker-compose... " | sh ) I've a application which has multi container. to easy installation, I decide to use packaging image. what I expected is like below ``` $ docker run my_application install | sh ``` -> pull all related images from registry ``` $...
This is an [open bug](https://github.com/docker/compose/issues/3352) in docker-compose. As a workaround, you can pass the `-T` option to `docker-compose exec`: ``` $ docker-compose exec --help [...] -T Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY. ``...
37731609
Curl: don't wait for response
12
2016-06-09 16:32:53
<p>I currently have a shell script which relies on a curl command like this:</p> <pre><code>curl --request POST -u name:pass -H "Content-Type: application/json" --data "{data}" https://url.com --cacert ./my_crt </code></pre> <p>I don't need the response of the command, and this command is in a big for loop, so waiti...
62,189
5,362,438
2016-06-09 18:56:18
37,734,083
16
2016-06-09 18:56:18
1,899,640
2016-06-09 18:56:18
https://stackoverflow.com/q/37731609
https://stackoverflow.com/a/37734083
<p>If you have a large number of requests you want to issue quickly, and you don't care about the output, there are two things you should do:</p> <ol> <li><strong>Do more requests with the same connection.</strong></li> </ol> <p>For small requests, it's generally much faster to do 10 requests each on 1 connection, th...
<p>If you have a large number of requests you want to issue quickly, and you don't care about the output, there are two things you should do:</p> <ol> <li><strong>Do more requests with the same connection.</strong></li> </ol> <p>For small requests, it's generally much faster to do 10 requests each on 1 connection, th...
387, 390
bash, shell
<h1>Curl: don't wait for response</h1> <p>I currently have a shell script which relies on a curl command like this:</p> <pre><code>curl --request POST -u name:pass -H "Content-Type: application/json" --data "{data}" https://url.com --cacert ./my_crt </code></pre> <p>I don't need the response of the command, and this...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,782
bash
# Curl: don't wait for response I currently have a shell script which relies on a curl command like this: ``` curl --request POST -u name:pass -H "Content-Type: application/json" --data "{data}" https://url.com --cacert ./my_crt ``` I don't need the response of the command, and this command is in a big for loop, so...
If you have a large number of requests you want to issue quickly, and you don't care about the output, there are two things you should do: 1. **Do more requests with the same connection.** For small requests, it's generally much faster to do 10 requests each on 1 connection, than 1 request each on 10 connections. For...
37378375
"cannot execute binary file" when trying to run a shell script on linux
12
2016-05-22 18:58:39
<p>I am very new to linux and shell scriprting. I am trying to run a shellscript from secure shell (ssh) on linux using following commands:</p> <pre><code>chmod +x path/to/mynewshell.sh sh path/to/mynewshell.sh </code></pre> <p>I get this error: </p> <pre><code>path/to/mynewshell.sh: path/to/mynewshell.sh: cannot e...
159,788
6,237,321
2022-10-28 13:09:45
37,378,396
16
2016-05-22 19:00:52
3,744,681
2016-05-22 21:31:42
https://stackoverflow.com/q/37378375
https://stackoverflow.com/a/37378396
<p><code>chmod -x</code> removes execution permission from a file. Do this:</p> <pre><code>chmod +x path/to/mynewshell.sh </code></pre> <p>And run it with</p> <pre><code>/path/to/mynewshell.sh </code></pre> <p>As the error report says, you script is not actually a script, it's a binary file.</p>
<p><code>chmod -x</code> removes execution permission from a file. Do this:</p> <pre><code>chmod +x path/to/mynewshell.sh </code></pre> <p>And run it with</p> <pre><code>/path/to/mynewshell.sh </code></pre> <p>As the error report says, you script is not actually a script, it's a binary file.</p>
58, 387, 390
bash, linux, shell
<h1>"cannot execute binary file" when trying to run a shell script on linux</h1> <p>I am very new to linux and shell scriprting. I am trying to run a shellscript from secure shell (ssh) on linux using following commands:</p> <pre><code>chmod +x path/to/mynewshell.sh sh path/to/mynewshell.sh </code></pre> <p>I get th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,783
bash
# "cannot execute binary file" when trying to run a shell script on linux I am very new to linux and shell scriprting. I am trying to run a shellscript from secure shell (ssh) on linux using following commands: ``` chmod +x path/to/mynewshell.sh sh path/to/mynewshell.sh ``` I get this error: ``` path/to/mynewshell...
`chmod -x` removes execution permission from a file. Do this: ``` chmod +x path/to/mynewshell.sh ``` And run it with ``` /path/to/mynewshell.sh ``` As the error report says, you script is not actually a script, it's a binary file.
29927005
How to check if a files exists in a specific directory in a bash script?
12
2015-04-28 18:18:42
<p>This is what I have been trying and it is unsuccessful. If I wanted to check if a file exists in the ~/.example directory</p> <pre><code>FILE=$1 if [ -e $FILE ~/.example ]; then echo "File exists" else echo "File does not exist" fi </code></pre>
38,635
4,843,328
2020-03-14 06:09:00
29,927,050
16
2015-04-28 18:21:34
4,687,135
2017-05-14 23:29:12
https://stackoverflow.com/q/29927005
https://stackoverflow.com/a/29927050
<p>You can use <code>$FILE</code> to concatenate with the directory to make the full path as below.</p> <pre><code>FILE="$1" if [ -e ~/.myexample/"$FILE" ]; then echo "File exists" else echo "File does not exist" fi </code></pre>
<p>You can use <code>$FILE</code> to concatenate with the directory to make the full path as below.</p> <pre><code>FILE="$1" if [ -e ~/.myexample/"$FILE" ]; then echo "File exists" else echo "File does not exist" fi </code></pre>
58, 387, 391, 531, 5310
bash, file, linux, scripting, terminal
<h1>How to check if a files exists in a specific directory in a bash script?</h1> <p>This is what I have been trying and it is unsuccessful. If I wanted to check if a file exists in the ~/.example directory</p> <pre><code>FILE=$1 if [ -e $FILE ~/.example ]; then echo "File exists" else echo "File does not ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,784
bash
# How to check if a files exists in a specific directory in a bash script? This is what I have been trying and it is unsuccessful. If I wanted to check if a file exists in the ~/.example directory ``` FILE=$1 if [ -e $FILE ~/.example ]; then echo "File exists" else echo "File does not exist" fi ```
You can use `$FILE` to concatenate with the directory to make the full path as below. ``` FILE="$1" if [ -e ~/.myexample/"$FILE" ]; then echo "File exists" else echo "File does not exist" fi ```
28899561
Temporarily disable 'set-e' / 'set -o errexit' in bash?
12
2015-03-06 13:15:10
<p>I have a script that uses <code>killall</code> to make sure an app isn't already running before starting it:</p> <pre><code>#!/bin/bash set -e some_command another_command sudo killall myapp # this causes the script to fail if myapp isn't running sleep 10 myapp start </code></pre> <p>However, if myapp isn't run...
7,600
1,033,422
2019-02-27 14:44:13
28,899,718
16
2015-03-06 13:23:49
2,807,880
2019-02-27 14:44:13
https://stackoverflow.com/q/28899561
https://stackoverflow.com/a/28899718
<p>If you want just allow this single command to end with error and consider it normal you can:</p> <pre><code>sudo killall myapp || : </code></pre> <p>: is a noop in bash. Effectively the line above is as explicitly as possible expressing "on error do nothing". You can achieve the same effect with maybe a little mor...
<p>If you want just allow this single command to end with error and consider it normal you can:</p> <pre><code>sudo killall myapp || : </code></pre> <p>: is a noop in bash. Effectively the line above is as explicitly as possible expressing "on error do nothing". You can achieve the same effect with maybe a little mor...
58, 387, 549
bash, linux, ubuntu
<h1>Temporarily disable 'set-e' / 'set -o errexit' in bash?</h1> <p>I have a script that uses <code>killall</code> to make sure an app isn't already running before starting it:</p> <pre><code>#!/bin/bash set -e some_command another_command sudo killall myapp # this causes the script to fail if myapp isn't running s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,785
bash
# Temporarily disable 'set-e' / 'set -o errexit' in bash? I have a script that uses `killall` to make sure an app isn't already running before starting it: ``` #!/bin/bash set -e some_command another_command sudo killall myapp # this causes the script to fail if myapp isn't running sleep 10 myapp start ``` Howeve...
If you want just allow this single command to end with error and consider it normal you can: ``` sudo killall myapp || : ``` : is a noop in bash. Effectively the line above is as explicitly as possible expressing "on error do nothing". You can achieve the same effect with maybe a little more idiomatic: ``` sudo kill...
28846194
Generate Machine Key using Power shell
12
2015-03-04 03:29:12
<p>I am trying to generate machine key to share between a few machine, after a quick google search i found this <a href="http://support.microsoft.com/kb/2915218#AppendixA" rel="noreferrer">article KB 2915218, Appendix A </a>.</p> <ol> <li>I copied the code and save as .ps1 extension which i believe is power shell exte...
20,403
1,172,730
2020-04-17 03:23:27
28,847,132
16
2015-03-04 05:18:22
3,517,626
2015-03-04 05:26:59
https://stackoverflow.com/q/28846194
https://stackoverflow.com/a/28847132
<p>The script contains a function so you'll have to first load the script and then run the function for it to work.</p> <p>First we'll have to load the file, i called my ps1 "MachineKey" so this is how i load it</p> <pre><code>PS E:\&gt; . .\MachineKey.ps1 </code></pre> <p>Once i've loaded the file if i want to run ...
<p>The script contains a function so you'll have to first load the script and then run the function for it to work.</p> <p>First we'll have to load the file, i called my ps1 "MachineKey" so this is how i load it</p> <pre><code>PS E:\&gt; . .\MachineKey.ps1 </code></pre> <p>Once i've loaded the file if i want to run ...
526
powershell
<h1>Generate Machine Key using Power shell</h1> <p>I am trying to generate machine key to share between a few machine, after a quick google search i found this <a href="http://support.microsoft.com/kb/2915218#AppendixA" rel="noreferrer">article KB 2915218, Appendix A </a>.</p> <ol> <li>I copied the code and save as .p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,786
bash
# Generate Machine Key using Power shell I am trying to generate machine key to share between a few machine, after a quick google search i found this [article KB 2915218, Appendix A](http://support.microsoft.com/kb/2915218#AppendixA) . 1. I copied the code and save as .ps1 extension which i believe is power shell ext...
The script contains a function so you'll have to first load the script and then run the function for it to work. First we'll have to load the file, i called my ps1 "MachineKey" so this is how i load it ``` PS E:\> . .\MachineKey.ps1 ``` Once i've loaded the file if i want to run the function called "Generate-Machine...
27660888
IntelliJ 14 on OSX: How to specify version of SVN client used through the IDE
12
2014-12-26 19:04:19
<p>I'm on OSX Yosemite which came with a default SVN client 1.7.x.<br/> I used macports to install 1.8.11 and checked out a repo using 1.8.11 (through zshell).<br/> When i use the <code>svn</code> command through the shell (both on zshell and bash), it points to 1.8.11.<br/></p> <p>However in IntelliJ 14, it reluctant...
4,196
4,271,755
2015-08-13 11:41:37
27,661,045
16
2014-12-26 19:21:25
4,271,755
2014-12-26 19:21:25
https://stackoverflow.com/q/27660888
https://stackoverflow.com/a/27661045
<p>Found one working solution.<br/> All I really had to do is use the full path of <code>svn</code> 1.8.11 (ie. <code>/opt/local/bin/svn</code>) installed by macports, under Preferences -> Version Control -> Subversion -> Use command line client<br/></p> <p>Though I still don't understand why it didn't pick this up by...
<p>Found one working solution.<br/> All I really had to do is use the full path of <code>svn</code> 1.8.11 (ie. <code>/opt/local/bin/svn</code>) installed by macports, under Preferences -> Version Control -> Subversion -> Use command line client<br/></p> <p>Though I still don't understand why it didn't pick this up by...
63, 387, 8945, 93854
bash, intellij-idea, oh-my-zsh, svn
<h1>IntelliJ 14 on OSX: How to specify version of SVN client used through the IDE</h1> <p>I'm on OSX Yosemite which came with a default SVN client 1.7.x.<br/> I used macports to install 1.8.11 and checked out a repo using 1.8.11 (through zshell).<br/> When i use the <code>svn</code> command through the shell (both on z...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,787
bash
# IntelliJ 14 on OSX: How to specify version of SVN client used through the IDE I'm on OSX Yosemite which came with a default SVN client 1.7.x. I used macports to install 1.8.11 and checked out a repo using 1.8.11 (through zshell). When i use the `svn` command through the shell (both on zshell and bash), it points...
Found one working solution. All I really had to do is use the full path of `svn` 1.8.11 (ie. `/opt/local/bin/svn`) installed by macports, under Preferences -> Version Control -> Subversion -> Use command line client Though I still don't understand why it didn't pick this up by default even though the shells did. ![...
26624116
How can I import data to Mongodb from Json file using java
12
2014-10-29 06:39:30
<p>I am struggling with importing data into <code>Mongodb</code> from a <code>Json</code> file.<br> I can do the same in command line by using <code>mongoimport command</code>.<br> I explored and tried lot but not able to import from Json file using java.</p> <p><strong>sample.json</strong></p> <pre><code> { "test...
24,667
1,491,414
2020-12-23 22:29:32
26,626,377
16
2014-10-29 09:11:00
3,943,271
2016-01-22 08:10:01
https://stackoverflow.com/q/26624116
https://stackoverflow.com/a/26626377
<p>Suppose you can read the JSON string respectively. For example, you read the first JSON text</p> <pre><code>{ "test_id" : 1245362, "name" : "ganesh", "age" : "28", "Job" : {"company name" : "company1", "designation" : "SSE" } } </code></pre> <p>and assign it to a variable (String json1), the next step is to p...
<p>Suppose you can read the JSON string respectively. For example, you read the first JSON text</p> <pre><code>{ "test_id" : 1245362, "name" : "ganesh", "age" : "28", "Job" : {"company name" : "company1", "designation" : "SSE" } } </code></pre> <p>and assign it to a variable (String json1), the next step is to p...
17, 390, 1231, 1508, 30073
command-line, java, json, mongodb, shell
<h1>How can I import data to Mongodb from Json file using java</h1> <p>I am struggling with importing data into <code>Mongodb</code> from a <code>Json</code> file.<br> I can do the same in command line by using <code>mongoimport command</code>.<br> I explored and tried lot but not able to import from Json file using ja...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,788
bash
# How can I import data to Mongodb from Json file using java I am struggling with importing data into `Mongodb` from a `Json` file. I can do the same in command line by using `mongoimport command`. I explored and tried lot but not able to import from Json file using java. **sample.json** ``` { "test_id" : 12...
Suppose you can read the JSON string respectively. For example, you read the first JSON text ``` { "test_id" : 1245362, "name" : "ganesh", "age" : "28", "Job" : {"company name" : "company1", "designation" : "SSE" } } ``` and assign it to a variable (String json1), the next step is to parse it, ``` DBObject dbo ...
26604333
Change the system version of nodejs - ubuntu
12
2014-10-28 09:03:43
<p>I just started to use node.js in local projects few days ago. My application works good, if I run it from command shell</p> <pre><code>nvm run 0.10.32 ./bin/www app </code></pre> <p>or </p> <pre><code>node ./bin/www app </code></pre> <p>So, it works with node version 0.10.xx or higher. But there is a problem: I ...
14,956
2,861,891
2021-12-20 06:27:11
26,613,584
16
2014-10-28 16:31:34
745,121
2014-10-28 16:31:34
https://stackoverflow.com/q/26604333
https://stackoverflow.com/a/26613584
<p>Verify that default node is really coming from nvm with <code>which node</code>, if its not, you can safely run :</p> <pre><code>rm `which node` </code></pre> <p>To set the default node version with nvm use :</p> <pre><code>nvm alias default 0.10.32 </code></pre> <p>If you have many apps that use different node ...
<p>Verify that default node is really coming from nvm with <code>which node</code>, if its not, you can safely run :</p> <pre><code>rm `which node` </code></pre> <p>To set the default node version with nvm use :</p> <pre><code>nvm alias default 0.10.32 </code></pre> <p>If you have many apps that use different node ...
390, 549, 46426
node.js, shell, ubuntu
<h1>Change the system version of nodejs - ubuntu</h1> <p>I just started to use node.js in local projects few days ago. My application works good, if I run it from command shell</p> <pre><code>nvm run 0.10.32 ./bin/www app </code></pre> <p>or </p> <pre><code>node ./bin/www app </code></pre> <p>So, it works with node...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,789
bash
# Change the system version of nodejs - ubuntu I just started to use node.js in local projects few days ago. My application works good, if I run it from command shell ``` nvm run 0.10.32 ./bin/www app ``` or ``` node ./bin/www app ``` So, it works with node version 0.10.xx or higher. But there is a problem: I can'...
Verify that default node is really coming from nvm with `which node`, if its not, you can safely run : ``` rm `which node` ``` To set the default node version with nvm use : ``` nvm alias default 0.10.32 ``` If you have many apps that use different node version, add a .npmrc in the root directory in each of them. ....
22634065
Bash 'read' command does not accept -i parameter on Mac. Any alternatives?
12
2014-03-25 12:04:44
<p>I have a bash script that works fine on my work Ubuntu machine, but sadly breaks when I try and run it on my Mac OSX <strike>Lion</strike> Mountain Lion laptop. The line that kills it is this:</p> <pre><code>while [[ -z "$SSHFS_PATH" ]] ; do read -e -p "Please enter the path on which to mount your file system: `e...
12,144
1,025,702
2018-02-25 19:21:48
22,635,266
16
2014-03-25 12:54:25
612,462
2014-03-25 12:54:25
https://stackoverflow.com/q/22634065
https://stackoverflow.com/a/22635266
<p>Mac OS X 10.7 Lion (and to this date all more recent versions as well, thanks @kojiro) ships with <code>bash 3.2</code> whereas <code>read -i</code> was introduced with <code>bash 4.0-alpha</code> (see the <a href="http://tiswww.case.edu/php/chet/bash/CHANGES" rel="noreferrer">ChangeLog</a>).</p> <p>You can either ...
<p>Mac OS X 10.7 Lion (and to this date all more recent versions as well, thanks @kojiro) ships with <code>bash 3.2</code> whereas <code>read -i</code> was introduced with <code>bash 4.0-alpha</code> (see the <a href="http://tiswww.case.edu/php/chet/bash/CHANGES" rel="noreferrer">ChangeLog</a>).</p> <p>You can either ...
369, 387
bash, macos
<h1>Bash 'read' command does not accept -i parameter on Mac. Any alternatives?</h1> <p>I have a bash script that works fine on my work Ubuntu machine, but sadly breaks when I try and run it on my Mac OSX <strike>Lion</strike> Mountain Lion laptop. The line that kills it is this:</p> <pre><code>while [[ -z "$SSHFS_PATH...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,790
bash
# Bash 'read' command does not accept -i parameter on Mac. Any alternatives? I have a bash script that works fine on my work Ubuntu machine, but sadly breaks when I try and run it on my Mac OSX Lion Mountain Lion laptop. The line that kills it is this: ``` while [[ -z "$SSHFS_PATH" ]] ; do read -e -p "Please enter ...
Mac OS X 10.7 Lion (and to this date all more recent versions as well, thanks @kojiro) ships with `bash 3.2` whereas `read -i` was introduced with `bash 4.0-alpha` (see the [ChangeLog](http://tiswww.case.edu/php/chet/bash/CHANGES)). You can either install a more recent version of `bash` using [`homebrew`](http://brew....
18647841
Retrieve exit status from php script inside of shell script
12
2013-09-06 00:04:26
<p>I have a bash shell script that calls a few PHP scripts like this.</p> <pre><code>#!/bin/bash php -f somescript.php php -f anotherscript.php </code></pre> <p>I want to compose an error log and/or an activity report based on the results of those scripts.</p> <p>Is there any way I can get the exit status of the p...
13,830
631,764
2021-06-01 07:17:17
21,118,232
16
2014-01-14 16:10:15
1,023,107
2015-11-18 00:45:33
https://stackoverflow.com/q/18647841
https://stackoverflow.com/a/21118232
<p>You can easily catch the output using the <em>backtick</em> operator, and get the exit code of the <strong>last command</strong> by using <em>$?</em>:</p> <pre><code>#!/bin/bash output=`php -f somescript.php` exitcode=$? anotheroutput=`php -f anotherscript.php` anotherexitcode=$? </code></pre>
<p>You can easily catch the output using the <em>backtick</em> operator, and get the exit code of the <strong>last command</strong> by using <em>$?</em>:</p> <pre><code>#!/bin/bash output=`php -f somescript.php` exitcode=$? anotheroutput=`php -f anotherscript.php` anotherexitcode=$? </code></pre>
5, 387, 390, 10021
bash, exit-code, php, shell
<h1>Retrieve exit status from php script inside of shell script</h1> <p>I have a bash shell script that calls a few PHP scripts like this.</p> <pre><code>#!/bin/bash php -f somescript.php php -f anotherscript.php </code></pre> <p>I want to compose an error log and/or an activity report based on the results of those...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,791
bash
# Retrieve exit status from php script inside of shell script I have a bash shell script that calls a few PHP scripts like this. ``` #!/bin/bash php -f somescript.php php -f anotherscript.php ``` I want to compose an error log and/or an activity report based on the results of those scripts. Is there any way I can...
You can easily catch the output using the *backtick* operator, and get the exit code of the **last command** by using *$?*: ``` #!/bin/bash output=`php -f somescript.php` exitcode=$? anotheroutput=`php -f anotherscript.php` anotherexitcode=$? ```
21034043
How to use Jenkins environment variable in shell script?
12
2014-01-10 00:26:56
<p>I want to update a java file with the jenkins build number. I plan on using a shell script to sed the value to the correct build number. I'm currently doing this:</p> <pre><code>sed -i 's/Version 3.0/Version $BUILD_DISPLAY_NAME/g' /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml </code></pre...
26,399
542,322
2018-02-21 15:56:23
21,034,720
16
2014-01-10 01:39:00
1,899,640
2014-01-10 01:39:00
https://stackoverflow.com/q/21034043
https://stackoverflow.com/a/21034720
<p>As <a href="http://www.shellcheck.net">shellcheck</a> would tell you, expansions don't happen in single quotes. Use double quotes instead: </p> <pre><code>sed -i "s/Version 3.0/Version $BUILD_DISPLAY_NAME/g" /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml </code></pre>
<p>As <a href="http://www.shellcheck.net">shellcheck</a> would tell you, expansions don't happen in single quotes. Use double quotes instead: </p> <pre><code>sed -i "s/Version 3.0/Version $BUILD_DISPLAY_NAME/g" /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml </code></pre>
387, 64999
bash, jenkins
<h1>How to use Jenkins environment variable in shell script?</h1> <p>I want to update a java file with the jenkins build number. I plan on using a shell script to sed the value to the correct build number. I'm currently doing this:</p> <pre><code>sed -i 's/Version 3.0/Version $BUILD_DISPLAY_NAME/g' /var/lib/jenkins/...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,792
bash
# How to use Jenkins environment variable in shell script? I want to update a java file with the jenkins build number. I plan on using a shell script to sed the value to the correct build number. I'm currently doing this: ``` sed -i 's/Version 3.0/Version $BUILD_DISPLAY_NAME/g' /var/lib/jenkins/jobs/AndroidTest/works...
As [shellcheck](http://www.shellcheck.net) would tell you, expansions don't happen in single quotes. Use double quotes instead: ``` sed -i "s/Version 3.0/Version $BUILD_DISPLAY_NAME/g" /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml ```
19912681
Build a string in Bash with newlines
12
2013-11-11 17:50:52
<p>I'm going through a script in Bash where, depending on the conditionals, I want to append to a variable different things and then display it at the very end. Something like this:</p> <pre><code>VAR=&quot;The &quot; if [[ whatever ]]; then VAR=&quot;$VAR cat wears a mask&quot; elif [[ whatevs ]]; then VAR=&q...
18,294
970,171
2022-06-17 20:16:06
19,912,771
16
2013-11-11 17:57:12
1,815,797
2022-03-27 15:47:10
https://stackoverflow.com/q/19912681
https://stackoverflow.com/a/19912771
<p>Using <a href="http://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting" rel="noreferrer">ANSI C quoting</a>:</p> <pre><code>var=&quot;$var&quot;$'\n'&quot;in a box&quot; </code></pre> <p>You could put the <code>$'\n'</code> in a variable:</p> <pre><code>newline=$'\n' var=&quot;$var${newline}in a box&...
<p>Using <a href="http://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting" rel="noreferrer">ANSI C quoting</a>:</p> <pre><code>var=&quot;$var&quot;$'\n'&quot;in a box&quot; </code></pre> <p>You could put the <code>$'\n'</code> in a variable:</p> <pre><code>newline=$'\n' var=&quot;$var${newline}in a box&...
387, 390, 3705
bash, newline, shell
<h1>Build a string in Bash with newlines</h1> <p>I'm going through a script in Bash where, depending on the conditionals, I want to append to a variable different things and then display it at the very end. Something like this:</p> <pre><code>VAR=&quot;The &quot; if [[ whatever ]]; then VAR=&quot;$VAR cat wears a ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,793
bash
# Build a string in Bash with newlines I'm going through a script in Bash where, depending on the conditionals, I want to append to a variable different things and then display it at the very end. Something like this: ``` VAR="The " if [[ whatever ]]; then VAR="$VAR cat wears a mask" elif [[ whatevs ]]; then ...
Using [ANSI C quoting](http://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting): ``` var="$var"$'\n'"in a box" ``` You could put the `$'\n'` in a variable: ``` newline=$'\n' var="$var${newline}in a box" ``` By the way, in this case, it's better to use the concatenation operator: ``` var+="${newline...
19302572
How to put sshpass command inside a bash script?
12
2013-10-10 17:40:37
<p>I am trying to run a sshpass command inside a bash script but it isn't working.</p> <p>If I run the same command from the terminal it works fine but running it in a bash script it doesn't.</p> <pre><code>#! /bin/bash sshpass -p 'password' ssh user@host command </code></pre> <p>I am aware of the security issues b...
133,704
2,764,739
2017-01-17 10:37:03
19,303,264
16
2013-10-10 18:19:34
220,710
2013-10-10 18:19:34
https://stackoverflow.com/q/19302572
https://stackoverflow.com/a/19303264
<p>Do <code>which sshpass</code> in your command line to get the absolute path to <code>sshpass</code> and replace it in the bash script. </p> <p>You should also probably do the same with the <code>command</code> you are trying to run.</p> <p>The problem might be that it is not finding it.</p>
<p>Do <code>which sshpass</code> in your command line to get the absolute path to <code>sshpass</code> and replace it in the bash script. </p> <p>You should also probably do the same with the <code>command</code> you are trying to run.</p> <p>The problem might be that it is not finding it.</p>
386, 387
bash, ssh
<h1>How to put sshpass command inside a bash script?</h1> <p>I am trying to run a sshpass command inside a bash script but it isn't working.</p> <p>If I run the same command from the terminal it works fine but running it in a bash script it doesn't.</p> <pre><code>#! /bin/bash sshpass -p 'password' ssh user@host com...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,794
bash
# How to put sshpass command inside a bash script? I am trying to run a sshpass command inside a bash script but it isn't working. If I run the same command from the terminal it works fine but running it in a bash script it doesn't. ``` #! /bin/bash sshpass -p 'password' ssh user@host command ``` I am aware of the...
Do `which sshpass` in your command line to get the absolute path to `sshpass` and replace it in the bash script. You should also probably do the same with the `command` you are trying to run. The problem might be that it is not finding it.
17557487
Linux: The command ls -la shows a file pointing to another file. What does that mean?
12
2013-07-09 20:24:16
<p>When I type <code>ls -la</code> to list all the files, I see this:</p> <pre><code>11 Jul 9 12:04 libcrypto.so -&gt; libcrypto.so.0 </code></pre> <p>I tried to change the name of libcrypto:</p> <pre><code>mv libcryto.so libpmcrypto.so </code></pre> <p>And now it shows:</p> <pre><code>11 Jul 9 12:04 libpmcrypto...
28,985
1,522,257
2013-07-26 15:13:58
17,557,657
16
2013-07-09 20:31:55
18,796
2013-07-09 20:57:00
https://stackoverflow.com/q/17557487
https://stackoverflow.com/a/17557657
<p>The file in question is a symbolic link. This is conceptually similar to the idea of a shortcut, but it appears to be the real file if you use it (Open it, copy it, etc.). The symbolic link is another name that "points to" the real file. When you do <code>ls -l</code> it also shows you which file is pointed to by...
<p>The file in question is a symbolic link. This is conceptually similar to the idea of a shortcut, but it appears to be the real file if you use it (Open it, copy it, etc.). The symbolic link is another name that "points to" the real file. When you do <code>ls -l</code> it also shows you which file is pointed to by...
387, 1122, 3589
bash, ls, symlink
<h1>Linux: The command ls -la shows a file pointing to another file. What does that mean?</h1> <p>When I type <code>ls -la</code> to list all the files, I see this:</p> <pre><code>11 Jul 9 12:04 libcrypto.so -&gt; libcrypto.so.0 </code></pre> <p>I tried to change the name of libcrypto:</p> <pre><code>mv libcryto.so...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,795
bash
# Linux: The command ls -la shows a file pointing to another file. What does that mean? When I type `ls -la` to list all the files, I see this: ``` 11 Jul 9 12:04 libcrypto.so -> libcrypto.so.0 ``` I tried to change the name of libcrypto: ``` mv libcryto.so libpmcrypto.so ``` And now it shows: ``` 11 Jul 9 12:0...
The file in question is a symbolic link. This is conceptually similar to the idea of a shortcut, but it appears to be the real file if you use it (Open it, copy it, etc.). The symbolic link is another name that "points to" the real file. When you do `ls -l` it also shows you which file is pointed to by the link. Renami...
15439542
how to use PowerShell to inventory Scheduled Tasks
12
2013-03-15 18:21:46
<p>Does anyone have a link or script that uses PowerShell to inventory the Scheduled Tasks on a server, including the Action?</p> <p>I am able to get the Scheduled Service com object and what I would call "top level" properties (name, state, lastruntime), but would like to also get information from the "Actions" part ...
58,937
1,130,790
2018-12-13 20:26:14
15,449,451
16
2013-03-16 12:48:29
702,944
2013-03-16 16:35:20
https://stackoverflow.com/q/15439542
https://stackoverflow.com/a/15449451
<p>This is probably very similar to current answers, but I wrote a quick script to get you going. The problem with your current script is that there is no <code>Actions</code> property in a task. You need to extract it from the xml task-definition that the comobject provides. The following script will return an array o...
<p>This is probably very similar to current answers, but I wrote a quick script to get you going. The problem with your current script is that there is no <code>Actions</code> property in a task. You need to extract it from the xml task-definition that the comobject provides. The following script will return an array o...
526, 9299
powershell, scheduled-tasks
<h1>how to use PowerShell to inventory Scheduled Tasks</h1> <p>Does anyone have a link or script that uses PowerShell to inventory the Scheduled Tasks on a server, including the Action?</p> <p>I am able to get the Scheduled Service com object and what I would call "top level" properties (name, state, lastruntime), but...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,796
bash
# how to use PowerShell to inventory Scheduled Tasks Does anyone have a link or script that uses PowerShell to inventory the Scheduled Tasks on a server, including the Action? I am able to get the Scheduled Service com object and what I would call "top level" properties (name, state, lastruntime), but would like to a...
This is probably very similar to current answers, but I wrote a quick script to get you going. The problem with your current script is that there is no `Actions` property in a task. You need to extract it from the xml task-definition that the comobject provides. The following script will return an array of objects, one...
13969817
Send text file, line by line, with netcat
12
2012-12-20 10:14:36
<p>I'm trying to send a file, line by line, with the following commands:</p> <pre><code>nc host port &lt; textfile cat textfile | nc host port </code></pre> <p>I've tried with <em>tail</em> and <em>head</em>, but with the same result: the entire file is sent as a unique line. The server is listening with a specific d...
38,230
329,584
2019-09-12 14:18:49
13,971,251
16
2012-12-20 11:31:27
793,796
2014-04-01 09:50:04
https://stackoverflow.com/q/13969817
https://stackoverflow.com/a/13971251
<p>Do you HAVE TO use netcat?</p> <pre><code>cat textfile &gt; /dev/tcp/HOST/PORT </code></pre> <p>can also serve your purpose, at least with bash.</p> <hr> <blockquote> <p>I'de like to send, and receive, one by one the lines, not all the file in a single shot.</p> </blockquote> <p>Try</p> <pre><code>while read...
<p>Do you HAVE TO use netcat?</p> <pre><code>cat textfile &gt; /dev/tcp/HOST/PORT </code></pre> <p>can also serve your purpose, at least with bash.</p> <hr> <blockquote> <p>I'de like to send, and receive, one by one the lines, not all the file in a single shot.</p> </blockquote> <p>Try</p> <pre><code>while read...
34, 390, 24801
netcat, shell, unix
<h1>Send text file, line by line, with netcat</h1> <p>I'm trying to send a file, line by line, with the following commands:</p> <pre><code>nc host port &lt; textfile cat textfile | nc host port </code></pre> <p>I've tried with <em>tail</em> and <em>head</em>, but with the same result: the entire file is sent as a uni...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,797
bash
# Send text file, line by line, with netcat I'm trying to send a file, line by line, with the following commands: ``` nc host port < textfile cat textfile | nc host port ``` I've tried with *tail* and *head*, but with the same result: the entire file is sent as a unique line. The server is listening with a specific ...
Do you HAVE TO use netcat? ``` cat textfile > /dev/tcp/HOST/PORT ``` can also serve your purpose, at least with bash. --- > I'de like to send, and receive, one by one the lines, not all the file in a single shot. Try ``` while read x; do echo "$x" | nc host port; done < textfile ```
13962703
How do I call exec in psake to an executable with a variable path?
12
2012-12-19 23:01:47
<p>I can't seem to call this executable correctly in my psake deploy script.</p> <p>If I do this:</p> <pre><code>exec { "$ArchiverOutputDir\NServiceBus.Host.exe /install" } </code></pre> <p>It simply outputs this (and is clearly not calling the executable - just outputting the value of that expression):</p> <pre><c...
2,833
549
2015-03-31 13:01:07
13,962,946
16
2012-12-19 23:28:11
153,982
2015-03-31 13:01:07
https://stackoverflow.com/q/13962703
https://stackoverflow.com/a/13962946
<p>Classic PowerShell issue. Try this instead:</p> <pre><code>exec { &amp; "$ArchiverOutputDir\NServiceBus.Host.exe" /install } </code></pre> <p>PowerShell not only executes commands, it also evaluates expressions e.g.:</p> <pre><code>C:\PS&gt; 2 + 2 4 C:\PS&gt; "hello world" hello world </code></pre> <p>What you h...
<p>Classic PowerShell issue. Try this instead:</p> <pre><code>exec { &amp; "$ArchiverOutputDir\NServiceBus.Host.exe" /install } </code></pre> <p>PowerShell not only executes commands, it also evaluates expressions e.g.:</p> <pre><code>C:\PS&gt; 2 + 2 4 C:\PS&gt; "hello world" hello world </code></pre> <p>What you h...
526, 17062
powershell, psake
<h1>How do I call exec in psake to an executable with a variable path?</h1> <p>I can't seem to call this executable correctly in my psake deploy script.</p> <p>If I do this:</p> <pre><code>exec { "$ArchiverOutputDir\NServiceBus.Host.exe /install" } </code></pre> <p>It simply outputs this (and is clearly not calling ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,798
bash
# How do I call exec in psake to an executable with a variable path? I can't seem to call this executable correctly in my psake deploy script. If I do this: ``` exec { "$ArchiverOutputDir\NServiceBus.Host.exe /install" } ``` It simply outputs this (and is clearly not calling the executable - just outputting the val...
Classic PowerShell issue. Try this instead: ``` exec { & "$ArchiverOutputDir\NServiceBus.Host.exe" /install } ``` PowerShell not only executes commands, it also evaluates expressions e.g.: ``` C:\PS> 2 + 2 4 C:\PS> "hello world" hello world ``` What you have given to PowerShell at the beginning of a pipeline is a s...
12750293
Find line number in a text file - without opening the file
12
2012-10-05 16:22:33
<p>In a very large file I need to find the position (line number) of a string, then extract the 2 lines above and below that string. </p> <p>To do this right now - I launch vi, find the string, note it's line number, exit vi, then use sed to extract the lines surrounding that string. </p> <p>Is there a way to streaml...
56,590
159,610
2023-11-23 11:29:50
12,750,353
16
2012-10-05 16:26:44
1,014,586
2012-10-05 17:18:55
https://stackoverflow.com/q/12750293
https://stackoverflow.com/a/12750353
<p>Maybe using grep like this:</p> <pre><code>grep -n -2 your_searched_for_string your_large_text_file </code></pre> <p>Will give you almost what you expect</p> <p>-n : tells grep to print the line number</p> <p>-2 : print 2 additional lines (and the wanted string, of course)</p>
<p>Maybe using grep like this:</p> <pre><code>grep -n -2 your_searched_for_string your_large_text_file </code></pre> <p>Will give you almost what you expect</p> <p>-n : tells grep to print the line number</p> <p>-2 : print 2 additional lines (and the wanted string, of course)</p>
58, 390
linux, shell
<h1>Find line number in a text file - without opening the file</h1> <p>In a very large file I need to find the position (line number) of a string, then extract the 2 lines above and below that string. </p> <p>To do this right now - I launch vi, find the string, note it's line number, exit vi, then use sed to extract t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,799
bash
# Find line number in a text file - without opening the file In a very large file I need to find the position (line number) of a string, then extract the 2 lines above and below that string. To do this right now - I launch vi, find the string, note it's line number, exit vi, then use sed to extract the lines surround...
Maybe using grep like this: ``` grep -n -2 your_searched_for_string your_large_text_file ``` Will give you almost what you expect -n : tells grep to print the line number -2 : print 2 additional lines (and the wanted string, of course)
12211560
What is the difference between ">" and "&>" in bash?
12
2012-08-31 08:28:03
<p>In bash we have 3 stream types:</p> <ul> <li>0 (STDIN)</li> <li>1 (STDOUT)</li> <li>2 (STDERR)</li> </ul> <p>So, while executing some program i can use these streams (e.g. i can redirect them from console to a file or smth like /dev/null, etc):</p> <pre><code># only errors from STDERR will be shown, STDOUT will be m...
6,303
1,391,074
2021-02-27 08:02:56
12,211,600
16
2012-08-31 08:30:41
714,501
2012-08-31 08:30:41
https://stackoverflow.com/q/12211560
https://stackoverflow.com/a/12211600
<blockquote> <p>what is the difference between ">" and "&amp;>" in bash?</p> </blockquote> <p>It's a bashism that redirects both <code>stdout</code> and <code>stderr</code>. It can also be achieved with the more portable:</p> <pre><code>command &gt; file 2&gt;&amp;1 </code></pre>
<blockquote> <p>what is the difference between ">" and "&amp;>" in bash?</p> </blockquote> <p>It's a bashism that redirects both <code>stdout</code> and <code>stderr</code>. It can also be achieved with the more portable:</p> <pre><code>command &gt; file 2&gt;&amp;1 </code></pre>
58, 387, 488
bash, console, linux
<h1>What is the difference between ">" and "&>" in bash?</h1> <p>In bash we have 3 stream types:</p> <ul> <li>0 (STDIN)</li> <li>1 (STDOUT)</li> <li>2 (STDERR)</li> </ul> <p>So, while executing some program i can use these streams (e.g. i can redirect them from console to a file or smth like /dev/null, etc):</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,800
bash
# What is the difference between ">" and "&>" in bash? In bash we have 3 stream types: - 0 (STDIN) - 1 (STDOUT) - 2 (STDERR) So, while executing some program i can use these streams (e.g. i can redirect them from console to a file or smth like /dev/null, etc): ``` # only errors from STDERR will be shown, STDOUT wil...
> what is the difference between ">" and "&>" in bash? It's a bashism that redirects both `stdout` and `stderr`. It can also be achieved with the more portable: ``` command > file 2>&1 ```
11905649
Unicode support for Invoke-Sqlcmd in PowerShell
12
2012-08-10 16:24:38
<p>The PowerShell <a href="http://msdn.microsoft.com/en-us/library/hh245198">sqlps module</a> provides core support for SQL Server access from within PowerShell and its <a href="http://msdn.microsoft.com/en-us/library/cc281720">Invoke-Sqlcmd</a> cmdlet is its main workhorse for executing literal queries or SQL script f...
15,494
115,690
2021-01-23 22:21:34
11,911,050
16
2012-08-11 01:10:24
135,965
2012-08-12 13:03:27
https://stackoverflow.com/q/11905649
https://stackoverflow.com/a/11911050
<p><strong>Update</strong> I tested invoke-sqlcmd on another machine and it works, so maybe the rest of this doesn't apply...</p> <p><strong>Update 2</strong> Only seems to have issue with -inputfile when executing via -Query parameter invoke-sqlcmd works fine.</p> <p>From what I can tell this has something to do wit...
<p><strong>Update</strong> I tested invoke-sqlcmd on another machine and it works, so maybe the rest of this doesn't apply...</p> <p><strong>Update 2</strong> Only seems to have issue with -inputfile when executing via -Query parameter invoke-sqlcmd works fine.</p> <p>From what I can tell this has something to do wit...
72, 279, 526, 7445
powershell, sqlcmd, sql-server, unicode
<h1>Unicode support for Invoke-Sqlcmd in PowerShell</h1> <p>The PowerShell <a href="http://msdn.microsoft.com/en-us/library/hh245198">sqlps module</a> provides core support for SQL Server access from within PowerShell and its <a href="http://msdn.microsoft.com/en-us/library/cc281720">Invoke-Sqlcmd</a> cmdlet is its mai...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,801
bash
# Unicode support for Invoke-Sqlcmd in PowerShell The PowerShell [sqlps module](http://msdn.microsoft.com/en-us/library/hh245198) provides core support for SQL Server access from within PowerShell and its [Invoke-Sqlcmd](http://msdn.microsoft.com/en-us/library/cc281720) cmdlet is its main workhorse for executing liter...
**Update** I tested invoke-sqlcmd on another machine and it works, so maybe the rest of this doesn't apply... **Update 2** Only seems to have issue with -inputfile when executing via -Query parameter invoke-sqlcmd works fine. From what I can tell this has something to do with ADO.NET DataTable when converting a strin...
11364722
run bash script without input
12
2012-07-06 15:00:31
<p>I have written a bash script which installs a number of packages, however for each consecutive package installation i am promoted with the following message:</p> <pre><code>After this operation, 1,006 kB of additional disk space will be used. Do you want to continue [Y/n]? </code></pre> <p>Is there a way of set...
6,368
1,285,948
2012-07-06 16:26:18
11,364,864
16
2012-07-06 15:08:39
1,085,062
2012-07-06 15:08:39
https://stackoverflow.com/q/11364722
https://stackoverflow.com/a/11364864
<p>Two methods come to mind. The first (and better option) is to use the options in your package manager. For example: </p> <pre><code>apt-get install -y [YOUR_PACKAGE] </code></pre> <p>if you use <code>apt</code> (type <code>apt-get install --help</code> for more help there). </p> <p>The second is more of a quick-'...
<p>Two methods come to mind. The first (and better option) is to use the options in your package manager. For example: </p> <pre><code>apt-get install -y [YOUR_PACKAGE] </code></pre> <p>if you use <code>apt</code> (type <code>apt-get install --help</code> for more help there). </p> <p>The second is more of a quick-'...
34, 387, 390
bash, shell, unix
<h1>run bash script without input</h1> <p>I have written a bash script which installs a number of packages, however for each consecutive package installation i am promoted with the following message:</p> <pre><code>After this operation, 1,006 kB of additional disk space will be used. Do you want to continue [Y/n]? ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,802
bash
# run bash script without input I have written a bash script which installs a number of packages, however for each consecutive package installation i am promoted with the following message: ``` After this operation, 1,006 kB of additional disk space will be used. Do you want to continue [Y/n]? ``` Is there a way o...
Two methods come to mind. The first (and better option) is to use the options in your package manager. For example: ``` apt-get install -y [YOUR_PACKAGE] ``` if you use `apt` (type `apt-get install --help` for more help there). The second is more of a quick-'n-dirty one...use a pipe after `yes`: ``` yes | apt-get i...
9568611
How does argparse (and the deprecated optparse) respond to 'tab' keypress after python program name, in bash?
12
2012-03-05 14:47:41
<p>I have tested <a href="http://furius.ca/optcomplete/"><code>optcomplete</code></a> working with the <code>optparse</code> module. Its example is a simple file so I could get that working. I also tested it using the <code>argparse</code> module as the prior one is deprecated. But I really do not understand how and by...
3,130
860,421
2023-09-27 18:53:44
9,571,453
16
2012-03-05 17:52:58
916,657
2023-09-27 18:53:44
https://stackoverflow.com/q/9568611
https://stackoverflow.com/a/9571453
<p>To understand what's happening here, let's check what that bash function actually does:</p> <pre><code>COMPREPLY=( $( \ COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT \ COMP_WORDS=&quot;${COMP_WORDS[*]}&quot; COMP_CWORD=$COMP_CWORD \ OPTPARSE_AUTO_COMPLETE=1 $1 ) ) </code></pre> <p>See the <code>$1</code>...
<p>To understand what's happening here, let's check what that bash function actually does:</p> <pre><code>COMPREPLY=( $( \ COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT \ COMP_WORDS=&quot;${COMP_WORDS[*]}&quot; COMP_CWORD=$COMP_CWORD \ OPTPARSE_AUTO_COMPLETE=1 $1 ) ) </code></pre> <p>See the <code>$1</code>...
16, 387, 4682, 8780, 59189
argparse, autocomplete, bash, python, shebang
<h1>How does argparse (and the deprecated optparse) respond to 'tab' keypress after python program name, in bash?</h1> <p>I have tested <a href="http://furius.ca/optcomplete/"><code>optcomplete</code></a> working with the <code>optparse</code> module. Its example is a simple file so I could get that working. I also tes...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,803
bash
# How does argparse (and the deprecated optparse) respond to 'tab' keypress after python program name, in bash? I have tested [`optcomplete`](http://furius.ca/optcomplete/) working with the `optparse` module. Its example is a simple file so I could get that working. I also tested it using the `argparse` module as the ...
To understand what's happening here, let's check what that bash function actually does: ``` COMPREPLY=( $( \ COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT \ COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD \ OPTPARSE_AUTO_COMPLETE=1 $1 ) ) ``` See the `$1` at the end? That means that it actually calls...
4418378
Wrap all commands entered within a Bash-Shell with a Python script
12
2010-12-11 19:00:20
<p>What i'd like to have is a mechanism that all commands i enter on a Bash-Terminal are wrapped by a Python-script. The Python-script executes the entered command, but it adds some additional magic (for example setting "dynamic" environment variables). Is that possible somehow? </p> <p>I'm running Ubuntu and Debian ...
4,719
319,905
2012-01-17 21:29:57
8,893,138
16
2012-01-17 10:36:15
319,905
2012-01-17 21:29:57
https://stackoverflow.com/q/4418378
https://stackoverflow.com/a/8893138
<p>The perfect way to wrap every command that is typed into a Bash Shell is to change the variable <code>PROMPT_COMMAND</code> inside the .bashrc. For example, if I want to do some Python stuff before every command, liked asked in my question:</p> <p>.bashrc:</p> <pre><code># ... PROMPT_COMMAND="python mycoolscript.p...
<p>The perfect way to wrap every command that is typed into a Bash Shell is to change the variable <code>PROMPT_COMMAND</code> inside the .bashrc. For example, if I want to do some Python stuff before every command, liked asked in my question:</p> <p>.bashrc:</p> <pre><code># ... PROMPT_COMMAND="python mycoolscript.p...
16, 58, 387
bash, linux, python
<h1>Wrap all commands entered within a Bash-Shell with a Python script</h1> <p>What i'd like to have is a mechanism that all commands i enter on a Bash-Terminal are wrapped by a Python-script. The Python-script executes the entered command, but it adds some additional magic (for example setting "dynamic" environment va...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,804
bash
# Wrap all commands entered within a Bash-Shell with a Python script What i'd like to have is a mechanism that all commands i enter on a Bash-Terminal are wrapped by a Python-script. The Python-script executes the entered command, but it adds some additional magic (for example setting "dynamic" environment variables)....
The perfect way to wrap every command that is typed into a Bash Shell is to change the variable `PROMPT_COMMAND` inside the .bashrc. For example, if I want to do some Python stuff before every command, liked asked in my question: .bashrc: ``` # ... PROMPT_COMMAND="python mycoolscript.py; $PROMPT_COMMAND;" export $PRO...
7773738
Execute an array of string describing shell command
12
2011-10-14 21:25:13
<p>I'm struggling to execute a set of command lines stored as strings in an array. My code looks like this :</p> <pre><code>arr=( "sudo apt-get update" "sudo apt-get install xxx" ) ... arr=( ${arr[@]} "ln -s /path1 /path2" ) etc... # Then I loop on the array of command for (( i = 0 ; i &lt; ${#arr[@]} ; i++ )) do ...
24,168
808,724
2024-08-06 00:50:30
7,774,197
16
2011-10-14 22:22:21
836,407
2011-10-14 23:07:15
https://stackoverflow.com/q/7773738
https://stackoverflow.com/a/7774197
<p>Use <code>${#arr[@]}</code> to get the number of items in the array (<code>${arr[@]}</code> gives the word count). Using either <code>eval</code> or back-ticks (<kbd>`</kbd>) to execute the command works:</p> <pre><code>[ 15:20 jon@host ~ ]$ cat run_yum_test.sh #!/bin/bash declare -a arr=("sudo yum search zsh" "s...
<p>Use <code>${#arr[@]}</code> to get the number of items in the array (<code>${arr[@]}</code> gives the word count). Using either <code>eval</code> or back-ticks (<kbd>`</kbd>) to execute the command works:</p> <pre><code>[ 15:20 jon@host ~ ]$ cat run_yum_test.sh #!/bin/bash declare -a arr=("sudo yum search zsh" "s...
387
bash
<h1>Execute an array of string describing shell command</h1> <p>I'm struggling to execute a set of command lines stored as strings in an array. My code looks like this :</p> <pre><code>arr=( "sudo apt-get update" "sudo apt-get install xxx" ) ... arr=( ${arr[@]} "ln -s /path1 /path2" ) etc... # Then I loop on the arra...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,805
bash
# Execute an array of string describing shell command I'm struggling to execute a set of command lines stored as strings in an array. My code looks like this : ``` arr=( "sudo apt-get update" "sudo apt-get install xxx" ) ... arr=( ${arr[@]} "ln -s /path1 /path2" ) etc... # Then I loop on the array of command for ((...
Use `${#arr[@]}` to get the number of items in the array (`${arr[@]}` gives the word count). Using either `eval` or back-ticks (`` ` ``) to execute the command works: ``` [ 15:20 jon@host ~ ]$ cat run_yum_test.sh #!/bin/bash declare -a arr=("sudo yum search zsh" "sudo yum list zsh") for (( i = 0; i < ${#arr[@]} ; i+...
6947925
Add app to OSX "Login Items" during a Package Maker installer postflight script
12
2011-08-04 20:11:15
<p>I need a way to add an application to the Login Items from a postflight script which is run as part of my installer. It needs to work on 10.5+. Preferably, it would work in a bash script. My application already requires administrative rights.</p> <p>The approach I found here: <a href="https://stackoverflow.com/q...
12,088
67,268
2017-07-30 00:48:24
7,643,260
16
2011-10-04 04:19:49
67,268
2013-03-13 00:30:21
https://stackoverflow.com/q/6947925
https://stackoverflow.com/a/7643260
<p>Here's the options I investigated and experimented with:</p> <h2>Option 1: Use Login Items</h2> <p>This is the method I used. It's very easy to do from a bash file by adding the following line to your postflight.</p> <pre><code>defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -ar...
<p>Here's the options I investigated and experimented with:</p> <h2>Option 1: Use Login Items</h2> <p>This is the method I used. It's very easy to do from a bash file by adding the following line to your postflight.</p> <pre><code>defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -ar...
369, 387, 19696
bash, macos, packagemaker
<h1>Add app to OSX "Login Items" during a Package Maker installer postflight script</h1> <p>I need a way to add an application to the Login Items from a postflight script which is run as part of my installer. It needs to work on 10.5+. Preferably, it would work in a bash script. My application already requires admin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,806
bash
# Add app to OSX "Login Items" during a Package Maker installer postflight script I need a way to add an application to the Login Items from a postflight script which is run as part of my installer. It needs to work on 10.5+. Preferably, it would work in a bash script. My application already requires administrative ri...
Here's the options I investigated and experimented with: ## Option 1: Use Login Items This is the method I used. It's very easy to do from a bash file by adding the following line to your postflight. ``` defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -array-add '{Path="/Application...
6854118
Bash 'for' loop syntax?
12
2011-07-28 04:32:51
<p>What is the syntax for a Bash <code>for</code> loop?</p> <p>I have tried:</p> <pre><code>for (($i=0;$i&lt;10;$i ++)) do echo $i done </code></pre> <p>I get this error:</p> <pre><code>line 1: ((: =0: syntax error: operand expected (error token is "=0") </code></pre>
14,820
null
2016-02-13 18:52:23
6,854,122
16
2011-07-28 04:33:45
417,980
2013-08-28 21:08:01
https://stackoverflow.com/q/6854118
https://stackoverflow.com/a/6854122
<p>Replace </p> <pre><code>for (($i=0... </code></pre> <p>with </p> <pre><code>for ((i=0;i&lt;10;i++)) </code></pre>
<p>Replace </p> <pre><code>for (($i=0... </code></pre> <p>with </p> <pre><code>for ((i=0;i&lt;10;i++)) </code></pre>
387, 390, 531
bash, scripting, shell
<h1>Bash 'for' loop syntax?</h1> <p>What is the syntax for a Bash <code>for</code> loop?</p> <p>I have tried:</p> <pre><code>for (($i=0;$i&lt;10;$i ++)) do echo $i done </code></pre> <p>I get this error:</p> <pre><code>line 1: ((: =0: syntax error: operand expected (error token is "=0") </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,807
bash
# Bash 'for' loop syntax? What is the syntax for a Bash `for` loop? I have tried: ``` for (($i=0;$i<10;$i ++)) do echo $i done ``` I get this error: ``` line 1: ((: =0: syntax error: operand expected (error token is "=0") ```
Replace ``` for (($i=0... ``` with ``` for ((i=0;i<10;i++)) ```
6756360
How do I get "previous executed command" in a bash script?
12
2011-07-20 02:32:50
<p>I use multiple bash sessions, and I want to keep track of history from all of them in one file (I don't care that it is multiplexed from multiple sessions, I can always put a session identifier in front of it.) I have tried doing </p> <pre><code>shopt -s histappend </code></pre> <p>and also adding </p> <pre><code...
11,866
2,344,982
2011-07-20 02:36:54
6,756,392
16
2011-07-20 02:36:54
643,977
2011-07-20 02:36:54
https://stackoverflow.com/q/6756360
https://stackoverflow.com/a/6756392
<p>Something like</p> <pre><code>fc -ln -1 </code></pre> <p>should work. That said, you're probably running into concurrent access issues (read: multiple shells overwriting each others' history) and you may not be able to do any better by hand.</p>
<p>Something like</p> <pre><code>fc -ln -1 </code></pre> <p>should work. That said, you're probably running into concurrent access issues (read: multiple shells overwriting each others' history) and you may not be able to do any better by hand.</p>
387
bash
<h1>How do I get "previous executed command" in a bash script?</h1> <p>I use multiple bash sessions, and I want to keep track of history from all of them in one file (I don't care that it is multiplexed from multiple sessions, I can always put a session identifier in front of it.) I have tried doing </p> <pre><code>sh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,808
bash
# How do I get "previous executed command" in a bash script? I use multiple bash sessions, and I want to keep track of history from all of them in one file (I don't care that it is multiplexed from multiple sessions, I can always put a session identifier in front of it.) I have tried doing ``` shopt -s histappend ```...
Something like ``` fc -ln -1 ``` should work. That said, you're probably running into concurrent access issues (read: multiple shells overwriting each others' history) and you may not be able to do any better by hand.
5590375
Recursively unzip files and then delete original file, leaving unzipped files in place from shell
12
2011-04-08 04:18:52
<p>I've so far figured out how to use find to recursively unzip all the files:</p> <pre><code>find . -depth -name `*.zip` -exec /usr/bin/unzip -n {} \; </code></pre> <p>But, I can't figure out how to remove the zip files one at a time after the extraction. Adding rm *.zip in an -a -exec ends up deleting most of the ...
37,997
697,974
2016-03-31 23:03:29
5,590,522
16
2011-04-08 04:41:39
246,762
2015-05-20 01:36:09
https://stackoverflow.com/q/5590375
https://stackoverflow.com/a/5590522
<p>have you tried:</p> <pre><code>find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -exec rm {} \; </code></pre> <p>or </p> <pre><code>find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -delete </code></pre> <p>or running a second find after the unzip one</p> <pre><code>find . -depth -name '*.zip' -...
<p>have you tried:</p> <pre><code>find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -exec rm {} \; </code></pre> <p>or </p> <pre><code>find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -delete </code></pre> <p>or running a second find after the unzip one</p> <pre><code>find . -depth -name '*.zip' -...
387, 5610, 7597
bash, rm, unzip
<h1>Recursively unzip files and then delete original file, leaving unzipped files in place from shell</h1> <p>I've so far figured out how to use find to recursively unzip all the files:</p> <pre><code>find . -depth -name `*.zip` -exec /usr/bin/unzip -n {} \; </code></pre> <p>But, I can't figure out how to remove the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,809
bash
# Recursively unzip files and then delete original file, leaving unzipped files in place from shell I've so far figured out how to use find to recursively unzip all the files: ``` find . -depth -name `*.zip` -exec /usr/bin/unzip -n {} \; ``` But, I can't figure out how to remove the zip files one at a time after the...
have you tried: ``` find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -exec rm {} \; ``` or ``` find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -delete ``` or running a second find after the unzip one ``` find . -depth -name '*.zip' -exec rm {} \; ```
4731344
Display all service names matching a string pattern
12
2011-01-19 02:57:34
<p>I'm trying to display the name (just the name) of all of the installed services that contain the string "SQL". For example, I want to see</p> <ul> <li>SQLAgent$SQL2008_R2</li> <li>SQLBrowser</li> <li>SQLWriter</li> </ul> <p>So I try this:</p> <pre><code>Get-WmiObject Win32_Service </code></pre> <p>This displays ...
66,310
25,216
2015-02-25 19:09:01
4,731,390
16
2011-01-19 03:11:34
236,131
2011-01-19 06:27:19
https://stackoverflow.com/q/4731344
https://stackoverflow.com/a/4731390
<p>The easiest way to achieve that is using <code>-Filter</code> Parameter</p> <pre><code>Get-WMIObject Win32_Service -Filter "Name LIKE '%SQL%'" | Select -ExpandProperty Name </code></pre> <p>In case, you want to go with your code only, here is the way you can modify it:</p> <pre><code>Get-WmiObject Win32_Service ...
<p>The easiest way to achieve that is using <code>-Filter</code> Parameter</p> <pre><code>Get-WMIObject Win32_Service -Filter "Name LIKE '%SQL%'" | Select -ExpandProperty Name </code></pre> <p>In case, you want to go with your code only, here is the way you can modify it:</p> <pre><code>Get-WmiObject Win32_Service ...
526, 2596
powershell, windows-services
<h1>Display all service names matching a string pattern</h1> <p>I'm trying to display the name (just the name) of all of the installed services that contain the string "SQL". For example, I want to see</p> <ul> <li>SQLAgent$SQL2008_R2</li> <li>SQLBrowser</li> <li>SQLWriter</li> </ul> <p>So I try this:</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,810
bash
# Display all service names matching a string pattern I'm trying to display the name (just the name) of all of the installed services that contain the string "SQL". For example, I want to see - SQLAgent$SQL2008_R2 - SQLBrowser - SQLWriter So I try this: ``` Get-WmiObject Win32_Service ``` This displays all of the ...
The easiest way to achieve that is using `-Filter` Parameter ``` Get-WMIObject Win32_Service -Filter "Name LIKE '%SQL%'" | Select -ExpandProperty Name ``` In case, you want to go with your code only, here is the way you can modify it: ``` Get-WmiObject Win32_Service | Select-Object -ExpandProperty Name | Select-St...
70609175
How to format date in bash to YYYY-DD-MMTHH:MM:SS.sss
11
2022-01-06 15:06:18
<p>can someone give me a point how to format data in bash with miliseconds? Thanks for help.</p> <p>BR.</p> <p>Petr</p>
18,100
403,675
2025-02-08 13:54:17
70,609,414
16
2022-01-06 15:23:20
403,675
2022-02-02 16:52:42
https://stackoverflow.com/q/70609175
https://stackoverflow.com/a/70609414
<p>Solution is pretty simple. It is <code>date '+%Y-%m-%dT%T.%3N'</code>.</p>
<p>Solution is pretty simple. It is <code>date '+%Y-%m-%dT%T.%3N'</code>.</p>
58, 245, 387, 5002
bash, date, format, linux
<h1>How to format date in bash to YYYY-DD-MMTHH:MM:SS.sss</h1> <p>can someone give me a point how to format data in bash with miliseconds? Thanks for help.</p> <p>BR.</p> <p>Petr</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,811
bash
# How to format date in bash to YYYY-DD-MMTHH:MM:SS.sss can someone give me a point how to format data in bash with miliseconds? Thanks for help. BR. Petr
Solution is pretty simple. It is `date '+%Y-%m-%dT%T.%3N'`.
61103034
Avoid command line arguments propagation when sourcing bash script
11
2020-04-08 14:22:59
<p>I have a bash script <code>a.sh</code> that looks like this:</p> <pre class="lang-sh prettyprint-override"><code>#!/bin/bash echo $# echo $1 </code></pre> <p>and a script <code>b.sh</code> that looks like this:</p> <pre class="lang-sh prettyprint-override"><code>#!/bin/bash source ./a.sh </code></pre> <p>If I ca...
3,838
1,028,138
2022-09-21 14:15:52
61,106,037
16
2020-04-08 17:00:50
89,817
2021-09-23 03:15:00
https://stackoverflow.com/q/61103034
https://stackoverflow.com/a/61106037
<p>The root of the problem is an anomaly in how the <code>source</code> command works. From the <a href="https://linux.die.net/man/1/bash" rel="noreferrer">bash man page</a>, in the &quot;Shell Builtin Commands&quot; section:</p> <blockquote> <p>. <em>filename</em> [<em>arguments</em>]<br /> source <em>filename</em> [<...
<p>The root of the problem is an anomaly in how the <code>source</code> command works. From the <a href="https://linux.die.net/man/1/bash" rel="noreferrer">bash man page</a>, in the &quot;Shell Builtin Commands&quot; section:</p> <blockquote> <p>. <em>filename</em> [<em>arguments</em>]<br /> source <em>filename</em> [<...
387
bash
<h1>Avoid command line arguments propagation when sourcing bash script</h1> <p>I have a bash script <code>a.sh</code> that looks like this:</p> <pre class="lang-sh prettyprint-override"><code>#!/bin/bash echo $# echo $1 </code></pre> <p>and a script <code>b.sh</code> that looks like this:</p> <pre class="lang-sh pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,812
bash
# Avoid command line arguments propagation when sourcing bash script I have a bash script `a.sh` that looks like this: ``` #!/bin/bash echo $# echo $1 ``` and a script `b.sh` that looks like this: ``` #!/bin/bash source ./a.sh ``` If I call `./a.sh` I'm correctly getting 0 and an empty line as output. When calling...
The root of the problem is an anomaly in how the `source` command works. From the [bash man page](https://linux.die.net/man/1/bash), in the "Shell Builtin Commands" section: > . *filename* [*arguments*] > source *filename* [*arguments*] > [...] If any *arguments* are supplied, they become the positional parameters...
53380988
How to execute Shell Script from Flask App
11
2018-11-19 18:57:17
<p>I've created and deployed a Flask App with Apache2 server WSGI in which now would like to run a .sh script from the App. However, from calling from python code, it doesn't execute. </p> <p>Here is the test.sh:</p> <pre><code>#!/bin/bash echo "hi from shell script" </code></pre> <p>Here is my python flask app cod...
31,627
3,866,549
2020-09-19 03:12:39
53,381,744
16
2018-11-19 19:55:20
3,129,414
2020-09-19 03:12:39
https://stackoverflow.com/q/53380988
https://stackoverflow.com/a/53381744
<p>To show command output inside Python, there are two popular methods:</p> <ol> <li><code>check_output()</code>: It runs command with arguments and return its output. <a href="https://docs.python.org/3/library/subprocess.html#subprocess.check_output" rel="noreferrer">(official documentation)</a></li> <li><code>subproc...
<p>To show command output inside Python, there are two popular methods:</p> <ol> <li><code>check_output()</code>: It runs command with arguments and return its output. <a href="https://docs.python.org/3/library/subprocess.html#subprocess.check_output" rel="noreferrer">(official documentation)</a></li> <li><code>subproc...
16, 387, 390, 54712
bash, flask, python, shell
<h1>How to execute Shell Script from Flask App</h1> <p>I've created and deployed a Flask App with Apache2 server WSGI in which now would like to run a .sh script from the App. However, from calling from python code, it doesn't execute. </p> <p>Here is the test.sh:</p> <pre><code>#!/bin/bash echo "hi from shell scrip...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,813
bash
# How to execute Shell Script from Flask App I've created and deployed a Flask App with Apache2 server WSGI in which now would like to run a .sh script from the App. However, from calling from python code, it doesn't execute. Here is the test.sh: ``` #!/bin/bash echo "hi from shell script" ``` Here is my python fla...
To show command output inside Python, there are two popular methods: 1. `check_output()`: It runs command with arguments and return its output. [(official documentation)](https://docs.python.org/3/library/subprocess.html#subprocess.check_output) 2. `subprocess.communicate()`: Interact with process: Send data to stdin....
51178003
Run bash script with Django
11
2018-07-04 16:40:15
<p>I'm really new in django. I need to run a bash script when I push a button in html, and I need to do it with Django Framework, because I used it to build my web. I'd be grateful if anybody could help me </p> <p>Edit: I have added my template and my views for being more helpful. In the 'nuevaCancion' template, I use...
16,664
9,499,537
2024-06-10 05:19:05
51,178,308
16
2018-07-04 17:04:16
7,003,620
2019-07-09 06:04:24
https://stackoverflow.com/q/51178003
https://stackoverflow.com/a/51178308
<p>You can do this with empty <code>form</code>.</p> <p>In your template make a empty <code>form</code></p> <pre><code># index.html &lt;form action="{% url 'run_sh' %}" method="POST"&gt; {% csrf_token %} &lt;button type="submit"&gt;Call&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Add <code>url</code> for y...
<p>You can do this with empty <code>form</code>.</p> <p>In your template make a empty <code>form</code></p> <pre><code># index.html &lt;form action="{% url 'run_sh' %}" method="POST"&gt; {% csrf_token %} &lt;button type="submit"&gt;Call&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Add <code>url</code> for y...
2, 16, 243, 387, 390
bash, django, html, python, shell
<h1>Run bash script with Django</h1> <p>I'm really new in django. I need to run a bash script when I push a button in html, and I need to do it with Django Framework, because I used it to build my web. I'd be grateful if anybody could help me </p> <p>Edit: I have added my template and my views for being more helpful. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,814
bash
# Run bash script with Django I'm really new in django. I need to run a bash script when I push a button in html, and I need to do it with Django Framework, because I used it to build my web. I'd be grateful if anybody could help me Edit: I have added my template and my views for being more helpful. In the 'nuevaCanc...
You can do this with empty `form`. In your template make a empty `form` ``` # index.html <form action="{% url 'run_sh' %}" method="POST"> {% csrf_token %} <button type="submit">Call</button> </form> ``` Add `url` for your `form` ``` from django.conf.urls import url from . import views urlpatterns = [ ...
48424152
Compare System.Version in Powershell
11
2018-01-24 13:52:24
<p>I have a case where I have to make a decision in script based on comparing versions Consider this example: </p> <pre><code>PS C:\&gt; [version]$SomeVersion='1.1.1' [version]$OtherVersion='1.1.1.0' PS C:\&gt; $SomeVersion Major Minor Build Revision ----- ----- ----- -------- 1 1 1 -1 P...
31,193
5,917,637
2019-06-19 18:42:56
48,424,304
16
2018-01-24 14:00:48
696,808
2019-06-19 18:42:56
https://stackoverflow.com/q/48424152
https://stackoverflow.com/a/48424304
<p>Use the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.version.-ctor?view=netframework-4.0" rel="noreferrer">three argument <code>System.Version</code> constructor</a> to make new instances with the relevant properties:</p> <pre><code>[Version]::new($scriptversion.Major,$scriptversion.Minor,$scriptver...
<p>Use the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.version.-ctor?view=netframework-4.0" rel="noreferrer">three argument <code>System.Version</code> constructor</a> to make new instances with the relevant properties:</p> <pre><code>[Version]::new($scriptversion.Major,$scriptversion.Minor,$scriptver...
526
powershell
<h1>Compare System.Version in Powershell</h1> <p>I have a case where I have to make a decision in script based on comparing versions Consider this example: </p> <pre><code>PS C:\&gt; [version]$SomeVersion='1.1.1' [version]$OtherVersion='1.1.1.0' PS C:\&gt; $SomeVersion Major Minor Build Revision ----- ----- --...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,815
bash
# Compare System.Version in Powershell I have a case where I have to make a decision in script based on comparing versions Consider this example: ``` PS C:\> [version]$SomeVersion='1.1.1' [version]$OtherVersion='1.1.1.0' PS C:\> $SomeVersion Major Minor Build Revision ----- ----- ----- -------- 1 1 ...
Use the [three argument `System.Version` constructor](https://learn.microsoft.com/en-us/dotnet/api/system.version.-ctor?view=netframework-4.0) to make new instances with the relevant properties: ``` [Version]::new($scriptversion.Major,$scriptversion.Minor,$scriptversion.Build) -gt [Version]::new($currentVersion.Major,...
47891523
How do I git grep for a string including a ">"?
11
2017-12-19 16:45:53
<p><code>git grep</code> seems to have simpler rules than regular GNU <code>grep</code>, which will allow you to <a href="https://stackoverflow.com/q/4262150/209139">search for tabs</a> and to <a href="https://stackoverflow.com/q/11234858/209139">escape special characters with a backslash</a>. I am trying to find occur...
6,438
209,139
2022-11-01 15:17:51
47,891,554
16
2017-12-19 16:47:32
14,122
2017-12-19 16:57:53
https://stackoverflow.com/q/47891523
https://stackoverflow.com/a/47891554
<p>When doubt, use a single-character class rather than a backslash to make a single character literal inside a regex:</p> <pre><code>git grep -e '-[&gt;]upload' </code></pre> <p>Whereas the meaning of a backslash can be different depending on the specific character and the specific regex syntax in use, <code>[&gt;]<...
<p>When doubt, use a single-character class rather than a backslash to make a single character literal inside a regex:</p> <pre><code>git grep -e '-[&gt;]upload' </code></pre> <p>Whereas the meaning of a backslash can be different depending on the specific character and the specific regex syntax in use, <code>[&gt;]<...
119, 387
bash, git
<h1>How do I git grep for a string including a ">"?</h1> <p><code>git grep</code> seems to have simpler rules than regular GNU <code>grep</code>, which will allow you to <a href="https://stackoverflow.com/q/4262150/209139">search for tabs</a> and to <a href="https://stackoverflow.com/q/11234858/209139">escape special c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,816
bash
# How do I git grep for a string including a ">"? `git grep` seems to have simpler rules than regular GNU `grep`, which will allow you to [search for tabs](https://stackoverflow.com/q/4262150/209139) and to [escape special characters with a backslash](https://stackoverflow.com/q/11234858/209139). I am trying to find o...
When doubt, use a single-character class rather than a backslash to make a single character literal inside a regex: ``` git grep -e '-[>]upload' ``` Whereas the meaning of a backslash can be different depending on the specific character and the specific regex syntax in use, `[>]` means the same thing consistently. *...
47661909
Need a string with a $ in powershell inside ' '
11
2017-12-05 20:13:16
<p>I am trying to write a PS script to find a share named C$$ but PS is interpreting the $ sign and I want to pass it into the filter. Normally \ stops this but after googling I cant get a working solution. </p> <pre><code>$string = "Name='C\$\$'" Write-Host $string get-wmiobject -Class Win32_share -filter $string </c...
18,902
7,837,492
2017-12-05 20:56:10
47,661,943
16
2017-12-05 20:16:02
7,869,690
2017-12-05 20:16:02
https://stackoverflow.com/q/47661909
https://stackoverflow.com/a/47661943
<p>You can use the backtick to escape characters in a string.</p> <pre><code>$string = "Name='C`$`$'" </code></pre> <p>That should return <code>Name='C$$'</code></p>
<p>You can use the backtick to escape characters in a string.</p> <pre><code>$string = "Name='C`$`$'" </code></pre> <p>That should return <code>Name='C$$'</code></p>
526, 24067
powershell, powershell-2.0
<h1>Need a string with a $ in powershell inside ' '</h1> <p>I am trying to write a PS script to find a share named C$$ but PS is interpreting the $ sign and I want to pass it into the filter. Normally \ stops this but after googling I cant get a working solution. </p> <pre><code>$string = "Name='C\$\$'" Write-Host $st...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,817
bash
# Need a string with a $ in powershell inside ' ' I am trying to write a PS script to find a share named C$$ but PS is interpreting the $ sign and I want to pass it into the filter. Normally \ stops this but after googling I cant get a working solution. ``` $string = "Name='C\$\$'" Write-Host $string get-wmiobject -C...
You can use the backtick to escape characters in a string. ``` $string = "Name='C`$`$'" ``` That should return `Name='C$$'`
46034256
Bash: How to check if a zip file contain a specified path/file.ext?
11
2017-09-04 09:37:57
<p>I've to handle 46 .zip file according to their internal structure.</p> <p>The first usefull check to branch the elaboration is check if a specific file is presente in the .zip. </p> <p>Actually i'm unzipping and testing the existence of unzipped file. </p> <p><strong>But, I ask you, is there a way to check if a f...
17,942
1,055,279
2020-05-06 12:51:31
46,034,900
16
2017-09-04 10:15:44
8,536,377
2017-09-04 10:53:24
https://stackoverflow.com/q/46034256
https://stackoverflow.com/a/46034900
<p>To check for specific file, you can combine <code>unzip -l</code> with <code>grep</code> to search for that file. The command will look something like this</p> <pre><code>unzip -l archive.zip | grep -q name_of_file &amp;&amp; echo $? </code></pre> <p>What this does is it lists all files in <code>archive.zip</code>...
<p>To check for specific file, you can combine <code>unzip -l</code> with <code>grep</code> to search for that file. The command will look something like this</p> <pre><code>unzip -l archive.zip | grep -q name_of_file &amp;&amp; echo $? </code></pre> <p>What this does is it lists all files in <code>archive.zip</code>...
387, 7597
bash, unzip
<h1>Bash: How to check if a zip file contain a specified path/file.ext?</h1> <p>I've to handle 46 .zip file according to their internal structure.</p> <p>The first usefull check to branch the elaboration is check if a specific file is presente in the .zip. </p> <p>Actually i'm unzipping and testing the existence of u...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,818
bash
# Bash: How to check if a zip file contain a specified path/file.ext? I've to handle 46 .zip file according to their internal structure. The first usefull check to branch the elaboration is check if a specific file is presente in the .zip. Actually i'm unzipping and testing the existence of unzipped file. **But, I ...
To check for specific file, you can combine `unzip -l` with `grep` to search for that file. The command will look something like this ``` unzip -l archive.zip | grep -q name_of_file && echo $? ``` What this does is it lists all files in `archive.zip`, pipes them to `grep` which searches for `name_of_file`. `grep` exi...
45895071
How to use substitution in xargs?
11
2017-08-26 11:55:33
<p>What I want to do is </p> <ol> <li>find all file with <code>.txt</code> extension</li> <li>cp them to <code>.dat</code> file</li> </ol> <p>it could do like this:</p> <pre><code>for f in `find . -type f -name "*.txt"`; do cp $f ${f%.txt}.dat; done </code></pre> <p>I want to do this with xargs, I have tried this:<...
12,118
2,849,157
2022-02-16 15:24:00
45,895,212
16
2017-08-26 12:11:54
963,881
2022-02-16 15:24:00
https://stackoverflow.com/q/45895071
https://stackoverflow.com/a/45895212
<blockquote> <ol> <li>How to do the substitution rightly?</li> </ol> </blockquote> <p>You cannot use substitution in the way you are trying to do because <code>{}</code> is not a bash variable (only part of xargs syntax), therefore bash cannot do substitution on it.</p> <p>A better way to it would be to create a full b...
<blockquote> <ol> <li>How to do the substitution rightly?</li> </ol> </blockquote> <p>You cannot use substitution in the way you are trying to do because <code>{}</code> is not a bash variable (only part of xargs syntax), therefore bash cannot do substitution on it.</p> <p>A better way to it would be to create a full b...
390, 10326
shell, xargs
<h1>How to use substitution in xargs?</h1> <p>What I want to do is </p> <ol> <li>find all file with <code>.txt</code> extension</li> <li>cp them to <code>.dat</code> file</li> </ol> <p>it could do like this:</p> <pre><code>for f in `find . -type f -name "*.txt"`; do cp $f ${f%.txt}.dat; done </code></pre> <p>I want...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,819
bash
# How to use substitution in xargs? What I want to do is 1. find all file with `.txt` extension 2. cp them to `.dat` file it could do like this: ``` for f in `find . -type f -name "*.txt"`; do cp $f ${f%.txt}.dat; done ``` I want to do this with xargs, I have tried this: ``` find . -type f -name "*.txt" | xargs -...
> 1. How to do the substitution rightly? You cannot use substitution in the way you are trying to do because `{}` is not a bash variable (only part of xargs syntax), therefore bash cannot do substitution on it. A better way to it would be to create a full bash command and provide it as and argument to xargs (e.g. `xa...
43022687
Python subprocess argument with equal sign and space
11
2017-03-25 22:28:44
<p>I am trying to run a command with <code>subprocess.check_output</code> without using <code>shell=True</code> keyword argument. My command is this:</p> <pre><code>command --parameter="something with spaces" </code></pre> <p>With this:</p> <pre><code>subprocess.check_output(['command', '--parameter="something with ...
6,785
4,273,690
2020-02-12 18:28:15
43,022,755
16
2017-03-25 22:37:21
2,203,038
2017-03-25 22:37:21
https://stackoverflow.com/q/43022687
https://stackoverflow.com/a/43022755
<p>Here's what you need to know:</p> <p>Spaces are used for separating arguments on the shell command line. However, if you are not using shell, you don't need to escape spaces. Spaces can be escaped at least two ways ( that I know of ): With quotes ( either single or double ) and the backslash . </p> <p>When yo...
<p>Here's what you need to know:</p> <p>Spaces are used for separating arguments on the shell command line. However, if you are not using shell, you don't need to escape spaces. Spaces can be escaped at least two ways ( that I know of ): With quotes ( either single or double ) and the backslash . </p> <p>When yo...
16, 390, 2348
python, shell, subprocess
<h1>Python subprocess argument with equal sign and space</h1> <p>I am trying to run a command with <code>subprocess.check_output</code> without using <code>shell=True</code> keyword argument. My command is this:</p> <pre><code>command --parameter="something with spaces" </code></pre> <p>With this:</p> <pre><code>sub...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,820
bash
# Python subprocess argument with equal sign and space I am trying to run a command with `subprocess.check_output` without using `shell=True` keyword argument. My command is this: ``` command --parameter="something with spaces" ``` With this: ``` subprocess.check_output(['command', '--parameter="something with spac...
Here's what you need to know: Spaces are used for separating arguments on the shell command line. However, if you are not using shell, you don't need to escape spaces. Spaces can be escaped at least two ways ( that I know of ): With quotes ( either single or double ) and the backslash . When you pass an array to subp...
41966140
How can I make an array of lists (or similar) in bash?
11
2017-01-31 19:40:37
<p>I want to iterate over a few lists in bash. Right now I have</p> <pre><code>array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done </code></pre> <p>This doesn't work. Is there any way to make a list of lists, array of array...
20,026
4,208,228
2018-12-27 13:16:14
41,966,239
16
2017-01-31 19:46:16
1,566,221
2017-01-31 19:52:16
https://stackoverflow.com/q/41966140
https://stackoverflow.com/a/41966239
<p>Once I added the missing <code>do</code> and <code>done</code> into your code:</p> <pre><code>array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done </code></pre> <p>it produced the expected output:</p> <pre><code>list1ite...
<p>Once I added the missing <code>do</code> and <code>done</code> into your code:</p> <pre><code>array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done </code></pre> <p>it produced the expected output:</p> <pre><code>list1ite...
114, 387, 2314, 5608
arrays, bash, list, loops
<h1>How can I make an array of lists (or similar) in bash?</h1> <p>I want to iterate over a few lists in bash. Right now I have</p> <pre><code>array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done </code></pre> <p>This doesn'...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,821
bash
# How can I make an array of lists (or similar) in bash? I want to iterate over a few lists in bash. Right now I have ``` array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done ``` This doesn't work. Is there any way to make ...
Once I added the missing `do` and `done` into your code: ``` array=("list1item1 list1item2" "list2item list2item2") for list in "${array[@]}" do for item in $list do echo $item done done ``` it produced the expected output: ``` list1item1 list1item2 list2item list2item2 ``` It's not clear to me...
41014742
Where will be nohup file created/stored
11
2016-12-07 10:16:12
<p>On executing below given command within a script file:</p> <p>Command : </p> <pre><code>nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &amp; </code></pre> <p>Where will the nohup.out file be created, assuming that script is running in root directory ?</p>
36,425
3,817,656
2020-01-03 16:07:39
41,014,970
16
2016-12-07 10:26:43
6,518,219
2016-12-07 10:32:52
https://stackoverflow.com/q/41014742
https://stackoverflow.com/a/41014970
<p>Could you check home directory. </p> <p>also you can redirect as below;</p> <pre><code>nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &amp;&gt; /tmp/nohup.out </code></pre> <blockquote> <p>man nohup ; </p> <p>If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, ap...
<p>Could you check home directory. </p> <p>also you can redirect as below;</p> <pre><code>nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &amp;&gt; /tmp/nohup.out </code></pre> <blockquote> <p>man nohup ; </p> <p>If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, ap...
58, 390
linux, shell
<h1>Where will be nohup file created/stored</h1> <p>On executing below given command within a script file:</p> <p>Command : </p> <pre><code>nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &amp; </code></pre> <p>Where will the nohup.out file be created, assuming that script is running in root directory ?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,822
bash
# Where will be nohup file created/stored On executing below given command within a script file: Command : ``` nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh & ``` Where will the nohup.out file be created, assuming that script is running in root directory ?
Could you check home directory. also you can redirect as below; ``` nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &> /tmp/nohup.out ``` > man nohup ; > > If standard input is a terminal, redirect it from /dev/null. If > standard output is a terminal, append output to 'nohup.out' if > possible, '$HOME/nohup.out' other...
40968061
Bad : modifier in $ (/)
11
2016-12-05 06:07:42
<pre><code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/my/lib </code></pre> <p>error:</p> <pre><code>Bad : modifier in $ (/) </code></pre> <p>echo $SHELL</p> <pre><code>/bin/tcsh </code></pre> <p>I want to add my library to LD_LIBRARY_PATH variable. But Gives the above error.</p>
35,344
7,172,075
2016-12-05 09:24:41
40,968,165
16
2016-12-05 06:15:28
5,291,015
2016-12-05 09:24:41
https://stackoverflow.com/q/40968061
https://stackoverflow.com/a/40968165
<p>As <a href="https://stackoverflow.com/users/20862/ignacio-vazquez-abrams">Ignacio Vazquez-Abrams</a>, pointed out you need to <a href="http://www.tcsh.org/EnvironmentVariable" rel="noreferrer">set environment variable</a> in <code>tcsh</code> syntax as</p> <pre><code>setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:"/home...
<p>As <a href="https://stackoverflow.com/users/20862/ignacio-vazquez-abrams">Ignacio Vazquez-Abrams</a>, pointed out you need to <a href="http://www.tcsh.org/EnvironmentVariable" rel="noreferrer">set environment variable</a> in <code>tcsh</code> syntax as</p> <pre><code>setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:"/home...
390, 8599
shell, tcsh
<h1>Bad : modifier in $ (/)</h1> <pre><code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/my/lib </code></pre> <p>error:</p> <pre><code>Bad : modifier in $ (/) </code></pre> <p>echo $SHELL</p> <pre><code>/bin/tcsh </code></pre> <p>I want to add my library to LD_LIBRARY_PATH variable. But Gives the above error.</p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,823
bash
# Bad : modifier in $ (/) ``` export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/my/lib ``` error: ``` Bad : modifier in $ (/) ``` echo $SHELL ``` /bin/tcsh ``` I want to add my library to LD_LIBRARY_PATH variable. But Gives the above error.
As [Ignacio Vazquez-Abrams](https://stackoverflow.com/users/20862/ignacio-vazquez-abrams), pointed out you need to [set environment variable](http://www.tcsh.org/EnvironmentVariable) in `tcsh` syntax as ``` setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:"/home/my/lib" ```
37258673
Bash: loop through files that DO NOT match extension
11
2016-05-16 16:24:34
<p>I'm writing a bash script that needs to loop files inside a directory that do not match a specific extension. So far, I've found that the following code loops all files that matches the given extension:</p> <pre><code>for f in *.txt ; do echo $f; done </code></pre> <p>How could insthead loop through files that...
7,839
2,746,388
2016-05-17 07:40:30
37,258,868
16
2016-05-16 16:35:51
1,126,841
2016-05-16 16:41:02
https://stackoverflow.com/q/37258673
https://stackoverflow.com/a/37258868
<p>You can pattern-match with the <code>==</code> operator.</p> <pre><code>for f in *; do [[ $f == *.txt ]] &amp;&amp; continue # [[ $f != *.txt ]] || continue ... done </code></pre> <p>If this might run in an empty directory, either use <code>shopt -s nullglob</code> prior to the loop, or put <code>[ -e ...
<p>You can pattern-match with the <code>==</code> operator.</p> <pre><code>for f in *; do [[ $f == *.txt ]] &amp;&amp; continue # [[ $f != *.txt ]] || continue ... done </code></pre> <p>If this might run in an empty directory, either use <code>shopt -s nullglob</code> prior to the loop, or put <code>[ -e ...
18, 387, 2314, 5310
bash, file, loops, regex
<h1>Bash: loop through files that DO NOT match extension</h1> <p>I'm writing a bash script that needs to loop files inside a directory that do not match a specific extension. So far, I've found that the following code loops all files that matches the given extension:</p> <pre><code>for f in *.txt ; do echo $f; don...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,824
bash
# Bash: loop through files that DO NOT match extension I'm writing a bash script that needs to loop files inside a directory that do not match a specific extension. So far, I've found that the following code loops all files that matches the given extension: ``` for f in *.txt ; do echo $f; done ``` How could ins...
You can pattern-match with the `==` operator. ``` for f in *; do [[ $f == *.txt ]] && continue # [[ $f != *.txt ]] || continue ... done ``` If this might run in an empty directory, either use `shopt -s nullglob` prior to the loop, or put `[ -e "$f" ] || continue` in side the loop. (The former is preferabl...
35217413
In bash, should I unset a local variable inside a function?
11
2016-02-05 06:12:05
<p>Should I unset my local variables at the end of a function in a bash script? As an example, the following function:</p> <pre><code>square() { local var=$1 (( var = var * var )) echo $var ## should I unset $var here?? } </code></pre> <p>Just curious about best practices, thanks!</p>
5,406
5,813,245
2016-02-05 13:37:18
35,225,591
16
2016-02-05 13:37:18
1,126,841
2016-02-05 13:37:18
https://stackoverflow.com/q/35217413
https://stackoverflow.com/a/35225591
<p>If you weren't using the <code>local</code> command, then you would want to unset the variable before leaving the function to avoid polluting the global namespace.</p> <pre><code>square () { var=$1 # var is global, and could be used after square returns (( var = var * var )) echo $var unset var ...
<p>If you weren't using the <code>local</code> command, then you would want to unset the variable before leaving the function to avoid polluting the global namespace.</p> <pre><code>square () { var=$1 # var is global, and could be used after square returns (( var = var * var )) echo $var unset var ...
34, 58, 387
bash, linux, unix
<h1>In bash, should I unset a local variable inside a function?</h1> <p>Should I unset my local variables at the end of a function in a bash script? As an example, the following function:</p> <pre><code>square() { local var=$1 (( var = var * var )) echo $var ## should I unset $var here?? } </code></pre> <p>J...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,825
bash
# In bash, should I unset a local variable inside a function? Should I unset my local variables at the end of a function in a bash script? As an example, the following function: ``` square() { local var=$1 (( var = var * var )) echo $var ## should I unset $var here?? } ``` Just curious about best practices, ...
If you weren't using the `local` command, then you would want to unset the variable before leaving the function to avoid polluting the global namespace. ``` square () { var=$1 # var is global, and could be used after square returns (( var = var * var )) echo $var unset var # Remove it from the glob...
33570391
How to see all Request URLs the server is doing (final URLs)
11
2015-11-06 15:40:50
<p>How list from the command line URLs requests that are made from the server (an *ux machine) to another machine.</p> <p>For instance, I am on the command line of server <strong>ALPHA_RE</strong> . I do a ping to google.co.uk and another ping to bbc.co.uk I would like to see, from the prompt :</p> <p>google.co.uk bb...
27,954
278,739
2015-11-15 19:19:34
33,615,540
16
2015-11-09 18:16:26
5,462,012
2015-11-15 19:19:34
https://stackoverflow.com/q/33570391
https://stackoverflow.com/a/33615540
<p>You can use <em>tcpdump</em> and <em>grep</em> to get info about activity about network traffic from the host, the following cmd line should get you all lines containing Host:</p> <pre><code> tcpdump -i any -A -vv -s 0 | grep -e "Host:" </code></pre> <p>If I run the above in one shell and start a Links session to...
<p>You can use <em>tcpdump</em> and <em>grep</em> to get info about activity about network traffic from the host, the following cmd line should get you all lines containing Host:</p> <pre><code> tcpdump -i any -A -vv -s 0 | grep -e "Host:" </code></pre> <p>If I run the above in one shell and start a Links session to...
58, 387, 1231, 5210, 12611
bash, command-line, http, linux, tcpdump
<h1>How to see all Request URLs the server is doing (final URLs)</h1> <p>How list from the command line URLs requests that are made from the server (an *ux machine) to another machine.</p> <p>For instance, I am on the command line of server <strong>ALPHA_RE</strong> . I do a ping to google.co.uk and another ping to bb...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,826
bash
# How to see all Request URLs the server is doing (final URLs) How list from the command line URLs requests that are made from the server (an *ux machine) to another machine. For instance, I am on the command line of server **ALPHA_RE** . I do a ping to google.co.uk and another ping to bbc.co.uk I would like to see, ...
You can use *tcpdump* and *grep* to get info about activity about network traffic from the host, the following cmd line should get you all lines containing Host: ``` tcpdump -i any -A -vv -s 0 | grep -e "Host:" ``` If I run the above in one shell and start a Links session to stackoverflow I see: ``` Host: www.stac...
33021473
PowerShell to extract specific column from csv and store in a variable
11
2015-10-08 16:41:09
<p>My keys.csv file looks like this</p> <pre><code> PrjKey BldKey key LS LOOKUPSNAP1 LS-LOOKUPSNAP1 LS LSUH3 LS-LSUH3 LSPERF LPMDS0 LSPERF-LPMDS0 LSPERF LSP0 LSPERF-LSP0 </code></pre> <p>I want to extract the values column "key" and store in a variable. I tried this</p> <pre><code>...
115,959
4,438,637
2017-09-14 16:58:03
33,022,326
16
2015-10-08 17:27:30
3,829,407
2017-09-14 16:58:03
https://stackoverflow.com/q/33021473
https://stackoverflow.com/a/33022326
<p>You had the right idea of using <code>Select-Object</code> to get the one property you want. The two issues you had was that <code>Select-Object key</code> returns and object array with a key property when it looks like you just want string array of keys. Also <strong>never</strong> use <code>Format-cmdlets</code> w...
<p>You had the right idea of using <code>Select-Object</code> to get the one property you want. The two issues you had was that <code>Select-Object key</code> returns and object array with a key property when it looks like you just want string array of keys. Also <strong>never</strong> use <code>Format-cmdlets</code> w...
526
powershell
<h1>PowerShell to extract specific column from csv and store in a variable</h1> <p>My keys.csv file looks like this</p> <pre><code> PrjKey BldKey key LS LOOKUPSNAP1 LS-LOOKUPSNAP1 LS LSUH3 LS-LSUH3 LSPERF LPMDS0 LSPERF-LPMDS0 LSPERF LSP0 LSPERF-LSP0 </code></pre> <p>I want to extrac...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,827
bash
# PowerShell to extract specific column from csv and store in a variable My keys.csv file looks like this ``` PrjKey BldKey key LS LOOKUPSNAP1 LS-LOOKUPSNAP1 LS LSUH3 LS-LSUH3 LSPERF LPMDS0 LSPERF-LPMDS0 LSPERF LSP0 LSPERF-LSP0 ``` I want to extract the values column "key" and sto...
You had the right idea of using `Select-Object` to get the one property you want. The two issues you had was that `Select-Object key` returns and object array with a key property when it looks like you just want string array of keys. Also **never** use `Format-cmdlets` when you want to save the data or use it in anothe...
32513203
pipes and foreach loops
11
2015-09-10 23:32:32
<p>Recently, I've been playing with PowerShell, and I've noticed some weird behavior when using pipes and <code>foreach</code> loops that I couldn't understand.</p> <p>This simple code works:</p> <pre><code>$x = foreach ($i in gci){$i.length} $x | measure -max </code></pre> <p>Makes sense.</p> <p>But this code won'...
14,013
3,232,836
2015-09-11 09:30:58
32,520,164
16
2015-09-11 09:30:58
1,630,171
2015-09-11 09:30:58
https://stackoverflow.com/q/32513203
https://stackoverflow.com/a/32520164
<p>The <code>foreach</code> statement doesn't use the pipeline architecture, so its output cannot be passed to a pipeline directly (i.e. item by item). To be able to pass output from a <code>foreach</code> loop to a pipeline you must run the loop in a subexpression:</p> <pre><code>$(foreach ($item in Get-ChildItem) { ...
<p>The <code>foreach</code> statement doesn't use the pipeline architecture, so its output cannot be passed to a pipeline directly (i.e. item by item). To be able to pass output from a <code>foreach</code> loop to a pipeline you must run the loop in a subexpression:</p> <pre><code>$(foreach ($item in Get-ChildItem) { ...
526, 24067
powershell, powershell-2.0
<h1>pipes and foreach loops</h1> <p>Recently, I've been playing with PowerShell, and I've noticed some weird behavior when using pipes and <code>foreach</code> loops that I couldn't understand.</p> <p>This simple code works:</p> <pre><code>$x = foreach ($i in gci){$i.length} $x | measure -max </code></pre> <p>Makes ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,828
bash
# pipes and foreach loops Recently, I've been playing with PowerShell, and I've noticed some weird behavior when using pipes and `foreach` loops that I couldn't understand. This simple code works: ``` $x = foreach ($i in gci){$i.length} $x | measure -max ``` Makes sense. But this code won't: ``` foreach ($i in gc...
The `foreach` statement doesn't use the pipeline architecture, so its output cannot be passed to a pipeline directly (i.e. item by item). To be able to pass output from a `foreach` loop to a pipeline you must run the loop in a subexpression: ``` $(foreach ($item in Get-ChildItem) { $item.Length }) | ... ``` or collec...
31132936
How to test if a string contains one of multiple substrings?
11
2015-06-30 08:11:23
<p>I wish to know if a string contains one of <code>abc</code>, <code>def</code>, <code>xyz</code>, etc. I could do it like:</p> <pre><code>$a.Contains("abc") -or $a.Contains("def") -or $a.Contains("xyz") </code></pre> <p>Well it works, but I have to change code if this substring list changes, and the performance is ...
41,124
4,927,124
2015-06-30 09:15:04
31,133,109
16
2015-06-30 08:20:31
1,163,423
2015-06-30 08:20:31
https://stackoverflow.com/q/31132936
https://stackoverflow.com/a/31133109
<p>You could use the -match method and create the regex automatically using string.join: </p> <pre class="lang-powershell prettyprint-override"><code>$referenz = @('abc', 'def', 'xyz') $referenzRegex = [string]::Join('|', $referenz) # create the regex </code></pre> <p>Usage:</p> <pre class="lang-powershell prett...
<p>You could use the -match method and create the regex automatically using string.join: </p> <pre class="lang-powershell prettyprint-override"><code>$referenz = @('abc', 'def', 'xyz') $referenzRegex = [string]::Join('|', $referenz) # create the regex </code></pre> <p>Usage:</p> <pre class="lang-powershell prett...
139, 526, 2936
compare, powershell, string
<h1>How to test if a string contains one of multiple substrings?</h1> <p>I wish to know if a string contains one of <code>abc</code>, <code>def</code>, <code>xyz</code>, etc. I could do it like:</p> <pre><code>$a.Contains("abc") -or $a.Contains("def") -or $a.Contains("xyz") </code></pre> <p>Well it works, but I have ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,829
bash
# How to test if a string contains one of multiple substrings? I wish to know if a string contains one of `abc`, `def`, `xyz`, etc. I could do it like: ``` $a.Contains("abc") -or $a.Contains("def") -or $a.Contains("xyz") ``` Well it works, but I have to change code if this substring list changes, and the performance...
You could use the -match method and create the regex automatically using string.join: ``` $referenz = @('abc', 'def', 'xyz') $referenzRegex = [string]::Join('|', $referenz) # create the regex ``` Usage: ``` "any string containing abc" -match $referenzRegex # true "any non matching string" -match $referenzRegex #...
31004140
How do I silence the HEAD of a curl request while using the silent flag?
11
2015-06-23 13:29:14
<p>When I run the curl command and direct the data to a file, I get back the content of the site as expected.</p> <pre><code>$ curl "www.site.com" &gt; file.txt $ head file.txt Top of site ... </code></pre> <p>However, this command shows a progress bar, which I do not want: </p> <pre><code> % Total % Received %...
13,998
908,939
2020-08-25 06:45:52
31,004,282
16
2015-06-23 13:35:05
2,146,346
2019-08-25 18:23:38
https://stackoverflow.com/q/31004140
https://stackoverflow.com/a/31004282
<p>Try this:</p> <pre><code>curl --silent "www.site.com" &gt; file.txt </code></pre> <p>If you wish, you can use the shorthand <code>-s</code>.</p>
<p>Try this:</p> <pre><code>curl --silent "www.site.com" &gt; file.txt </code></pre> <p>If you wish, you can use the shorthand <code>-s</code>.</p>
387, 390, 1231, 1554, 5813
bash, command-line, curl, pipe, shell
<h1>How do I silence the HEAD of a curl request while using the silent flag?</h1> <p>When I run the curl command and direct the data to a file, I get back the content of the site as expected.</p> <pre><code>$ curl "www.site.com" &gt; file.txt $ head file.txt Top of site ... </code></pre> <p>However, this command show...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,830
bash
# How do I silence the HEAD of a curl request while using the silent flag? When I run the curl command and direct the data to a file, I get back the content of the site as expected. ``` $ curl "www.site.com" > file.txt $ head file.txt Top of site ... ``` However, this command shows a progress bar, which I do not wan...
Try this: ``` curl --silent "www.site.com" > file.txt ``` If you wish, you can use the shorthand `-s`.
28723720
Terminal cursor disappears when using Rails server and pry/byebug together
11
2015-02-25 16:02:43
<p>If I trigger <code>pry</code> or <code>byebug</code>, eventually while using the live-debug mode the cursor will disappear, and input will become slow/laggy. Ultimately I have to <code>Ctrl-C</code> and kill the unicorn/puma process. After I've quit the process the terminal works, but the cursor is sometimes still m...
2,003
1,712,406
2015-02-26 03:01:35
28,723,862
16
2015-02-25 16:09:22
3,920,143
2015-02-25 16:09:22
https://stackoverflow.com/q/28723720
https://stackoverflow.com/a/28723862
<p>When the cursor disappears you can enter the command <code>stty echo</code> and hit enter. That should bring the cursor back. </p>
<p>When the cursor disappears you can enter the command <code>stty echo</code> and hit enter. That should bring the cursor back. </p>
387, 4984, 72417, 85786
bash, pry, ruby-on-rails, ruby-on-rails-4
<h1>Terminal cursor disappears when using Rails server and pry/byebug together</h1> <p>If I trigger <code>pry</code> or <code>byebug</code>, eventually while using the live-debug mode the cursor will disappear, and input will become slow/laggy. Ultimately I have to <code>Ctrl-C</code> and kill the unicorn/puma process....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,831
bash
# Terminal cursor disappears when using Rails server and pry/byebug together If I trigger `pry` or `byebug`, eventually while using the live-debug mode the cursor will disappear, and input will become slow/laggy. Ultimately I have to `Ctrl-C` and kill the unicorn/puma process. After I've quit the process the terminal ...
When the cursor disappears you can enter the command `stty echo` and hit enter. That should bring the cursor back.
28504839
how to delete a file with quote in file name
11
2015-02-13 17:03:24
<p>When I do <code>ls</code> in my directory, get bunch of these:</p> <pre><code>data.log&quot;.2015-01-22&quot; data.log&quot;.2015-01-23&quot; </code></pre> <p>However when I do this:</p> <pre><code>rm: cannot remove `data.log.2015-01-22': No such file or directory </code></pre> <p>If I could somehow do something lin...
12,226
3,616,806
2021-12-11 08:26:26
28,527,909
16
2015-02-15 15:51:05
648,658
2021-01-10 09:35:10
https://stackoverflow.com/q/28504839
https://stackoverflow.com/a/28527909
<p>If you only need to do this once in a while interactively, use</p> <pre><code>rm -i -- * </code></pre> <p>and answer <code>y</code> or <code>n</code> as appropriate. This can be used to get rid of many files having funny characters in their name.</p> <p>It has the advantage of not needing to type/escape funny charac...
<p>If you only need to do this once in a while interactively, use</p> <pre><code>rm -i -- * </code></pre> <p>and answer <code>y</code> or <code>n</code> as appropriate. This can be used to get rid of many files having funny characters in their name.</p> <p>It has the advantage of not needing to type/escape funny charac...
387, 390
bash, shell
<h1>how to delete a file with quote in file name</h1> <p>When I do <code>ls</code> in my directory, get bunch of these:</p> <pre><code>data.log&quot;.2015-01-22&quot; data.log&quot;.2015-01-23&quot; </code></pre> <p>However when I do this:</p> <pre><code>rm: cannot remove `data.log.2015-01-22': No such file or director...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,832
bash
# how to delete a file with quote in file name When I do `ls` in my directory, get bunch of these: ``` data.log".2015-01-22" data.log".2015-01-23" ``` However when I do this: ``` rm: cannot remove `data.log.2015-01-22': No such file or directory ``` If I could somehow do something line `ls | escape quotes | xargs ...
If you only need to do this once in a while interactively, use ``` rm -i -- * ``` and answer `y` or `n` as appropriate. This can be used to get rid of many files having funny characters in their name. It has the advantage of not needing to type/escape funny characters, blanks, etc, since the shell globbing with `*` ...
27443368
Azure Websites Kudu REST API - Authentication
11
2014-12-12 12:08:14
<p>I'm trying to use PowerShell to put an updated content file onto an Azure Website via the REST API. However, when supplying my credentials into <code>Invoke-RestMethod -Credentials</code> I am returned the HTML of the standard Azure login page.</p> <p>How can I authenticate with Kudu from PowerShell? Thanks.</p>
5,780
107,783
2015-12-30 00:48:27
27,664,329
16
2014-12-27 04:29:44
1,081,786
2014-12-27 04:29:44
https://stackoverflow.com/q/27443368
https://stackoverflow.com/a/27664329
<p>You can first get the website via Powershell and then use the publish credentials from the website to call the Kudu REST API. The example below will get the Kudu version.</p> <pre><code>$website = Get-AzureWebsite -Name "WebsiteName" $username = $website.PublishingUsername $password = $website.PublishingPassword ...
<p>You can first get the website via Powershell and then use the publish credentials from the website to call the Kudu REST API. The example below will get the Kudu version.</p> <pre><code>$website = Get-AzureWebsite -Name "WebsiteName" $username = $website.PublishingUsername $password = $website.PublishingPassword ...
364, 526, 81099, 116275
azure-web-app-service, kudu, powershell, rest
<h1>Azure Websites Kudu REST API - Authentication</h1> <p>I'm trying to use PowerShell to put an updated content file onto an Azure Website via the REST API. However, when supplying my credentials into <code>Invoke-RestMethod -Credentials</code> I am returned the HTML of the standard Azure login page.</p> <p>How can I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,833
bash
# Azure Websites Kudu REST API - Authentication I'm trying to use PowerShell to put an updated content file onto an Azure Website via the REST API. However, when supplying my credentials into `Invoke-RestMethod -Credentials` I am returned the HTML of the standard Azure login page. How can I authenticate with Kudu fro...
You can first get the website via Powershell and then use the publish credentials from the website to call the Kudu REST API. The example below will get the Kudu version. ``` $website = Get-AzureWebsite -Name "WebsiteName" $username = $website.PublishingUsername $password = $website.PublishingPassword $base64AuthInfo...
25094004
Extended POSIX utilities using command find on Mac OS X?
11
2014-08-02 10:23:44
<p>I try to do this command on my Mac OS X 10.9 Terminal:</p> <pre><code>find / -type f -regextype posix-extended -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \; </code></pre> <p>But the Bash v 3.2 response is:</p> <pre><code>find: -regextype: unknown primary or operator </code></pre> <p>I have made a de...
4,001
3,901,849
2014-11-22 23:13:45
27,083,611
16
2014-11-22 23:13:45
2,171,044
2014-11-22 23:13:45
https://stackoverflow.com/q/25094004
https://stackoverflow.com/a/27083611
<p>The simplest answer to your question is that on OS X you need to use the <code>-E</code> option instead of <code>-regextype posix-extended</code></p> <p>ie:</p> <blockquote> <p>find / -type f <strong>-regextype posix-extended</strong> -regex "(.*A.<em>a.</em>.*)|(.*a.<em>A.</em>.*)" -exec tail -n 3 '{}' \;</p> <...
<p>The simplest answer to your question is that on OS X you need to use the <code>-E</code> option instead of <code>-regextype posix-extended</code></p> <p>ie:</p> <blockquote> <p>find / -type f <strong>-regextype posix-extended</strong> -regex "(.*A.<em>a.</em>.*)|(.*a.<em>A.</em>.*)" -exec tail -n 3 '{}' \;</p> <...
18, 369, 387, 391, 10193
bash, find, macos, regex, terminal
<h1>Extended POSIX utilities using command find on Mac OS X?</h1> <p>I try to do this command on my Mac OS X 10.9 Terminal:</p> <pre><code>find / -type f -regextype posix-extended -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \; </code></pre> <p>But the Bash v 3.2 response is:</p> <pre><code>find: -regexty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,834
bash
# Extended POSIX utilities using command find on Mac OS X? I try to do this command on my Mac OS X 10.9 Terminal: ``` find / -type f -regextype posix-extended -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \; ``` But the Bash v 3.2 response is: ``` find: -regextype: unknown primary or operator ``` I have ...
The simplest answer to your question is that on OS X you need to use the `-E` option instead of `-regextype posix-extended` ie: > find / -type f **-regextype posix-extended** -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \; becomes: > find **-E** / -type f -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n ...
26041934
How does CVE-2014-7169 work? Breakdown of the test code
11
2014-09-25 15:06:14
<p>With a bash release which has been patched for shellshock</p> <pre><code>$ bash --version GNU bash, version 3.2.52(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc. $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" bash: warning: x: ignoring function definition at...
2,039
2,891,365
2014-09-30 00:47:31
26,111,063
16
2014-09-30 00:47:31
371,250
2014-09-30 00:47:31
https://stackoverflow.com/q/26041934
https://stackoverflow.com/a/26111063
<h2>The bug</h2> <p>CVE-2014-7169 is a bug in bash's parser. Bash's parser uses a variable <code>eol_ungetc_lookahead</code> to ungetc characters across lines. That variable wasn't being properly reset from the <code>reset_parser</code> function, which is called e.g. on some syntax errors. Using that bug, it's possibl...
<h2>The bug</h2> <p>CVE-2014-7169 is a bug in bash's parser. Bash's parser uses a variable <code>eol_ungetc_lookahead</code> to ungetc characters across lines. That variable wasn't being properly reset from the <code>reset_parser</code> function, which is called e.g. on some syntax errors. Using that bug, it's possibl...
387, 2172, 107178
bash, exploit, shellshock-bash-bug
<h1>How does CVE-2014-7169 work? Breakdown of the test code</h1> <p>With a bash release which has been patched for shellshock</p> <pre><code>$ bash --version GNU bash, version 3.2.52(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc. $ env x='() { :;}; echo vulnerable' bash -c "echo ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,835
bash
# How does CVE-2014-7169 work? Breakdown of the test code With a bash release which has been patched for shellshock ``` $ bash --version GNU bash, version 3.2.52(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc. $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" bash...
## The bug CVE-2014-7169 is a bug in bash's parser. Bash's parser uses a variable `eol_ungetc_lookahead` to ungetc characters across lines. That variable wasn't being properly reset from the `reset_parser` function, which is called e.g. on some syntax errors. Using that bug, it's possible to inject a character into th...
26045893
Powershell here-string expansion
11
2014-09-25 18:46:23
<p><strong>Here-strings</strong></p> <p>There are some examples regarding Powershell 'here-string' but I have hardly come across 'here-string' expansion. so I posted this to be of some help.<br><br> When you want to add some literal with line breaks, both single and double quotes do not need to be escaped and no need ...
24,579
554,060
2015-10-31 17:47:38
26,045,894
16
2014-09-25 18:46:23
554,060
2014-09-25 23:25:29
https://stackoverflow.com/q/26045893
https://stackoverflow.com/a/26045894
<p>Here is how to introduce CmdLet and a date variable to show current date like so: <br>For example the following is what we want to achieve:</p> <pre><code>Hello world! 09/25/2014 11:39:56 '(this will appear as is)' ! </code></pre> <p>Here is how:</p> <pre><code>@" Hello world! $(Get-Date) '(this will appear as is...
<p>Here is how to introduce CmdLet and a date variable to show current date like so: <br>For example the following is what we want to achieve:</p> <pre><code>Hello world! 09/25/2014 11:39:56 '(this will appear as is)' ! </code></pre> <p>Here is how:</p> <pre><code>@" Hello world! $(Get-Date) '(this will appear as is...
526, 73157
powershell, powershell-3.0
<h1>Powershell here-string expansion</h1> <p><strong>Here-strings</strong></p> <p>There are some examples regarding Powershell 'here-string' but I have hardly come across 'here-string' expansion. so I posted this to be of some help.<br><br> When you want to add some literal with line breaks, both single and double quo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,836
bash
# Powershell here-string expansion **Here-strings** There are some examples regarding Powershell 'here-string' but I have hardly come across 'here-string' expansion. so I posted this to be of some help. When you want to add some literal with line breaks, both single and double quotes do not need to be escaped an...
Here is how to introduce CmdLet and a date variable to show current date like so: For example the following is what we want to achieve: ``` Hello world! 09/25/2014 11:39:56 '(this will appear as is)' ! ``` Here is how: ``` @" Hello world! $(Get-Date) '(this will appear as is)' ! "@ ``` Or with variable: ``` $my...
23445175
qwinsta /server:somesrv equivalent in Powershell?
11
2014-05-03 13:38:48
<p>When I run the <code>qwinsta /server:somesrv</code> command in <code>cmd</code> I can get a listing of all the current RDP sessions that are logged into a particular Windows server. </p> <pre><code> SESSIONNAME USERNAME ID STATE TYPE DEVICE console ...
26,271
18,149
2024-09-26 00:08:07
23,454,741
16
2014-05-04 09:42:24
702,944
2023-02-25 19:15:34
https://stackoverflow.com/q/23445175
https://stackoverflow.com/a/23454741
<p>There are multiple alternatives:</p> <ul> <li>Use the <a href="https://www.powershellgallery.com/packages/PSTerminalServices/1.0" rel="nofollow noreferrer">Terminal Services PowerShell Module</a>. <em>Easy solution</em>.</li> <li>Writing a powershell wrapper that parses the output of <code>qwinsta</code> to objects....
<p>There are multiple alternatives:</p> <ul> <li>Use the <a href="https://www.powershellgallery.com/packages/PSTerminalServices/1.0" rel="nofollow noreferrer">Terminal Services PowerShell Module</a>. <em>Easy solution</em>.</li> <li>Writing a powershell wrapper that parses the output of <code>qwinsta</code> to objects....
526, 3356
powershell, remote-desktop
<h1>qwinsta /server:somesrv equivalent in Powershell?</h1> <p>When I run the <code>qwinsta /server:somesrv</code> command in <code>cmd</code> I can get a listing of all the current RDP sessions that are logged into a particular Windows server. </p> <pre><code> SESSIONNAME USERNAME ID STATE TY...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,837
bash
# qwinsta /server:somesrv equivalent in Powershell? When I run the `qwinsta /server:somesrv` command in `cmd` I can get a listing of all the current RDP sessions that are logged into a particular Windows server. ``` SESSIONNAME USERNAME ID STATE TYPE DEVICE console ...
There are multiple alternatives: - Use the [Terminal Services PowerShell Module](https://www.powershellgallery.com/packages/PSTerminalServices/1.0). *Easy solution*. - Writing a powershell wrapper that parses the output of `qwinsta` to objects. *Easy solution. See example below* - Use the `Cassia.DLL` .Net wrapper to ...
20554032
bash tail on a live log file, counting uniq lines with same date/time
11
2013-12-12 20:54:08
<p>I'm looking for a good way to tail on a live log file, and display number of lines with the same date/time.</p> <p>Currently this is working:</p> <pre><code> tail -F /var/logs/request.log | [cut the date-time] | uniq -c </code></pre> <p>BUT the performance is not good enough. There is a delay of more than one min...
19,798
1,424,321
2015-03-28 22:16:21
20,558,267
16
2013-12-13 02:49:30
1,967,396
2013-12-13 02:49:30
https://stackoverflow.com/q/20554032
https://stackoverflow.com/a/20558267
<p>Your problem is most likely related to buffering in your system, not anything intrinsically wrong with your line of code. I was able to create a test scenario where I could reproduce it - then make it go away. I hope it will work for you too.</p> <p>Here is my test scenario. First I write a short script that writes...
<p>Your problem is most likely related to buffering in your system, not anything intrinsically wrong with your line of code. I was able to create a test scenario where I could reproduce it - then make it go away. I hope it will work for you too.</p> <p>Here is my test scenario. First I write a short script that writes...
387, 942, 7896, 35617
bash, logging, tail, uniq
<h1>bash tail on a live log file, counting uniq lines with same date/time</h1> <p>I'm looking for a good way to tail on a live log file, and display number of lines with the same date/time.</p> <p>Currently this is working:</p> <pre><code> tail -F /var/logs/request.log | [cut the date-time] | uniq -c </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,838
bash
# bash tail on a live log file, counting uniq lines with same date/time I'm looking for a good way to tail on a live log file, and display number of lines with the same date/time. Currently this is working: ``` tail -F /var/logs/request.log | [cut the date-time] | uniq -c ``` BUT the performance is not good enough...
Your problem is most likely related to buffering in your system, not anything intrinsically wrong with your line of code. I was able to create a test scenario where I could reproduce it - then make it go away. I hope it will work for you too. Here is my test scenario. First I write a short script that writes the time ...
18277308
Invoke remote powershell command from C#
11
2013-08-16 15:45:47
<p>I'm trying to run an invoke-command cmdlet using C# but I can't figure out the right syntax. I just want to run this simple command:</p> <pre><code>invoke-command -ComputerName mycomp.mylab.com -ScriptBlock {"get-childitem C:\windows"} </code></pre> <p>In C# code, I have done the following:</p> <pre><code>Initial...
13,693
819,415
2017-08-11 15:11:14
18,277,368
16
2013-08-16 15:49:27
819,415
2013-08-16 15:49:27
https://stackoverflow.com/q/18277308
https://stackoverflow.com/a/18277368
<p>Ah, the parameter to ScriptBlock itself needs to be of type ScriptBlock.</p> <p>full code:</p> <pre><code>InitialSessionState initial = InitialSessionState.CreateDefault(); Runspace runspace = RunspaceFactory.CreateRunspace(initial); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; ps....
<p>Ah, the parameter to ScriptBlock itself needs to be of type ScriptBlock.</p> <p>full code:</p> <pre><code>InitialSessionState initial = InitialSessionState.CreateDefault(); Runspace runspace = RunspaceFactory.CreateRunspace(initial); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; ps....
1, 9, 526
.net, c#, powershell
<h1>Invoke remote powershell command from C#</h1> <p>I'm trying to run an invoke-command cmdlet using C# but I can't figure out the right syntax. I just want to run this simple command:</p> <pre><code>invoke-command -ComputerName mycomp.mylab.com -ScriptBlock {"get-childitem C:\windows"} </code></pre> <p>In C# code, ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,839
bash
# Invoke remote powershell command from C# I'm trying to run an invoke-command cmdlet using C# but I can't figure out the right syntax. I just want to run this simple command: ``` invoke-command -ComputerName mycomp.mylab.com -ScriptBlock {"get-childitem C:\windows"} ``` In C# code, I have done the following: ``` I...
Ah, the parameter to ScriptBlock itself needs to be of type ScriptBlock. full code: ``` InitialSessionState initial = InitialSessionState.CreateDefault(); Runspace runspace = RunspaceFactory.CreateRunspace(initial); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; ps.AddCommand("invoke-co...
17723790
How to get first character of variable
11
2013-07-18 12:43:12
<p>I'm trying to get the first character of a variable, but I'm getting a Bad substitution error. Can anyone help me fix it?</p> <p>code is:</p> <pre><code>while IFS=$'\n' read line do if [ ! ${line:0:1} == "#"] # Error on this line then eval echo "$line" eval createSymlink $line fi done &lt; /some/fil...
18,433
264,276
2018-02-09 16:58:07
17,723,820
16
2013-07-18 12:44:54
1,983,854
2016-08-18 09:24:47
https://stackoverflow.com/q/17723790
https://stackoverflow.com/a/17723820
<p>To get the first character of a variable you need to say:</p> <pre><code>v="hello" $ echo "${v:0:1}" h </code></pre> <p>However, your code has a syntax error:</p> <pre><code>[ ! ${line:0:1} == "#"] # ^-- missing space </code></pre> <p>So this can do the trick:</p> <pre><code>$ a="123456" $ [...
<p>To get the first character of a variable you need to say:</p> <pre><code>v="hello" $ echo "${v:0:1}" h </code></pre> <p>However, your code has a syntax error:</p> <pre><code>[ ! ${line:0:1} == "#"] # ^-- missing space </code></pre> <p>So this can do the trick:</p> <pre><code>$ a="123456" $ [...
387
bash
<h1>How to get first character of variable</h1> <p>I'm trying to get the first character of a variable, but I'm getting a Bad substitution error. Can anyone help me fix it?</p> <p>code is:</p> <pre><code>while IFS=$'\n' read line do if [ ! ${line:0:1} == "#"] # Error on this line then eval echo "$line" e...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,840
bash
# How to get first character of variable I'm trying to get the first character of a variable, but I'm getting a Bad substitution error. Can anyone help me fix it? code is: ``` while IFS=$'\n' read line do if [ ! ${line:0:1} == "#"] # Error on this line then eval echo "$line" eval createSymlink $line fi...
To get the first character of a variable you need to say: ``` v="hello" $ echo "${v:0:1}" h ``` However, your code has a syntax error: ``` [ ! ${line:0:1} == "#"] # ^-- missing space ``` So this can do the trick: ``` $ a="123456" $ [ ! "${a:0:1}" == "#" ] && echo "doesnt start with #" doesnt st...
15777232
how can I echo/print specific lines from a bash variable
11
2013-04-03 01:13:23
<p>I am trying to print specific lines from a multi-line bash variable. I've found the following:</p> <pre><code>while read line; do echo LINE: "$line"; done &lt;&lt;&lt; "$x" </code></pre> <p>where x would be the variable, but that simply prints out all lines instead of just a single one (say line 1 for instance). H...
27,511
1,161,841
2013-04-03 01:46:28
15,777,243
16
2013-04-03 01:14:38
140,750
2013-04-03 01:30:00
https://stackoverflow.com/q/15777232
https://stackoverflow.com/a/15777243
<p>To print the Nth line: </p> <pre><code>sed -n ${N}p &lt;&lt;&lt; "$x" </code></pre> <p>or (more portably):</p> <pre><code>sed -n ${N}p &lt;&lt; EOF $x EOF </code></pre> <p>or</p> <pre><code>echo "$x" | sed -n "$N"p </code></pre> <p>or</p> <pre><code>echo "$x" | sed -n ${N}p </code></pre> <p>or (for the spe...
<p>To print the Nth line: </p> <pre><code>sed -n ${N}p &lt;&lt;&lt; "$x" </code></pre> <p>or (more portably):</p> <pre><code>sed -n ${N}p &lt;&lt; EOF $x EOF </code></pre> <p>or</p> <pre><code>echo "$x" | sed -n "$N"p </code></pre> <p>or</p> <pre><code>echo "$x" | sed -n ${N}p </code></pre> <p>or (for the spe...
276, 387, 1012
bash, debian, variables
<h1>how can I echo/print specific lines from a bash variable</h1> <p>I am trying to print specific lines from a multi-line bash variable. I've found the following:</p> <pre><code>while read line; do echo LINE: "$line"; done &lt;&lt;&lt; "$x" </code></pre> <p>where x would be the variable, but that simply prints out a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,841
bash
# how can I echo/print specific lines from a bash variable I am trying to print specific lines from a multi-line bash variable. I've found the following: ``` while read line; do echo LINE: "$line"; done <<< "$x" ``` where x would be the variable, but that simply prints out all lines instead of just a single one (say...
To print the Nth line: ``` sed -n ${N}p <<< "$x" ``` or (more portably): ``` sed -n ${N}p << EOF $x EOF ``` or ``` echo "$x" | sed -n "$N"p ``` or ``` echo "$x" | sed -n ${N}p ``` or (for the specific case N==3) ``` echo "$x" | sed -n 3p ``` or ``` while read line; do echo LINE: "$line"; done <<< "$x" | sed ...
13223279
how can a sourced file inherit trap DEBUG?
11
2012-11-04 21:47:04
<p>Running the following snippet:</p> <pre><code>#!/bin/bash function preexec () { echo -e "\n--&gt;preexec command: $BASH_COMMAND" } trap 'preexec' DEBUG function testfunc () { echo "testfunc called $1" } testfunc "main" source "source.sh" exit 0 </code></pre> <p><br> where source.sh is</p> <pre><code>#...
2,184
1,032,370
2017-04-10 15:01:13
14,674,293
16
2013-02-03 15:53:45
1,032,370
2013-12-07 18:10:45
https://stackoverflow.com/q/13223279
https://stackoverflow.com/a/14674293
<p>I solved setting in the main file:</p> <pre><code>set -o functrace </code></pre> <p><br> From BASH man:</p> <blockquote> <p>If set, any traps on DEBUG and RETURN are inherited by shell functions, command substitutions, and commands executed in a subshell environment. The DEBUG and RETURN traps are normally ...
<p>I solved setting in the main file:</p> <pre><code>set -o functrace </code></pre> <p><br> From BASH man:</p> <blockquote> <p>If set, any traps on DEBUG and RETURN are inherited by shell functions, command substitutions, and commands executed in a subshell environment. The DEBUG and RETURN traps are normally ...
277, 387, 124485
bash, bash-trap, debugging
<h1>how can a sourced file inherit trap DEBUG?</h1> <p>Running the following snippet:</p> <pre><code>#!/bin/bash function preexec () { echo -e "\n--&gt;preexec command: $BASH_COMMAND" } trap 'preexec' DEBUG function testfunc () { echo "testfunc called $1" } testfunc "main" source "source.sh" exit 0 </code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,842
bash
# how can a sourced file inherit trap DEBUG? Running the following snippet: ``` #!/bin/bash function preexec () { echo -e "\n-->preexec command: $BASH_COMMAND" } trap 'preexec' DEBUG function testfunc () { echo "testfunc called $1" } testfunc "main" source "source.sh" exit 0 ``` where source.sh is ``` #...
I solved setting in the main file: ``` set -o functrace ``` From BASH man: > If set, any traps on DEBUG and RETURN are inherited by shell > functions, command substitutions, and commands executed in a subshell > environment. The DEBUG and RETURN traps are normally not inherited in > such cases. Being *'source'* a s...
13736385
How to write a shell script that checks if git repository is up to date?
11
2012-12-06 03:15:31
<pre><code>#!/bin/bash #gedit tidy plugin init=false SRC_DIR=~/repos DIRECTORY="Gedit-Clientside-Plugin" #making repos directory if [ ! -d "$SRC_DIR" ]; then mkdir $SRC_DIR; fi if [ ! -d "$SRC_DIR/$DIRECTORY" ]; then init=true cd $SRC_DIR &amp;&amp; pwd &amp;&amp; git clone git://github.com/trentrichardson/...
17,412
751,969
2013-06-04 14:33:34
13,738,316
16
2012-12-06 06:45:18
6,309
2012-12-06 09:24:11
https://stackoverflow.com/q/13736385
https://stackoverflow.com/a/13738316
<p>I would rather use the solution of "<a href="https://stackoverflow.com/a/12791408/6309">git: check if pull needed</a>":</p> <pre><code>git fetch origin reslog=$(git log HEAD..origin/master --oneline) if [[ "${reslog}" != "" ]] ; then git merge origin/master # completing the pull ... </code></pre>
<p>I would rather use the solution of "<a href="https://stackoverflow.com/a/12791408/6309">git: check if pull needed</a>":</p> <pre><code>git fetch origin reslog=$(git log HEAD..origin/master --oneline) if [[ "${reslog}" != "" ]] ; then git merge origin/master # completing the pull ... </code></pre>
119, 387, 390
bash, git, shell
<h1>How to write a shell script that checks if git repository is up to date?</h1> <pre><code>#!/bin/bash #gedit tidy plugin init=false SRC_DIR=~/repos DIRECTORY="Gedit-Clientside-Plugin" #making repos directory if [ ! -d "$SRC_DIR" ]; then mkdir $SRC_DIR; fi if [ ! -d "$SRC_DIR/$DIRECTORY" ]; then init=true ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,843
bash
# How to write a shell script that checks if git repository is up to date? ``` #!/bin/bash #gedit tidy plugin init=false SRC_DIR=~/repos DIRECTORY="Gedit-Clientside-Plugin" #making repos directory if [ ! -d "$SRC_DIR" ]; then mkdir $SRC_DIR; fi if [ ! -d "$SRC_DIR/$DIRECTORY" ]; then init=true cd $SRC_DIR ...
I would rather use the solution of "[git: check if pull needed](https://stackoverflow.com/a/12791408/6309)": ``` git fetch origin reslog=$(git log HEAD..origin/master --oneline) if [[ "${reslog}" != "" ]] ; then git merge origin/master # completing the pull ... ```
12569123
regular expression extract string after a colon in bash
11
2012-09-24 16:27:13
<p>I need to extract the string after the <code>:</code> in an example below:</p> <p><code>package:project.abc.def</code></p> <p>Where i would get <code>project.abc.def</code> as a result.</p> <p>I am attempting this in bash and i believe i have a regular expression that will work <code>:([^:]*)$</code>.</p> <p>In ...
17,872
427,763
2014-08-26 22:37:49
12,569,202
16
2012-09-24 16:33:09
1,404,992
2014-08-26 22:37:49
https://stackoverflow.com/q/12569123
https://stackoverflow.com/a/12569202
<p>There is no need for a regex here, just a simple prefix substitution:</p> <pre><code>$ apk="package:project.abc.def" $ apk=${apk##package:} project.abc.def </code></pre> <p>The ## syntax is one of bash's parameters expansions. Instead of #, % can be used to trim the end. See <a href="https://www.gnu.org/software/b...
<p>There is no need for a regex here, just a simple prefix substitution:</p> <pre><code>$ apk="package:project.abc.def" $ apk=${apk##package:} project.abc.def </code></pre> <p>The ## syntax is one of bash's parameters expansions. Instead of #, % can be used to trim the end. See <a href="https://www.gnu.org/software/b...
18, 387
bash, regex
<h1>regular expression extract string after a colon in bash</h1> <p>I need to extract the string after the <code>:</code> in an example below:</p> <p><code>package:project.abc.def</code></p> <p>Where i would get <code>project.abc.def</code> as a result.</p> <p>I am attempting this in bash and i believe i have a regu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,844
bash
# regular expression extract string after a colon in bash I need to extract the string after the `:` in an example below: `package:project.abc.def` Where i would get `project.abc.def` as a result. I am attempting this in bash and i believe i have a regular expression that will work `:([^:]*)$`. In my bash script i...
There is no need for a regex here, just a simple prefix substitution: ``` $ apk="package:project.abc.def" $ apk=${apk##package:} project.abc.def ``` The ## syntax is one of bash's parameters expansions. Instead of #, % can be used to trim the end. See [this section](https://www.gnu.org/software/bash/manual/html_node/...
11551509
Quick benchmark from the command line
11
2012-07-18 22:50:49
<p>I'd like to benchmark a PHP script, but this would equally apply to anything that can be run from the command line.</p> <p>Using bash is there a simple way to benchmark a script, i.e. run a command multiple times and time how long it takes?</p>
6,658
1,196,970
2022-06-18 12:26:42
11,555,395
16
2012-07-19 06:53:10
217,071
2012-07-19 06:59:58
https://stackoverflow.com/q/11551509
https://stackoverflow.com/a/11555395
<p>In command line, you can:</p> <pre><code>$ time php foobar.php </code></pre> <p>Here <code>time</code> is a bash built-in.</p> <p>For multiple runs:</p> <pre><code>$ time for a in {1..10}; do php foobar.php; done real 0m13.042s user 0m0.021s sys 0m0.044s </code></pre> <p>However, you need to calculate...
<p>In command line, you can:</p> <pre><code>$ time php foobar.php </code></pre> <p>Here <code>time</code> is a bash built-in.</p> <p>For multiple runs:</p> <pre><code>$ time for a in {1..10}; do php foobar.php; done real 0m13.042s user 0m0.021s sys 0m0.044s </code></pre> <p>However, you need to calculate...
5, 387, 722
bash, benchmarking, php
<h1>Quick benchmark from the command line</h1> <p>I'd like to benchmark a PHP script, but this would equally apply to anything that can be run from the command line.</p> <p>Using bash is there a simple way to benchmark a script, i.e. run a command multiple times and time how long it takes?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,845
bash
# Quick benchmark from the command line I'd like to benchmark a PHP script, but this would equally apply to anything that can be run from the command line. Using bash is there a simple way to benchmark a script, i.e. run a command multiple times and time how long it takes?
In command line, you can: ``` $ time php foobar.php ``` Here `time` is a bash built-in. For multiple runs: ``` $ time for a in {1..10}; do php foobar.php; done real 0m13.042s user 0m0.021s sys 0m0.044s ``` However, you need to calculate the average time by hand.
10718065
Modifying Visual Studio solution and project files with PowerShell
11
2012-05-23 10:27:16
<p>We are currently reorganizing our source code, moving stuff around in a new directory structure. This impacts our Visual Studio solution and project files, where things like assembly references, possibly output directories, pre and post build events, and so on ... must be updated to reflect our changes.</p> <p>Sinc...
9,060
311,712
2023-01-09 20:54:24
10,861,645
16
2012-06-02 10:39:35
30,321
2012-07-20 09:33:23
https://stackoverflow.com/q/10718065
https://stackoverflow.com/a/10861645
<p>In my experience, the easiest way to manipulate Visual Studio solutions using PowerShell (from within or outside of Visual Studio) is to load the project file as XML and use PowerShell to manipulate it.</p> <pre class="lang-powershell prettyprint-override"><code>$proj = [xml](get-content Path\To\MyProject.csproj) $...
<p>In my experience, the easiest way to manipulate Visual Studio solutions using PowerShell (from within or outside of Visual Studio) is to load the project file as XML and use PowerShell to manipulate it.</p> <pre class="lang-powershell prettyprint-override"><code>$proj = [xml](get-content Path\To\MyProject.csproj) $...
526, 1362, 14456
automation, powershell, visual-studio-2010
<h1>Modifying Visual Studio solution and project files with PowerShell</h1> <p>We are currently reorganizing our source code, moving stuff around in a new directory structure. This impacts our Visual Studio solution and project files, where things like assembly references, possibly output directories, pre and post buil...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,846
bash
# Modifying Visual Studio solution and project files with PowerShell We are currently reorganizing our source code, moving stuff around in a new directory structure. This impacts our Visual Studio solution and project files, where things like assembly references, possibly output directories, pre and post build events,...
In my experience, the easiest way to manipulate Visual Studio solutions using PowerShell (from within or outside of Visual Studio) is to load the project file as XML and use PowerShell to manipulate it. ``` $proj = [xml](get-content Path\To\MyProject.csproj) $proj.GetElementsByTagName("PostBuildEvent") | foreach { ...
9589092
Read input from redirected stdin with python
11
2012-03-06 17:47:36
<p>I have this loop that reads lines from stdin until a newline is entered, however, this only works from typing in the input. How do I get the program to read lines from a redirected stdin via the command line?</p> <p>For instance:</p> <pre><code>$ python graph.py &lt; input.input </code></pre> <p>Here is the loop ...
31,431
412,520
2020-06-28 14:43:39
9,589,320
16
2012-03-06 18:02:09
916,657
2012-03-06 18:02:09
https://stackoverflow.com/q/9589092
https://stackoverflow.com/a/9589320
<p>As others have mentioned, probably your condition <code>line == '\n'</code> never holds true. The proper solution would be to use a loop like:</p> <pre><code>for line in sys.stdin: stripped = line.strip() if not stripped: break lines.append(stripped) </code></pre>
<p>As others have mentioned, probably your condition <code>line == '\n'</code> never holds true. The proper solution would be to use a loop like:</p> <pre><code>for line in sys.stdin: stripped = line.strip() if not stripped: break lines.append(stripped) </code></pre>
16, 390, 1701
python, shell, stdin
<h1>Read input from redirected stdin with python</h1> <p>I have this loop that reads lines from stdin until a newline is entered, however, this only works from typing in the input. How do I get the program to read lines from a redirected stdin via the command line?</p> <p>For instance:</p> <pre><code>$ python graph.p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,847
bash
# Read input from redirected stdin with python I have this loop that reads lines from stdin until a newline is entered, however, this only works from typing in the input. How do I get the program to read lines from a redirected stdin via the command line? For instance: ``` $ python graph.py < input.input ``` Here i...
As others have mentioned, probably your condition `line == '\n'` never holds true. The proper solution would be to use a loop like: ``` for line in sys.stdin: stripped = line.strip() if not stripped: break lines.append(stripped) ```
8343894
AES encrypt with openssl command line tool, and decrypt in Java
11
2011-12-01 15:32:23
<p>I have a bash script that uses the openssl tool to encrypt.</p> <pre><code>#!/bin/bash key128="1234567890123456" iv="1234567890123456" openssl enc -aes-128-cbc -in test -out test.enc -K $key128 -iv $iv </code></pre> <p>And Java code that tries to decrypt the file produced by the script.</p> <pre><code>public cla...
54,051
533,212
2011-12-02 05:07:30
8,352,010
16
2011-12-02 05:07:30
533,212
2011-12-02 05:07:30
https://stackoverflow.com/q/8343894
https://stackoverflow.com/a/8352010
<p>As @Polynomial mentioned above, the keys and iv's don't match between the bash script and Java code. Changing the bash script to the following solves the problem.</p> <pre><code>#!/bin/bash key128="01020304050607080900010203040506" iv="01020304050607080900010203040506" openssl enc -aes-128-cbc -in test -out test....
<p>As @Polynomial mentioned above, the keys and iv's don't match between the bash script and Java code. Changing the bash script to the following solves the problem.</p> <pre><code>#!/bin/bash key128="01020304050607080900010203040506" iv="01020304050607080900010203040506" openssl enc -aes-128-cbc -in test -out test....
17, 219, 387, 2387, 6728
aes, bash, cryptography, encryption, java
<h1>AES encrypt with openssl command line tool, and decrypt in Java</h1> <p>I have a bash script that uses the openssl tool to encrypt.</p> <pre><code>#!/bin/bash key128="1234567890123456" iv="1234567890123456" openssl enc -aes-128-cbc -in test -out test.enc -K $key128 -iv $iv </code></pre> <p>And Java code that tri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,848
bash
# AES encrypt with openssl command line tool, and decrypt in Java I have a bash script that uses the openssl tool to encrypt. ``` #!/bin/bash key128="1234567890123456" iv="1234567890123456" openssl enc -aes-128-cbc -in test -out test.enc -K $key128 -iv $iv ``` And Java code that tries to decrypt the file produced b...
As @Polynomial mentioned above, the keys and iv's don't match between the bash script and Java code. Changing the bash script to the following solves the problem. ``` #!/bin/bash key128="01020304050607080900010203040506" iv="01020304050607080900010203040506" openssl enc -aes-128-cbc -in test -out test.enc -K $key128 ...
8086191
Create Binary files in UNIX
11
2011-11-10 20:58:30
<p>This question was out there for a while and I thought I should offer some bonus points if I can get it to work. </p> <h1>What did I do…</h1> <p>Recently at work, I wrote a parser that would convert a binary file in a readable format. Binary file isn't an Ascii file with <code>10101010</code> characters. It has bee...
12,464
970,195
2017-01-12 12:38:06
8,301,961
16
2011-11-28 20:35:26
null
2011-11-29 08:31:47
https://stackoverflow.com/q/8086191
https://stackoverflow.com/a/8301961
<p>You can use <a href="http://linux.die.net/man/1/xxd." rel="noreferrer"><strong>xxd</strong></a> to convert to and from binary files / hexdumps quite simply.</p> <p>data to hex </p> <pre><code>echo Hello | xxd -p 48656c6c6f0a </code></pre> <p>hex to data</p> <pre><code>echo 48656c6c6f0a | xxd -r -p Hello </code...
<p>You can use <a href="http://linux.die.net/man/1/xxd." rel="noreferrer"><strong>xxd</strong></a> to convert to and from binary files / hexdumps quite simply.</p> <p>data to hex </p> <pre><code>echo Hello | xxd -p 48656c6c6f0a </code></pre> <p>hex to data</p> <pre><code>echo 48656c6c6f0a | xxd -r -p Hello </code...
387, 1357, 2834, 5004, 73656
bash, binaryfiles, hexdump, parsing, xxd
<h1>Create Binary files in UNIX</h1> <p>This question was out there for a while and I thought I should offer some bonus points if I can get it to work. </p> <h1>What did I do…</h1> <p>Recently at work, I wrote a parser that would convert a binary file in a readable format. Binary file isn't an Ascii file with <code>1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,849
bash
# Create Binary files in UNIX This question was out there for a while and I thought I should offer some bonus points if I can get it to work. # What did I do… Recently at work, I wrote a parser that would convert a binary file in a readable format. Binary file isn't an Ascii file with `10101010` characters. It has b...
You can use [**xxd**](http://linux.die.net/man/1/xxd.) to convert to and from binary files / hexdumps quite simply. data to hex ``` echo Hello | xxd -p 48656c6c6f0a ``` hex to data ``` echo 48656c6c6f0a | xxd -r -p Hello ``` or ``` echo 48 65 6c 6c 6f 0a | xxd -r -p Hello ``` The `-p` is postscript mode which ...
7907055
-bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory
11
2011-10-26 18:18:43
<p>Whenever I open a new terminal window I now get:</p> <p><code>-bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory</code></p> <p>Any idea as to why this is happening and how to get rid of it?</p>
11,619
435,471
2018-03-13 20:41:01
7,907,130
16
2011-10-26 18:26:17
836,407
2011-10-26 18:26:17
https://stackoverflow.com/q/7907055
https://stackoverflow.com/a/7907130
<p>Make sure the first line of the file <code>/usr/local/bin/heroku</code> is <code>#!/path/to/ruby</code>. You may need to change it from <code>/usr/local/bin/ruby</code> to <code>/usr/bin/ruby</code>, or if you cannot find the <code>ruby</code> executable, type <code>which ruby</code> or <code>updatedb &amp;&amp; lo...
<p>Make sure the first line of the file <code>/usr/local/bin/heroku</code> is <code>#!/path/to/ruby</code>. You may need to change it from <code>/usr/local/bin/ruby</code> to <code>/usr/bin/ruby</code>, or if you cannot find the <code>ruby</code> executable, type <code>which ruby</code> or <code>updatedb &amp;&amp; lo...
12, 387, 8279
bash, heroku, ruby
<h1>-bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory</h1> <p>Whenever I open a new terminal window I now get:</p> <p><code>-bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory</code></p> <p>Any idea as to why this is happening and h...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,850
bash
# -bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory Whenever I open a new terminal window I now get: `-bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad interpreter: No such file or directory` Any idea as to why this is happening and how to get rid of it?
Make sure the first line of the file `/usr/local/bin/heroku` is `#!/path/to/ruby`. You may need to change it from `/usr/local/bin/ruby` to `/usr/bin/ruby`, or if you cannot find the `ruby` executable, type `which ruby` or `updatedb && locate ruby` to find it. --- If the above doesn't work... Check your `~/.bashrc`, ...
7817637
Bash: How do I make sub-processes of a script be terminated, when the script is terminated?
11
2011-10-19 07:00:47
<p>The question applies to a script such as the following:</p> <h2>Script</h2> <pre><code>#!/bin/sh SRC="/tmp/my-server-logs" echo "STARTING GREP JOBS..." for f in `find ${SRC} -name '*log*2011*' | sort --reverse` do ( OUT=`nice grep -ci -E "${1}" "${f}"` if [ "${OUT}" != "0" ] then ...
4,697
964,681
2014-02-07 14:16:31
7,817,949
16
2011-10-19 07:34:57
918
2011-10-19 08:00:54
https://stackoverflow.com/q/7817637
https://stackoverflow.com/a/7817949
<p>Write a trap for <code>Ctrl+c</code> and in the trap kill all of the subprocesses. Put this before your <code>wait</code> command.</p> <pre><code>function handle_sigint() { for proc in `jobs -p` do kill $proc done } trap handle_sigint SIGINT </code></pre>
<p>Write a trap for <code>Ctrl+c</code> and in the trap kill all of the subprocesses. Put this before your <code>wait</code> command.</p> <pre><code>function handle_sigint() { for proc in `jobs -p` do kill $proc done } trap handle_sigint SIGINT </code></pre>
58, 387, 2348, 5643
bash, linux, subprocess, termination
<h1>Bash: How do I make sub-processes of a script be terminated, when the script is terminated?</h1> <p>The question applies to a script such as the following:</p> <h2>Script</h2> <pre><code>#!/bin/sh SRC="/tmp/my-server-logs" echo "STARTING GREP JOBS..." for f in `find ${SRC} -name '*log*2011*' | sort --reverse` d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,851
bash
# Bash: How do I make sub-processes of a script be terminated, when the script is terminated? The question applies to a script such as the following: ## Script ``` #!/bin/sh SRC="/tmp/my-server-logs" echo "STARTING GREP JOBS..." for f in `find ${SRC} -name '*log*2011*' | sort --reverse` do ( OUT=`nice ...
Write a trap for `Ctrl+c` and in the trap kill all of the subprocesses. Put this before your `wait` command. ``` function handle_sigint() { for proc in `jobs -p` do kill $proc done } trap handle_sigint SIGINT ```
6816923
What does "- <" mean when you run powershell?
11
2011-07-25 13:34:17
<p>The recommended way to run scripts is </p> <pre><code>powershell.exe -NonInteractive -Command " &amp; some.ps1 " </code></pre> <p>However for example TeamCity PowerShell runner uses:</p> <pre><code>powershell.exe -NonInteractive -Command - &lt; some.ps1 </code></pre> <p>I do not have an idea what "- &lt;" means...
1,123
38,975
2011-07-25 13:48:07
6,817,031
16
2011-07-25 13:42:10
22,211
2011-07-25 13:47:46
https://stackoverflow.com/q/6816923
https://stackoverflow.com/a/6817031
<p>Because <code>powershell.exe</code> is being invoked through the Windows shell, it is the same as if you were on a normal command prompt (<code>cmd.exe</code>). In that situation <code>&lt;</code> pipes a file to the standard input (<code>stdin</code>) of the previous command. The help for <code>powershell.exe</code...
<p>Because <code>powershell.exe</code> is being invoked through the Windows shell, it is the same as if you were on a normal command prompt (<code>cmd.exe</code>). In that situation <code>&lt;</code> pipes a file to the standard input (<code>stdin</code>) of the previous command. The help for <code>powershell.exe</code...
526, 604
powershell, teamcity
<h1>What does "- <" mean when you run powershell?</h1> <p>The recommended way to run scripts is </p> <pre><code>powershell.exe -NonInteractive -Command " &amp; some.ps1 " </code></pre> <p>However for example TeamCity PowerShell runner uses:</p> <pre><code>powershell.exe -NonInteractive -Command - &lt; some.ps1 </co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,852
bash
# What does "- <" mean when you run powershell? The recommended way to run scripts is ``` powershell.exe -NonInteractive -Command " & some.ps1 " ``` However for example TeamCity PowerShell runner uses: ``` powershell.exe -NonInteractive -Command - < some.ps1 ``` I do not have an idea what "- <" means and cannot fi...
Because `powershell.exe` is being invoked through the Windows shell, it is the same as if you were on a normal command prompt (`cmd.exe`). In that situation `<` pipes a file to the standard input (`stdin`) of the previous command. The help for `powershell.exe` states that if the value of `-Command` is simply `-`, the c...
6618427
xargs jar tvf - does not work
11
2011-07-07 23:43:53
<p>Objective: to list files in all jars.</p> <p>This works:</p> <pre><code>for f in `find . -name "*.jar"`; do jar tvf $f; done </code></pre> <p>This works too:</p> <pre><code>find . -name "*.jar" -exec jar tvf {} \; </code></pre> <p>This does not (it does not print any output):</p> <pre><code>find . -name "*.jar...
3,656
45,525
2019-07-30 19:03:02
6,618,445
16
2011-07-07 23:46:54
567,435
2011-07-07 23:46:54
https://stackoverflow.com/q/6618427
https://stackoverflow.com/a/6618445
<p>Does this works</p> <pre><code>find . -name "*.jar"|xargs -n 1 jar -tvf </code></pre>
<p>Does this works</p> <pre><code>find . -name "*.jar"|xargs -n 1 jar -tvf </code></pre>
387, 10326
bash, xargs
<h1>xargs jar tvf - does not work</h1> <p>Objective: to list files in all jars.</p> <p>This works:</p> <pre><code>for f in `find . -name "*.jar"`; do jar tvf $f; done </code></pre> <p>This works too:</p> <pre><code>find . -name "*.jar" -exec jar tvf {} \; </code></pre> <p>This does not (it does not print any outpu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,853
bash
# xargs jar tvf - does not work Objective: to list files in all jars. This works: ``` for f in `find . -name "*.jar"`; do jar tvf $f; done ``` This works too: ``` find . -name "*.jar" -exec jar tvf {} \; ``` This does not (it does not print any output): ``` find . -name "*.jar" | xargs jar tvf ``` Why does the ...
Does this works ``` find . -name "*.jar"|xargs -n 1 jar -tvf ```
4464467
Add group "Everyone" to directory and all of it's sub-directories
11
2010-12-16 19:08:48
<p>I'm currently using Vista 32-bit. How do I add the Windows security group "Everyone" and give full control to a directory and all of it's sub-directories and all files? Is there a powershell script that I could use?</p> <p>Thanks!</p>
27,037
349,308
2014-07-14 20:41:17
4,466,027
16
2010-12-16 22:32:08
349,308
2010-12-16 22:32:08
https://stackoverflow.com/q/4464467
https://stackoverflow.com/a/4466027
<p>I've expanded on martona's snippet and was able to give access to all folders and sub-folders. Here's my code -</p> <pre><code>$FilesAndFolders = gci "c:\data" -recurse | % {$_.FullName} foreach($FileAndFolder in $FilesAndFolders) { #using get-item instead because some of the folders have '[' or ']' character a...
<p>I've expanded on martona's snippet and was able to give access to all folders and sub-folders. Here's my code -</p> <pre><code>$FilesAndFolders = gci "c:\data" -recurse | % {$_.FullName} foreach($FileAndFolder in $FilesAndFolders) { #using get-item instead because some of the folders have '[' or ']' character a...
64, 136, 526, 8084
powershell, security, usergroups, windows
<h1>Add group "Everyone" to directory and all of it's sub-directories</h1> <p>I'm currently using Vista 32-bit. How do I add the Windows security group "Everyone" and give full control to a directory and all of it's sub-directories and all files? Is there a powershell script that I could use?</p> <p>Thanks!</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,854
bash
# Add group "Everyone" to directory and all of it's sub-directories I'm currently using Vista 32-bit. How do I add the Windows security group "Everyone" and give full control to a directory and all of it's sub-directories and all files? Is there a powershell script that I could use? Thanks!
I've expanded on martona's snippet and was able to give access to all folders and sub-folders. Here's my code - ``` $FilesAndFolders = gci "c:\data" -recurse | % {$_.FullName} foreach($FileAndFolder in $FilesAndFolders) { #using get-item instead because some of the folders have '[' or ']' character and Powershell ...
3707116
git: stage only new files
11
2010-09-14 08:11:51
<p>When I have:</p> <ul> <li>dirty working directory,</li> <li>dirty staging area,</li> <li>and I copied some new files to the project,</li> </ul> <p>how do I stage only the new ones?</p> <pre><code>git alias adduntracked=… </code></pre>
4,273
234,780
2016-09-15 07:42:25
3,709,301
16
2010-09-14 13:28:17
67,022
2012-05-21 12:52:25
https://stackoverflow.com/q/3707116
https://stackoverflow.com/a/3709301
<p>This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for <code>git-ls-files --exclude-standard</code>). It will run at the top level of your tree.</p> <pre><code>[alias] adduntracked=!git add $(git ls-files -o --exclude-standard) </code></pre>
<p>This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for <code>git-ls-files --exclude-standard</code>). It will run at the top level of your tree.</p> <pre><code>[alias] adduntracked=!git add $(git ls-files -o --exclude-standard) </code></pre>
119, 387, 531
bash, git, scripting
<h1>git: stage only new files</h1> <p>When I have:</p> <ul> <li>dirty working directory,</li> <li>dirty staging area,</li> <li>and I copied some new files to the project,</li> </ul> <p>how do I stage only the new ones?</p> <pre><code>git alias adduntracked=… </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,855
bash
# git: stage only new files When I have: - dirty working directory, - dirty staging area, - and I copied some new files to the project, how do I stage only the new ones? ``` git alias adduntracked=… ```
This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for `git-ls-files --exclude-standard`). It will run at the top level of your tree. ``` [alias] adduntracked=!git add $(git ls-files -o --exclude-standard) ```
3708647
replace the first line of text from a file
11
2010-09-14 12:01:35
<p>I would like to copy a file from one location to another, and replace the first line of text with a string. I almost have the script complete, but not quite there.. (see below)</p> <pre><code># -- copy the ASCX file to the control templates $fileName = "LandingUserControl.ascx" $source = "D:\TfsProjects\LandingPag...
19,680
97,686
2021-11-12 16:27:24
3,708,704
16
2010-09-14 12:08:32
323,582
2010-09-14 12:08:32
https://stackoverflow.com/q/3708647
https://stackoverflow.com/a/3708704
<p>Not a one-liner but it works (replace test1.txt and test2.txt with your paths):</p> <pre><code>.{ "&lt;text to add&gt;" Get-Content test1.txt | Select-Object -Skip 1 } | Set-Content test2.txt </code></pre>
<p>Not a one-liner but it works (replace test1.txt and test2.txt with your paths):</p> <pre><code>.{ "&lt;text to add&gt;" Get-Content test1.txt | Select-Object -Skip 1 } | Set-Content test2.txt </code></pre>
526
powershell
<h1>replace the first line of text from a file</h1> <p>I would like to copy a file from one location to another, and replace the first line of text with a string. I almost have the script complete, but not quite there.. (see below)</p> <pre><code># -- copy the ASCX file to the control templates $fileName = "LandingUs...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,856
bash
# replace the first line of text from a file I would like to copy a file from one location to another, and replace the first line of text with a string. I almost have the script complete, but not quite there.. (see below) ``` # -- copy the ASCX file to the control templates $fileName = "LandingUserControl.ascx" $sour...
Not a one-liner but it works (replace test1.txt and test2.txt with your paths): ``` .{ "<text to add>" Get-Content test1.txt | Select-Object -Skip 1 } | Set-Content test2.txt ```
3589033
exec line from file in bash
11
2010-08-28 01:08:33
<p>I'm trying to read commands from a text file and execute each line from a bash script.</p> <pre><code>#!/bin/bash while read line; do $line done &lt; "commands.txt" </code></pre> <p>In some cases, if <code>$line</code> contains commands that are meant to run in background, eg <code>command 2&gt;&amp;1 &am...
16,428
11,301
2017-09-09 15:36:06
3,589,092
16
2010-08-28 01:32:53
131,527
2010-08-28 01:32:53
https://stackoverflow.com/q/3589033
https://stackoverflow.com/a/3589092
<p>if all your commands are inside "commands.txt", essentially, you can call it a shell script. That's why you can either source it, or run it like normal, ie chmod u+x , then you can execute it using <code>sh commands.txt</code></p>
<p>if all your commands are inside "commands.txt", essentially, you can call it a shell script. That's why you can either source it, or run it like normal, ie chmod u+x , then you can execute it using <code>sh commands.txt</code></p>
387
bash
<h1>exec line from file in bash</h1> <p>I'm trying to read commands from a text file and execute each line from a bash script.</p> <pre><code>#!/bin/bash while read line; do $line done &lt; "commands.txt" </code></pre> <p>In some cases, if <code>$line</code> contains commands that are meant to run in backgro...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,857
bash
# exec line from file in bash I'm trying to read commands from a text file and execute each line from a bash script. ``` #!/bin/bash while read line; do $line done < "commands.txt" ``` In some cases, if `$line` contains commands that are meant to run in background, eg `command 2>&1 &` they will not start in...
if all your commands are inside "commands.txt", essentially, you can call it a shell script. That's why you can either source it, or run it like normal, ie chmod u+x , then you can execute it using `sh commands.txt`
1912328
How to map Delete and End keys on tcsh shell?
11
2009-12-16 04:39:53
<p>I use tcsh , and when Delete/End is pressed on cmd line, it simply shows up as <code>~</code> ; I have to press <code>&lt;Ctrl&gt;&lt;e&gt;</code> to go to end of line. Can anyone help me to be able to use Delete/End keys as their name suggests ?</p>
7,493
212,942
2009-12-16 05:45:11
1,912,527
16
2009-12-16 05:36:06
54,435
2009-12-16 05:36:06
https://stackoverflow.com/q/1912328
https://stackoverflow.com/a/1912527
<p>Those keys already worked on my Debian system. I found these commands in the <code>/etc/csh.cshrc</code> file:</p> <pre><code>if ($?tcsh &amp;&amp; $?prompt) then bindkey "\e[1~" beginning-of-line # Home bindkey "\e[7~" beginning-of-line # Home rxvt bindkey "\e[2~" overwrite-mode # Ins ...
<p>Those keys already worked on my Debian system. I found these commands in the <code>/etc/csh.cshrc</code> file:</p> <pre><code>if ($?tcsh &amp;&amp; $?prompt) then bindkey "\e[1~" beginning-of-line # Home bindkey "\e[7~" beginning-of-line # Home rxvt bindkey "\e[2~" overwrite-mode # Ins ...
267, 390, 8599
keyboard, shell, tcsh
<h1>How to map Delete and End keys on tcsh shell?</h1> <p>I use tcsh , and when Delete/End is pressed on cmd line, it simply shows up as <code>~</code> ; I have to press <code>&lt;Ctrl&gt;&lt;e&gt;</code> to go to end of line. Can anyone help me to be able to use Delete/End keys as their name suggests ?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,858
bash
# How to map Delete and End keys on tcsh shell? I use tcsh , and when Delete/End is pressed on cmd line, it simply shows up as `~` ; I have to press `<Ctrl><e>` to go to end of line. Can anyone help me to be able to use Delete/End keys as their name suggests ?
Those keys already worked on my Debian system. I found these commands in the `/etc/csh.cshrc` file: ``` if ($?tcsh && $?prompt) then bindkey "\e[1~" beginning-of-line # Home bindkey "\e[7~" beginning-of-line # Home rxvt bindkey "\e[2~" overwrite-mode # Ins bindkey "\e[3~" delete-char...
1567112
Convert Keith Hill's PowerShell Get-Clipboard and Set-Clipboard to a PSM1 script
11
2009-10-14 15:32:31
<p>I'd like to convert Keith Hill's C# implementation of Get-Clipboard and Set-Clipboard into pure PowerShell as a .PSM1 file.</p> <p>Is there a way to spin up an STA thread in PowerShell as he does in his Cmdlet when working with the clipboard?</p> <p><a href="http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A...
8,159
3,957
2019-11-25 21:05:01
1,573,295
16
2009-10-15 15:54:21
183,178
2013-01-25 17:57:31
https://stackoverflow.com/q/1567112
https://stackoverflow.com/a/1573295
<p>TextBox doesn't require -STA switch.</p> <pre><code>function Get-ClipBoard { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Paste() $tb.Text } function Set-ClipBoard() { Param( [Parameter(ValueFromPipeline=$true)] ...
<p>TextBox doesn't require -STA switch.</p> <pre><code>function Get-ClipBoard { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Paste() $tb.Text } function Set-ClipBoard() { Param( [Parameter(ValueFromPipeline=$true)] ...
9, 526, 1381, 15878
c#, multithreading, powershell, sta
<h1>Convert Keith Hill's PowerShell Get-Clipboard and Set-Clipboard to a PSM1 script</h1> <p>I'd like to convert Keith Hill's C# implementation of Get-Clipboard and Set-Clipboard into pure PowerShell as a .PSM1 file.</p> <p>Is there a way to spin up an STA thread in PowerShell as he does in his Cmdlet when working wit...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,859
bash
# Convert Keith Hill's PowerShell Get-Clipboard and Set-Clipboard to a PSM1 script I'd like to convert Keith Hill's C# implementation of Get-Clipboard and Set-Clipboard into pure PowerShell as a .PSM1 file. Is there a way to spin up an STA thread in PowerShell as he does in his Cmdlet when working with the clipboard?...
TextBox doesn't require -STA switch. ``` function Get-ClipBoard { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Paste() $tb.Text } function Set-ClipBoard() { Param( [Parameter(ValueFromPipeline=$true)] [string] ...
49988312
How do I create files with special characters in Linux?
10
2018-04-23 19:09:41
<p>I am using the <code>touch</code> command to try and create a file with the name <code>"\?$*'KwaMe'*$?\"</code> (quotation marks included as part of the file name). However when I type <code>touch "\?$*'KwaMe'*$?\"</code> in the Terminal, it doesn't give me the result I am expecting. How can I create this file?</p>
45,795
9,438,033
2023-02-19 11:14:23
49,988,431
16
2018-04-23 19:17:56
5,660,517
2021-01-26 17:52:53
https://stackoverflow.com/q/49988312
https://stackoverflow.com/a/49988431
<p><strong>You need to <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html" rel="noreferrer">escape special characters</a> with the backslash symbol (<code>\</code>).</strong></p> <hr /> <p>This command will create a file named <code>&quot;\?$*'KwaMe'*$?\&quot;</code>:</p> <pre class="lang-sh prettyp...
<p><strong>You need to <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html" rel="noreferrer">escape special characters</a> with the backslash symbol (<code>\</code>).</strong></p> <hr /> <p>This command will create a file named <code>&quot;\?$*'KwaMe'*$?\&quot;</code>:</p> <pre class="lang-sh prettyp...
58, 387, 390, 1062, 12725
bash, filenames, linux, shell, special-characters
<h1>How do I create files with special characters in Linux?</h1> <p>I am using the <code>touch</code> command to try and create a file with the name <code>"\?$*'KwaMe'*$?\"</code> (quotation marks included as part of the file name). However when I type <code>touch "\?$*'KwaMe'*$?\"</code> in the Terminal, it doesn't gi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,860
bash
# How do I create files with special characters in Linux? I am using the `touch` command to try and create a file with the name `"\?$*'KwaMe'*$?\"` (quotation marks included as part of the file name). However when I type `touch "\?$*'KwaMe'*$?\"` in the Terminal, it doesn't give me the result I am expecting. How can I...
**You need to [escape special characters](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html) with the backslash symbol (`\`).** --- This command will create a file named `"\?$*'KwaMe'*$?\"`: ``` touch \"\\\?\$\*\'KwaMe\'\*\$\?\\\" ``` --- ### Explanation 1. **Double your `\`**, like this: `\\`, so tha...
49626250
Flask Shell Commands not working
10
2018-04-03 09:10:46
<p>I'm new to python and flask and currently working on the <a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database" rel="noreferrer">Flask Mega-Tutorial</a>, however: I'm stuck getting <code>flask shell</code> to recognize my custom symbols/commands. </p> <p>When I try to access the mod...
17,104
9,589,937
2018-11-01 06:01:52
49,801,351
16
2018-04-12 16:12:47
9,589,937
2018-04-12 16:12:47
https://stackoverflow.com/q/49626250
https://stackoverflow.com/a/49801351
<p>Thanks a lot to <a href="https://stackoverflow.com/users/904393/miguel">Miguel</a>, the writer of the FLASK Mega Tutorial (<a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="noreferrer">go check that out</a>) wo solved my problem!</p> <p>As he pointed out in <a href="https...
<p>Thanks a lot to <a href="https://stackoverflow.com/users/904393/miguel">Miguel</a>, the writer of the FLASK Mega Tutorial (<a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="noreferrer">go check that out</a>) wo solved my problem!</p> <p>As he pointed out in <a href="https...
16, 390, 54712, 60010
flask, python, python-3.x, shell
<h1>Flask Shell Commands not working</h1> <p>I'm new to python and flask and currently working on the <a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database" rel="noreferrer">Flask Mega-Tutorial</a>, however: I'm stuck getting <code>flask shell</code> to recognize my custom symbols/comma...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
8,861
bash
# Flask Shell Commands not working I'm new to python and flask and currently working on the [Flask Mega-Tutorial](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database), however: I'm stuck getting `flask shell` to recognize my custom symbols/commands. When I try to access the model `User` as a...
Thanks a lot to [Miguel](https://stackoverflow.com/users/904393/miguel), the writer of the FLASK Mega Tutorial ([go check that out](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world)) wo solved my problem! As he pointed out in [a comment below my question](https://stackoverflow.com/questi...