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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
10546739 | Sublime text 2 - How to run a shell command over ssh? | 10 | 2012-05-11 06:50:30 | <p>I'm new to <em>Sublime Text 2</em> and there's something I haven't figured out yet, how can I run a bash command over SSH ?</p>
<p>For example, to view the <em>Apache</em> error log on my dev server, I'd like to be able to run :</p>
<pre><code>ssh root@192.168.0.2 "tail -10 /var/log/httpd-error-user.log"
</code></... | 18,201 | 335,642 | 2014-01-09 08:52:51 | 10,554,143 | 14 | 2012-05-11 15:16:17 | 335,642 | 2012-05-11 15:16:17 | https://stackoverflow.com/q/10546739 | https://stackoverflow.com/a/10554143 | <p>I'll answer my own question. You can easily create a build pointing to any script, so all I had to do was create <code>myscript.sh</code> containing :</p>
<pre><code>#!/bin/bash
ssh root@192.168.0.2 "tail -10 /var/log/httpd-error-user.log"
</code></pre>
<p>And then create a new <em>Build System</em> in <em>ST2</e... | <p>I'll answer my own question. You can easily create a build pointing to any script, so all I had to do was create <code>myscript.sh</code> containing :</p> <pre><code>#!/bin/bash ssh root@192.168.0.2 "tail -10 /var/log/httpd-error-user.log" </code></pre> <p>And then create a new <em>Build System</em> in <em>ST2</e... | 387, 5025, 78970 | bash, editor, sublimetext2 | <h1>Sublime text 2 - How to run a shell command over ssh?</h1>
<p>I'm new to <em>Sublime Text 2</em> and there's something I haven't figured out yet, how can I run a bash command over SSH ?</p>
<p>For example, to view the <em>Apache</em> error log on my dev server, I'd like to be able to run :</p>
<pre><code>ssh root... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,766 | bash | # Sublime text 2 - How to run a shell command over ssh?
I'm new to *Sublime Text 2* and there's something I haven't figured out yet, how can I run a bash command over SSH ?
For example, to view the *Apache* error log on my dev server, I'd like to be able to run :
```
ssh root@192.168.0.2 "tail -10 /var/log/httpd-err... | I'll answer my own question. You can easily create a build pointing to any script, so all I had to do was create `myscript.sh` containing :
```
#!/bin/bash
ssh root@192.168.0.2 "tail -10 /var/log/httpd-error-user.log"
```
And then create a new *Build System* in *ST2* to call it :
```
{
"cmd": ["./myscript.sh"]
}... |
10283622 | Load Multiple Modules (.psm1) using a single psd1 file | 10 | 2012-04-23 15:33:12 | <p>I want to organize functions into <strong>multiple .psm1 files</strong> and have them loaded by a <strong>single Module Manifest file (.psd1)</strong> -- such that <strong>Only</strong> the <strong>.psd1 file</strong> would need to have the <strong>same name as the module</strong>. </p>
<p>I think it should be pos... | 28,193 | 763,026 | 2013-08-19 09:13:59 | 10,296,028 | 14 | 2012-04-24 10:21:10 | 763,026 | 2013-05-03 13:53:45 | https://stackoverflow.com/q/10283622 | https://stackoverflow.com/a/10296028 | <ol>
<li>Launch the Powershell ISE</li>
<li>Use the <code>New-ModuleManifest</code> command</li>
<li>Follow the instructions here - <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd878297%28v=vs.85%29.aspx" rel="noreferrer">How to Write a Module Manifest</a>. When asked for nested modules, key in the ... | <ol> <li>Launch the Powershell ISE</li> <li>Use the <code>New-ModuleManifest</code> command</li> <li>Follow the instructions here - <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd878297%28v=vs.85%29.aspx" rel="noreferrer">How to Write a Module Manifest</a>. When asked for nested modules, key in the ... | 526, 24067 | powershell, powershell-2.0 | <h1>Load Multiple Modules (.psm1) using a single psd1 file</h1>
<p>I want to organize functions into <strong>multiple .psm1 files</strong> and have them loaded by a <strong>single Module Manifest file (.psd1)</strong> -- such that <strong>Only</strong> the <strong>.psd1 file</strong> would need to have the <strong>sam... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,767 | bash | # Load Multiple Modules (.psm1) using a single psd1 file
I want to organize functions into **multiple .psm1 files** and have them loaded by a **single Module Manifest file (.psd1)** -- such that **Only** the **.psd1 file** would need to have the **same name as the module**.
I think it should be possible. Can anyone h... | 1. Launch the Powershell ISE
2. Use the `New-ModuleManifest` command
3. Follow the instructions here - [How to Write a Module Manifest](http://msdn.microsoft.com/en-us/library/windows/desktop/dd878297%28v=vs.85%29.aspx). When asked for nested modules, key in the module as `Modulepath\Modulename.psm1`
4. Finally, once t... |
10212179 | Using Java to find simple Active Directory Information | 10 | 2012-04-18 15:00:12 | <p>This is my first post, so please be gentle.</p>
<p>I've recentley started using Powershell at work to change AD groups, find AD information etc. but I'm lacking the GUI that I like so much about Java.</p>
<p>Is there a simple way (or example of code) whereby I enter a target hostname and I'm returned with the deta... | 29,086 | 1,341,708 | 2012-04-19 08:36:46 | 10,224,441 | 14 | 2012-04-19 08:36:46 | 608,772 | 2012-04-19 08:36:46 | https://stackoverflow.com/q/10212179 | https://stackoverflow.com/a/10224441 | <p>If you are looking for a full java GUI to query Active-Directory, you may have a look to <a href="http://directory.apache.org/studio/" rel="noreferrer">Apache Directory Studio</a>.</p>
<p>If you want to query AD just using java, here is a sample code :</p>
<pre><code>class TestAD
{
static DirContext ldapContex... | <p>If you are looking for a full java GUI to query Active-Directory, you may have a look to <a href="http://directory.apache.org/studio/" rel="noreferrer">Apache Directory Studio</a>.</p> <p>If you want to query AD just using java, here is a sample code :</p> <pre><code>class TestAD { static DirContext ldapContex... | 17, 526, 865, 10401 | active-directory, java, powershell, user-interface | <h1>Using Java to find simple Active Directory Information</h1>
<p>This is my first post, so please be gentle.</p>
<p>I've recentley started using Powershell at work to change AD groups, find AD information etc. but I'm lacking the GUI that I like so much about Java.</p>
<p>Is there a simple way (or example of code) ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,768 | bash | # Using Java to find simple Active Directory Information
This is my first post, so please be gentle.
I've recentley started using Powershell at work to change AD groups, find AD information etc. but I'm lacking the GUI that I like so much about Java.
Is there a simple way (or example of code) whereby I enter a targe... | If you are looking for a full java GUI to query Active-Directory, you may have a look to [Apache Directory Studio](http://directory.apache.org/studio/).
If you want to query AD just using java, here is a sample code :
```
class TestAD
{
static DirContext ldapContext;
public static void main (String[] args) thr... |
9943187 | Colour output of program run under BASH | 10 | 2012-03-30 12:42:46 | <p>I need to be able to be able to make some text on terminal more noticeable, and what I thought was to make the text colored. Either the actual text, or the space in each letter's rectangle-thingy (think vi's cursor). The only two extra specs that I think are important for my application are : the program should be d... | 5,631 | 1,210,010 | 2019-03-15 21:11:59 | 9,943,250 | 14 | 2012-03-30 12:46:37 | 565,635 | 2012-03-30 21:59:28 | https://stackoverflow.com/q/9943187 | https://stackoverflow.com/a/9943250 | <p>Most terminals respect the ASCII color sequences. They work by outputting <code>ESC</code>, followed by <code>[</code>, then a semicolon-separated list of color values, then <code>m</code>. These are common values:</p>
<pre><code>Special
0 Reset all attributes
1 Bright
2 Dim
4 Underscore
5 Blink
7 Reverse
... | <p>Most terminals respect the ASCII color sequences. They work by outputting <code>ESC</code>, followed by <code>[</code>, then a semicolon-separated list of color values, then <code>m</code>. These are common values:</p> <pre><code>Special 0 Reset all attributes 1 Bright 2 Dim 4 Underscore 5 Blink 7 Reverse ... | 10, 58, 387, 6439 | bash, c++, colors, linux | <h1>Colour output of program run under BASH</h1>
<p>I need to be able to be able to make some text on terminal more noticeable, and what I thought was to make the text colored. Either the actual text, or the space in each letter's rectangle-thingy (think vi's cursor). The only two extra specs that I think are important... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,769 | bash | # Colour output of program run under BASH
I need to be able to be able to make some text on terminal more noticeable, and what I thought was to make the text colored. Either the actual text, or the space in each letter's rectangle-thingy (think vi's cursor). The only two extra specs that I think are important for my a... | Most terminals respect the ASCII color sequences. They work by outputting `ESC`, followed by `[`, then a semicolon-separated list of color values, then `m`. These are common values:
```
Special
0 Reset all attributes
1 Bright
2 Dim
4 Underscore
5 Blink
7 Reverse
8 Hidden
Foreground colors
30 Black
31 Red
... |
9483171 | Escaping special characters in bash variables | 10 | 2012-02-28 13:53:59 | <p>I'm trying to read a file containing filepaths line by line and scp the files to another server, but because of certain characters in the filenames like '(', ')', '&' etc. I need to escape the input:</p>
<p><strong>input.txt</strong>:</p>
<pre><code>/folder1/folderA/filename+(oh+how+nice,+parantheses)
</code><... | 37,456 | 890,231 | 2021-11-16 12:22:15 | 9,488,318 | 14 | 2012-02-28 19:23:00 | 89,817 | 2012-02-28 19:23:00 | https://stackoverflow.com/q/9483171 | https://stackoverflow.com/a/9488318 | <p>Part of the problem here is that the local and remote filenames are parsed differently: the local filename is used directly, so the only thing you need to do is enclose it in double-quotes (as in @Ignacio's answer), but the remote filename gets passed to a remote shell which runs it through another layer of parsing ... | <p>Part of the problem here is that the local and remote filenames are parsed differently: the local filename is used directly, so the only thing you need to do is enclose it in double-quotes (as in @Ignacio's answer), but the remote filename gets passed to a remote shell which runs it through another layer of parsing ... | 387, 3149, 4804, 12725 | bash, escaping, scp, special-characters | <h1>Escaping special characters in bash variables</h1>
<p>I'm trying to read a file containing filepaths line by line and scp the files to another server, but because of certain characters in the filenames like '(', ')', '&' etc. I need to escape the input:</p>
<p><strong>input.txt</strong>:</p>
<pre><code>/folde... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,770 | bash | # Escaping special characters in bash variables
I'm trying to read a file containing filepaths line by line and scp the files to another server, but because of certain characters in the filenames like '(', ')', '&' etc. I need to escape the input:
**input.txt**:
```
/folder1/folderA/filename+(oh+how+nice,+paranthese... | Part of the problem here is that the local and remote filenames are parsed differently: the local filename is used directly, so the only thing you need to do is enclose it in double-quotes (as in @Ignacio's answer), but the remote filename gets passed to a remote shell which runs it through another layer of parsing (qu... |
9415740 | How to get process id from process name? | 10 | 2012-02-23 15:15:45 | <p>I'm trying to create a shell script getting the <em>process id</em> of the Skype app on my Mac.</p>
<blockquote>
<p>ps -clx | grep 'Skype' | awk '{print $2}' | head -1</p>
</blockquote>
<p>The above is working fine, but there are two problems:</p>
<p><strong>1)</strong>
The <em>grep</em> command would get all p... | 19,913 | 617,413 | 2020-01-10 17:31:36 | 9,417,296 | 14 | 2012-02-23 16:44:07 | 368,630 | 2012-02-23 16:44:07 | https://stackoverflow.com/q/9415740 | https://stackoverflow.com/a/9417296 | <p>Your <code>ps -cl1</code> output looks like this:</p>
<pre><code> UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD
501 185 172 104 0 31 0 2453272 1728 - S ffffff80145c5ec0 ?? 0:00.00 httpd
501 303 1 80004004 0 31 0... | <p>Your <code>ps -cl1</code> output looks like this:</p> <pre><code> UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD 501 185 172 104 0 31 0 2453272 1728 - S ffffff80145c5ec0 ?? 0:00.00 httpd 501 303 1 80004004 0 31 0... | 369, 387, 990, 1271 | awk, bash, grep, macos | <h1>How to get process id from process name?</h1>
<p>I'm trying to create a shell script getting the <em>process id</em> of the Skype app on my Mac.</p>
<blockquote>
<p>ps -clx | grep 'Skype' | awk '{print $2}' | head -1</p>
</blockquote>
<p>The above is working fine, but there are two problems:</p>
<p><strong>1)<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,771 | bash | # How to get process id from process name?
I'm trying to create a shell script getting the *process id* of the Skype app on my Mac.
> ps -clx | grep 'Skype' | awk '{print $2}' | head -1
The above is working fine, but there are two problems:
**1)**
The *grep* command would get all process if their name just contains... | Your `ps -cl1` output looks like this:
```
UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD
501 185 172 104 0 31 0 2453272 1728 - S ffffff80145c5ec0 ?? 0:00.00 httpd
501 303 1 80004004 0 31 0 2456440 1656 - S... |
7158136 | What happens if I name a bash script function with the name of a binary located in the PATH? | 10 | 2011-08-23 08:25:22 | <p>Suppose I write a function in a bash script, with the name of an available binary, say, pwd:</p>
<pre><code>function pwd(){
echo '/'
}
</code></pre>
<p>Alright, that seems a bit weird, but the question is: what will happen if further in my script I write the commands:</p>
<pre><code>cd /usr
pwd
</code></pre>
... | 3,062 | 508,035 | 2011-08-23 08:39:59 | 7,158,210 | 14 | 2011-08-23 08:32:04 | 665,901 | 2011-08-23 08:39:59 | https://stackoverflow.com/q/7158136 | https://stackoverflow.com/a/7158210 | <p>Your function will get called because it hides the <code>pwd</code> builtin.</p>
<p>To force the command to be executed, use the <code>command</code> builtin:</p>
<pre><code>command pwd
</code></pre>
<p>From bash manual:</p>
<pre><code> command [-pVv] command [arg ...]
Run command with args suppress... | <p>Your function will get called because it hides the <code>pwd</code> builtin.</p> <p>To force the command to be executed, use the <code>command</code> builtin:</p> <pre><code>command pwd </code></pre> <p>From bash manual:</p> <pre><code> command [-pVv] command [arg ...] Run command with args suppress... | 58, 387, 390 | bash, linux, shell | <h1>What happens if I name a bash script function with the name of a binary located in the PATH?</h1>
<p>Suppose I write a function in a bash script, with the name of an available binary, say, pwd:</p>
<pre><code>function pwd(){
echo '/'
}
</code></pre>
<p>Alright, that seems a bit weird, but the question is: wha... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,772 | bash | # What happens if I name a bash script function with the name of a binary located in the PATH?
Suppose I write a function in a bash script, with the name of an available binary, say, pwd:
```
function pwd(){
echo '/'
}
```
Alright, that seems a bit weird, but the question is: what will happen if further in my sc... | Your function will get called because it hides the `pwd` builtin.
To force the command to be executed, use the `command` builtin:
```
command pwd
```
From bash manual:
```
command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function
lookup. Only builtin c... |
6149167 | Executing powershell script file which is a string value | 10 | 2011-05-27 07:28:59 | <p>I have script file Get-ProcesWithParam.ps1 as</p>
<pre><code> param(
$name
)
function List-Process($name)
{
Write-Host "Process List"
get-process -name $name
#get-process
}
List-Process -name $name
</code></pre>
<p>In another script I get this file name as string variable </p>
<pre><code>$scrip... | 11,321 | 214,647 | 2014-04-09 18:48:26 | 6,149,344 | 14 | 2011-05-27 07:51:42 | 307,138 | 2011-05-27 07:51:42 | https://stackoverflow.com/q/6149167 | https://stackoverflow.com/a/6149344 | <p>Try <code>&</code>:</p>
<pre><code>$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
</code></pre>
| <p>Try <code>&</code>:</p> <pre><code>$foo = ".\Get-ProcesWithParam.ps1" $bar="iexplore" & $foo $bar </code></pre> | 526 | powershell | <h1>Executing powershell script file which is a string value</h1>
<p>I have script file Get-ProcesWithParam.ps1 as</p>
<pre><code> param(
$name
)
function List-Process($name)
{
Write-Host "Process List"
get-process -name $name
#get-process
}
List-Process -name $name
</code></pre>
<p>In another scri... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,773 | bash | # Executing powershell script file which is a string value
I have script file Get-ProcesWithParam.ps1 as
```
param(
$name
)
function List-Process($name)
{
Write-Host "Process List"
get-process -name $name
#get-process
}
List-Process -name $name
```
In another script I get this file name as string... | Try `&`:
```
$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
``` |
3286615 | Adding spaces to stdout | 10 | 2010-07-20 02:42:54 | <p>Is it possible to add spaces to the left of every output to stdout (and stderr if possible) when I run commands in a bash shell script?</p>
<p>I'd like to do something like:</p>
<pre><code>#!/bin/bash
echo Installing: Something
echo " => installing prerequisite1"
## INSERT MAGICAL LEFT SPACES COMMAND HERE #... | 12,442 | 14,540 | 2015-08-09 13:36:18 | 3,286,625 | 14 | 2010-07-20 02:45:07 | 14,860 | 2010-07-20 02:56:49 | https://stackoverflow.com/q/3286615 | https://stackoverflow.com/a/3286625 | <p>Yes, you can quote them for simple things:</p>
<pre><code>echo ' => installing prerequisite1'
</code></pre>
<p>and pipe the output through <code>sed</code> for complex things:</p>
<pre><code>tar vzxf lostzilla.tar.gz 2>&1 | sed 's/^/ /'
</code></pre>
<p>The <code>2>&1</code> puts stdout and... | <p>Yes, you can quote them for simple things:</p> <pre><code>echo ' => installing prerequisite1' </code></pre> <p>and pipe the output through <code>sed</code> for complex things:</p> <pre><code>tar vzxf lostzilla.tar.gz 2>&1 | sed 's/^/ /' </code></pre> <p>The <code>2>&1</code> puts stdout and... | 387 | bash | <h1>Adding spaces to stdout</h1>
<p>Is it possible to add spaces to the left of every output to stdout (and stderr if possible) when I run commands in a bash shell script?</p>
<p>I'd like to do something like:</p>
<pre><code>#!/bin/bash
echo Installing: Something
echo " => installing prerequisite1"
## INSERT M... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,774 | bash | # Adding spaces to stdout
Is it possible to add spaces to the left of every output to stdout (and stderr if possible) when I run commands in a bash shell script?
I'd like to do something like:
```
#!/bin/bash
echo Installing: Something
echo " => installing prerequisite1"
## INSERT MAGICAL LEFT SPACES COMMAND HER... | Yes, you can quote them for simple things:
```
echo ' => installing prerequisite1'
```
and pipe the output through `sed` for complex things:
```
tar vzxf lostzilla.tar.gz 2>&1 | sed 's/^/ /'
```
The `2>&1` puts stdout and stderr onto the stdout stream and the `sed` replaces every start-of-line marker with thre... |
1769140 | How to iterate over positional parameters in a Bash script? | 10 | 2009-11-20 08:50:48 | <p>Where am I going wrong?</p>
<p>I have some files as follows:</p>
<pre><code>filename_tau.txt
filename_xhpl.txt
filename_fft.txt
filename_PMB_MPI.txt
filename_mpi_tile_io.txt
</code></pre>
<p>I pass <code>tau</code>, <code>xhpl</code>, <code>fft</code>, <code>mpi_tile_io</code> and <code>PMB_MPI</code> as positional ... | 10,851 | 196,093 | 2023-07-19 22:53:03 | 1,769,202 | 14 | 2009-11-20 09:02:59 | 121,394 | 2023-07-19 22:53:03 | https://stackoverflow.com/q/1769140 | https://stackoverflow.com/a/1769202 | <p>Set up your for loop like this. With this syntax, the loop iterates over the positional parameters, assigning each one to 'point' in turn.</p>
<pre class="lang-bash prettyprint-override"><code>for point; do
grep "$str" ${filename}${point}.txt
done
</code></pre>
<p>As explained in <a href="https://www.g... | <p>Set up your for loop like this. With this syntax, the loop iterates over the positional parameters, assigning each one to 'point' in turn.</p> <pre class="lang-bash prettyprint-override"><code>for point; do grep "$str" ${filename}${point}.txt done </code></pre> <p>As explained in <a href="https://www.g... | 387, 531 | bash, scripting | <h1>How to iterate over positional parameters in a Bash script?</h1>
<p>Where am I going wrong?</p>
<p>I have some files as follows:</p>
<pre><code>filename_tau.txt
filename_xhpl.txt
filename_fft.txt
filename_PMB_MPI.txt
filename_mpi_tile_io.txt
</code></pre>
<p>I pass <code>tau</code>, <code>xhpl</code>, <code>fft</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,775 | bash | # How to iterate over positional parameters in a Bash script?
Where am I going wrong?
I have some files as follows:
```
filename_tau.txt
filename_xhpl.txt
filename_fft.txt
filename_PMB_MPI.txt
filename_mpi_tile_io.txt
```
I pass `tau`, `xhpl`, `fft`, `mpi_tile_io` and `PMB_MPI` as positional parameters to script as... | Set up your for loop like this. With this syntax, the loop iterates over the positional parameters, assigning each one to 'point' in turn.
```
for point; do
grep "$str" ${filename}${point}.txt
done
```
As explained in [the documentation](https://www.gnu.org/software/bash/manual/html_node/Looping-Constructs.html#in... |
1267967 | How can I bulk rename files using PowerShell? | 10 | 2009-08-12 18:41:36 | <p>I'm trying to recursively rename a bunch of <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server" rel="noreferrer">TFS</a> folders using <code>tf rename</code>, <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="noreferrer">PowerShell</a> and a regular expression but I'm having some issues with P... | 6,289 | 327 | 2020-01-27 11:28:35 | 1,269,429 | 14 | 2009-08-13 00:25:32 | 153,982 | 2009-08-13 01:04:55 | https://stackoverflow.com/q/1267967 | https://stackoverflow.com/a/1269429 | <p>I would first filter by 5* so you only process names that start with 5. Also, in this case since tf.exe isn't a PowerShell cmdlet, you don't want to use a scriptblock to determine a new name. Just use a grouping expression like so:</p>
<pre><code>dir -filter 5* | foreach { tf rename $_ ($_.Name -replace '^5', '2.3... | <p>I would first filter by 5* so you only process names that start with 5. Also, in this case since tf.exe isn't a PowerShell cmdlet, you don't want to use a scriptblock to determine a new name. Just use a grouping expression like so:</p> <pre><code>dir -filter 5* | foreach { tf rename $_ ($_.Name -replace '^5', '2.3... | 526, 733 | powershell, tfs | <h1>How can I bulk rename files using PowerShell?</h1>
<p>I'm trying to recursively rename a bunch of <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server" rel="noreferrer">TFS</a> folders using <code>tf rename</code>, <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="noreferrer">PowerShell</a> and... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,776 | bash | # How can I bulk rename files using PowerShell?
I'm trying to recursively rename a bunch of [TFS](http://en.wikipedia.org/wiki/Team_Foundation_Server) folders using `tf rename`, [PowerShell](http://en.wikipedia.org/wiki/Windows_PowerShell) and a regular expression but I'm having some issues with PowerShell as I haven'... | I would first filter by 5* so you only process names that start with 5. Also, in this case since tf.exe isn't a PowerShell cmdlet, you don't want to use a scriptblock to determine a new name. Just use a grouping expression like so:
```
dir -filter 5* | foreach { tf rename $_ ($_.Name -replace '^5', '2.3.2')}
```
BTW,... |
75113202 | How do I delete specific history entries in Nushell? | 9 | 2023-01-13 18:32:50 | <p>Given a history like this in Nushell, how do I delete specific entries; e.g. entries 6, 8, and 10?</p>
<pre><code>nu > history
╭────┬────────────────────╮
│ # │ command │
├────┼────────────────────┤
│ 0 │ history --clear │
│ 1 │ php --version │
│ 2 │ composer --version │
│ 3 │ node --versi... | 2,328 | 1,944 | 2023-01-23 09:10:38 | 75,113,734 | 14 | 2023-01-13 19:31:36 | 2,158,479 | 2023-01-13 22:15:14 | https://stackoverflow.com/q/75113202 | https://stackoverflow.com/a/75113734 | <p>nu's <code>history</code> command does not (yet) provide a functionality to delete items similar to bash's <code>history -d</code>. However, you can query where the history file is located using <code>$nu.history-path</code>, then use <code>drop nth</code> to delete the lines in question.</p>
<pre class="lang-bash p... | <p>nu's <code>history</code> command does not (yet) provide a functionality to delete items similar to bash's <code>history -d</code>. However, you can query where the history file is located using <code>$nu.history-path</code>, then use <code>drop nth</code> to delete the lines in question.</p> <pre class="lang-bash p... | 152591 | nushell | <h1>How do I delete specific history entries in Nushell?</h1>
<p>Given a history like this in Nushell, how do I delete specific entries; e.g. entries 6, 8, and 10?</p>
<pre><code>nu > history
╭────┬────────────────────╮
│ # │ command │
├────┼────────────────────┤
│ 0 │ history --clear │
│ 1 │ php --... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,777 | bash | # How do I delete specific history entries in Nushell?
Given a history like this in Nushell, how do I delete specific entries; e.g. entries 6, 8, and 10?
```
nu > history
╭────┬────────────────────╮
│ # │ command │
├────┼────────────────────┤
│ 0 │ history --clear │
│ 1 │ php --version │
│ 2 │ ... | nu's `history` command does not (yet) provide a functionality to delete items similar to bash's `history -d`. However, you can query where the history file is located using `$nu.history-path`, then use `drop nth` to delete the lines in question.
```
open $nu.history-path | lines | drop nth 6 8 10 | save -f $nu.history... |
71160837 | PowerShell Delete folder if exists | 9 | 2022-02-17 15:23:37 | <p>Could you help me again with a powershell script?
I want to check if multiple folders exist, if they exist then delete the complete folder.
Also provide information if the folder has been deleted or information if the folder does not exist.</p>
<p>I now use the script below for multiple files. (thanks to good help)
... | 24,571 | 18,234,055 | 2023-10-31 14:58:21 | 71,162,070 | 14 | 2022-02-17 16:39:20 | 45,375 | 2023-10-31 14:58:21 | https://stackoverflow.com/q/71160837 | https://stackoverflow.com/a/71162070 | <ul>
<li><p>To remove a directory (folder) that <em>has content</em>, you must use the <code>-Recurse</code> switch with <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.management/remove-item" rel="noreferrer"><code>Remove-Item</code></a> - otherwise, an <em>interactive confirmation prompt<... | <ul> <li><p>To remove a directory (folder) that <em>has content</em>, you must use the <code>-Recurse</code> switch with <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.management/remove-item" rel="noreferrer"><code>Remove-Item</code></a> - otherwise, an <em>interactive confirmation prompt<... | 526 | powershell | <h1>PowerShell Delete folder if exists</h1>
<p>Could you help me again with a powershell script?
I want to check if multiple folders exist, if they exist then delete the complete folder.
Also provide information if the folder has been deleted or information if the folder does not exist.</p>
<p>I now use the script belo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,778 | bash | # PowerShell Delete folder if exists
Could you help me again with a powershell script?
I want to check if multiple folders exist, if they exist then delete the complete folder.
Also provide information if the folder has been deleted or information if the folder does not exist.
I now use the script below for multiple ... | - To remove a directory (folder) that *has content*, you must use the `-Recurse` switch with [`Remove-Item`](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/remove-item) - otherwise, an *interactive confirmation prompt* is presented.
- A given path existing doesn't necessarily mean that it... |
68487529 | How to ensure Python prints UTF-8 (and not UTF-16-LE) when piped in PowerShell? | 9 | 2021-07-22 15:26:43 | <p>I want to print text as UTF-8 when piped (to, for example, a file), so on Python 3.7.3 on Windows 10 via PowerShell, I'm doing this:</p>
<pre class="lang-py prettyprint-override"><code>import sys
if not sys.stdout.isatty():
sys.stdout.reconfigure(encoding='utf-8')
print("Mamma mia.")
</code></pre>
<p... | 2,623 | 2,280,091 | 2023-10-13 14:52:40 | 68,488,098 | 14 | 2021-07-22 16:04:48 | 45,375 | 2023-10-13 14:52:40 | https://stackoverflow.com/q/68487529 | https://stackoverflow.com/a/68488098 | <p><strong>Update</strong>:</p>
<ul>
<li><p><strong><a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core)</em></a> v7.4+</strong> now <strong><em>does</em> support raw byte handling with external programs</strong> - see <a href="https://stackoverflow.co... | <p><strong>Update</strong>:</p> <ul> <li><p><strong><a href="https://github.com/PowerShell/PowerShell/blob/master/README.md" rel="nofollow noreferrer"><em>PowerShell (Core)</em></a> v7.4+</strong> now <strong><em>does</em> support raw byte handling with external programs</strong> - see <a href="https://stackoverflow.co... | 16, 526, 8944, 12658 | character-encoding, powershell, python, utf-8 | <h1>How to ensure Python prints UTF-8 (and not UTF-16-LE) when piped in PowerShell?</h1>
<p>I want to print text as UTF-8 when piped (to, for example, a file), so on Python 3.7.3 on Windows 10 via PowerShell, I'm doing this:</p>
<pre class="lang-py prettyprint-override"><code>import sys
if not sys.stdout.isatty():
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,779 | bash | # How to ensure Python prints UTF-8 (and not UTF-16-LE) when piped in PowerShell?
I want to print text as UTF-8 when piped (to, for example, a file), so on Python 3.7.3 on Windows 10 via PowerShell, I'm doing this:
```
import sys
if not sys.stdout.isatty():
sys.stdout.reconfigure(encoding='utf-8')
print("Mamma ... | **Update**:
- **[*PowerShell (Core)*](https://github.com/PowerShell/PowerShell/blob/master/README.md) v7.4+** now ***does* support raw byte handling with external programs** - see [this answer](https://stackoverflow.com/a/59118502/45375).
- The **following therefore applies only to *Windows PowerShell* and *PowerShell... |
57531370 | How to Uninstall-Module of older version | 9 | 2019-08-16 21:32:03 | <p>The system appears to have two (2) versions of PowerShellGet module installed.</p>
<pre><code>Script 2.2 PowerShellGet
Script 1.0.0.1 PowerShellGet
</code></pre>
<p>How can I uninstall the older version? The <code>Uninstall-Module</code> command appears to be looking in the <code>2.2</code> direc... | 15,674 | 447,901 | 2025-06-18 17:57:50 | 57,531,703 | 14 | 2019-08-16 22:13:55 | 2,150,063 | 2019-08-16 23:39:32 | https://stackoverflow.com/q/57531370 | https://stackoverflow.com/a/57531703 | <p><strong>Short answer:</strong></p>
<p>You can't that uninstall something with <code>PowerShellGet</code> if it wasn't installed with <code>PowerShellGet</code>.</p>
<p><strong>Long answer:</strong></p>
<p><code>PowerShellGet v1.0.0.1</code> was installed as a part of Windows, and not using <code>PowerShellGet</co... | <p><strong>Short answer:</strong></p> <p>You can't that uninstall something with <code>PowerShellGet</code> if it wasn't installed with <code>PowerShellGet</code>.</p> <p><strong>Long answer:</strong></p> <p><code>PowerShellGet v1.0.0.1</code> was installed as a part of Windows, and not using <code>PowerShellGet</co... | 526 | powershell | <h1>How to Uninstall-Module of older version</h1>
<p>The system appears to have two (2) versions of PowerShellGet module installed.</p>
<pre><code>Script 2.2 PowerShellGet
Script 1.0.0.1 PowerShellGet
</code></pre>
<p>How can I uninstall the older version? The <code>Uninstall-Module</code> command a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,780 | bash | # How to Uninstall-Module of older version
The system appears to have two (2) versions of PowerShellGet module installed.
```
Script 2.2 PowerShellGet
Script 1.0.0.1 PowerShellGet
```
How can I uninstall the older version? The `Uninstall-Module` command appears to be looking in the `2.2` directory.... | **Short answer:**
You can't that uninstall something with `PowerShellGet` if it wasn't installed with `PowerShellGet`.
**Long answer:**
`PowerShellGet v1.0.0.1` was installed as a part of Windows, and not using `PowerShellGet` (naturally). Hence, why you can't use `PowerShellGet` to `Uninstall-Module` it.
`PowerShe... |
57262158 | Adding SQS redrive policy using AWS CLI command | 9 | 2019-07-29 22:34:58 | <p>I am trying to set redrive policy for SQS using the AWS CLI Command below , but seeing an error related to redrive JSON. Can you please let me know how I can fix this?</p>
<pre><code>redrive_policy="{\"RedrivePolicy\":{\"deadLetterTargetArn\":\"$dlq_arn\",\"maxReceiveCount\":\"15\"}}"
</code></pre>
<p><strong>AWS ... | 8,210 | 1,042,646 | 2022-11-27 16:31:29 | 57,275,796 | 14 | 2019-07-30 16:05:11 | 2,145,693 | 2019-07-30 16:05:11 | https://stackoverflow.com/q/57262158 | https://stackoverflow.com/a/57275796 | <p>Have you tried just creating the JSON in a separate file and passing it as an argument to your AWS CLI command? I find it's difficult to get all of the escaping correct when passing the JSON as a parameter. So you'd basically do it as the example shows in the AWS documentation:</p>
<p><a href="https://docs.aws.amaz... | <p>Have you tried just creating the JSON in a separate file and passing it as an argument to your AWS CLI command? I find it's difficult to get all of the escaping correct when passing the JSON as a parameter. So you'd basically do it as the example shows in the AWS documentation:</p> <p><a href="https://docs.aws.amaz... | 34, 390, 32457, 33388, 64999 | amazon-sqs, amazon-web-services, jenkins, shell, unix | <h1>Adding SQS redrive policy using AWS CLI command</h1>
<p>I am trying to set redrive policy for SQS using the AWS CLI Command below , but seeing an error related to redrive JSON. Can you please let me know how I can fix this?</p>
<pre><code>redrive_policy="{\"RedrivePolicy\":{\"deadLetterTargetArn\":\"$dlq_arn\",\"m... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,781 | bash | # Adding SQS redrive policy using AWS CLI command
I am trying to set redrive policy for SQS using the AWS CLI Command below , but seeing an error related to redrive JSON. Can you please let me know how I can fix this?
```
redrive_policy="{\"RedrivePolicy\":{\"deadLetterTargetArn\":\"$dlq_arn\",\"maxReceiveCount\":\"1... | Have you tried just creating the JSON in a separate file and passing it as an argument to your AWS CLI command? I find it's difficult to get all of the escaping correct when passing the JSON as a parameter. So you'd basically do it as the example shows in the AWS documentation:
<https://docs.aws.amazon.com/cli/latest/... |
53914241 | bash script adding git credentials from bash script | 9 | 2018-12-24 13:44:47 | <p>I need to be able to add git credentials from my to my bash script but can't figure out how to do this.</p>
<pre><code>git clone https://xxxxxxx
</code></pre>
<p>would ask for my username name and password. </p>
<p>how to i pass these in a bash script ?</p>
<p>any pointers would be appreciated</p>
| 22,301 | 6,363,050 | 2018-12-24 21:42:34 | 53,914,312 | 14 | 2018-12-24 13:51:37 | 1,677,270 | 2018-12-24 21:42:34 | https://stackoverflow.com/q/53914241 | https://stackoverflow.com/a/53914312 | <p>For basic HTTP authentication you can:</p>
<ol>
<li><p>Pass credentials inside url:</p>
<pre><code>git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
</code></pre>
<p><strong>WARN</strong> this is not secure: url with credentials can be seen by another user on your machine with <code>ps</code> or ... | <p>For basic HTTP authentication you can:</p> <ol> <li><p>Pass credentials inside url:</p> <pre><code>git clone http://USERNAME:PASSWORD@some_git_server.com/project.git </code></pre> <p><strong>WARN</strong> this is not secure: url with credentials can be seen by another user on your machine with <code>ps</code> or ... | 58, 387, 390, 531 | bash, linux, scripting, shell | <h1>bash script adding git credentials from bash script</h1>
<p>I need to be able to add git credentials from my to my bash script but can't figure out how to do this.</p>
<pre><code>git clone https://xxxxxxx
</code></pre>
<p>would ask for my username name and password. </p>
<p>how to i pass these in a bash script ?... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,782 | bash | # bash script adding git credentials from bash script
I need to be able to add git credentials from my to my bash script but can't figure out how to do this.
```
git clone https://xxxxxxx
```
would ask for my username name and password.
how to i pass these in a bash script ?
any pointers would be appreciated | For basic HTTP authentication you can:
1. Pass credentials inside url:
```
git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
```
**WARN** this is not secure: url with credentials can be seen by another user on your machine with `ps` or `top` utilities when you work with remote repo.
2. U... |
51044312 | Iterate Over Files in Variable Path (Bash) | 9 | 2018-06-26 13:38:46 | <p>I was looking for the best way to find iterate over files in a variables path and came across <a href="https://stackoverflow.com/questions/20796200/how-to-iterate-over-files-in-a-directory-with-bash">this</a> question. </p>
<p>However, this and every other solution I've found uses a literal path rather than a varia... | 4,658 | 4,364,101 | 2018-06-26 14:15:26 | 51,045,097 | 14 | 2018-06-26 14:15:26 | 548,225 | 2018-06-26 14:15:26 | https://stackoverflow.com/q/51044312 | https://stackoverflow.com/a/51045097 | <p>Glob expansion doesn't happen inside quotes (both single and double) in shell.</p>
<p>You should be using this code:</p>
<pre><code>for file in "$path"/*; do
echo "INFO - Checking $file"
[[ -e $file ]] || continue
done
</code></pre>
| <p>Glob expansion doesn't happen inside quotes (both single and double) in shell.</p> <p>You should be using this code:</p> <pre><code>for file in "$path"/*; do echo "INFO - Checking $file" [[ -e $file ]] || continue done </code></pre> | 387, 390, 3889 | bash, glob, shell | <h1>Iterate Over Files in Variable Path (Bash)</h1>
<p>I was looking for the best way to find iterate over files in a variables path and came across <a href="https://stackoverflow.com/questions/20796200/how-to-iterate-over-files-in-a-directory-with-bash">this</a> question. </p>
<p>However, this and every other solutio... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,783 | bash | # Iterate Over Files in Variable Path (Bash)
I was looking for the best way to find iterate over files in a variables path and came across [this](https://stackoverflow.com/questions/20796200/how-to-iterate-over-files-in-a-directory-with-bash) question.
However, this and every other solution I've found uses a literal ... | Glob expansion doesn't happen inside quotes (both single and double) in shell.
You should be using this code:
```
for file in "$path"/*; do
echo "INFO - Checking $file"
[[ -e $file ]] || continue
done
``` |
50156206 | `source ~/.bash_profile` do not works inside a bash script | 9 | 2018-05-03 13:25:41 | <p>This is a script that move a bash file into homepage and load it with source command.</p>
<pre><code># update.sh
#!/bin/bash
cp -f $PWD/bash_profile ~/.bash_profile
source ~/.bash_profile
</code></pre>
<p>It does not work! It update file with <code>cp -f $PWD/bash_profile ~/.bash_profile</code>.</p>
<p>Inside <co... | 13,141 | 1,420,625 | 2021-07-01 03:09:19 | 50,156,308 | 14 | 2018-05-03 13:30:35 | 8,448,272 | 2018-05-03 13:30:35 | https://stackoverflow.com/q/50156206 | https://stackoverflow.com/a/50156308 | <p>From MangeshBiradar <a href="https://stackoverflow.com/questions/16011245/source-files-in-a-bash-script">here</a>:</p>
<p>Execute Shell Script Using <code>. ./</code> (dot space dot slash)</p>
<p>While executing the shell script using “dot space dot slash”, as shown below, it will execute the script in the current... | <p>From MangeshBiradar <a href="https://stackoverflow.com/questions/16011245/source-files-in-a-bash-script">here</a>:</p> <p>Execute Shell Script Using <code>. ./</code> (dot space dot slash)</p> <p>While executing the shell script using “dot space dot slash”, as shown below, it will execute the script in the current... | 387, 151644 | bash, dot-source | <h1>`source ~/.bash_profile` do not works inside a bash script</h1>
<p>This is a script that move a bash file into homepage and load it with source command.</p>
<pre><code># update.sh
#!/bin/bash
cp -f $PWD/bash_profile ~/.bash_profile
source ~/.bash_profile
</code></pre>
<p>It does not work! It update file with <cod... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,784 | bash | # `source ~/.bash_profile` do not works inside a bash script
This is a script that move a bash file into homepage and load it with source command.
```
# update.sh
#!/bin/bash
cp -f $PWD/bash_profile ~/.bash_profile
source ~/.bash_profile
```
It does not work! It update file with `cp -f $PWD/bash_profile ~/.bash_prof... | From MangeshBiradar [here](https://stackoverflow.com/questions/16011245/source-files-in-a-bash-script):
Execute Shell Script Using `. ./` (dot space dot slash)
While executing the shell script using “dot space dot slash”, as shown below, it will execute the script in the current shell without forking a sub shell.
`$... |
47933172 | Is there some way to define a parameterless powershell parameter set? | 9 | 2017-12-21 21:48:56 | <p>I've got some fairly complex functions that I'm writing for a library module, with lots of different ways it can be called. However, it is in fact possible to default all of them, but when I try to call my function with no parameters the call fails because the parameter set cannot be determined. </p>
<p>I would lik... | 2,515 | 307,163 | 2017-12-21 21:59:00 | 47,933,277 | 14 | 2017-12-21 21:59:00 | 1,630,171 | 2017-12-21 21:59:00 | https://stackoverflow.com/q/47933172 | https://stackoverflow.com/a/47933277 | <p>Sure is. Just specify a default parameter set name that isn't used otherwise:</p>
<pre><code>function Foo {
[CmdletBinding(DefaultParameterSetName='x')]
Param(
[Parameter(Mandatory=$true, ParameterSetName='y')]$a,
[Parameter(Mandatory=$false, ParameterSetName='y')]$b,
[Parameter(Mand... | <p>Sure is. Just specify a default parameter set name that isn't used otherwise:</p> <pre><code>function Foo { [CmdletBinding(DefaultParameterSetName='x')] Param( [Parameter(Mandatory=$true, ParameterSetName='y')]$a, [Parameter(Mandatory=$false, ParameterSetName='y')]$b, [Parameter(Mand... | 526, 119568 | parameter-sets, powershell | <h1>Is there some way to define a parameterless powershell parameter set?</h1>
<p>I've got some fairly complex functions that I'm writing for a library module, with lots of different ways it can be called. However, it is in fact possible to default all of them, but when I try to call my function with no parameters the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,785 | bash | # Is there some way to define a parameterless powershell parameter set?
I've got some fairly complex functions that I'm writing for a library module, with lots of different ways it can be called. However, it is in fact possible to default all of them, but when I try to call my function with no parameters the call fail... | Sure is. Just specify a default parameter set name that isn't used otherwise:
```
function Foo {
[CmdletBinding(DefaultParameterSetName='x')]
Param(
[Parameter(Mandatory=$true, ParameterSetName='y')]$a,
[Parameter(Mandatory=$false, ParameterSetName='y')]$b,
[Parameter(Mandatory=$true, P... |
47480143 | PowerShell script to take backup of all environment variables & save it in a file | 9 | 2017-11-24 21:19:44 | <p>I am new to PowerShell and recently started learning about some of its commands.</p>
<p>Now I am looking to try adding, editing and deleting any path entry from the environment Path variable (System).</p>
<p>But I am concerned about the case if anything goes wrong, so I want to take backup of all environment varia... | 6,380 | 365,107 | 2024-11-21 05:42:45 | 47,480,515 | 14 | 2017-11-24 22:02:52 | 45,375 | 2023-10-18 22:59:30 | https://stackoverflow.com/q/47480143 | https://stackoverflow.com/a/47480515 | <p>Note: <strong>PowerShell's <code>env:</code> drive only reflects the environment variables of the <em>current process</em></strong> - to <em>persistently</em> change the system's or the current user's environment variables, you must use the .NET framework directly - see <a href="https://stackoverflow.com/a/38928399/... | <p>Note: <strong>PowerShell's <code>env:</code> drive only reflects the environment variables of the <em>current process</em></strong> - to <em>persistently</em> change the system's or the current user's environment variables, you must use the .NET framework directly - see <a href="https://stackoverflow.com/a/38928399/... | 493, 526, 1231, 9013, 9938 | backup, command-line, command-prompt, environment-variables, powershell | <h1>PowerShell script to take backup of all environment variables & save it in a file</h1>
<p>I am new to PowerShell and recently started learning about some of its commands.</p>
<p>Now I am looking to try adding, editing and deleting any path entry from the environment Path variable (System).</p>
<p>But I am concern... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,786 | bash | # PowerShell script to take backup of all environment variables & save it in a file
I am new to PowerShell and recently started learning about some of its commands.
Now I am looking to try adding, editing and deleting any path entry from the environment Path variable (System).
But I am concerned about the case if an... | Note: **PowerShell's `env:` drive only reflects the environment variables of the *current process*** - to *persistently* change the system's or the current user's environment variables, you must use the .NET framework directly - see [this answer](https://stackoverflow.com/a/38928399/45375).
The following snippet, whic... |
43550407 | pip install pickle not working - no such file or directory | 9 | 2017-04-21 19:18:06 | <p>Ubuntu 16.04 LTS, trying to install cpickle with pip. I've searched a bit, haven't found anything useful yet. </p>
<p>PYTHONPATH isn't set.</p>
<h1>Error message</h1>
<pre><code>user@hostname:~$ sudo -H pip3 install cpickle
Collecting cpickle
Using cached cpickle-0.5.tar.gz
Complete output from command pyth... | 75,234 | 2,620,549 | 2020-12-12 20:49:37 | 43,550,927 | 14 | 2017-04-21 19:51:11 | 2,572,645 | 2020-12-12 20:49:37 | https://stackoverflow.com/q/43550407 | https://stackoverflow.com/a/43550927 | <p>Checking on the interweb, I found this</p>
<p><a href="https://i.sstatic.net/si9il.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/si9il.png" alt="enter image description here" /></a></p>
<blockquote>
<p>A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with... | <p>Checking on the interweb, I found this</p> <p><a href="https://i.sstatic.net/si9il.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/si9il.png" alt="enter image description here" /></a></p> <blockquote> <p>A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with... | 16, 58, 387, 5119, 60010 | bash, linux, pip, python, python-3.x | <h1>pip install pickle not working - no such file or directory</h1>
<p>Ubuntu 16.04 LTS, trying to install cpickle with pip. I've searched a bit, haven't found anything useful yet. </p>
<p>PYTHONPATH isn't set.</p>
<h1>Error message</h1>
<pre><code>user@hostname:~$ sudo -H pip3 install cpickle
Collecting cpickle
U... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,787 | bash | # pip install pickle not working - no such file or directory
Ubuntu 16.04 LTS, trying to install cpickle with pip. I've searched a bit, haven't found anything useful yet.
PYTHONPATH isn't set.
# Error message
```
user@hostname:~$ sudo -H pip3 install cpickle
Collecting cpickle
Using cached cpickle-0.5.tar.gz
... | Checking on the interweb, I found this
[](https://i.sstatic.net/si9il.png)
> A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pic... |
41292533 | TFS | VSTS - Custom Build Task execution cannot find VstsTaskSdk.psd1 | 9 | 2016-12-22 22:25:51 | <p>My team is working on a TFS/VSTS custom build task that utilizes the <a href="https://github.com/Microsoft/vsts-task-lib" rel="noreferrer">vsts-task-lib</a>. </p>
<p>We followed the instructions on <a href="https://github.com/Microsoft/vsts-task-lib/blob/master/powershell/Docs/Consuming.md#package-the-sdk-with-the-... | 4,876 | 918,237 | 2017-02-23 16:54:23 | 41,303,360 | 14 | 2016-12-23 14:37:49 | 11,799 | 2017-02-23 16:54:23 | https://stackoverflow.com/q/41292533 | https://stackoverflow.com/a/41303360 | <p>You need to move the SDK files to <code>...\VstsTaskSdk\*</code> rather than them being in a version specific folder. I ran into the same issue and resolved it this way.</p>
| <p>You need to move the SDK files to <code>...\VstsTaskSdk\*</code> rather than them being in a version specific folder. I ran into the same issue and resolved it this way.</p> | 526, 733, 116537 | azure-devops, powershell, tfs | <h1>TFS | VSTS - Custom Build Task execution cannot find VstsTaskSdk.psd1</h1>
<p>My team is working on a TFS/VSTS custom build task that utilizes the <a href="https://github.com/Microsoft/vsts-task-lib" rel="noreferrer">vsts-task-lib</a>. </p>
<p>We followed the instructions on <a href="https://github.com/Microsoft/v... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,788 | bash | # TFS | VSTS - Custom Build Task execution cannot find VstsTaskSdk.psd1
My team is working on a TFS/VSTS custom build task that utilizes the [vsts-task-lib](https://github.com/Microsoft/vsts-task-lib).
We followed the instructions on [this github page](https://github.com/Microsoft/vsts-task-lib/blob/master/powershell... | You need to move the SDK files to `...\VstsTaskSdk\*` rather than them being in a version specific folder. I ran into the same issue and resolved it this way. |
31798580 | Launch Metro style apps using powershell | 9 | 2015-08-03 23:55:01 | <p>I am trying to write a powershell script for windows 10 that will automatically launch a Metro-style app.
The <code>Start-Process</code> cmdlet seems like it should work, but I cannot get it to launch anything unless I provide a path to the <code>.exe</code></p>
<p>For example, the following input works:</p>
<pre>... | 16,831 | 256,232 | 2024-05-20 19:12:21 | 39,490,206 | 14 | 2016-09-14 12:14:40 | null | 2016-09-14 12:14:40 | https://stackoverflow.com/q/31798580 | https://stackoverflow.com/a/39490206 | <p>Store Apps can only be started by the shell. Try this:</p>
<pre><code>explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
</code></pre>
| <p>Store Apps can only be started by the shell. Try this:</p> <pre><code>explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App </code></pre> | 26462, 73157, 84376, 107329, 113708 | appx, powershell-3.0, start-process, uwp, windows-10 | <h1>Launch Metro style apps using powershell</h1>
<p>I am trying to write a powershell script for windows 10 that will automatically launch a Metro-style app.
The <code>Start-Process</code> cmdlet seems like it should work, but I cannot get it to launch anything unless I provide a path to the <code>.exe</code></p>
<p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,789 | bash | # Launch Metro style apps using powershell
I am trying to write a powershell script for windows 10 that will automatically launch a Metro-style app.
The `Start-Process` cmdlet seems like it should work, but I cannot get it to launch anything unless I provide a path to the `.exe`
For example, the following input works... | Store Apps can only be started by the shell. Try this:
```
explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
``` |
38257354 | Preserving PowerShell function return type | 9 | 2016-07-08 00:41:37 | <p>In my PowerShell script I need to call a .NET method with the following signature:</p>
<pre class="lang-cs prettyprint-override"><code>class CustomList : System.Collections.Generic.List<string> { }
interface IProcessor { void Process(CustomList list); }
</code></pre>
<p>I made a helper function to generate ... | 6,315 | 280,778 | 2024-05-17 15:19:58 | 38,257,654 | 14 | 2016-07-08 01:25:46 | 712,649 | 2024-05-17 15:19:58 | https://stackoverflow.com/q/38257354 | https://stackoverflow.com/a/38257654 | <pre><code>return $list
</code></pre>
<p>causes the collection to unravel and get "piped" out one by one. Such is the nature of PowerShell.</p>
<p>You can prevent this, by wrapping the output variable itself in a 1-item array, using the unary array operator <code>,</code>:</p>
<pre><code>return ,$list
</code>... | <pre><code>return $list </code></pre> <p>causes the collection to unravel and get "piped" out one by one. Such is the nature of PowerShell.</p> <p>You can prevent this, by wrapping the output variable itself in a 1-item array, using the unary array operator <code>,</code>:</p> <pre><code>return ,$list </code>... | 526, 2754 | casting, powershell | <h1>Preserving PowerShell function return type</h1>
<p>In my PowerShell script I need to call a .NET method with the following signature:</p>
<pre class="lang-cs prettyprint-override"><code>class CustomList : System.Collections.Generic.List<string> { }
interface IProcessor { void Process(CustomList list); }
</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,790 | bash | # Preserving PowerShell function return type
In my PowerShell script I need to call a .NET method with the following signature:
```
class CustomList : System.Collections.Generic.List<string> { }
interface IProcessor { void Process(CustomList list); }
```
I made a helper function to generate the list:
```
function ... | ```
return $list
```
causes the collection to unravel and get "piped" out one by one. Such is the nature of PowerShell.
You can prevent this, by wrapping the output variable itself in a 1-item array, using the unary array operator `,`:
```
return ,$list
```
Alternatively, use `Write-Output -NoEnumerate` to signal n... |
36126625 | Is there a way to measure how much a shell command used memory? | 9 | 2016-03-21 08:59:35 | <p>Is there a way to measure how much an executed terminal command/operation used memory, like the built-in command <code>time</code> for measuring execution time. I'd like to compare commands with different parameters.</p>
| 2,322 | 5,738,290 | 2017-10-23 18:39:06 | 37,522,183 | 14 | 2016-05-30 09:28:46 | 5,738,290 | 2017-10-23 18:39:06 | https://stackoverflow.com/q/36126625 | https://stackoverflow.com/a/37522183 | <p>I was looking for something like <a href="http://man7.org/linux/man-pages/man1/time.1.html" rel="noreferrer">this</a>.</p>
<p>This is how I used it:</p>
<pre><code>$/usr/bin/time -f "%E %M" *<command>*
</code></pre>
<p>That gave me:<br>
time (%E) - elapsed real time (in [hours:]minutes:seconds);<br>
<strong... | <p>I was looking for something like <a href="http://man7.org/linux/man-pages/man1/time.1.html" rel="noreferrer">this</a>.</p> <p>This is how I used it:</p> <pre><code>$/usr/bin/time -f "%E %M" *<command>* </code></pre> <p>That gave me:<br> time (%E) - elapsed real time (in [hours:]minutes:seconds);<br> <strong... | 58, 387, 390, 391, 1231 | bash, command-line, linux, shell, terminal | <h1>Is there a way to measure how much a shell command used memory?</h1>
<p>Is there a way to measure how much an executed terminal command/operation used memory, like the built-in command <code>time</code> for measuring execution time. I'd like to compare commands with different parameters.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,791 | bash | # Is there a way to measure how much a shell command used memory?
Is there a way to measure how much an executed terminal command/operation used memory, like the built-in command `time` for measuring execution time. I'd like to compare commands with different parameters. | I was looking for something like [this](http://man7.org/linux/man-pages/man1/time.1.html).
This is how I used it:
```
$/usr/bin/time -f "%E %M" *<command>*
```
That gave me:
time (%E) - elapsed real time (in [hours:]minutes:seconds);
**memory (%M) - maximum resident set size of the process during its lifetime, i... |
36991903 | Idle bash script until CTRL+c event is logged | 9 | 2016-05-02 21:22:41 | <p>I have a bash script which does some work, which is done fairly quick.
It should then idle until the user decides to terminate it, followed by some clean-up code.</p>
<p>This is why I trap the <kbd>CTRL</kbd>+<kbd>c</kbd> event with the following code:</p>
<pre><code>control_c()
{
cleanup
exit 0
}
trap contro... | 12,086 | 5,438,714 | 2021-08-21 16:34:55 | 36,991,974 | 14 | 2016-05-02 21:27:11 | 14,122 | 2016-05-02 21:27:11 | https://stackoverflow.com/q/36991903 | https://stackoverflow.com/a/36991974 | <p>Assuming you're connected to a TTY:</p>
<pre><code># idle waiting for abort from user
read -r -d '' _ </dev/tty
</code></pre>
| <p>Assuming you're connected to a TTY:</p> <pre><code># idle waiting for abort from user read -r -d '' _ </dev/tty </code></pre> | 58, 387, 2221, 11847 | bash, ctrl, linux, sleep | <h1>Idle bash script until CTRL+c event is logged</h1>
<p>I have a bash script which does some work, which is done fairly quick.
It should then idle until the user decides to terminate it, followed by some clean-up code.</p>
<p>This is why I trap the <kbd>CTRL</kbd>+<kbd>c</kbd> event with the following code:</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,792 | bash | # Idle bash script until CTRL+c event is logged
I have a bash script which does some work, which is done fairly quick.
It should then idle until the user decides to terminate it, followed by some clean-up code.
This is why I trap the `CTRL`+`c` event with the following code:
```
control_c()
{
cleanup
exit 0
}
t... | Assuming you're connected to a TTY:
```
# idle waiting for abort from user
read -r -d '' _ </dev/tty
``` |
35789888 | Powershell - Exclude folders in Get-ChildItem | 9 | 2016-03-04 06:59:15 | <p>How to exclude folders ? Now I hardcode the folder names but i want it to be more flexible.</p>
<pre><code>foreach($file in Get-ChildItem $fileDirectory -Exclude folderA,folderb)
</code></pre>
| 48,968 | 664,481 | 2022-11-07 20:50:10 | 35,791,155 | 14 | 2016-03-04 08:21:20 | 3,360,416 | 2016-03-04 08:35:10 | https://stackoverflow.com/q/35789888 | https://stackoverflow.com/a/35791155 | <p>"How to exclude folders ?" , if you mean all folders :</p>
<pre><code>get-childitem "$fileDirectory\\*" -file
</code></pre>
<p>but it works only for the first level of $fileDirectory .
This works recursevly :</p>
<pre><code>Get-ChildItem "$fileDirectory\\*" -Recurse | ForEach-Object { if (!($_.PSIsContainer)) ... | <p>"How to exclude folders ?" , if you mean all folders :</p> <pre><code>get-childitem "$fileDirectory\\*" -file </code></pre> <p>but it works only for the first level of $fileDirectory . This works recursevly :</p> <pre><code>Get-ChildItem "$fileDirectory\\*" -Recurse | ForEach-Object { if (!($_.PSIsContainer)) ... | 526 | powershell | <h1>Powershell - Exclude folders in Get-ChildItem</h1>
<p>How to exclude folders ? Now I hardcode the folder names but i want it to be more flexible.</p>
<pre><code>foreach($file in Get-ChildItem $fileDirectory -Exclude folderA,folderb)
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,793 | bash | # Powershell - Exclude folders in Get-ChildItem
How to exclude folders ? Now I hardcode the folder names but i want it to be more flexible.
```
foreach($file in Get-ChildItem $fileDirectory -Exclude folderA,folderb)
``` | "How to exclude folders ?" , if you mean all folders :
```
get-childitem "$fileDirectory\\*" -file
```
but it works only for the first level of $fileDirectory .
This works recursevly :
```
Get-ChildItem "$fileDirectory\\*" -Recurse | ForEach-Object { if (!($_.PSIsContainer)) { $_}}
```
or
```
Get-ChildItem "$fil... |
35274597 | Store mysql result in a bash array variable | 9 | 2016-02-08 16:35:27 | <p>I am trying to store MySQL result into a global bash array variable but I don't know how to do it.</p>
<p>Should I save the MySQL command result in a file and read the file line by line in my <code>for</code> loop for my other treatment?</p>
<p>Example:</p>
<pre><code>user password
Pierre aaa
Paul bbb
</code></pr... | 21,515 | 4,567,796 | 2024-10-05 13:00:37 | 35,276,157 | 14 | 2016-02-08 17:57:31 | 1,765,658 | 2024-10-05 13:00:37 | https://stackoverflow.com/q/35274597 | https://stackoverflow.com/a/35276157 | <h2>Mapfile for containing whole table into one bash variable</h2>
<p>You could try this:</p>
<pre class="lang-bash prettyprint-override"><code>mapfile result < <(mysql –uroot –ppwd –se "SELECT * from users;")
</code></pre>
<p>Than</p>
<pre class="lang-bash prettyprint-override"><code>echo ${result[0]%... | <h2>Mapfile for containing whole table into one bash variable</h2> <p>You could try this:</p> <pre class="lang-bash prettyprint-override"><code>mapfile result < <(mysql –uroot –ppwd –se "SELECT * from users;") </code></pre> <p>Than</p> <pre class="lang-bash prettyprint-override"><code>echo ${result[0]%... | 21, 387 | bash, mysql | <h1>Store mysql result in a bash array variable</h1>
<p>I am trying to store MySQL result into a global bash array variable but I don't know how to do it.</p>
<p>Should I save the MySQL command result in a file and read the file line by line in my <code>for</code> loop for my other treatment?</p>
<p>Example:</p>
<pr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,794 | bash | # Store mysql result in a bash array variable
I am trying to store MySQL result into a global bash array variable but I don't know how to do it.
Should I save the MySQL command result in a file and read the file line by line in my `for` loop for my other treatment?
Example:
```
user password
Pierre aaa
Paul bbb
```... | ## Mapfile for containing whole table into one bash variable
You could try this:
```
mapfile result < <(mysql –uroot –ppwd –se "SELECT * from users;")
```
Than
```
echo ${result[0]%$'\t'*}
echo ${result[0]#*$'\t'}
```
or
```
for row in "${result[@]}";do
echo Name: ${row%$'\t'*} pass: ${row#*$'\t'}
done
```... |
33823151 | Union and Intersection of Hashtables in PowerShell | 9 | 2015-11-20 09:28:20 | <p>In <em><a href="https://stackoverflow.com/questions/8609204/union-and-intersection-in-powershell">Union and Intersection in PowerShell?</a></em> cool one-liners for set operations of arrays are described.</p>
<p>I want to do this with hashtables and have a solution using the keysets of the dictionaries. To extend t... | 4,197 | 914,053 | 2024-04-16 19:54:29 | 33,839,784 | 14 | 2015-11-21 04:39:04 | 2,460,798 | 2015-11-21 04:39:04 | https://stackoverflow.com/q/33823151 | https://stackoverflow.com/a/33839784 | <p>You can use the same technique as for lists, but use the hash table keys, as you indicate in the OP. </p>
<p>For union and intersection you have an additional problem. Of the keys in common between the two hash tables, which value will you keep? Assume you will always keep the value in the first hash table. Then:<... | <p>You can use the same technique as for lists, but use the hash table keys, as you indicate in the OP. </p> <p>For union and intersection you have an additional problem. Of the keys in common between the two hash tables, which value will you keep? Assume you will always keep the value in the first hash table. Then:<... | 526 | powershell | <h1>Union and Intersection of Hashtables in PowerShell</h1>
<p>In <em><a href="https://stackoverflow.com/questions/8609204/union-and-intersection-in-powershell">Union and Intersection in PowerShell?</a></em> cool one-liners for set operations of arrays are described.</p>
<p>I want to do this with hashtables and have a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,795 | bash | # Union and Intersection of Hashtables in PowerShell
In *[Union and Intersection in PowerShell?](https://stackoverflow.com/questions/8609204/union-and-intersection-in-powershell)* cool one-liners for set operations of arrays are described.
I want to do this with hashtables and have a solution using the keysets of the... | You can use the same technique as for lists, but use the hash table keys, as you indicate in the OP.
For union and intersection you have an additional problem. Of the keys in common between the two hash tables, which value will you keep? Assume you will always keep the value in the first hash table. Then:
```
# need ... |
26932672 | Broken tab completion on make under linux | 9 | 2014-11-14 14:53:14 | <p>I have no idea how tab completion works, but all of a sudden mine is broken. I don't even know what info to provide other than the use case.
there is a target <code>clean</code> in the makefile.</p>
<p><code>$ make c<tab></code> results in </p>
<p><code>$ make c23:set: command not found
lean
</code></p>
<p>... | 3,465 | 786,559 | 2017-08-30 11:46:28 | 31,288,089 | 14 | 2015-07-08 09:03:26 | 786,559 | 2015-07-08 15:51:10 | https://stackoverflow.com/q/26932672 | https://stackoverflow.com/a/31288089 | <p>thanks to <a href="https://stackoverflow.com/questions/26932672/broken-tab-completion-on-make-under-linux?noredirect=1#comment50554123_26932672">Etan's comment</a> and Aaron's indication of where makefiles are, I managed to debug this.</p>
<p>I ran <code>set -x</code> so I could track what was happening when doing ... | <p>thanks to <a href="https://stackoverflow.com/questions/26932672/broken-tab-completion-on-make-under-linux?noredirect=1#comment50554123_26932672">Etan's comment</a> and Aaron's indication of where makefiles are, I managed to debug this.</p> <p>I ran <code>set -x</code> so I could track what was happening when doing ... | 58, 387, 4301, 12891 | bash, linux, makefile, tab-completion | <h1>Broken tab completion on make under linux</h1>
<p>I have no idea how tab completion works, but all of a sudden mine is broken. I don't even know what info to provide other than the use case.
there is a target <code>clean</code> in the makefile.</p>
<p><code>$ make c<tab></code> results in </p>
<p><code>$ ma... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,796 | bash | # Broken tab completion on make under linux
I have no idea how tab completion works, but all of a sudden mine is broken. I don't even know what info to provide other than the use case.
there is a target `clean` in the makefile.
`$ make c<tab>` results in
`$ make c23:set: command not found
lean`
**EDIT:**
I believe ... | thanks to [Etan's comment](https://stackoverflow.com/questions/26932672/broken-tab-completion-on-make-under-linux?noredirect=1#comment50554123_26932672) and Aaron's indication of where makefiles are, I managed to debug this.
I ran `set -x` so I could track what was happening when doing the tab completion. The output o... |
29932604 | grep: Invalid regular expression | 9 | 2015-04-29 01:04:39 | <p>I have a text file which looks like this:</p>
<pre><code>haha1,haha2,haha3,haha4
test1,test2,test3,test4,[offline],test5
letter1,letter2,letter3,letter4
output1,output2,[offline],output3,output4
check1,[core],check2
num1,num2,num3,num4
</code></pre>
<p>I need to exclude all those lines that have "[ ]" and output t... | 9,813 | 4,472,008 | 2015-04-29 04:33:20 | 29,932,634 | 14 | 2015-04-29 01:06:47 | 68,587 | 2015-04-29 01:06:47 | https://stackoverflow.com/q/29932604 | https://stackoverflow.com/a/29932634 | <p>Use <code>grep -F</code> to treat the search pattern as a fixed string. You could also replace <code>wc -l</code> with <code>grep -c</code>.</p>
<pre><code>grep -cF ",[" loaded.txt > newloaded.txt
</code></pre>
<p>If you're curious, <code>[</code> is a special character. If you don't use <code>-F</code> then yo... | <p>Use <code>grep -F</code> to treat the search pattern as a fixed string. You could also replace <code>wc -l</code> with <code>grep -c</code>.</p> <pre><code>grep -cF ",[" loaded.txt > newloaded.txt </code></pre> <p>If you're curious, <code>[</code> is a special character. If you don't use <code>-F</code> then yo... | 58, 387, 390, 1271, 17938 | bash, grep, linux, shell, text-files | <h1>grep: Invalid regular expression</h1>
<p>I have a text file which looks like this:</p>
<pre><code>haha1,haha2,haha3,haha4
test1,test2,test3,test4,[offline],test5
letter1,letter2,letter3,letter4
output1,output2,[offline],output3,output4
check1,[core],check2
num1,num2,num3,num4
</code></pre>
<p>I need to exclude al... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,797 | bash | # grep: Invalid regular expression
I have a text file which looks like this:
```
haha1,haha2,haha3,haha4
test1,test2,test3,test4,[offline],test5
letter1,letter2,letter3,letter4
output1,output2,[offline],output3,output4
check1,[core],check2
num1,num2,num3,num4
```
I need to exclude all those lines that have "[ ]" and... | Use `grep -F` to treat the search pattern as a fixed string. You could also replace `wc -l` with `grep -c`.
```
grep -cF ",[" loaded.txt > newloaded.txt
```
If you're curious, `[` is a special character. If you don't use `-F` then you'll need to escape it with a backslash.
```
grep -c ",\[" loaded.txt > newloaded.tx... |
29082466 | check IPs if they exist in /etc/hosts | 9 | 2015-03-16 16:49:29 | <p>I am trying to create a .sh script that checks if some IP/Domain like "teamspeak.com" exists in /etc/hosts and if it does not then I want to add something to the hosts file.</p>
<p>Right now I am trying this with:</p>
<pre><code>if ! grep -q "teamspeak.com == teamspeak.com" /etc/hosts; then
echo "Exists"
else
... | 4,990 | 3,472,305 | 2015-03-16 17:11:42 | 29,082,739 | 14 | 2015-03-16 17:03:28 | 1,310,995 | 2015-03-16 17:11:42 | https://stackoverflow.com/q/29082466 | https://stackoverflow.com/a/29082739 | <pre><code>grep -q
</code></pre>
<p>exits with 0 if any match is found, otherwise it exits with 1 so you need to remove ! and == comparison:</p>
<pre><code>if grep -q "teamspeak.com" /etc/hosts; then
echo "Exists"
else
echo "Add to etc host ting here" >> /etc/hosts;
fi
</code></pre>
<p>Note that it is... | <pre><code>grep -q </code></pre> <p>exits with 0 if any match is found, otherwise it exits with 1 so you need to remove ! and == comparison:</p> <pre><code>if grep -q "teamspeak.com" /etc/hosts; then echo "Exists" else echo "Add to etc host ting here" >> /etc/hosts; fi </code></pre> <p>Note that it is... | 58, 387, 10327, 87902 | bash, linux, sh, synology | <h1>check IPs if they exist in /etc/hosts</h1>
<p>I am trying to create a .sh script that checks if some IP/Domain like "teamspeak.com" exists in /etc/hosts and if it does not then I want to add something to the hosts file.</p>
<p>Right now I am trying this with:</p>
<pre><code>if ! grep -q "teamspeak.com == teamspea... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,798 | bash | # check IPs if they exist in /etc/hosts
I am trying to create a .sh script that checks if some IP/Domain like "teamspeak.com" exists in /etc/hosts and if it does not then I want to add something to the hosts file.
Right now I am trying this with:
```
if ! grep -q "teamspeak.com == teamspeak.com" /etc/hosts; then
... | ```
grep -q
```
exits with 0 if any match is found, otherwise it exits with 1 so you need to remove ! and == comparison:
```
if grep -q "teamspeak.com" /etc/hosts; then
echo "Exists"
else
echo "Add to etc host ting here" >> /etc/hosts;
fi
```
Note that it is not word based search so it finds myteamspeak.com ... |
23201024 | Externally-located 'npm run' scripts in package.json on Windows? | 9 | 2014-04-21 16:05:15 | <p>As we know, you can run arbitrary commands using <code>npm run</code> by adding a <code>scripts</code> hash to your <code>package.json</code>:</p>
<pre><code>"scripts": {
"build-js": "browserify browser/main.js | uglifyjs -mc > static/bundle.js"
}
</code></pre>
<p>Which would then be run with <code>npm run ... | 9,327 | null | 2017-08-07 09:16:33 | 28,047,101 | 14 | 2015-01-20 13:55:54 | 1,971,662 | 2016-10-28 06:30:27 | https://stackoverflow.com/q/23201024 | https://stackoverflow.com/a/28047101 | <p>From <a href="https://processwire.com/talk/topic/8681-how-to-use-npm-as-a-build-tool-replacing-gruntgulp/" rel="noreferrer">a helpful article</a> on using NPM as a build tool, why not simply use a JavaScript file? </p>
<p>Here's the example given in the article (slightly modified for clarity): </p>
<pre><code>// s... | <p>From <a href="https://processwire.com/talk/topic/8681-how-to-use-npm-as-a-build-tool-replacing-gruntgulp/" rel="noreferrer">a helpful article</a> on using NPM as a build tool, why not simply use a JavaScript file? </p> <p>Here's the example given in the article (slightly modified for clarity): </p> <pre><code>// s... | 3, 64, 387, 46426, 61387 | bash, javascript, node.js, npm, windows | <h1>Externally-located 'npm run' scripts in package.json on Windows?</h1>
<p>As we know, you can run arbitrary commands using <code>npm run</code> by adding a <code>scripts</code> hash to your <code>package.json</code>:</p>
<pre><code>"scripts": {
"build-js": "browserify browser/main.js | uglifyjs -mc > static/... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,799 | bash | # Externally-located 'npm run' scripts in package.json on Windows?
As we know, you can run arbitrary commands using `npm run` by adding a `scripts` hash to your `package.json`:
```
"scripts": {
"build-js": "browserify browser/main.js | uglifyjs -mc > static/bundle.js"
}
```
Which would then be run with `npm run ... | From [a helpful article](https://processwire.com/talk/topic/8681-how-to-use-npm-as-a-build-tool-replacing-gruntgulp/) on using NPM as a build tool, why not simply use a JavaScript file?
Here's the example given in the article (slightly modified for clarity):
```
// scripts/favicon.js
var favicons = require('favicons... |
26431682 | Why cant I have a space between option and optional argument using getopt? | 9 | 2014-10-17 18:59:59 | <p>When using getopt to parse commandline parameters you can put a space in between the option flag and the argument for required arguments but not for optional arguments. Optional arguments will only be parsed if they are right after the option.</p>
<pre><code>TEMP=`getopt -o p:q:: -n 'mkqueue.sh' -- "$@"`
if [ $? !... | 6,334 | 958,490 | 2014-10-17 22:09:56 | 26,432,578 | 14 | 2014-10-17 19:58:49 | 1,566,221 | 2014-10-17 22:09:56 | https://stackoverflow.com/q/26431682 | https://stackoverflow.com/a/26432578 | <p>That limitation is documented in the manpage for <code>getopt</code>:</p>
<blockquote>
<p>A simple short option is a `-' followed by a short option character. If the option has a required argument, it may be written directly after the option character or as the next parameter (ie. separated by whitespace ... | <p>That limitation is documented in the manpage for <code>getopt</code>:</p> <blockquote> <p>A simple short option is a `-' followed by a short option character. If the option has a required argument, it may be written directly after the option character or as the next parameter (ie. separated by whitespace ... | 387, 10831 | bash, getopt | <h1>Why cant I have a space between option and optional argument using getopt?</h1>
<p>When using getopt to parse commandline parameters you can put a space in between the option flag and the argument for required arguments but not for optional arguments. Optional arguments will only be parsed if they are right after t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,800 | bash | # Why cant I have a space between option and optional argument using getopt?
When using getopt to parse commandline parameters you can put a space in between the option flag and the argument for required arguments but not for optional arguments. Optional arguments will only be parsed if they are right after the option... | That limitation is documented in the manpage for `getopt`:
> A simple short option is a `-' followed by a short option character. If the option has a required argument, it may be written directly after the option character or as the next parameter (ie. separated by whitespace on the command line). **If the option has ... |
25089210 | App Pool advanced settings using Powershell Desired Configuration State | 9 | 2014-08-01 21:51:50 | <p>How can I modify various settings inside either a new or exisitng App Pool using Powershell? </p>
<p>I am interesting in some of the "Advanced" settings such as Enable 32-Bit Applications, Managed Pipeline Mode, Process Model Identity, etc. Any ideas on how I can do this? I tried using the xWebAdministration module... | 15,353 | 3,897,176 | 2019-07-01 07:32:04 | 25,387,981 | 14 | 2014-08-19 15:59:51 | 201,990 | 2015-01-31 19:09:49 | https://stackoverflow.com/q/25089210 | https://stackoverflow.com/a/25387981 | <p>Yes, a custom DSC resource is the only way to do this with DSC. If you are able to use PowerShell scripting without DSC, you can use the <a href="http://technet.microsoft.com/en-us/library/ee790599.aspx">WebAdministration module</a> module to create the pool, and then modify it from there. </p>
<pre><code>$appPoolN... | <p>Yes, a custom DSC resource is the only way to do this with DSC. If you are able to use PowerShell scripting without DSC, you can use the <a href="http://technet.microsoft.com/en-us/library/ee790599.aspx">WebAdministration module</a> module to create the pool, and then modify it from there. </p> <pre><code>$appPoolN... | 215, 526, 10223, 103292 | application-pool, dsc, iis, powershell | <h1>App Pool advanced settings using Powershell Desired Configuration State</h1>
<p>How can I modify various settings inside either a new or exisitng App Pool using Powershell? </p>
<p>I am interesting in some of the "Advanced" settings such as Enable 32-Bit Applications, Managed Pipeline Mode, Process Model Identity,... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,801 | bash | # App Pool advanced settings using Powershell Desired Configuration State
How can I modify various settings inside either a new or exisitng App Pool using Powershell?
I am interesting in some of the "Advanced" settings such as Enable 32-Bit Applications, Managed Pipeline Mode, Process Model Identity, etc. Any ideas o... | Yes, a custom DSC resource is the only way to do this with DSC. If you are able to use PowerShell scripting without DSC, you can use the [WebAdministration module](http://technet.microsoft.com/en-us/library/ee790599.aspx) module to create the pool, and then modify it from there.
```
$appPoolName = "MyAppPool"
New-WebA... |
23977475 | Running a shell command from a flask app | 9 | 2014-06-01 06:56:36 | <p>I'm trying to run a shell command from a flask app and trying to grab the output. The app I'm trying with is following:</p>
<pre><code>from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def hello():
cmd = ["ls"," -l"]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
... | 18,780 | 1,310,692 | 2019-06-23 21:50:01 | 23,977,489 | 14 | 2014-06-01 06:59:25 | 2,225,682 | 2016-08-29 22:36:25 | https://stackoverflow.com/q/23977475 | https://stackoverflow.com/a/23977489 | <p>It's a simple typo. <code>cd</code> in the following line should be <code>cmd</code>:</p>
<pre><code>p = subprocess.Popen(cd, # <----
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
</code></pre>
<p><strong>UPDATE</strong></p>... | <p>It's a simple typo. <code>cd</code> in the following line should be <code>cmd</code>:</p> <pre><code>p = subprocess.Popen(cd, # <---- stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) </code></pre> <p><strong>UPDATE</strong></p>... | 16, 390, 54712 | flask, python, shell | <h1>Running a shell command from a flask app</h1>
<p>I'm trying to run a shell command from a flask app and trying to grab the output. The app I'm trying with is following:</p>
<pre><code>from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def hello():
cmd = ["ls"," -l"]
p = subp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,802 | bash | # Running a shell command from a flask app
I'm trying to run a shell command from a flask app and trying to grab the output. The app I'm trying with is following:
```
from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def hello():
cmd = ["ls"," -l"]
p = subprocess.Popen(cmd, st... | It's a simple typo. `cd` in the following line should be `cmd`:
```
p = subprocess.Popen(cd, # <----
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
```
**UPDATE**
There's another typo; remove a space in the second item:
```
cmd =... |
23522557 | Set permissions and settings on IIS FTP site using PowerShell | 9 | 2014-05-07 15:51:51 | <p>I am beginner in PowerShell I try this script and worked well but I need to change the FTP Authorization Rules to "All Users" (Read,Write) and change "FTP user Isolation" to "User Name Directory".</p>
<pre><code>## NEEDED FOR IIS CMDLETS
Import-Module WebAdministration
## CREATE FTP SITE AND SET C:\inetpub\f... | 13,964 | 3,612,940 | 2019-09-09 07:11:38 | 23,534,136 | 14 | 2014-05-08 06:18:25 | 3,612,940 | 2014-05-10 16:19:13 | https://stackoverflow.com/q/23522557 | https://stackoverflow.com/a/23534136 | <p>After search a long time finally find the solution It will be</p>
<pre><code> ## NEEDED FOR IIS CMDLETS
Import-Module WebAdministration
## CREATE FTP SITE AND SET C:\inetpub\ftproot AS HOME DIRECTORY
New-WebFtpSite -Name "test" -Port "21" -Force
cmd /c \Windows\System32\inetsrv\appcmd set SITE "test" "-virtu... | <p>After search a long time finally find the solution It will be</p> <pre><code> ## NEEDED FOR IIS CMDLETS Import-Module WebAdministration ## CREATE FTP SITE AND SET C:\inetpub\ftproot AS HOME DIRECTORY New-WebFtpSite -Name "test" -Port "21" -Force cmd /c \Windows\System32\inetsrv\appcmd set SITE "test" "-virtu... | 215, 261, 526 | ftp, iis, powershell | <h1>Set permissions and settings on IIS FTP site using PowerShell</h1>
<p>I am beginner in PowerShell I try this script and worked well but I need to change the FTP Authorization Rules to "All Users" (Read,Write) and change "FTP user Isolation" to "User Name Directory".</p>
<pre><code>## NEEDED FOR IIS CMDLETS
Impo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,803 | bash | # Set permissions and settings on IIS FTP site using PowerShell
I am beginner in PowerShell I try this script and worked well but I need to change the FTP Authorization Rules to "All Users" (Read,Write) and change "FTP user Isolation" to "User Name Directory".
```
## NEEDED FOR IIS CMDLETS
Import-Module WebAdminis... | After search a long time finally find the solution It will be
```
## NEEDED FOR IIS CMDLETS
Import-Module WebAdministration
## CREATE FTP SITE AND SET C:\inetpub\ftproot AS HOME DIRECTORY
New-WebFtpSite -Name "test" -Port "21" -Force
cmd /c \Windows\System32\inetsrv\appcmd set SITE "test" "-virtualDirectoryDef... |
22386203 | no newline in echo/printf in BASH while loop | 9 | 2014-03-13 17:22:23 | <p>why on executing following script each printf (tried also with echo) is printed on the same line??</p>
<pre><code>function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | \
{ while read_dom; do
printf "(entity:content %s:%s)" $ENTITY $CONTENT
}
</code></pre>
<p... | 24,443 | 2,144,057 | 2014-03-13 17:23:58 | 22,386,249 | 14 | 2014-03-13 17:23:47 | 1,518,087 | 2014-03-13 17:23:47 | https://stackoverflow.com/q/22386203 | https://stackoverflow.com/a/22386249 | <p>You'll just need to add the newline character, <code>\n</code>, to the <code>printf</code> statement:</p>
<pre><code>printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
</code></pre>
| <p>You'll just need to add the newline character, <code>\n</code>, to the <code>printf</code> statement:</p> <pre><code>printf "(entity:content %s:%s)\n" $ENTITY $CONTENT </code></pre> | 387, 1156, 3705, 13824, 17310 | bash, echo, newline, printf, while-loop | <h1>no newline in echo/printf in BASH while loop</h1>
<p>why on executing following script each printf (tried also with echo) is printed on the same line??</p>
<pre><code>function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | \
{ while read_dom; do
printf "(entit... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,804 | bash | # no newline in echo/printf in BASH while loop
why on executing following script each printf (tried also with echo) is printed on the same line??
```
function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | \
{ while read_dom; do
printf "(entity:content %s:%s)" $ENTITY ... | You'll just need to add the newline character, `\n`, to the `printf` statement:
```
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
``` |
22343187 | Why is an empty PowerShell pipeline not the same as null? | 9 | 2014-03-12 06:00:15 | <p>I am trying to understand the behavior of the @() array constructor, and I came across this very strange test.</p>
<p>It seems that the value of an empty pipeline is "not quite" the same as $null, even though it is -eq $null</p>
<p>The output of each statement is shown after the ###</p>
<pre><code>$y = 1,2,3,4 | ... | 3,448 | 37,572 | 2019-06-24 19:59:55 | 22,365,076 | 14 | 2014-03-12 22:16:06 | 2,797,457 | 2014-03-13 19:27:51 | https://stackoverflow.com/q/22343187 | https://stackoverflow.com/a/22365076 | <p>Expanding on Frode F.'s answer, "nothing" is a mostly magical value in PowerShell - it's called [System.Management.Automation.Internal.AutomationNull]::Value. The following will work similarly:</p>
<pre><code>$y = 1,2,3,4 | ? { $_ -ge 5 }
$y = [System.Management.Automation.Internal.AutomationNull]::Value
</code></... | <p>Expanding on Frode F.'s answer, "nothing" is a mostly magical value in PowerShell - it's called [System.Management.Automation.Internal.AutomationNull]::Value. The following will work similarly:</p> <pre><code>$y = 1,2,3,4 | ? { $_ -ge 5 } $y = [System.Management.Automation.Internal.AutomationNull]::Value </code></... | 526, 694 | null, powershell | <h1>Why is an empty PowerShell pipeline not the same as null?</h1>
<p>I am trying to understand the behavior of the @() array constructor, and I came across this very strange test.</p>
<p>It seems that the value of an empty pipeline is "not quite" the same as $null, even though it is -eq $null</p>
<p>The output of ea... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,805 | bash | # Why is an empty PowerShell pipeline not the same as null?
I am trying to understand the behavior of the @() array constructor, and I came across this very strange test.
It seems that the value of an empty pipeline is "not quite" the same as $null, even though it is -eq $null
The output of each statement is shown a... | Expanding on Frode F.'s answer, "nothing" is a mostly magical value in PowerShell - it's called [System.Management.Automation.Internal.AutomationNull]::Value. The following will work similarly:
```
$y = 1,2,3,4 | ? { $_ -ge 5 }
$y = [System.Management.Automation.Internal.AutomationNull]::Value
```
PowerShell treats t... |
22252226 | Passport local strategy and cURL | 9 | 2014-03-07 14:04:10 | <p>I would like to test my node.js + express + passport.js test application (RESTful) with CURL. My code:</p>
<pre><code>var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var passport = require('passport');
var LocalStrategy = require('passport-... | 3,790 | 2,081,129 | 2015-12-05 19:47:21 | 22,253,261 | 14 | 2014-03-07 14:48:09 | 3,142,963 | 2015-12-05 19:47:21 | https://stackoverflow.com/q/22252226 | https://stackoverflow.com/a/22253261 | <p>First, make <code>curl</code> save cookies when you log in with</p>
<pre><code>curl --cookie-jar jarfile --data "username=admin&password=admin" http://localhost:3000/login
</code></pre>
<p>Read the stored cookies when accessing <code>/test</code>:</p>
<pre><code>curl --cookie jarfile "http://localhost:3000/t... | <p>First, make <code>curl</code> save cookies when you log in with</p> <pre><code>curl --cookie-jar jarfile --data "username=admin&password=admin" http://localhost:3000/login </code></pre> <p>Read the stored cookies when accessing <code>/test</code>:</p> <pre><code>curl --cookie jarfile "http://localhost:3000/t... | 1554, 46426, 61874, 62301, 106662 | curl, express, git-bash, node.js, passport.js | <h1>Passport local strategy and cURL</h1>
<p>I would like to test my node.js + express + passport.js test application (RESTful) with CURL. My code:</p>
<pre><code>var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var passport = require('passport... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,806 | bash | # Passport local strategy and cURL
I would like to test my node.js + express + passport.js test application (RESTful) with CURL. My code:
```
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var passport = require('passport');
var LocalStrateg... | First, make `curl` save cookies when you log in with
```
curl --cookie-jar jarfile --data "username=admin&password=admin" http://localhost:3000/login
```
Read the stored cookies when accessing `/test`:
```
curl --cookie jarfile "http://localhost:3000/test"
```
Some modifications to the app itself were needed before... |
21946679 | How to publish/approve a page in SharePoint 2010 from powershell | 9 | 2014-02-21 22:44:02 | <p>I have a list urls for specific SharePoint 2010 pages. I can visit each page and click the publish button. Then approve button to publish the pages.</p>
<p>I am trying to automate the process. I am wondering if there is any way to do that from powershell?</p>
| 8,673 | 322,848 | 2014-02-23 15:29:34 | 21,970,233 | 14 | 2014-02-23 15:29:34 | 210,462 | 2014-02-23 15:29:34 | https://stackoverflow.com/q/21946679 | https://stackoverflow.com/a/21970233 | <p>The script bellow should do it:</p>
<pre><code>$web = Get-SPWeb http://demo2010a:20905
$pages = "http://demo2010a:20905/Pages/TvAndRadioAlerts.aspx","http://demo2010a:20905/Pages/Systems.aspx"
$pages | ForEach-Object {
$item = $web.GetListItem($_)
if ($item.File.CheckOutType -ne "None")
{
$item.File... | <p>The script bellow should do it:</p> <pre><code>$web = Get-SPWeb http://demo2010a:20905 $pages = "http://demo2010a:20905/Pages/TvAndRadioAlerts.aspx","http://demo2010a:20905/Pages/Systems.aspx" $pages | ForEach-Object { $item = $web.GetListItem($_) if ($item.File.CheckOutType -ne "None") { $item.File... | 526, 669, 35343 | powershell, sharepoint, sharepoint-2010 | <h1>How to publish/approve a page in SharePoint 2010 from powershell</h1>
<p>I have a list urls for specific SharePoint 2010 pages. I can visit each page and click the publish button. Then approve button to publish the pages.</p>
<p>I am trying to automate the process. I am wondering if there is any way to do that fro... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,807 | bash | # How to publish/approve a page in SharePoint 2010 from powershell
I have a list urls for specific SharePoint 2010 pages. I can visit each page and click the publish button. Then approve button to publish the pages.
I am trying to automate the process. I am wondering if there is any way to do that from powershell? | The script bellow should do it:
```
$web = Get-SPWeb http://demo2010a:20905
$pages = "http://demo2010a:20905/Pages/TvAndRadioAlerts.aspx","http://demo2010a:20905/Pages/Systems.aspx"
$pages | ForEach-Object {
$item = $web.GetListItem($_)
if ($item.File.CheckOutType -ne "None")
{
$item.File.CheckIn("Auto... |
21739926 | FileInfo.BaseName exists in PowerShell but not in straight .NET | 9 | 2014-02-12 21:20:59 | <p>Why is it that in .NET the <code>System.IO.FileInfo</code> object does not have a <code>BaseName</code> property, but I can use the property through PowerShell, e.g.:</p>
<pre><code>$FolderItems = Get-ChildItem -Path "C:\" | Where-Object {$_ -isnot [IO.DirectoryInfo]}
foreach ($FolderItem in $FolderItems)
{
wr... | 3,677 | 2,704,659 | 2016-03-28 13:04:47 | 21,740,207 | 14 | 2014-02-12 21:36:01 | 574,168 | 2014-02-12 21:36:01 | https://stackoverflow.com/q/21739926 | https://stackoverflow.com/a/21740207 | <p>Powershell adds that property for you. If you run get-member on a fileinfo object, you can see that it's a script property, and even the script itself:</p>
<pre><code>get-item testfile1.txt | Get-Member BaseName | format-list
TypeName : System.IO.FileInfo
Name : BaseName
MemberType : ScriptProperty
Defini... | <p>Powershell adds that property for you. If you run get-member on a fileinfo object, you can see that it's a script property, and even the script itself:</p> <pre><code>get-item testfile1.txt | Get-Member BaseName | format-list TypeName : System.IO.FileInfo Name : BaseName MemberType : ScriptProperty Defini... | 1, 526 | .net, powershell | <h1>FileInfo.BaseName exists in PowerShell but not in straight .NET</h1>
<p>Why is it that in .NET the <code>System.IO.FileInfo</code> object does not have a <code>BaseName</code> property, but I can use the property through PowerShell, e.g.:</p>
<pre><code>$FolderItems = Get-ChildItem -Path "C:\" | Where-Object {$_ -... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,808 | bash | # FileInfo.BaseName exists in PowerShell but not in straight .NET
Why is it that in .NET the `System.IO.FileInfo` object does not have a `BaseName` property, but I can use the property through PowerShell, e.g.:
```
$FolderItems = Get-ChildItem -Path "C:\" | Where-Object {$_ -isnot [IO.DirectoryInfo]}
foreach ($Folde... | Powershell adds that property for you. If you run get-member on a fileinfo object, you can see that it's a script property, and even the script itself:
```
get-item testfile1.txt | Get-Member BaseName | format-list
TypeName : System.IO.FileInfo
Name : BaseName
MemberType : ScriptProperty
Definition : System.O... |
21051151 | Why can I not use an exclamation mark in bash' echo, not even when it is escaped? | 9 | 2014-01-10 17:55:33 | <p>My question is simple:</p>
<pre><code>$ echo "Hello!"
sh: !": event not found
</code></pre>
<p>What is <code>!</code> in this case? I then tried <code>echo "Match\!"</code>, but that resolves to <code>Match\!</code>. How do I have to write the statement?</p>
| 2,888 | 2,265,734 | 2014-01-10 18:32:29 | 21,051,177 | 14 | 2014-01-10 17:57:12 | 548,225 | 2014-01-10 17:57:12 | https://stackoverflow.com/q/21051151 | https://stackoverflow.com/a/21051177 | <p>You can use single quotes:</p>
<pre><code>echo 'Hello!'
Hello!
</code></pre>
<p>Otherwise in double quotes shell attempts to expand <code>!</code> to an event from the history..</p>
| <p>You can use single quotes:</p> <pre><code>echo 'Hello!' Hello! </code></pre> <p>Otherwise in double quotes shell attempts to expand <code>!</code> to an event from the history..</p> | 387 | bash | <h1>Why can I not use an exclamation mark in bash' echo, not even when it is escaped?</h1>
<p>My question is simple:</p>
<pre><code>$ echo "Hello!"
sh: !": event not found
</code></pre>
<p>What is <code>!</code> in this case? I then tried <code>echo "Match\!"</code>, but that resolves to <code>Match\!</code>. How do ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,809 | bash | # Why can I not use an exclamation mark in bash' echo, not even when it is escaped?
My question is simple:
```
$ echo "Hello!"
sh: !": event not found
```
What is `!` in this case? I then tried `echo "Match\!"`, but that resolves to `Match\!`. How do I have to write the statement? | You can use single quotes:
```
echo 'Hello!'
Hello!
```
Otherwise in double quotes shell attempts to expand `!` to an event from the history.. |
20012982 | Can Powershell Give Me Information on the Server's Certificate Used By Invoke-WebRequest? | 9 | 2013-11-16 00:21:51 | <p>For instance, in Powershell 4,</p>
<pre><code>$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
</code></pre>
<p>That command works perfectly well, but, is there any way for me to also get the information about the SSL certificate us... | 17,755 | 1,301,738 | 2024-01-22 09:31:10 | 20,014,855 | 14 | 2013-11-16 04:54:37 | 370,734 | 2013-11-16 04:54:37 | https://stackoverflow.com/q/20012982 | https://stackoverflow.com/a/20014855 | <p>The PowerShell cmdlets don't have a native way to do this. You will probably have to drop down to the .Net libraries if you want certificate information.</p>
<p>One way of doing this will involve using the <code>System.Net.ServicePointManager</code> class. In specific, the <code>FindServicePoint</code> method.</p>... | <p>The PowerShell cmdlets don't have a native way to do this. You will probably have to drop down to the .Net libraries if you want certificate information.</p> <p>One way of doing this will involve using the <code>System.Net.ServicePointManager</code> class. In specific, the <code>FindServicePoint</code> method.</p>... | 526, 95686 | powershell, powershell-4.0 | <h1>Can Powershell Give Me Information on the Server's Certificate Used By Invoke-WebRequest?</h1>
<p>For instance, in Powershell 4,</p>
<pre><code>$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
</code></pre>
<p>That command works pe... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,810 | bash | # Can Powershell Give Me Information on the Server's Certificate Used By Invoke-WebRequest?
For instance, in Powershell 4,
```
$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
```
That command works perfectly well, but, is there any w... | The PowerShell cmdlets don't have a native way to do this. You will probably have to drop down to the .Net libraries if you want certificate information.
One way of doing this will involve using the `System.Net.ServicePointManager` class. In specific, the `FindServicePoint` method.
This will have to be done as a sepa... |
19377716 | how to compare two columns in a single file in unix | 9 | 2013-10-15 09:30:53 | <p>My req is i need to get the output if the two columns are not equal below is my code.</p>
<p>The output is as below here my req is for example the first shouldnt be printed as both are equal the second should be printed as both are not equal.</p>
<pre><code>cat testingfull.txt|sed -n '/"Exp_CDL_BOOKINGS_F"/,/TABLE... | 16,839 | 2,871,618 | 2019-05-03 12:46:05 | 19,377,833 | 14 | 2013-10-15 09:36:23 | 548,225 | 2014-11-24 13:39:31 | https://stackoverflow.com/q/19377716 | https://stackoverflow.com/a/19377833 | <p>Compare columns in your awk command:</p>
<pre><code>awk -F'"' '$8!=$12 {print $8,"=",$12}'
</code></pre>
| <p>Compare columns in your awk command:</p> <pre><code>awk -F'"' '$8!=$12 {print $8,"=",$12}' </code></pre> | 34, 387 | bash, unix | <h1>how to compare two columns in a single file in unix</h1>
<p>My req is i need to get the output if the two columns are not equal below is my code.</p>
<p>The output is as below here my req is for example the first shouldnt be printed as both are equal the second should be printed as both are not equal.</p>
<pre><c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,811 | bash | # how to compare two columns in a single file in unix
My req is i need to get the output if the two columns are not equal below is my code.
The output is as below here my req is for example the first shouldnt be printed as both are equal the second should be printed as both are not equal.
```
cat testingfull.txt|sed... | Compare columns in your awk command:
```
awk -F'"' '$8!=$12 {print $8,"=",$12}'
``` |
19321903 | What is the equivalent of 'nohup' in PowerShell? | 9 | 2013-10-11 15:30:32 | <p>How can I emulate the behavior of the unix command <code>nohup</code> in PowerShell? That is <code>nohup my-other-nonblocking-command</code>. I have noticed the <code>Start-Job</code> command, however the syntax is somewhat unclear to me.</p>
| 16,488 | 18,858 | 2013-10-11 19:17:28 | 19,324,839 | 14 | 2013-10-11 18:24:04 | 246,826 | 2013-10-11 18:30:03 | https://stackoverflow.com/q/19321903 | https://stackoverflow.com/a/19324839 | <pre><code>> Start-Job my.exe
</code></pre>
<p>Fails with this output:</p>
<pre><code>Start-Job : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Start-Job my.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Job], ParameterBinding... | <pre><code>> Start-Job my.exe </code></pre> <p>Fails with this output:</p> <pre><code>Start-Job : Parameter set cannot be resolved using the specified named parameters. At line:1 char:1 + Start-Job my.exe + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Start-Job], ParameterBinding... | 526, 18966 | nohup, powershell | <h1>What is the equivalent of 'nohup' in PowerShell?</h1>
<p>How can I emulate the behavior of the unix command <code>nohup</code> in PowerShell? That is <code>nohup my-other-nonblocking-command</code>. I have noticed the <code>Start-Job</code> command, however the syntax is somewhat unclear to me.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,812 | bash | # What is the equivalent of 'nohup' in PowerShell?
How can I emulate the behavior of the unix command `nohup` in PowerShell? That is `nohup my-other-nonblocking-command`. I have noticed the `Start-Job` command, however the syntax is somewhat unclear to me. | ```
> Start-Job my.exe
```
Fails with this output:
```
Start-Job : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Start-Job my.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Job], ParameterBindingException
+ FullyQualifiedErro... |
18838111 | How to open two html files with default browser | 9 | 2013-09-16 22:07:14 | <p>I have a script that generates two reports and many many html files and I would like to open only two html files with the default browser.</p>
<p>My Powershell script finishes like this:</p>
<pre><code>Invoke-Item C:\Reports\XUReport.htm
Invoke-Item C:\Reports\index.htm
</code></pre>
<p>My script is only opening ... | 12,732 | 1,026,105 | 2013-09-17 07:40:55 | 18,844,020 | 14 | 2013-09-17 07:40:55 | 520,612 | 2013-09-17 07:40:55 | https://stackoverflow.com/q/18838111 | https://stackoverflow.com/a/18844020 | <p>Add a little pause from one call and the other one:</p>
<pre><code>Invoke-Item C:\Reports\XUReport.htm
start-sleep 1
Invoke-Item C:\Reports\index.htm
</code></pre>
| <p>Add a little pause from one call and the other one:</p> <pre><code>Invoke-Item C:\Reports\XUReport.htm start-sleep 1 Invoke-Item C:\Reports\index.htm </code></pre> | 73157 | powershell-3.0 | <h1>How to open two html files with default browser</h1>
<p>I have a script that generates two reports and many many html files and I would like to open only two html files with the default browser.</p>
<p>My Powershell script finishes like this:</p>
<pre><code>Invoke-Item C:\Reports\XUReport.htm
Invoke-Item C:\Repor... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,813 | bash | # How to open two html files with default browser
I have a script that generates two reports and many many html files and I would like to open only two html files with the default browser.
My Powershell script finishes like this:
```
Invoke-Item C:\Reports\XUReport.htm
Invoke-Item C:\Reports\index.htm
```
My script... | Add a little pause from one call and the other one:
```
Invoke-Item C:\Reports\XUReport.htm
start-sleep 1
Invoke-Item C:\Reports\index.htm
``` |
18824205 | PowerShell parameters with special characters | 9 | 2013-09-16 09:07:56 | <p>I am working on a PowerShell script to send an email, and some of the parameters may contains special characters, such as % and &.</p>
<pre><code>powershell.exe .\sendmail.ps1 -to "user@something.com" -body "Special character & causing trouble." -subject 'PowerShell email'
</code></pre>
<p>This gives the f... | 29,532 | 18,651 | 2013-09-16 10:06:12 | 18,825,235 | 14 | 2013-09-16 10:00:17 | 520,612 | 2013-09-16 10:06:12 | https://stackoverflow.com/q/18824205 | https://stackoverflow.com/a/18825235 | <p>Try call the script in this way and let me know:</p>
<pre><code>powershell.exe -command "& .\sendmail.ps1 -to user@something.com -body 'Special character & causing trouble.' -subject 'PowerShell email'"
</code></pre>
| <p>Try call the script in this way and let me know:</p> <pre><code>powershell.exe -command "& .\sendmail.ps1 -to user@something.com -body 'Special character & causing trouble.' -subject 'PowerShell email'" </code></pre> | 526 | powershell | <h1>PowerShell parameters with special characters</h1>
<p>I am working on a PowerShell script to send an email, and some of the parameters may contains special characters, such as % and &.</p>
<pre><code>powershell.exe .\sendmail.ps1 -to "user@something.com" -body "Special character & causing trouble." -subjec... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,814 | bash | # PowerShell parameters with special characters
I am working on a PowerShell script to send an email, and some of the parameters may contains special characters, such as % and &.
```
powershell.exe .\sendmail.ps1 -to "user@something.com" -body "Special character & causing trouble." -subject 'PowerShell email'
```
Th... | Try call the script in this way and let me know:
```
powershell.exe -command "& .\sendmail.ps1 -to user@something.com -body 'Special character & causing trouble.' -subject 'PowerShell email'"
``` |
16706005 | Exact grep -f command in Linux | 9 | 2013-05-23 05:05:30 | <p>I have 2 txt files in Linux.</p>
<p>A.txt contents (each line will contain a number):</p>
<pre><code>1
2
3
</code></pre>
<p>B.txt contents (each line will contain a number):</p>
<pre><code>1
2
3
10
20
30
</code></pre>
<p><code>grep -f A.txt B.txt</code> results below:</p>
<pre><code>1
2
3
10
20
30
</code></pre... | 40,155 | 411,883 | 2023-04-17 21:26:51 | 16,706,026 | 14 | 2013-05-23 05:07:56 | 548,225 | 2023-04-17 21:26:51 | https://stackoverflow.com/q/16706005 | https://stackoverflow.com/a/16706026 | <p>For exact match use <code>-x</code> switch</p>
<pre><code>grep -x -f A.txt B.txt
</code></pre>
<p><strong>EDIT:</strong> If you don't want grep's regex capabilities and need to treat search pattern as fixed-strings then use <code>-F</code> switch as:</p>
<pre><code>grep -xF -f A.txt B.txt
</code></pre>
<pre><code> ... | <p>For exact match use <code>-x</code> switch</p> <pre><code>grep -x -f A.txt B.txt </code></pre> <p><strong>EDIT:</strong> If you don't want grep's regex capabilities and need to treat search pattern as fixed-strings then use <code>-F</code> switch as:</p> <pre><code>grep -xF -f A.txt B.txt </code></pre> <pre><code> ... | 34, 58, 390, 1271 | grep, linux, shell, unix | <h1>Exact grep -f command in Linux</h1>
<p>I have 2 txt files in Linux.</p>
<p>A.txt contents (each line will contain a number):</p>
<pre><code>1
2
3
</code></pre>
<p>B.txt contents (each line will contain a number):</p>
<pre><code>1
2
3
10
20
30
</code></pre>
<p><code>grep -f A.txt B.txt</code> results below:</p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,815 | bash | # Exact grep -f command in Linux
I have 2 txt files in Linux.
A.txt contents (each line will contain a number):
```
1
2
3
```
B.txt contents (each line will contain a number):
```
1
2
3
10
20
30
```
`grep -f A.txt B.txt` results below:
```
1
2
3
10
20
30
```
Is there a way to grep in such a way I will get only ... | For exact match use `-x` switch
```
grep -x -f A.txt B.txt
```
**EDIT:** If you don't want grep's regex capabilities and need to treat search pattern as fixed-strings then use `-F` switch as:
```
grep -xF -f A.txt B.txt
```
```
-x, --line-regexp
Only input lines selected against an entire fixed st... |
16072041 | Is Powershell -sta (apartment state) preferred? | 9 | 2013-04-17 23:30:55 | <p>I've been dabbling in Powershell (2.0) for the past several months and would love to use it to modernize and standardize some of the processes at work - mostly DOS based processes. Because of the nature of the work, there could be around 100 executions of the same script(s) going at once. </p>
<p>First--Is Powers... | 9,007 | 2,292,870 | 2018-05-04 17:43:52 | 16,073,022 | 14 | 2013-04-18 01:28:25 | 251,123 | 2013-04-18 11:54:45 | https://stackoverflow.com/q/16072041 | https://stackoverflow.com/a/16073022 | <p>In PSv2, the console host runs as MTA, and the ISE runs as STA. In PSv3 the console <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/02/09/weekend-scripter-playing-around-with-powershell-namespace-apartmentstate.aspx" rel="noreferrer">defaults to STA</a>.</p>
<p>You can see what your apartment state... | <p>In PSv2, the console host runs as MTA, and the ISE runs as STA. In PSv3 the console <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/02/09/weekend-scripter-playing-around-with-powershell-namespace-apartmentstate.aspx" rel="noreferrer">defaults to STA</a>.</p> <p>You can see what your apartment state... | 526, 15878 | powershell, sta | <h1>Is Powershell -sta (apartment state) preferred?</h1>
<p>I've been dabbling in Powershell (2.0) for the past several months and would love to use it to modernize and standardize some of the processes at work - mostly DOS based processes. Because of the nature of the work, there could be around 100 executions of the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,816 | bash | # Is Powershell -sta (apartment state) preferred?
I've been dabbling in Powershell (2.0) for the past several months and would love to use it to modernize and standardize some of the processes at work - mostly DOS based processes. Because of the nature of the work, there could be around 100 executions of the same scri... | In PSv2, the console host runs as MTA, and the ISE runs as STA. In PSv3 the console [defaults to STA](http://blogs.technet.com/b/heyscriptingguy/archive/2013/02/09/weekend-scripter-playing-around-with-powershell-namespace-apartmentstate.aspx).
You can see what your apartment state is with this:
```
[System.Threading.... |
15804895 | Rijndael 256 encryption: Java and .NET do not match | 9 | 2013-04-04 07:20:35 | <p>I need to translate a powershell script with Rijandael encryption to Java.
Here is the source powershell code:</p>
<pre><code>[Reflection.Assembly]::LoadWithPartialName("System.Security")
Add-Type -AssemblyName System.Web
$sKy = "bbee9a3e8e44e28edb4539186d182aaa"
$sIV = "131a68dc13160766f37dc931d7e518aa"
$myRi... | 4,820 | 2,243,491 | 2013-04-04 07:23:09 | 15,804,940 | 14 | 2013-04-04 07:23:09 | 22,656 | 2013-04-04 07:23:09 | https://stackoverflow.com/q/15804895 | https://stackoverflow.com/a/15804940 | <p>Your results <em>are</em> the same, as far as I can see - it's just that in Java, bytes are signed. (That's icky, but it doesn't affect the actual bits you're getting.)</p>
<p>If you add 256 to every negative value in the Java results, you'll see they're the same as the .NET code:</p>
<pre><code>.NET: 241 10... | <p>Your results <em>are</em> the same, as far as I can see - it's just that in Java, bytes are signed. (That's icky, but it doesn't affect the actual bits you're getting.)</p> <p>If you add 256 to every negative value in the Java results, you'll see they're the same as the .NET code:</p> <pre><code>.NET: 241 10... | 1, 17, 526, 4172, 15549 | .net, bouncycastle, java, powershell, rijndael | <h1>Rijndael 256 encryption: Java and .NET do not match</h1>
<p>I need to translate a powershell script with Rijandael encryption to Java.
Here is the source powershell code:</p>
<pre><code>[Reflection.Assembly]::LoadWithPartialName("System.Security")
Add-Type -AssemblyName System.Web
$sKy = "bbee9a3e8e44e28edb453918... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,817 | bash | # Rijndael 256 encryption: Java and .NET do not match
I need to translate a powershell script with Rijandael encryption to Java.
Here is the source powershell code:
```
[Reflection.Assembly]::LoadWithPartialName("System.Security")
Add-Type -AssemblyName System.Web
$sKy = "bbee9a3e8e44e28edb4539186d182aaa"
$sIV = ... | Your results *are* the same, as far as I can see - it's just that in Java, bytes are signed. (That's icky, but it doesn't affect the actual bits you're getting.)
If you add 256 to every negative value in the Java results, you'll see they're the same as the .NET code:
```
.NET: 241 100 194 184 166
Java: ... |
11685135 | How to get parent folder of executing script in zsh? | 9 | 2012-07-27 09:34:09 | <p>In bash i get the executing script's parent folder name by this line</p>
<pre><code>SCRIPT_PARENT=`readlink -f ${BASH_SOURCE%/*}/..`
</code></pre>
<p>Is there any way to achieve this in zsh in a way that works both in zsh and bash?</p>
<p>Assume i have got a file <code>/some/folder/rootfolder/subfolder/script</co... | 9,083 | 375,157 | 2013-02-24 21:15:14 | 15,056,664 | 14 | 2013-02-24 21:05:33 | 375,157 | 2013-02-24 21:15:14 | https://stackoverflow.com/q/11685135 | https://stackoverflow.com/a/15056664 | <p>I now realized that <code>$0</code> in zsh behaves like <code>$BASH_SOURCE</code> in bash. So using <code>$BASH_SOURCE</code> when available and falling back to <code>$0</code> solves my problem:</p>
<pre><code>${BASH_SOURCE:-$0}
</code></pre>
<p>There is a little zsh edge case left, when sourcing from <code>$PATH... | <p>I now realized that <code>$0</code> in zsh behaves like <code>$BASH_SOURCE</code> in bash. So using <code>$BASH_SOURCE</code> when available and falling back to <code>$0</code> solves my problem:</p> <pre><code>${BASH_SOURCE:-$0} </code></pre> <p>There is a little zsh edge case left, when sourcing from <code>$PATH... | 387, 3791 | bash, zsh | <h1>How to get parent folder of executing script in zsh?</h1>
<p>In bash i get the executing script's parent folder name by this line</p>
<pre><code>SCRIPT_PARENT=`readlink -f ${BASH_SOURCE%/*}/..`
</code></pre>
<p>Is there any way to achieve this in zsh in a way that works both in zsh and bash?</p>
<p>Assume i have... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,818 | bash | # How to get parent folder of executing script in zsh?
In bash i get the executing script's parent folder name by this line
```
SCRIPT_PARENT=`readlink -f ${BASH_SOURCE%/*}/..`
```
Is there any way to achieve this in zsh in a way that works both in zsh and bash?
Assume i have got a file `/some/folder/rootfolder/sub... | I now realized that `$0` in zsh behaves like `$BASH_SOURCE` in bash. So using `$BASH_SOURCE` when available and falling back to `$0` solves my problem:
```
${BASH_SOURCE:-$0}
```
There is a little zsh edge case left, when sourcing from `$PATH` like:
```
zsh> cat ../script
echo \$0: $0
echo \$BASH_SOURCE: $BASH_SOURC... |
14238270 | Setting a website's application pool in IIS using Powershell | 9 | 2013-01-09 15:08:54 | <p>I need a Powershell command that does the equivalent of adding a website in IIS, but need the bindings for the "Application pool":</p>
<p><img src="https://i.sstatic.net/IBvxk.png" alt="enter image description here"></p>
<p>So far I can add a website doing this:</p>
<pre><code>New-Item iis:\Sites\swmarket -bindin... | 9,430 | 510,731 | 2016-01-19 14:00:46 | 14,241,082 | 14 | 2013-01-09 15:53:12 | 40,899 | 2013-01-09 16:00:35 | https://stackoverflow.com/q/14238270 | https://stackoverflow.com/a/14241082 | <pre><code>Set-ItemProperty iis:\Sites\swmarket -Name applicationpool -Value swmarket
</code></pre>
<p>Alternatively, with Powershell 3, you could do this:</p>
<pre><code>New-WebAppPool -Name $WebSiteName
New-Website -Name $WebSiteName -ApplicationPool $WebSiteName -HostHeader $WebSiteName -PhysicalPath $PathInfo -Po... | <pre><code>Set-ItemProperty iis:\Sites\swmarket -Name applicationpool -Value swmarket </code></pre> <p>Alternatively, with Powershell 3, you could do this:</p> <pre><code>New-WebAppPool -Name $WebSiteName New-Website -Name $WebSiteName -ApplicationPool $WebSiteName -HostHeader $WebSiteName -PhysicalPath $PathInfo -Po... | 215, 526, 10223 | application-pool, iis, powershell | <h1>Setting a website's application pool in IIS using Powershell</h1>
<p>I need a Powershell command that does the equivalent of adding a website in IIS, but need the bindings for the "Application pool":</p>
<p><img src="https://i.sstatic.net/IBvxk.png" alt="enter image description here"></p>
<p>So far I can add a we... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,819 | bash | # Setting a website's application pool in IIS using Powershell
I need a Powershell command that does the equivalent of adding a website in IIS, but need the bindings for the "Application pool":

So far I can add a website doing this:
```
New-Item iis:\... | ```
Set-ItemProperty iis:\Sites\swmarket -Name applicationpool -Value swmarket
```
Alternatively, with Powershell 3, you could do this:
```
New-WebAppPool -Name $WebSiteName
New-Website -Name $WebSiteName -ApplicationPool $WebSiteName -HostHeader $WebSiteName -PhysicalPath $PathInfo -Port 80
Set-Content $PathInfo\def... |
11281893 | How to split mailbox into single file per message? | 9 | 2012-07-01 12:20:24 | <p>I'd like to split my inbox into separate files (one file per one message) by bash command, or may be simple program in Java. How can I do it?</p>
<p>WBR, Thanx.</p>
| 12,273 | 517,073 | 2025-04-05 16:06:24 | 11,282,287 | 14 | 2012-07-01 13:17:19 | 1,458,569 | 2022-06-01 18:52:08 | https://stackoverflow.com/q/11281893 | https://stackoverflow.com/a/11282287 | <p>Just use <code>formail</code>. <code>formail</code> is a program that can process mailbox, run some actions for each message in the mailbox, separate messages and so on.</p>
<p>More info: <a href="http://www.manpagez.com/man/1/formail/" rel="nofollow noreferrer">http://www.manpagez.com/man/1/formail/</a></p>
<p>If y... | <p>Just use <code>formail</code>. <code>formail</code> is a program that can process mailbox, run some actions for each message in the mailbox, separate messages and so on.</p> <p>More info: <a href="http://www.manpagez.com/man/1/formail/" rel="nofollow noreferrer">http://www.manpagez.com/man/1/formail/</a></p> <p>If y... | 34, 58, 146, 387, 19228 | bash, email, linux, mbox, unix | <h1>How to split mailbox into single file per message?</h1>
<p>I'd like to split my inbox into separate files (one file per one message) by bash command, or may be simple program in Java. How can I do it?</p>
<p>WBR, Thanx.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,820 | bash | # How to split mailbox into single file per message?
I'd like to split my inbox into separate files (one file per one message) by bash command, or may be simple program in Java. How can I do it?
WBR, Thanx. | Just use `formail`. `formail` is a program that can process mailbox, run some actions for each message in the mailbox, separate messages and so on.
More info: <http://www.manpagez.com/man/1/formail/>
If you want just split a mailbox to separate files,
I would suggest such solution:
```
$ cat $MAIL | formail -ds sh -... |
10486575 | Bash: how to take a number from string? (regular expression maybe) | 9 | 2012-05-07 17:42:42 | <p>I want to get a count of symbols in a file.</p>
<pre><code>wc -c f1.txt | grep [0-9]
</code></pre>
<p>But this code return a line where grep found numbers. I want to retrun only <strong>38</strong>. How?</p>
| 12,779 | 842,692 | 2018-01-31 15:07:16 | 10,486,606 | 14 | 2012-05-07 17:45:14 | 548,225 | 2012-05-07 18:13:04 | https://stackoverflow.com/q/10486575 | https://stackoverflow.com/a/10486606 | <p>You can use awk:</p>
<pre><code>wc -c f1.txt | awk '{print $1}'
</code></pre>
<p>OR using <code>grep -o</code>:</p>
<pre><code>wc -c f1.txt | grep -o "[0-9]\+"
</code></pre>
<p>OR using bash regex capabilities:</p>
<pre><code>re="^ *([0-9]+)" && [[ "$(wc -c f1.txt)" =~ $re ]] && echo "${BASH_REM... | <p>You can use awk:</p> <pre><code>wc -c f1.txt | awk '{print $1}' </code></pre> <p>OR using <code>grep -o</code>:</p> <pre><code>wc -c f1.txt | grep -o "[0-9]\+" </code></pre> <p>OR using bash regex capabilities:</p> <pre><code>re="^ *([0-9]+)" && [[ "$(wc -c f1.txt)" =~ $re ]] && echo "${BASH_REM... | 18, 387, 1271 | bash, grep, regex | <h1>Bash: how to take a number from string? (regular expression maybe)</h1>
<p>I want to get a count of symbols in a file.</p>
<pre><code>wc -c f1.txt | grep [0-9]
</code></pre>
<p>But this code return a line where grep found numbers. I want to retrun only <strong>38</strong>. How?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,821 | bash | # Bash: how to take a number from string? (regular expression maybe)
I want to get a count of symbols in a file.
```
wc -c f1.txt | grep [0-9]
```
But this code return a line where grep found numbers. I want to retrun only **38**. How? | You can use awk:
```
wc -c f1.txt | awk '{print $1}'
```
OR using `grep -o`:
```
wc -c f1.txt | grep -o "[0-9]\+"
```
OR using bash regex capabilities:
```
re="^ *([0-9]+)" && [[ "$(wc -c f1.txt)" =~ $re ]] && echo "${BASH_REMATCH[1]}"
``` |
9405200 | Write to terminal after redirecting stdout to a file without using stderr? | 9 | 2012-02-23 00:00:27 | <p>I have two shell scripts, one that serves as the main "program" and another that serves as a "library." </p>
<p>In several places in the "program," I'll do something like: <code>log "$thing" >> "$logfile"</code>, where <code>log</code> is a function defined in the "library."</p>
<pre><code># program.sh
logf... | 13,545 | 886,931 | 2012-02-23 00:19:52 | 9,405,235 | 14 | 2012-02-23 00:05:42 | 20,862 | 2012-02-23 00:05:42 | https://stackoverflow.com/q/9405200 | https://stackoverflow.com/a/9405235 | <p>Open <code>/dev/tty</code> on another FD.</p>
<pre><code>exec 0< /dev/null
exec 1> /dev/null
exec 2> /dev/null
exec 3> /dev/tty
echo 'Hello, World!' >&3
</code></pre>
| <p>Open <code>/dev/tty</code> on another FD.</p> <pre><code>exec 0< /dev/null exec 1> /dev/null exec 2> /dev/null exec 3> /dev/tty echo 'Hello, World!' >&3 </code></pre> | 387, 390, 4867, 31901 | bash, http-redirect, shell, stdout | <h1>Write to terminal after redirecting stdout to a file without using stderr?</h1>
<p>I have two shell scripts, one that serves as the main "program" and another that serves as a "library." </p>
<p>In several places in the "program," I'll do something like: <code>log "$thing" >> "$logfile"</code>, where <code>l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,822 | bash | # Write to terminal after redirecting stdout to a file without using stderr?
I have two shell scripts, one that serves as the main "program" and another that serves as a "library."
In several places in the "program," I'll do something like: `log "$thing" >> "$logfile"`, where `log` is a function defined in the "libra... | Open `/dev/tty` on another FD.
```
exec 0< /dev/null
exec 1> /dev/null
exec 2> /dev/null
exec 3> /dev/tty
echo 'Hello, World!' >&3
``` |
8678523 | Rename it after copied using powershell | 9 | 2011-12-30 10:31:39 | <p>I am trying to recursively copy the files and rename them.</p>
<p>My folders has file with same name ,so i need to rename it the moment it is copied.</p>
<p>But i am keep facing issue. Following is my code. It should find the CopyForBuild.bat file and copy it to E:\CopyForBuild folder. Once it is copied , the firs... | 21,579 | 399,145 | 2011-12-30 13:48:08 | 8,678,578 | 14 | 2011-12-30 10:38:44 | 978,511 | 2011-12-30 13:48:08 | https://stackoverflow.com/q/8678523 | https://stackoverflow.com/a/8678578 | <p>You can rename file while copying in Copy-Item, just provide full path in both places:</p>
<pre><code>copy-item c:\PST\1.config c:\PST\2.config
</code></pre>
<p>This will rename 1.config to 2.config. No need to call separate rename function.
Your code should now look something like this:</p>
<pre><code>$File = Ge... | <p>You can rename file while copying in Copy-Item, just provide full path in both places:</p> <pre><code>copy-item c:\PST\1.config c:\PST\2.config </code></pre> <p>This will rename 1.config to 2.config. No need to call separate rename function. Your code should now look something like this:</p> <pre><code>$File = Ge... | 526, 24067 | powershell, powershell-2.0 | <h1>Rename it after copied using powershell</h1>
<p>I am trying to recursively copy the files and rename them.</p>
<p>My folders has file with same name ,so i need to rename it the moment it is copied.</p>
<p>But i am keep facing issue. Following is my code. It should find the CopyForBuild.bat file and copy it to E:\... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,823 | bash | # Rename it after copied using powershell
I am trying to recursively copy the files and rename them.
My folders has file with same name ,so i need to rename it the moment it is copied.
But i am keep facing issue. Following is my code. It should find the CopyForBuild.bat file and copy it to E:\CopyForBuild folder. On... | You can rename file while copying in Copy-Item, just provide full path in both places:
```
copy-item c:\PST\1.config c:\PST\2.config
```
This will rename 1.config to 2.config. No need to call separate rename function.
Your code should now look something like this:
```
$File = Get-ChildItem -Path "V:\MyFolder\" -Filt... |
8561247 | Bash/Shell-Move all files from subdirectories into target directory? | 9 | 2011-12-19 12:18:21 | <p>How do I bash a command or a shell script to move all the files from the subdirectories to one target directory in Linux?</p>
| 11,269 | 610,569 | 2011-12-19 12:25:30 | 8,561,342 | 14 | 2011-12-19 12:25:30 | 847,601 | 2011-12-19 12:25:30 | https://stackoverflow.com/q/8561247 | https://stackoverflow.com/a/8561342 | <p>If you are using GNU mv, the <code>-t</code> option (target directory) is pretty useful:</p>
<pre><code>find sourcedir -type f -print0 | xargs -0 mv -t target
</code></pre>
<p><code>man mv</code> gives more details.</p>
| <p>If you are using GNU mv, the <code>-t</code> option (target directory) is pretty useful:</p> <pre><code>find sourcedir -type f -print0 | xargs -0 mv -t target </code></pre> <p><code>man mv</code> gives more details.</p> | 34, 58, 387, 390, 5634 | bash, linux, move, shell, unix | <h1>Bash/Shell-Move all files from subdirectories into target directory?</h1>
<p>How do I bash a command or a shell script to move all the files from the subdirectories to one target directory in Linux?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,824 | bash | # Bash/Shell-Move all files from subdirectories into target directory?
How do I bash a command or a shell script to move all the files from the subdirectories to one target directory in Linux? | If you are using GNU mv, the `-t` option (target directory) is pretty useful:
```
find sourcedir -type f -print0 | xargs -0 mv -t target
```
`man mv` gives more details. |
8506533 | PowerShell equivalent of curl HTTP POST for file transfer | 9 | 2011-12-14 14:55:31 | <p>I'm currently uploading a file via an HTTP post with a call like this:</p>
<pre><code>curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"
</code></pre>
<p>This works fi... | 14,454 | 205,018 | 2017-05-28 22:46:24 | 8,508,633 | 14 | 2011-12-14 17:08:07 | 4,916 | 2017-05-28 22:46:24 | https://stackoverflow.com/q/8506533 | https://stackoverflow.com/a/8508633 | <p>In theory the following...</p>
<pre><code>curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"
</code></pre>
<p>It could be replaced by using <a href="http://msdn.micros... | <p>In theory the following...</p> <pre><code>curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n" </code></pre> <p>It could be replaced by using <a href="http://msdn.micros... | 1, 526, 1554 | .net, curl, powershell | <h1>PowerShell equivalent of curl HTTP POST for file transfer</h1>
<p>I'm currently uploading a file via an HTTP post with a call like this:</p>
<pre><code>curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&re... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,825 | bash | # PowerShell equivalent of curl HTTP POST for file transfer
I'm currently uploading a file via an HTTP post with a call like this:
```
curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"
... | In theory the following...
```
curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"
```
It could be replaced by using [System.Net.WebClient.UploadFile](http://msdn.microsoft.com/en-us/libr... |
5021720 | PowerShell mkdir alias + Set-StrictMode -Version 2. Strange bug. Why? | 9 | 2011-02-16 20:25:37 | <p>It's something unbelievable. This is a PowerShell code snippet in <code>test.ps1</code> file:</p>
<pre><code>Set-StrictMode -Version 2
mkdir c:\tmp\1 # same with 'md c:\tmp\1'
</code></pre>
<p>Start <code>cmd.exe</code>, navigate to folder with <code>test.ps1</code> script and run it:</p>
<pre><code>c:\tmp>po... | 4,838 | 77,733 | 2015-08-21 14:43:13 | 6,552,850 | 14 | 2011-07-01 20:21:17 | 825,426 | 2011-07-01 20:21:17 | https://stackoverflow.com/q/5021720 | https://stackoverflow.com/a/6552850 | <p>Even though a workaround has already been found, I thought people might be interested in an explanation.</p>
<p>As to why it behaves differently in the shell versus cmd.exe, see <a href="https://stackoverflow.com/questions/2894641/powershell-2-0-running-scripts-for-the-command-line-call-vs-from-the-ise">Powershell ... | <p>Even though a workaround has already been found, I thought people might be interested in an explanation.</p> <p>As to why it behaves differently in the shell versus cmd.exe, see <a href="https://stackoverflow.com/questions/2894641/powershell-2-0-running-scripts-for-the-command-line-call-vs-from-the-ise">Powershell ... | 526, 1448, 24423 | alias, mkdir, powershell | <h1>PowerShell mkdir alias + Set-StrictMode -Version 2. Strange bug. Why?</h1>
<p>It's something unbelievable. This is a PowerShell code snippet in <code>test.ps1</code> file:</p>
<pre><code>Set-StrictMode -Version 2
mkdir c:\tmp\1 # same with 'md c:\tmp\1'
</code></pre>
<p>Start <code>cmd.exe</code>, navigate to fo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,826 | bash | # PowerShell mkdir alias + Set-StrictMode -Version 2. Strange bug. Why?
It's something unbelievable. This is a PowerShell code snippet in `test.ps1` file:
```
Set-StrictMode -Version 2
mkdir c:\tmp\1 # same with 'md c:\tmp\1'
```
Start `cmd.exe`, navigate to folder with `test.ps1` script and run it:
```
c:\tmp>pow... | Even though a workaround has already been found, I thought people might be interested in an explanation.
As to why it behaves differently in the shell versus cmd.exe, see [Powershell 2.0 - Running scripts for the command line call vs. from the ISE](https://stackoverflow.com/questions/2894641/powershell-2-0-running-scr... |
6417233 | How to do date calculations in Shell Scripting? | 9 | 2011-06-20 20:42:48 | <p>I have a shell script that runs every night to backup my EC2 sites database and html to S3, and when it backs the folders up, it appends the date to it for easier viewing. But I want it to also be able to delete the relevant backup folders from 3 days before. How can I do the calculations to get the date 3 days ago?... | 14,229 | 781,620 | 2018-10-17 11:23:07 | 6,417,313 | 14 | 2011-06-20 20:48:48 | 42,388 | 2011-06-20 20:48:48 | https://stackoverflow.com/q/6417233 | https://stackoverflow.com/a/6417313 | <p>You can use the -d flag for the date command:</p>
<pre><code>-d, --date=STRING
display time described by STRING, not 'now'
</code></pre>
<p>So, just change your date variable to:</p>
<pre><code>DATE=`date +%m%d%Y -d "3 days ago"`
</code></pre>
| <p>You can use the -d flag for the date command:</p> <pre><code>-d, --date=STRING display time described by STRING, not 'now' </code></pre> <p>So, just change your date variable to:</p> <pre><code>DATE=`date +%m%d%Y -d "3 days ago"` </code></pre> | 387, 390, 23536 | bash, date-arithmetic, shell | <h1>How to do date calculations in Shell Scripting?</h1>
<p>I have a shell script that runs every night to backup my EC2 sites database and html to S3, and when it backs the folders up, it appends the date to it for easier viewing. But I want it to also be able to delete the relevant backup folders from 3 days before. ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,827 | bash | # How to do date calculations in Shell Scripting?
I have a shell script that runs every night to backup my EC2 sites database and html to S3, and when it backs the folders up, it appends the date to it for easier viewing. But I want it to also be able to delete the relevant backup folders from 3 days before. How can I... | You can use the -d flag for the date command:
```
-d, --date=STRING
display time described by STRING, not 'now'
```
So, just change your date variable to:
```
DATE=`date +%m%d%Y -d "3 days ago"`
``` |
6306289 | Linux Script- Date Manipulations | 9 | 2011-06-10 12:22:50 | <p>I will set one date variable(Say '08-JUN-2011') and I want to do some calculations based on that date namely,<br>
1. Have to get the first day of the given day's month.<br>
2. Previous date of the given date's month.<br>
3. Last day of the given date's month.</p>
<p>All I know is manipulating using the current syst... | 17,788 | 709,416 | 2014-02-05 07:04:55 | 6,309,052 | 14 | 2011-06-10 16:05:38 | 714,208 | 2011-06-10 16:05:38 | https://stackoverflow.com/q/6306289 | https://stackoverflow.com/a/6309052 | <p>Here's how to perform the manipulations using GNU date:</p>
<pre><code>#!/bin/sh
USER_DATE=JUN-08-2011
# first day of the month
FIRST_DAY_OF_MONTH=$(date -d "$USER_DATE" +%b-01-%Y)
PREVIOUS_DAY=$(date -d "$USER_DATE -1 days" +%b-%d-%Y)
# last day of the month
FIRST_DAY_NEXT_MONTH=$(date -d "$USER_DATE +1 month"... | <p>Here's how to perform the manipulations using GNU date:</p> <pre><code>#!/bin/sh USER_DATE=JUN-08-2011 # first day of the month FIRST_DAY_OF_MONTH=$(date -d "$USER_DATE" +%b-01-%Y) PREVIOUS_DAY=$(date -d "$USER_DATE -1 days" +%b-%d-%Y) # last day of the month FIRST_DAY_NEXT_MONTH=$(date -d "$USER_DATE +1 month"... | 58, 390, 531 | linux, scripting, shell | <h1>Linux Script- Date Manipulations</h1>
<p>I will set one date variable(Say '08-JUN-2011') and I want to do some calculations based on that date namely,<br>
1. Have to get the first day of the given day's month.<br>
2. Previous date of the given date's month.<br>
3. Last day of the given date's month.</p>
<p>All I k... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,828 | bash | # Linux Script- Date Manipulations
I will set one date variable(Say '08-JUN-2011') and I want to do some calculations based on that date namely,
1. Have to get the first day of the given day's month.
2. Previous date of the given date's month.
3. Last day of the given date's month.
All I know is manipulating us... | Here's how to perform the manipulations using GNU date:
```
#!/bin/sh
USER_DATE=JUN-08-2011
# first day of the month
FIRST_DAY_OF_MONTH=$(date -d "$USER_DATE" +%b-01-%Y)
PREVIOUS_DAY=$(date -d "$USER_DATE -1 days" +%b-%d-%Y)
# last day of the month
FIRST_DAY_NEXT_MONTH=$(date -d "$USER_DATE +1 month" +%b-01-%Y)
LA... |
5556651 | PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function? | 9 | 2011-04-05 18:29:11 | <p>So I have a cmdlet named update-name that I have no access to change.</p>
<p>I have created a function named update-name (the same name as the cmdlet). How do I call the cmdlet from the function with the same name? </p>
<p>I've tried a few things and none of them seem to work.</p>
<pre><code>function update-name... | 3,675 | 18,475 | 2011-04-05 19:38:12 | 5,557,358 | 14 | 2011-04-05 19:26:56 | 153,982 | 2011-04-05 19:26:56 | https://stackoverflow.com/q/5556651 | https://stackoverflow.com/a/5557358 | <p>You the cmdlet's module name to disambiguate the names:</p>
<pre><code>PS> Get-Command Start-Process | Format-Table ModuleName
ModuleName
----------
Microsoft.PowerShell.Management
PS> Microsoft.PowerShell.Management\Start-Process Notepad
</code></pre>
| <p>You the cmdlet's module name to disambiguate the names:</p> <pre><code>PS> Get-Command Start-Process | Format-Table ModuleName ModuleName ---------- Microsoft.PowerShell.Management PS> Microsoft.PowerShell.Management\Start-Process Notepad </code></pre> | 526, 5569, 34956, 153947 | function, powershell, powershell-cmdlet, redefinition | <h1>PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function?</h1>
<p>So I have a cmdlet named update-name that I have no access to change.</p>
<p>I have created a function named update-name (the same name as the cmdlet). How do I call the cmdlet from the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,829 | bash | # PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function?
So I have a cmdlet named update-name that I have no access to change.
I have created a function named update-name (the same name as the cmdlet). How do I call the cmdlet from the function with th... | You the cmdlet's module name to disambiguate the names:
```
PS> Get-Command Start-Process | Format-Table ModuleName
ModuleName
----------
Microsoft.PowerShell.Management
PS> Microsoft.PowerShell.Management\Start-Process Notepad
``` |
5408670 | Unix: Print file name and line number of each line that exceeds 80 characters of each file in a folder | 9 | 2011-03-23 16:39:51 | <p>Title sums it up. I'm working in Unix, korn shell. And I'm trying to print the file name and line number of each line that exceeds 80 characters of each file in the current folder.</p>
<p>I can use "<strong>awk 'length > 80' *.cpp</strong>" to give all lines longer than 80 characters, but I can't seem to pull out t... | 6,669 | 3,166,038 | 2011-03-23 21:23:27 | 5,408,728 | 14 | 2011-03-23 16:45:06 | 78,845 | 2011-03-23 21:23:27 | https://stackoverflow.com/q/5408670 | https://stackoverflow.com/a/5408728 | <p>Almost there! This will give you a <code>grep</code>-style output, useful in editors like Vim to be able to navigate the output:</p>
<pre><code>awk 'length > 80 {print FILENAME "(" FNR "): " $0}' *.cpp
</code></pre>
<p>Or to give the format you asked for:</p>
<pre><code>awk 'length > 80 {print FILENAME " li... | <p>Almost there! This will give you a <code>grep</code>-style output, useful in editors like Vim to be able to navigate the output:</p> <pre><code>awk 'length > 80 {print FILENAME "(" FNR "): " $0}' *.cpp </code></pre> <p>Or to give the format you asked for:</p> <pre><code>awk 'length > 80 {print FILENAME " li... | 34, 390, 531 | scripting, shell, unix | <h1>Unix: Print file name and line number of each line that exceeds 80 characters of each file in a folder</h1>
<p>Title sums it up. I'm working in Unix, korn shell. And I'm trying to print the file name and line number of each line that exceeds 80 characters of each file in the current folder.</p>
<p>I can use "<stro... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,830 | bash | # Unix: Print file name and line number of each line that exceeds 80 characters of each file in a folder
Title sums it up. I'm working in Unix, korn shell. And I'm trying to print the file name and line number of each line that exceeds 80 characters of each file in the current folder.
I can use "**awk 'length > 80' *... | Almost there! This will give you a `grep`-style output, useful in editors like Vim to be able to navigate the output:
```
awk 'length > 80 {print FILENAME "(" FNR "): " $0}' *.cpp
```
Or to give the format you asked for:
```
awk 'length > 80 {print FILENAME " line " FNR "\n\t" $0}' *.cpp
```
`FILENAME` and `FNR` (l... |
4656927 | Is it possible to distribute STDIN over parallel processes? | 9 | 2011-01-11 11:07:40 | <p>Given the following example input on STDIN:</p>
<pre><code>foo
bar bar
baz
===
qux
bla
===
def
zzz yyy
</code></pre>
<p>Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel?</p>
<p>So the example input above would result in 3 parallel processes ... | 6,778 | 183,605 | 2011-02-17 14:48:08 | 4,658,623 | 14 | 2011-01-11 14:26:39 | 452,012 | 2011-02-17 14:48:08 | https://stackoverflow.com/q/4656927 | https://stackoverflow.com/a/4658623 | <p>GNU Parallel can do that from version 20110205.</p>
<pre><code>cat | parallel --pipe --recend '===\n' --rrs do_stuff
</code></pre>
| <p>GNU Parallel can do that from version 20110205.</p> <pre><code>cat | parallel --pipe --recend '===\n' --rrs do_stuff </code></pre> | 353, 387, 1701, 5910, 10326 | bash, parallel-processing, process, stdin, xargs | <h1>Is it possible to distribute STDIN over parallel processes?</h1>
<p>Given the following example input on STDIN:</p>
<pre><code>foo
bar bar
baz
===
qux
bla
===
def
zzz yyy
</code></pre>
<p>Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel?</p>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,831 | bash | # Is it possible to distribute STDIN over parallel processes?
Given the following example input on STDIN:
```
foo
bar bar
baz
===
qux
bla
===
def
zzz yyy
```
Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel?
So the example input above would res... | GNU Parallel can do that from version 20110205.
```
cat | parallel --pipe --recend '===\n' --rrs do_stuff
``` |
3936518 | PowerShell: How to check for multiple conditions (folder existence) | 9 | 2010-10-14 18:51:03 | <p>I am in the process of writing a script to make changes to folder permissions. Before it does that I would to do some checking to make sure that I am working in the correct directory. My problem is how do I check to see if four subfolders (i.e. Admin, Workspace, Com, & Data) exists before the script progresses. ... | 19,986 | 179,979 | 2017-09-04 13:37:23 | 3,936,545 | 14 | 2010-10-14 18:54:52 | 23,283 | 2010-10-14 18:54:52 | https://stackoverflow.com/q/3936518 | https://stackoverflow.com/a/3936545 | <p>What's wrong with the following?</p>
<pre><code>if ( (Test-Path $path1) -and (Test-Path $path2) ) {
}
</code></pre>
| <p>What's wrong with the following?</p> <pre><code>if ( (Test-Path $path1) -and (Test-Path $path2) ) { } </code></pre> | 526 | powershell | <h1>PowerShell: How to check for multiple conditions (folder existence)</h1>
<p>I am in the process of writing a script to make changes to folder permissions. Before it does that I would to do some checking to make sure that I am working in the correct directory. My problem is how do I check to see if four subfolders (... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,832 | bash | # PowerShell: How to check for multiple conditions (folder existence)
I am in the process of writing a script to make changes to folder permissions. Before it does that I would to do some checking to make sure that I am working in the correct directory. My problem is how do I check to see if four subfolders (i.e. Admi... | What's wrong with the following?
```
if ( (Test-Path $path1) -and (Test-Path $path2) ) {
}
``` |
2862746 | "This Friday" in bash script | 9 | 2010-05-19 03:51:18 | <p>Is there a way to calculate a time stamp for the next coming up of a week day?</p>
<p>So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it. </p>
<p>I know the date command can parse a giv... | 5,673 | 192,705 | 2015-12-09 00:51:50 | 2,862,762 | 14 | 2010-05-19 03:56:02 | 47,773 | 2010-05-19 04:05:15 | https://stackoverflow.com/q/2862746 | https://stackoverflow.com/a/2862762 | <p>With GNU date:</p>
<pre><code>date -d 'this Friday' '+%d/%m/%y'
</code></pre>
<p>See <a href="http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings" rel="noreferrer">Relative items in date strings</a>, part of the GNU date documentatoin. There ar... | <p>With GNU date:</p> <pre><code>date -d 'this Friday' '+%d/%m/%y' </code></pre> <p>See <a href="http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings" rel="noreferrer">Relative items in date strings</a>, part of the GNU date documentatoin. There ar... | 387, 5002 | bash, date | <h1>"This Friday" in bash script</h1>
<p>Is there a way to calculate a time stamp for the next coming up of a week day?</p>
<p>So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it. </p>
<p>I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,833 | bash | # "This Friday" in bash script
Is there a way to calculate a time stamp for the next coming up of a week day?
So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it.
I know the date command c... | With GNU date:
```
date -d 'this Friday' '+%d/%m/%y'
```
See [Relative items in date strings](http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings), part of the GNU date documentatoin. There are also [examples](http://www.gnu.org/software/coreutils/... |
1864534 | Windows Powershell SDK and System.Management.Automation.PSObject | 9 | 2009-12-08 04:14:58 | <p>I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS.
It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced.
I did some searching in MSDN and I found that this seems to be part of the Win... | 26,265 | 54,760 | 2009-12-08 20:10:50 | 1,864,660 | 14 | 2009-12-08 04:48:02 | 153,982 | 2009-12-08 04:48:02 | https://stackoverflow.com/q/1864534 | https://stackoverflow.com/a/1864660 | <p>Look in <code>C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0</code> for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-858... | <p>Look in <code>C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0</code> for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-858... | 9, 64, 526, 759 | c#, powershell, sdk, windows | <h1>Windows Powershell SDK and System.Management.Automation.PSObject</h1>
<p>I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS.
It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced.
I di... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,834 | bash | # Windows Powershell SDK and System.Management.Automation.PSObject
I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS.
It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced.
I did some se... | Look in `C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0` for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the [Windows SDK](http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE33... |
1402610 | How do I capture a SQLPlus exit code within a shell script? | 9 | 2009-09-09 23:08:11 | <p>I have a KornShell (ksh) script that logins into SQL*Plus and executing a script. Within the shell script I would like to capture the status code of the SQL statement that was executed. Currently there is an error with SQL and I am unable to capture it by checking $?.
How would I capture the success or error code ... | 40,464 | 150,509 | 2014-01-07 17:47:24 | 1,402,691 | 14 | 2009-09-09 23:35:09 | 81,179 | 2013-12-01 09:24:13 | https://stackoverflow.com/q/1402610 | https://stackoverflow.com/a/1402691 | <p>Have you tried using</p>
<pre><code>whenever sqlerror exit sql.sqlcode
</code></pre>
<p>in your sql script? (also see <a href="http://web.archive.org/web/20100325213119/http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm" rel="nofollow noreferrer">this link</a>)</p>
| <p>Have you tried using</p> <pre><code>whenever sqlerror exit sql.sqlcode </code></pre> <p>in your sql script? (also see <a href="http://web.archive.org/web/20100325213119/http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm" rel="nofollow noreferrer">this link</a>)</p> | 379, 390, 531, 1964, 4480 | error-handling, ksh, scripting, shell, sqlplus | <h1>How do I capture a SQLPlus exit code within a shell script?</h1>
<p>I have a KornShell (ksh) script that logins into SQL*Plus and executing a script. Within the shell script I would like to capture the status code of the SQL statement that was executed. Currently there is an error with SQL and I am unable to capt... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,835 | bash | # How do I capture a SQLPlus exit code within a shell script?
I have a KornShell (ksh) script that logins into SQL*Plus and executing a script. Within the shell script I would like to capture the status code of the SQL statement that was executed. Currently there is an error with SQL and I am unable to capture it by c... | Have you tried using
```
whenever sqlerror exit sql.sqlcode
```
in your sql script? (also see [this link](http://web.archive.org/web/20100325213119/http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm)) |
239526 | truncate output in BASH | 9 | 2008-10-27 10:35:43 | <p>How do I truncate output in BASH? </p>
<p>For example, if I "du file.name" how do I just get the numeric value and nothing more?</p>
<p>later addition:<br>
all solutions work perfectly. I chose to accept the most enlightning "cut" answer because I prefer the simplest approach in bash files others are supposed to b... | 8,957 | 11,813 | 2008-10-27 12:59:39 | 239,532 | 14 | 2008-10-27 10:39:00 | 20,074 | 2008-10-27 11:31:38 | https://stackoverflow.com/q/239526 | https://stackoverflow.com/a/239532 | <p>If you know what the delimiters are then cut is your friend</p>
<pre><code>du | cut -f1
</code></pre>
<p>Cut defaults to tab delimiters so in this case you are selecting the first field. </p>
<p>You can change delimiters: cut -d ' ' would use a space as a delimiter. (from <a href="https://stackoverflow.com/users/... | <p>If you know what the delimiters are then cut is your friend</p> <pre><code>du | cut -f1 </code></pre> <p>Cut defaults to tab delimiters so in this case you are selecting the first field. </p> <p>You can change delimiters: cut -d ' ' would use a space as a delimiter. (from <a href="https://stackoverflow.com/users/... | 58, 387 | bash, linux | <h1>truncate output in BASH</h1>
<p>How do I truncate output in BASH? </p>
<p>For example, if I "du file.name" how do I just get the numeric value and nothing more?</p>
<p>later addition:<br>
all solutions work perfectly. I chose to accept the most enlightning "cut" answer because I prefer the simplest approach in ba... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,836 | bash | # truncate output in BASH
How do I truncate output in BASH?
For example, if I "du file.name" how do I just get the numeric value and nothing more?
later addition:
all solutions work perfectly. I chose to accept the most enlightning "cut" answer because I prefer the simplest approach in bash files others are suppos... | If you know what the delimiters are then cut is your friend
```
du | cut -f1
```
Cut defaults to tab delimiters so in this case you are selecting the first field.
You can change delimiters: cut -d ' ' would use a space as a delimiter. (from [Tomalak](https://stackoverflow.com/users/18771/tomalak))
You can also sele... |
72895720 | pre-commit hook does not echo on terminal | 8 | 2022-07-07 09:49:51 | <p>I am trying to run a script with pre-commit hook. Here is my script:</p>
<p>build_script.sh</p>
<pre><code> #! /bin/bash
echo "Stage 1: Preparing CMake configuration"
</code></pre>
<p>.pre-commit-config.yaml</p>
<pre><code>fail_fast: false
- repo: local
hooks:
- id: Generate build
nam... | 5,722 | 13,626,038 | 2022-07-07 13:36:51 | 72,898,524 | 14 | 2022-07-07 13:16:24 | 812,183 | 2022-07-07 13:16:24 | https://stackoverflow.com/q/72895720 | https://stackoverflow.com/a/72898524 | <p>pre-commit takes a bit from unix philosophy here -- it is silent unless there is a problem (by default).</p>
<p>if your script fails then the output will be displayed</p>
<p>you can also use <code>--verbose</code> to show the full output (for debugging) and optionally set <a href="https://pre-commit.com/#config-verb... | <p>pre-commit takes a bit from unix philosophy here -- it is silent unless there is a problem (by default).</p> <p>if your script fails then the output will be displayed</p> <p>you can also use <code>--verbose</code> to show the full output (for debugging) and optionally set <a href="https://pre-commit.com/#config-verb... | 387, 13824, 25281, 139402 | bash, echo, pre-commit.com, pre-commit-hook | <h1>pre-commit hook does not echo on terminal</h1>
<p>I am trying to run a script with pre-commit hook. Here is my script:</p>
<p>build_script.sh</p>
<pre><code> #! /bin/bash
echo "Stage 1: Preparing CMake configuration"
</code></pre>
<p>.pre-commit-config.yaml</p>
<pre><code>fail_fast: false
- repo: local... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,837 | bash | # pre-commit hook does not echo on terminal
I am trying to run a script with pre-commit hook. Here is my script:
build_script.sh
```
#! /bin/bash
echo "Stage 1: Preparing CMake configuration"
```
.pre-commit-config.yaml
```
fail_fast: false
- repo: local
hooks:
- id: Generate build
name: Gen... | pre-commit takes a bit from unix philosophy here -- it is silent unless there is a problem (by default).
if your script fails then the output will be displayed
you can also use `--verbose` to show the full output (for debugging) and optionally set [`verbose: true`](https://pre-commit.com/#config-verbose) on your hook... |
71963736 | how to get multiple values from a json array/object using jq | 8 | 2022-04-22 05:15:19 | <p>how to get multiple values from a JSON array/object using jq in a single line?</p>
<p>here curl request and its response</p>
<pre><code>curl -s -k --location --request GET "https://${HOSTNAME}/api/v1/projects/myProjects?page=1&pageSize=2" --header "Authorization: Bearer "$token"" | ... | 4,562 | 14,004,008 | 2024-01-12 12:54:33 | 71,964,370 | 14 | 2022-04-22 06:35:46 | 2,158,479 | 2022-04-22 06:35:46 | https://stackoverflow.com/q/71963736 | https://stackoverflow.com/a/71964370 | <p>With <code>.[].name + " " + .[].id'</code> you iterate twice over the array. Iterate once and extract your data in one go:</p>
<pre class="lang-sh prettyprint-override"><code>curl … | jq -r '.data[] | .name + " " + .id'
</code></pre>
<pre class="lang-none prettyprint-override"><code>Netbank734113... | <p>With <code>.[].name + " " + .[].id'</code> you iterate twice over the array. Iterate once and extract your data in one go:</p> <pre class="lang-sh prettyprint-override"><code>curl … | jq -r '.data[] | .name + " " + .id' </code></pre> <pre class="lang-none prettyprint-override"><code>Netbank734113... | 390, 105170 | jq, shell | <h1>how to get multiple values from a json array/object using jq</h1>
<p>how to get multiple values from a JSON array/object using jq in a single line?</p>
<p>here curl request and its response</p>
<pre><code>curl -s -k --location --request GET "https://${HOSTNAME}/api/v1/projects/myProjects?page=1&pageSize=2&... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,838 | bash | # how to get multiple values from a json array/object using jq
how to get multiple values from a JSON array/object using jq in a single line?
here curl request and its response
```
curl -s -k --location --request GET "https://${HOSTNAME}/api/v1/projects/myProjects?page=1&pageSize=2" --header "Authorization: Bearer "... | With `.[].name + " " + .[].id'` you iterate twice over the array. Iterate once and extract your data in one go:
```
curl … | jq -r '.data[] | .name + " " + .id'
```
```
Netbank734113 8a70803f8045722601804f62d54c5d9d
Netbank734112 8a70801c804568ae01804f625a923f8d
```
[Demo](https://jqplay.org/s/ZJ2MpA4D9q)
---
You ... |
69430038 | Conda environment name hides git branch after conda init in Powershell | 8 | 2021-10-04 01:16:20 | <p>I have the Posh-Git module installed for Powershell and, recently, I also installed Anaconda and did <code>conda init</code>. Apparently, this modifies the <code>profile.ps1</code> file by adding the following code:</p>
<pre><code>#region conda initialize
# !! Contents within this block are managed by 'conda init' !... | 658 | 3,121,975 | 2021-12-30 03:37:03 | 70,527,216 | 14 | 2021-12-30 03:37:03 | 7,735,643 | 2021-12-30 03:37:03 | https://stackoverflow.com/q/69430038 | https://stackoverflow.com/a/70527216 | <p>The posh-git <a href="https://github.com/dahlbyk/posh-git#customizing-the-posh-git-prompt" rel="noreferrer">docs</a> state that posh-git won't modify a custom prompt. So when you run <code>Import-Module posh-git</code> after conda has initialized, you won't see anything change. The solution is to put <code>Import-Mo... | <p>The posh-git <a href="https://github.com/dahlbyk/posh-git#customizing-the-posh-git-prompt" rel="noreferrer">docs</a> state that posh-git won't modify a custom prompt. So when you run <code>Import-Module posh-git</code> after conda has initialized, you won't see anything change. The solution is to put <code>Import-Mo... | 119, 526, 96537 | conda, git, powershell | <h1>Conda environment name hides git branch after conda init in Powershell</h1>
<p>I have the Posh-Git module installed for Powershell and, recently, I also installed Anaconda and did <code>conda init</code>. Apparently, this modifies the <code>profile.ps1</code> file by adding the following code:</p>
<pre><code>#regio... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,839 | bash | # Conda environment name hides git branch after conda init in Powershell
I have the Posh-Git module installed for Powershell and, recently, I also installed Anaconda and did `conda init`. Apparently, this modifies the `profile.ps1` file by adding the following code:
```
#region conda initialize
# !! Contents within t... | The posh-git [docs](https://github.com/dahlbyk/posh-git#customizing-the-posh-git-prompt) state that posh-git won't modify a custom prompt. So when you run `Import-Module posh-git` after conda has initialized, you won't see anything change. The solution is to put `Import-Module posh-git` before the conda initialization ... |
63291583 | Powershell: What's the difference between Alias and Function? | 8 | 2020-08-06 20:53:05 | <p>Im setting up my powershell profile to create aliases of commonly used commands. <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7#examples" rel="noreferrer">On Microsoft's documentation</a> it says, if I want to make an alias for a command with par... | 4,527 | 5,614,052 | 2026-01-11 14:45:00 | 63,292,585 | 14 | 2020-08-06 22:23:33 | 45,375 | 2026-01-11 14:45:00 | https://stackoverflow.com/q/63291583 | https://stackoverflow.com/a/63292585 | <ul>
<li><p>An <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Aliases" rel="nofollow noreferrer"><strong><em>alias</em></strong></a> in PowerShell allows you to define <strong><em>an alternative name</em> for another command</strong>.</p>
<ul>
<li><p>Unlike in POSIX-c... | <ul> <li><p>An <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Aliases" rel="nofollow noreferrer"><strong><em>alias</em></strong></a> in PowerShell allows you to define <strong><em>an alternative name</em> for another command</strong>.</p> <ul> <li><p>Unlike in POSIX-c... | 64, 526, 531, 1448, 5569 | alias, function, powershell, scripting, windows | <h1>Powershell: What's the difference between Alias and Function?</h1>
<p>Im setting up my powershell profile to create aliases of commonly used commands. <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7#examples" rel="noreferrer">On Microsoft's docum... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,840 | bash | # Powershell: What's the difference between Alias and Function?
Im setting up my powershell profile to create aliases of commonly used commands. [On Microsoft's documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7#examples) it says, if I want to ma... | - An [***alias***](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Aliases) in PowerShell allows you to define ***an alternative name* for another command**.
- Unlike in POSIX-compatible shells such as `bash`, **you *cannot include pass-through arguments* in its definition -... |
61606054 | Passing Ipython variables as string arguments to shell command | 8 | 2020-05-05 04:56:51 | <p>How do I execute a shell command from Ipython/Jupyter notebook passing the value of a python string variable as a string in the bash argument like in this example:</p>
<pre><code>sp_name = 'littleGuy' #the variable
sp_details = !az ad app list --filter "DisplayName eq '$sp_name'" #the shell command
</code></pre>
... | 8,612 | 5,976,033 | 2020-05-15 07:38:16 | 61,699,906 | 14 | 2020-05-09 16:14:51 | 4,611,565 | 2020-05-09 16:28:03 | https://stackoverflow.com/q/61606054 | https://stackoverflow.com/a/61699906 | <p>The main problem you encounters seems to come from the quotes needed in your string.
You can keep the quotes in your string by using a format instruction and a raw string.</p>
<p>Use a 'r' before the whole string to indicate it is to be read as raw string, ie: special caracters have to not be interpreted. A raw str... | <p>The main problem you encounters seems to come from the quotes needed in your string. You can keep the quotes in your string by using a format instruction and a raw string.</p> <p>Use a 'r' before the whole string to indicate it is to be read as raw string, ie: special caracters have to not be interpreted. A raw str... | 16, 390, 14670 | ipython, python, shell | <h1>Passing Ipython variables as string arguments to shell command</h1>
<p>How do I execute a shell command from Ipython/Jupyter notebook passing the value of a python string variable as a string in the bash argument like in this example:</p>
<pre><code>sp_name = 'littleGuy' #the variable
sp_details = !az ad app list... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,841 | bash | # Passing Ipython variables as string arguments to shell command
How do I execute a shell command from Ipython/Jupyter notebook passing the value of a python string variable as a string in the bash argument like in this example:
```
sp_name = 'littleGuy' #the variable
sp_details = !az ad app list --filter "DisplayNa... | The main problem you encounters seems to come from the quotes needed in your string.
You can keep the quotes in your string by using a format instruction and a raw string.
Use a 'r' before the whole string to indicate it is to be read as raw string, ie: special caracters have to not be interpreted. A raw string is not... |
60808333 | Unknown V4L2 pixel format equivalent for yuvj420p | 8 | 2020-03-23 05:27:17 | <p>I am trying to pipe a mp4 video located in Videos/video.mp4 to a virtual webcam device located at /dev/video0.</p>
<p>I tried running:
<code>ffmpeg -re -i Videos/video.mp4 -map 0:v -f v4l2 /dev/video0</code>
and I keep getting the following error:</p>
<pre><code>[video4linux2,v4l2 @ 0x5580cf270100] Unknown V4L2 pi... | 7,393 | 11,787,588 | 2020-03-23 06:22:33 | 60,808,772 | 14 | 2020-03-23 06:22:33 | 1,109,017 | 2020-03-23 06:22:33 | https://stackoverflow.com/q/60808333 | https://stackoverflow.com/a/60808772 | <p>Add <code>-vf format=yuv420p</code> (or the alias <code>-pix_fmt yuv420p</code>).</p>
<p>The v4l2 output device doesn't support yuvj420p which is the pixel format of your input. In most cases <code>ffmpeg</code> will automatically choose a supported pixel format, but it is unable to do so for V4L2 output, so you ha... | <p>Add <code>-vf format=yuv420p</code> (or the alias <code>-pix_fmt yuv420p</code>).</p> <p>The v4l2 output device doesn't support yuvj420p which is the pixel format of your input. In most cases <code>ffmpeg</code> will automatically choose a supported pixel format, but it is unable to do so for V4L2 output, so you ha... | 58, 387, 519, 3847, 114342 | bash, ffmpeg, linux, v4l2loopback, video | <h1>Unknown V4L2 pixel format equivalent for yuvj420p</h1>
<p>I am trying to pipe a mp4 video located in Videos/video.mp4 to a virtual webcam device located at /dev/video0.</p>
<p>I tried running:
<code>ffmpeg -re -i Videos/video.mp4 -map 0:v -f v4l2 /dev/video0</code>
and I keep getting the following error:</p>
<pre... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,842 | bash | # Unknown V4L2 pixel format equivalent for yuvj420p
I am trying to pipe a mp4 video located in Videos/video.mp4 to a virtual webcam device located at /dev/video0.
I tried running:
`ffmpeg -re -i Videos/video.mp4 -map 0:v -f v4l2 /dev/video0`
and I keep getting the following error:
```
[video4linux2,v4l2 @ 0x5580cf27... | Add `-vf format=yuv420p` (or the alias `-pix_fmt yuv420p`).
The v4l2 output device doesn't support yuvj420p which is the pixel format of your input. In most cases `ffmpeg` will automatically choose a supported pixel format, but it is unable to do so for V4L2 output, so you have to manually do it:
```
ffmpeg -re -i Vi... |
59079861 | How to update "physical path" of a site on IIS 10 using Powershell? | 8 | 2019-11-27 23:37:44 | <p>When creating a site I manage to set the path with the following line of code</p>
<pre><code>New-WebSite -Name "mysite" -port 8084 -PhysicalPath "c:\inetpub\wwwroot" -ApplicationPool "myappPool"
</code></pre>
<p>I have tried to figure out how to update the path, nothing found via Configuration Editor. I thought I ... | 12,496 | 512,139 | 2023-12-08 19:17:09 | 59,081,204 | 14 | 2019-11-28 03:09:54 | 11,147,346 | 2019-11-28 03:09:54 | https://stackoverflow.com/q/59079861 | https://stackoverflow.com/a/59081204 | <p>You could use below PowerShell command to change the iis site physical path.</p>
<p>run PowerShell as administrator.</p>
<p>run below command:</p>
<pre><code>PS C:\WINDOWS\system32> Import-Module WebAdministration
PS C:\WINDOWS\system32> Set-ItemProperty IIS:\Sites\sitea -name physicalPath -value "D:\s1"
<... | <p>You could use below PowerShell command to change the iis site physical path.</p> <p>run PowerShell as administrator.</p> <p>run below command:</p> <pre><code>PS C:\WINDOWS\system32> Import-Module WebAdministration PS C:\WINDOWS\system32> Set-ItemProperty IIS:\Sites\sitea -name physicalPath -value "D:\s1" <... | 215, 526, 68067 | iis, powershell, web-administration | <h1>How to update "physical path" of a site on IIS 10 using Powershell?</h1>
<p>When creating a site I manage to set the path with the following line of code</p>
<pre><code>New-WebSite -Name "mysite" -port 8084 -PhysicalPath "c:\inetpub\wwwroot" -ApplicationPool "myappPool"
</code></pre>
<p>I have tried to figure out... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,843 | bash | # How to update "physical path" of a site on IIS 10 using Powershell?
When creating a site I manage to set the path with the following line of code
```
New-WebSite -Name "mysite" -port 8084 -PhysicalPath "c:\inetpub\wwwroot" -ApplicationPool "myappPool"
```
I have tried to figure out how to update the path, nothing ... | You could use below PowerShell command to change the iis site physical path.
run PowerShell as administrator.
run below command:
```
PS C:\WINDOWS\system32> Import-Module WebAdministration
PS C:\WINDOWS\system32> Set-ItemProperty IIS:\Sites\sitea -name physicalPath -value "D:\s1"
```
after changing the path open i... |
58861008 | Get first value after Where-Object condition | 8 | 2019-11-14 16:02:00 | <p>Give the following command how to get only the first value after the <code>where</code> condition? </p>
<pre><code>Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
select id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} |
where USER -notlike 'condition'
</code></pre>
... | 5,609 | 12,373,804 | 2019-11-14 16:21:25 | 58,861,063 | 14 | 2019-11-14 16:04:54 | 584,676 | 2019-11-14 16:21:25 | https://stackoverflow.com/q/58861008 | https://stackoverflow.com/a/58861063 | <p>Pipe your results to <code>Select-Object -First 1</code> like so:</p>
<pre><code>Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
Select-Object Id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} |
Where-Object { $_.USER -notlike 'condition' } |
Select-Object -First 1... | <p>Pipe your results to <code>Select-Object -First 1</code> like so:</p> <pre><code>Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} | Select-Object Id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} | Where-Object { $_.USER -notlike 'condition' } | Select-Object -First 1... | 526 | powershell | <h1>Get first value after Where-Object condition</h1>
<p>Give the following command how to get only the first value after the <code>where</code> condition? </p>
<pre><code>Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
select id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Valu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,844 | bash | # Get first value after Where-Object condition
Give the following command how to get only the first value after the `where` condition?
```
Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
select id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} |
where USER -notlike 'con... | Pipe your results to `Select-Object -First 1` like so:
```
Get-WinEvent -FilterHashtable @{Logname = 'Security';EndTime=$Time; ID = 5379} |
Select-Object Id , TimeCreated, @{ n='USER'; E ={ $_.Properties[1].Value}} |
Where-Object { $_.USER -notlike 'condition' } |
Select-Object -First 1
``` |
55912074 | How does one properly assign temporary Bash variables on a per-command basis? | 8 | 2019-04-29 23:35:50 | <p>Bash seems to behave unpredictably in regards to temporary, per-command variable assignment, specifically with <code>IFS</code>.</p>
<p>I often assign <code>IFS</code> to a temporary value in conjunction with the <code>read</code> command. I would like to use the same mechanic to tailor output, but currently resort... | 16,897 | 11,053,344 | 2024-03-14 10:07:39 | 55,912,332 | 14 | 2019-04-30 00:14:09 | 922,613 | 2019-04-30 00:14:09 | https://stackoverflow.com/q/55912074 | https://stackoverflow.com/a/55912332 | <pre><code>$ foo=bar
$ foo=qux echo $foo
bar
</code></pre>
<p>This is a common bash gotcha -- and <a href="https://www.shellcheck.net/" rel="noreferrer">https://www.shellcheck.net/</a> catches it:</p>
<pre><code>
foo=qux echo $foo
^-- SC2097: This assignment is only seen by the forked process.
^-- SC2098... | <pre><code>$ foo=bar $ foo=qux echo $foo bar </code></pre> <p>This is a common bash gotcha -- and <a href="https://www.shellcheck.net/" rel="noreferrer">https://www.shellcheck.net/</a> catches it:</p> <pre><code> foo=qux echo $foo ^-- SC2097: This assignment is only seen by the forked process. ^-- SC2098... | 387, 2182, 26793 | bash, ifs, scope | <h1>How does one properly assign temporary Bash variables on a per-command basis?</h1>
<p>Bash seems to behave unpredictably in regards to temporary, per-command variable assignment, specifically with <code>IFS</code>.</p>
<p>I often assign <code>IFS</code> to a temporary value in conjunction with the <code>read</code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,846 | bash | # How does one properly assign temporary Bash variables on a per-command basis?
Bash seems to behave unpredictably in regards to temporary, per-command variable assignment, specifically with `IFS`.
I often assign `IFS` to a temporary value in conjunction with the `read` command. I would like to use the same mechanic ... | ```
$ foo=bar
$ foo=qux echo $foo
bar
```
This is a common bash gotcha -- and <https://www.shellcheck.net/> catches it:
```
foo=qux echo $foo
^-- SC2097: This assignment is only seen by the forked process.
^-- SC2098: This expansion will not see the mentioned assignment.
```
The issue is that the first ... |
54658352 | passing quoted arguments from batch file to `powershell start` - self-elevation on demand | 8 | 2019-02-12 20:37:32 | <p>I am writing a Windows batch file that automatically escalates itself to administrative permissions, provided the user clicks "Yes" on the User Access Control dialog that appears.</p>
<p>I am using a technique I learned <a href="https://stackoverflow.com/a/11995662">here</a> to detect whether we already have admin ... | 2,110 | 3,019,689 | 2023-04-24 01:51:10 | 54,701,990 | 14 | 2019-02-15 02:43:37 | 45,375 | 2023-04-24 01:51:10 | https://stackoverflow.com/q/54658352 | https://stackoverflow.com/a/54701990 |
<ul>
<li><p>You've run into a perfect storm of <em>two</em> quoting hells (<code>cmd</code> <em>and</em> PowerShell), garnished with a <a href="https://github.com/PowerShell/PowerShell/issues/8898" rel="nofollow noreferrer">PowerShell bug</a> (as of PowerShell Core 6.2.0).</p>
</li>
<li><p>To work around the bug, the ... | <ul> <li><p>You've run into a perfect storm of <em>two</em> quoting hells (<code>cmd</code> <em>and</em> PowerShell), garnished with a <a href="https://github.com/PowerShell/PowerShell/issues/8898" rel="nofollow noreferrer">PowerShell bug</a> (as of PowerShell Core 6.2.0).</p> </li> <li><p>To work around the bug, the ... | 430, 526, 4804, 7002, 60888 | batch-file, elevated-privileges, escaping, powershell, quotes | <h1>passing quoted arguments from batch file to `powershell start` - self-elevation on demand</h1>
<p>I am writing a Windows batch file that automatically escalates itself to administrative permissions, provided the user clicks "Yes" on the User Access Control dialog that appears.</p>
<p>I am using a technique I learn... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,847 | bash | # passing quoted arguments from batch file to `powershell start` - self-elevation on demand
I am writing a Windows batch file that automatically escalates itself to administrative permissions, provided the user clicks "Yes" on the User Access Control dialog that appears.
I am using a technique I learned [here](https:... | - You've run into a perfect storm of *two* quoting hells (`cmd` *and* PowerShell), garnished with a [PowerShell bug](https://github.com/PowerShell/PowerShell/issues/8898) (as of PowerShell Core 6.2.0).
- To work around the bug, the batch file cannot be reinvoked *directly* and must instead be reinvoked via `cmd /c`.
- ... |
52174455 | using powershell to replace extended ascii character in a text file | 8 | 2018-09-04 21:52:17 | <p>I'm needing to replace a hex 93 character to a "" string inside several csv files. Below is the code that I'm using. But it is not working I think the reason that it does not work is because the hex value is greater than 7F (Dec 127). I've tried several other methods to no avail. Any help would be appreciated.<... | 16,155 | 2,187,053 | 2019-08-14 02:03:10 | 52,176,525 | 14 | 2018-09-05 03:12:07 | 45,375 | 2019-08-14 02:03:10 | https://stackoverflow.com/q/52174455 | https://stackoverflow.com/a/52176525 | <p><strong>In Windows PowerShell, the default character encoding when reading from / writing to<sup>[1]</sup> <em>files</em> is "ANSI"</strong>, i.e., the legacy 8-bit code page implied by the active system locale.<br>
(By contrast, PowerShell <em>Core</em> defaults to UTF-8.)</p>
<p>For instance, the code page associ... | <p><strong>In Windows PowerShell, the default character encoding when reading from / writing to<sup>[1]</sup> <em>files</em> is "ANSI"</strong>, i.e., the legacy 8-bit code page implied by the active system locale.<br> (By contrast, PowerShell <em>Core</em> defaults to UTF-8.)</p> <p>For instance, the code page associ... | 526, 2498, 12658 | character-encoding, powershell, replace | <h1>using powershell to replace extended ascii character in a text file</h1>
<p>I'm needing to replace a hex 93 character to a "" string inside several csv files. Below is the code that I'm using. But it is not working I think the reason that it does not work is because the hex value is greater than 7F (Dec 127). I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,848 | bash | # using powershell to replace extended ascii character in a text file
I'm needing to replace a hex 93 character to a "" string inside several csv files. Below is the code that I'm using. But it is not working I think the reason that it does not work is because the hex value is greater than 7F (Dec 127). I've tried sev... | **In Windows PowerShell, the default character encoding when reading from / writing to[1] *files* is "ANSI"**, i.e., the legacy 8-bit code page implied by the active system locale.
(By contrast, PowerShell *Core* defaults to UTF-8.)
For instance, the code page associated with the system locale on an US-English syste... |
51293191 | how to run powershell script through excel VBA | 8 | 2018-07-11 19:45:33 | <p>I am trying to use an Excel VBA macro to launch a PowerShell script if a certain condition is met. I'm not getting any errors in the code when it runs and I am able to manually run the PowerShell script from the Windows Explorer window without errors. However, when I execute the below VBA code, the PowerShell does n... | 46,985 | 5,393,024 | 2018-07-12 11:47:08 | 51,293,698 | 14 | 2018-07-11 20:25:10 | 478,884 | 2018-07-11 20:25:10 | https://stackoverflow.com/q/51293191 | https://stackoverflow.com/a/51293698 | <p>If your file path has spaces you need to put quotes around it. </p>
<pre><code>x = Shell("POWERSHELL.exe -noexit " & _
"""H:\Operations\REPORTS\Reports2018\Balance Sheet\SLmarginJE.ps1""", 1)
</code></pre>
| <p>If your file path has spaces you need to put quotes around it. </p> <pre><code>x = Shell("POWERSHELL.exe -noexit " & _ """H:\Operations\REPORTS\Reports2018\Balance Sheet\SLmarginJE.ps1""", 1) </code></pre> | 522, 526, 1449 | excel, powershell, vba | <h1>how to run powershell script through excel VBA</h1>
<p>I am trying to use an Excel VBA macro to launch a PowerShell script if a certain condition is met. I'm not getting any errors in the code when it runs and I am able to manually run the PowerShell script from the Windows Explorer window without errors. However, ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,849 | bash | # how to run powershell script through excel VBA
I am trying to use an Excel VBA macro to launch a PowerShell script if a certain condition is met. I'm not getting any errors in the code when it runs and I am able to manually run the PowerShell script from the Windows Explorer window without errors. However, when I ex... | If your file path has spaces you need to put quotes around it.
```
x = Shell("POWERSHELL.exe -noexit " & _
"""H:\Operations\REPORTS\Reports2018\Balance Sheet\SLmarginJE.ps1""", 1)
``` |
49449190 | golang on windows: How to build for Linux? | 8 | 2018-03-23 11:58:15 | <p>How do I compile a go file/project on windows for Linux?</p>
<p>On Linux it should be possible via one-liner: </p>
<pre><code>GOOS=windows go build -o filename.exe codefile.go
</code></pre>
<p>I tried something similar via Powershell, but on my Linux server (Ubuntu 16.04 amd64) only an error appears:</p>
<blockq... | 16,833 | null | 2018-03-23 18:28:12 | 49,449,564 | 14 | 2018-03-23 12:22:11 | 9,060,838 | 2018-03-23 16:41:05 | https://stackoverflow.com/q/49449190 | https://stackoverflow.com/a/49449564 | <p>Use git bash if you have it installed οn your machine and execute the below command</p>
<pre><code>env GOOS=linux go build -o filename
</code></pre>
<p>You could set the execution operating system for the whole command session through:</p>
<pre><code>set GOOS=linux
go build -o filename
</code></pre>
<p>It worked... | <p>Use git bash if you have it installed οn your machine and execute the below command</p> <pre><code>env GOOS=linux go build -o filename </code></pre> <p>You could set the execution operating system for the whole command session through:</p> <pre><code>set GOOS=linux go build -o filename </code></pre> <p>It worked... | 526, 9013, 11282, 15627 | cross-compiling, environment-variables, go, powershell | <h1>golang on windows: How to build for Linux?</h1>
<p>How do I compile a go file/project on windows for Linux?</p>
<p>On Linux it should be possible via one-liner: </p>
<pre><code>GOOS=windows go build -o filename.exe codefile.go
</code></pre>
<p>I tried something similar via Powershell, but on my Linux server (Ubu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,851 | bash | # golang on windows: How to build for Linux?
How do I compile a go file/project on windows for Linux?
On Linux it should be possible via one-liner:
```
GOOS=windows go build -o filename.exe codefile.go
```
I tried something similar via Powershell, but on my Linux server (Ubuntu 16.04 amd64) only an error appears:
... | Use git bash if you have it installed οn your machine and execute the below command
```
env GOOS=linux go build -o filename
```
You could set the execution operating system for the whole command session through:
```
set GOOS=linux
go build -o filename
```
It worked for me on same Windows 10 version and runs smoothl... |
48837407 | How would I pick a random character from a string/array with Bash? | 8 | 2018-02-17 02:49:08 | <p>I have an example where I am attempting to randomly generate a letter in a set of letters (i.e. var="abcdefghijklmnopqrstuvwxyz").</p>
<p><strong>How would I have:</strong></p>
<pre><code>var="abcdefghijklmnopqrstuvwxyz"
echo "${var}"
</code></pre>
<p><strong>yield:</strong> <em><code>some_letter</code></em></p>... | 6,973 | 9,277,587 | 2021-08-04 22:17:36 | 48,837,435 | 14 | 2018-02-17 02:53:21 | 14,122 | 2018-02-17 14:53:19 | https://stackoverflow.com/q/48837407 | https://stackoverflow.com/a/48837435 | <pre><code>var="abcdefghijklmnopqrstuvwxyz"
echo "${var:$(( RANDOM % ${#var} )):1}" # pick a 1 char substring starting at a random position
</code></pre>
<p>This works because:</p>
<ul>
<li><code>${var:START:LEN}</code> is a <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a> tha... | <pre><code>var="abcdefghijklmnopqrstuvwxyz" echo "${var:$(( RANDOM % ${#var} )):1}" # pick a 1 char substring starting at a random position </code></pre> <p>This works because:</p> <ul> <li><code>${var:START:LEN}</code> is a <a href="http://wiki.bash-hackers.org/syntax/pe" rel="noreferrer">parameter expansion</a> tha... | 197, 387 | bash, random | <h1>How would I pick a random character from a string/array with Bash?</h1>
<p>I have an example where I am attempting to randomly generate a letter in a set of letters (i.e. var="abcdefghijklmnopqrstuvwxyz").</p>
<p><strong>How would I have:</strong></p>
<pre><code>var="abcdefghijklmnopqrstuvwxyz"
echo "${var}"
</c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,852 | bash | # How would I pick a random character from a string/array with Bash?
I have an example where I am attempting to randomly generate a letter in a set of letters (i.e. var="abcdefghijklmnopqrstuvwxyz").
**How would I have:**
```
var="abcdefghijklmnopqrstuvwxyz"
echo "${var}"
```
**yield:** *`some_letter`*
The point ... | ```
var="abcdefghijklmnopqrstuvwxyz"
echo "${var:$(( RANDOM % ${#var} )):1}" # pick a 1 char substring starting at a random position
```
This works because:
- `${var:START:LEN}` is a [parameter expansion](http://wiki.bash-hackers.org/syntax/pe) that expands to a substing of `$var`
- `${#var}` is a parameter expansion... |
47285157 | Output multiple commands into columns | 8 | 2017-11-14 11:52:13 | <p>I'm trying to write a script which runs various commands and outputs the result of each command into one column but I'm not able to get the output ot be displayed in colums.</p>
<pre><code>#!/bin/bash
# Get GBP Neighbour NAMES
NEIGHBOR=$(vtysh -c 'show ip bgp neighbors' | grep Incoming | awk '{print $7}')
# Get IP... | 3,831 | 1,213,611 | 2020-07-04 07:20:10 | 47,285,336 | 14 | 2017-11-14 12:00:27 | 3,185,459 | 2017-11-14 12:00:27 | https://stackoverflow.com/q/47285157 | https://stackoverflow.com/a/47285336 | <p>With <strong><code>paste</code></strong> command:</p>
<pre><code>paste -d'|' <(echo "$NEIGHBOR ") <(echo "$IP") <(echo "$TIME") <(echo "$STATE")
</code></pre>
| <p>With <strong><code>paste</code></strong> command:</p> <pre><code>paste -d'|' <(echo "$NEIGHBOR ") <(echo "$IP") <(echo "$TIME") <(echo "$STATE") </code></pre> | 387 | bash | <h1>Output multiple commands into columns</h1>
<p>I'm trying to write a script which runs various commands and outputs the result of each command into one column but I'm not able to get the output ot be displayed in colums.</p>
<pre><code>#!/bin/bash
# Get GBP Neighbour NAMES
NEIGHBOR=$(vtysh -c 'show ip bgp neighbors... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,853 | bash | # Output multiple commands into columns
I'm trying to write a script which runs various commands and outputs the result of each command into one column but I'm not able to get the output ot be displayed in colums.
```
#!/bin/bash
# Get GBP Neighbour NAMES
NEIGHBOR=$(vtysh -c 'show ip bgp neighbors' | grep Incoming |... | With **`paste`** command:
```
paste -d'|' <(echo "$NEIGHBOR ") <(echo "$IP") <(echo "$TIME") <(echo "$STATE")
``` |
43357925 | powershell -Or operator not working | 8 | 2017-04-11 23:41:14 | <p>Can someone tell me why the -or does not work. If I run the code the first output is administrator which returns true but when it gets to the kahuna account it still returns false not true.</p>
<pre><code>(Get-LocalUser).Name | Out-File C:\localusers.txt
ForEach ($User in Get-Content C:\localusers.txt)
{
If (... | 17,532 | 7,469,795 | 2019-02-09 17:22:46 | 43,357,955 | 14 | 2017-04-11 23:45:37 | 5,487,553 | 2017-04-11 23:45:37 | https://stackoverflow.com/q/43357925 | https://stackoverflow.com/a/43357955 | <p>Try</p>
<pre><code>If ($User -match "administrator" -or $User -match "kahuna")
</code></pre>
<p>Your <code>-or</code> operator doesn't tie the values of the previous operator together. You need to specify a 2nd conditional operator after <code>-or</code> I believe.</p>
| <p>Try</p> <pre><code>If ($User -match "administrator" -or $User -match "kahuna") </code></pre> <p>Your <code>-or</code> operator doesn't tie the values of the previous operator together. You need to specify a 2nd conditional operator after <code>-or</code> I believe.</p> | 526 | powershell | <h1>powershell -Or operator not working</h1>
<p>Can someone tell me why the -or does not work. If I run the code the first output is administrator which returns true but when it gets to the kahuna account it still returns false not true.</p>
<pre><code>(Get-LocalUser).Name | Out-File C:\localusers.txt
ForEach ($User... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,854 | bash | # powershell -Or operator not working
Can someone tell me why the -or does not work. If I run the code the first output is administrator which returns true but when it gets to the kahuna account it still returns false not true.
```
(Get-LocalUser).Name | Out-File C:\localusers.txt
ForEach ($User in Get-Content C:\lo... | Try
```
If ($User -match "administrator" -or $User -match "kahuna")
```
Your `-or` operator doesn't tie the values of the previous operator together. You need to specify a 2nd conditional operator after `-or` I believe. |
42810888 | How would I create a text file and fill it with sudo permission in bash | 8 | 2017-03-15 13:14:14 | <p>I'm trying to create and fill a file in a directory that requires sudo permission. I've tried:</p>
<pre><code>$ echo 'hello' > sudo tee /data/hello
</code></pre>
<p>However, I just get the output that /etc/file does not exist:</p>
<pre><code>$ cat /data/hello
cat: /data/hello: No such file or directory
</code></p... | 24,634 | 7,491,660 | 2023-08-10 15:01:45 | 42,811,643 | 14 | 2017-03-15 13:47:12 | 14,122 | 2017-03-15 13:47:12 | https://stackoverflow.com/q/42810888 | https://stackoverflow.com/a/42811643 | <p>The question has been edited to include a log of the problem being introduced, which includes the command:</p>
<pre><code># Taken from edited question
$ echo 'hello' > sudo tee /data/hello
</code></pre>
<p>In bash (which allows redirection operators at any point in a simple command), this is precisely equivalen... | <p>The question has been edited to include a log of the problem being introduced, which includes the command:</p> <pre><code># Taken from edited question $ echo 'hello' > sudo tee /data/hello </code></pre> <p>In bash (which allows redirection operators at any point in a simple command), this is precisely equivalen... | 387 | bash | <h1>How would I create a text file and fill it with sudo permission in bash</h1>
<p>I'm trying to create and fill a file in a directory that requires sudo permission. I've tried:</p>
<pre><code>$ echo 'hello' > sudo tee /data/hello
</code></pre>
<p>However, I just get the output that /etc/file does not exist:</p>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,855 | bash | # How would I create a text file and fill it with sudo permission in bash
I'm trying to create and fill a file in a directory that requires sudo permission. I've tried:
```
$ echo 'hello' > sudo tee /data/hello
```
However, I just get the output that /etc/file does not exist:
```
$ cat /data/hello
cat: /data/hello:... | The question has been edited to include a log of the problem being introduced, which includes the command:
```
# Taken from edited question
$ echo 'hello' > sudo tee /data/hello
```
In bash (which allows redirection operators at any point in a simple command), this is precisely equivalent to running:
```
# From ques... |
42245271 | How to run curl in bash script and keep the result in a variable | 8 | 2017-02-15 09:23:57 | <p>This should have been easy but for some reason it's not:</p>
<p>Trying to run a simple <code>curl</code> command, get it's output, and do stuff with it.</p>
<pre><code>cmd='curl -v -H "A: B" http://stackoverflow.com'
result=`$cmd | grep "A:"`
...
</code></pre>
<p>The problem - the header "A: B" is not sent. </p>
... | 74,521 | 1,156,067 | 2021-03-23 07:53:17 | 42,245,484 | 14 | 2017-02-15 09:33:33 | 4,765,902 | 2017-02-15 09:33:33 | https://stackoverflow.com/q/42245271 | https://stackoverflow.com/a/42245484 | <p>Your problem here is that all you are doing on the first command is just setting cmd to equal a string.</p>
<p>Try using <code>$(...)</code> to execute the actual command like so:</p>
<pre><code>cmd=$(curl -v -H "A: B" http://stackoverflow.com)
</code></pre>
<p>The result of this will be the actual output from wi... | <p>Your problem here is that all you are doing on the first command is just setting cmd to equal a string.</p> <p>Try using <code>$(...)</code> to execute the actual command like so:</p> <pre><code>cmd=$(curl -v -H "A: B" http://stackoverflow.com) </code></pre> <p>The result of this will be the actual output from wi... | 387, 1554 | bash, curl | <h1>How to run curl in bash script and keep the result in a variable</h1>
<p>This should have been easy but for some reason it's not:</p>
<p>Trying to run a simple <code>curl</code> command, get it's output, and do stuff with it.</p>
<pre><code>cmd='curl -v -H "A: B" http://stackoverflow.com'
result=`$cmd | grep "A:"... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,856 | bash | # How to run curl in bash script and keep the result in a variable
This should have been easy but for some reason it's not:
Trying to run a simple `curl` command, get it's output, and do stuff with it.
```
cmd='curl -v -H "A: B" http://stackoverflow.com'
result=`$cmd | grep "A:"`
...
```
The problem - the header "A... | Your problem here is that all you are doing on the first command is just setting cmd to equal a string.
Try using `$(...)` to execute the actual command like so:
```
cmd=$(curl -v -H "A: B" http://stackoverflow.com)
```
The result of this will be the actual output from with curl request.
This has been answered many... |
41165719 | Embedding an Expect script inside a Bash script | 8 | 2016-12-15 13:45:42 | <p>I have the following script:</p>
<pre><code>#!/bin/bash
if [ `hostname` = 'EXAMPLE' ]
then
/usr/bin/expect << EOD
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
spawn scp -rp host:~/errfiles/ /home/USERNAME/errfiles/
expect "id_rsa':"
send "PASSWORD\r"... | 16,808 | 6,013,700 | 2020-06-12 20:18:54 | 41,173,047 | 14 | 2016-12-15 20:45:16 | 2,877,364 | 2020-06-12 20:18:54 | https://stackoverflow.com/q/41165719 | https://stackoverflow.com/a/41173047 | <p>Your Bash script is passing the Expect commands on the standard input of <code>expect</code>. That is what the <a href="http://wiki.bash-hackers.org/syntax/redirection?s[]=redirection#here_documents" rel="noreferrer">here-document</a> <code><<EOD</code> does. However, <code>expect</code>... expects its command... | <p>Your Bash script is passing the Expect commands on the standard input of <code>expect</code>. That is what the <a href="http://wiki.bash-hackers.org/syntax/redirection?s[]=redirection#here_documents" rel="noreferrer">here-document</a> <code><<EOD</code> does. However, <code>expect</code>... expects its command... | 387, 9048 | bash, expect | <h1>Embedding an Expect script inside a Bash script</h1>
<p>I have the following script:</p>
<pre><code>#!/bin/bash
if [ `hostname` = 'EXAMPLE' ]
then
/usr/bin/expect << EOD
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
spawn scp -rp host:~/errfiles/ /ho... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,857 | bash | # Embedding an Expect script inside a Bash script
I have the following script:
```
#!/bin/bash
if [ `hostname` = 'EXAMPLE' ]
then
/usr/bin/expect << EOD
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
spawn scp -rp host:~/errfiles/ /home/USERNAME/errfiles/
expe... | Your Bash script is passing the Expect commands on the standard input of `expect`. That is what the [here-document](http://wiki.bash-hackers.org/syntax/redirection?s[]=redirection#here_documents) `<<EOD` does. However, `expect`... expects its commands to be provided in a file, or as the argument of a `-c`, per the [man... |
39967359 | Can I use TLS with Send-MailMessage cmdlet? | 8 | 2016-10-10 21:55:48 | <p>I am trying to send an email using PowerShell, but need to use TLS. Any way I can do that using Send-MailMessage cmdlet?</p>
<p>This is my code:</p>
<pre><code>$file = "c:\Mail-content.txt"
if (test-path $file)
{
$from = "afgarciact@gmail.com"
$to = "<slopez@comfama.com.co>","<carloscu@comfama.c... | 65,391 | 2,355,322 | 2022-02-26 09:53:43 | 39,967,829 | 14 | 2016-10-10 22:41:25 | 712,649 | 2016-10-10 22:45:34 | https://stackoverflow.com/q/39967359 | https://stackoverflow.com/a/39967829 | <p>Make sure your specify the <code>-UseSsl</code> switch:</p>
<pre><code>Send-MailMessage -SmtpServer $smtpserver -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8)
</code></pre>
<p>If the SMTP server uses a specific port for SMTP over TLS, use the <code>-... | <p>Make sure your specify the <code>-UseSsl</code> switch:</p> <pre><code>Send-MailMessage -SmtpServer $smtpserver -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8) </code></pre> <p>If the SMTP server uses a specific port for SMTP over TLS, use the <code>-... | 526 | powershell | <h1>Can I use TLS with Send-MailMessage cmdlet?</h1>
<p>I am trying to send an email using PowerShell, but need to use TLS. Any way I can do that using Send-MailMessage cmdlet?</p>
<p>This is my code:</p>
<pre><code>$file = "c:\Mail-content.txt"
if (test-path $file)
{
$from = "afgarciact@gmail.com"
$to = "&... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,858 | bash | # Can I use TLS with Send-MailMessage cmdlet?
I am trying to send an email using PowerShell, but need to use TLS. Any way I can do that using Send-MailMessage cmdlet?
This is my code:
```
$file = "c:\Mail-content.txt"
if (test-path $file)
{
$from = "afgarciact@gmail.com"
$to = "<slopez@comfama.com.co>","<c... | Make sure your specify the `-UseSsl` switch:
```
Send-MailMessage -SmtpServer $smtpserver -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8)
```
If the SMTP server uses a specific port for SMTP over TLS, use the `-Port` parameter:
```
Send-MailMessage -Smt... |
39930118 | Elegant way to remove target file if a Make rule fails | 8 | 2016-10-08 07:59:41 | <p>I have a rule in my Makefile that roughly looks like this:</p>
<pre><code>target_file: src_file
some_tool src_file > target_file
</code></pre>
<p>(Of course, in reality I'm using <code>$@</code> and <code>$<</code>, but for this question I prefer a more explicit style.)</p>
<p>The problem is that <code... | 2,242 | 19,163 | 2016-10-08 10:39:06 | 39,931,368 | 14 | 2016-10-08 10:39:06 | 6,644,919 | 2016-10-08 10:39:06 | https://stackoverflow.com/q/39930118 | https://stackoverflow.com/a/39931368 | <p>You could use the <a href="https://www.gnu.org/software/make/manual/html_node/Special-Targets.html" rel="noreferrer">special target</a> <code>.DELETE_ON_ERROR</code>:</p>
<blockquote>
<p>If .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, then make will delete the target of a rule if it has cha... | <p>You could use the <a href="https://www.gnu.org/software/make/manual/html_node/Special-Targets.html" rel="noreferrer">special target</a> <code>.DELETE_ON_ERROR</code>:</p> <blockquote> <p>If .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, then make will delete the target of a rule if it has cha... | 390, 4301, 4867, 13213, 33522 | gnu-make, makefile, redirectstandardoutput, shell, stdout | <h1>Elegant way to remove target file if a Make rule fails</h1>
<p>I have a rule in my Makefile that roughly looks like this:</p>
<pre><code>target_file: src_file
some_tool src_file > target_file
</code></pre>
<p>(Of course, in reality I'm using <code>$@</code> and <code>$<</code>, but for this question I ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,859 | bash | # Elegant way to remove target file if a Make rule fails
I have a rule in my Makefile that roughly looks like this:
```
target_file: src_file
some_tool src_file > target_file
```
(Of course, in reality I'm using `$@` and `$<`, but for this question I prefer a more explicit style.)
The problem is that `targe... | You could use the [special target](https://www.gnu.org/software/make/manual/html_node/Special-Targets.html) `.DELETE_ON_ERROR`:
> If .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, then make will delete the target of a rule if it has changed and its recipe exits with a nonzero exit status, just as ... |
38752735 | How Do You Override a Function in Powershell | 8 | 2016-08-03 20:08:53 | <p>All I can find online about doing this is to override a cmdlet, but I need to override a windows form event. Here is the C# equivalent of what I need:</p>
<pre><code>protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}
</code></pre>
<p>They were saying that you ju... | 9,922 | 1,427,105 | 2016-08-04 07:00:02 | 38,753,003 | 14 | 2016-08-03 20:25:35 | 3,905,079 | 2016-08-03 20:25:35 | https://stackoverflow.com/q/38752735 | https://stackoverflow.com/a/38753003 | <p><a href="https://stackoverflow.com/a/38753022/3905079">If you're referring to a method, Chris Dent's answer covers that nicely</a>!</p>
<p>For native PowerShell cmdlets/functions I will copy <a href="https://serverfault.com/q/642076/236470">my answer from ServerFault</a> here:</p>
<p>Yes, you can override <code>Ge... | <p><a href="https://stackoverflow.com/a/38753022/3905079">If you're referring to a method, Chris Dent's answer covers that nicely</a>!</p> <p>For native PowerShell cmdlets/functions I will copy <a href="https://serverfault.com/q/642076/236470">my answer from ServerFault</a> here:</p> <p>Yes, you can override <code>Ge... | 526, 2125, 36252 | overriding, powershell, winforms | <h1>How Do You Override a Function in Powershell</h1>
<p>All I can find online about doing this is to override a cmdlet, but I need to override a windows form event. Here is the C# equivalent of what I need:</p>
<pre><code>protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosi... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,860 | bash | # How Do You Override a Function in Powershell
All I can find online about doing this is to override a cmdlet, but I need to override a windows form event. Here is the C# equivalent of what I need:
```
protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}
```
They we... | [If you're referring to a method, Chris Dent's answer covers that nicely](https://stackoverflow.com/a/38753022/3905079)!
For native PowerShell cmdlets/functions I will copy [my answer from ServerFault](https://serverfault.com/q/642076/236470) here:
Yes, you can override `Get-ChildItem` or any other cmdlet in Powershe... |
36749719 | Setting InheritanceFlags vs PropagationFlags in Powershell | 8 | 2016-04-20 16:21:16 | <p>I'm trying to find the right combination of the InheritanceFlags and PropagationFlags so that my new folder will not inherit the folder's permissions before it, but will propagate the rights to the folders/files contained in the new folder... I tried swapping the two from what I have below, but that only gave the ne... | 10,437 | 6,147,123 | 2016-04-20 17:56:57 | 36,751,606 | 14 | 2016-04-20 17:56:57 | 150,605 | 2016-04-20 17:56:57 | https://stackoverflow.com/q/36749719 | https://stackoverflow.com/a/36751606 | <p>Calling <code>$acl.SetAccessRuleProtection($true, $false)</code> should prevent that directory or file from inheriting permissions from its parent directory, with the second parameter specifying that the previously-inherited permissions should be removed. Enabling protection = disabling inheritance.</p>
<p>In your... | <p>Calling <code>$acl.SetAccessRuleProtection($true, $false)</code> should prevent that directory or file from inheriting permissions from its parent directory, with the second parameter specifying that the previously-inherited permissions should be removed. Enabling protection = disabling inheritance.</p> <p>In your... | 526, 926, 18026 | inheritance, powershell, propagation | <h1>Setting InheritanceFlags vs PropagationFlags in Powershell</h1>
<p>I'm trying to find the right combination of the InheritanceFlags and PropagationFlags so that my new folder will not inherit the folder's permissions before it, but will propagate the rights to the folders/files contained in the new folder... I trie... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,861 | bash | # Setting InheritanceFlags vs PropagationFlags in Powershell
I'm trying to find the right combination of the InheritanceFlags and PropagationFlags so that my new folder will not inherit the folder's permissions before it, but will propagate the rights to the folders/files contained in the new folder... I tried swappin... | Calling `$acl.SetAccessRuleProtection($true, $false)` should prevent that directory or file from inheriting permissions from its parent directory, with the second parameter specifying that the previously-inherited permissions should be removed. Enabling protection = disabling inheritance.
In your `New-Ace` function, [... |
35783222 | Powershell: Filter Hashtable - and get back a Hastable | 8 | 2016-03-03 21:18:10 | <p>Filtering a Hashtable using GetEnumerator always returns a object[] instead of a Hashtable:</p>
<pre><code># Init Hashtable
$items = @{ a1 = 1; a2 = 2; b1 = 3; b2 = 4}
# apply a filter
$filtered = $items.GetEnumerator() | ?{ $_.Key -match "a.*" }
# The result looks great
$filtered
Name V... | 18,200 | 4,795,779 | 2023-03-04 23:31:10 | 35,783,327 | 14 | 2016-03-03 21:24:32 | 3,905,079 | 2018-09-12 17:33:18 | https://stackoverflow.com/q/35783222 | https://stackoverflow.com/a/35783327 | <p><code>$filtered</code> is an array of dictionary entries. There's no single cast or ctor for this as far as I know.</p>
<p>You can construct a hash though:</p>
<pre><code>$hash = @{}
$filtered | ForEach-Object { $hash.Add($_.Key, $_.Value) }
</code></pre>
<p>Another workflow:</p>
<pre><code># Init Hashtable
$ite... | <p><code>$filtered</code> is an array of dictionary entries. There's no single cast or ctor for this as far as I know.</p> <p>You can construct a hash though:</p> <pre><code>$hash = @{} $filtered | ForEach-Object { $hash.Add($_.Key, $_.Value) } </code></pre> <p>Another workflow:</p> <pre><code># Init Hashtable $ite... | 526, 5189 | hashtable, powershell | <h1>Powershell: Filter Hashtable - and get back a Hastable</h1>
<p>Filtering a Hashtable using GetEnumerator always returns a object[] instead of a Hashtable:</p>
<pre><code># Init Hashtable
$items = @{ a1 = 1; a2 = 2; b1 = 3; b2 = 4}
# apply a filter
$filtered = $items.GetEnumerator() | ?{ $_.Key -match "a.*" }
# The... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,862 | bash | # Powershell: Filter Hashtable - and get back a Hastable
Filtering a Hashtable using GetEnumerator always returns a object[] instead of a Hashtable:
```
# Init Hashtable
$items = @{ a1 = 1; a2 = 2; b1 = 3; b2 = 4}
# apply a filter
$filtered = $items.GetEnumerator() | ?{ $_.Key -match "a.*" }
# The result looks great
... | `$filtered` is an array of dictionary entries. There's no single cast or ctor for this as far as I know.
You can construct a hash though:
```
$hash = @{}
$filtered | ForEach-Object { $hash.Add($_.Key, $_.Value) }
```
Another workflow:
```
# Init Hashtable
$items = @{ a1 = 1; a2 = 2; b1 = 3; b2 = 4}
# Copy keys to ... |
33790965 | Set a one line powershell for sleep and hibernate to turn off | 8 | 2015-11-18 21:41:53 | <pre><code>powershell -Command "& {c:\windows\system32\powercfg.exe -change -monitor-timeout-ac 0; c:\windows\system32\powercfg.exe - change - monitor - timeout - dc 0; c:\windows\system32\powercfg.exe - change - disk - timeout - ac 0; c:\windows\system32\powercfg.exe - change - disk - timeout - dc 0; c:\windows\sy... | 59,914 | 4,068,911 | 2022-01-28 20:11:52 | 33,856,010 | 14 | 2015-11-22 14:42:30 | 4,068,911 | 2016-09-03 12:06:25 | https://stackoverflow.com/q/33790965 | https://stackoverflow.com/a/33856010 | <pre><code>var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
newProcessInfo.FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
newProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // hide processes as they happen
newProcessInfo.Verb = "ru... | <pre><code>var newProcessInfo = new System.Diagnostics.ProcessStartInfo(); newProcessInfo.FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"; newProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // hide processes as they happen newProcessInfo.Verb = "ru... | 526, 1796, 2221, 13136 | command, hibernation, powershell, sleep | <h1>Set a one line powershell for sleep and hibernate to turn off</h1>
<pre><code>powershell -Command "& {c:\windows\system32\powercfg.exe -change -monitor-timeout-ac 0; c:\windows\system32\powercfg.exe - change - monitor - timeout - dc 0; c:\windows\system32\powercfg.exe - change - disk - timeout - ac 0; c:\window... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,863 | bash | # Set a one line powershell for sleep and hibernate to turn off
```
powershell -Command "& {c:\windows\system32\powercfg.exe -change -monitor-timeout-ac 0; c:\windows\system32\powercfg.exe - change - monitor - timeout - dc 0; c:\windows\system32\powercfg.exe - change - disk - timeout - ac 0; c:\windows\system32\powerc... | ```
var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
newProcessInfo.FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
newProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // hide processes as they happen
newProcessInfo.Verb = "runas"; /... |
31994427 | How do I loop through all of my Git repositories and update them? | 8 | 2015-08-13 17:05:54 | <p>I have a folder where I keep all of my Git repos. I usually just do <code>git pull</code> to get my changes, but now that I have over 50 repos it becomes a burden to have to do this for every folder.</p>
<p>How can I run a command that will loop through every repo and update it for me?</p>
| 8,835 | 1,603,399 | 2025-03-12 19:42:29 | 31,994,428 | 14 | 2015-08-13 17:05:54 | 1,603,399 | 2015-08-23 16:27:34 | https://stackoverflow.com/q/31994427 | https://stackoverflow.com/a/31994428 | <p>In Bash you can run this command which will loop through every repo in your working directory, stash your changes, fetch the origin and pull the latest commit.</p>
<pre><code>for d in */; do cd $d; git stash; (git pull &); cd ..; done
</code></pre>
<p>Some things to note:</p>
<ul>
<li>This will use your worki... | <p>In Bash you can run this command which will loop through every repo in your working directory, stash your changes, fetch the origin and pull the latest commit.</p> <pre><code>for d in */; do cd $d; git stash; (git pull &); cd ..; done </code></pre> <p>Some things to note:</p> <ul> <li>This will use your worki... | 119, 387 | bash, git | <h1>How do I loop through all of my Git repositories and update them?</h1>
<p>I have a folder where I keep all of my Git repos. I usually just do <code>git pull</code> to get my changes, but now that I have over 50 repos it becomes a burden to have to do this for every folder.</p>
<p>How can I run a command that will ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,864 | bash | # How do I loop through all of my Git repositories and update them?
I have a folder where I keep all of my Git repos. I usually just do `git pull` to get my changes, but now that I have over 50 repos it becomes a burden to have to do this for every folder.
How can I run a command that will loop through every repo and... | In Bash you can run this command which will loop through every repo in your working directory, stash your changes, fetch the origin and pull the latest commit.
```
for d in */; do cd $d; git stash; (git pull &); cd ..; done
```
Some things to note:
- This will use your working branch in your repo
- `(git pull &)` op... |
31447753 | Shell command to reverse each line of file | 8 | 2015-07-16 07:21:03 | <p>I have a file <em>test.txt</em> with the following text</p>
<pre><code>1 2 3 4
3 4 5 6
8 7 3 2
</code></pre>
<p>I want to save it as</p>
<pre><code>4 3 2 1
6 5 4 3
2 3 7 8
</code></pre>
<p>Is there any shell command which does that?</p>
| 2,999 | 4,661,588 | 2015-07-16 07:31:02 | 31,447,864 | 14 | 2015-07-16 07:26:19 | 548,225 | 2015-07-16 07:26:19 | https://stackoverflow.com/q/31447753 | https://stackoverflow.com/a/31447864 | <p><code>rev</code> will do the job:</p>
<pre><code>rev file
4 3 2 1
6 5 4 3
2 3 7 8
</code></pre>
| <p><code>rev</code> will do the job:</p> <pre><code>rev file 4 3 2 1 6 5 4 3 2 3 7 8 </code></pre> | 387, 390 | bash, shell | <h1>Shell command to reverse each line of file</h1>
<p>I have a file <em>test.txt</em> with the following text</p>
<pre><code>1 2 3 4
3 4 5 6
8 7 3 2
</code></pre>
<p>I want to save it as</p>
<pre><code>4 3 2 1
6 5 4 3
2 3 7 8
</code></pre>
<p>Is there any shell command which does that?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,865 | bash | # Shell command to reverse each line of file
I have a file *test.txt* with the following text
```
1 2 3 4
3 4 5 6
8 7 3 2
```
I want to save it as
```
4 3 2 1
6 5 4 3
2 3 7 8
```
Is there any shell command which does that? | `rev` will do the job:
```
rev file
4 3 2 1
6 5 4 3
2 3 7 8
``` |
31124009 | How do I pass in optional flags and parameters to bash script? | 8 | 2015-06-29 19:31:37 | <p>I have a bash script that I pass parameters into (and access via $1). This parameter is a single command that must be processed (i.e. git pull, checkout dev, etc.). </p>
<p>I run my script like <code>./script_name git pull</code></p>
<p>Now, I want to add an optional flag to my script to do some other functionalit... | 13,244 | 3,353,018 | 2015-06-29 19:41:59 | 31,124,204 | 14 | 2015-06-29 19:41:59 | 7,552 | 2015-06-29 19:41:59 | https://stackoverflow.com/q/31124009 | https://stackoverflow.com/a/31124204 | <p>Using getopts is indeed the way to go:</p>
<pre><code>has_t_option=false
while getopts :ht opt; do
case $opt in
h) show_some_help; exit ;;
t) has_t_option=true ;;
:) echo "Missing argument for option -$OPTARG"; exit 1;;
\?) echo "Unknown option -$OPTARG"; exit 1;;
esac
done
... | <p>Using getopts is indeed the way to go:</p> <pre><code>has_t_option=false while getopts :ht opt; do case $opt in h) show_some_help; exit ;; t) has_t_option=true ;; :) echo "Missing argument for option -$OPTARG"; exit 1;; \?) echo "Unknown option -$OPTARG"; exit 1;; esac done ... | 34, 387 | bash, unix | <h1>How do I pass in optional flags and parameters to bash script?</h1>
<p>I have a bash script that I pass parameters into (and access via $1). This parameter is a single command that must be processed (i.e. git pull, checkout dev, etc.). </p>
<p>I run my script like <code>./script_name git pull</code></p>
<p>Now, I... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,866 | bash | # How do I pass in optional flags and parameters to bash script?
I have a bash script that I pass parameters into (and access via $1). This parameter is a single command that must be processed (i.e. git pull, checkout dev, etc.).
I run my script like `./script_name git pull`
Now, I want to add an optional flag to my... | Using getopts is indeed the way to go:
```
has_t_option=false
while getopts :ht opt; do
case $opt in
h) show_some_help; exit ;;
t) has_t_option=true ;;
:) echo "Missing argument for option -$OPTARG"; exit 1;;
\?) echo "Unknown option -$OPTARG"; exit 1;;
esac
done
# here's the k... |
31034540 | Correct usage of bc in a shell script? | 8 | 2015-06-24 18:45:29 | <p>I'm simply trying to multiplying some float variables using bc:</p>
<pre><code>#!/bin/bash
a=2.77 | bc
b=2.0 | bc
for cc in $(seq 0. 0.001 0.02)
do
c=${cc} | bc
d=$((a * b * c)) | bc
echo "$d" | bc
done
</code></pre>
<p>And this does not give me an output. I know it's a silly one but I've tried a nu... | 20,267 | 4,122,544 | 2025-12-19 21:32:44 | 31,035,766 | 14 | 2015-06-24 19:53:20 | 1,566,221 | 2015-06-24 19:59:31 | https://stackoverflow.com/q/31034540 | https://stackoverflow.com/a/31035766 | <p><code>bc</code> is a command-line utility, not some obscure part of shell syntax. The utility reads mathematical expressions from its standard input and prints values to its standard output. Since it is not part of the shell, it has no access to shell variables.</p>
<p>The shell pipe operator (<kbd>|</kbd>) connect... | <p><code>bc</code> is a command-line utility, not some obscure part of shell syntax. The utility reads mathematical expressions from its standard input and prints values to its standard output. Since it is not part of the shell, it has no access to shell variables.</p> <p>The shell pipe operator (<kbd>|</kbd>) connect... | 259, 387, 390, 34696 | bash, bc, math, shell | <h1>Correct usage of bc in a shell script?</h1>
<p>I'm simply trying to multiplying some float variables using bc:</p>
<pre><code>#!/bin/bash
a=2.77 | bc
b=2.0 | bc
for cc in $(seq 0. 0.001 0.02)
do
c=${cc} | bc
d=$((a * b * c)) | bc
echo "$d" | bc
done
</code></pre>
<p>And this does not give me an out... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,867 | bash | # Correct usage of bc in a shell script?
I'm simply trying to multiplying some float variables using bc:
```
#!/bin/bash
a=2.77 | bc
b=2.0 | bc
for cc in $(seq 0. 0.001 0.02)
do
c=${cc} | bc
d=$((a * b * c)) | bc
echo "$d" | bc
done
```
And this does not give me an output. I know it's a silly one but ... | `bc` is a command-line utility, not some obscure part of shell syntax. The utility reads mathematical expressions from its standard input and prints values to its standard output. Since it is not part of the shell, it has no access to shell variables.
The shell pipe operator (`|`) connects the standard output of one s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.