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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24142436 | Powershell parsing a properties file that contains colons | 7 | 2014-06-10 13:33:25 | <p>If I have a .properties file that contains directories (which contain colons):</p>
<pre><code>some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
</code></pre>
<p>and then use ConvertFrom-StringData to convert Key=Value pairs from said properties file to a hash table:</p>
<pre><code>$props_file = Get-Content "F:... | 10,882 | 746,437 | 2016-10-22 10:39:18 | 24,144,783 | 14 | 2014-06-10 15:20:48 | 2,792,096 | 2014-06-10 15:51:10 | https://stackoverflow.com/q/24142436 | https://stackoverflow.com/a/24144783 | <p>Colons have nothing to do with the error you get. And yes, it can be achieved using ConvertFrom-StringData but, as already mentioned, you're feeding it an array instead of a string. Moreover, you need paths with double backslashes in your file because single backslashes are interpreted as escape characters.</p>
<p>... | <p>Colons have nothing to do with the error you get. And yes, it can be achieved using ConvertFrom-StringData but, as already mentioned, you're feeding it an array instead of a string. Moreover, you need paths with double backslashes in your file because single backslashes are interpreted as escape characters.</p> <p>... | 526, 5189, 45703 | hashtable, powershell, properties-file | <h1>Powershell parsing a properties file that contains colons</h1>
<p>If I have a .properties file that contains directories (which contain colons):</p>
<pre><code>some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
</code></pre>
<p>and then use ConvertFrom-StringData to convert Key=Value pairs from said properties ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,968 | bash | # Powershell parsing a properties file that contains colons
If I have a .properties file that contains directories (which contain colons):
```
some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
```
and then use ConvertFrom-StringData to convert Key=Value pairs from said properties file to a hash table:
```
$props... | Colons have nothing to do with the error you get. And yes, it can be achieved using ConvertFrom-StringData but, as already mentioned, you're feeding it an array instead of a string. Moreover, you need paths with double backslashes in your file because single backslashes are interpreted as escape characters.
Here's how... |
23736555 | Correctly count number of lines a bash variable | 7 | 2014-05-19 11:27:06 | <p>I need to count the number of lines of a given variable. For example I need to find how many lines <code>VAR</code> has, where <code>VAR=$(git log -n 10 --format="%s")</code>.</p>
<p>I tried with <code>echo "$VAR" | wc -l)</code>, which indeed works, but if <code>VAR</code> is empty, is prints <code>1</code>, which... | 7,450 | 433,940 | 2014-05-19 12:53:03 | 23,736,832 | 14 | 2014-05-19 11:41:29 | 632,407 | 2014-05-19 11:41:29 | https://stackoverflow.com/q/23736555 | https://stackoverflow.com/a/23736832 | <p>The <code>wc</code> counts the <em>number of newline chars</em>. You can use <code>grep -c '^'</code> for counting lines.
You can see the difference with:</p>
<pre><code>#!/bin/bash
count_it() {
echo "Variablie contains $2: ==>$1<=="
echo -n 'grep:'; echo -n "$1" | grep -c '^'
echo -n 'wc :'; ec... | <p>The <code>wc</code> counts the <em>number of newline chars</em>. You can use <code>grep -c '^'</code> for counting lines. You can see the difference with:</p> <pre><code>#!/bin/bash count_it() { echo "Variablie contains $2: ==>$1<==" echo -n 'grep:'; echo -n "$1" | grep -c '^' echo -n 'wc :'; ec... | 387, 390, 39056 | bash, shell, wc | <h1>Correctly count number of lines a bash variable</h1>
<p>I need to count the number of lines of a given variable. For example I need to find how many lines <code>VAR</code> has, where <code>VAR=$(git log -n 10 --format="%s")</code>.</p>
<p>I tried with <code>echo "$VAR" | wc -l)</code>, which indeed works, but if <... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,969 | bash | # Correctly count number of lines a bash variable
I need to count the number of lines of a given variable. For example I need to find how many lines `VAR` has, where `VAR=$(git log -n 10 --format="%s")`.
I tried with `echo "$VAR" | wc -l)`, which indeed works, but if `VAR` is empty, is prints `1`, which is wrong. Is ... | The `wc` counts the *number of newline chars*. You can use `grep -c '^'` for counting lines.
You can see the difference with:
```
#!/bin/bash
count_it() {
echo "Variablie contains $2: ==>$1<=="
echo -n 'grep:'; echo -n "$1" | grep -c '^'
echo -n 'wc :'; echo -n "$1" | wc -l
echo
}
VAR=''
count_it "$... |
22313005 | How to read email from command line in linux? | 7 | 2014-03-10 22:47:40 | <p>I have a server with roundcube installed in it. I tried sending email into it from external email with my username@servername. It turns out that I was not able to read emails (no email pops up in inbox) but when I send email to some external email address from roundcube then it works fine. I was wondering if there i... | 6,279 | 2,008,447 | 2018-12-14 10:27:38 | 22,313,039 | 14 | 2014-03-10 22:50:02 | 1,783,163 | 2018-12-14 10:27:38 | https://stackoverflow.com/q/22313005 | https://stackoverflow.com/a/22313039 | <p>Yes. There is a nearly 30 yrs old 'mail' command. But an </p>
<pre><code>apt-get install alpine
</code></pre>
<p>helped a lot as well.</p>
| <p>Yes. There is a nearly 30 yrs old 'mail' command. But an </p> <pre><code>apt-get install alpine </code></pre> <p>helped a lot as well.</p> | 34, 58, 146, 390, 1231 | command-line, email, linux, shell, unix | <h1>How to read email from command line in linux?</h1>
<p>I have a server with roundcube installed in it. I tried sending email into it from external email with my username@servername. It turns out that I was not able to read emails (no email pops up in inbox) but when I send email to some external email address from r... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,970 | bash | # How to read email from command line in linux?
I have a server with roundcube installed in it. I tried sending email into it from external email with my username@servername. It turns out that I was not able to read emails (no email pops up in inbox) but when I send email to some external email address from roundcube ... | Yes. There is a nearly 30 yrs old 'mail' command. But an
```
apt-get install alpine
```
helped a lot as well. |
9342359 | How to download in bash from zippyshare? | 7 | 2012-02-18 15:14:14 | <p>Can anyone help me how to download files from zippyshare.com using bash (server with CentOS)?
Their download button made with flash, so i can't retrieve download link.</p>
| 20,399 | 1,218,197 | 2018-03-31 04:28:52 | 21,100,640 | 14 | 2014-01-13 20:22:26 | 1,533,054 | 2014-12-07 23:44:06 | https://stackoverflow.com/q/9342359 | https://stackoverflow.com/a/21100640 | <p>It's definitely possible, but it's a little hacky. I've been doing it myself for quite some time using <code>wget</code>. The trick is to make the server think that the request is being made from a browser and to make that happen, you need a couple of things:</p>
<ul>
<li>The Download Link (The actual link to the f... | <p>It's definitely possible, but it's a little hacky. I've been doing it myself for quite some time using <code>wget</code>. The trick is to make the server think that the request is being made from a browser and to make that happen, you need a couple of things:</p> <ul> <li>The Download Link (The actual link to the f... | 3, 387, 1554, 5583, 8109 | bash, curl, download, javascript, wget | <h1>How to download in bash from zippyshare?</h1>
<p>Can anyone help me how to download files from zippyshare.com using bash (server with CentOS)?
Their download button made with flash, so i can't retrieve download link.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,971 | bash | # How to download in bash from zippyshare?
Can anyone help me how to download files from zippyshare.com using bash (server with CentOS)?
Their download button made with flash, so i can't retrieve download link. | It's definitely possible, but it's a little hacky. I've been doing it myself for quite some time using `wget`. The trick is to make the server think that the request is being made from a browser and to make that happen, you need a couple of things:
- The Download Link (The actual link to the file)
- Link Referrer (The... |
20494015 | Confusion with the redirection of output to 2>&1? | 7 | 2013-12-10 12:02:56 | <p>I have checked couple of relevant posts regarding this in stackoverflow and other sources regarding the usage of 2>&1. </p>
<p>Unfortunately so far have not get my head around it completely.</p>
<p>I understand that 2 is the stderr and 1 is the stdout and we are combining with the 2>&1.</p>
<p>But my ques... | 3,608 | 2,195,440 | 2014-04-10 06:06:08 | 20,494,125 | 14 | 2013-12-10 12:08:02 | 2,768,341 | 2013-12-10 12:19:26 | https://stackoverflow.com/q/20494015 | https://stackoverflow.com/a/20494125 | <p>See this:</p>
<p><strong><code>mycommand > /dev/null</code></strong></p>
<p>it will redirect channel 1 (which is stdout) of mycommand to /dev/null</p>
<p><strong><code>mycommand 2> /dev/null</code></strong></p>
<p>it will redirect channel 2 (which is stderr) to /dev/null</p>
<p><strong><code>mycommand >... | <p>See this:</p> <p><strong><code>mycommand > /dev/null</code></strong></p> <p>it will redirect channel 1 (which is stdout) of mycommand to /dev/null</p> <p><strong><code>mycommand 2> /dev/null</code></strong></p> <p>it will redirect channel 2 (which is stderr) to /dev/null</p> <p><strong><code>mycommand >... | 58, 387, 390, 1964 | bash, ksh, linux, shell | <h1>Confusion with the redirection of output to 2>&1?</h1>
<p>I have checked couple of relevant posts regarding this in stackoverflow and other sources regarding the usage of 2>&1. </p>
<p>Unfortunately so far have not get my head around it completely.</p>
<p>I understand that 2 is the stderr and 1 is the stdout ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,972 | bash | # Confusion with the redirection of output to 2>&1?
I have checked couple of relevant posts regarding this in stackoverflow and other sources regarding the usage of 2>&1.
Unfortunately so far have not get my head around it completely.
I understand that 2 is the stderr and 1 is the stdout and we are combining with th... | See this:
**`mycommand > /dev/null`**
it will redirect channel 1 (which is stdout) of mycommand to /dev/null
**`mycommand 2> /dev/null`**
it will redirect channel 2 (which is stderr) to /dev/null
**`mycommand > /dev/null 2>&1`**
it will redirect channel 1 to /dev/null and then bind channel 2 (stderr) to channel 1... |
12649055 | Create datetime object of other timezone in Powershell | 7 | 2012-09-29 01:07:01 | <p>Basically I am trying to find a way to convert datetime of a particular timezone to other timezone while taking DST into consideration too. e.g.</p>
<p><em><strong>What is the time in "Central Pacific Standard Time" when it is, say, 2012/9/29 9:00AM in "Tokyo Standard Time" ?</em></strong></p>
<p>I found some sol... | 18,904 | 1,411,943 | 2013-11-20 16:15:58 | 20,101,121 | 14 | 2013-11-20 16:15:58 | 1,510,454 | 2013-11-20 16:15:58 | https://stackoverflow.com/q/12649055 | https://stackoverflow.com/a/20101121 | <p>This solution worked well for me:</p>
<pre><code>$cstzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time")
$csttime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $cstzone)
</code></pre>
<p>You can then manipulate the $csttime variable just like a datetime object:... | <p>This solution worked well for me:</p> <pre><code>$cstzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time") $csttime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $cstzone) </code></pre> <p>You can then manipulate the $csttime variable just like a datetime object:... | 526, 982, 1263 | datetime, powershell, timezone | <h1>Create datetime object of other timezone in Powershell</h1>
<p>Basically I am trying to find a way to convert datetime of a particular timezone to other timezone while taking DST into consideration too. e.g.</p>
<p><em><strong>What is the time in "Central Pacific Standard Time" when it is, say, 2012/9/29 9:00AM i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,973 | bash | # Create datetime object of other timezone in Powershell
Basically I am trying to find a way to convert datetime of a particular timezone to other timezone while taking DST into consideration too. e.g.
***What is the time in "Central Pacific Standard Time" when it is, say, 2012/9/29 9:00AM in "Tokyo Standard Time" ?*... | This solution worked well for me:
```
$cstzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time")
$csttime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $cstzone)
```
You can then manipulate the $csttime variable just like a datetime object:
```
Get-Date $csttime.Add... |
17838782 | -bash: sudo: command not found Mac OS X (EC2 CLI prob?) | 7 | 2013-07-24 15:41:46 | <p>Getting the error:<br/>
<code>-bash: sudo: command not found</code> <br/>
<code>echo $PATH</code> outputs <code>PATH:EC2_HOME/bin</code>
<br/>
I'm running Mac OSX 10.8.3</p>
<p>That seems wrong even for a n00b like me.
How do I fix my $PATH and return my computer to it's former self?</p>
| 36,728 | 306,443 | 2021-03-23 08:59:51 | 17,838,907 | 14 | 2013-07-24 15:47:35 | 1,471,829 | 2013-07-25 08:02:04 | https://stackoverflow.com/q/17838782 | https://stackoverflow.com/a/17838907 | <p>As stated in the comments the right files to set up your <code>$PATH</code> variable are: <code>~/.profile</code> or <code>~/.bash_profile</code></p>
<pre><code>export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
</code></pre>
<p>In this way when you re-enter in the console your <code>PATH<... | <p>As stated in the comments the right files to set up your <code>$PATH</code> variable are: <code>~/.profile</code> or <code>~/.bash_profile</code></p> <pre><code>export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH </code></pre> <p>In this way when you re-enter in the console your <code>PATH<... | 369, 387, 1674 | bash, macos, sudo | <h1>-bash: sudo: command not found Mac OS X (EC2 CLI prob?)</h1>
<p>Getting the error:<br/>
<code>-bash: sudo: command not found</code> <br/>
<code>echo $PATH</code> outputs <code>PATH:EC2_HOME/bin</code>
<br/>
I'm running Mac OSX 10.8.3</p>
<p>That seems wrong even for a n00b like me.
How do I fix my $PATH and return... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,974 | bash | # -bash: sudo: command not found Mac OS X (EC2 CLI prob?)
Getting the error:
`-bash: sudo: command not found`
`echo $PATH` outputs `PATH:EC2_HOME/bin`
I'm running Mac OSX 10.8.3
That seems wrong even for a n00b like me.
How do I fix my $PATH and return my computer to it's former self? | As stated in the comments the right files to set up your `$PATH` variable are: `~/.profile` or `~/.bash_profile`
```
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
```
In this way when you re-enter in the console your `PATH` will work fine.
You can add other directories to your `$PATH` as... |
14652445 | Parse ps' "etime" output and convert it into seconds | 7 | 2013-02-01 18:10:05 | <p>These are possible output formats for <code>ps h -eo etime</code></p>
<pre><code>21-18:26:30
15:28:37
48:14
00:01
</code></pre>
<p>How to parse them into seconds? </p>
<ul>
<li>Please assume at least 3 digits for the days part as I don't know how long it can be.</li>
<li>The output will be <code>eg... | 18,998 | 131,874 | 2022-11-22 16:26:27 | 14,653,443 | 14 | 2013-02-01 19:15:26 | 828,193 | 2015-09-16 12:28:40 | https://stackoverflow.com/q/14652445 | https://stackoverflow.com/a/14653443 | <p>With awk:</p>
<pre><code>#!/usr/bin/awk -f
BEGIN { FS = ":" }
{
if (NF == 2) {
print $1*60 + $2
} else if (NF == 3) {
split($1, a, "-");
if (a[2] != "" ) {
print ((a[1]*24+a[2])*60 + $2) * 60 + $3;
} else {
print ($1*60 + $2) * 60 + $3;
}
}
}
</code></pre>
<p>Run with :</p>
... | <p>With awk:</p> <pre><code>#!/usr/bin/awk -f BEGIN { FS = ":" } { if (NF == 2) { print $1*60 + $2 } else if (NF == 3) { split($1, a, "-"); if (a[2] != "" ) { print ((a[1]*24+a[2])*60 + $2) * 60 + $3; } else { print ($1*60 + $2) * 60 + $3; } } } </code></pre> <p>Run with :</p> ... | 18, 58, 387, 1357, 9780 | bash, linux, parsing, regex, type-conversion | <h1>Parse ps' "etime" output and convert it into seconds</h1>
<p>These are possible output formats for <code>ps h -eo etime</code></p>
<pre><code>21-18:26:30
15:28:37
48:14
00:01
</code></pre>
<p>How to parse them into seconds? </p>
<ul>
<li>Please assume at least 3 digits for the days part as I don't... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,975 | bash | # Parse ps' "etime" output and convert it into seconds
These are possible output formats for `ps h -eo etime`
```
21-18:26:30
15:28:37
48:14
00:01
```
How to parse them into seconds?
- Please assume at least 3 digits for the days part as I don't know how long it can be.
- The output will be `egreped`... | With awk:
```
#!/usr/bin/awk -f
BEGIN { FS = ":" }
{
if (NF == 2) {
print $1*60 + $2
} else if (NF == 3) {
split($1, a, "-");
if (a[2] != "" ) {
print ((a[1]*24+a[2])*60 + $2) * 60 + $3;
} else {
print ($1*60 + $2) * 60 + $3;
}
}
}
```
Run with :
```
awk -f script.awk datafile... |
14080306 | remove CR line terminators | 7 | 2012-12-29 09:17:19 | <p>Firstly I would say that I have read <a href="https://stackoverflow.com/questions/313178/whats-the-best-way-of-doing-dos2unix-on-a-500k-line-file-in-windows">this post</a> however I still have problems for the <code>CR line terminators</code>.</p>
<p>There is a file called <code>build_test.sh</code>, I edited in <c... | 20,992 | 528,929 | 2015-01-08 03:46:42 | 14,080,318 | 14 | 2012-12-29 09:19:27 | 1,093,528 | 2012-12-29 11:42:10 | https://stackoverflow.com/q/14080306 | https://stackoverflow.com/a/14080318 | <p>Simple <code>\r</code> terminators for newlines are "old Mac" line terminators, it is strange that an editor in 2012+ even generates files with such line terminators... Anyway, you can use the <code>mac2unix</code> command, which is part of the <code>dos2unix</code> distribution:</p>
<pre><code># Edits thefile inli... | <p>Simple <code>\r</code> terminators for newlines are "old Mac" line terminators, it is strange that an editor in 2012+ even generates files with such line terminators... Anyway, you can use the <code>mac2unix</code> command, which is part of the <code>dos2unix</code> distribution:</p> <pre><code># Edits thefile inli... | 34, 390, 3705, 5370 | dos, newline, shell, unix | <h1>remove CR line terminators</h1>
<p>Firstly I would say that I have read <a href="https://stackoverflow.com/questions/313178/whats-the-best-way-of-doing-dos2unix-on-a-500k-line-file-in-windows">this post</a> however I still have problems for the <code>CR line terminators</code>.</p>
<p>There is a file called <code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,976 | bash | # remove CR line terminators
Firstly I would say that I have read [this post](https://stackoverflow.com/questions/313178/whats-the-best-way-of-doing-dos2unix-on-a-500k-line-file-in-windows) however I still have problems for the `CR line terminators`.
There is a file called `build_test.sh`, I edited in `leafpad` and i... | Simple `\r` terminators for newlines are "old Mac" line terminators, it is strange that an editor in 2012+ even generates files with such line terminators... Anyway, you can use the `mac2unix` command, which is part of the `dos2unix` distribution:
```
# Edits thefile inline
mac2unix thefile
# Takes origfile as an inpu... |
13731463 | Linux shell script : make a folder with the current date name | 7 | 2012-12-05 20:04:02 | <p>I am trying to make a simple backup script and i have problem creating a folder with the curent date for name</p>
<p>My script is that and basically the problem is on the last line</p>
<pre><code>drivers=$(ls /media/)
declare -i c=0
for word in $drivers
do
echo "($c)$word"
c=c+1
done
read -n 1 drive
echo... | 49,443 | 1,187,293 | 2015-06-29 21:28:18 | 13,732,246 | 14 | 2012-12-05 20:55:08 | 1,387,612 | 2012-12-05 20:55:08 | https://stackoverflow.com/q/13731463 | https://stackoverflow.com/a/13732246 | <p><code>:</code> is not valid on FAT (it is used to specify disk). Some of M$ invalid character works on GNU/Linux systems but it is safer to avoid them (just replace with <code>.</code>). Use following date format</p>
<pre><code>date +%Y_%m_%d_%H_%M_%S
</code></pre>
<p>It should works on most file systems but it co... | <p><code>:</code> is not valid on FAT (it is used to specify disk). Some of M$ invalid character works on GNU/Linux systems but it is safer to avoid them (just replace with <code>.</code>). Use following date format</p> <pre><code>date +%Y_%m_%d_%H_%M_%S </code></pre> <p>It should works on most file systems but it co... | 58, 387, 390 | bash, linux, shell | <h1>Linux shell script : make a folder with the current date name</h1>
<p>I am trying to make a simple backup script and i have problem creating a folder with the curent date for name</p>
<p>My script is that and basically the problem is on the last line</p>
<pre><code>drivers=$(ls /media/)
declare -i c=0
for word i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,977 | bash | # Linux shell script : make a folder with the current date name
I am trying to make a simple backup script and i have problem creating a folder with the curent date for name
My script is that and basically the problem is on the last line
```
drivers=$(ls /media/)
declare -i c=0
for word in $drivers
do
echo "($c... | `:` is not valid on FAT (it is used to specify disk). Some of M$ invalid character works on GNU/Linux systems but it is safer to avoid them (just replace with `.`). Use following date format
```
date +%Y_%m_%d_%H_%M_%S
```
It should works on most file systems but it could be too long for MS DOS FAT. More info you wil... |
12350222 | How can I generate a GUID in Vim? | 7 | 2012-09-10 10:55:12 | <p>Vim doesn't have a built-in GUID generator.</p>
<p>For the project I'm working on, I can rely on Powershell being available, so the following gives me a GUID string:</p>
<pre><code>[guid]::NewGuid().ToString()
</code></pre>
<p>I call this within a substitution, as follows:</p>
<pre><code>%s/foo/\=system('[guid]:... | 5,260 | 329,888 | 2022-08-25 07:05:24 | 12,350,432 | 14 | 2012-09-10 11:10:31 | 110,151 | 2022-08-25 07:05:24 | https://stackoverflow.com/q/12350222 | https://stackoverflow.com/a/12350432 | <p>If you can rely on Vim's Python scripting support being available</p>
<pre><code>:pyx import uuid
:%s/foo/\=pyxeval('str(uuid.uuid4())')/
</code></pre>
<p>(If your Vim and Python are very old, use <code>:py</code> and <code>pyeval()</code> instead of <code>:pyx</code> and <code>pyxeval()</code>.)</p>
| <p>If you can rely on Vim's Python scripting support being available</p> <pre><code>:pyx import uuid :%s/foo/\=pyxeval('str(uuid.uuid4())')/ </code></pre> <p>(If your Vim and Python are very old, use <code>:py</code> and <code>pyeval()</code> instead of <code>:pyx</code> and <code>pyxeval()</code>.)</p> | 370, 526, 3567 | guid, powershell, vim | <h1>How can I generate a GUID in Vim?</h1>
<p>Vim doesn't have a built-in GUID generator.</p>
<p>For the project I'm working on, I can rely on Powershell being available, so the following gives me a GUID string:</p>
<pre><code>[guid]::NewGuid().ToString()
</code></pre>
<p>I call this within a substitution, as follow... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,978 | bash | # How can I generate a GUID in Vim?
Vim doesn't have a built-in GUID generator.
For the project I'm working on, I can rely on Powershell being available, so the following gives me a GUID string:
```
[guid]::NewGuid().ToString()
```
I call this within a substitution, as follows:
```
%s/foo/\=system('[guid]::NewGuid... | If you can rely on Vim's Python scripting support being available
```
:pyx import uuid
:%s/foo/\=pyxeval('str(uuid.uuid4())')/
```
(If your Vim and Python are very old, use `:py` and `pyeval()` instead of `:pyx` and `pyxeval()`.) |
11392033 | Passing python array to bash script (and passing bash variable to python function) | 7 | 2012-07-09 09:08:35 | <p>I have written a Python module which contains functions that return arrays. I want to be able to access the string arrays returned from the python module, and iterate over in a bash script, so I may iterate over the array elements.</p>
<p>For example:</p>
<h1>Python module (mymod)</h1>
<pre><code>def foo():
r... | 14,764 | 962,891 | 2019-05-03 20:00:13 | 11,392,201 | 14 | 2012-07-09 09:21:08 | 655,183 | 2012-07-09 09:32:12 | https://stackoverflow.com/q/11392033 | https://stackoverflow.com/a/11392201 | <p>Second try - this time shell takes the integration brunt.</p>
<p>Given <em>foo.py</em> containing this:</p>
<pre><code>def foo():
foo = ('String', 'Tuple', 'From', 'Python' )
return foo
</code></pre>
<p>Then write your bash script as follows:</p>
<pre><code>#!/bin/bash
FOO=`python -c 'from foo im... | <p>Second try - this time shell takes the integration brunt.</p> <p>Given <em>foo.py</em> containing this:</p> <pre><code>def foo(): foo = ('String', 'Tuple', 'From', 'Python' ) return foo </code></pre> <p>Then write your bash script as follows:</p> <pre><code>#!/bin/bash FOO=`python -c 'from foo im... | 16, 387 | bash, python | <h1>Passing python array to bash script (and passing bash variable to python function)</h1>
<p>I have written a Python module which contains functions that return arrays. I want to be able to access the string arrays returned from the python module, and iterate over in a bash script, so I may iterate over the array ele... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,979 | bash | # Passing python array to bash script (and passing bash variable to python function)
I have written a Python module which contains functions that return arrays. I want to be able to access the string arrays returned from the python module, and iterate over in a bash script, so I may iterate over the array elements.
F... | Second try - this time shell takes the integration brunt.
Given *foo.py* containing this:
```
def foo():
foo = ('String', 'Tuple', 'From', 'Python' )
return foo
```
Then write your bash script as follows:
```
#!/bin/bash
FOO=`python -c 'from foo import *; print " ".join(foo())'`
for x in $FOO:
do
... |
11114788 | Bash: How refresh shell after installing virtualenvwrapper [Without restarting the shell]? | 7 | 2012-06-20 07:29:13 | <p>I am using <code>python-fabric</code> to setup my server, which configures the server programatically.</p>
<p>So, I installed <code>virtualenvwrapper</code> as :</p>
<pre><code>sudo apt-get install virtualenvwrapper
</code></pre>
<p>That installed - Virtualenvwrapper and adds its initialization scripts to shell s... | 3,086 | 731,963 | 2012-06-21 05:20:22 | 11,131,918 | 14 | 2012-06-21 05:20:22 | 731,963 | 2012-06-21 05:20:22 | https://stackoverflow.com/q/11114788 | https://stackoverflow.com/a/11131918 | <p>Solved the problem :</p>
<pre><code>source /etc/bash_completion.d/virtualenvwrapper
</code></pre>
<p>This is where it was storing all its magic which gets included to <code>.bashrc</code> automatically.</p>
| <p>Solved the problem :</p> <pre><code>source /etc/bash_completion.d/virtualenvwrapper </code></pre> <p>This is where it was storing all its magic which gets included to <code>.bashrc</code> automatically.</p> | 16, 387, 549, 16113, 42950 | apt-get, bash, fabric, python, ubuntu | <h1>Bash: How refresh shell after installing virtualenvwrapper [Without restarting the shell]?</h1>
<p>I am using <code>python-fabric</code> to setup my server, which configures the server programatically.</p>
<p>So, I installed <code>virtualenvwrapper</code> as :</p>
<pre><code>sudo apt-get install virtualenvwrapper... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,980 | bash | # Bash: How refresh shell after installing virtualenvwrapper [Without restarting the shell]?
I am using `python-fabric` to setup my server, which configures the server programatically.
So, I installed `virtualenvwrapper` as :
```
sudo apt-get install virtualenvwrapper
```
That installed - Virtualenvwrapper and adds... | Solved the problem :
```
source /etc/bash_completion.d/virtualenvwrapper
```
This is where it was storing all its magic which gets included to `.bashrc` automatically. |
11090875 | Powershell get-item VersionInfo.ProductVersion incorrect / different than WMI | 7 | 2012-06-18 20:55:51 | <p>I'm trying to understand why Powershell would get back a different version number for a DLL file than what both the file properties page from Windows Explorer, and a WMI query shows. (I apologize in advance if this doesn't correctly qualify as a coding question.)</p>
<p>The scenario:</p>
<p>Running the following po... | 21,035 | 1,464,775 | 2021-07-19 10:59:38 | 11,093,966 | 14 | 2012-06-19 03:23:02 | 608,772 | 2012-06-19 16:23:22 | https://stackoverflow.com/q/11090875 | https://stackoverflow.com/a/11093966 | <p>The problem is that you are using the <code>ProductVersion</code> propertie which seems to be hard coded somewhere, IE and WMI are just buildind the product version from : </p>
<pre><code>ProductMajorPart : 6
ProductMinorPart : 1
ProductBuildPart : 7601
ProductPrivatePart : 17767
</code></pre>
<p>Same for <c... | <p>The problem is that you are using the <code>ProductVersion</code> propertie which seems to be hard coded somewhere, IE and WMI are just buildind the product version from : </p> <pre><code>ProductMajorPart : 6 ProductMinorPart : 1 ProductBuildPart : 7601 ProductPrivatePart : 17767 </code></pre> <p>Same for <c... | 526, 15348, 22676, 61774 | powershell, versioninfo, wmic, wmi-query | <h1>Powershell get-item VersionInfo.ProductVersion incorrect / different than WMI</h1>
<p>I'm trying to understand why Powershell would get back a different version number for a DLL file than what both the file properties page from Windows Explorer, and a WMI query shows. (I apologize in advance if this doesn't correc... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,981 | bash | # Powershell get-item VersionInfo.ProductVersion incorrect / different than WMI
I'm trying to understand why Powershell would get back a different version number for a DLL file than what both the file properties page from Windows Explorer, and a WMI query shows. (I apologize in advance if this doesn't correctly qualif... | The problem is that you are using the `ProductVersion` propertie which seems to be hard coded somewhere, IE and WMI are just buildind the product version from :
```
ProductMajorPart : 6
ProductMinorPart : 1
ProductBuildPart : 7601
ProductPrivatePart : 17767
```
Same for `FileVersion` with : FileMajorPart, FileM... |
10559064 | Terminate makefile command when subcommand throws? | 7 | 2012-05-11 21:46:46 | <p>I've got the following Makefile:</p>
<pre><code>#runs the working directory unit tests
test:
@NODE_ENV=test; \
mocha --ignore-leaks $(shell find ./test -name \*test.js);
#deploys working directory
deploy:
@make test; \
make deploy-git; \
make deploy-servers;
#deploys working to git deploym... | 10,379 | 45,974 | 2016-03-17 21:11:52 | 10,559,225 | 14 | 2012-05-11 22:03:21 | 648,658 | 2016-03-17 21:11:52 | https://stackoverflow.com/q/10559064 | https://stackoverflow.com/a/10559225 | <p>The exit status of a shell command <em>list</em> is the exit status of the last command in the list. Simply turn your command list into separate single <em>simple commands</em>. By default, <code>make</code> stops when a command returns nonzero. So you get what you want with</p>
<pre><code>deploy:
@make test
... | <p>The exit status of a shell command <em>list</em> is the exit status of the last command in the list. Simply turn your command list into separate single <em>simple commands</em>. By default, <code>make</code> stops when a command returns nonzero. So you get what you want with</p> <pre><code>deploy: @make test ... | 390, 4301 | makefile, shell | <h1>Terminate makefile command when subcommand throws?</h1>
<p>I've got the following Makefile:</p>
<pre><code>#runs the working directory unit tests
test:
@NODE_ENV=test; \
mocha --ignore-leaks $(shell find ./test -name \*test.js);
#deploys working directory
deploy:
@make test; \
make deploy-git;... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,982 | bash | # Terminate makefile command when subcommand throws?
I've got the following Makefile:
```
#runs the working directory unit tests
test:
@NODE_ENV=test; \
mocha --ignore-leaks $(shell find ./test -name \*test.js);
#deploys working directory
deploy:
@make test; \
make deploy-git; \
make deploy-s... | The exit status of a shell command *list* is the exit status of the last command in the list. Simply turn your command list into separate single *simple commands*. By default, `make` stops when a command returns nonzero. So you get what you want with
```
deploy:
@make test
make deploy-git
make deploy-serve... |
10358615 | What does the -EA switch represent on Send-MailMessage? | 7 | 2012-04-27 22:20:14 | <p>For example:</p>
<blockquote>
<p>Send-MailMessage -To $to -From $sender -subject $subject -SmtpServer $mailserver -Attachments $efile -EA Stop</p>
</blockquote>
<p>All those switches are documented on <a href="http://technet.microsoft.com/en-us/library/dd347693.aspx" rel="noreferrer">http://technet.microsoft.com... | 7,984 | 1,128,875 | 2014-08-27 05:44:42 | 10,359,176 | 14 | 2012-04-27 23:35:08 | 251,123 | 2014-08-27 05:44:42 | https://stackoverflow.com/q/10358615 | https://stackoverflow.com/a/10359176 | <p><code>-ea</code> is parameter alias for <code>-ErrorAction</code>. See <a href="http://ss64.com/ps/common.html" rel="noreferrer">http://ss64.com/ps/common.html</a> . It's listed in the common parameters in the <code>Send-MailMessage</code> <a href="http://technet.microsoft.com/en-us/library/dd347693.aspx" rel="noref... | <p><code>-ea</code> is parameter alias for <code>-ErrorAction</code>. See <a href="http://ss64.com/ps/common.html" rel="noreferrer">http://ss64.com/ps/common.html</a> . It's listed in the common parameters in the <code>Send-MailMessage</code> <a href="http://technet.microsoft.com/en-us/library/dd347693.aspx" rel="noref... | 526 | powershell | <h1>What does the -EA switch represent on Send-MailMessage?</h1>
<p>For example:</p>
<blockquote>
<p>Send-MailMessage -To $to -From $sender -subject $subject -SmtpServer $mailserver -Attachments $efile -EA Stop</p>
</blockquote>
<p>All those switches are documented on <a href="http://technet.microsoft.com/en-us/lib... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,983 | bash | # What does the -EA switch represent on Send-MailMessage?
For example:
> Send-MailMessage -To $to -From $sender -subject $subject -SmtpServer $mailserver -Attachments $efile -EA Stop
All those switches are documented on <http://technet.microsoft.com/en-us/library/dd347693.aspx> except the -EA switch.
What does this... | `-ea` is parameter alias for `-ErrorAction`. See <http://ss64.com/ps/common.html> . It's listed in the common parameters in the `Send-MailMessage` [documentation](http://technet.microsoft.com/en-us/library/dd347693.aspx).
This shows the options for ErrorAction:
```
[enum]::getValues([System.Management.Automation.Acti... |
10178608 | Changing bash prompt in new bash | 7 | 2012-04-16 17:15:18 | <p>When I create an new bash process, the prompt defaults to a very simple one.
I know I can edit .bashrc etc to change this, but is there a way of passing the prompt with the bash command?</p>
<p>thanks!</p>
| 4,401 | 787,036 | 2022-04-06 13:49:31 | 10,178,710 | 14 | 2012-04-16 17:23:32 | 159,834 | 2012-04-16 17:23:32 | https://stackoverflow.com/q/10178608 | https://stackoverflow.com/a/10178710 | <p>The prompt is defined by the PS1, PS2, PS3 and PS4 environment variables. So, e.g. the following will start a new bash with the prompt set to "foo: ":</p>
<pre><code>PS1="foo: " bash --norc
</code></pre>
<p>The <code>--norc</code> is required to suppress processing of the initialization files, which would override... | <p>The prompt is defined by the PS1, PS2, PS3 and PS4 environment variables. So, e.g. the following will start a new bash with the prompt set to "foo: ":</p> <pre><code>PS1="foo: " bash --norc </code></pre> <p>The <code>--norc</code> is required to suppress processing of the initialization files, which would override... | 387, 390, 5003 | bash, prompt, shell | <h1>Changing bash prompt in new bash</h1>
<p>When I create an new bash process, the prompt defaults to a very simple one.
I know I can edit .bashrc etc to change this, but is there a way of passing the prompt with the bash command?</p>
<p>thanks!</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,984 | bash | # Changing bash prompt in new bash
When I create an new bash process, the prompt defaults to a very simple one.
I know I can edit .bashrc etc to change this, but is there a way of passing the prompt with the bash command?
thanks! | The prompt is defined by the PS1, PS2, PS3 and PS4 environment variables. So, e.g. the following will start a new bash with the prompt set to "foo: ":
```
PS1="foo: " bash --norc
```
The `--norc` is required to suppress processing of the initialization files, which would override the `PS1` variable. |
9635208 | `if [-e file.txt]` not working in bash | 7 | 2012-03-09 13:58:41 | <p>I'm trying to check if a file exists using bash. This is my code</p>
<pre><code>if [-e file.txt]; then
echo "file exists"
else
echo "file doesn't exist"
fi
</code></pre>
<p>But when I run it I get:</p>
<pre><code>./test.sh: line 3: [-e: command not found
</code></pre>
<p>What am I doing wrong?</p>
| 11,131 | 290,650 | 2012-03-09 16:31:55 | 9,635,262 | 14 | 2012-03-09 14:01:38 | 978,917 | 2012-03-09 14:01:38 | https://stackoverflow.com/q/9635208 | https://stackoverflow.com/a/9635262 | <p><code>[</code> is not a special token in Bash; it's just that the <em>word</em> <code>[</code> is a builtin command (just like <code>echo</code>). So you need a space after it. And, similarly, you need a space before <code>]</code>:</p>
<pre><code>if [ -e file.txt ] ; then
</code></pre>
<p>That said, I recommend <... | <p><code>[</code> is not a special token in Bash; it's just that the <em>word</em> <code>[</code> is a builtin command (just like <code>echo</code>). So you need a space after it. And, similarly, you need a space before <code>]</code>:</p> <pre><code>if [ -e file.txt ] ; then </code></pre> <p>That said, I recommend <... | 387 | bash | <h1>`if [-e file.txt]` not working in bash</h1>
<p>I'm trying to check if a file exists using bash. This is my code</p>
<pre><code>if [-e file.txt]; then
echo "file exists"
else
echo "file doesn't exist"
fi
</code></pre>
<p>But when I run it I get:</p>
<pre><code>./test.sh: line 3: [-e: command not found
</code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,985 | bash | # `if [-e file.txt]` not working in bash
I'm trying to check if a file exists using bash. This is my code
```
if [-e file.txt]; then
echo "file exists"
else
echo "file doesn't exist"
fi
```
But when I run it I get:
```
./test.sh: line 3: [-e: command not found
```
What am I doing wrong? | `[` is not a special token in Bash; it's just that the *word* `[` is a builtin command (just like `echo`). So you need a space after it. And, similarly, you need a space before `]`:
```
if [ -e file.txt ] ; then
```
That said, I recommend `[[ ]]` instead — it's safer in a few ways (though it still requires the spaces... |
9615528 | Simple Powershell Msbuild with parameter fails | 7 | 2012-03-08 09:42:42 | <p>I am trying to pass a simple variable passing, </p>
<p>No parameter</p>
<pre><code>msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
</code></pre>
<p>Try 1</p>
<pre><code>$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbuild MySolution.sln + $buildOptions
</code></pre>
<p>-> c... | 7,692 | 121,859 | 2012-03-08 10:11:38 | 9,615,603 | 14 | 2012-03-08 09:47:43 | 9,833 | 2012-03-08 10:11:38 | https://stackoverflow.com/q/9615528 | https://stackoverflow.com/a/9615603 | <p>Try one of these:</p>
<pre><code>msbuild MySolution.sln $buildOptions
Start-Process msbuild -ArgumentList MySolution.sln,$buildOptions -NoNewWindow
</code></pre>
<p>By the way, there's a new feature in PowerShell v3 just for this kind of situations, anything after --% is treated as is, so you're command will look... | <p>Try one of these:</p> <pre><code>msbuild MySolution.sln $buildOptions Start-Process msbuild -ArgumentList MySolution.sln,$buildOptions -NoNewWindow </code></pre> <p>By the way, there's a new feature in PowerShell v3 just for this kind of situations, anything after --% is treated as is, so you're command will look... | 265, 526 | msbuild, powershell | <h1>Simple Powershell Msbuild with parameter fails</h1>
<p>I am trying to pass a simple variable passing, </p>
<p>No parameter</p>
<pre><code>msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
</code></pre>
<p>Try 1</p>
<pre><code>$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbui... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,986 | bash | # Simple Powershell Msbuild with parameter fails
I am trying to pass a simple variable passing,
No parameter
```
msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
```
Try 1
```
$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbuild MySolution.sln + $buildOptions
```
-> cause MSB1... | Try one of these:
```
msbuild MySolution.sln $buildOptions
Start-Process msbuild -ArgumentList MySolution.sln,$buildOptions -NoNewWindow
```
By the way, there's a new feature in PowerShell v3 just for this kind of situations, anything after --% is treated as is, so you're command will look like:
```
msbuild MySolut... |
9517960 | How to tracing script flow | 7 | 2012-03-01 14:28:43 | <p>I'm fairly new to Powershell and have written some pretty large scripts ie a script that calls others scripts which have functions nested in other functions. When I launch this script I sometimes get errors that I don't know where they came from. Is there an easy way to see where this script terminated so I can tr... | 6,782 | 999,246 | 2016-04-08 22:39:17 | 9,520,573 | 14 | 2012-03-01 17:00:05 | 320,508 | 2012-03-01 17:00:05 | https://stackoverflow.com/q/9517960 | https://stackoverflow.com/a/9520573 | <p>You can use <code>Set-PsDebug</code> to get PowerShell to output almost every line it runs:</p>
<pre><code>Set-PSDebug -Trace 1;
</code></pre>
<p>Only downside is you'll probably end up with a lot of output to wade through...</p>
| <p>You can use <code>Set-PsDebug</code> to get PowerShell to output almost every line it runs:</p> <pre><code>Set-PSDebug -Trace 1; </code></pre> <p>Only downside is you'll probably end up with a lot of output to wade through...</p> | 526 | powershell | <h1>How to tracing script flow</h1>
<p>I'm fairly new to Powershell and have written some pretty large scripts ie a script that calls others scripts which have functions nested in other functions. When I launch this script I sometimes get errors that I don't know where they came from. Is there an easy way to see wher... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,987 | bash | # How to tracing script flow
I'm fairly new to Powershell and have written some pretty large scripts ie a script that calls others scripts which have functions nested in other functions. When I launch this script I sometimes get errors that I don't know where they came from. Is there an easy way to see where this scri... | You can use `Set-PsDebug` to get PowerShell to output almost every line it runs:
```
Set-PSDebug -Trace 1;
```
Only downside is you'll probably end up with a lot of output to wade through... |
8316649 | Bash programmation (Cygwin): Illegal Character ^M | 7 | 2011-11-29 19:36:29 | <p>I have a problem with a character. I think it's a conversion problem between dos and unix.</p>
<p>I have a variable that is a float value.
When I print it with the echo command i get:</p>
<pre><code>0.495959
</code></pre>
<p>But when I try to make an operation on that value with the bc command (I am not sure how ... | 14,464 | 1,072,053 | 2012-03-19 22:17:32 | 8,316,934 | 14 | 2011-11-29 19:59:46 | 978,917 | 2011-11-29 19:59:46 | https://stackoverflow.com/q/8316649 | https://stackoverflow.com/a/8316934 | <p>I don't have Cygwin handy, but in regular Bash, you can use the <code>tr -d</code> command to strip out specified characters, and you can use the <code>$'...'</code> notation to specify weird characters in a command-line argument (it's like a normal single-quoted string, except that it supports C/Java/Perl/etc.-like... | <p>I don't have Cygwin handy, but in regular Bash, you can use the <code>tr -d</code> command to strip out specified characters, and you can use the <code>$'...'</code> notation to specify weird characters in a command-line argument (it's like a normal single-quoted string, except that it supports C/Java/Perl/etc.-like... | 64, 387, 1731, 34696 | bash, bc, cygwin, windows | <h1>Bash programmation (Cygwin): Illegal Character ^M</h1>
<p>I have a problem with a character. I think it's a conversion problem between dos and unix.</p>
<p>I have a variable that is a float value.
When I print it with the echo command i get:</p>
<pre><code>0.495959
</code></pre>
<p>But when I try to make an oper... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,988 | bash | # Bash programmation (Cygwin): Illegal Character ^M
I have a problem with a character. I think it's a conversion problem between dos and unix.
I have a variable that is a float value.
When I print it with the echo command i get:
```
0.495959
```
But when I try to make an operation on that value with the bc command ... | I don't have Cygwin handy, but in regular Bash, you can use the `tr -d` command to strip out specified characters, and you can use the `$'...'` notation to specify weird characters in a command-line argument (it's like a normal single-quoted string, except that it supports C/Java/Perl/etc.-like escape sequences). So, t... |
6891110 | How to start powershell with a window title? | 7 | 2011-07-31 17:39:12 | <p>I have a batch file that allows me to go to particular folder based on my input.</p>
<pre><code>d:
cd d:\test\bits
@ECHO off
cls
:start
ECHO.
ECHO 1. Perl
ECHO 2. Python
set choice=
set /p choice=type in number to go to appropriate code folder:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto ... | 12,242 | 539,542 | 2023-02-01 06:00:24 | 6,891,574 | 14 | 2011-07-31 18:54:20 | 526,535 | 2011-07-31 18:54:20 | https://stackoverflow.com/q/6891110 | https://stackoverflow.com/a/6891574 | <p>From what I expected and what I was able to reproduce with your script, the current directory is set to the intended one (<code>d:\test\bits\code\pl</code> if I enter 1)</p>
<p>For the title part, you can do the following:</p>
<pre><code>start powershell -NoExit -command "$Host.UI.RawUI.WindowTitle = 'bits'"
</cod... | <p>From what I expected and what I was able to reproduce with your script, the current directory is set to the intended one (<code>d:\test\bits\code\pl</code> if I enter 1)</p> <p>For the title part, you can do the following:</p> <pre><code>start powershell -NoExit -command "$Host.UI.RawUI.WindowTitle = 'bits'" </cod... | 526, 2631 | cmd, powershell | <h1>How to start powershell with a window title?</h1>
<p>I have a batch file that allows me to go to particular folder based on my input.</p>
<pre><code>d:
cd d:\test\bits
@ECHO off
cls
:start
ECHO.
ECHO 1. Perl
ECHO 2. Python
set choice=
set /p choice=type in number to go to appropriate code folder:
if not '%choice%'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,989 | bash | # How to start powershell with a window title?
I have a batch file that allows me to go to particular folder based on my input.
```
d:
cd d:\test\bits
@ECHO off
cls
:start
ECHO.
ECHO 1. Perl
ECHO 2. Python
set choice=
set /p choice=type in number to go to appropriate code folder:
if not '%choice%'=='' set choice=%cho... | From what I expected and what I was able to reproduce with your script, the current directory is set to the intended one (`d:\test\bits\code\pl` if I enter 1)
For the title part, you can do the following:
```
start powershell -NoExit -command "$Host.UI.RawUI.WindowTitle = 'bits'"
``` |
6859249 | Extracting x random values from a bash array | 7 | 2011-07-28 12:52:11 | <p>I have an array in Bash, say it contains the numbers {1, 2, 3, 4, 5}. I want to extract some of those numbers randomly, such that the same number doesn't get extracted twice.</p>
<p>Basically, if I wanted to extract 3 numbers from the array, I want results like: {3, 4, 1} or {5, 2, 4} and not {1, 1, 3} or {2, 5, 2}... | 7,400 | 846,291 | 2019-10-31 13:58:43 | 6,859,860 | 14 | 2011-07-28 13:38:42 | 34,148 | 2017-12-02 19:25:16 | https://stackoverflow.com/q/6859249 | https://stackoverflow.com/a/6859860 | <p>Decided to write an answer, as I found the <code>--input-range</code> option to <code>shuf</code> that turned out handy:</p>
<pre><code>N=3
ARRAY=( zero one two three four five )
for index in $(shuf --input-range=0-$(( ${#ARRAY[*]} - 1 )) -n ${N})
do
echo ${ARRAY[$index]}
done
</code></pre>
| <p>Decided to write an answer, as I found the <code>--input-range</code> option to <code>shuf</code> that turned out handy:</p> <pre><code>N=3 ARRAY=( zero one two three four five ) for index in $(shuf --input-range=0-$(( ${#ARRAY[*]} - 1 )) -n ${N}) do echo ${ARRAY[$index]} done </code></pre> | 114, 387 | arrays, bash | <h1>Extracting x random values from a bash array</h1>
<p>I have an array in Bash, say it contains the numbers {1, 2, 3, 4, 5}. I want to extract some of those numbers randomly, such that the same number doesn't get extracted twice.</p>
<p>Basically, if I wanted to extract 3 numbers from the array, I want results like:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,990 | bash | # Extracting x random values from a bash array
I have an array in Bash, say it contains the numbers {1, 2, 3, 4, 5}. I want to extract some of those numbers randomly, such that the same number doesn't get extracted twice.
Basically, if I wanted to extract 3 numbers from the array, I want results like: {3, 4, 1} or {5... | Decided to write an answer, as I found the `--input-range` option to `shuf` that turned out handy:
```
N=3
ARRAY=( zero one two three four five )
for index in $(shuf --input-range=0-$(( ${#ARRAY[*]} - 1 )) -n ${N})
do
echo ${ARRAY[$index]}
done
``` |
4358192 | How do I append lines from one file to the end of each line of another file? | 7 | 2010-12-05 09:40:24 | <p>Suppose I have two files:</p>
<pre>
cat
dog
baboon
</pre>
<pre>
feline
canine
primate
</pre>
<p>I want to append the lines from one file at the end of another file after adding a space. I know a way to do this using a for loop in bash, but I think there is a single command that can do this sort of thing, and I ju... | 6,782 | 145,537 | 2015-08-11 22:04:36 | 4,358,204 | 14 | 2010-12-05 09:44:10 | 427,545 | 2010-12-05 09:53:01 | https://stackoverflow.com/q/4358192 | https://stackoverflow.com/a/4358204 | <pre><code>paste --delimiter=' ' file1 file2
</code></pre>
<p>Note: the result will be written to stdout. If you want to store the result in a file, use a redirection operator:</p>
<pre><code>paste --delimiter=' ' file1 file2 > outputfile
</code></pre>
<p>Run <code>man paste</code> for more information about the ... | <pre><code>paste --delimiter=' ' file1 file2 </code></pre> <p>Note: the result will be written to stdout. If you want to store the result in a file, use a redirection operator:</p> <pre><code>paste --delimiter=' ' file1 file2 > outputfile </code></pre> <p>Run <code>man paste</code> for more information about the ... | 387, 6051, 9325 | append, bash, line | <h1>How do I append lines from one file to the end of each line of another file?</h1>
<p>Suppose I have two files:</p>
<pre>
cat
dog
baboon
</pre>
<pre>
feline
canine
primate
</pre>
<p>I want to append the lines from one file at the end of another file after adding a space. I know a way to do this using a for loop i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,991 | bash | # How do I append lines from one file to the end of each line of another file?
Suppose I have two files:
```
cat
dog
baboon
```
```
feline
canine
primate
```
I want to append the lines from one file at the end of another file after adding a space. I know a way to do this using a for loop in bash, but I think there ... | ```
paste --delimiter=' ' file1 file2
```
Note: the result will be written to stdout. If you want to store the result in a file, use a redirection operator:
```
paste --delimiter=' ' file1 file2 > outputfile
```
Run `man paste` for more information about the command. |
4193817 | How to remove header and footer records of a flat file using UNIX shell script? | 7 | 2010-11-16 11:52:36 | <p>I am having a flat file as give below. How do I delete the header and footer from the file using UNIX shell script and rewrite the same file.</p>
<pre><code>9 20050427 HEADER RECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456... | 71,500 | 501,511 | 2017-05-15 06:46:06 | 4,193,988 | 14 | 2010-11-16 12:12:36 | 110,488 | 2017-05-15 06:46:06 | https://stackoverflow.com/q/4193817 | https://stackoverflow.com/a/4193988 | <p>... and with <code>sed</code>:</p>
<p>As <a href="http://users/491264/baramin" rel="noreferrer">@Baramin</a> noted: the least amount to type is <code>sed '1d;$d'</code>, here is how it works:</p>
<h2>By line number</h2>
<pre><code>sed -i'' -e '1d' -e '$d' yourfile
</code></pre>
<p><code>1d</code> deletes first l... | <p>... and with <code>sed</code>:</p> <p>As <a href="http://users/491264/baramin" rel="noreferrer">@Baramin</a> noted: the least amount to type is <code>sed '1d;$d'</code>, here is how it works:</p> <h2>By line number</h2> <pre><code>sed -i'' -e '1d' -e '$d' yourfile </code></pre> <p><code>1d</code> deletes first l... | 34, 390, 531 | scripting, shell, unix | <h1>How to remove header and footer records of a flat file using UNIX shell script?</h1>
<p>I am having a flat file as give below. How do I delete the header and footer from the file using UNIX shell script and rewrite the same file.</p>
<pre><code>9 20050427 HEADER RECORD
0000000 00000 000000000 123456 00 654321 DATA... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,992 | bash | # How to remove header and footer records of a flat file using UNIX shell script?
I am having a flat file as give below. How do I delete the header and footer from the file using UNIX shell script and rewrite the same file.
```
9 20050427 HEADER RECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000... | ... and with `sed`:
As [@Baramin](http://users/491264/baramin) noted: the least amount to type is `sed '1d;$d'`, here is how it works:
## By line number
```
sed -i'' -e '1d' -e '$d' yourfile
```
`1d` deletes first line `$d` deletes last line.
## Or by pattern
```
sed -r -i -e '/^[0-9] [0-9]{8} HEADER RECORD$/d' \... |
4096962 | What does it mean "bash < <( curl http://rvm.io/releases/rvm-install-head )" | 7 | 2010-11-04 13:08:10 | <p>The RVM homepage</p>
<p><a href="http://rvm.io/" rel="nofollow">http://rvm.io/</a></p>
<p>recommends people install RVM using</p>
<pre><code>bash < <( curl http://rvm.io/releases/rvm-install-head )
</code></pre>
<p>What is this syntax? <code>command <( another_command)</code></p>
<p>Can't the original ... | 4,145 | 325,418 | 2013-01-08 02:31:55 | 4,097,009 | 14 | 2010-11-04 13:13:25 | 69,755 | 2013-01-08 02:31:55 | https://stackoverflow.com/q/4096962 | https://stackoverflow.com/a/4097009 | <p><code><(command)</code> creates a named pipe with the output of the command (or uses an existing <code>/dev/fd</code> file), and substitutes the filename of that pipe into the command. <code><</code> then redirects standard input from that given file.</p>
<p>So yes, in this case, this is equivalent to </p>
<... | <p><code><(command)</code> creates a named pipe with the output of the command (or uses an existing <code>/dev/fd</code> file), and substitutes the filename of that pipe into the command. <code><</code> then redirects standard input from that given file.</p> <p>So yes, in this case, this is equivalent to </p> <... | 387, 390 | bash, shell | <h1>What does it mean "bash < <( curl http://rvm.io/releases/rvm-install-head )"</h1>
<p>The RVM homepage</p>
<p><a href="http://rvm.io/" rel="nofollow">http://rvm.io/</a></p>
<p>recommends people install RVM using</p>
<pre><code>bash < <( curl http://rvm.io/releases/rvm-install-head )
</code></pre>
<p>What i... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,993 | bash | # What does it mean "bash < <( curl http://rvm.io/releases/rvm-install-head )"
The RVM homepage
<http://rvm.io/>
recommends people install RVM using
```
bash < <( curl http://rvm.io/releases/rvm-install-head )
```
What is this syntax? `command <( another_command)`
Can't the original line be? `curl http://rvm.io/r... | `<(command)` creates a named pipe with the output of the command (or uses an existing `/dev/fd` file), and substitutes the filename of that pipe into the command. `<` then redirects standard input from that given file.
So yes, in this case, this is equivalent to
```
curl http://rvm.io/releases/rvm-install-head | bash... |
3519610 | Makefile with multiple targets | 7 | 2010-08-19 07:24:35 | <p>Hopefully this is a very simple question. I have a makefile pattern rule that looks like this:</p>
<pre><code>%.so : %.f %.pyf
f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt
</code></pre>
<p>I want the makefile to build a number of .so files... | 10,357 | 424,902 | 2010-08-20 10:31:09 | 3,519,634 | 14 | 2010-08-19 07:28:48 | 251,122 | 2010-08-19 07:28:48 | https://stackoverflow.com/q/3519610 | https://stackoverflow.com/a/3519634 | <p>The usual trick is to add a 'dummy' target as the first that depends on all targets you want to build when running a plain <code>make</code>:</p>
<pre><code>all: radgrd_py.so lodiso_py.so
</code></pre>
<p>It is a convention to call this target 'all' or 'default'. For extra correctness, let <code>make</code> know t... | <p>The usual trick is to add a 'dummy' target as the first that depends on all targets you want to build when running a plain <code>make</code>:</p> <pre><code>all: radgrd_py.so lodiso_py.so </code></pre> <p>It is a convention to call this target 'all' or 'default'. For extra correctness, let <code>make</code> know t... | 58, 390, 4301 | linux, makefile, shell | <h1>Makefile with multiple targets</h1>
<p>Hopefully this is a very simple question. I have a makefile pattern rule that looks like this:</p>
<pre><code>%.so : %.f %.pyf
f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt
</code></pre>
<p>I want the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,994 | bash | # Makefile with multiple targets
Hopefully this is a very simple question. I have a makefile pattern rule that looks like this:
```
%.so : %.f %.pyf
f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt
```
I want the makefile to build a number of .so file... | The usual trick is to add a 'dummy' target as the first that depends on all targets you want to build when running a plain `make`:
```
all: radgrd_py.so lodiso_py.so
```
It is a convention to call this target 'all' or 'default'. For extra correctness, let `make` know that this is not a real file by adding this line t... |
2224969 | shell script not running via crontab, runs fine manually | 7 | 2010-02-08 21:24:28 | <p>I have tried exporting my paths and variables and crontab still will not run my script. I'm sure I am doing something wrong.</p>
<p>I have a shell script which runs a jar file. This is not working correctly. </p>
<p>After reading around I have read this is commonly due to incorrect paths due to cron running via it... | 43,400 | 269,008 | 2013-02-28 15:50:19 | 2,225,723 | 14 | 2010-02-08 23:40:34 | 26,428 | 2010-02-09 01:12:33 | https://stackoverflow.com/q/2224969 | https://stackoverflow.com/a/2225723 | <p>Try specifying the full path to the jar file:</p>
<pre><code>/usr/bin/java -jar /path/to/Pharmagistics_auto.jar -o
</code></pre>
| <p>Try specifying the full path to the jar file:</p> <pre><code>/usr/bin/java -jar /path/to/Pharmagistics_auto.jar -o </code></pre> | 58, 390, 601 | cron, linux, shell | <h1>shell script not running via crontab, runs fine manually</h1>
<p>I have tried exporting my paths and variables and crontab still will not run my script. I'm sure I am doing something wrong.</p>
<p>I have a shell script which runs a jar file. This is not working correctly. </p>
<p>After reading around I have read ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,995 | bash | # shell script not running via crontab, runs fine manually
I have tried exporting my paths and variables and crontab still will not run my script. I'm sure I am doing something wrong.
I have a shell script which runs a jar file. This is not working correctly.
After reading around I have read this is commonly due to ... | Try specifying the full path to the jar file:
```
/usr/bin/java -jar /path/to/Pharmagistics_auto.jar -o
``` |
2098485 | Check string for all lowercase letters in PowerShell | 7 | 2010-01-20 01:33:43 | <p>I want to be able to test if a PowerShell string is all lowercase letters.</p>
<p>I am not the worlds best regex monkey, but I have been trying along these lines:</p>
<pre><code>if ($mystring -match "[a-z]^[A-Z]") {
echo "its lower!"
}
</code></pre>
<p>But of course they doesn't work, and searching the Intern... | 26,993 | 218,215 | 2025-08-29 08:34:47 | 2,098,489 | 14 | 2010-01-20 01:36:01 | 73,070 | 2010-01-20 07:11:24 | https://stackoverflow.com/q/2098485 | https://stackoverflow.com/a/2098489 | <p>PowerShell by default matches case-insensitively, so you need to use the <code>-cmatch</code> operator:</p>
<pre><code>if ($mystring -cmatch "^[a-z]*$") { ... }
</code></pre>
<p><code>-cmatch</code> is <em>always</em> case-sensitive, while <code>-imatch</code> is always case-insensitive.</p>
<p>Side note: Your re... | <p>PowerShell by default matches case-insensitively, so you need to use the <code>-cmatch</code> operator:</p> <pre><code>if ($mystring -cmatch "^[a-z]*$") { ... } </code></pre> <p><code>-cmatch</code> is <em>always</em> case-sensitive, while <code>-imatch</code> is always case-insensitive.</p> <p>Side note: Your re... | 18, 526, 6107 | case, powershell, regex | <h1>Check string for all lowercase letters in PowerShell</h1>
<p>I want to be able to test if a PowerShell string is all lowercase letters.</p>
<p>I am not the worlds best regex monkey, but I have been trying along these lines:</p>
<pre><code>if ($mystring -match "[a-z]^[A-Z]") {
echo "its lower!"
}
</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,996 | bash | # Check string for all lowercase letters in PowerShell
I want to be able to test if a PowerShell string is all lowercase letters.
I am not the worlds best regex monkey, but I have been trying along these lines:
```
if ($mystring -match "[a-z]^[A-Z]") {
echo "its lower!"
}
```
But of course they doesn't work, an... | PowerShell by default matches case-insensitively, so you need to use the `-cmatch` operator:
```
if ($mystring -cmatch "^[a-z]*$") { ... }
```
`-cmatch` is *always* case-sensitive, while `-imatch` is always case-insensitive.
Side note: Your regular expression was also a little weird. Basically you want the one I pro... |
72907826 | How to fail Azure devops pipeline task specifically for failures in bash script | 6 | 2022-07-08 07:05:37 | <p>I am using Azure Devops pipeline and in that there is one task that will create KVM guest VM and once VM is created through packer inside the host it will run a bash script to check the status of services running inside the guest VM.
If any services are not running or thrown error then this bash script will exit wit... | 12,509 | 17,426,313 | 2022-07-12 08:20:54 | 72,949,128 | 14 | 2022-07-12 08:20:54 | 16,600,319 | 2022-07-12 08:20:54 | https://stackoverflow.com/q/72907826 | https://stackoverflow.com/a/72949128 | <p>You can try and use <code>exit 1</code> command to have the bash task failed. And it is often a command you'll issue soon after an error is logged.</p>
<p>Additionally, you also may use <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#example-... | <p>You can try and use <code>exit 1</code> command to have the bash task failed. And it is often a command you'll issue soon after an error is logged.</p> <p>Additionally, you also may use <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#example-... | 387, 2844, 14158, 116537, 119596 | azure, azure-devops, azure-pipelines, bash, pipeline | <h1>How to fail Azure devops pipeline task specifically for failures in bash script</h1>
<p>I am using Azure Devops pipeline and in that there is one task that will create KVM guest VM and once VM is created through packer inside the host it will run a bash script to check the status of services running inside the gues... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,997 | bash | # How to fail Azure devops pipeline task specifically for failures in bash script
I am using Azure Devops pipeline and in that there is one task that will create KVM guest VM and once VM is created through packer inside the host it will run a bash script to check the status of services running inside the guest VM.
If ... | You can try and use `exit 1` command to have the bash task failed. And it is often a command you'll issue soon after an error is logged.
Additionally, you also may use [logging commands](https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#example-log-an-error) ... |
68209348 | Command to open a new terminal within a terminal in Windows OS | 6 | 2021-07-01 11:28:16 | <p>As I was going through it, it is possible in Ubuntu 20.04 LTS by typing <a href="https://askubuntu.com/q/401009"><code>gnome-terminal</code></a>.</p>
<p>Is there any command on Windows for the same?</p>
| 9,308 | 14,147,127 | 2025-05-22 08:49:17 | 68,215,857 | 14 | 2021-07-01 19:20:21 | 45,375 | 2024-11-25 23:56:50 | https://stackoverflow.com/q/68209348 | https://stackoverflow.com/a/68215857 | <p>It's not entirely clear what you're asking, but here's a few pointers for <em>Windows</em>:</p>
<ul>
<li><p>If you're using <strong>regular console windows</strong> (<code>conhost.exe</code>):</p>
<ul>
<li><p>To open another <strong><code>cmd.exe</code></strong> console window from <code>cmd.exe</code> (run <code>st... | <p>It's not entirely clear what you're asking, but here's a few pointers for <em>Windows</em>:</p> <ul> <li><p>If you're using <strong>regular console windows</strong> (<code>conhost.exe</code>):</p> <ul> <li><p>To open another <strong><code>cmd.exe</code></strong> console window from <code>cmd.exe</code> (run <code>st... | 526, 2631, 5910, 9938, 138178 | cmd, command-prompt, powershell, process, windows-terminal | <h1>Command to open a new terminal within a terminal in Windows OS</h1>
<p>As I was going through it, it is possible in Ubuntu 20.04 LTS by typing <a href="https://askubuntu.com/q/401009"><code>gnome-terminal</code></a>.</p>
<p>Is there any command on Windows for the same?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,998 | bash | # Command to open a new terminal within a terminal in Windows OS
As I was going through it, it is possible in Ubuntu 20.04 LTS by typing [`gnome-terminal`](https://askubuntu.com/q/401009).
Is there any command on Windows for the same? | It's not entirely clear what you're asking, but here's a few pointers for *Windows*:
- If you're using **regular console windows** (`conhost.exe`):
- To open another **`cmd.exe`** console window from `cmd.exe` (run `start /?` for help):
- `start cmd`
- Or even just `start` by itself.
- To open another **... |
63394927 | What does the tty do when a process asks for input or outputs to the screen? | 6 | 2020-08-13 12:13:50 | <p>Ive read numerous posts about tty. They all start with the historical reasons for the tty name. Please leave this out and just describe the tty system as it exists today. Then they talk about how a tty is a file and that stdin, stdout and sterr of a process started in a terminal are all mapped to this file.
How are ... | 5,023 | 1,219,638 | 2021-10-30 03:55:07 | 63,433,910 | 14 | 2020-08-16 06:39:41 | 10,678,955 | 2021-10-30 03:55:07 | https://stackoverflow.com/q/63394927 | https://stackoverflow.com/a/63433910 | <p>This turned out really long, so brace yourself...</p>
<h2>TTY Device</h2>
<p>You are looking at a TTY as a screen divided to e.g. 80x24 tiles.
But a TTY is a console: it contains an input device (generally connected to a keyboard) and an output device (generally connected to a screen).</p>
<h2>TTY Abstraction</h2>
<... | <p>This turned out really long, so brace yourself...</p> <h2>TTY Device</h2> <p>You are looking at a TTY as a screen divided to e.g. 80x24 tiles. But a TTY is a console: it contains an input device (generally connected to a keyboard) and an output device (generally connected to a screen).</p> <h2>TTY Abstraction</h2> <... | 58, 390, 391, 2035, 17165 | kernel, linux, shell, terminal, tty | <h1>What does the tty do when a process asks for input or outputs to the screen?</h1>
<p>Ive read numerous posts about tty. They all start with the historical reasons for the tty name. Please leave this out and just describe the tty system as it exists today. Then they talk about how a tty is a file and that stdin, std... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 9,999 | bash | # What does the tty do when a process asks for input or outputs to the screen?
Ive read numerous posts about tty. They all start with the historical reasons for the tty name. Please leave this out and just describe the tty system as it exists today. Then they talk about how a tty is a file and that stdin, stdout and s... | This turned out really long, so brace yourself...
## TTY Device
You are looking at a TTY as a screen divided to e.g. 80x24 tiles.
But a TTY is a console: it contains an input device (generally connected to a keyboard) and an output device (generally connected to a screen).
## TTY Abstraction
While the TTY is connec... |
57705570 | How to prevent save input history that begins with a space in PowerShell? | 6 | 2019-08-29 07:53:21 | <p>In bash (at least in Ubuntu), it is possible not to save commands starting with a space in the history (HISTCONTROL).
Is there a way to get this feature in Powershell?</p>
| 3,009 | 1,465,500 | 2021-12-02 04:34:20 | 62,936,536 | 14 | 2020-07-16 14:04:09 | 1,213,346 | 2021-12-02 04:34:20 | https://stackoverflow.com/q/57705570 | https://stackoverflow.com/a/62936536 | <p>Since at least PowerShell 5.1 you can use <a href="https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#parameters" rel="noreferrer"><code>Set-PSReadlineOption</code></a>'s <code>-AddToHistoryHandler</code> to validate if a command should be added to the history wit... | <p>Since at least PowerShell 5.1 you can use <a href="https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#parameters" rel="noreferrer"><code>Set-PSReadlineOption</code></a>'s <code>-AddToHistoryHandler</code> to validate if a command should be added to the history wit... | 390, 526, 21413 | input-history, powershell, shell | <h1>How to prevent save input history that begins with a space in PowerShell?</h1>
<p>In bash (at least in Ubuntu), it is possible not to save commands starting with a space in the history (HISTCONTROL).
Is there a way to get this feature in Powershell?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,000 | bash | # How to prevent save input history that begins with a space in PowerShell?
In bash (at least in Ubuntu), it is possible not to save commands starting with a space in the history (HISTCONTROL).
Is there a way to get this feature in Powershell? | Since at least PowerShell 5.1 you can use [`Set-PSReadlineOption`](https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#parameters)'s `-AddToHistoryHandler` to validate if a command should be added to the history with a custom function.
> `-AddToHistoryHandler` Specif... |
61994226 | How to delete history in a range in linux bash | 6 | 2020-05-25 00:48:20 | <p>Fooling around with Linux on my Pi and ran into this problem. I found that you can remove a certain line with the command <code>history -d linenumber</code> but what if I want to remove a range (which I think is much more practical)? So I looked up how to loop in several places. Both ways of looping worked for an e... | 11,549 | null | 2024-03-19 17:21:44 | 61,994,637 | 14 | 2020-05-25 01:48:52 | 484,674 | 2020-05-25 19:36:37 | https://stackoverflow.com/q/61994226 | https://stackoverflow.com/a/61994637 | <pre><code>for ((i=258;i<=262;++i)); do "history -d $i"; done;
</code></pre>
<p>as you said, is simply not working due to quotes</p>
<pre><code>for i in {5..10}; do history -d $i; done;
</code></pre>
<p>is working, but you must ensure to have entries from 5 to 10, which in your examples, you don't have.<br>
Take ... | <pre><code>for ((i=258;i<=262;++i)); do "history -d $i"; done; </code></pre> <p>as you said, is simply not working due to quotes</p> <pre><code>for i in {5..10}; do history -d $i; done; </code></pre> <p>is working, but you must ensure to have entries from 5 to 10, which in your examples, you don't have.<br> Take ... | 387, 2314, 2531, 145953 | bash, command-history, for-loop, loops | <h1>How to delete history in a range in linux bash</h1>
<p>Fooling around with Linux on my Pi and ran into this problem. I found that you can remove a certain line with the command <code>history -d linenumber</code> but what if I want to remove a range (which I think is much more practical)? So I looked up how to loop... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,001 | bash | # How to delete history in a range in linux bash
Fooling around with Linux on my Pi and ran into this problem. I found that you can remove a certain line with the command `history -d linenumber` but what if I want to remove a range (which I think is much more practical)? So I looked up how to loop in several places. B... | ```
for ((i=258;i<=262;++i)); do "history -d $i"; done;
```
as you said, is simply not working due to quotes
```
for i in {5..10}; do history -d $i; done;
```
is working, but you must ensure to have entries from 5 to 10, which in your examples, you don't have.
Take into account that every item you remove, the posi... |
61907994 | Git Bash confuse with Slash '/' when running bash script on Windows | 6 | 2020-05-20 08:00:43 | <p>How can I run bash script on git bash with slash '/' on Windows.</p>
<p>Here is my script file. I can run well on Ubuntu/Linux.</p>
<pre><code>#!/bin/sh
KONG_ADMIN_HOST=localhost
KONG_ADMIN_PORT=8001
registerServiceRoute() {
printf "\nRegister %s service route\n" $1
curl -XPOST ${KONG_ADMIN_HOST}:${KONG_ADMI... | 2,145 | 11,341,827 | 2020-05-20 08:32:38 | 61,908,450 | 14 | 2020-05-20 08:26:29 | 12,927,909 | 2020-05-20 08:32:38 | https://stackoverflow.com/q/61907994 | https://stackoverflow.com/a/61908450 | <p>Add the following before your <code>curl</code> command:</p>
<pre><code>export MSYS_NO_PATHCONV=1
</code></pre>
<p>Caveat emptor: The solution is based off a similar issue that occurs for docker commands on Windows (ref: <a href="https://books.google.com/books?id=hHc5DwAAQBAJ&pg=PA196&lpg=PA196&dq=envi... | <p>Add the following before your <code>curl</code> command:</p> <pre><code>export MSYS_NO_PATHCONV=1 </code></pre> <p>Caveat emptor: The solution is based off a similar issue that occurs for docker commands on Windows (ref: <a href="https://books.google.com/books?id=hHc5DwAAQBAJ&pg=PA196&lpg=PA196&dq=envi... | 64, 387, 390, 10194, 61874 | bash, git-bash, shell, slash, windows | <h1>Git Bash confuse with Slash '/' when running bash script on Windows</h1>
<p>How can I run bash script on git bash with slash '/' on Windows.</p>
<p>Here is my script file. I can run well on Ubuntu/Linux.</p>
<pre><code>#!/bin/sh
KONG_ADMIN_HOST=localhost
KONG_ADMIN_PORT=8001
registerServiceRoute() {
printf "\... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,002 | bash | # Git Bash confuse with Slash '/' when running bash script on Windows
How can I run bash script on git bash with slash '/' on Windows.
Here is my script file. I can run well on Ubuntu/Linux.
```
#!/bin/sh
KONG_ADMIN_HOST=localhost
KONG_ADMIN_PORT=8001
registerServiceRoute() {
printf "\nRegister %s service route\... | Add the following before your `curl` command:
```
export MSYS_NO_PATHCONV=1
```
Caveat emptor: The solution is based off a similar issue that occurs for docker commands on Windows (ref: [The DevOps 2.1 Toolkit: Docker Swarm](https://books.google.com/books?id=hHc5DwAAQBAJ&pg=PA196&lpg=PA196&dq=environment+variable+win... |
59498570 | Powershell sorting hash table | 6 | 2019-12-27 09:26:07 | <p>I am seeing some seemingly very weird behavior with a hash table I am sorting and then trying to review the results. I build the hash table, then I need to sort that table based on values, and I see two bits of weirdness.</p>
<p>This works fine outside of a class</p>
<pre><code>$hash = [hashtable]::New()
$type = '... | 23,722 | 4,552,490 | 2023-04-24 10:55:25 | 59,500,386 | 14 | 2019-12-27 11:50:32 | 45,375 | 2023-04-24 10:55:25 | https://stackoverflow.com/q/59498570 | https://stackoverflow.com/a/59500386 |
<ul>
<li><p><a href="https://stackoverflow.com/a/59499027/45375">Vasil Svilenov Nikolov's helpful answer</a> explains the fundamental problem with your approach:</p>
<ul>
<li><p><strong>You fundamentally cannot sort a hash table</strong> (<a href="https://learn.microsoft.com/en-US/dotnet/api/System.Collections.Hashtab... | <ul> <li><p><a href="https://stackoverflow.com/a/59499027/45375">Vasil Svilenov Nikolov's helpful answer</a> explains the fundamental problem with your approach:</p> <ul> <li><p><strong>You fundamentally cannot sort a hash table</strong> (<a href="https://learn.microsoft.com/en-US/dotnet/api/System.Collections.Hashtab... | 134, 526, 5189 | hashtable, powershell, sorting | <h1>Powershell sorting hash table</h1>
<p>I am seeing some seemingly very weird behavior with a hash table I am sorting and then trying to review the results. I build the hash table, then I need to sort that table based on values, and I see two bits of weirdness.</p>
<p>This works fine outside of a class</p>
<pre><co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,003 | bash | # Powershell sorting hash table
I am seeing some seemingly very weird behavior with a hash table I am sorting and then trying to review the results. I build the hash table, then I need to sort that table based on values, and I see two bits of weirdness.
This works fine outside of a class
```
$hash = [hashtable]::New... | - [Vasil Svilenov Nikolov's helpful answer](https://stackoverflow.com/a/59499027/45375) explains the fundamental problem with your approach:
- **You fundamentally cannot sort a hash table** ([`[hashtable]`](https://learn.microsoft.com/en-US/dotnet/api/System.Collections.Hashtable) instance) by its keys: the ordering... |
58185002 | How to compare JSON in powershell | 6 | 2019-10-01 12:40:50 | <p>I have a requirement where I need to compare JSON object from a file to the JSON message which comes into Anypoint MQ queue. I am able to get the message from the queue. I have used below script but it is not working. I did both <code>-eq</code> and <code>Compare-Object</code> but they are not working. </p>
<pre><c... | 14,202 | 12,124,859 | 2019-10-01 18:48:35 | 58,189,249 | 14 | 2019-10-01 16:53:44 | 45,375 | 2019-10-01 18:48:35 | https://stackoverflow.com/q/58185002 | https://stackoverflow.com/a/58189249 | <p><strong>If you just want to know <em>if</em> the two JSON-originated objects differ</strong>, without needing to know <em>how</em>:</p>
<pre class="lang-bsh prettyprint-override"><code>$contentEqual = ($po_ps_output | ConvertTo-Json -Compress) -eq
($po_python_output | ConvertTo-Json -Compress)
</co... | <p><strong>If you just want to know <em>if</em> the two JSON-originated objects differ</strong>, without needing to know <em>how</em>:</p> <pre class="lang-bsh prettyprint-override"><code>$contentEqual = ($po_ps_output | ConvertTo-Json -Compress) -eq ($po_python_output | ConvertTo-Json -Compress) </co... | 526, 136495 | mulesoft, powershell | <h1>How to compare JSON in powershell</h1>
<p>I have a requirement where I need to compare JSON object from a file to the JSON message which comes into Anypoint MQ queue. I am able to get the message from the queue. I have used below script but it is not working. I did both <code>-eq</code> and <code>Compare-Object</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,004 | bash | # How to compare JSON in powershell
I have a requirement where I need to compare JSON object from a file to the JSON message which comes into Anypoint MQ queue. I am able to get the message from the queue. I have used below script but it is not working. I did both `-eq` and `Compare-Object` but they are not working.
... | **If you just want to know *if* the two JSON-originated objects differ**, without needing to know *how*:
```
$contentEqual = ($po_ps_output | ConvertTo-Json -Compress) -eq
($po_python_output | ConvertTo-Json -Compress)
```
Note:
- `ConvertTo-Json` defaults to a serialization depth of `2` - use `-Dep... |
40257475 | PowerShell: write-output only writes one object | 6 | 2016-10-26 08:38:06 | <p>I'm learning PowerShell and a vast number of articles I read strongly discourages the use of write-host telling me it's "bad practice" and almost always, the output can be displayed in another way.</p>
<p>So, I'm taking the advice and try to avoid use of write-host. One suggestion I found was to use write-output in... | 8,673 | 3,270,761 | 2020-11-27 13:26:21 | 50,416,448 | 14 | 2018-05-18 17:23:13 | 45,375 | 2020-11-27 13:26:21 | https://stackoverflow.com/q/40257475 | https://stackoverflow.com/a/50416448 | <ul>
<li><p>Just to clarify: <strong>the problem is only a <em>display</em> problem</strong>:</p>
<ul>
<li><em>When outputting to the console</em>, <strong>if the <em>first</em> object is <em>table-formatted</em> (if <code>Format-Table</code> is applied, which happens <em>implicitly</em> in your case), the display colu... | <ul> <li><p>Just to clarify: <strong>the problem is only a <em>display</em> problem</strong>:</p> <ul> <li><em>When outputting to the console</em>, <strong>if the <em>first</em> object is <em>table-formatted</em> (if <code>Format-Table</code> is applied, which happens <em>implicitly</em> in your case), the display colu... | 526 | powershell | <h1>PowerShell: write-output only writes one object</h1>
<p>I'm learning PowerShell and a vast number of articles I read strongly discourages the use of write-host telling me it's "bad practice" and almost always, the output can be displayed in another way.</p>
<p>So, I'm taking the advice and try to avoid use of writ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,005 | bash | # PowerShell: write-output only writes one object
I'm learning PowerShell and a vast number of articles I read strongly discourages the use of write-host telling me it's "bad practice" and almost always, the output can be displayed in another way.
So, I'm taking the advice and try to avoid use of write-host. One sugg... | - Just to clarify: **the problem is only a *display* problem**:
- *When outputting to the console*, **if the *first* object is *table-formatted* (if `Format-Table` is applied, which happens *implicitly* in your case), the display columns are *locked in* based on that first object's properties**.
Since your sec... |
46881831 | Using double quotes in awk | 6 | 2017-10-23 04:09:26 | <p>This command will print <code>a</code>.</p>
<pre><code>echo "line1 a b c" | awk '{ print $2 }'
</code></pre>
<p>If I change single quotes to double quotes, like this, it will print whole line.</p>
<pre><code>echo "line1 a b c" | awk "{ print $2 }"
</code></pre>
<p>Why? I know I should use single quotes, but why ... | 5,472 | 4,578,392 | 2018-03-01 08:03:34 | 46,882,507 | 14 | 2017-10-23 05:31:39 | 1,787,434 | 2017-10-25 22:38:38 | https://stackoverflow.com/q/46881831 | https://stackoverflow.com/a/46882507 | <p>If the <code>awk</code> command is single quoted, the <code>$2</code> is not interpreted by the shell, but is instead passed as the literal string <code>$2</code> to <code>awk</code>. <code>awk</code> will then <code>print</code> the second space delimited token in the input string, which in this case is <code>a</co... | <p>If the <code>awk</code> command is single quoted, the <code>$2</code> is not interpreted by the shell, but is instead passed as the literal string <code>$2</code> to <code>awk</code>. <code>awk</code> will then <code>print</code> the second space delimited token in the input string, which in this case is <code>a</co... | 58, 390 | linux, shell | <h1>Using double quotes in awk</h1>
<p>This command will print <code>a</code>.</p>
<pre><code>echo "line1 a b c" | awk '{ print $2 }'
</code></pre>
<p>If I change single quotes to double quotes, like this, it will print whole line.</p>
<pre><code>echo "line1 a b c" | awk "{ print $2 }"
</code></pre>
<p>Why? I know ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,006 | bash | # Using double quotes in awk
This command will print `a`.
```
echo "line1 a b c" | awk '{ print $2 }'
```
If I change single quotes to double quotes, like this, it will print whole line.
```
echo "line1 a b c" | awk "{ print $2 }"
```
Why? I know I should use single quotes, but why is the whole line printed if I u... | If the `awk` command is single quoted, the `$2` is not interpreted by the shell, but is instead passed as the literal string `$2` to `awk`. `awk` will then `print` the second space delimited token in the input string, which in this case is `a`.
```
echo "line1 a b c" | awk '{ print $2 }' # prints the second space-deli... |
46421158 | Powershell String Length Validation | 6 | 2017-09-26 08:14:50 | <p>I created a really simple <code>HelloWorld.ps1</code> Power-shell script which accepts a <code>Name</code> parameter, validates its length and then prints a hello message, for example if you pass <code>John</code> as <code>Name</code>, it's supposed to print <code>Hello John!</code>.</p>
<p>Here is the Power-shell ... | 26,301 | 3,110,834 | 2019-12-20 15:51:23 | 46,421,159 | 14 | 2017-09-26 08:14:50 | 3,110,834 | 2019-12-20 15:51:23 | https://stackoverflow.com/q/46421158 | https://stackoverflow.com/a/46421159 | <p><strong>The problem - Using wrong operator</strong></p>
<p>Using wrong operators is a common mistake in PowerShell. In fact <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-5.1" rel="noreferrer"><code>></code></a> is <a href="https://l... | <p><strong>The problem - Using wrong operator</strong></p> <p>Using wrong operators is a common mistake in PowerShell. In fact <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-5.1" rel="noreferrer"><code>></code></a> is <a href="https://l... | 526, 153947 | powershell, powershell-cmdlet | <h1>Powershell String Length Validation</h1>
<p>I created a really simple <code>HelloWorld.ps1</code> Power-shell script which accepts a <code>Name</code> parameter, validates its length and then prints a hello message, for example if you pass <code>John</code> as <code>Name</code>, it's supposed to print <code>Hello J... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,007 | bash | # Powershell String Length Validation
I created a really simple `HelloWorld.ps1` Power-shell script which accepts a `Name` parameter, validates its length and then prints a hello message, for example if you pass `John` as `Name`, it's supposed to print `Hello John!`.
Here is the Power-shell script:
```
param (
[... | **The problem - Using wrong operator**
Using wrong operators is a common mistake in PowerShell. In fact [`>`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-5.1) is [output redirection operator](https://learn.microsoft.com/en-us/powershell/module/m... |
46070152 | How to run powershell command in batch file | 6 | 2017-09-06 08:19:37 | <pre><code>@ECHO off
$BIOS= Get-WmiObject -computername "BAHRIATSG2-PC" -Namespace
root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface
$BIOS.SetBIOSSetting('Setup Password','<utf-16/>TheBIOSPassword','<utf-16/>')
pause
</code></pre>
<p>when i save as .bat file and run it does not working otherwise... | 66,000 | 7,444,903 | 2024-12-13 17:10:08 | 46,071,092 | 14 | 2017-09-06 09:07:31 | 2,091,803 | 2017-09-06 09:07:31 | https://stackoverflow.com/q/46070152 | https://stackoverflow.com/a/46071092 | <p>Enclose your PowerShell code in,</p>
<pre><code>powershell -Command "& {}"
</code></pre>
<p>Remember to separate all statements with <code>;</code> and to enclose your <code>"</code> with a quoted string, i.e by using <code>""</code></p>
<pre><code>powershell -Command "& {$BIOS= Get-WmiObject -computernam... | <p>Enclose your PowerShell code in,</p> <pre><code>powershell -Command "& {}" </code></pre> <p>Remember to separate all statements with <code>;</code> and to enclose your <code>"</code> with a quoted string, i.e by using <code>""</code></p> <pre><code>powershell -Command "& {$BIOS= Get-WmiObject -computernam... | 526, 7002 | batch-file, powershell | <h1>How to run powershell command in batch file</h1>
<pre><code>@ECHO off
$BIOS= Get-WmiObject -computername "BAHRIATSG2-PC" -Namespace
root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface
$BIOS.SetBIOSSetting('Setup Password','<utf-16/>TheBIOSPassword','<utf-16/>')
pause
</code></pre>
<p>when i sav... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,008 | bash | # How to run powershell command in batch file
```
@ECHO off
$BIOS= Get-WmiObject -computername "BAHRIATSG2-PC" -Namespace
root/hp/instrumentedBIOS -Class HP_BIOSSettingInterface
$BIOS.SetBIOSSetting('Setup Password','<utf-16/>TheBIOSPassword','<utf-16/>')
pause
```
when i save as .bat file and run it does not wor... | Enclose your PowerShell code in,
```
powershell -Command "& {}"
```
Remember to separate all statements with `;` and to enclose your `"` with a quoted string, i.e by using `""`
```
powershell -Command "& {$BIOS= Get-WmiObject -computername ""BAHRIATSG2-PC\"" -Namespace root/hp/instrumentedBIOS -Class HP_BIOSSettingI... |
43014600 | How to execute terminal command in swift? | 6 | 2017-03-25 09:14:06 | <p>I am new toSswift. How can I run this process from Swift code?</p>
<ol>
<li>open Terminal window</li>
<li>execute <code>cd Desktop/firebase-mac</code></li>
<li>execute <code>npm start</code></li>
</ol>
<p>What I am actually trying to do is to start Node server on click from Swift code.</p>
| 13,637 | 7,174,045 | 2021-08-05 06:12:23 | 43,017,475 | 14 | 2017-03-25 14:17:04 | 632,407 | 2017-03-25 14:43:10 | https://stackoverflow.com/q/43014600 | https://stackoverflow.com/a/43017475 | <p>Full examples:</p>
<ul>
<li>go to some directory, let say <code>Desktop</code></li>
<li>Create a file with name <code>swsh</code>, and add into it (plaintext, not rtf, or doc)</li>
</ul>
<pre><code>#!/usr/bin/env xcrun swift
import Foundation
func shell(launchPath: String, arguments: [String]) -> String {
... | <p>Full examples:</p> <ul> <li>go to some directory, let say <code>Desktop</code></li> <li>Create a file with name <code>swsh</code>, and add into it (plaintext, not rtf, or doc)</li> </ul> <pre><code>#!/usr/bin/env xcrun swift import Foundation func shell(launchPath: String, arguments: [String]) -> String { ... | 369, 387, 391, 46426, 104797 | bash, macos, node.js, swift, terminal | <h1>How to execute terminal command in swift?</h1>
<p>I am new toSswift. How can I run this process from Swift code?</p>
<ol>
<li>open Terminal window</li>
<li>execute <code>cd Desktop/firebase-mac</code></li>
<li>execute <code>npm start</code></li>
</ol>
<p>What I am actually trying to do is to start Node server on ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,009 | bash | # How to execute terminal command in swift?
I am new toSswift. How can I run this process from Swift code?
1. open Terminal window
2. execute `cd Desktop/firebase-mac`
3. execute `npm start`
What I am actually trying to do is to start Node server on click from Swift code. | Full examples:
- go to some directory, let say `Desktop`
- Create a file with name `swsh`, and add into it (plaintext, not rtf, or doc)
```
#!/usr/bin/env xcrun swift
import Foundation
func shell(launchPath: String, arguments: [String]) -> String {
let process = Process()
process.launchPath = launchPath
... |
43005432 | Check if a video file has subtitles | 6 | 2017-03-24 17:14:23 | <p>Is it possible to check if a video file has a subtitle using bash and get a simple answer like "yes" or "no". I don't need to know any details about the subtitles.</p>
<p>Maybe using ffmpeg?</p>
| 8,782 | 3,186,995 | 2025-05-18 20:31:17 | 43,005,839 | 14 | 2017-03-24 17:37:06 | 5,726,027 | 2024-05-08 03:58:22 | https://stackoverflow.com/q/43005432 | https://stackoverflow.com/a/43005839 | <p>This should display a <code>0</code> if subtitles are found, and any other value if not found.</p>
<pre><code>ffmpeg -i video -c copy -map 0:s:0 -frames:s 1 -f null - -v 0 -hide_banner; echo $?
</code></pre>
| <p>This should display a <code>0</code> if subtitles are found, and any other value if not found.</p> <pre><code>ffmpeg -i video -c copy -map 0:s:0 -frames:s 1 -f null - -v 0 -hide_banner; echo $? </code></pre> | 58, 387, 549, 3847 | bash, ffmpeg, linux, ubuntu | <h1>Check if a video file has subtitles</h1>
<p>Is it possible to check if a video file has a subtitle using bash and get a simple answer like "yes" or "no". I don't need to know any details about the subtitles.</p>
<p>Maybe using ffmpeg?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,010 | bash | # Check if a video file has subtitles
Is it possible to check if a video file has a subtitle using bash and get a simple answer like "yes" or "no". I don't need to know any details about the subtitles.
Maybe using ffmpeg? | This should display a `0` if subtitles are found, and any other value if not found.
```
ffmpeg -i video -c copy -map 0:s:0 -frames:s 1 -f null - -v 0 -hide_banner; echo $?
``` |
41127585 | Shell: How to check available space and exit if not enough? | 6 | 2016-12-13 17:55:12 | <p>I want to check if I do have enough space before executing my script.
I thought about</p>
<pre><code>#!/bin/bash
set -e
cd
Home=$(pwd)
reqSpace=100000000
if [ (available Space) < reqSpace ]
echo "not enough Space"
exit 1
fi
do something
</code></pre>
<p>The space I want to check via</p>
<pre><code>df |... | 9,222 | 4,174,358 | 2024-06-05 10:20:10 | 41,127,750 | 14 | 2016-12-13 18:05:13 | 45,375 | 2024-06-05 10:20:10 | https://stackoverflow.com/q/41127585 | https://stackoverflow.com/a/41127750 | <p>Bringing it all together (<code>set -e</code> and <code>cd</code> omitted for brevity; Bash-specific syntax - not POSIX-compliant):</p>
<pre><code>#!/bin/bash
# Note: Numbers are 1024-byte units on Linux,
# and 512-byte units on macOS.
reqSpace=100000000
availSpace=$(df "$HOME" | awk 'NR==2 { print ... | <p>Bringing it all together (<code>set -e</code> and <code>cd</code> omitted for brevity; Bash-specific syntax - not POSIX-compliant):</p> <pre><code>#!/bin/bash # Note: Numbers are 1024-byte units on Linux, # and 512-byte units on macOS. reqSpace=100000000 availSpace=$(df "$HOME" | awk 'NR==2 { print ... | 58, 390 | linux, shell | <h1>Shell: How to check available space and exit if not enough?</h1>
<p>I want to check if I do have enough space before executing my script.
I thought about</p>
<pre><code>#!/bin/bash
set -e
cd
Home=$(pwd)
reqSpace=100000000
if [ (available Space) < reqSpace ]
echo "not enough Space"
exit 1
fi
do something... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,011 | bash | # Shell: How to check available space and exit if not enough?
I want to check if I do have enough space before executing my script.
I thought about
```
#!/bin/bash
set -e
cd
Home=$(pwd)
reqSpace=100000000
if [ (available Space) < reqSpace ]
echo "not enough Space"
exit 1
fi
do something
```
The space I want ... | Bringing it all together (`set -e` and `cd` omitted for brevity; Bash-specific syntax - not POSIX-compliant):
```
#!/bin/bash
# Note: Numbers are 1024-byte units on Linux,
# and 512-byte units on macOS.
reqSpace=100000000
availSpace=$(df "$HOME" | awk 'NR==2 { print $4 }')
if (( availSpace < reqSpace )); then
... |
40010042 | How do you pull a list of all scheduled jobs in Windows 2012 Server Task Scheduler? | 6 | 2016-10-12 23:40:12 | <p>I've been tasked with running a daily report that looks at all our jobs scheduled to run on that day, and checks to see if they have successfully ran or not. For now we are running on Windows 2008 Server, and have our jobs scheduled through the Task Scheduler. I'm definitely not a Windows developer, so I'm wonderi... | 28,954 | 4,372,759 | 2016-10-13 03:21:06 | 40,010,171 | 14 | 2016-10-12 23:55:51 | 6,591,806 | 2016-10-13 03:21:06 | https://stackoverflow.com/q/40010042 | https://stackoverflow.com/a/40010171 | <p>Try the following PowerShell command for scheduled tasks</p>
<pre><code> Get-ScheduledTask | Get-ScheduledTaskInfo
</code></pre>
<p>This will give you the information like when was the last time a task was run and what was the output etc. To make it look more organised or to select only information you require y... | <p>Try the following PowerShell command for scheduled tasks</p> <pre><code> Get-ScheduledTask | Get-ScheduledTaskInfo </code></pre> <p>This will give you the information like when was the last time a task was run and what was the output etc. To make it look more organised or to select only information you require y... | 64, 526, 84278 | powershell, windows, windows-server-2012 | <h1>How do you pull a list of all scheduled jobs in Windows 2012 Server Task Scheduler?</h1>
<p>I've been tasked with running a daily report that looks at all our jobs scheduled to run on that day, and checks to see if they have successfully ran or not. For now we are running on Windows 2008 Server, and have our jobs ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,012 | bash | # How do you pull a list of all scheduled jobs in Windows 2012 Server Task Scheduler?
I've been tasked with running a daily report that looks at all our jobs scheduled to run on that day, and checks to see if they have successfully ran or not. For now we are running on Windows 2008 Server, and have our jobs scheduled ... | Try the following PowerShell command for scheduled tasks
```
Get-ScheduledTask | Get-ScheduledTaskInfo
```
This will give you the information like when was the last time a task was run and what was the output etc. To make it look more organised or to select only information you require you can do the following:
`... |
38801077 | How do you parse the SRV record's port from a dig result? | 6 | 2016-08-06 06:03:00 | <p>I'm parsing the output of dig like this to get the port of an SRV record. </p>
<pre><code>export SERVER_DNS_NAME=myserver
echo "SERVER_DNS_NAME: " $SERVER_DNS_NAME
echo "dig: " $(dig +noall +answer $SERVER_DNS_NAME SRV )
echo "port old: " $(dig +noall +answer $SERVER_DNS_NAME SRV | cut -d ' ' -f 6)
SERVER_DIG_RESUL... | 20,252 | 15,441 | 2021-04-29 02:45:27 | 38,846,351 | 14 | 2016-08-09 09:02:08 | 6,782 | 2016-08-09 09:02:08 | https://stackoverflow.com/q/38801077 | https://stackoverflow.com/a/38846351 | <p>Use the <code>+short</code> option to <code>dig</code> which will give you the most abbreviated output which is then trivially parsed:</p>
<pre><code>% dig +short _xmpp-client._tcp.jabber.org. SRV
31 30 5222 hermes2v6.jabber.org.
30 30 5222 hermes2.jabber.org.
</code></pre>
| <p>Use the <code>+short</code> option to <code>dig</code> which will give you the most abbreviated output which is then trivially parsed:</p> <pre><code>% dig +short _xmpp-client._tcp.jabber.org. SRV 31 30 5222 hermes2v6.jabber.org. 30 30 5222 hermes2.jabber.org. </code></pre> | 325, 387, 700, 8838 | bash, dig, dns, port | <h1>How do you parse the SRV record's port from a dig result?</h1>
<p>I'm parsing the output of dig like this to get the port of an SRV record. </p>
<pre><code>export SERVER_DNS_NAME=myserver
echo "SERVER_DNS_NAME: " $SERVER_DNS_NAME
echo "dig: " $(dig +noall +answer $SERVER_DNS_NAME SRV )
echo "port old: " $(dig +noa... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,013 | bash | # How do you parse the SRV record's port from a dig result?
I'm parsing the output of dig like this to get the port of an SRV record.
```
export SERVER_DNS_NAME=myserver
echo "SERVER_DNS_NAME: " $SERVER_DNS_NAME
echo "dig: " $(dig +noall +answer $SERVER_DNS_NAME SRV )
echo "port old: " $(dig +noall +answer $SERVER_DN... | Use the `+short` option to `dig` which will give you the most abbreviated output which is then trivially parsed:
```
% dig +short _xmpp-client._tcp.jabber.org. SRV
31 30 5222 hermes2v6.jabber.org.
30 30 5222 hermes2.jabber.org.
``` |
24218482 | What's the maximum number of columns for Format-Table cmdlet in PowerShell | 6 | 2014-06-14 09:22:36 | <p>I'm writing a script emitting output in columns using <a href="http://technet.microsoft.com/en-us/library/hh849892.aspx" rel="nofollow noreferrer">Format-Table</a>, and cannot get more than 9 to show (either with or without the <a href="http://blogs.technet.com/b/nexthop/archive/2011/03/21/psformatorselect.aspx" rel... | 13,651 | 29,290 | 2020-09-03 21:28:14 | 38,794,195 | 14 | 2016-08-05 16:48:12 | 5,359,778 | 2016-08-05 16:48:12 | https://stackoverflow.com/q/24218482 | https://stackoverflow.com/a/38794195 | <p>By default, Format-Table will only show 10 columns. To get them all, use "*". See Example and Output below for details. </p>
<p>(FYI: -Wrap is used when the column is being displayed but the data in it is being truncated.)</p>
<p>EXAMPLE:</p>
<pre><code>$aryTemp = @()
$objTemp = New-Object PSObject
$objTemp |... | <p>By default, Format-Table will only show 10 columns. To get them all, use "*". See Example and Output below for details. </p> <p>(FYI: -Wrap is used when the column is being displayed but the data in it is being truncated.)</p> <p>EXAMPLE:</p> <pre><code>$aryTemp = @() $objTemp = New-Object PSObject $objTemp |... | 526, 95686 | powershell, powershell-4.0 | <h1>What's the maximum number of columns for Format-Table cmdlet in PowerShell</h1>
<p>I'm writing a script emitting output in columns using <a href="http://technet.microsoft.com/en-us/library/hh849892.aspx" rel="nofollow noreferrer">Format-Table</a>, and cannot get more than 9 to show (either with or without the <a hr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,014 | bash | # What's the maximum number of columns for Format-Table cmdlet in PowerShell
I'm writing a script emitting output in columns using [Format-Table](http://technet.microsoft.com/en-us/library/hh849892.aspx), and cannot get more than 9 to show (either with or without the [-AutoSize](http://blogs.technet.com/b/nexthop/arch... | By default, Format-Table will only show 10 columns. To get them all, use "*". See Example and Output below for details.
(FYI: -Wrap is used when the column is being displayed but the data in it is being truncated.)
EXAMPLE:
```
$aryTemp = @()
$objTemp = New-Object PSObject
$objTemp | Add-Member -type NoteProperty -N... |
38487179 | crontab script fail: end of file unexpected (expecting ")") when call $(date) | 6 | 2016-07-20 17:35:18 | <p>I want to add</p>
<pre><code>0 5 1 * * goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/report-week-$(date +%Y.%m.%d).html
</code></pre>
<p>but crontab always complains about that:</p>
<pre><code>Subject: Cron <root@deimos> goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/repor... | 1,871 | 2,755,116 | 2016-07-21 01:18:43 | 38,487,305 | 14 | 2016-07-20 17:42:45 | 1,126,841 | 2016-07-21 01:18:43 | https://stackoverflow.com/q/38487179 | https://stackoverflow.com/a/38487305 | <p><code>%</code> has special meaning in a crontab (it represents a newline), so you need to escape it to specify a literal percent sign.</p>
<pre><code> 0 5 1 * * goaccess ... > /home/xan/reports/report-week-$(date +\%Y.\%m.\%d).html
</code></pre>
| <p><code>%</code> has special meaning in a crontab (it represents a newline), so you need to escape it to specify a literal percent sign.</p> <pre><code> 0 5 1 * * goaccess ... > /home/xan/reports/report-week-$(date +\%Y.\%m.\%d).html </code></pre> | 387, 601, 115184 | bash, cron, goaccess | <h1>crontab script fail: end of file unexpected (expecting ")") when call $(date)</h1>
<p>I want to add</p>
<pre><code>0 5 1 * * goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/report-week-$(date +%Y.%m.%d).html
</code></pre>
<p>but crontab always complains about that:</p>
<pre><code>Subject: Cron &l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,015 | bash | # crontab script fail: end of file unexpected (expecting ")") when call $(date)
I want to add
```
0 5 1 * * goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/report-week-$(date +%Y.%m.%d).html
```
but crontab always complains about that:
```
Subject: Cron <root@deimos> goaccess -f /var/log/nginx/access.l... | `%` has special meaning in a crontab (it represents a newline), so you need to escape it to specify a literal percent sign.
```
0 5 1 * * goaccess ... > /home/xan/reports/report-week-$(date +\%Y.\%m.\%d).html
``` |
36097266 | Removing a PowerShell module using its version number | 6 | 2016-03-19 02:51:57 | <p>Is there an easy way to pass version as a parameter to <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Get-Module" rel="nofollow noreferrer"><code>Get-Module</code></a>?</p>
<p>I have two different versions of Azure PowerShell installed:</p>
<pre><code>C:\WINDOWS\system32>... | 24,982 | 2,517,730 | 2018-12-30 01:09:45 | 36,097,385 | 14 | 2016-03-19 03:11:45 | 5,329,137 | 2016-03-19 17:51:17 | https://stackoverflow.com/q/36097266 | https://stackoverflow.com/a/36097385 | <p>Please see: <code>get-help Remove-Module -full</code></p>
<pre><code>-FullyQualifiedName [<String[]>]
Removes modules with names that are specified in the form of
ModuleSpecification objects (described by the Remarks section of Module
Specification Constructor (Hashtable) on MSDN). F... | <p>Please see: <code>get-help Remove-Module -full</code></p> <pre><code>-FullyQualifiedName [<String[]>] Removes modules with names that are specified in the form of ModuleSpecification objects (described by the Remarks section of Module Specification Constructor (Hashtable) on MSDN). F... | 526 | powershell | <h1>Removing a PowerShell module using its version number</h1>
<p>Is there an easy way to pass version as a parameter to <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Get-Module" rel="nofollow noreferrer"><code>Get-Module</code></a>?</p>
<p>I have two different versions of Azur... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,016 | bash | # Removing a PowerShell module using its version number
Is there an easy way to pass version as a parameter to [`Get-Module`](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Get-Module)?
I have two different versions of Azure PowerShell installed:
```
C:\WINDOWS\system32> get-module -na... | Please see: `get-help Remove-Module -full`
```
-FullyQualifiedName [<String[]>]
Removes modules with names that are specified in the form of
ModuleSpecification objects (described by the Remarks section of Module
Specification Constructor (Hashtable) on MSDN). For example, the
FullyQ... |
34660374 | How to test connection to mysql server? | 6 | 2016-01-07 16:33:01 | <p>I'm trying to figure out how to test if a connection is possible with a given set of user, pw, and db name info. I parse out the user_name, password and database_name from an environment file and then I would like to test if the connection is possible. If possible continue with the rest of the script and if not poss... | 43,610 | 3,429,954 | 2016-01-07 17:03:43 | 34,661,044 | 14 | 2016-01-07 17:03:43 | 4,850,040 | 2016-01-07 17:03:43 | https://stackoverflow.com/q/34660374 | https://stackoverflow.com/a/34661044 | <p>You can make a no-op connection:</p>
<pre><code>mysql -e '\q'
</code></pre>
<p>If I run this with a suitable <code>.my.cnf</code> file, <code>$?</code> is zero. If I try to use a different user:</p>
<pre><code>mysql -u root -e '\q'
</code></pre>
<p>then I get an error message (which can be redirected away with ... | <p>You can make a no-op connection:</p> <pre><code>mysql -e '\q' </code></pre> <p>If I run this with a suitable <code>.my.cnf</code> file, <code>$?</code> is zero. If I try to use a different user:</p> <pre><code>mysql -u root -e '\q' </code></pre> <p>then I get an error message (which can be redirected away with ... | 21, 390 | mysql, shell | <h1>How to test connection to mysql server?</h1>
<p>I'm trying to figure out how to test if a connection is possible with a given set of user, pw, and db name info. I parse out the user_name, password and database_name from an environment file and then I would like to test if the connection is possible. If possible con... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,017 | bash | # How to test connection to mysql server?
I'm trying to figure out how to test if a connection is possible with a given set of user, pw, and db name info. I parse out the user_name, password and database_name from an environment file and then I would like to test if the connection is possible. If possible continue wit... | You can make a no-op connection:
```
mysql -e '\q'
```
If I run this with a suitable `.my.cnf` file, `$?` is zero. If I try to use a different user:
```
mysql -u root -e '\q'
```
then I get an error message (which can be redirected away with `2>/dev/null`) and `$?` is non-zero.
Note that this is a fairly limited t... |
32998146 | bash printf two arrays in two columns | 6 | 2015-10-07 16:56:44 | <p>I have let's say arrays ar1 and ar2 I want both of these arrays be printed in two columns.</p>
<pre><code> printf "%s\t%s\n" "${ar1[@]}" "${ar2[@]}"
</code></pre>
<p>any ideas?</p>
| 3,037 | 1,914,225 | 2021-02-11 18:41:25 | 32,998,279 | 14 | 2015-10-07 17:03:26 | 548,225 | 2015-10-07 18:29:15 | https://stackoverflow.com/q/32998146 | https://stackoverflow.com/a/32998279 | <p>Assuming array elements don't contain newlines, <code>paste</code> can do this job:</p>
<pre><code>ar1=(1 2 3 4 5 6)
ar2=(a b c d e f)
paste <(printf "%s\n" "${ar1[@]}") <(printf "%s\n" "${ar2[@]}")
1 a
2 b
3 c
4 d
5 e
6 f
</code></pre>
<p>Otherwise a pure BASH loop:</p>
<pre><code>for ((i=0; i&... | <p>Assuming array elements don't contain newlines, <code>paste</code> can do this job:</p> <pre><code>ar1=(1 2 3 4 5 6) ar2=(a b c d e f) paste <(printf "%s\n" "${ar1[@]}") <(printf "%s\n" "${ar2[@]}") 1 a 2 b 3 c 4 d 5 e 6 f </code></pre> <p>Otherwise a pure BASH loop:</p> <pre><code>for ((i=0; i&... | 114, 387, 1156 | arrays, bash, printf | <h1>bash printf two arrays in two columns</h1>
<p>I have let's say arrays ar1 and ar2 I want both of these arrays be printed in two columns.</p>
<pre><code> printf "%s\t%s\n" "${ar1[@]}" "${ar2[@]}"
</code></pre>
<p>any ideas?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,018 | bash | # bash printf two arrays in two columns
I have let's say arrays ar1 and ar2 I want both of these arrays be printed in two columns.
```
printf "%s\t%s\n" "${ar1[@]}" "${ar2[@]}"
```
any ideas? | Assuming array elements don't contain newlines, `paste` can do this job:
```
ar1=(1 2 3 4 5 6)
ar2=(a b c d e f)
paste <(printf "%s\n" "${ar1[@]}") <(printf "%s\n" "${ar2[@]}")
1 a
2 b
3 c
4 d
5 e
6 f
```
Otherwise a pure BASH loop:
```
for ((i=0; i< "${#ar1[@]}"; i++)) do printf "%s\t%s\n" "${ar1[$i]}" ... |
32217413 | Error while trying to load module environment in makefile | 6 | 2015-08-26 03:13:58 | <p>I have a makefile and I'm trying to load some modules before running the target. Here is the makefile:</p>
<pre><code>CC=g++
all:
. /usr/share/Modules/init/bash
module load gcc/4.8.1
module load opencv
module load python/2.7.5
$(CC) -std=gnu++11 -lstdc++ -fPIC -shared... | 6,994 | 2,308,191 | 2015-08-26 03:44:16 | 32,217,641 | 14 | 2015-08-26 03:44:16 | 258,523 | 2015-08-26 03:44:16 | https://stackoverflow.com/q/32217413 | https://stackoverflow.com/a/32217641 | <p>The default shell for running make recipes is <code>/bin/sh</code> not <code>/bin/bash</code>. You can override that by assigning to the <a href="http://www.gnu.org/software/make/manual/make.html#Choosing-the-Shell" rel="noreferrer"><code>SHELL</code></a> variable. (Note the addition of <code>.SHELLFLAGS</code> in m... | <p>The default shell for running make recipes is <code>/bin/sh</code> not <code>/bin/bash</code>. You can override that by assigning to the <a href="http://www.gnu.org/software/make/manual/make.html#Choosing-the-Shell" rel="noreferrer"><code>SHELL</code></a> variable. (Note the addition of <code>.SHELLFLAGS</code> in m... | 387, 4301 | bash, makefile | <h1>Error while trying to load module environment in makefile</h1>
<p>I have a makefile and I'm trying to load some modules before running the target. Here is the makefile:</p>
<pre><code>CC=g++
all:
. /usr/share/Modules/init/bash
module load gcc/4.8.1
module load opencv
module ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,019 | bash | # Error while trying to load module environment in makefile
I have a makefile and I'm trying to load some modules before running the target. Here is the makefile:
```
CC=g++
all:
. /usr/share/Modules/init/bash
module load gcc/4.8.1
module load opencv
module load python/2.7.5
... | The default shell for running make recipes is `/bin/sh` not `/bin/bash`. You can override that by assigning to the [`SHELL`](http://www.gnu.org/software/make/manual/make.html#Choosing-the-Shell) variable. (Note the addition of `.SHELLFLAGS` in make 4.0.)
Additionally, each line of a recipe is run in its own shell sess... |
32066800 | php shell_exec permission denied | 6 | 2015-08-18 08:00:27 | <p><code>shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1")</code></p>
<p>I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command.</p>
<p>How can I open these permissions?</p>
| 34,868 | 3,918,128 | 2015-08-18 09:30:31 | 32,068,610 | 14 | 2015-08-18 09:30:31 | 1,441,828 | 2015-08-18 09:30:31 | https://stackoverflow.com/q/32066800 | https://stackoverflow.com/a/32068610 | <p>Your PHP code is trying to access <code>/Users/Nerses/Downloads/ads.txt</code>, as you can see, that folder is owned by the user called "Nerses".</p>
<p>He is the only one (and root) who can access it (unless you change the permissions to that folder).</p>
<p>Normally, the user that executes <code>shell_exec</code... | <p>Your PHP code is trying to access <code>/Users/Nerses/Downloads/ads.txt</code>, as you can see, that folder is owned by the user called "Nerses".</p> <p>He is the only one (and root) who can access it (unless you change the permissions to that folder).</p> <p>Normally, the user that executes <code>shell_exec</code... | 5, 7932, 8646 | exec, php, shell-exec | <h1>php shell_exec permission denied</h1>
<p><code>shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1")</code></p>
<p>I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command.</p>
<p>How can I open these permissions?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,020 | bash | # php shell_exec permission denied
`shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1")`
I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command.
How can I open these permissions? | Your PHP code is trying to access `/Users/Nerses/Downloads/ads.txt`, as you can see, that folder is owned by the user called "Nerses".
He is the only one (and root) who can access it (unless you change the permissions to that folder).
Normally, the user that executes `shell_exec` is called `www-data`, so give permiss... |
30820977 | 'find' (command) finds nothing with -wholename | 6 | 2015-06-13 16:31:29 | <p>Why does this command work:</p>
<pre><code>/home/user1/tmp $ find ./../.. -wholename '.*/tmp/file.c' -exec echo '{}' \;
./../../user2/tmp/file.c
/home/user1/tmp $
</code></pre>
<p>And this command does not work? (finds nothing)</p>
<pre><code>/home/user1/tmp $ find /home -wholename '.*/tmp/file.c' -exec echo '{}'... | 15,433 | 670,521 | 2015-06-13 19:21:07 | 30,821,111 | 14 | 2015-06-13 16:44:36 | 4,178,025 | 2015-06-13 16:44:36 | https://stackoverflow.com/q/30820977 | https://stackoverflow.com/a/30821111 | <p>The first command generates file names starting with <code>./../..</code>. Thus the wholename pattern will match because they start with <code>.</code>.</p>
<p>The second command generates filenames starting with <code>/home</code>. However, the wholename pattern is still looking for paths starting with <code>.</co... | <p>The first command generates file names starting with <code>./../..</code>. Thus the wholename pattern will match because they start with <code>.</code>.</p> <p>The second command generates filenames starting with <code>/home</code>. However, the wholename pattern is still looking for paths starting with <code>.</co... | 58, 218, 387, 10193 | bash, directory, find, linux | <h1>'find' (command) finds nothing with -wholename</h1>
<p>Why does this command work:</p>
<pre><code>/home/user1/tmp $ find ./../.. -wholename '.*/tmp/file.c' -exec echo '{}' \;
./../../user2/tmp/file.c
/home/user1/tmp $
</code></pre>
<p>And this command does not work? (finds nothing)</p>
<pre><code>/home/user1/tmp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,021 | bash | # 'find' (command) finds nothing with -wholename
Why does this command work:
```
/home/user1/tmp $ find ./../.. -wholename '.*/tmp/file.c' -exec echo '{}' \;
./../../user2/tmp/file.c
/home/user1/tmp $
```
And this command does not work? (finds nothing)
```
/home/user1/tmp $ find /home -wholename '.*/tmp/file.c' -ex... | The first command generates file names starting with `./../..`. Thus the wholename pattern will match because they start with `.`.
The second command generates filenames starting with `/home`. However, the wholename pattern is still looking for paths starting with `.` which will not match any file in this case.
Note ... |
29847709 | Run a .jar file using .sh file in unix | 6 | 2015-04-24 12:35:37 | <p>I have a jar file <code>DirectoryScanner.jar</code> created in windows 7. I want to execute this jar on a unix server.
I ran the following command in putty and the jar run absolutely fine as expected:</p>
<pre><code>java -jar DirectoryScanner.jar
</code></pre>
<p>Now I want to create a .sh file on the unix server ... | 83,009 | 4,391,517 | 2022-12-27 08:08:24 | 29,920,781 | 14 | 2015-04-28 13:21:32 | 3,156,898 | 2015-04-28 13:21:32 | https://stackoverflow.com/q/29847709 | https://stackoverflow.com/a/29920781 | <p>In your shell script change into the directory containing the jar files. Possibly not the best practice but I use this all the time to emulate a 'working directory' where scripts are started from. This way my shell script can be installed in a <code>scripts</code> directory and my Java can be installed in a <code>li... | <p>In your shell script change into the directory containing the jar files. Possibly not the best practice but I use this all the time to emulate a 'working directory' where scripts are started from. This way my shell script can be installed in a <code>scripts</code> directory and my Java can be installed in a <code>li... | 17, 34, 387, 390, 4841 | bash, jar, java, shell, unix | <h1>Run a .jar file using .sh file in unix</h1>
<p>I have a jar file <code>DirectoryScanner.jar</code> created in windows 7. I want to execute this jar on a unix server.
I ran the following command in putty and the jar run absolutely fine as expected:</p>
<pre><code>java -jar DirectoryScanner.jar
</code></pre>
<p>Now... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,022 | bash | # Run a .jar file using .sh file in unix
I have a jar file `DirectoryScanner.jar` created in windows 7. I want to execute this jar on a unix server.
I ran the following command in putty and the jar run absolutely fine as expected:
```
java -jar DirectoryScanner.jar
```
Now I want to create a .sh file on the unix ser... | In your shell script change into the directory containing the jar files. Possibly not the best practice but I use this all the time to emulate a 'working directory' where scripts are started from. This way my shell script can be installed in a `scripts` directory and my Java can be installed in a `lib` directory.
Assu... |
27993448 | bash: Iterating over members of a JSON array selected by index | 6 | 2015-01-16 21:58:04 | <p>I'm using <code>jq</code> to parse a JSON file, extracting each JSON array in a series into a shell array.</p>
<p>My current code looks like the following:</p>
<pre><code>for ((i = 0; i < ${#nvars[@]}; i++)); do
v1=($(cat $INPUT | jq '."config"[i]."var1"[]'))
echo $v1
done
</code></pre>
<p>error messag... | 16,415 | 1,580,594 | 2022-01-03 14:20:20 | 27,993,824 | 14 | 2015-01-16 22:30:20 | 14,122 | 2015-01-17 02:08:49 | https://stackoverflow.com/q/27993448 | https://stackoverflow.com/a/27993824 | <p>There's a fair bit of room for improvement. Let's start here:</p>
<pre><code>v1=($(cat $INPUT | jq '."config"[$i]."var1"[]'))
</code></pre>
<p>...first, you don't actually need to use <code>cat</code>; it's slowing your performance, because it forces <code>jq</code> to read from a pipe rather than from your input ... | <p>There's a fair bit of room for improvement. Let's start here:</p> <pre><code>v1=($(cat $INPUT | jq '."config"[$i]."var1"[]')) </code></pre> <p>...first, you don't actually need to use <code>cat</code>; it's slowing your performance, because it forces <code>jq</code> to read from a pipe rather than from your input ... | 58, 387, 390, 1508, 105170 | bash, jq, json, linux, shell | <h1>bash: Iterating over members of a JSON array selected by index</h1>
<p>I'm using <code>jq</code> to parse a JSON file, extracting each JSON array in a series into a shell array.</p>
<p>My current code looks like the following:</p>
<pre><code>for ((i = 0; i < ${#nvars[@]}; i++)); do
v1=($(cat $INPUT | jq '.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,023 | bash | # bash: Iterating over members of a JSON array selected by index
I'm using `jq` to parse a JSON file, extracting each JSON array in a series into a shell array.
My current code looks like the following:
```
for ((i = 0; i < ${#nvars[@]}; i++)); do
v1=($(cat $INPUT | jq '."config"[i]."var1"[]'))
echo $v1
done... | There's a fair bit of room for improvement. Let's start here:
```
v1=($(cat $INPUT | jq '."config"[$i]."var1"[]'))
```
...first, you don't actually need to use `cat`; it's slowing your performance, because it forces `jq` to read from a pipe rather than from your input file directly. Just running `jq <"$INPUT"` would ... |
27868569 | Execute shell script in Java and read Output | 6 | 2015-01-09 20:19:54 | <p>I am executing the shell script using below method in java </p>
<pre><code>public static void main(String ar[])
{
//key value are being read from properties file, here I am assigning the sample values directly
key=mine
value="ls-1|tail-1"
String[] cmd = { "jj.sh" , key,value};
Process script_exe... | 41,011 | 1,400,123 | 2023-04-01 02:13:12 | 27,871,038 | 14 | 2015-01-09 23:37:37 | 1,899,640 | 2023-04-01 02:13:12 | https://stackoverflow.com/q/27868569 | https://stackoverflow.com/a/27871038 | <p>The primary reason why this doesn't work is that <code>`$2`</code> is not the same as <code>`ls -1 | tail -1`</code>, even when <code>$2</code> is set to that string.</p>
<p>If your script accepts a literal string with a command to execute, you can use <code>eval</code> to do so.</p>
<p>I created a complete example.... | <p>The primary reason why this doesn't work is that <code>`$2`</code> is not the same as <code>`ls -1 | tail -1`</code>, even when <code>$2</code> is set to that string.</p> <p>If your script accepts a literal string with a command to execute, you can use <code>eval</code> to do so.</p> <p>I created a complete example.... | 17, 58, 387, 390 | bash, java, linux, shell | <h1>Execute shell script in Java and read Output</h1>
<p>I am executing the shell script using below method in java </p>
<pre><code>public static void main(String ar[])
{
//key value are being read from properties file, here I am assigning the sample values directly
key=mine
value="ls-1|tail-1"
Strin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,024 | bash | # Execute shell script in Java and read Output
I am executing the shell script using below method in java
```
public static void main(String ar[])
{
//key value are being read from properties file, here I am assigning the sample values directly
key=mine
value="ls-1|tail-1"
String[] cmd = { "jj.sh" ,... | The primary reason why this doesn't work is that `` `$2` `` is not the same as `` `ls -1 | tail -1` ``, even when `$2` is set to that string.
If your script accepts a literal string with a command to execute, you can use `eval` to do so.
I created a complete example. Please copy-paste it and verify that it works befo... |
27808730 | Word splitting happens even with double quotes | 6 | 2015-01-06 23:00:00 | <p>According to <a href="http://tldp.org/LDP/abs/html/quotingvar.html" rel="noreferrer">http://tldp.org/LDP/abs/html/quotingvar.html</a></p>
<blockquote>
<p>Use double quotes to prevent word splitting.
An argument enclosed in double quotes presents itself as a single word,
even if it contains whitespace separato... | 1,128 | 940,313 | 2015-01-06 23:06:31 | 27,808,801 | 14 | 2015-01-06 23:06:31 | 258,523 | 2015-01-06 23:06:31 | https://stackoverflow.com/q/27808730 | https://stackoverflow.com/a/27808801 | <p>The answer is that <code>$@</code> is special.</p>
<p>From the <a href="http://www.gnu.org/software/bash/manual/bashref.html">Bash Reference Manual</a> section <a href="http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters"><code>3.4.2 Special Parameters</code></a>:</p>
<blockquote>
<p>@</p>
... | <p>The answer is that <code>$@</code> is special.</p> <p>From the <a href="http://www.gnu.org/software/bash/manual/bashref.html">Bash Reference Manual</a> section <a href="http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters"><code>3.4.2 Special Parameters</code></a>:</p> <blockquote> <p>@</p> ... | 387 | bash | <h1>Word splitting happens even with double quotes</h1>
<p>According to <a href="http://tldp.org/LDP/abs/html/quotingvar.html" rel="noreferrer">http://tldp.org/LDP/abs/html/quotingvar.html</a></p>
<blockquote>
<p>Use double quotes to prevent word splitting.
An argument enclosed in double quotes presents itself as ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,025 | bash | # Word splitting happens even with double quotes
According to <http://tldp.org/LDP/abs/html/quotingvar.html>
> Use double quotes to prevent word splitting.
> An argument enclosed in double quotes presents itself as a single word,
> even if it contains whitespace separators.
However, I have
```
0> /bin/bash --versio... | The answer is that `$@` is special.
From the [Bash Reference Manual](http://www.gnu.org/software/bash/manual/bashref.html) section [`3.4.2 Special Parameters`](http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters):
> @
>
> Expands to the positional parameters, starting from one. When the expansion ... |
26735271 | Use android adb shell to return one activity | 6 | 2014-11-04 12:34:01 | <p>I have the following problem:</p>
<p>Our company manufactured a android device that have no return button (not physical and not at the bottom of the screen), so I can't return to the previous activity/screen. Now I need to test an App developed by a third-party that only save settings when I return to the previous ... | 15,078 | 1,718,174 | 2022-07-12 17:34:20 | 26,736,655 | 14 | 2014-11-04 13:43:54 | 322,642 | 2022-07-12 17:34:20 | https://stackoverflow.com/q/26735271 | https://stackoverflow.com/a/26736655 | <p>you might want to try:</p>
<pre><code>adb shell input keyevent KEYCODE_BACK
</code></pre>
<p>cf. <a href="https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_BACK" rel="noreferrer">KEYCODE_BACK</a> event</p>
| <p>you might want to try:</p> <pre><code>adb shell input keyevent KEYCODE_BACK </code></pre> <p>cf. <a href="https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_BACK" rel="noreferrer">KEYCODE_BACK</a> event</p> | 390, 1386, 22975 | adb, android, shell | <h1>Use android adb shell to return one activity</h1>
<p>I have the following problem:</p>
<p>Our company manufactured a android device that have no return button (not physical and not at the bottom of the screen), so I can't return to the previous activity/screen. Now I need to test an App developed by a third-party ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,026 | bash | # Use android adb shell to return one activity
I have the following problem:
Our company manufactured a android device that have no return button (not physical and not at the bottom of the screen), so I can't return to the previous activity/screen. Now I need to test an App developed by a third-party that only save s... | you might want to try:
```
adb shell input keyevent KEYCODE_BACK
```
cf. [KEYCODE_BACK](https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_BACK) event |
26561550 | How to get no. of lines count that matches a string from all the files in a folder | 6 | 2014-10-25 10:47:31 | <p><strong>Problem Description:-</strong> I have a folder which contains so many text files. I want to search for a particular string say "string_example" in all files in that folder.Then I should get the count of total no. of lines in all files which has the string "string_example". That means if there are 5 matching... | 26,724 | 3,655,122 | 2017-05-29 08:28:35 | 26,561,562 | 14 | 2014-10-25 10:49:11 | 548,225 | 2017-05-29 08:28:35 | https://stackoverflow.com/q/26561550 | https://stackoverflow.com/a/26561562 | <p>You can pipe your <code>grep</code> with <code>wc -l</code> to get count of lines containing your keyword:</p>
<pre><code>grep -r "string_example" . | wc -l
</code></pre>
| <p>You can pipe your <code>grep</code> with <code>wc -l</code> to get count of lines containing your keyword:</p> <pre><code>grep -r "string_example" . | wc -l </code></pre> | 58, 387, 390 | bash, linux, shell | <h1>How to get no. of lines count that matches a string from all the files in a folder</h1>
<p><strong>Problem Description:-</strong> I have a folder which contains so many text files. I want to search for a particular string say "string_example" in all files in that folder.Then I should get the count of total no. of ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,027 | bash | # How to get no. of lines count that matches a string from all the files in a folder
**Problem Description:-** I have a folder which contains so many text files. I want to search for a particular string say "string_example" in all files in that folder.Then I should get the count of total no. of lines in all files whic... | You can pipe your `grep` with `wc -l` to get count of lines containing your keyword:
```
grep -r "string_example" . | wc -l
``` |
24868950 | Perl escaping argument for bash execution | 6 | 2014-07-21 15:31:20 | <p>I've written some code in Perl which executes some bash command within its execution. My problem was when bash command attributes contained white space inside which failed bash command execution. But I've managed to work with those argument simply adding quotes around argument. Unfortunately during tests I've found ... | 8,576 | 1,995,281 | 2016-05-22 11:22:38 | 24,869,016 | 14 | 2014-07-21 15:35:31 | 17,389 | 2014-07-21 15:35:31 | https://stackoverflow.com/q/24868950 | https://stackoverflow.com/a/24869016 | <p>It's much easier to use single quotes in bash; then the only character you need to worry about is a single quote itself.</p>
<pre><code>($arbitrary_string) =~ s/'/'"'"'/g;
`echo '$arbitrary_string'`
</code></pre>
| <p>It's much easier to use single quotes in bash; then the only character you need to worry about is a single quote itself.</p> <pre><code>($arbitrary_string) =~ s/'/'"'"'/g; `echo '$arbitrary_string'` </code></pre> | 58, 387, 390, 580 | bash, linux, perl, shell | <h1>Perl escaping argument for bash execution</h1>
<p>I've written some code in Perl which executes some bash command within its execution. My problem was when bash command attributes contained white space inside which failed bash command execution. But I've managed to work with those argument simply adding quotes arou... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,028 | bash | # Perl escaping argument for bash execution
I've written some code in Perl which executes some bash command within its execution. My problem was when bash command attributes contained white space inside which failed bash command execution. But I've managed to work with those argument simply adding quotes around argume... | It's much easier to use single quotes in bash; then the only character you need to worry about is a single quote itself.
```
($arbitrary_string) =~ s/'/'"'"'/g;
`echo '$arbitrary_string'`
``` |
23272927 | Why does AWK not treat this array index as a number unless I use int()? | 6 | 2014-04-24 15:13:06 | <p>I have genomics files of the following type:</p>
<pre><code>$ cat test-file_long.txt
2 41647 A G
2 45895 A G
2 45953 T C
2 224919 A G
2 230055 C G
2 233239 A G
2 234130 T G
2 23454 T C
</code></pre>
<p>When I use the following short AWK script, it does not return all of the elements which are greater than the ele... | 610 | 3,337,836 | 2014-04-24 17:40:53 | 23,272,992 | 14 | 2014-04-24 15:16:22 | 2,088,135 | 2014-04-24 17:40:53 | https://stackoverflow.com/q/23272927 | https://stackoverflow.com/a/23272992 | <p>Array keys in awk are strings, so alphabetical comparison is being done here. In your first example, <code>459</code> is greater than <code>458</code> alphabetically, so it passes the test.</p>
<p>If your only goal is to print the lines whose 2nd column is <code>> 45895</code> <em>numerically</em>, this would do... | <p>Array keys in awk are strings, so alphabetical comparison is being done here. In your first example, <code>459</code> is greater than <code>458</code> alphabetically, so it passes the test.</p> <p>If your only goal is to print the lines whose 2nd column is <code>> 45895</code> <em>numerically</em>, this would do... | 114, 387, 990 | arrays, awk, bash | <h1>Why does AWK not treat this array index as a number unless I use int()?</h1>
<p>I have genomics files of the following type:</p>
<pre><code>$ cat test-file_long.txt
2 41647 A G
2 45895 A G
2 45953 T C
2 224919 A G
2 230055 C G
2 233239 A G
2 234130 T G
2 23454 T C
</code></pre>
<p>When I use the following short ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,029 | bash | # Why does AWK not treat this array index as a number unless I use int()?
I have genomics files of the following type:
```
$ cat test-file_long.txt
2 41647 A G
2 45895 A G
2 45953 T C
2 224919 A G
2 230055 C G
2 233239 A G
2 234130 T G
2 23454 T C
```
When I use the following short AWK script, it does not return al... | Array keys in awk are strings, so alphabetical comparison is being done here. In your first example, `459` is greater than `458` alphabetically, so it passes the test.
If your only goal is to print the lines whose 2nd column is `> 45895` *numerically*, this would do:
```
awk '$2 > 45895' test-file_long.txt
```
Varia... |
22786580 | Exclude a define pattern using awk | 6 | 2014-04-01 12:56:46 | <p>I have a file with two columns and want to print the first column only if a determined pattern is not found in the second column, the file can be for example:</p>
<pre><code>3 0.
5 0.
4 1.
3 1.
10 0.
</code></pre>
<p>and I want to print the values in the first column only if there isn't the number 1. in t... | 20,468 | 761,620 | 2019-12-20 08:45:50 | 22,786,619 | 14 | 2014-04-01 12:58:19 | 1,983,854 | 2019-12-20 08:45:50 | https://stackoverflow.com/q/22786580 | https://stackoverflow.com/a/22786619 | <p>In general, you just need to indicate what pattern you don't want to match:</p>
<pre><code>awk '! /pattern/' file
</code></pre>
<p>In this specific case, where you want to print the 1st column of lines where 2st column is <em>not</em> "1.", you can say:</p>
<pre><code>$ awk '$2 != "1." {print $1}' file
3
5
10
</c... | <p>In general, you just need to indicate what pattern you don't want to match:</p> <pre><code>awk '! /pattern/' file </code></pre> <p>In this specific case, where you want to print the 1st column of lines where 2st column is <em>not</em> "1.", you can say:</p> <pre><code>$ awk '$2 != "1." {print $1}' file 3 5 10 </c... | 387, 990 | awk, bash | <h1>Exclude a define pattern using awk</h1>
<p>I have a file with two columns and want to print the first column only if a determined pattern is not found in the second column, the file can be for example:</p>
<pre><code>3 0.
5 0.
4 1.
3 1.
10 0.
</code></pre>
<p>and I want to print the values in the first c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,030 | bash | # Exclude a define pattern using awk
I have a file with two columns and want to print the first column only if a determined pattern is not found in the second column, the file can be for example:
```
3 0.
5 0.
4 1.
3 1.
10 0.
```
and I want to print the values in the first column only if there isn't the num... | In general, you just need to indicate what pattern you don't want to match:
```
awk '! /pattern/' file
```
In this specific case, where you want to print the 1st column of lines where 2st column is *not* "1.", you can say:
```
$ awk '$2 != "1." {print $1}' file
3
5
10
```
When the condition is accomplished, `{print... |
19052607 | Bash: using EXPORT inside SSH command | 6 | 2013-09-27 13:54:18 | <p>When executing this command:</p>
<pre><code>user@local:~ >ssh user@remote " export myvar=myvalue ; echo myvar=$myvar ; "
</code></pre>
<p>I get output:</p>
<pre><code>myvar=
</code></pre>
<p>When running directly on remote machine, I get the expected result:</p>
<pre><code>user@remote:~ > export myvar=myv... | 15,962 | 1,464,298 | 2013-09-27 14:05:14 | 19,052,798 | 14 | 2013-09-27 14:05:14 | 7,552 | 2013-09-27 14:05:14 | https://stackoverflow.com/q/19052607 | https://stackoverflow.com/a/19052798 | <p>That's because you're using double quotes, so the variable is being expanded on your <em>local</em> machine <em>before</em> ssh is even invoked. Use single quotes:</p>
<pre><code>ssh user@remote 'export myvar=myvalue ; echo myvar=$myvar'
</code></pre>
| <p>That's because you're using double quotes, so the variable is being expanded on your <em>local</em> machine <em>before</em> ssh is even invoked. Use single quotes:</p> <pre><code>ssh user@remote 'export myvar=myvalue ; echo myvar=$myvar' </code></pre> | 386, 387 | bash, ssh | <h1>Bash: using EXPORT inside SSH command</h1>
<p>When executing this command:</p>
<pre><code>user@local:~ >ssh user@remote " export myvar=myvalue ; echo myvar=$myvar ; "
</code></pre>
<p>I get output:</p>
<pre><code>myvar=
</code></pre>
<p>When running directly on remote machine, I get the expected result:</p>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,031 | bash | # Bash: using EXPORT inside SSH command
When executing this command:
```
user@local:~ >ssh user@remote " export myvar=myvalue ; echo myvar=$myvar ; "
```
I get output:
```
myvar=
```
When running directly on remote machine, I get the expected result:
```
user@remote:~ > export myvar=myvalue ; echo myvar=$myvar ;
... | That's because you're using double quotes, so the variable is being expanded on your *local* machine *before* ssh is even invoked. Use single quotes:
```
ssh user@remote 'export myvar=myvalue ; echo myvar=$myvar'
``` |
18953667 | "Illegal Byte sequence" error while using shell commands in mac bash terminal | 6 | 2013-09-23 07:17:18 | <p>Getting "illegal byte sequence" error while trying to extract non English characters from a large file in MacOS bash shell.
This is the script that I am trying to use:</p>
<pre><code>sed 's/[][a-z,0-9,A-Z,!@#\$%^&*(){}":/_-|. -][\;''=?]*//g' < $1 >Abhineet_extract1.txt;
sed 's/\(.\)/\1\
/g' <Abhineet_e... | 19,842 | 2,114,936 | 2013-09-23 07:29:26 | 18,953,848 | 14 | 2013-09-23 07:29:26 | 2,235,132 | 2013-09-23 07:29:26 | https://stackoverflow.com/q/18953667 | https://stackoverflow.com/a/18953848 | <p>It seems that a UTF-8 locale is causing <code>Illegal byte sequence</code>.</p>
<p>Instead say:</p>
<pre><code>LC_CTYPE=C your_command
</code></pre>
<p><code>man locale</code> says:</p>
<pre><code> These environment variables affect each locale categories for all
locale-aware programs:
LC_CTYPE
... | <p>It seems that a UTF-8 locale is causing <code>Illegal byte sequence</code>.</p> <p>Instead say:</p> <pre><code>LC_CTYPE=C your_command </code></pre> <p><code>man locale</code> says:</p> <pre><code> These environment variables affect each locale categories for all locale-aware programs: LC_CTYPE ... | 34, 387, 390, 5282, 35617 | bash, sed, shell, uniq, unix | <h1>"Illegal Byte sequence" error while using shell commands in mac bash terminal</h1>
<p>Getting "illegal byte sequence" error while trying to extract non English characters from a large file in MacOS bash shell.
This is the script that I am trying to use:</p>
<pre><code>sed 's/[][a-z,0-9,A-Z,!@#\$%^&*(){}":/_-|.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,032 | bash | # "Illegal Byte sequence" error while using shell commands in mac bash terminal
Getting "illegal byte sequence" error while trying to extract non English characters from a large file in MacOS bash shell.
This is the script that I am trying to use:
```
sed 's/[][a-z,0-9,A-Z,!@#\$%^&*(){}":/_-|. -][\;''=?]*//g' < $1 >A... | It seems that a UTF-8 locale is causing `Illegal byte sequence`.
Instead say:
```
LC_CTYPE=C your_command
```
`man locale` says:
```
These environment variables affect each locale categories for all
locale-aware programs:
LC_CTYPE
Character classification and case conversion.
``` |
18928260 | If command with user input OS X terminal | 6 | 2013-09-21 02:19:20 | <p>So I'm new to the OS X terminal and I'm trying to figure out how to use the <code>if</code> command with the <code>read</code> command.</p>
<p>Like this:</p>
<pre><code>echo stuff:
read f
if [ "f" == "y"]
then
echo wassup
else exit
</code></pre>
<p>What am I doing wrong?</p>
| 23,586 | 2,666,223 | 2022-05-18 01:49:49 | 18,928,267 | 14 | 2013-09-21 02:20:58 | 200,291 | 2013-09-21 02:20:58 | https://stackoverflow.com/q/18928260 | https://stackoverflow.com/a/18928267 | <p>You're asking bash to compare whether the strings <code>f</code> and <code>y</code> are equivalent. Clearly, they're not. You need to use a variable substitution:</p>
<pre><code>if [ "$f" == "y" ]
</code></pre>
<p>With this, it's asking “is the string consisting of the contents of the variable <code>f</code> equiv... | <p>You're asking bash to compare whether the strings <code>f</code> and <code>y</code> are equivalent. Clearly, they're not. You need to use a variable substitution:</p> <pre><code>if [ "$f" == "y" ] </code></pre> <p>With this, it's asking “is the string consisting of the contents of the variable <code>f</code> equiv... | 369, 387, 391, 2773 | bash, if-statement, macos, terminal | <h1>If command with user input OS X terminal</h1>
<p>So I'm new to the OS X terminal and I'm trying to figure out how to use the <code>if</code> command with the <code>read</code> command.</p>
<p>Like this:</p>
<pre><code>echo stuff:
read f
if [ "f" == "y"]
then
echo wassup
else exit
</code></pre>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,033 | bash | # If command with user input OS X terminal
So I'm new to the OS X terminal and I'm trying to figure out how to use the `if` command with the `read` command.
Like this:
```
echo stuff:
read f
if [ "f" == "y"]
then
echo wassup
else exit
```
What am I doing wrong? | You're asking bash to compare whether the strings `f` and `y` are equivalent. Clearly, they're not. You need to use a variable substitution:
```
if [ "$f" == "y" ]
```
With this, it's asking “is the string consisting of the contents of the variable `f` equivalent to the string `y`?”, which is probably what you were t... |
18480926 | Using git how to transfer code from one branch to another existing branch (not necessarily master)? | 6 | 2013-08-28 06:36:32 | <p>I have my code in one branch in the team git repo.
Now I need to "transfer" (i.e push) it into another branch of the same repo which team members are using. How can I do that ?</p>
<p>I prefer using git bash.</p>
<p>P.S - The new branch I have to transfer to is not <em>"master"</em>.</p>
| 24,575 | 1,472,493 | 2013-08-28 06:48:05 | 18,481,103 | 14 | 2013-08-28 06:48:05 | 2,536,029 | 2013-08-28 06:48:05 | https://stackoverflow.com/q/18480926 | https://stackoverflow.com/a/18481103 | <p>go to the target branch (<code>git checkout target</code>) and merge the code-having branch (<code>git merge code-having</code>). then, if needed, push the updated target branch to its remote.</p>
| <p>go to the target branch (<code>git checkout target</code>) and merge the code-having branch (<code>git merge code-having</code>). then, if needed, push the updated target branch to its remote.</p> | 119, 61874 | git, git-bash | <h1>Using git how to transfer code from one branch to another existing branch (not necessarily master)?</h1>
<p>I have my code in one branch in the team git repo.
Now I need to "transfer" (i.e push) it into another branch of the same repo which team members are using. How can I do that ?</p>
<p>I prefer using git bash... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,034 | bash | # Using git how to transfer code from one branch to another existing branch (not necessarily master)?
I have my code in one branch in the team git repo.
Now I need to "transfer" (i.e push) it into another branch of the same repo which team members are using. How can I do that ?
I prefer using git bash.
P.S - The new... | go to the target branch (`git checkout target`) and merge the code-having branch (`git merge code-having`). then, if needed, push the updated target branch to its remote. |
18217930 | while IFS= read -r -d $'\0' file ... explanation | 6 | 2013-08-13 19:48:32 | <p>I do not understand this line of shell script. Doesn't the while statement need a 'test' or [ ] or [[ ]] expression that will set $? to 1 or 0? How does</p>
<pre><code>while IFS= read -r -d $'\0'; do ...; done
</code></pre>
<p>do that? Any help understanding the syntax here is greatly appreciated.</p>
| 5,387 | 1,693,487 | 2023-04-02 10:44:55 | 18,218,019 | 14 | 2013-08-13 19:53:50 | 978,917 | 2013-08-13 19:53:50 | https://stackoverflow.com/q/18217930 | https://stackoverflow.com/a/18218019 | <p>In Bash, <code><i>varname</i>=<i>value</i> <i>command</i></code> runs <i>command</i> with the environment variable <code><i>varname</i></code> set to <code><i>value</i></code> (and all other environment variables inherited normally). So <code>IFS= read -r -d $'\0'</code> runs the command <code>read -r -d $'\0'</code... | <p>In Bash, <code><i>varname</i>=<i>value</i> <i>command</i></code> runs <i>command</i> with the environment variable <code><i>varname</i></code> set to <code><i>value</i></code> (and all other environment variables inherited normally). So <code>IFS= read -r -d $'\0'</code> runs the command <code>read -r -d $'\0'</code... | 387 | bash | <h1>while IFS= read -r -d $'\0' file ... explanation</h1>
<p>I do not understand this line of shell script. Doesn't the while statement need a 'test' or [ ] or [[ ]] expression that will set $? to 1 or 0? How does</p>
<pre><code>while IFS= read -r -d $'\0'; do ...; done
</code></pre>
<p>do that? Any help understandin... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,035 | bash | # while IFS= read -r -d $'\0' file ... explanation
I do not understand this line of shell script. Doesn't the while statement need a 'test' or [ ] or [[ ]] expression that will set $? to 1 or 0? How does
```
while IFS= read -r -d $'\0'; do ...; done
```
do that? Any help understanding the syntax here is greatly appr... | In Bash, `varname=value command` runs *command* with the environment variable `varname` set to `value` (and all other environment variables inherited normally). So `IFS= read -r -d $'\0'` runs the command `read -r -d $'\0'` with the environment variable `IFS` set to the empty string (meaning no field separators).
Sinc... |
15662799 | Powershell function to replace or add lines in text files | 6 | 2013-03-27 15:31:12 | <p>I'm working on a powershell script that modifies config files. I have files like this:</p>
<pre><code>#####################################################
# comment about logentrytimeout
#####################################################
Logentrytimeout= 1800
</code></pre>
<p>who should look like this:</p>
<p... | 30,594 | 1,257,145 | 2016-10-26 20:01:51 | 15,664,222 | 14 | 2013-03-27 16:33:38 | 1,565,512 | 2013-03-27 16:33:38 | https://stackoverflow.com/q/15662799 | https://stackoverflow.com/a/15664222 | <p>Assuming the <code>$key</code> you want to replace is always at the beginning of a line, and that it contains no special regex characters</p>
<pre><code>function setConfig( $file, $key, $value ) {
$content = Get-Content $file
if ( $content -match "^$key\s*=" ) {
$content -replace "^$key\s*=.*", "$ke... | <p>Assuming the <code>$key</code> you want to replace is always at the beginning of a line, and that it contains no special regex characters</p> <pre><code>function setConfig( $file, $key, $value ) { $content = Get-Content $file if ( $content -match "^$key\s*=" ) { $content -replace "^$key\s*=.*", "$ke... | 18, 526, 2498, 6051 | append, powershell, regex, replace | <h1>Powershell function to replace or add lines in text files</h1>
<p>I'm working on a powershell script that modifies config files. I have files like this:</p>
<pre><code>#####################################################
# comment about logentrytimeout
#####################################################
Logentr... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,036 | bash | # Powershell function to replace or add lines in text files
I'm working on a powershell script that modifies config files. I have files like this:
```
#####################################################
# comment about logentrytimeout
#####################################################
Logentrytimeout= 1800
```
... | Assuming the `$key` you want to replace is always at the beginning of a line, and that it contains no special regex characters
```
function setConfig( $file, $key, $value ) {
$content = Get-Content $file
if ( $content -match "^$key\s*=" ) {
$content -replace "^$key\s*=.*", "$key = $value" |
Set... |
14901373 | How do I log output of a shell script and also display on the screen? | 6 | 2013-02-15 18:48:07 | <p>I am running a script called upgrade.sh</p>
<p>ANd upgrade.sh calls a script called roll.sh</p>
<pre><code>roll.sh >> logfile.text
</code></pre>
<p>But roll.sh has some questions and prompts, and the redirect is preventing those outputs from hitting the screen. I cannot edit roll.sh. </p>
<p>I also tried `... | 18,438 | 813,040 | 2013-02-15 18:54:03 | 14,901,402 | 14 | 2013-02-15 18:49:49 | 446,554 | 2013-02-15 18:49:49 | https://stackoverflow.com/q/14901373 | https://stackoverflow.com/a/14901402 | <p>Use <code>tee</code>, it was created specifically for this purpose: to forward standard input to the screen and one or more files. Make sure to use the <code>-a</code> option to append to <code>logfile.text</code> if you don't want to overwrite it.</p>
<pre><code>roll.sh | tee -a logfile.text
</code></pre>
| <p>Use <code>tee</code>, it was created specifically for this purpose: to forward standard input to the screen and one or more files. Make sure to use the <code>-a</code> option to append to <code>logfile.text</code> if you don't want to overwrite it.</p> <pre><code>roll.sh | tee -a logfile.text </code></pre> | 34, 58, 390, 942 | linux, logging, shell, unix | <h1>How do I log output of a shell script and also display on the screen?</h1>
<p>I am running a script called upgrade.sh</p>
<p>ANd upgrade.sh calls a script called roll.sh</p>
<pre><code>roll.sh >> logfile.text
</code></pre>
<p>But roll.sh has some questions and prompts, and the redirect is preventing those ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,037 | bash | # How do I log output of a shell script and also display on the screen?
I am running a script called upgrade.sh
ANd upgrade.sh calls a script called roll.sh
```
roll.sh >> logfile.text
```
But roll.sh has some questions and prompts, and the redirect is preventing those outputs from hitting the screen. I cannot edit... | Use `tee`, it was created specifically for this purpose: to forward standard input to the screen and one or more files. Make sure to use the `-a` option to append to `logfile.text` if you don't want to overwrite it.
```
roll.sh | tee -a logfile.text
``` |
11978892 | What is the optimal way to extract values between braces in bash/awk? | 6 | 2012-08-15 23:48:57 | <p>I have the output in this format:</p>
<pre><code>Infosome - infotwo: (29333) - data-info-ids: (33389, 94934)
</code></pre>
<p>I want to extract the last two numbers in the last pair of braces. Some times there is only a single number in the last pair of braces.</p>
<p>This is the code I used.</p>
<pre><code>echo... | 10,508 | null | 2015-04-13 16:25:40 | 11,978,918 | 14 | 2012-08-15 23:51:50 | 348,785 | 2012-08-15 23:51:50 | https://stackoverflow.com/q/11978892 | https://stackoverflow.com/a/11978918 | <p>Try this:</p>
<pre><code>awk -F '[()]' '{print $(NF-1)}' input | tr -d ,
</code></pre>
<p>It's kind of refactoring of your command.</p>
| <p>Try this:</p> <pre><code>awk -F '[()]' '{print $(NF-1)}' input | tr -d , </code></pre> <p>It's kind of refactoring of your command.</p> | 387, 390, 990 | awk, bash, shell | <h1>What is the optimal way to extract values between braces in bash/awk?</h1>
<p>I have the output in this format:</p>
<pre><code>Infosome - infotwo: (29333) - data-info-ids: (33389, 94934)
</code></pre>
<p>I want to extract the last two numbers in the last pair of braces. Some times there is only a single number in... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,038 | bash | # What is the optimal way to extract values between braces in bash/awk?
I have the output in this format:
```
Infosome - infotwo: (29333) - data-info-ids: (33389, 94934)
```
I want to extract the last two numbers in the last pair of braces. Some times there is only a single number in the last pair of braces.
This i... | Try this:
```
awk -F '[()]' '{print $(NF-1)}' input | tr -d ,
```
It's kind of refactoring of your command. |
10881157 | Read file names from directory in Bash | 6 | 2012-06-04 12:18:59 | <p>I need to write a script that reads all the file names from a directory and then depending on the file name, for example if it contains R1 or R2, it will concatenates all the file names that contain, for example R1 in the name.</p>
<p>Can anyone give me some tip how to do this?</p>
<p>The only thing I was able to ... | 53,280 | 476,595 | 2022-12-06 21:32:49 | 10,881,176 | 14 | 2012-06-04 12:20:02 | 14,122 | 2014-01-28 19:25:13 | https://stackoverflow.com/q/10881157 | https://stackoverflow.com/a/10881176 | <p>To make the smallest change that fixes the problem:</p>
<pre><code>dir="path to the files"
for f in "$dir"/*; do
cat "$f"
done
</code></pre>
<p>To accomplish what you describe as your desired end goal:</p>
<pre><code>shopt -s nullglob
dir="path to the files"
substrings=( R1 R2 )
for substring in "${substrings[@... | <p>To make the smallest change that fixes the problem:</p> <pre><code>dir="path to the files" for f in "$dir"/*; do cat "$f" done </code></pre> <p>To accomplish what you describe as your desired end goal:</p> <pre><code>shopt -s nullglob dir="path to the files" substrings=( R1 R2 ) for substring in "${substrings[@... | 387 | bash | <h1>Read file names from directory in Bash</h1>
<p>I need to write a script that reads all the file names from a directory and then depending on the file name, for example if it contains R1 or R2, it will concatenates all the file names that contain, for example R1 in the name.</p>
<p>Can anyone give me some tip how t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,039 | bash | # Read file names from directory in Bash
I need to write a script that reads all the file names from a directory and then depending on the file name, for example if it contains R1 or R2, it will concatenates all the file names that contain, for example R1 in the name.
Can anyone give me some tip how to do this?
The ... | To make the smallest change that fixes the problem:
```
dir="path to the files"
for f in "$dir"/*; do
cat "$f"
done
```
To accomplish what you describe as your desired end goal:
```
shopt -s nullglob
dir="path to the files"
substrings=( R1 R2 )
for substring in "${substrings[@]}"; do
cat /dev/null "$dir"/*"$subs... |
10651116 | Exception thrown when creating a website via Invoke-Command | 6 | 2012-05-18 10:42:08 | <p>I'm calling the command</p>
<pre><code>Invoke-Command -computername remotepc {
Import-Module WebAdministration;
New-Website -Name www.somesite.com -ApplicationPool www.somesite.com -hostHeader www.somesite.com -physicalPath c:\inetpub\wwwroot }
</code></pre>
<p>The website is created successfully in IIS on the ... | 1,920 | 47,339 | 2012-05-18 12:41:34 | 10,652,760 | 14 | 2012-05-18 12:35:18 | 608,772 | 2012-05-18 12:41:34 | https://stackoverflow.com/q/10651116 | https://stackoverflow.com/a/10652760 | <p>Can you try :</p>
<pre><code>$var = New-Website ...
</code></pre>
<p>Not sure but <code>New-Website</code> return an object that PowerShell remote session try to serialize unsuccesfully. </p>
| <p>Can you try :</p> <pre><code>$var = New-Website ... </code></pre> <p>Not sure but <code>New-Website</code> return an object that PowerShell remote session try to serialize unsuccesfully. </p> | 215, 526 | iis, powershell | <h1>Exception thrown when creating a website via Invoke-Command</h1>
<p>I'm calling the command</p>
<pre><code>Invoke-Command -computername remotepc {
Import-Module WebAdministration;
New-Website -Name www.somesite.com -ApplicationPool www.somesite.com -hostHeader www.somesite.com -physicalPath c:\inetpub\wwwroot }... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,040 | bash | # Exception thrown when creating a website via Invoke-Command
I'm calling the command
```
Invoke-Command -computername remotepc {
Import-Module WebAdministration;
New-Website -Name www.somesite.com -ApplicationPool www.somesite.com -hostHeader www.somesite.com -physicalPath c:\inetpub\wwwroot }
```
The website is... | Can you try :
```
$var = New-Website ...
```
Not sure but `New-Website` return an object that PowerShell remote session try to serialize unsuccesfully. |
10340007 | Exporting powershell output to text file | 6 | 2012-04-26 19:24:07 | <p>I have a foreach loop inside my powershell script with prints $output on the shell during each iteration. There are lot many outputs and the number of entries that the shell can display is limited. I am looking to export the output to a text file. I know how to do it in command line. How is it possible in a powershe... | 91,824 | 945,391 | 2013-08-21 23:56:40 | 10,340,269 | 14 | 2012-04-26 19:41:44 | 153,982 | 2012-04-30 19:26:58 | https://stackoverflow.com/q/10340007 | https://stackoverflow.com/a/10340269 | <p>You can always redirect the output an exe to a file like so (even from cmd.exe):</p>
<pre><code>powershell c:\test.ps1 > c:\test.log
</code></pre>
<p>Within PowerShell, you can also redirect individual commands to file but in those cases you probably want to append to the log file rather than overwrite it e.g.:... | <p>You can always redirect the output an exe to a file like so (even from cmd.exe):</p> <pre><code>powershell c:\test.ps1 > c:\test.log </code></pre> <p>Within PowerShell, you can also redirect individual commands to file but in those cases you probably want to append to the log file rather than overwrite it e.g.:... | 64, 526, 531, 1231, 7002 | batch-file, command-line, powershell, scripting, windows | <h1>Exporting powershell output to text file</h1>
<p>I have a foreach loop inside my powershell script with prints $output on the shell during each iteration. There are lot many outputs and the number of entries that the shell can display is limited. I am looking to export the output to a text file. I know how to do it... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,041 | bash | # Exporting powershell output to text file
I have a foreach loop inside my powershell script with prints $output on the shell during each iteration. There are lot many outputs and the number of entries that the shell can display is limited. I am looking to export the output to a text file. I know how to do it in comma... | You can always redirect the output an exe to a file like so (even from cmd.exe):
```
powershell c:\test.ps1 > c:\test.log
```
Within PowerShell, you can also redirect individual commands to file but in those cases you probably want to append to the log file rather than overwrite it e.g.:
```
$logFile = 'c:\temp\test... |
10326933 | Case Sensitive Sort Unix Bash | 6 | 2012-04-26 03:45:23 | <p>Here is a screenshot of an issue I'm having with sort:</p>
<p><a href="https://i.sstatic.net/QafQy.png">https://i.sstatic.net/QafQy.png</a></p>
<p>The objective I want out of this, is to put all equal strings on consecutive lines. It works for 99% of the list I'm sorting, but there's a few hitches such as those i... | 3,244 | 1,159,330 | 2012-04-27 08:37:03 | 10,326,956 | 14 | 2012-04-26 03:47:33 | 643,977 | 2012-04-26 03:47:33 | https://stackoverflow.com/q/10326933 | https://stackoverflow.com/a/10326956 | <p>You probably need to override the locale; most Linux systems default to a UTF8 locale which specifies both case independent sorting and ignoring punctuation.</p>
<pre><code>LANG=C sort filename
</code></pre>
| <p>You probably need to override the locale; most Linux systems default to a UTF8 locale which specifies both case independent sorting and ignoring punctuation.</p> <pre><code>LANG=C sort filename </code></pre> | 34, 134, 387 | bash, sorting, unix | <h1>Case Sensitive Sort Unix Bash</h1>
<p>Here is a screenshot of an issue I'm having with sort:</p>
<p><a href="https://i.sstatic.net/QafQy.png">https://i.sstatic.net/QafQy.png</a></p>
<p>The objective I want out of this, is to put all equal strings on consecutive lines. It works for 99% of the list I'm sorting, bu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,042 | bash | # Case Sensitive Sort Unix Bash
Here is a screenshot of an issue I'm having with sort:
<https://i.sstatic.net/QafQy.png>
The objective I want out of this, is to put all equal strings on consecutive lines. It works for 99% of the list I'm sorting, but there's a few hitches such as those in the screen shot.
So all th... | You probably need to override the locale; most Linux systems default to a UTF8 locale which specifies both case independent sorting and ignoring punctuation.
```
LANG=C sort filename
``` |
9310571 | How to change encoding in many files? | 6 | 2012-02-16 11:33:57 | <p>I try this:</p>
<pre><code>find . -exec iconv -f iso8859-2 -t utf-8 {} \;
</code></pre>
<p>but output goes to the screen, not to the same file. How to do it?</p>
| 11,552 | 671,391 | 2013-09-23 03:06:41 | 9,310,774 | 14 | 2012-02-16 11:49:37 | 942,521 | 2012-02-20 11:32:44 | https://stackoverflow.com/q/9310571 | https://stackoverflow.com/a/9310774 | <p>Try this:</p>
<pre><code>find . -type f -print -exec iconv -f iso8859-2 -t utf-8 -o {}.converted {} \; -exec mv {}.converted {} \;
</code></pre>
<p>It will use temp file with '.converted' suffix (extension) and then will move it to original name, so be careful if you have files with '.converted' suffixes (I don't ... | <p>Try this:</p> <pre><code>find . -type f -print -exec iconv -f iso8859-2 -t utf-8 -o {}.converted {} \; -exec mv {}.converted {} \; </code></pre> <p>It will use temp file with '.converted' suffix (extension) and then will move it to original name, so be careful if you have files with '.converted' suffixes (I don't ... | 58, 387 | bash, linux | <h1>How to change encoding in many files?</h1>
<p>I try this:</p>
<pre><code>find . -exec iconv -f iso8859-2 -t utf-8 {} \;
</code></pre>
<p>but output goes to the screen, not to the same file. How to do it?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,043 | bash | # How to change encoding in many files?
I try this:
```
find . -exec iconv -f iso8859-2 -t utf-8 {} \;
```
but output goes to the screen, not to the same file. How to do it? | Try this:
```
find . -type f -print -exec iconv -f iso8859-2 -t utf-8 -o {}.converted {} \; -exec mv {}.converted {} \;
```
It will use temp file with '.converted' suffix (extension) and then will move it to original name, so be careful if you have files with '.converted' suffixes (I don't think you have).
Also this... |
8747303 | Converting time 121.419419 to readable minutes/seconds | 6 | 2012-01-05 17:56:52 | <p>I'd like to calculate the time my script runs, but my result from get-date is in totalseconds.</p>
<p>How can I convert this to 31:14:12 behing hours:minutes:seconds?</p>
| 13,624 | 1,114,155 | 2013-10-11 10:57:26 | 8,747,462 | 14 | 2012-01-05 18:07:24 | 9,833 | 2012-01-05 18:13:56 | https://stackoverflow.com/q/8747303 | https://stackoverflow.com/a/8747462 | <pre><code>PS> $ts = New-TimeSpan -Seconds 1234567
PS> '{0:00}:{1:00}:{2:00}' -f $ts.Hours,$ts.Minutes,$ts.Seconds
06:56:07
</code></pre>
<p>or</p>
<pre><code>PS> "$ts" -replace '^\d+?\.'
06:56:07
</code></pre>
| <pre><code>PS> $ts = New-TimeSpan -Seconds 1234567 PS> '{0:00}:{1:00}:{2:00}' -f $ts.Hours,$ts.Minutes,$ts.Seconds 06:56:07 </code></pre> <p>or</p> <pre><code>PS> "$ts" -replace '^\d+?\.' 06:56:07 </code></pre> | 526, 603 | powershell, time | <h1>Converting time 121.419419 to readable minutes/seconds</h1>
<p>I'd like to calculate the time my script runs, but my result from get-date is in totalseconds.</p>
<p>How can I convert this to 31:14:12 behing hours:minutes:seconds?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,044 | bash | # Converting time 121.419419 to readable minutes/seconds
I'd like to calculate the time my script runs, but my result from get-date is in totalseconds.
How can I convert this to 31:14:12 behing hours:minutes:seconds? | ```
PS> $ts = New-TimeSpan -Seconds 1234567
PS> '{0:00}:{1:00}:{2:00}' -f $ts.Hours,$ts.Minutes,$ts.Seconds
06:56:07
```
or
```
PS> "$ts" -replace '^\d+?\.'
06:56:07
``` |
8618853 | Rename all the files in the folder with increasing numbers | 6 | 2011-12-23 17:19:45 | <p>I have a folder and inside that folder I have 10-15 files with arbitrary names.
The filenames may include spaces in them. For example: <code>wWw.page.com __ (576)_002</code>.
In a terminal, when I press <code>w</code> and then <code>tab</code> the file name appears like this: <code>wWw.page.com\ \ __\ \(576\)_0.txt... | 6,768 | 706,780 | 2011-12-24 07:29:49 | 8,618,902 | 14 | 2011-12-23 17:25:34 | 714,501 | 2011-12-23 17:31:24 | https://stackoverflow.com/q/8618853 | https://stackoverflow.com/a/8618902 | <p>Instead of <code>ls</code> try to <code>glob</code>:</p>
<pre><code>index=0;
for name in *.txt
do
cp "${name}" "${index}.txt"
index=$((index+1))
done
</code></pre>
| <p>Instead of <code>ls</code> try to <code>glob</code>:</p> <pre><code>index=0; for name in *.txt do cp "${name}" "${index}.txt" index=$((index+1)) done </code></pre> | 58, 387, 390, 391 | bash, linux, shell, terminal | <h1>Rename all the files in the folder with increasing numbers</h1>
<p>I have a folder and inside that folder I have 10-15 files with arbitrary names.
The filenames may include spaces in them. For example: <code>wWw.page.com __ (576)_002</code>.
In a terminal, when I press <code>w</code> and then <code>tab</code> the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,045 | bash | # Rename all the files in the folder with increasing numbers
I have a folder and inside that folder I have 10-15 files with arbitrary names.
The filenames may include spaces in them. For example: `wWw.page.com __ (576)_002`.
In a terminal, when I press `w` and then `tab` the file name appears like this: `wWw.page.com\... | Instead of `ls` try to `glob`:
```
index=0;
for name in *.txt
do
cp "${name}" "${index}.txt"
index=$((index+1))
done
``` |
6531317 | How to get an variable output from remote pssession | 6 | 2011-06-30 07:25:06 | <p>I have a script to get virtual harddisk info from vmm, im executing it remotely from a server, currently im unable to get the variable value outside of the pssession in the local host, could you please help me out with achieveing the same.</p>
<pre><code>PS C:\Windows\system32> enter-pssession iscvmm02
[iscvmm02... | 16,071 | 804,199 | 2015-08-06 19:03:04 | 6,531,697 | 14 | 2011-06-30 08:00:01 | 503,046 | 2015-08-06 19:03:04 | https://stackoverflow.com/q/6531317 | https://stackoverflow.com/a/6531697 | <p>This example gets listing from remote computer's C drive and assigns it into a local variable. So tune your VMM script accordingly.</p>
<pre><code>$session = New-PSSession -ComputerName RemoteSystem
Invoke-Command -Session $session -ScriptBlock { $remoteC = gci c:\ }
# This shouldn't print anything.
$localC
# Print... | <p>This example gets listing from remote computer's C drive and assigns it into a local variable. So tune your VMM script accordingly.</p> <pre><code>$session = New-PSSession -ComputerName RemoteSystem Invoke-Command -Session $session -ScriptBlock { $remoteC = gci c:\ } # This shouldn't print anything. $localC # Print... | 114, 526, 63177 | arrays, powershell, powershell-remoting | <h1>How to get an variable output from remote pssession</h1>
<p>I have a script to get virtual harddisk info from vmm, im executing it remotely from a server, currently im unable to get the variable value outside of the pssession in the local host, could you please help me out with achieveing the same.</p>
<pre><code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,046 | bash | # How to get an variable output from remote pssession
I have a script to get virtual harddisk info from vmm, im executing it remotely from a server, currently im unable to get the variable value outside of the pssession in the local host, could you please help me out with achieveing the same.
```
PS C:\Windows\system... | This example gets listing from remote computer's C drive and assigns it into a local variable. So tune your VMM script accordingly.
```
$session = New-PSSession -ComputerName RemoteSystem
Invoke-Command -Session $session -ScriptBlock { $remoteC = gci c:\ }
# This shouldn't print anything.
$localC
# Print the result on... |
6365191 | Import large MySQL .sql file on Windows with Force | 6 | 2011-06-15 22:28:22 | <p>I would like to import a 350MB MySQL .sql file on a Windows 7 machine. I usually do this by using </p>
<pre><code>mysql -uuser -p -e "source c:/path/to/file.sql" database
</code></pre>
<p>since < doesn't work in Powershell. </p>
<p>My .sql file has an error in it this time. I'd prefer to just skip the bad row ... | 15,890 | 210,827 | 2014-03-07 14:43:32 | 6,365,553 | 14 | 2011-06-15 23:16:01 | 22,211 | 2011-06-16 00:18:15 | https://stackoverflow.com/q/6365191 | https://stackoverflow.com/a/6365553 | <p>You're probably going to have to have Powershell execute this in the standard console in order to use <code><</code> properly. Technically you could use <code>get-content</code> and pipe the output to <code>mysql</code>, but I've always found that to be slow, and it somehow still keeps the file contents in memory... | <p>You're probably going to have to have Powershell execute this in the standard console in order to use <code><</code> properly. Technically you could use <code>get-content</code> and pipe the output to <code>mysql</code>, but I've always found that to be slow, and it somehow still keeps the file contents in memory... | 21, 22, 64, 432, 526 | import, mysql, powershell, sql, windows | <h1>Import large MySQL .sql file on Windows with Force</h1>
<p>I would like to import a 350MB MySQL .sql file on a Windows 7 machine. I usually do this by using </p>
<pre><code>mysql -uuser -p -e "source c:/path/to/file.sql" database
</code></pre>
<p>since < doesn't work in Powershell. </p>
<p>My .sql file has an... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,047 | bash | # Import large MySQL .sql file on Windows with Force
I would like to import a 350MB MySQL .sql file on a Windows 7 machine. I usually do this by using
```
mysql -uuser -p -e "source c:/path/to/file.sql" database
```
since < doesn't work in Powershell.
My .sql file has an error in it this time. I'd prefer to just sk... | You're probably going to have to have Powershell execute this in the standard console in order to use `<` properly. Technically you could use `get-content` and pipe the output to `mysql`, but I've always found that to be slow, and it somehow still keeps the file contents in memory of the Powershell session.
This is ho... |
5521513 | Powershell gurus, please clarify variable scope in function | 6 | 2011-04-02 06:07:31 | <p>I read that variables inside the scope of a function are accessible in the current scope when the function script is dot-sourced.</p>
<p>Is it true? It's very strange, and unusual I think...</p>
<p>Can me clarify the reasons of this. Example, <code>my-f</code> sets <code>$my-f-var</code> to some integer, let's say... | 16,068 | 253,811 | 2011-04-02 06:54:50 | 5,521,563 | 14 | 2011-04-02 06:20:09 | 153,982 | 2011-04-02 06:54:50 | https://stackoverflow.com/q/5521513 | https://stackoverflow.com/a/5521563 | <p>Variables within the function are local to that scope unless you dot the invocation of the function name. When you dot source a script, the top-level script variables are effectively imported into the current scope along with the function definitions e.g.:</p>
<pre><code>PS> '$scriptvar = 2; function my-f { ${m... | <p>Variables within the function are local to that scope unless you dot the invocation of the function name. When you dot source a script, the top-level script variables are effectively imported into the current scope along with the function definitions e.g.:</p> <pre><code>PS> '$scriptvar = 2; function my-f { ${m... | 526, 2182 | powershell, scope | <h1>Powershell gurus, please clarify variable scope in function </h1>
<p>I read that variables inside the scope of a function are accessible in the current scope when the function script is dot-sourced.</p>
<p>Is it true? It's very strange, and unusual I think...</p>
<p>Can me clarify the reasons of this. Example, <c... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,048 | bash | # Powershell gurus, please clarify variable scope in function
I read that variables inside the scope of a function are accessible in the current scope when the function script is dot-sourced.
Is it true? It's very strange, and unusual I think...
Can me clarify the reasons of this. Example, `my-f` sets `$my-f-var` to... | Variables within the function are local to that scope unless you dot the invocation of the function name. When you dot source a script, the top-level script variables are effectively imported into the current scope along with the function definitions e.g.:
```
PS> '$scriptvar = 2; function my-f { ${my-f-var} = 2 }' > ... |
5051782 | ruby net-ssh login shell | 6 | 2011-02-19 15:56:50 | <p>Is there any way i can get a login shell in ruby using net-ssh?
Is that even possible?</p>
<p>By login shell i mean the ones the source /etc/profile..</p>
| 4,750 | 287,892 | 2018-05-06 15:14:20 | 5,344,321 | 14 | 2011-03-17 19:43:34 | 8,325 | 2011-03-17 19:43:34 | https://stackoverflow.com/q/5051782 | https://stackoverflow.com/a/5344321 | <p>Net-SSH is too low level to simply provide this up front (the way it is now, anyways). You can check out Net-SSH-Shell which builds upon Net-SSH to add login shell functionality: <a href="https://github.com/mitchellh/net-ssh-shell" rel="noreferrer">https://github.com/mitchellh/net-ssh-shell</a></p>
<p>The implement... | <p>Net-SSH is too low level to simply provide this up front (the way it is now, anyways). You can check out Net-SSH-Shell which builds upon Net-SSH to add login shell functionality: <a href="https://github.com/mitchellh/net-ssh-shell" rel="noreferrer">https://github.com/mitchellh/net-ssh-shell</a></p> <p>The implement... | 12, 386, 387, 31124 | bash, net-ssh, ruby, ssh | <h1>ruby net-ssh login shell</h1>
<p>Is there any way i can get a login shell in ruby using net-ssh?
Is that even possible?</p>
<p>By login shell i mean the ones the source /etc/profile..</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,049 | bash | # ruby net-ssh login shell
Is there any way i can get a login shell in ruby using net-ssh?
Is that even possible?
By login shell i mean the ones the source /etc/profile.. | Net-SSH is too low level to simply provide this up front (the way it is now, anyways). You can check out Net-SSH-Shell which builds upon Net-SSH to add login shell functionality: <https://github.com/mitchellh/net-ssh-shell>
The implementation is solid and works, however I found its not too useful since you can't speci... |
5024215 | how to restrain bash from removing blanks when processing file | 6 | 2011-02-17 01:37:05 | <p>A simple yet annoying thing:<br>
Using a script like this: </p>
<pre><code>while read x; do
echo "$x"
done<file
</code></pre>
<p>on a file containing whitespace: </p>
<pre><code> text
</code></pre>
<p>will give me an output without the whitespace:</p>
<pre><code>text
</code></pre>
<p>The proble... | 2,392 | 405,658 | 2015-04-04 17:33:52 | 5,024,237 | 14 | 2011-02-17 01:41:11 | 20,862 | 2011-02-17 01:41:11 | https://stackoverflow.com/q/5024215 | https://stackoverflow.com/a/5024237 | <p><code>read</code> is stripping the whitespace. Wipe <code>$IFS</code> first.</p>
<pre><code>while IFS= read x
do
echo "$x"
done < file
</code></pre>
| <p><code>read</code> is stripping the whitespace. Wipe <code>$IFS</code> first.</p> <pre><code>while IFS= read x do echo "$x" done < file </code></pre> | 387 | bash | <h1>how to restrain bash from removing blanks when processing file</h1>
<p>A simple yet annoying thing:<br>
Using a script like this: </p>
<pre><code>while read x; do
echo "$x"
done<file
</code></pre>
<p>on a file containing whitespace: </p>
<pre><code> text
</code></pre>
<p>will give me an output w... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,050 | bash | # how to restrain bash from removing blanks when processing file
A simple yet annoying thing:
Using a script like this:
```
while read x; do
echo "$x"
done<file
```
on a file containing whitespace:
```
text
```
will give me an output without the whitespace:
```
text
```
The problem is i need this s... | `read` is stripping the whitespace. Wipe `$IFS` first.
```
while IFS= read x
do
echo "$x"
done < file
``` |
4196523 | Render SSRS Report with parameters using SOAP in Powershell | 6 | 2010-11-16 16:38:42 | <p>I've been toying with this for days with no luck. Essentially I'm trying to build a simple library to render SSRS reports using Powershell. I'm using Powershell in an attempt to ease development later on (Instead of coding a C# app for each project). Mostly this will be used to schedule various things with report... | 18,230 | 479,732 | 2020-08-04 19:17:31 | 4,410,251 | 14 | 2010-12-10 15:16:40 | 479,732 | 2010-12-10 15:16:40 | https://stackoverflow.com/q/4196523 | https://stackoverflow.com/a/4410251 | <p>Here's some information on the solution that I ended up using, in case anyone else needs to do the same. It works really well.</p>
<p>The first approach that worked was building a DLL to use by the Powershell script. This worked fine, but it causes two problems. First, your script <em>had</em> to tote around a D... | <p>Here's some information on the solution that I ended up using, in case anyone else needs to do the same. It works really well.</p> <p>The first approach that worked was building a DLL to use by the Powershell script. This worked fine, but it causes two problems. First, your script <em>had</em> to tote around a D... | 526, 34777 | powershell, reporting-services | <h1>Render SSRS Report with parameters using SOAP in Powershell</h1>
<p>I've been toying with this for days with no luck. Essentially I'm trying to build a simple library to render SSRS reports using Powershell. I'm using Powershell in an attempt to ease development later on (Instead of coding a C# app for each proje... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,051 | bash | # Render SSRS Report with parameters using SOAP in Powershell
I've been toying with this for days with no luck. Essentially I'm trying to build a simple library to render SSRS reports using Powershell. I'm using Powershell in an attempt to ease development later on (Instead of coding a C# app for each project). Mostly... | Here's some information on the solution that I ended up using, in case anyone else needs to do the same. It works really well.
The first approach that worked was building a DLL to use by the Powershell script. This worked fine, but it causes two problems. First, your script *had* to tote around a DLL. Second, this DLL... |
2416880 | Passing variable through ssh doesnt work | 6 | 2010-03-10 12:42:31 | <p>I'm trying to pass a variable through a ssh connection, like this:</p>
<p><code>working_dir="/home/user/some_dir/"</code></p>
<p><code>ssh $USER@some_host 'qsub $working_dir/some_file.txt'</code></p>
<p>The connection itself is established, but this code gives me the following error:</p>
<p><code>working_dir: Un... | 13,310 | 288,803 | 2011-08-11 13:14:01 | 2,416,896 | 14 | 2010-03-10 12:44:24 | 290,122 | 2010-03-10 12:44:24 | https://stackoverflow.com/q/2416880 | https://stackoverflow.com/a/2416896 | <p>Try using double quotes, that should evaluate the variable locally:</p>
<p><code>ssh $USER@some_host "qsub $working_dir/some_file.txt"</code></p>
| <p>Try using double quotes, that should evaluate the variable locally:</p> <p><code>ssh $USER@some_host "qsub $working_dir/some_file.txt"</code></p> | 386, 387 | bash, ssh | <h1>Passing variable through ssh doesnt work</h1>
<p>I'm trying to pass a variable through a ssh connection, like this:</p>
<p><code>working_dir="/home/user/some_dir/"</code></p>
<p><code>ssh $USER@some_host 'qsub $working_dir/some_file.txt'</code></p>
<p>The connection itself is established, but this code gives me ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,052 | bash | # Passing variable through ssh doesnt work
I'm trying to pass a variable through a ssh connection, like this:
`working_dir="/home/user/some_dir/"`
`ssh $USER@some_host 'qsub $working_dir/some_file.txt'`
The connection itself is established, but this code gives me the following error:
`working_dir: Undefined variab... | Try using double quotes, that should evaluate the variable locally:
`ssh $USER@some_host "qsub $working_dir/some_file.txt"` |
2357704 | 'unexpected token' in PowerShell when fully pathing executable | 6 | 2010-03-01 17:28:57 | <p>Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive. </p>
<pre><code># My path includes pscp so this works.
pscp.exe -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HOST}:${PROXY_DIR}
# This does not work. I get unexp... | 11,840 | 4,527 | 2010-03-02 00:45:05 | 2,357,863 | 14 | 2010-03-01 17:52:28 | 153,982 | 2010-03-02 00:45:05 | https://stackoverflow.com/q/2357704 | https://stackoverflow.com/a/2357863 | <p>That's because this is also considered a parse error:</p>
<pre><code>"foo"\pscp.exe
</code></pre>
<p>Whereas this parses correctly as you have found:</p>
<pre><code>"$PUTTY_PATH\pscp.exe"
</code></pre>
<p>That resolves to a valid string but as you have already noticed, a string doesn't execute. You have to use... | <p>That's because this is also considered a parse error:</p> <pre><code>"foo"\pscp.exe </code></pre> <p>Whereas this parses correctly as you have found:</p> <pre><code>"$PUTTY_PATH\pscp.exe" </code></pre> <p>That resolves to a valid string but as you have already noticed, a string doesn't execute. You have to use... | 526 | powershell | <h1>'unexpected token' in PowerShell when fully pathing executable</h1>
<p>Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive. </p>
<pre><code># My path includes pscp so this works.
pscp.exe -i $PRIVATE_KEY $file ${P... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,053 | bash | # 'unexpected token' in PowerShell when fully pathing executable
Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive.
```
# My path includes pscp so this works.
pscp.exe -i $PRIVATE_KEY $file ${PROXY_USER}@${PROXY_HO... | That's because this is also considered a parse error:
```
"foo"\pscp.exe
```
Whereas this parses correctly as you have found:
```
"$PUTTY_PATH\pscp.exe"
```
That resolves to a valid string but as you have already noticed, a string doesn't execute. You have to use the call operator `&` to invoke the command that is ... |
6182369 | Exec a shell command in Go | 142 | 2011-05-31 02:18:08 | <p>I'm looking to execute a shell command in Go and get the resulting output as a string in my program. I saw the <a href="http://rosettacode.org/wiki/Execute_a_system_command#Go" rel="noreferrer">Rosetta Code</a> version:</p>
<pre><code>package main
import "fmt"
import "exec"
func main() {
cmd, err := exec.Run("/b... | 270,032 | 422 | 2024-11-07 14:13:36 | 6,182,595 | 13 | 2011-05-31 03:01:11 | 357,705 | 2019-04-03 11:53:07 | https://stackoverflow.com/q/6182369 | https://stackoverflow.com/a/6182595 | <p><strong>This answer does not represent the current state of the Go standard library. Please take a look at <a href="https://stackoverflow.com/a/7786922">@Lourenco's answer</a> for an up-to-date method!</strong></p>
<hr>
<p>Your example does not actually read the data from stdout. This works for me.</p>
<pre><code... | <p><strong>This answer does not represent the current state of the Go standard library. Please take a look at <a href="https://stackoverflow.com/a/7786922">@Lourenco's answer</a> for an up-to-date method!</strong></p> <hr> <p>Your example does not actually read the data from stdout. This works for me.</p> <pre><code... | 7839, 15627 | go, shellexecute | <h1>Exec a shell command in Go</h1>
<p>I'm looking to execute a shell command in Go and get the resulting output as a string in my program. I saw the <a href="http://rosettacode.org/wiki/Execute_a_system_command#Go" rel="noreferrer">Rosetta Code</a> version:</p>
<pre><code>package main
import "fmt"
import "exec"
func... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,054 | bash | # Exec a shell command in Go
I'm looking to execute a shell command in Go and get the resulting output as a string in my program. I saw the [Rosetta Code](http://rosettacode.org/wiki/Execute_a_system_command#Go) version:
```
package main
import "fmt"
import "exec"
func main() {
cmd, err := exec.Run("/bin/ls", []st... | **This answer does not represent the current state of the Go standard library. Please take a look at [@Lourenco's answer](https://stackoverflow.com/a/7786922) for an up-to-date method!**
---
Your example does not actually read the data from stdout. This works for me.
```
package main
import (
"fmt"
"exec"
... |
9443694 | How to add line number for output, prompt for line, then act based on input? | 76 | 2012-02-25 11:46:57 | <p>I wrote a shell script like this:</p>
<pre><code>#! /bin/sh
...
ls | grep "android"
...
</code></pre>
<p>and the output is :</p>
<pre><code>android1
android2
xx_android
...
</code></pre>
<p>I want to add a number in each file, like this:</p>
<pre><code> 1 android1
2 android2
3 XX_android
...
... | 52,620 | 1,165,196 | 2017-09-14 17:18:18 | 9,443,857 | 13 | 2012-02-25 12:10:18 | 348,785 | 2016-08-02 05:04:36 | https://stackoverflow.com/q/9443694 | https://stackoverflow.com/a/9443857 | <p>Instead of implementing the interaction, you can use built-in command <code>select</code>.</p>
<pre><code>select d in $(find . -type d -name '*android*'); do
if [ -n "$d" ]; then
# put your command here
echo "$d selected"
fi
done
</code></pre>
| <p>Instead of implementing the interaction, you can use built-in command <code>select</code>.</p> <pre><code>select d in $(find . -type d -name '*android*'); do if [ -n "$d" ]; then # put your command here echo "$d selected" fi done </code></pre> | 58, 390 | linux, shell | <h1>How to add line number for output, prompt for line, then act based on input?</h1>
<p>I wrote a shell script like this:</p>
<pre><code>#! /bin/sh
...
ls | grep "android"
...
</code></pre>
<p>and the output is :</p>
<pre><code>android1
android2
xx_android
...
</code></pre>
<p>I want to add a number in each file,... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,055 | bash | # How to add line number for output, prompt for line, then act based on input?
I wrote a shell script like this:
```
#! /bin/sh
...
ls | grep "android"
...
```
and the output is :
```
android1
android2
xx_android
...
```
I want to add a number in each file, like this:
```
1 android1
2 android2
3 XX_... | Instead of implementing the interaction, you can use built-in command `select`.
```
select d in $(find . -type d -name '*android*'); do
if [ -n "$d" ]; then
# put your command here
echo "$d selected"
fi
done
``` |
1821968 | How do I kill a backgrounded/detached ssh session? | 69 | 2009-11-30 19:44:21 | <p>I am using the program synergy together with an ssh tunnel</p>
<p>It works, i just have to open an console an type these two commands:</p>
<pre><code>ssh -f -N -L localhost:12345:otherHost:12345 otherUser@OtherHost
synergyc localhost
</code></pre>
<p>because im lazy i made an Bash-Script which is run with one mou... | 100,346 | 221,584 | 2023-06-08 14:31:41 | 1,826,338 | 13 | 2009-12-01 13:56:15 | 221,584 | 2009-12-01 13:56:15 | https://stackoverflow.com/q/1821968 | https://stackoverflow.com/a/1826338 | <p>well i dont want to add an & at the end of the commands as the connection will die if the console wintow is closed ... so i ended up with an ps-grep-awk-sed-combo</p>
<pre><code>ssh -f -N -L localhost:12345:otherHost:12345 otherUser@otherHost
echo `ps aux | grep -F 'ssh -f -N -L localhost' | grep -v -F 'grep'... | <p>well i dont want to add an & at the end of the commands as the connection will die if the console wintow is closed ... so i ended up with an ps-grep-awk-sed-combo</p> <pre><code>ssh -f -N -L localhost:12345:otherHost:12345 otherUser@otherHost echo `ps aux | grep -F 'ssh -f -N -L localhost' | grep -v -F 'grep'... | 386, 387, 3300, 15292 | background-process, bash, pid, ssh | <h1>How do I kill a backgrounded/detached ssh session?</h1>
<p>I am using the program synergy together with an ssh tunnel</p>
<p>It works, i just have to open an console an type these two commands:</p>
<pre><code>ssh -f -N -L localhost:12345:otherHost:12345 otherUser@OtherHost
synergyc localhost
</code></pre>
<p>bec... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,056 | bash | # How do I kill a backgrounded/detached ssh session?
I am using the program synergy together with an ssh tunnel
It works, i just have to open an console an type these two commands:
```
ssh -f -N -L localhost:12345:otherHost:12345 otherUser@OtherHost
synergyc localhost
```
because im lazy i made an Bash-Script which... | well i dont want to add an & at the end of the commands as the connection will die if the console wintow is closed ... so i ended up with an ps-grep-awk-sed-combo
```
ssh -f -N -L localhost:12345:otherHost:12345 otherUser@otherHost
echo `ps aux | grep -F 'ssh -f -N -L localhost' | grep -v -F 'grep' | awk '{ print $2... |
23828413 | Get MAC address using shell script | 53 | 2014-05-23 11:47:31 | <p>Currently all the solution mentioned for getting the MAC address always use eth0.
But what if instead of eth0 my interfaces start with eth1. Also on OS X the interface names are different.<br>
Also the interface eth0 may be present but is unused. i.e. not active, it doesn't have an IP. </p>
<p>So is there a way I c... | 152,450 | 3,639,687 | 2024-11-25 21:28:30 | 23,828,821 | 13 | 2014-05-23 12:06:44 | 874,188 | 2018-03-09 05:31:48 | https://stackoverflow.com/q/23828413 | https://stackoverflow.com/a/23828821 | <p>Observe that the interface name and the MAC address are the first and last fields on a line with no leading whitespace.</p>
<p>If one of the indented lines contains <code>inet addr:</code> the latest interface name and MAC address should be printed.</p>
<pre><code>ifconfig -a |
awk '/^[a-z]/ { iface=$1; mac=$NF; n... | <p>Observe that the interface name and the MAC address are the first and last fields on a line with no leading whitespace.</p> <p>If one of the indented lines contains <code>inet addr:</code> the latest interface name and MAC address should be printed.</p> <pre><code>ifconfig -a | awk '/^[a-z]/ { iface=$1; mac=$NF; n... | 58, 390, 3753 | linux, mac-address, shell | <h1>Get MAC address using shell script</h1>
<p>Currently all the solution mentioned for getting the MAC address always use eth0.
But what if instead of eth0 my interfaces start with eth1. Also on OS X the interface names are different.<br>
Also the interface eth0 may be present but is unused. i.e. not active, it doesn'... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,057 | bash | # Get MAC address using shell script
Currently all the solution mentioned for getting the MAC address always use eth0.
But what if instead of eth0 my interfaces start with eth1. Also on OS X the interface names are different.
Also the interface eth0 may be present but is unused. i.e. not active, it doesn't have an I... | Observe that the interface name and the MAC address are the first and last fields on a line with no leading whitespace.
If one of the indented lines contains `inet addr:` the latest interface name and MAC address should be printed.
```
ifconfig -a |
awk '/^[a-z]/ { iface=$1; mac=$NF; next }
/inet addr:/ { print i... |
20108886 | Powershell: Scheduled Task with Daily Trigger and Repetition Interval | 45 | 2013-11-20 22:57:31 | <p>I cant seem to figure out how to create a new scheduled task that is triggered daily and repeats every 30 minutes. I have been going in circles.</p>
<p>Everything about this below works for setting the task I want, but only triggered once. </p>
<pre><code>#Credentials to run task as
$username = "$env:USERDOMAIN\... | 139,447 | 893,158 | 2025-09-22 12:57:14 | 20,111,866 | 13 | 2013-11-21 03:27:45 | 893,158 | 2018-01-22 21:59:05 | https://stackoverflow.com/q/20108886 | https://stackoverflow.com/a/20111866 | <p>I'm sure there must be a better way, but this is my current workaround.</p>
<p>I created a task with the triggers I wanted then grabbed the XML it generated. </p>
<p>Below I am creating the task, then pulling the XML for that new task, replacing my triggers, then un-registering the task it and re-registering it w... | <p>I'm sure there must be a better way, but this is my current workaround.</p> <p>I created a task with the triggers I wanted then grabbed the XML it generated. </p> <p>Below I am creating the task, then pulling the XML for that new task, replacing my triggers, then un-registering the task it and re-registering it w... | 526, 73157 | powershell, powershell-3.0 | <h1>Powershell: Scheduled Task with Daily Trigger and Repetition Interval</h1>
<p>I cant seem to figure out how to create a new scheduled task that is triggered daily and repeats every 30 minutes. I have been going in circles.</p>
<p>Everything about this below works for setting the task I want, but only triggered on... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,058 | bash | # Powershell: Scheduled Task with Daily Trigger and Repetition Interval
I cant seem to figure out how to create a new scheduled task that is triggered daily and repeats every 30 minutes. I have been going in circles.
Everything about this below works for setting the task I want, but only triggered once.
```
#Credent... | I'm sure there must be a better way, but this is my current workaround.
I created a task with the triggers I wanted then grabbed the XML it generated.
Below I am creating the task, then pulling the XML for that new task, replacing my triggers, then un-registering the task it and re-registering it with the updated XML... |
7394290 | How to check return value from the shell directive | 42 | 2011-09-12 21:29:33 | <p>In my Makefile, I need to test if the current directory is an SVN repo or not and if it is not I want to indicate an error using the $(error) directive in Makefile.</p>
<p>So I plan to use the return value of $(shell svn info .) but I'm not sure how to get this value from within the Makefile.</p>
<p>Note: I'm not ... | 44,827 | 380,757 | 2024-03-13 17:34:47 | 7,397,267 | 13 | 2011-09-13 05:35:56 | 380,757 | 2011-09-13 05:35:56 | https://stackoverflow.com/q/7394290 | https://stackoverflow.com/a/7397267 | <p>This worked fine for me - based on @eriktous' answer with a minor modification of redirecting stdout as well to skip the output from svn info on a valid svn repo.</p>
<pre><code>SVN_INFO := $(shell svn info . 1>&2 2> /dev/null; echo $$?)
ifneq ($(SVN_INFO),0)
$(error "Not an SVN repo...")
endif
</code... | <p>This worked fine for me - based on @eriktous' answer with a minor modification of redirecting stdout as well to skip the output from svn info on a valid svn repo.</p> <pre><code>SVN_INFO := $(shell svn info . 1>&2 2> /dev/null; echo $$?) ifneq ($(SVN_INFO),0) $(error "Not an SVN repo...") endif </code... | 390, 4301, 9206, 13213 | gnu-make, makefile, return-value, shell | <h1>How to check return value from the shell directive</h1>
<p>In my Makefile, I need to test if the current directory is an SVN repo or not and if it is not I want to indicate an error using the $(error) directive in Makefile.</p>
<p>So I plan to use the return value of $(shell svn info .) but I'm not sure how to get... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,059 | bash | # How to check return value from the shell directive
In my Makefile, I need to test if the current directory is an SVN repo or not and if it is not I want to indicate an error using the $(error) directive in Makefile.
So I plan to use the return value of $(shell svn info .) but I'm not sure how to get this value from... | This worked fine for me - based on @eriktous' answer with a minor modification of redirecting stdout as well to skip the output from svn info on a valid svn repo.
```
SVN_INFO := $(shell svn info . 1>&2 2> /dev/null; echo $$?)
ifneq ($(SVN_INFO),0)
$(error "Not an SVN repo...")
endif
``` |
21999983 | Fast hash for strings | 38 | 2014-02-24 22:00:13 | <p>I have a set of ASCII strings, let's say they are file paths. They could be both short and quite long.</p>
<p>I'm looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids:</p>
<pre><code>https://www.youtube.com/wa... | 51,041 | 203,204 | 2023-02-17 20:43:38 | 22,000,293 | 13 | 2014-02-24 22:17:11 | 1,970,751 | 2014-03-08 02:06:53 | https://stackoverflow.com/q/21999983 | https://stackoverflow.com/a/22000293 | <p>I guess this question is off-topic, because opinion based, but at least one hint for you, I know the <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function" rel="noreferrer">FNV hash</a> because it is used by <em>The Sims 3</em> to find resources based on their names between the differen... | <p>I guess this question is off-topic, because opinion based, but at least one hint for you, I know the <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function" rel="noreferrer">FNV hash</a> because it is used by <em>The Sims 3</em> to find resources based on their names between the differen... | 16, 248, 387, 581, 111502 | algorithm, bash, hash, hashids, python | <h1>Fast hash for strings</h1>
<p>I have a set of ASCII strings, let's say they are file paths. They could be both short and quite long.</p>
<p>I'm looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids:</p>
<pre><... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,060 | bash | # Fast hash for strings
I have a set of ASCII strings, let's say they are file paths. They could be both short and quite long.
I'm looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids:
```
https://www.youtube.co... | I guess this question is off-topic, because opinion based, but at least one hint for you, I know the [FNV hash](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) because it is used by *The Sims 3* to find resources based on their names between the different content packages. They use the 64 bi... |
571429 | PowerShell, Web Requests, and Proxies | 37 | 2009-02-20 22:08:30 | <p>When making a simple <a href="https://stackoverflow.com/questions/340553/what-is-the-best-way-to-send-http-requests-from-windows-powershell">web request</a> is there a way to tell the PowerShell environment to just use your Internet Explorer's proxy settings?</p>
<p>My proxy settings are controlled by a network pol... | 85,972 | 36,590 | 2021-08-12 09:51:27 | 571,520 | 13 | 2009-02-20 22:37:23 | 16,076 | 2021-08-12 09:51:27 | https://stackoverflow.com/q/571429 | https://stackoverflow.com/a/571520 | <p><em>Untested</em>:</p>
<pre><code>$user = $env:username
$webproxy = (get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
$pwd = Read-Host "Password?" -assecurestring
$proxy = new-object System.Net.WebProxy
$proxy.Address = $webproxy
$account = new-object Syste... | <p><em>Untested</em>:</p> <pre><code>$user = $env:username $webproxy = (get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer $pwd = Read-Host "Password?" -assecurestring $proxy = new-object System.Net.WebProxy $proxy.Address = $webproxy $account = new-object Syste... | 526, 24067 | powershell, powershell-2.0 | <h1>PowerShell, Web Requests, and Proxies</h1>
<p>When making a simple <a href="https://stackoverflow.com/questions/340553/what-is-the-best-way-to-send-http-requests-from-windows-powershell">web request</a> is there a way to tell the PowerShell environment to just use your Internet Explorer's proxy settings?</p>
<p>My... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,061 | bash | # PowerShell, Web Requests, and Proxies
When making a simple [web request](https://stackoverflow.com/questions/340553/what-is-the-best-way-to-send-http-requests-from-windows-powershell) is there a way to tell the PowerShell environment to just use your Internet Explorer's proxy settings?
My proxy settings are control... | *Untested*:
```
$user = $env:username
$webproxy = (get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
$pwd = Read-Host "Password?" -assecurestring
$proxy = new-object System.Net.WebProxy
$proxy.Address = $webproxy
$account = new-object System.Net.NetworkCredential($user,... |
822907 | How do I use PowerShell to Validate XML files against an XSD? | 36 | 2009-05-05 01:21:50 | <p>As a part of my development I'd like to be able to validate an entire folder's worth of XML files against a single XSD file. A PowerShell function seems like a good candidate for this as I can then just pipe a list of files to it like so: dir *.xml | Validate-Xml -Schema .\MySchema.xsd</p>
<p>I've considered port... | 36,171 | 87,912 | 2025-11-28 09:57:38 | 823,013 | 13 | 2009-05-05 02:16:47 | 87,912 | 2024-07-03 14:43:01 | https://stackoverflow.com/q/822907 | https://stackoverflow.com/a/823013 | <p>I wrote a PowerShell function to do this:</p>
<p>Usage:</p>
<pre class="lang-powershell prettyprint-override"><code>dir *.xml | Test-Xml -Schema ".\MySchemaFile.xsd" -Namespace "http://tempuri.org"
</code></pre>
<p>Code:</p>
<pre class="lang-powershell prettyprint-override"><code>function Test-Xm... | <p>I wrote a PowerShell function to do this:</p> <p>Usage:</p> <pre class="lang-powershell prettyprint-override"><code>dir *.xml | Test-Xml -Schema ".\MySchemaFile.xsd" -Namespace "http://tempuri.org" </code></pre> <p>Code:</p> <pre class="lang-powershell prettyprint-override"><code>function Test-Xm... | 19, 526, 1532 | powershell, xml, xsd | <h1>How do I use PowerShell to Validate XML files against an XSD?</h1>
<p>As a part of my development I'd like to be able to validate an entire folder's worth of XML files against a single XSD file. A PowerShell function seems like a good candidate for this as I can then just pipe a list of files to it like so: dir *... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,062 | bash | # How do I use PowerShell to Validate XML files against an XSD?
As a part of my development I'd like to be able to validate an entire folder's worth of XML files against a single XSD file. A PowerShell function seems like a good candidate for this as I can then just pipe a list of files to it like so: dir *.xml | Vali... | I wrote a PowerShell function to do this:
Usage:
```
dir *.xml | Test-Xml -Schema ".\MySchemaFile.xsd" -Namespace "http://tempuri.org"
```
Code:
```
function Test-Xml {
param(
$InputObject = $null,
$Namespace = $null,
$SchemaFile = $null
)
BEGIN {
$failCount = 0
... |
11723442 | How do you set java version in windows git bash? | 35 | 2012-07-30 14:21:17 | <p>How do you set the java version to use in a windows git bash? Does it work via the environment variables? Java -version gives another version in dos command prompt than in git bash...</p>
| 97,221 | 26,521 | 2020-10-22 05:29:21 | 11,723,765 | 13 | 2012-07-30 14:40:48 | 1,172,714 | 2012-07-30 14:40:48 | https://stackoverflow.com/q/11723442 | https://stackoverflow.com/a/11723765 | <p>You don't set the java version. You are seeking the <code>$PATH</code> (bash) and the <code>%PATH%</code> (Windows/DOS/cmd.exe) environment variables. When you run the command <code>java -version</code>, the shell searches the directories on the <code>$PATH</code> to locate the <code>java</code> program and run it... | <p>You don't set the java version. You are seeking the <code>$PATH</code> (bash) and the <code>%PATH%</code> (Windows/DOS/cmd.exe) environment variables. When you run the command <code>java -version</code>, the shell searches the directories on the <code>$PATH</code> to locate the <code>java</code> program and run it... | 64, 61874 | git-bash, windows | <h1>How do you set java version in windows git bash?</h1>
<p>How do you set the java version to use in a windows git bash? Does it work via the environment variables? Java -version gives another version in dos command prompt than in git bash...</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,063 | bash | # How do you set java version in windows git bash?
How do you set the java version to use in a windows git bash? Does it work via the environment variables? Java -version gives another version in dos command prompt than in git bash... | You don't set the java version. You are seeking the `$PATH` (bash) and the `%PATH%` (Windows/DOS/cmd.exe) environment variables. When you run the command `java -version`, the shell searches the directories on the `$PATH` to locate the `java` program and run it with the given arguments. If you get different results in d... |
57016157 | How to stop git from writing non-errors to stderr | 34 | 2019-07-13 04:31:29 | <p>I have a script that I am using to automatically sync various remote git repositories. One thing I am trying to do with my scripts is to capture the output of stderr from every command and write all those errors into a text file that is then emailed to me after the script has finished. This will alert me to any prob... | 7,423 | 6,627,890 | 2022-01-02 23:07:51 | 57,016,167 | 13 | 2019-07-13 04:34:16 | 6,309 | 2019-07-13 05:15:47 | https://stackoverflow.com/q/57016157 | https://stackoverflow.com/a/57016167 | <blockquote>
<p>write all those errors into a text file </p>
</blockquote>
<p>Those are <em>not</em> always error, considering most Git commands outputs information message on stderr, as <a href="https://stackoverflow.com/a/37561629/6309">I mentioned here</a>:</p>
<blockquote>
<p>stderr as it is just informative ... | <blockquote> <p>write all those errors into a text file </p> </blockquote> <p>Those are <em>not</em> always error, considering most Git commands outputs information message on stderr, as <a href="https://stackoverflow.com/a/37561629/6309">I mentioned here</a>:</p> <blockquote> <p>stderr as it is just informative ... | 119, 387, 19156 | bash, git, stderr | <h1>How to stop git from writing non-errors to stderr</h1>
<p>I have a script that I am using to automatically sync various remote git repositories. One thing I am trying to do with my scripts is to capture the output of stderr from every command and write all those errors into a text file that is then emailed to me af... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,064 | bash | # How to stop git from writing non-errors to stderr
I have a script that I am using to automatically sync various remote git repositories. One thing I am trying to do with my scripts is to capture the output of stderr from every command and write all those errors into a text file that is then emailed to me after the s... | > write all those errors into a text file
Those are *not* always error, considering most Git commands outputs information message on stderr, as [I mentioned here](https://stackoverflow.com/a/37561629/6309):
> stderr as it is just informative messages, not to be consumed by machines.
If it better to test the exit sta... |
9126060 | Is there an easy way to set nullglob for one glob | 30 | 2012-02-03 09:02:09 | <p>In bash, if you do this:</p>
<pre><code>mkdir /tmp/empty
array=(/tmp/empty/*)
</code></pre>
<p>you find that <code>array</code> now has one element, <code>"/tmp/empty/*"</code>, not zero as you'd like. Thankfully, this can be avoided by turning on the nullglob shell option using <code>shopt -s nullglob</code></p>
... | 12,754 | 27,727 | 2021-11-25 20:47:31 | 20,580,952 | 13 | 2013-12-14 07:49:06 | 27,581 | 2013-12-24 17:36:29 | https://stackoverflow.com/q/9126060 | https://stackoverflow.com/a/20580952 | <p>With <code>mapfile</code> in Bash 4, you can load an array from a subshell with something like: <code>mapfile array < <(shopt -s nullglob; for f in ./*; do echo "$f"; done)</code>. Full example:</p>
<pre><code>$ shopt nullglob
nullglob off
$ find
.
./bar baz
./qux quux
$ mapfile array < <(shopt -... | <p>With <code>mapfile</code> in Bash 4, you can load an array from a subshell with something like: <code>mapfile array < <(shopt -s nullglob; for f in ./*; do echo "$f"; done)</code>. Full example:</p> <pre><code>$ shopt nullglob nullglob off $ find . ./bar baz ./qux quux $ mapfile array < <(shopt -... | 387, 3889, 135295 | bash, glob, shopt | <h1>Is there an easy way to set nullglob for one glob</h1>
<p>In bash, if you do this:</p>
<pre><code>mkdir /tmp/empty
array=(/tmp/empty/*)
</code></pre>
<p>you find that <code>array</code> now has one element, <code>"/tmp/empty/*"</code>, not zero as you'd like. Thankfully, this can be avoided by turning on the null... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,065 | bash | # Is there an easy way to set nullglob for one glob
In bash, if you do this:
```
mkdir /tmp/empty
array=(/tmp/empty/*)
```
you find that `array` now has one element, `"/tmp/empty/*"`, not zero as you'd like. Thankfully, this can be avoided by turning on the nullglob shell option using `shopt -s nullglob`
But nullgl... | With `mapfile` in Bash 4, you can load an array from a subshell with something like: `mapfile array < <(shopt -s nullglob; for f in ./*; do echo "$f"; done)`. Full example:
```
$ shopt nullglob
nullglob off
$ find
.
./bar baz
./qux quux
$ mapfile array < <(shopt -s nullglob; for f in ./*; do echo "$f"; done)
$ ... |
464777 | How do I change a file's attribute using Powershell? | 30 | 2009-01-21 10:40:32 | <p>I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location that have been copied.</p>
<p>How do I clear the Archive attribute of a file using Powershell?</p>
| 59,790 | 24,490 | 2023-06-16 00:26:56 | 464,826 | 13 | 2009-01-21 10:58:33 | 16,076 | 2009-01-21 10:58:33 | https://stackoverflow.com/q/464777 | https://stackoverflow.com/a/464826 | <p>From <a href="http://scriptolog.blogspot.com/2007/10/file-attributes-helper-functions.html" rel="noreferrer">here</a>:</p>
<pre><code>function Get-FileAttribute{
param($file,$attribute)
$val = [System.IO.FileAttributes]$attribute;
if((gci $file -force).Attributes -band $val -eq $val){$true;} else { $fal... | <p>From <a href="http://scriptolog.blogspot.com/2007/10/file-attributes-helper-functions.html" rel="noreferrer">here</a>:</p> <pre><code>function Get-FileAttribute{ param($file,$attribute) $val = [System.IO.FileAttributes]$attribute; if((gci $file -force).Attributes -band $val -eq $val){$true;} else { $fal... | 526 | powershell | <h1>How do I change a file's attribute using Powershell?</h1>
<p>I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location that have been copied.</p>
<p>How do I clear the Archive attribute of a file u... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,066 | bash | # How do I change a file's attribute using Powershell?
I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location that have been copied.
How do I clear the Archive attribute of a file using Powershell? | From [here](http://scriptolog.blogspot.com/2007/10/file-attributes-helper-functions.html):
```
function Get-FileAttribute{
param($file,$attribute)
$val = [System.IO.FileAttributes]$attribute;
if((gci $file -force).Attributes -band $val -eq $val){$true;} else { $false; }
}
function Set-FileAttribute{
... |
62739850 | wget command not found in git bash | 28 | 2020-07-05 11:06:24 | <p>I've already tried pip install wget in my cmd, which reads</p>
<pre><code>>pip install wget
Requirement already satisfied: wget in c:\users\user\...\python\python38-32\lib\site-packages (3.2)
</code></pre>
<p>however when I try the command in git bash, it keeps showing</p>
<pre><code>$ wget
bash: wget: command no... | 72,899 | 8,836,876 | 2024-08-12 19:54:01 | 62,739,902 | 13 | 2020-07-05 11:12:49 | 3,390,419 | 2020-07-05 11:12:49 | https://stackoverflow.com/q/62739850 | https://stackoverflow.com/a/62739902 | <p>With the command:</p>
<pre><code>pip install wget
</code></pre>
<p>you installed this Python library <a href="https://pypi.org/project/wget/" rel="noreferrer">https://pypi.org/project/wget/</a>, so you can use that from inside Python:</p>
<pre><code>import wget
</code></pre>
<hr />
<p>I imagine what you actually wan... | <p>With the command:</p> <pre><code>pip install wget </code></pre> <p>you installed this Python library <a href="https://pypi.org/project/wget/" rel="noreferrer">https://pypi.org/project/wget/</a>, so you can use that from inside Python:</p> <pre><code>import wget </code></pre> <hr /> <p>I imagine what you actually wan... | 5583, 6268, 61874 | git-bash, path, wget | <h1>wget command not found in git bash</h1>
<p>I've already tried pip install wget in my cmd, which reads</p>
<pre><code>>pip install wget
Requirement already satisfied: wget in c:\users\user\...\python\python38-32\lib\site-packages (3.2)
</code></pre>
<p>however when I try the command in git bash, it keeps showing<... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10 | 10,067 | bash | # wget command not found in git bash
I've already tried pip install wget in my cmd, which reads
```
>pip install wget
Requirement already satisfied: wget in c:\users\user\...\python\python38-32\lib\site-packages (3.2)
```
however when I try the command in git bash, it keeps showing
```
$ wget
bash: wget: command no... | With the command:
```
pip install wget
```
you installed this Python library <https://pypi.org/project/wget/>, so you can use that from inside Python:
```
import wget
```
---
I imagine what you actually want is to be able to use `wget` from inside Git bash. To do what, install [Wget for Windows](http://gnuwin32.so... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.