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
62969992
Clojure: what's the way to have current time string with babashka with least dependency?
8
2020-07-18 14:56:06
<p>With the following expression,</p> <pre><code>bb '(new java.util.Date)' #inst &quot;2020-07-18T14:35:16.663-00:00&quot; </code></pre> <p>I want to get a string, and slightly formatted as:</p> <pre><code>&quot;2020-07-18 UTC 14:35:16&quot; </code></pre> <p>With Babashka (bb), I wish to have the least dependency. Othe...
2,350
126,164
2020-07-20 00:22:39
62,970,721
15
2020-07-18 16:04:34
6,264
2020-07-18 16:04:34
https://stackoverflow.com/q/62969992
https://stackoverflow.com/a/62970721
<p>In babashka you can use the <code>java.time</code> package:</p> <pre class="lang-clj prettyprint-override"><code>(import 'java.time.format.DateTimeFormatter 'java.time.LocalDateTime) (def date (LocalDateTime/now)) (def formatter (DateTimeFormatter/ofPattern &quot;yyyy-MM-dd HH:mm:ss&quot;)) (.format date fo...
<p>In babashka you can use the <code>java.time</code> package:</p> <pre class="lang-clj prettyprint-override"><code>(import 'java.time.format.DateTimeFormatter 'java.time.LocalDateTime) (def date (LocalDateTime/now)) (def formatter (DateTimeFormatter/ofPattern &quot;yyyy-MM-dd HH:mm:ss&quot;)) (.format date fo...
603, 2512, 5002, 6525, 145505
babashka, calendar, clojure, date, time
<h1>Clojure: what's the way to have current time string with babashka with least dependency?</h1> <p>With the following expression,</p> <pre><code>bb '(new java.util.Date)' #inst &quot;2020-07-18T14:35:16.663-00:00&quot; </code></pre> <p>I want to get a string, and slightly formatted as:</p> <pre><code>&quot;2020-07-18...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,364
bash
# Clojure: what's the way to have current time string with babashka with least dependency? With the following expression, ``` bb '(new java.util.Date)' #inst "2020-07-18T14:35:16.663-00:00" ``` I want to get a string, and slightly formatted as: ``` "2020-07-18 UTC 14:35:16" ``` With Babashka (bb), I wish to have t...
In babashka you can use the `java.time` package: ``` (import 'java.time.format.DateTimeFormatter 'java.time.LocalDateTime) (def date (LocalDateTime/now)) (def formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss")) (.format date formatter) ;;=> "2020-07-18 18:04:04" ```
55063570
How to resolve variables in a Powershell script block
8
2019-03-08 12:48:05
<p>Given I have:</p> <pre><code>$a = &quot;world&quot; $b = { write-host &quot;hello $a&quot; } </code></pre> <p>How do I get the resolved text of the script block, which should be the entre string including write-host:</p> <pre><code>write-host &quot;hello world&quot; </code></pre> <p>UPDATE: additional clarifications...
12,327
3,140,853
2024-07-29 11:36:43
55,064,086
15
2019-03-08 13:19:58
11,025,476
2019-03-08 16:59:44
https://stackoverflow.com/q/55063570
https://stackoverflow.com/a/55064086
<p>As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:</p> <pre><code>$ExecutionContext.InvokeCommand.ExpandString($b) </code></pre> <p>Calling <code>.InvokeCommand.ExpandString($...
<p>As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:</p> <pre><code>$ExecutionContext.InvokeCommand.ExpandString($b) </code></pre> <p>Calling <code>.InvokeCommand.ExpandString($...
526
powershell
<h1>How to resolve variables in a Powershell script block</h1> <p>Given I have:</p> <pre><code>$a = &quot;world&quot; $b = { write-host &quot;hello $a&quot; } </code></pre> <p>How do I get the resolved text of the script block, which should be the entre string including write-host:</p> <pre><code>write-host &quot;hello...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,365
bash
# How to resolve variables in a Powershell script block Given I have: ``` $a = "world" $b = { write-host "hello $a" } ``` How do I get the resolved text of the script block, which should be the entre string including write-host: ``` write-host "hello world" ``` UPDATE: additional clarifications If you just print ...
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following: ``` $ExecutionContext.InvokeCommand.ExpandString($b) ``` Calling `.InvokeCommand.ExpandString($b)` on the current execution con...
54624827
JQ, how to count depending on conditions?
8
2019-02-11 06:10:11
<p>Using jq, I need to <strong>get the count</strong> within an array depending on two criterias: it MUST have <code>status === 'skipped' &amp;&amp; ref.includes(version)</code></p> <pre><code>[ { "id": 15484, "sha": "52606c8da57984d1243f436e5d12e275db29a6e0", "ref": "v1.4.15", "status": "canceled" ...
10,857
2,127,277
2019-02-21 20:19:40
54,624,970
15
2019-02-11 06:25:09
5,291,015
2019-02-11 19:48:27
https://stackoverflow.com/q/54624827
https://stackoverflow.com/a/54624970
<p>Use the <code>length()</code> function at the end of the filter, after putting the objects list into an array</p> <pre><code>jq '[.[] | select(.status == "skipped") | select(.ref | test("1\\.4\\.15"))] | length' </code></pre> <p>but for just returning the objects leave out the logic to get the length</p> <pre><co...
<p>Use the <code>length()</code> function at the end of the filter, after putting the objects list into an array</p> <pre><code>jq '[.[] | select(.status == "skipped") | select(.ref | test("1\\.4\\.15"))] | length' </code></pre> <p>but for just returning the objects leave out the logic to get the length</p> <pre><co...
58, 387, 1012, 1508, 105170
bash, debian, jq, json, linux
<h1>JQ, how to count depending on conditions?</h1> <p>Using jq, I need to <strong>get the count</strong> within an array depending on two criterias: it MUST have <code>status === 'skipped' &amp;&amp; ref.includes(version)</code></p> <pre><code>[ { "id": 15484, "sha": "52606c8da57984d1243f436e5d12e275db29a6e0...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,366
bash
# JQ, how to count depending on conditions? Using jq, I need to **get the count** within an array depending on two criterias: it MUST have `status === 'skipped' && ref.includes(version)` ``` [ { "id": 15484, "sha": "52606c8da57984d1243f436e5d12e275db29a6e0", "ref": "v1.4.15", "status": "canceled" ...
Use the `length()` function at the end of the filter, after putting the objects list into an array ``` jq '[.[] | select(.status == "skipped") | select(.ref | test("1\\.4\\.15"))] | length' ``` but for just returning the objects leave out the logic to get the length ``` jq '[.[] | select(.status == "skipped") | sele...
53841976
Get the date modified to be formatted with AM/PM with powershell
8
2018-12-18 22:23:00
<p>I've currently got</p> <pre><code>Get-Item &quot;C:\path\to\file.txt&quot; | ForEach-Object { $_.LastWriteTime } </code></pre> <p>Which outputs like this</p> <pre><code>12/18/2018 16:54:32 </code></pre> <p>But I want it to output like this</p> <pre><code>12/18/2018 4:54 PM </code></pre> <p>Is there any way I can do ...
38,064
10,808,414
2023-02-18 00:31:29
53,842,101
15
2018-12-18 22:33:53
4,643,093
2023-02-18 00:31:29
https://stackoverflow.com/q/53841976
https://stackoverflow.com/a/53842101
<p>Use the DateTime objects formatting. More info <a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings" rel="nofollow noreferrer">here</a></p> <pre class="lang-bash prettyprint-override"><code>Get-Item &quot;C:\path\to\file.txt&quot; | ForEach-Object { $_.LastWrit...
<p>Use the DateTime objects formatting. More info <a href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings" rel="nofollow noreferrer">here</a></p> <pre class="lang-bash prettyprint-override"><code>Get-Item &quot;C:\path\to\file.txt&quot; | ForEach-Object { $_.LastWrit...
526, 555, 1263
datetime, formatting, powershell
<h1>Get the date modified to be formatted with AM/PM with powershell</h1> <p>I've currently got</p> <pre><code>Get-Item &quot;C:\path\to\file.txt&quot; | ForEach-Object { $_.LastWriteTime } </code></pre> <p>Which outputs like this</p> <pre><code>12/18/2018 16:54:32 </code></pre> <p>But I want it to output like this</p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,367
bash
# Get the date modified to be formatted with AM/PM with powershell I've currently got ``` Get-Item "C:\path\to\file.txt" | ForEach-Object { $_.LastWriteTime } ``` Which outputs like this ``` 12/18/2018 16:54:32 ``` But I want it to output like this ``` 12/18/2018 4:54 PM ``` Is there any way I can do that?
Use the DateTime objects formatting. More info [here](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) ``` Get-Item "C:\path\to\file.txt" | ForEach-Object { $_.LastWriteTime.ToString("MM/dd/yyyy hh:mm tt") } ```
52293871
powershell performance: Get-ChildItem -Include vs. Get-ChildItem | Where-Object
8
2018-09-12 11:16:12
<p>I tried a few options to iterate my directories and get a huge performance difference between the following commands:</p> <p>Slow:</p> <pre><code>Get-ChildItem -Directory -Force -Recurse -Depth 3 -Include '$tf' </code></pre> <p>Fast:</p> <pre><code>Get-ChildItem -Directory -Force -Recurse -Depth 3 | Where-Object...
2,518
7,761,156
2018-09-12 11:41:43
52,294,304
15
2018-09-12 11:41:43
712,649
2018-09-12 11:41:43
https://stackoverflow.com/q/52293871
https://stackoverflow.com/a/52294304
<p><code>Get-ChildItem</code> is a provider cmdlet - that means that a bulk of its actual work is offloaded to an underlying provider, likely the <code>FileSystem</code> provider in your case.</p> <p>The provider itself doesn't actually support the <code>-Include</code>/<code>-Exclude</code> parameters, that's one of ...
<p><code>Get-ChildItem</code> is a provider cmdlet - that means that a bulk of its actual work is offloaded to an underlying provider, likely the <code>FileSystem</code> provider in your case.</p> <p>The provider itself doesn't actually support the <code>-Include</code>/<code>-Exclude</code> parameters, that's one of ...
526
powershell
<h1>powershell performance: Get-ChildItem -Include vs. Get-ChildItem | Where-Object</h1> <p>I tried a few options to iterate my directories and get a huge performance difference between the following commands:</p> <p>Slow:</p> <pre><code>Get-ChildItem -Directory -Force -Recurse -Depth 3 -Include '$tf' </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,368
bash
# powershell performance: Get-ChildItem -Include vs. Get-ChildItem | Where-Object I tried a few options to iterate my directories and get a huge performance difference between the following commands: Slow: ``` Get-ChildItem -Directory -Force -Recurse -Depth 3 -Include '$tf' ``` Fast: ``` Get-ChildItem -Directory -...
`Get-ChildItem` is a provider cmdlet - that means that a bulk of its actual work is offloaded to an underlying provider, likely the `FileSystem` provider in your case. The provider itself doesn't actually support the `-Include`/`-Exclude` parameters, that's one of the few things that the cmdlet takes care off - and fo...
51183960
How to change language/region and speech in Windows 10 with Powershell script
8
2018-07-05 05:29:20
<p>I'm trying to switch language, region and speech inside Windows 10 with a Powershell script. After the script ends, the user will be logged out and have to log in again. So everything should be changed.</p> <p>But the region and speech is currently not changed. Does anyone know what i'm missing in the script?</p> ...
34,353
6,108,697
2024-10-18 10:49:20
51,374,938
15
2018-07-17 06:50:11
6,108,697
2018-07-17 06:50:11
https://stackoverflow.com/q/51183960
https://stackoverflow.com/a/51374938
<p>Found the solution. Thanks for the link to the thread. </p> <p>To switch on german language</p> <pre><code>Set-Culture de-DE Set-WinSystemLocale -SystemLocale de-DE Set-WinUILanguageOverride -Language de-DE Set-WinUserLanguageList de-DE -Force Set-WinHomeLocation -GeoId 94 shutdown -r;exit </code></pre> <p>For en...
<p>Found the solution. Thanks for the link to the thread. </p> <p>To switch on german language</p> <pre><code>Set-Culture de-DE Set-WinSystemLocale -SystemLocale de-DE Set-WinUILanguageOverride -Language de-DE Set-WinUserLanguageList de-DE -Force Set-WinHomeLocation -GeoId 94 shutdown -r;exit </code></pre> <p>For en...
526, 9013, 106599, 107329
cortana, environment-variables, powershell, windows-10
<h1>How to change language/region and speech in Windows 10 with Powershell script</h1> <p>I'm trying to switch language, region and speech inside Windows 10 with a Powershell script. After the script ends, the user will be logged out and have to log in again. So everything should be changed.</p> <p>But the region and ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,369
bash
# How to change language/region and speech in Windows 10 with Powershell script I'm trying to switch language, region and speech inside Windows 10 with a Powershell script. After the script ends, the user will be logged out and have to log in again. So everything should be changed. But the region and speech is curren...
Found the solution. Thanks for the link to the thread. To switch on german language ``` Set-Culture de-DE Set-WinSystemLocale -SystemLocale de-DE Set-WinUILanguageOverride -Language de-DE Set-WinUserLanguageList de-DE -Force Set-WinHomeLocation -GeoId 94 shutdown -r;exit ``` For en-US use following lines ``` Set-Cu...
50986354
Execute python program from command line without script file
8
2018-06-22 10:54:02
<p>I want to execute a python program on a remote server, without creating a script. The remote server does not allow me to create any files anywhere on the file system.</p> <p>The python program has following structure, though the functions are a lot more complicated</p> <pre><code>def test2(): print("test2") def...
10,803
414,939
2022-04-11 21:36:56
50,986,737
15
2018-06-22 11:15:49
7,003,620
2021-03-28 18:41:30
https://stackoverflow.com/q/50986354
https://stackoverflow.com/a/50986737
<p>i found a solution, maybe it will help, you can use <code>EOF</code></p> <pre><code>$ python &lt;&lt; EOF &gt; def test2(): &gt; print(&quot;test2&quot;) &gt; &gt; def test_func(): &gt; test2() &gt; print(&quot;test_func&quot;) &gt; &gt; test_func() &gt; EOF # output test2 test_func </code></pre> <p>You can...
<p>i found a solution, maybe it will help, you can use <code>EOF</code></p> <pre><code>$ python &lt;&lt; EOF &gt; def test2(): &gt; print(&quot;test2&quot;) &gt; &gt; def test_func(): &gt; test2() &gt; print(&quot;test_func&quot;) &gt; &gt; test_func() &gt; EOF # output test2 test_func </code></pre> <p>You can...
16, 387
bash, python
<h1>Execute python program from command line without script file</h1> <p>I want to execute a python program on a remote server, without creating a script. The remote server does not allow me to create any files anywhere on the file system.</p> <p>The python program has following structure, though the functions are a l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,370
bash
# Execute python program from command line without script file I want to execute a python program on a remote server, without creating a script. The remote server does not allow me to create any files anywhere on the file system. The python program has following structure, though the functions are a lot more complica...
i found a solution, maybe it will help, you can use `EOF` ``` $ python << EOF > def test2(): > print("test2") > > def test_func(): > test2() > print("test_func") > > test_func() > EOF # output test2 test_func ``` You can also use `python -c` with `"""` ``` $ python -c """ def test2(): print("test2") def ...
49835860
Fastest Way to Create a File With Random Data
8
2018-04-14 20:25:55
<p>I have a requirement to create files of a specified size filled with random data. I can't use any third party tools to achieve this so all I have at my disposal is all the Powershell commands.</p> <p>What I have here works well with small files ranging in size from 1 KB to a 30 KB. It doesn't scale well when the f...
8,269
4,020,238
2018-10-10 10:46:51
49,836,223
15
2018-04-14 21:07:49
52,598
2018-04-15 21:29:45
https://stackoverflow.com/q/49835860
https://stackoverflow.com/a/49836223
<p>Following writes a set of random bytes to a file and is still pretty fast</p> <p><strong>Edit</strong><br> <sub>Kudos to Tom Blodget for pointing out an issue in decoding/encoding</sub></p> <pre><code>$bytes = 10MB [System.Security.Cryptography.RNGCryptoServiceProvider] $rng = New-Object System.Security.Cryptogra...
<p>Following writes a set of random bytes to a file and is still pretty fast</p> <p><strong>Edit</strong><br> <sub>Kudos to Tom Blodget for pointing out an issue in decoding/encoding</sub></p> <pre><code>$bytes = 10MB [System.Security.Cryptography.RNGCryptoServiceProvider] $rng = New-Object System.Security.Cryptogra...
526
powershell
<h1>Fastest Way to Create a File With Random Data</h1> <p>I have a requirement to create files of a specified size filled with random data. I can't use any third party tools to achieve this so all I have at my disposal is all the Powershell commands.</p> <p>What I have here works well with small files ranging in size...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,371
bash
# Fastest Way to Create a File With Random Data I have a requirement to create files of a specified size filled with random data. I can't use any third party tools to achieve this so all I have at my disposal is all the Powershell commands. What I have here works well with small files ranging in size from 1 KB to a 3...
Following writes a set of random bytes to a file and is still pretty fast **Edit** Kudos to Tom Blodget for pointing out an issue in decoding/encoding ``` $bytes = 10MB [System.Security.Cryptography.RNGCryptoServiceProvider] $rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider $rndbytes = New-Ob...
44368990
How do I get properties that ONLY have populated values?
8
2017-06-05 12:30:20
<p>How do I get properties that ONLY have populated values?</p> <p>So for example if I run</p> <pre><code>Get-QADUser -Identity "SomeOne" -IncludeAllProperties </code></pre> <p>the output would of course include.. all properties, including those with and those without values. I want a listing of properties with valu...
20,059
6,537,651
2023-07-22 13:09:05
44,370,775
15
2017-06-05 14:02:45
5,771,128
2017-06-05 14:02:45
https://stackoverflow.com/q/44368990
https://stackoverflow.com/a/44370775
<p>You could try using the built-in (hidden) property of PowerShell objects called <strong>PSObject</strong>, which includes a property called <strong>Properties</strong>, i.e. a list of all properties on the parent object.</p> <p>Maybe easier with an example. Take <code>Get-Process</code>... a process can have many a...
<p>You could try using the built-in (hidden) property of PowerShell objects called <strong>PSObject</strong>, which includes a property called <strong>Properties</strong>, i.e. a list of all properties on the parent object.</p> <p>Maybe easier with an example. Take <code>Get-Process</code>... a process can have many a...
526, 18663
powershell, quest
<h1>How do I get properties that ONLY have populated values?</h1> <p>How do I get properties that ONLY have populated values?</p> <p>So for example if I run</p> <pre><code>Get-QADUser -Identity "SomeOne" -IncludeAllProperties </code></pre> <p>the output would of course include.. all properties, including those with ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,372
bash
# How do I get properties that ONLY have populated values? How do I get properties that ONLY have populated values? So for example if I run ``` Get-QADUser -Identity "SomeOne" -IncludeAllProperties ``` the output would of course include.. all properties, including those with and those without values. I want a listi...
You could try using the built-in (hidden) property of PowerShell objects called **PSObject**, which includes a property called **Properties**, i.e. a list of all properties on the parent object. Maybe easier with an example. Take `Get-Process`... a process can have many attributes (properties) with or without values. ...
41733251
os.chdir() to relative home directory (/home/usr/)
8
2017-01-19 03:34:03
<p>Is there a way to use os.chdir() to go to relative user folder?</p> <p>I'm making a bash and the only issue I found is the <code>cd ~</code>, <code>arg[0]</code> is undefined since I'm using this cd functions:</p> <pre><code>def cd(args): os.chdir(args[0]) return current_status </code></pre> <p>Which I wa...
10,265
3,431,636
2017-01-19 03:36:25
41,733,276
15
2017-01-19 03:36:25
82,294
2017-01-19 03:36:25
https://stackoverflow.com/q/41733251
https://stackoverflow.com/a/41733276
<p>No, <code>os.chdir</code> won't do that, since it is just a thin wrapper around a system call. Consider that <code>~</code> is actually a legal name for a directory.</p> <p>You can, however, use <code>os.expanduser</code> to expand <code>~</code> in a path.</p> <pre><code>def cd(path): os.chdir(os.path.expand...
<p>No, <code>os.chdir</code> won't do that, since it is just a thin wrapper around a system call. Consider that <code>~</code> is actually a legal name for a directory.</p> <p>You can, however, use <code>os.expanduser</code> to expand <code>~</code> in a path.</p> <pre><code>def cd(path): os.chdir(os.path.expand...
16, 387, 390, 36377
bash, chdir, python, shell
<h1>os.chdir() to relative home directory (/home/usr/)</h1> <p>Is there a way to use os.chdir() to go to relative user folder?</p> <p>I'm making a bash and the only issue I found is the <code>cd ~</code>, <code>arg[0]</code> is undefined since I'm using this cd functions:</p> <pre><code>def cd(args): os.chdir(arg...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,373
bash
# os.chdir() to relative home directory (/home/usr/) Is there a way to use os.chdir() to go to relative user folder? I'm making a bash and the only issue I found is the `cd ~`, `arg[0]` is undefined since I'm using this cd functions: ``` def cd(args): os.chdir(args[0]) return current_status ``` Which I want...
No, `os.chdir` won't do that, since it is just a thin wrapper around a system call. Consider that `~` is actually a legal name for a directory. You can, however, use `os.expanduser` to expand `~` in a path. ``` def cd(path): os.chdir(os.path.expanduser(path)) ``` Note that this will also expand `~user` to the ho...
40593740
Can namerefs (declare -n) be used with arrays in bash? What does the documentation mean when it says declare -n cannot be applied to arrays?
8
2016-11-14 16:43:47
<p>In another question to stackoverflow, I asked how to pass array to a function. An answer recommended me a previous answers. One answer suggests that declare with -n option, referencing, is useful to pass array to an function, like following,</p> <pre><code>declare -a array=( 1 2 ) function array_pass_by_referen...
5,445
5,396,302
2023-02-12 12:06:11
40,593,912
15
2016-11-14 16:54:19
45,375
2016-11-14 19:27:51
https://stackoverflow.com/q/40593740
https://stackoverflow.com/a/40593912
<p>Further down on the <code>man</code> page, under the <code>PARAMETERS</code> heading, it also says: </p> <blockquote> <p>However, nameref variables can reference array variables and subscripted array variables.</p> </blockquote> <p>In other words:</p> <ul> <li>You can't declare a nameref variable <em>itself<...
<p>Further down on the <code>man</code> page, under the <code>PARAMETERS</code> heading, it also says: </p> <blockquote> <p>However, nameref variables can reference array variables and subscripted array variables.</p> </blockquote> <p>In other words:</p> <ul> <li>You can't declare a nameref variable <em>itself<...
387
bash
<h1>Can namerefs (declare -n) be used with arrays in bash? What does the documentation mean when it says declare -n cannot be applied to arrays?</h1> <p>In another question to stackoverflow, I asked how to pass array to a function. An answer recommended me a previous answers. One answer suggests that declare with -n...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,374
bash
# Can namerefs (declare -n) be used with arrays in bash? What does the documentation mean when it says declare -n cannot be applied to arrays? In another question to stackoverflow, I asked how to pass array to a function. An answer recommended me a previous answers. One answer suggests that declare with -n option, ref...
Further down on the `man` page, under the `PARAMETERS` heading, it also says: > However, nameref variables can reference array variables and subscripted array variables. In other words: - You can't declare a nameref variable *itself* as an array (`declare -a -n foo=...` will result in a syntax error). - But a namere...
38336329
ls not updating to reflect new files?
8
2016-07-12 18:22:40
<p>I am running a program that creates a bunch of files in a certain directory, and I want to watch the files get created.</p> <p>I open two terminal windows and cd one of them (call it terminal A) to the directory of the program (so I can run it) and the other (terminal B) to the directory where the output files get ...
4,119
2,049,443
2016-07-12 18:45:56
38,336,580
15
2016-07-12 18:40:00
6,580,940
2016-07-12 18:45:56
https://stackoverflow.com/q/38336329
https://stackoverflow.com/a/38336580
<p>This sequence of events seems to reproduce the issue.</p> <p><img src="https://i.sstatic.net/BOmgH.png" alt="image"></p> <p>Your program in terminal A probably deletes terminal B's current directory and then recreates it with the same name, so <code>ls</code> doesn't work since that particular directory that was o...
<p>This sequence of events seems to reproduce the issue.</p> <p><img src="https://i.sstatic.net/BOmgH.png" alt="image"></p> <p>Your program in terminal A probably deletes terminal B's current directory and then recreates it with the same name, so <code>ls</code> doesn't work since that particular directory that was o...
58, 387, 3589, 5310
bash, file, linux, ls
<h1>ls not updating to reflect new files?</h1> <p>I am running a program that creates a bunch of files in a certain directory, and I want to watch the files get created.</p> <p>I open two terminal windows and cd one of them (call it terminal A) to the directory of the program (so I can run it) and the other (terminal ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,375
bash
# ls not updating to reflect new files? I am running a program that creates a bunch of files in a certain directory, and I want to watch the files get created. I open two terminal windows and cd one of them (call it terminal A) to the directory of the program (so I can run it) and the other (terminal B) to the direct...
This sequence of events seems to reproduce the issue. ![image](https://i.sstatic.net/BOmgH.png) Your program in terminal A probably deletes terminal B's current directory and then recreates it with the same name, so `ls` doesn't work since that particular directory that was originally `cd`'d to by terminal B doesn't ...
38233988
Automatically reword all rebased commits
8
2016-07-06 21:22:05
<p>I want to be able to touch up my commit messages before I push them to my remote, but I want to automatically do that.</p> <p>I can reword all my additional commits by doing</p> <pre><code>git rebase -i origin/master </code></pre> <p>This brings up an editor where I can change all the commits from <code>pick</cod...
3,017
6,194,839
2022-06-24 10:06:56
38,234,236
15
2016-07-06 21:40:09
6,541,288
2016-07-06 21:40:09
https://stackoverflow.com/q/38233988
https://stackoverflow.com/a/38234236
<p>Since the question is a bit vague on the nature of edits, these are just cues on what you could do.</p> <blockquote> <p>I don't want to have to change every commit to reword.</p> </blockquote> <p>You could change the editor used by <code>git-rebase -i</code> with <code>git config sequence.editor 'sed -i s/pick/r...
<p>Since the question is a bit vague on the nature of edits, these are just cues on what you could do.</p> <blockquote> <p>I don't want to have to change every commit to reword.</p> </blockquote> <p>You could change the editor used by <code>git-rebase -i</code> with <code>git config sequence.editor 'sed -i s/pick/r...
119, 387
bash, git
<h1>Automatically reword all rebased commits</h1> <p>I want to be able to touch up my commit messages before I push them to my remote, but I want to automatically do that.</p> <p>I can reword all my additional commits by doing</p> <pre><code>git rebase -i origin/master </code></pre> <p>This brings up an editor where...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,376
bash
# Automatically reword all rebased commits I want to be able to touch up my commit messages before I push them to my remote, but I want to automatically do that. I can reword all my additional commits by doing ``` git rebase -i origin/master ``` This brings up an editor where I can change all the commits from `pick...
Since the question is a bit vague on the nature of edits, these are just cues on what you could do. > I don't want to have to change every commit to reword. You could change the editor used by `git-rebase -i` with `git config sequence.editor 'sed -i s/pick/reword/'`, so that no editor pops for the rebase-todo, and pi...
36625593
How to get the complete calling command of a BASH script from inside the script (not just the arguments)
8
2016-04-14 14:05:27
<p>I have a BASH script that has a long set of arguments and two ways of calling it: </p> <pre><code>my_script --option1 value --option2 value ... etc </code></pre> <p>or </p> <pre><code>my_script val1 val2 val3 ..... valn </code></pre> <p>This script in turn compiles and runs a large FORTRAN code suite that e...
11,942
6,068,294
2016-04-15 15:10:54
36,625,791
15
2016-04-14 14:12:51
45,375
2016-04-15 15:10:54
https://stackoverflow.com/q/36625593
https://stackoverflow.com/a/36625791
<p>You can try the following:</p> <pre><code>myInvocation="$(printf %q "$BASH_SOURCE")$((($#)) &amp;&amp; printf ' %q' "$@")" </code></pre> <p><code>$BASH_SOURCE</code> refers to the running script (as invoked), and <code>$@</code> is the array of arguments; <code>(($#)) &amp;&amp;</code> ensures that the following <...
<p>You can try the following:</p> <pre><code>myInvocation="$(printf %q "$BASH_SOURCE")$((($#)) &amp;&amp; printf ' %q' "$@")" </code></pre> <p><code>$BASH_SOURCE</code> refers to the running script (as invoked), and <code>$@</code> is the array of arguments; <code>(($#)) &amp;&amp;</code> ensures that the following <...
58, 387, 390
bash, linux, shell
<h1>How to get the complete calling command of a BASH script from inside the script (not just the arguments)</h1> <p>I have a BASH script that has a long set of arguments and two ways of calling it: </p> <pre><code>my_script --option1 value --option2 value ... etc </code></pre> <p>or </p> <pre><code>my_script val...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,377
bash
# How to get the complete calling command of a BASH script from inside the script (not just the arguments) I have a BASH script that has a long set of arguments and two ways of calling it: ``` my_script --option1 value --option2 value ... etc ``` or ``` my_script val1 val2 val3 ..... valn ``` This script in turn...
You can try the following: ``` myInvocation="$(printf %q "$BASH_SOURCE")$((($#)) && printf ' %q' "$@")" ``` `$BASH_SOURCE` refers to the running script (as invoked), and `$@` is the array of arguments; `(($#)) &&` ensures that the following `printf` command is only executed if at least 1 argument was passed; `printf ...
36346817
Powershell "private" scope seems not useful at all
8
2016-04-01 02:01:24
<p>I've got the script below, from internet:</p> <pre><code>$private:a = 1 Function test { "variable a contains $a" $a = 2 "variable a contains $a" } test </code></pre> <p>It prints 2. No problem. If I delete "private", like below:</p> <pre><code>$a = 1 Function test { "variable a contains $a" ...
9,316
4,927,124
2022-11-12 21:10:12
36,352,633
15
2016-04-01 09:26:20
4,003,407
2016-04-01 14:49:06
https://stackoverflow.com/q/36346817
https://stackoverflow.com/a/36352633
<p>Private scope can be useful when writing a function that invokes a user-supplied callback. Consider this simple example:</p> <pre><code>filter Where-Name { param( [ScriptBlock]$Condition ) $FirstName, $LastName = $_ -split ' ' if(&amp;$Condition $FirstName $LastName) { $_ } } </c...
<p>Private scope can be useful when writing a function that invokes a user-supplied callback. Consider this simple example:</p> <pre><code>filter Where-Name { param( [ScriptBlock]$Condition ) $FirstName, $LastName = $_ -split ' ' if(&amp;$Condition $FirstName $LastName) { $_ } } </c...
526, 2182, 4943
powershell, private, scope
<h1>Powershell "private" scope seems not useful at all</h1> <p>I've got the script below, from internet:</p> <pre><code>$private:a = 1 Function test { "variable a contains $a" $a = 2 "variable a contains $a" } test </code></pre> <p>It prints 2. No problem. If I delete "private", like below:</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
9,378
bash
# Powershell "private" scope seems not useful at all I've got the script below, from internet: ``` $private:a = 1 Function test { "variable a contains $a" $a = 2 "variable a contains $a" } test ``` It prints 2. No problem. If I delete "private", like below: ``` $a = 1 Function test { "variable a c...
Private scope can be useful when writing a function that invokes a user-supplied callback. Consider this simple example: ``` filter Where-Name { param( [ScriptBlock]$Condition ) $FirstName, $LastName = $_ -split ' ' if(&$Condition $FirstName $LastName) { $_ } } ``` Then, if someone...
34246819
"sh: : unknown operand" in Yocto
8
2015-12-13 00:52:19
<p>The following works in Ubuntu but not Yocto (Poky).</p> <pre><code>root@system:~/# x='abc' root@system:~/# y='' root@system:~/# [[ $(echo $x) != '' ]] &amp;&amp; echo true true root@system:~/# [[ $(echo $y) != '' ]] &amp;&amp; echo true sh: : unknown operand </code></pre> <p>In Ubuntu the last line returns nothing...
44,860
1,156,245
2015-12-13 16:23:54
34,251,849
15
2015-12-13 13:53:32
4,687,135
2015-12-13 13:53:32
https://stackoverflow.com/q/34246819
https://stackoverflow.com/a/34251849
<p>The problem seems to be that <code>$(echo $y)</code> is expanding to an empty string, and then <code>[[</code> isn't handling it correctly. The solution to that would be to quote the command substitution like</p> <pre><code>[[ "$(echo "$y")" != '' ]] &amp;&amp; echo true </code></pre> <p>though it's probably bett...
<p>The problem seems to be that <code>$(echo $y)</code> is expanding to an empty string, and then <code>[[</code> isn't handling it correctly. The solution to that would be to quote the command substitution like</p> <pre><code>[[ "$(echo "$y")" != '' ]] &amp;&amp; echo true </code></pre> <p>though it's probably bett...
390, 104267
shell, yocto
<h1>"sh: : unknown operand" in Yocto</h1> <p>The following works in Ubuntu but not Yocto (Poky).</p> <pre><code>root@system:~/# x='abc' root@system:~/# y='' root@system:~/# [[ $(echo $x) != '' ]] &amp;&amp; echo true true root@system:~/# [[ $(echo $y) != '' ]] &amp;&amp; echo true sh: : unknown operand </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,379
bash
# "sh: : unknown operand" in Yocto The following works in Ubuntu but not Yocto (Poky). ``` root@system:~/# x='abc' root@system:~/# y='' root@system:~/# [[ $(echo $x) != '' ]] && echo true true root@system:~/# [[ $(echo $y) != '' ]] && echo true sh: : unknown operand ``` In Ubuntu the last line returns nothing (as ex...
The problem seems to be that `$(echo $y)` is expanding to an empty string, and then `[[` isn't handling it correctly. The solution to that would be to quote the command substitution like ``` [[ "$(echo "$y")" != '' ]] && echo true ``` though it's probably better still to use [printf than echo](https://unix.stackexcha...
32169795
Git for Windows, run git bash without mintty?
8
2015-08-23 18:05:33
<p>After upgrading my PC to Windows 10 and doing a reset, I had to redownload all of my programs. When I downloaded Git for Windows, it came with a newer version compared to what I used before. This version looks to use mintty for the terminal, which doesn't seem to support using arrow keys to scroll through options ...
11,461
1,795,832
2016-02-23 07:17:11
32,328,351
15
2015-09-01 09:43:11
1,539,872
2015-09-01 09:43:11
https://stackoverflow.com/q/32169795
https://stackoverflow.com/a/32328351
<p>I'm using <a href="http://sourceforge.net/projects/console/">console2</a> to display my different <code>cmd.exe</code> and <code>bash</code> windows in tabs, so I ran into the same problem. The way I solved it was to call <code>cmd.exe</code> and have it launch the git <code>bash</code>. That seems to do the trick...
<p>I'm using <a href="http://sourceforge.net/projects/console/">console2</a> to display my different <code>cmd.exe</code> and <code>bash</code> windows in tabs, so I ran into the same problem. The way I solved it was to call <code>cmd.exe</code> and have it launch the git <code>bash</code>. That seems to do the trick...
119, 61874
git, git-bash
<h1>Git for Windows, run git bash without mintty?</h1> <p>After upgrading my PC to Windows 10 and doing a reset, I had to redownload all of my programs. When I downloaded Git for Windows, it came with a newer version compared to what I used before. This version looks to use mintty for the terminal, which doesn't seem...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,380
bash
# Git for Windows, run git bash without mintty? After upgrading my PC to Windows 10 and doing a reset, I had to redownload all of my programs. When I downloaded Git for Windows, it came with a newer version compared to what I used before. This version looks to use mintty for the terminal, which doesn't seem to support...
I'm using [console2](http://sourceforge.net/projects/console/) to display my different `cmd.exe` and `bash` windows in tabs, so I ran into the same problem. The way I solved it was to call `cmd.exe` and have it launch the git `bash`. That seems to do the trick for me. So configure your tool(s) to use a shell like that:...
30452699
make bash script display system event dialog, then take its result and use it in an if statement
8
2015-05-26 07:54:16
<p>I'm on macOS. I have a script that, after asking for confirmation using <code>read</code> in Terminal, uses <code>grep</code> to check whether /dev/disk1 is mounted, then formats that disk. That's a dangerous script, hence why asking if it's okay first is vital.</p> <p>Eventually, I would like to have this script b...
8,027
4,939,413
2018-06-27 07:02:40
30,464,956
15
2015-05-26 17:16:59
438,157
2015-05-26 17:16:59
https://stackoverflow.com/q/30452699
https://stackoverflow.com/a/30464956
<p>Yes, it is possible in bash to take the output of an osascript dialog. Here’s an example with a Yes/No dialog box:</p> <pre><code>#!/bin/bash SURETY="$(osascript -e 'display dialog "Are you sure you want to partition this disk?" buttons {"Yes", "No"} default button "No"')" if [ "$SURETY" = "button returned:Yes" ]...
<p>Yes, it is possible in bash to take the output of an osascript dialog. Here’s an example with a Yes/No dialog box:</p> <pre><code>#!/bin/bash SURETY="$(osascript -e 'display dialog "Are you sure you want to partition this disk?" buttons {"Yes", "No"} default button "No"')" if [ "$SURETY" = "button returned:Yes" ]...
369, 387, 390, 1243
applescript, bash, macos, shell
<h1>make bash script display system event dialog, then take its result and use it in an if statement</h1> <p>I'm on macOS. I have a script that, after asking for confirmation using <code>read</code> in Terminal, uses <code>grep</code> to check whether /dev/disk1 is mounted, then formats that disk. That's a dangerous sc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,381
bash
# make bash script display system event dialog, then take its result and use it in an if statement I'm on macOS. I have a script that, after asking for confirmation using `read` in Terminal, uses `grep` to check whether /dev/disk1 is mounted, then formats that disk. That's a dangerous script, hence why asking if it's ...
Yes, it is possible in bash to take the output of an osascript dialog. Here’s an example with a Yes/No dialog box: ``` #!/bin/bash SURETY="$(osascript -e 'display dialog "Are you sure you want to partition this disk?" buttons {"Yes", "No"} default button "No"')" if [ "$SURETY" = "button returned:Yes" ]; then ech...
29119383
PowerShell use regular expression to split a string
8
2015-03-18 10:19:19
<p>This is my code:</p> <pre><code>[regex]::split("1,2 3", '(,|\s)+') </code></pre> <p>What I want is an array with three elements <code>1, 2, 3</code>, however, what I got it is an array with five elements.</p> <pre><code>PS C:\Users\a&gt; [regex]::split("1,2 3", '(,|\s)+').Length 5 PS C:\Users\a&gt; </code></p...
48,732
170,931
2022-01-31 04:11:49
29,120,112
15
2015-03-18 10:54:36
3,829,407
2020-05-04 22:11:08
https://stackoverflow.com/q/29119383
https://stackoverflow.com/a/29120112
<p>In PowerShell when you use a <code>-split</code> function if you have part of the match in brackets <code>()</code> you are asking for that match to be returned as well. I am sure that the same is true with the static method of <code>[regex]</code> as well. Consider the output from the two following commands (which ...
<p>In PowerShell when you use a <code>-split</code> function if you have part of the match in brackets <code>()</code> you are asking for that match to be returned as well. I am sure that the same is true with the static method of <code>[regex]</code> as well. Consider the output from the two following commands (which ...
18, 526, 2193
powershell, regex, split
<h1>PowerShell use regular expression to split a string</h1> <p>This is my code:</p> <pre><code>[regex]::split("1,2 3", '(,|\s)+') </code></pre> <p>What I want is an array with three elements <code>1, 2, 3</code>, however, what I got it is an array with five elements.</p> <pre><code>PS C:\Users\a&gt; [regex]::spli...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,382
bash
# PowerShell use regular expression to split a string This is my code: ``` [regex]::split("1,2 3", '(,|\s)+') ``` What I want is an array with three elements `1, 2, 3`, however, what I got it is an array with five elements. ``` PS C:\Users\a> [regex]::split("1,2 3", '(,|\s)+').Length 5 PS C:\Users\a> ``` How t...
In PowerShell when you use a `-split` function if you have part of the match in brackets `()` you are asking for that match to be returned as well. I am sure that the same is true with the static method of `[regex]` as well. Consider the output from the two following commands (which are similar to yours) and you will s...
28966977
Get only the drive letter from a path in PowerShell
8
2015-03-10 14:55:56
<p>I want to make a script in PowerShell to help easily translate a path like this:</p> <pre><code>H:\MyDoc.docx </code></pre> <p>Into its true absolute path, like this:</p> <pre><code>\\FileServer\UserShares\Organization\Department\Me\MyDoc.docx </code></pre> <p>In this case, I've created a network drive mapping o...
28,059
477,682
2017-08-09 17:03:19
28,967,236
15
2015-03-10 15:06:57
3,115,685
2015-03-10 15:14:40
https://stackoverflow.com/q/28966977
https://stackoverflow.com/a/28967236
<p>You could use the <code>PSDrive</code> property of the FileInfo object:</p> <pre><code>(Get-Item .\your\path\to\file.ext).PSDrive.Name </code></pre>
<p>You could use the <code>PSDrive</code> property of the FileInfo object:</p> <pre><code>(Get-Item .\your\path\to\file.ext).PSDrive.Name </code></pre>
526
powershell
<h1>Get only the drive letter from a path in PowerShell</h1> <p>I want to make a script in PowerShell to help easily translate a path like this:</p> <pre><code>H:\MyDoc.docx </code></pre> <p>Into its true absolute path, like this:</p> <pre><code>\\FileServer\UserShares\Organization\Department\Me\MyDoc.docx </code></...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,383
bash
# Get only the drive letter from a path in PowerShell I want to make a script in PowerShell to help easily translate a path like this: ``` H:\MyDoc.docx ``` Into its true absolute path, like this: ``` \\FileServer\UserShares\Organization\Department\Me\MyDoc.docx ``` In this case, I've created a network drive mappi...
You could use the `PSDrive` property of the FileInfo object: ``` (Get-Item .\your\path\to\file.ext).PSDrive.Name ```
27356095
How can I stop the Powershell command `Get-NetFirewallRule` from throwing an error?
8
2014-12-08 10:39:30
<p>I'm trying to determine if a firewall rule exists or not, with Powershell.</p> <p>If the rule does <em>not</em> exist, I get an ugly error message. If it does exist, all is good :)</p> <p>How can I check if the rule exists without any ugly red error message occuring?</p> <p>eg.</p> <pre><code>Import-Module NetSe...
5,015
30,674
2014-12-08 10:51:15
27,356,180
15
2014-12-08 10:44:01
3,115,685
2014-12-08 10:51:15
https://stackoverflow.com/q/27356095
https://stackoverflow.com/a/27356180
<p>Populate the <code>-ErrorAction</code> parameter for the cmdlet</p> <p><code>Get-NetFirewallRule -DisplayName $name -ErrorAction SilentlyContinue</code></p> <p>At this point you can test the result of the last command using <code>$?</code>. If the rule exists, this will return <code>$true</code>.</p> <p>Alternati...
<p>Populate the <code>-ErrorAction</code> parameter for the cmdlet</p> <p><code>Get-NetFirewallRule -DisplayName $name -ErrorAction SilentlyContinue</code></p> <p>At this point you can test the result of the last command using <code>$?</code>. If the rule exists, this will return <code>$true</code>.</p> <p>Alternati...
526, 2045
firewall, powershell
<h1>How can I stop the Powershell command `Get-NetFirewallRule` from throwing an error?</h1> <p>I'm trying to determine if a firewall rule exists or not, with Powershell.</p> <p>If the rule does <em>not</em> exist, I get an ugly error message. If it does exist, all is good :)</p> <p>How can I check if the rule exists...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,384
bash
# How can I stop the Powershell command `Get-NetFirewallRule` from throwing an error? I'm trying to determine if a firewall rule exists or not, with Powershell. If the rule does *not* exist, I get an ugly error message. If it does exist, all is good :) How can I check if the rule exists without any ugly red error me...
Populate the `-ErrorAction` parameter for the cmdlet `Get-NetFirewallRule -DisplayName $name -ErrorAction SilentlyContinue` At this point you can test the result of the last command using `$?`. If the rule exists, this will return `$true`. Alternatively, you can use a try / catch block: ``` try { Get-NetFirewallR...
25732814
PowerShell can't use the matching enum type?
8
2014-09-08 20:39:44
<p>Am I doing something stupid here?</p> <p>I specify that a function takes a particular enum type as an argument:</p> <pre><code>PS&gt; add-type -AssemblyName System.ServiceProcess PS&gt; function test([System.ServiceProcess.ServiceControllerStatus]$x) { Write-host $x $x.gettype() } </code></pre> <p>The type is mos...
7,807
1,394,393
2020-08-31 19:10:25
25,733,351
15
2014-09-08 21:25:00
2,797,457
2020-08-31 19:10:25
https://stackoverflow.com/q/25732814
https://stackoverflow.com/a/25733351
<p>You are running into a small gotcha regarding parsing modes. You can put parens around the argument and it will work:</p> <pre><code>test ([System.ServiceProcess.ServiceControllerStatus]::Stopped) </code></pre> <p>Alternatively, conversions from string to enum happen naturally, so you could write:</p> <pre><code>te...
<p>You are running into a small gotcha regarding parsing modes. You can put parens around the argument and it will work:</p> <pre><code>test ([System.ServiceProcess.ServiceControllerStatus]::Stopped) </code></pre> <p>Alternatively, conversions from string to enum happen naturally, so you could write:</p> <pre><code>te...
360, 526, 1078, 1926
enums, parameters, powershell, types
<h1>PowerShell can't use the matching enum type?</h1> <p>Am I doing something stupid here?</p> <p>I specify that a function takes a particular enum type as an argument:</p> <pre><code>PS&gt; add-type -AssemblyName System.ServiceProcess PS&gt; function test([System.ServiceProcess.ServiceControllerStatus]$x) { Write-ho...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,385
bash
# PowerShell can't use the matching enum type? Am I doing something stupid here? I specify that a function takes a particular enum type as an argument: ``` PS> add-type -AssemblyName System.ServiceProcess PS> function test([System.ServiceProcess.ServiceControllerStatus]$x) { Write-host $x $x.gettype() } ``` The typ...
You are running into a small gotcha regarding parsing modes. You can put parens around the argument and it will work: ``` test ([System.ServiceProcess.ServiceControllerStatus]::Stopped) ``` Alternatively, conversions from string to enum happen naturally, so you could write: ``` test Stopped ``` Here are a couple go...
25062341
How to run multiple jar files at once using shell script?
8
2014-07-31 15:01:31
<p><a href="https://stackoverflow.com/questions/14554786/batch-script-run-multiple-jar-files-at-once/14556024#14556024">Similar question</a> related to Batch script has an answer. But I need same in shell script.</p>
14,846
3,485,172
2019-09-17 11:44:42
25,062,541
15
2014-07-31 15:08:58
1,174,332
2014-07-31 15:08:58
https://stackoverflow.com/q/25062341
https://stackoverflow.com/a/25062541
<p>Just launch your jar adding a &amp; at the end Example : </p> <pre><code>#!/bin/bash java -jar myjar1.jar &amp; java -jar myjar2.jar &amp; java -jar myjar3.jar &amp; </code></pre> <p>If you want the jar keep running after closing the terminal, use nohup : </p> <pre><code>#!/bin/bash nohup java -jar myjar1.jar &...
<p>Just launch your jar adding a &amp; at the end Example : </p> <pre><code>#!/bin/bash java -jar myjar1.jar &amp; java -jar myjar2.jar &amp; java -jar myjar3.jar &amp; </code></pre> <p>If you want the jar keep running after closing the terminal, use nohup : </p> <pre><code>#!/bin/bash nohup java -jar myjar1.jar &...
390, 7002
batch-file, shell
<h1>How to run multiple jar files at once using shell script?</h1> <p><a href="https://stackoverflow.com/questions/14554786/batch-script-run-multiple-jar-files-at-once/14556024#14556024">Similar question</a> related to Batch script has an answer. But I need same in shell script.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,386
bash
# How to run multiple jar files at once using shell script? [Similar question](https://stackoverflow.com/questions/14554786/batch-script-run-multiple-jar-files-at-once/14556024#14556024) related to Batch script has an answer. But I need same in shell script.
Just launch your jar adding a & at the end Example : ``` #!/bin/bash java -jar myjar1.jar & java -jar myjar2.jar & java -jar myjar3.jar & ``` If you want the jar keep running after closing the terminal, use nohup : ``` #!/bin/bash nohup java -jar myjar1.jar & nohup java -jar myjar2.jar & nohup java -jar myjar3.jar...
24102663
How do I use bash to bulk add a file full of IP blocks to IPTables
8
2014-06-08 03:16:53
<p>How can I bulk add a text file full of IP blocks to IPTables using BASH (or another scripting language)? Or is there some other way of blocking these address ranges?</p> <p>EDIT: In other words is there a way to program something to iterate through the file and build the relevant entries? </p>
5,770
1,499,072
2016-01-07 21:25:51
24,102,703
15
2014-06-08 03:23:39
1,347,170
2014-06-08 03:23:39
https://stackoverflow.com/q/24102663
https://stackoverflow.com/a/24102703
<p>Could you just create a loop within your iptables config script? Something like</p> <pre><code>#!/bin/bash for x in $(cat ip_list.txt) do iptables -A INPUT -s $x -j DROP done </code></pre> <p>Where your <code>ip_list.txt</code> file would just look like</p> <pre><code>1.1.1.1 2.2.2.2 3.3.3.3 etc </code></pre>...
<p>Could you just create a loop within your iptables config script? Something like</p> <pre><code>#!/bin/bash for x in $(cat ip_list.txt) do iptables -A INPUT -s $x -j DROP done </code></pre> <p>Where your <code>ip_list.txt</code> file would just look like</p> <pre><code>1.1.1.1 2.2.2.2 3.3.3.3 etc </code></pre>...
387, 5431
bash, iptables
<h1>How do I use bash to bulk add a file full of IP blocks to IPTables</h1> <p>How can I bulk add a text file full of IP blocks to IPTables using BASH (or another scripting language)? Or is there some other way of blocking these address ranges?</p> <p>EDIT: In other words is there a way to program something to iterate...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,387
bash
# How do I use bash to bulk add a file full of IP blocks to IPTables How can I bulk add a text file full of IP blocks to IPTables using BASH (or another scripting language)? Or is there some other way of blocking these address ranges? EDIT: In other words is there a way to program something to iterate through the fil...
Could you just create a loop within your iptables config script? Something like ``` #!/bin/bash for x in $(cat ip_list.txt) do iptables -A INPUT -s $x -j DROP done ``` Where your `ip_list.txt` file would just look like ``` 1.1.1.1 2.2.2.2 3.3.3.3 etc ```
23441994
truncate table via command line in Linux
8
2014-05-03 08:27:54
<p>I want to truncate one of my db table using mysqldump command so that I can place that command in sh file for executing it on daily basis. Do any one know about this command? Thanks in advance</p>
13,799
2,042,759
2019-08-20 15:38:37
23,442,043
15
2014-05-03 08:33:29
1,767,938
2014-05-03 08:33:29
https://stackoverflow.com/q/23441994
https://stackoverflow.com/a/23442043
<p>You can use mysql command line client to do it</p> <pre><code>mysql -h dbserver_hostname -e "truncate table schema_name.table_name" </code></pre>
<p>You can use mysql command line client to do it</p> <pre><code>mysql -h dbserver_hostname -e "truncate table schema_name.table_name" </code></pre>
21, 58, 10327
linux, mysql, sh
<h1>truncate table via command line in Linux</h1> <p>I want to truncate one of my db table using mysqldump command so that I can place that command in sh file for executing it on daily basis. Do any one know about this command? Thanks in advance</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,388
bash
# truncate table via command line in Linux I want to truncate one of my db table using mysqldump command so that I can place that command in sh file for executing it on daily basis. Do any one know about this command? Thanks in advance
You can use mysql command line client to do it ``` mysql -h dbserver_hostname -e "truncate table schema_name.table_name" ```
22797530
How to print #!/bin/bash using echo command
8
2014-04-01 21:46:27
<p>I have tried the escape character but it doesn't seems works with <strong>!</strong>. I need this to auto-configure packages using scripts.</p>
21,239
2,828,681
2014-04-02 07:11:32
22,797,555
15
2014-04-01 21:48:18
1,899,640
2014-04-01 21:48:18
https://stackoverflow.com/q/22797530
https://stackoverflow.com/a/22797555
<p><code>!</code> is magic in a default interactive bash session, but not in scripts (<code>set +H</code> to disable in an interactive prompt). In any case:</p> <pre><code>echo '#!/bin/bash' </code></pre>
<p><code>!</code> is magic in a default interactive bash session, but not in scripts (<code>set +H</code> to disable in an interactive prompt). In any case:</p> <pre><code>echo '#!/bin/bash' </code></pre>
387, 390, 1796, 4804, 13824
bash, command, echo, escaping, shell
<h1>How to print #!/bin/bash using echo command</h1> <p>I have tried the escape character but it doesn't seems works with <strong>!</strong>. I need this to auto-configure packages using scripts.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,389
bash
# How to print #!/bin/bash using echo command I have tried the escape character but it doesn't seems works with **!**. I need this to auto-configure packages using scripts.
`!` is magic in a default interactive bash session, but not in scripts (`set +H` to disable in an interactive prompt). In any case: ``` echo '#!/bin/bash' ```
22574201
Running python script as root
8
2014-03-22 06:20:34
<p>I have the following script:</p> <pre><code>#!/usr/bin/env python import sys import pyttsx def main(): ...
105,526
1,190,419
2023-10-10 17:10:56
22,574,300
15
2014-03-22 06:32:01
641,955
2019-08-22 04:20:49
https://stackoverflow.com/q/22574201
https://stackoverflow.com/a/22574300
<p>So you want the script to run as <code>root</code>, even without <code>sudo</code>? For that you would need to set the <em>setuid bit</em> on the script with <code>sudo chmod u+s program</code>. However, most Unix distributions allow this only for binaries, and not for scripts, for security reasons. In general it's ...
<p>So you want the script to run as <code>root</code>, even without <code>sudo</code>? For that you would need to set the <em>setuid bit</em> on the script with <code>sudo chmod u+s program</code>. However, most Unix distributions allow this only for binaries, and not for scripts, for security reasons. In general it's ...
16, 390, 10824, 12079
alsa, python, root, shell
<h1>Running python script as root</h1> <p>I have the following script:</p> <pre><code>#!/usr/bin/env python import sys import pyttsx ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,390
bash
# Running python script as root I have the following script: ``` #!/usr/bin/env python import sys import pyttsx def main...
So you want the script to run as `root`, even without `sudo`? For that you would need to set the *setuid bit* on the script with `sudo chmod u+s program`. However, most Unix distributions allow this only for binaries, and not for scripts, for security reasons. In general it's really not a good idea to do that. If you ...
21342094
How Can I calculate the sum of a specific column using bash?
8
2014-01-24 20:40:31
<p>I want to calculate the sum of a specific column using bash without using the print that specific column (I want to keep all the output columns of my pipeline and only sum one of them!)</p>
22,803
1,080,684
2016-06-14 11:29:13
21,342,227
15
2014-01-24 20:48:32
3,030,305
2014-01-24 20:48:32
https://stackoverflow.com/q/21342094
https://stackoverflow.com/a/21342227
<p>If you wanted to sum over, say, the second column, but print all columns in some pipeline:</p> <pre><code>cat data | awk '{sum+=$2 ; print $0} END{print "sum=",sum}' </code></pre> <p>If the file data looks like:</p> <pre><code>1 2 3 4 5 6 7 8 9 </code></pre> <p>Then the output would be:</p> <pre><code>1 2 3 4 5...
<p>If you wanted to sum over, say, the second column, but print all columns in some pipeline:</p> <pre><code>cat data | awk '{sum+=$2 ; print $0} END{print "sum=",sum}' </code></pre> <p>If the file data looks like:</p> <pre><code>1 2 3 4 5 6 7 8 9 </code></pre> <p>Then the output would be:</p> <pre><code>1 2 3 4 5...
387, 4928
bash, sum
<h1>How Can I calculate the sum of a specific column using bash?</h1> <p>I want to calculate the sum of a specific column using bash without using the print that specific column (I want to keep all the output columns of my pipeline and only sum one of them!)</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,391
bash
# How Can I calculate the sum of a specific column using bash? I want to calculate the sum of a specific column using bash without using the print that specific column (I want to keep all the output columns of my pipeline and only sum one of them!)
If you wanted to sum over, say, the second column, but print all columns in some pipeline: ``` cat data | awk '{sum+=$2 ; print $0} END{print "sum=",sum}' ``` If the file data looks like: ``` 1 2 3 4 5 6 7 8 9 ``` Then the output would be: ``` 1 2 3 4 5 6 7 8 9 sum= 15 ```
17747864
how can I use linux command sed to process Little-endian UTF-16 file
8
2013-07-19 13:53:05
<p>I am working on an application about windows rdp. Now I get a problem when I try to use the sed command to replace the string of IP address directly in the rdp file. But after executing this command, the origin rdp file is garbled. </p> <pre><code>sed -i "s/address:s:.*/address:s:$(cat check-free-ip.to.rdpzhitong.r...
7,070
2,576,093
2013-07-22 11:18:03
17,786,213
15
2013-07-22 11:18:03
733,345
2013-07-22 11:18:03
https://stackoverflow.com/q/17747864
https://stackoverflow.com/a/17786213
<p>If the file is UTF-16 encoded text (as <a href="http://msdn.microsoft.com/en-us/library/ms861803.aspx">RDP is</a>), and that is not your current encoding (it's not likely to be on Linux) then you can pre- and post-process the file with <code>iconv</code>. For example:</p> <pre><code>iconv -f utf-16 -t us-ascii &lt;...
<p>If the file is UTF-16 encoded text (as <a href="http://msdn.microsoft.com/en-us/library/ms861803.aspx">RDP is</a>), and that is not your current encoding (it's not likely to be on Linux) then you can pre- and post-process the file with <code>iconv</code>. For example:</p> <pre><code>iconv -f utf-16 -t us-ascii &lt;...
390, 10016, 11692
endianness, shell, utf-16
<h1>how can I use linux command sed to process Little-endian UTF-16 file</h1> <p>I am working on an application about windows rdp. Now I get a problem when I try to use the sed command to replace the string of IP address directly in the rdp file. But after executing this command, the origin rdp file is garbled. </p> <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,392
bash
# how can I use linux command sed to process Little-endian UTF-16 file I am working on an application about windows rdp. Now I get a problem when I try to use the sed command to replace the string of IP address directly in the rdp file. But after executing this command, the origin rdp file is garbled. ``` sed -i "s/a...
If the file is UTF-16 encoded text (as [RDP is](http://msdn.microsoft.com/en-us/library/ms861803.aspx)), and that is not your current encoding (it's not likely to be on Linux) then you can pre- and post-process the file with `iconv`. For example: ``` iconv -f utf-16 -t us-ascii <rdpzhitong.rdp | sed 's/original/modif...
17628867
solve $1: ambiguous redirect
8
2013-07-13 09:34:52
<p>I'm using this script to backup an old private instance of postgresql to gmail periodically:</p> <pre><code>#!/bin/bash /opt/local/lib/postgresql83/bin/pg_dump maxgests -U postgres | gzip --best -c &gt; $1 &amp;&amp; (/opt/local/bin/mutt -s `date "+%d-%m-%Y-%H:%M"` -a $1 $2 &lt; /dev/null) </code></pre> <p>As of l...
39,878
2,448,104
2013-07-13 09:40:42
17,628,906
15
2013-07-13 09:38:47
874,188
2013-07-13 09:38:47
https://stackoverflow.com/q/17628867
https://stackoverflow.com/a/17628906
<p><code>$1</code> is apparently empty.</p> <p>As a general guidance, you should put your variable interpolations in double quotes, nearly always.</p>
<p><code>$1</code> is apparently empty.</p> <p>As a general guidance, you should put your variable interpolations in double quotes, nearly always.</p>
387
bash
<h1>solve $1: ambiguous redirect</h1> <p>I'm using this script to backup an old private instance of postgresql to gmail periodically:</p> <pre><code>#!/bin/bash /opt/local/lib/postgresql83/bin/pg_dump maxgests -U postgres | gzip --best -c &gt; $1 &amp;&amp; (/opt/local/bin/mutt -s `date "+%d-%m-%Y-%H:%M"` -a $1 $2 &lt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,393
bash
# solve $1: ambiguous redirect I'm using this script to backup an old private instance of postgresql to gmail periodically: ``` #!/bin/bash /opt/local/lib/postgresql83/bin/pg_dump maxgests -U postgres | gzip --best -c > $1 && (/opt/local/bin/mutt -s `date "+%d-%m-%Y-%H:%M"` -a $1 $2 < /dev/null) ``` As of late I'm g...
`$1` is apparently empty. As a general guidance, you should put your variable interpolations in double quotes, nearly always.
16597342
bash test for yum or apt based linux
8
2013-05-16 20:57:41
<p>Simple question -- what's the canonical way to test in bash whether yum or apt-get are present? I'm writing a script that will run on client machines and install unison, then create a cron job for it ... </p>
6,899
362,808
2014-07-27 15:35:20
16,597,499
15
2013-05-16 21:07:18
2,327,476
2013-05-16 21:16:58
https://stackoverflow.com/q/16597342
https://stackoverflow.com/a/16597499
<p>With bash script (or sh, zsh, ksh) you could use the builtin <code>command -v yum</code> and <code>command -v apt-get</code>.<br> (yes, the command is named command)</p> <p>Zero output means it isn't there, otherwise you get the commands path.</p> <p>You could then use a test statement to test whether the result w...
<p>With bash script (or sh, zsh, ksh) you could use the builtin <code>command -v yum</code> and <code>command -v apt-get</code>.<br> (yes, the command is named command)</p> <p>Zero output means it isn't there, otherwise you get the commands path.</p> <p>You could then use a test statement to test whether the result w...
387, 7425, 16113
apt-get, bash, yum
<h1>bash test for yum or apt based linux</h1> <p>Simple question -- what's the canonical way to test in bash whether yum or apt-get are present? I'm writing a script that will run on client machines and install unison, then create a cron job for it ... </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,394
bash
# bash test for yum or apt based linux Simple question -- what's the canonical way to test in bash whether yum or apt-get are present? I'm writing a script that will run on client machines and install unison, then create a cron job for it ...
With bash script (or sh, zsh, ksh) you could use the builtin `command -v yum` and `command -v apt-get`. (yes, the command is named command) Zero output means it isn't there, otherwise you get the commands path. You could then use a test statement to test whether the result was null or not. ``` [ -n "$(command -v y...
16322792
'tail -f' doesn't give single lines when piped through grep'
8
2013-05-01 17:03:13
<p>I am launching a website, and I wanted to setup a Bash one-liner so when someone hits the site it would make a beep using the internal buzzer.</p> <p>So far it's working using the following.</p> <pre><code>tail -f access_log | while read x ; do echo -ne '\007' $x '\n' ; done </code></pre> <p>Tail follows the acce...
1,657
683,017
2022-10-24 15:52:50
16,322,840
15
2013-05-01 17:05:56
68,587
2013-05-01 17:05:56
https://stackoverflow.com/q/16322792
https://stackoverflow.com/a/16322840
<p>Grep's output is buffered when it's used in a pipe. Use <code>--line-buffered</code> to force it to use line buffering so it outputs lines immediately.</p> <pre><code>tail -f access_log | grep --line-buffered "/index.php" | while read x ; do echo -ne '\007' $x '\n' ; done </code></pre> <p>You could also combine th...
<p>Grep's output is buffered when it's used in a pipe. Use <code>--line-buffered</code> to force it to use line buffering so it outputs lines immediately.</p> <pre><code>tail -f access_log | grep --line-buffered "/index.php" | while read x ; do echo -ne '\007' $x '\n' ; done </code></pre> <p>You could also combine th...
387
bash
<h1>'tail -f' doesn't give single lines when piped through grep'</h1> <p>I am launching a website, and I wanted to setup a Bash one-liner so when someone hits the site it would make a beep using the internal buzzer.</p> <p>So far it's working using the following.</p> <pre><code>tail -f access_log | while read x ; do ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,395
bash
# 'tail -f' doesn't give single lines when piped through grep' I am launching a website, and I wanted to setup a Bash one-liner so when someone hits the site it would make a beep using the internal buzzer. So far it's working using the following. ``` tail -f access_log | while read x ; do echo -ne '\007' $x '\n' ; d...
Grep's output is buffered when it's used in a pipe. Use `--line-buffered` to force it to use line buffering so it outputs lines immediately. ``` tail -f access_log | grep --line-buffered "/index.php" | while read x ; do echo -ne '\007' $x '\n' ; done ``` You could also combine the `grep` and `while` loop into a singl...
14629121
Bash split string
8
2013-01-31 15:19:56
<p>I have the following data in array:</p> <pre><code>MY_ARR[0]="./path/path2/name.exe 'word1 word2' 'name1,name2'" MY_ARR[1]="./path/path2/name.exe 'word1 word2' 'name3,name4,name5'" MY_ARR[2]=".name.exe 'word1 word2'" MY_ARR[3]="name.exe" MY_ARR[4]="./path/path2/name.exe 'word1 word2' 'name1'" MY_ARR[5]="./path/pat...
21,901
1,109,014
2014-01-31 11:21:46
14,629,210
15
2013-01-31 15:25:05
1,983,854
2014-01-08 10:17:29
https://stackoverflow.com/q/14629121
https://stackoverflow.com/a/14629210
<p>It looks like the separator between the fields is an space. Hence, you can use <code>cut</code> to split them:</p> <pre><code>file=$(echo "${MY_ARR[1]}" | cut -d' ' -f1) parameter=$(echo "${MY_ARR[1]}" | cut -d' ' -f2-) </code></pre> <ul> <li><code>-f1</code> means the first parameter.</li> <li><code>-f2-</code> m...
<p>It looks like the separator between the fields is an space. Hence, you can use <code>cut</code> to split them:</p> <pre><code>file=$(echo "${MY_ARR[1]}" | cut -d' ' -f1) parameter=$(echo "${MY_ARR[1]}" | cut -d' ' -f2-) </code></pre> <ul> <li><code>-f1</code> means the first parameter.</li> <li><code>-f2-</code> m...
139, 387, 990, 2193, 4257
awk, bash, cut, split, string
<h1>Bash split string</h1> <p>I have the following data in array:</p> <pre><code>MY_ARR[0]="./path/path2/name.exe 'word1 word2' 'name1,name2'" MY_ARR[1]="./path/path2/name.exe 'word1 word2' 'name3,name4,name5'" MY_ARR[2]=".name.exe 'word1 word2'" MY_ARR[3]="name.exe" MY_ARR[4]="./path/path2/name.exe 'word1 word2' 'na...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,397
bash
# Bash split string I have the following data in array: ``` MY_ARR[0]="./path/path2/name.exe 'word1 word2' 'name1,name2'" MY_ARR[1]="./path/path2/name.exe 'word1 word2' 'name3,name4,name5'" MY_ARR[2]=".name.exe 'word1 word2'" MY_ARR[3]="name.exe" MY_ARR[4]="./path/path2/name.exe 'word1 word2' 'name1'" MY_ARR[5]="./p...
It looks like the separator between the fields is an space. Hence, you can use `cut` to split them: ``` file=$(echo "${MY_ARR[1]}" | cut -d' ' -f1) parameter=$(echo "${MY_ARR[1]}" | cut -d' ' -f2-) ``` - `-f1` means the first parameter. - `-f2-` means everything from the second parameter.
14544636
Respect last line if it's not terminated with a new line char (\n) when using read
8
2013-01-27 05:11:28
<p>I have noticed for a while that <code>read</code> never actually reads the last line of a file if there is not, at the end of it, a "newline" character. This is understandable if one consider that, as long as there is not a "newline" character in a file, it is as if it contained 0 line (which is quite difficult to a...
10,480
2,002,452
2013-03-23 01:07:25
14,547,230
15
2013-01-27 12:19:35
990,363
2013-03-23 01:07:25
https://stackoverflow.com/q/14544636
https://stackoverflow.com/a/14547230
<p><code>read</code> does, in fact, read an unterminated line into the assigned var (<code>$REPLY</code> by default). It also returns false on such a line, which just means ‘end of file’; directly using its return value in the classic <code>while</code> loop thus skips that one last line. If you change the loop logic s...
<p><code>read</code> does, in fact, read an unterminated line into the assigned var (<code>$REPLY</code> by default). It also returns false on such a line, which just means ‘end of file’; directly using its return value in the classic <code>while</code> loop thus skips that one last line. If you change the loop logic s...
387, 390, 14334
bash, built-in, shell
<h1>Respect last line if it's not terminated with a new line char (\n) when using read</h1> <p>I have noticed for a while that <code>read</code> never actually reads the last line of a file if there is not, at the end of it, a "newline" character. This is understandable if one consider that, as long as there is not a "...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,398
bash
# Respect last line if it's not terminated with a new line char (\n) when using read I have noticed for a while that `read` never actually reads the last line of a file if there is not, at the end of it, a "newline" character. This is understandable if one consider that, as long as there is not a "newline" character i...
`read` does, in fact, read an unterminated line into the assigned var (`$REPLY` by default). It also returns false on such a line, which just means ‘end of file’; directly using its return value in the classic `while` loop thus skips that one last line. If you change the loop logic slightly, you can process non-new lin...
12286187
Explain this command: . ~/nvm/nvm.sh
8
2012-09-05 16:49:15
<p>I am by no means a novice user on Linux, but I just don't understand why one has to put . in front of this command:</p> <pre><code>. ~/nvm/nvm.sh </code></pre> <p>For those in the know, this is how to activate the nvm bash script (it allows for a virtual environment in the NodeJS universe). But if one does not put...
8,887
1,143,837
2012-12-15 06:44:32
12,286,198
15
2012-09-05 16:50:16
714,501
2012-12-15 06:44:32
https://stackoverflow.com/q/12286187
https://stackoverflow.com/a/12286198
<blockquote> <pre><code>. ~/nvm/nvm.sh </code></pre> </blockquote> <p>It asks the interpreter to interpret the script <strong>in the current process</strong>. In <code>bash</code> it's equivalent to:</p> <pre><code>source ~/nvm/nvm.sh </code></pre> <p>You need to execute a script in the current process if you want i...
<blockquote> <pre><code>. ~/nvm/nvm.sh </code></pre> </blockquote> <p>It asks the interpreter to interpret the script <strong>in the current process</strong>. In <code>bash</code> it's equivalent to:</p> <pre><code>source ~/nvm/nvm.sh </code></pre> <p>You need to execute a script in the current process if you want i...
58, 387, 81748
bash, linux, nvm
<h1>Explain this command: . ~/nvm/nvm.sh</h1> <p>I am by no means a novice user on Linux, but I just don't understand why one has to put . in front of this command:</p> <pre><code>. ~/nvm/nvm.sh </code></pre> <p>For those in the know, this is how to activate the nvm bash script (it allows for a virtual environment in...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,399
bash
# Explain this command: . ~/nvm/nvm.sh I am by no means a novice user on Linux, but I just don't understand why one has to put . in front of this command: ``` . ~/nvm/nvm.sh ``` For those in the know, this is how to activate the nvm bash script (it allows for a virtual environment in the NodeJS universe). But if one...
> ``` > . ~/nvm/nvm.sh > ``` It asks the interpreter to interpret the script **in the current process**. In `bash` it's equivalent to: ``` source ~/nvm/nvm.sh ``` You need to execute a script in the current process if you want it to change the environment (variables, et al). You can view more details with `help .` ...
12058705
A better way to do git clone
8
2012-08-21 15:54:50
<p>This is lazy programmer request. I would like to create a shell script automate the following process: </p> <pre><code>git clone &lt;remote-repo-url&gt; cd &lt;cloned-folder&gt; open &lt;cloned-folder&gt; </code></pre> <p>So the idea here is to clone a URL and then immediately <code>cd</code> into the <code>clone...
13,871
782,901
2020-11-03 11:20:00
12,059,200
15
2012-08-21 16:25:08
745
2012-08-21 16:25:08
https://stackoverflow.com/q/12058705
https://stackoverflow.com/a/12059200
<p>bash function to do this (works in zsh also):</p> <pre><code>function lazyclone { url=$1; reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//'); git clone $url $reponame; cd $reponame; } </code></pre> <p>The <code>awk</code> command prints the part after the last <code>/</code> (e.g fr...
<p>bash function to do this (works in zsh also):</p> <pre><code>function lazyclone { url=$1; reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//'); git clone $url $reponame; cd $reponame; } </code></pre> <p>The <code>awk</code> command prints the part after the last <code>/</code> (e.g fr...
119, 390, 1362
automation, git, shell
<h1>A better way to do git clone</h1> <p>This is lazy programmer request. I would like to create a shell script automate the following process: </p> <pre><code>git clone &lt;remote-repo-url&gt; cd &lt;cloned-folder&gt; open &lt;cloned-folder&gt; </code></pre> <p>So the idea here is to clone a URL and then immediatel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,400
bash
# A better way to do git clone This is lazy programmer request. I would like to create a shell script automate the following process: ``` git clone <remote-repo-url> cd <cloned-folder> open <cloned-folder> ``` So the idea here is to clone a URL and then immediately `cd` into the `cloned-folder`. The trick here is to...
bash function to do this (works in zsh also): ``` function lazyclone { url=$1; reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//'); git clone $url $reponame; cd $reponame; } ``` The `awk` command prints the part after the last `/` (e.g from `http://example.com/myrepo.git` to `myrepo.git...
11660962
Determine where a UNIX alias is defined
8
2012-07-26 01:07:32
<p>Is there a (somewhat) reliable way to get the 'origin' of a command, even if the command is an alias? For example, if I put this in my .bash_profile</p> <pre><code>alias lsa="ls -A" </code></pre> <p>and I wanted to know from the command-line where <code>lsa</code> is defined, is that possible? I know about the <co...
4,810
1,516,425
2016-09-06 07:09:06
11,660,985
15
2012-07-26 01:12:01
418,413
2013-08-30 21:40:37
https://stackoverflow.com/q/11660962
https://stackoverflow.com/a/11660985
<p>As Carl pointed out in his comment, <code>type</code> is the correct way to find out how a name is defined.</p> <pre class="lang-bash prettyprint-override"><code>mini:~ michael$ alias foo='echo bar' mini:~ michael$ biz() { echo bar; } mini:~ michael$ type foo foo is aliased to `echo bar' mini:~ michael$ type biz bi...
<p>As Carl pointed out in his comment, <code>type</code> is the correct way to find out how a name is defined.</p> <pre class="lang-bash prettyprint-override"><code>mini:~ michael$ alias foo='echo bar' mini:~ michael$ biz() { echo bar; } mini:~ michael$ type foo foo is aliased to `echo bar' mini:~ michael$ type biz bi...
34, 58, 387, 390
bash, linux, shell, unix
<h1>Determine where a UNIX alias is defined</h1> <p>Is there a (somewhat) reliable way to get the 'origin' of a command, even if the command is an alias? For example, if I put this in my .bash_profile</p> <pre><code>alias lsa="ls -A" </code></pre> <p>and I wanted to know from the command-line where <code>lsa</code> i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,401
bash
# Determine where a UNIX alias is defined Is there a (somewhat) reliable way to get the 'origin' of a command, even if the command is an alias? For example, if I put this in my .bash_profile ``` alias lsa="ls -A" ``` and I wanted to know from the command-line where `lsa` is defined, is that possible? I know about th...
As Carl pointed out in his comment, `type` is the correct way to find out how a name is defined. ``` mini:~ michael$ alias foo='echo bar' mini:~ michael$ biz() { echo bar; } mini:~ michael$ type foo foo is aliased to `echo bar' mini:~ michael$ type biz biz is a function biz () { echo bar } mini:~ michael$ type [...
10575005
Output a boolean from an Rscript into a Bash variable
8
2012-05-13 20:34:10
<p>I have an R script that outputs TRUE or FALSE. In R, it's using a bona fide T/F data type, but when I echo its return value to bash, it seems to be a string, saying:</p> <p><code>&quot;[1] TRUE&quot;</code></p> <p>or</p> <p><code>&quot;[1] FALSE&quot;</code></p> <p>They are both preceded by [1]. Neither is [0], th...
6,106
1,052,117
2022-01-10 17:35:07
10,575,091
15
2012-05-13 20:46:14
1,855,677
2012-05-16 19:45:15
https://stackoverflow.com/q/10575005
https://stackoverflow.com/a/10575091
<p>Instead of using either print() or the implicit print()-ing that occurs when an object name is offered to the R interpreter, you should be using <code>cat()</code> which will not prepend the "[1] " in front of either TRUE or FALSE. If you want 0/1, then use <code>cat(as.numeric(.))</code>. Try this instead:</p> <pr...
<p>Instead of using either print() or the implicit print()-ing that occurs when an object name is offered to the R interpreter, you should be using <code>cat()</code> which will not prepend the "[1] " in front of either TRUE or FALSE. If you want 0/1, then use <code>cat(as.numeric(.))</code>. Try this instead:</p> <pr...
387, 4452
bash, r
<h1>Output a boolean from an Rscript into a Bash variable</h1> <p>I have an R script that outputs TRUE or FALSE. In R, it's using a bona fide T/F data type, but when I echo its return value to bash, it seems to be a string, saying:</p> <p><code>&quot;[1] TRUE&quot;</code></p> <p>or</p> <p><code>&quot;[1] FALSE&quot;</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,402
bash
# Output a boolean from an Rscript into a Bash variable I have an R script that outputs TRUE or FALSE. In R, it's using a bona fide T/F data type, but when I echo its return value to bash, it seems to be a string, saying: `"[1] TRUE"` or `"[1] FALSE"` They are both preceded by [1]. Neither is [0], that is not a ty...
Instead of using either print() or the implicit print()-ing that occurs when an object name is offered to the R interpreter, you should be using `cat()` which will not prepend the "[1] " in front of either TRUE or FALSE. If you want 0/1, then use `cat(as.numeric(.))`. Try this instead: ``` myinput <- TRUE #or FALSE Fu...
10234872
Changing system proxy settings in Ubuntu 12.04 from terminal
8
2012-04-19 18:54:52
<p>I've been working in Ubuntu 12.04 and one of the things that I am trying to implement in a Bash script is modifying the proxy settings of the system. To clarify, this would be a script that sets up each VM that I make with the programs and packages that I need. I can find and edit the Proxy settings manually through...
31,189
1,188,403
2013-05-03 06:13:47
10,313,887
15
2012-04-25 10:32:45
39,726
2012-04-25 10:32:45
https://stackoverflow.com/q/10234872
https://stackoverflow.com/a/10313887
<p>You must use new <code>gsettings</code> tool and not old gconftool, with a bit different keys:</p> <pre><code>gsettings set org.gnome.system.proxy.socks host '127.0.0.1' gsettings set org.gnome.system.proxy.socks port 3128 gsettings set org.gnome.system.proxy mode 'manual' # to disable proxy: # gsettings set org.g...
<p>You must use new <code>gsettings</code> tool and not old gconftool, with a bit different keys:</p> <pre><code>gsettings set org.gnome.system.proxy.socks host '127.0.0.1' gsettings set org.gnome.system.proxy.socks port 3128 gsettings set org.gnome.system.proxy mode 'manual' # to disable proxy: # gsettings set org.g...
58, 387, 549, 725, 760
bash, configuration, linux, proxy, ubuntu
<h1>Changing system proxy settings in Ubuntu 12.04 from terminal</h1> <p>I've been working in Ubuntu 12.04 and one of the things that I am trying to implement in a Bash script is modifying the proxy settings of the system. To clarify, this would be a script that sets up each VM that I make with the programs and package...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,404
bash
# Changing system proxy settings in Ubuntu 12.04 from terminal I've been working in Ubuntu 12.04 and one of the things that I am trying to implement in a Bash script is modifying the proxy settings of the system. To clarify, this would be a script that sets up each VM that I make with the programs and packages that I ...
You must use new `gsettings` tool and not old gconftool, with a bit different keys: ``` gsettings set org.gnome.system.proxy.socks host '127.0.0.1' gsettings set org.gnome.system.proxy.socks port 3128 gsettings set org.gnome.system.proxy mode 'manual' # to disable proxy: # gsettings set org.gnome.system.proxy mode 'n...
10076741
How to redirect standard input and output with Bash
8
2012-04-09 16:57:44
<pre><code>#!/bin/bash ./program &lt; input.txt &gt; output.txt </code></pre> <p>The <code>&gt; output.txt</code> part is being ignored so output.txt ends up being empty.</p> <p>This works for the <code>sort</code> command so I expected to also work for other programs.</p> <p>Any reason this doesn't work? How should...
8,663
658,014
2012-04-09 17:01:32
10,076,805
15
2012-04-09 17:01:32
129,570
2012-04-09 17:01:32
https://stackoverflow.com/q/10076741
https://stackoverflow.com/a/10076805
<p>The most likely explanation is that the output you're seeing is from <code>stderr</code>, not <code>stdout</code>. To redirect both of them to a file, do this:</p> <pre><code>./program &lt; input.txt &gt; output.txt 2&gt;&amp;1 </code></pre> <p>or</p> <pre><code>./program &lt; input.txt &amp;&gt; output.txt </co...
<p>The most likely explanation is that the output you're seeing is from <code>stderr</code>, not <code>stdout</code>. To redirect both of them to a file, do this:</p> <pre><code>./program &lt; input.txt &gt; output.txt 2&gt;&amp;1 </code></pre> <p>or</p> <pre><code>./program &lt; input.txt &amp;&gt; output.txt </co...
345, 387
bash, io
<h1>How to redirect standard input and output with Bash</h1> <pre><code>#!/bin/bash ./program &lt; input.txt &gt; output.txt </code></pre> <p>The <code>&gt; output.txt</code> part is being ignored so output.txt ends up being empty.</p> <p>This works for the <code>sort</code> command so I expected to also work for oth...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,405
bash
# How to redirect standard input and output with Bash ``` #!/bin/bash ./program < input.txt > output.txt ``` The `> output.txt` part is being ignored so output.txt ends up being empty. This works for the `sort` command so I expected to also work for other programs. Any reason this doesn't work? How should I achieve...
The most likely explanation is that the output you're seeing is from `stderr`, not `stdout`. To redirect both of them to a file, do this: ``` ./program < input.txt > output.txt 2>&1 ``` or ``` ./program < input.txt &> output.txt ```
9606503
Using sed and regex to capture last part of url
8
2012-03-07 17:42:34
<p>I'm trying to make sed match the last part of a url and output just that. For example:</p> <p><code>echo "http://randomurl/suburl/file.mp3" | sed (expression)</code></p> <p>should give the output:</p> <p><code>file.mp3</code></p> <p>So far I've tried <code>sed 's|\([^/]+mp3\)$|\1|g'</code> but it just outputs th...
7,080
909,438
2012-10-22 07:12:19
9,606,533
15
2012-03-07 17:44:22
164,835
2012-03-07 17:44:22
https://stackoverflow.com/q/9606503
https://stackoverflow.com/a/9606533
<p>this works:</p> <pre><code> echo "http://randomurl/suburl/file.mp3" | sed 's#.*/##' </code></pre>
<p>this works:</p> <pre><code> echo "http://randomurl/suburl/file.mp3" | sed 's#.*/##' </code></pre>
18, 58, 387
bash, linux, regex
<h1>Using sed and regex to capture last part of url</h1> <p>I'm trying to make sed match the last part of a url and output just that. For example:</p> <p><code>echo "http://randomurl/suburl/file.mp3" | sed (expression)</code></p> <p>should give the output:</p> <p><code>file.mp3</code></p> <p>So far I've tried <code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,406
bash
# Using sed and regex to capture last part of url I'm trying to make sed match the last part of a url and output just that. For example: `echo "http://randomurl/suburl/file.mp3" | sed (expression)` should give the output: `file.mp3` So far I've tried `sed 's|\([^/]+mp3\)$|\1|g'` but it just outputs the whole url. ...
this works: ``` echo "http://randomurl/suburl/file.mp3" | sed 's#.*/##' ```
7176572
How to merge files in bash in alphabetical order
8
2011-08-24 13:52:12
<p>I need to merge a bunch of mp3 files together. I know that simply doing </p> <pre><code>cat file1.mp3 &gt;&gt; file2.mp3 </code></pre> <p>seems to work fine (at least it plays back correctly on my Zune anyway).</p> <p>I'd like to run </p> <pre><code>cat *.mp3 &gt; merged.mp3 </code></pre> <p>but since there are...
10,998
117,549
2011-08-24 15:12:42
7,176,969
15
2011-08-24 14:17:09
115,845
2011-08-24 15:12:42
https://stackoverflow.com/q/7176572
https://stackoverflow.com/a/7176969
<p>Your version (<code>cat *.mp3 &gt; merged.mp3</code>) should work as you'd expect. The <code>*.mp3</code> is expanded by the shell and will be in alphabetical order. </p> <p>From the <a href="http://www.gnu.org/software/bash/manual/bashref.html#index-pathname-expansion-95" rel="nofollow noreferrer">Bash Reference M...
<p>Your version (<code>cat *.mp3 &gt; merged.mp3</code>) should work as you'd expect. The <code>*.mp3</code> is expanded by the shell and will be in alphabetical order. </p> <p>From the <a href="http://www.gnu.org/software/bash/manual/bashref.html#index-pathname-expansion-95" rel="nofollow noreferrer">Bash Reference M...
387, 3589, 22820
bash, cat, ls
<h1>How to merge files in bash in alphabetical order</h1> <p>I need to merge a bunch of mp3 files together. I know that simply doing </p> <pre><code>cat file1.mp3 &gt;&gt; file2.mp3 </code></pre> <p>seems to work fine (at least it plays back correctly on my Zune anyway).</p> <p>I'd like to run </p> <pre><code>cat *...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,407
bash
# How to merge files in bash in alphabetical order I need to merge a bunch of mp3 files together. I know that simply doing ``` cat file1.mp3 >> file2.mp3 ``` seems to work fine (at least it plays back correctly on my Zune anyway). I'd like to run ``` cat *.mp3 > merged.mp3 ``` but since there are around 50 separa...
Your version (`cat *.mp3 > merged.mp3`) should work as you'd expect. The `*.mp3` is expanded by the shell and will be in alphabetical order. From the [Bash Reference Manual](http://www.gnu.org/software/bash/manual/bashref.html#index-pathname-expansion-95): > After word splitting, unless the -f option has been set, Ba...
3819659
How to do "tail this file until that process stops" in Bash?
8
2010-09-29 07:44:02
<p>I have a couple of scripts to control some applications (start/stop/list/etc). Currently my "stop" script just sends an interrupt signal to an application, but I'd like to have more feedback about what application does when it is shutting down. Ideally, I'd like to start tailing its log, then send an interrupt signa...
3,212
6,533
2020-02-09 08:53:53
3,819,814
15
2010-09-29 08:15:57
182,675
2010-09-29 15:34:26
https://stackoverflow.com/q/3819659
https://stackoverflow.com/a/3819814
<p>For just tailing a log file until a certain process stops (using <code>tail</code> from <em>GNU coreutils</em>):</p> <pre><code>do_something &gt; logfile &amp; tail --pid $! -f logfile </code></pre> <p><strong>UPDATE</strong> The above contains a race condition: In case <code>do_something</code> spews many lines i...
<p>For just tailing a log file until a certain process stops (using <code>tail</code> from <em>GNU coreutils</em>):</p> <pre><code>do_something &gt; logfile &amp; tail --pid $! -f logfile </code></pre> <p><strong>UPDATE</strong> The above contains a race condition: In case <code>do_something</code> spews many lines i...
387, 390
bash, shell
<h1>How to do "tail this file until that process stops" in Bash?</h1> <p>I have a couple of scripts to control some applications (start/stop/list/etc). Currently my "stop" script just sends an interrupt signal to an application, but I'd like to have more feedback about what application does when it is shutting down. Id...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,408
bash
# How to do "tail this file until that process stops" in Bash? I have a couple of scripts to control some applications (start/stop/list/etc). Currently my "stop" script just sends an interrupt signal to an application, but I'd like to have more feedback about what application does when it is shutting down. Ideally, I'...
For just tailing a log file until a certain process stops (using `tail` from *GNU coreutils*): ``` do_something > logfile & tail --pid $! -f logfile ``` **UPDATE** The above contains a race condition: In case `do_something` spews many lines into `logfile`, the `tail` will skip all of them but the last few. To avoid t...
374687
Why is "echo foo | read a ; echo $a" not working as expected?
8
2008-12-17 14:27:33
<p>I could replicate the problem with various shells under FreeBSD, GNU/Linux, and Solaris. It had me head-scratching for more than an hour, so I decided to post the question here.</p>
9,932
20,520
2014-07-13 00:13:13
374,702
15
2008-12-17 14:31:10
43,582
2008-12-17 14:31:10
https://stackoverflow.com/q/374687
https://stackoverflow.com/a/374702
<p>Due to the piping the <code>read</code> is executed in its own subshell.</p> <pre><code>echo foo | while read a; do echo $a; done </code></pre> <p>will do what you expect it to.</p>
<p>Due to the piping the <code>read</code> is executed in its own subshell.</p> <pre><code>echo foo | while read a; do echo $a; done </code></pre> <p>will do what you expect it to.</p>
34, 58, 390
linux, shell, unix
<h1>Why is "echo foo | read a ; echo $a" not working as expected?</h1> <p>I could replicate the problem with various shells under FreeBSD, GNU/Linux, and Solaris. It had me head-scratching for more than an hour, so I decided to post the question here.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,409
bash
# Why is "echo foo | read a ; echo $a" not working as expected? I could replicate the problem with various shells under FreeBSD, GNU/Linux, and Solaris. It had me head-scratching for more than an hour, so I decided to post the question here.
Due to the piping the `read` is executed in its own subshell. ``` echo foo | while read a; do echo $a; done ``` will do what you expect it to.
71324859
bash: npm: command not found in cPanel Terminal
7
2022-03-02 15:01:03
<p>I get response, When try to write:</p> <pre><code>$ /opt/cpanel/ea-nodejs16/bin/npm -v 8.1.2 </code></pre> <p>but with :</p> <pre><code>$ npm -v bash: npm: command not found </code></pre> <p>So, I tried as the same logic but it didn't work:</p> <pre><code>$ /opt/cpanel/ea-nodejs16/bin/npm install npm ERR! code ENOEN...
16,608
11,973,741
2022-09-08 09:02:40
73,646,358
15
2022-09-08 09:02:40
11,992,703
2022-09-08 09:02:40
https://stackoverflow.com/q/71324859
https://stackoverflow.com/a/73646358
<p>First install NodeJS install on cPanel, WHM.</p> <p>To install NodeJS from WHM, Goto <strong>Home / Software / EasyApache 4</strong></p> <p>And in Additional Packages find NodeJS.</p> <p><a href="https://i.sstatic.net/ip5GO.png" rel="noreferrer"><img src="https://i.sstatic.net/ip5GO.png" alt="enter image description...
<p>First install NodeJS install on cPanel, WHM.</p> <p>To install NodeJS from WHM, Goto <strong>Home / Software / EasyApache 4</strong></p> <p>And in Additional Packages find NodeJS.</p> <p><a href="https://i.sstatic.net/ip5GO.png" rel="noreferrer"><img src="https://i.sstatic.net/ip5GO.png" alt="enter image description...
387, 12409, 12410, 46426, 61387
bash, cpanel, node.js, npm, whm
<h1>bash: npm: command not found in cPanel Terminal</h1> <p>I get response, When try to write:</p> <pre><code>$ /opt/cpanel/ea-nodejs16/bin/npm -v 8.1.2 </code></pre> <p>but with :</p> <pre><code>$ npm -v bash: npm: command not found </code></pre> <p>So, I tried as the same logic but it didn't work:</p> <pre><code>$ /o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,410
bash
# bash: npm: command not found in cPanel Terminal I get response, When try to write: ``` $ /opt/cpanel/ea-nodejs16/bin/npm -v 8.1.2 ``` but with : ``` $ npm -v bash: npm: command not found ``` So, I tried as the same logic but it didn't work: ``` $ /opt/cpanel/ea-nodejs16/bin/npm install npm ERR! code ENOENT npm ...
First install NodeJS install on cPanel, WHM. To install NodeJS from WHM, Goto **Home / Software / EasyApache 4** And in Additional Packages find NodeJS. [![enter image description here](https://i.sstatic.net/ip5GO.png)](https://i.sstatic.net/ip5GO.png) After that create an environment variable which points to the n...
73603594
I am Unable to start OpenSSH with Windows PowerShell
7
2022-09-05 00:17:09
<p><strong>Problem:</strong> Unable to issue command <code>Start-Service sshd</code> in Windows PowerShell 7.2.6.</p> <p><strong>Expected Results:</strong> OpenSSH Server Starts.</p> <p><strong>Actual Results:</strong> <code>Start-Service: Cannot find any service with service name 'sshd'.</code>.</p> <p><strong>Investi...
19,219
18,257,801
2025-07-19 05:02:10
73,603,692
15
2022-09-05 00:49:37
18,257,801
2022-09-05 00:49:37
https://stackoverflow.com/q/73603594
https://stackoverflow.com/a/73603692
<p>As per Abraham Zinalas Comment.</p> <p><strong>Solution</strong></p> <pre><code>PS &gt; Get-WindowsCapability -Online -Name open* | Add-WindowsCapability -Online Path : Online : True RestartNeeded : False Path : Online : True RestartNeeded : False PS &gt; Get-WindowsCapability -On...
<p>As per Abraham Zinalas Comment.</p> <p><strong>Solution</strong></p> <pre><code>PS &gt; Get-WindowsCapability -Online -Name open* | Add-WindowsCapability -Online Path : Online : True RestartNeeded : False Path : Online : True RestartNeeded : False PS &gt; Get-WindowsCapability -On...
64, 386, 526
powershell, ssh, windows
<h1>I am Unable to start OpenSSH with Windows PowerShell</h1> <p><strong>Problem:</strong> Unable to issue command <code>Start-Service sshd</code> in Windows PowerShell 7.2.6.</p> <p><strong>Expected Results:</strong> OpenSSH Server Starts.</p> <p><strong>Actual Results:</strong> <code>Start-Service: Cannot find any se...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,411
bash
# I am Unable to start OpenSSH with Windows PowerShell **Problem:** Unable to issue command `Start-Service sshd` in Windows PowerShell 7.2.6. **Expected Results:** OpenSSH Server Starts. **Actual Results:** `Start-Service: Cannot find any service with service name 'sshd'.`. **Investigation:** Above error clearing i...
As per Abraham Zinalas Comment. **Solution** ``` PS > Get-WindowsCapability -Online -Name open* | Add-WindowsCapability -Online Path : Online : True RestartNeeded : False Path : Online : True RestartNeeded : False PS > Get-WindowsCapability -Online -Name open* Name : OpenS...
59744790
Bash/WSL - How to run command as root?
7
2020-01-15 03:32:23
<pre><code>&gt;ubuntu1804.exe -c "echo $USER" mpen </code></pre> <p>That runs the command as me, how do I run it as root?</p> <p>The help page doesn't even mention <code>-c</code> </p> <pre><code>&gt;ubuntu1804.exe help Launches or configures a Linux distribution. Usage: &lt;no args&gt; Launches the u...
36,706
65,387
2024-07-24 22:52:34
59,763,908
15
2020-01-16 06:10:16
65,387
2020-01-16 06:16:00
https://stackoverflow.com/q/59744790
https://stackoverflow.com/a/59763908
<p>Turns out there's another command simply called <code>wsl</code> that lets you run arbitrary commands as arbitrary users:</p> <pre><code>&gt;wsl -u root -d Ubuntu-18.04 -- echo "I am g$USER" I am groot </code></pre> <p>N.B. you need to use separate args (instead of a string) for this one.</p> <p><code>-d</code> i...
<p>Turns out there's another command simply called <code>wsl</code> that lets you run arbitrary commands as arbitrary users:</p> <pre><code>&gt;wsl -u root -d Ubuntu-18.04 -- echo "I am g$USER" I am groot </code></pre> <p>N.B. you need to use separate args (instead of a string) for this one.</p> <p><code>-d</code> i...
387, 549, 107329, 119526
bash, ubuntu, windows-10, windows-subsystem-for-linux
<h1>Bash/WSL - How to run command as root?</h1> <pre><code>&gt;ubuntu1804.exe -c "echo $USER" mpen </code></pre> <p>That runs the command as me, how do I run it as root?</p> <p>The help page doesn't even mention <code>-c</code> </p> <pre><code>&gt;ubuntu1804.exe help Launches or configures a Linux distribution. U...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,412
bash
# Bash/WSL - How to run command as root? ``` >ubuntu1804.exe -c "echo $USER" mpen ``` That runs the command as me, how do I run it as root? The help page doesn't even mention `-c` ``` >ubuntu1804.exe help Launches or configures a Linux distribution. Usage: <no args> Launches the user's default shell in...
Turns out there's another command simply called `wsl` that lets you run arbitrary commands as arbitrary users: ``` >wsl -u root -d Ubuntu-18.04 -- echo "I am g$USER" I am groot ``` N.B. you need to use separate args (instead of a string) for this one. `-d` is optional. You can change the default distro like ``` wsl...
59551619
How to extract value from json contained in a variable using jq in bash
7
2020-01-01 10:16:26
<p>I am writing a bash script which has a json value stored in a variable now i want to extract the values in that json using Jq. The code used is. </p> <pre><code>json_val={"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri?code=lyz1To6ZTWClDHSiaeXyxg"} code_val= echo"$json_val" |...
16,895
7,419,457
2022-05-11 15:36:46
59,551,649
15
2020-01-01 10:21:41
548,225
2020-01-01 10:32:53
https://stackoverflow.com/q/59551619
https://stackoverflow.com/a/59551649
<p>You may use this:</p> <pre><code>json_val='{"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri?code=lyz1To6ZTWClDHSiaeXyxg"}' code_val=$(jq -r '.code' &lt;&lt;&lt; "$json_val") echo "$code_val" </code></pre> <p></p> <pre><code>lyz1To6ZTWClDHSiaeXyxg </code></pre> <p>Note follow...
<p>You may use this:</p> <pre><code>json_val='{"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri?code=lyz1To6ZTWClDHSiaeXyxg"}' code_val=$(jq -r '.code' &lt;&lt;&lt; "$json_val") echo "$code_val" </code></pre> <p></p> <pre><code>lyz1To6ZTWClDHSiaeXyxg </code></pre> <p>Note follow...
58, 387, 390, 105170
bash, jq, linux, shell
<h1>How to extract value from json contained in a variable using jq in bash</h1> <p>I am writing a bash script which has a json value stored in a variable now i want to extract the values in that json using Jq. The code used is. </p> <pre><code>json_val={"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,413
bash
# How to extract value from json contained in a variable using jq in bash I am writing a bash script which has a json value stored in a variable now i want to extract the values in that json using Jq. The code used is. ``` json_val={"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri...
You may use this: ``` json_val='{"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri?code=lyz1To6ZTWClDHSiaeXyxg"}' code_val=$(jq -r '.code' <<< "$json_val") echo "$code_val" ``` ``` lyz1To6ZTWClDHSiaeXyxg ``` Note following changes: - Wrap complete json string in single quotes - u...
49194078
How to Disconnect VPN in Windows Via Powershell
7
2018-03-09 12:42:48
<p>I'm always connecting and disconnecting to my VPN and I have a powershell script that connects to the VPN profile and it's brilliant. I dont have to type anything just run it. </p> <p>However, I always needed to disconnected via the convoluted GUI. </p> <p>The awesome script I use to connect goes something like:</...
18,149
5,142,580
2025-04-15 01:44:43
49,194,774
15
2018-03-09 13:22:08
5,403,693
2018-03-09 13:22:08
https://stackoverflow.com/q/49194078
https://stackoverflow.com/a/49194774
<p><code>rasdial</code> has a parameter <code>/DISCONNECT</code> that should do what you want.</p> <p>You could rewrite your script to do the disconnect like this:</p> <pre><code>$vpnName = "MyVPN"; $vpn = Get-VpnConnection -Name $vpnName; if($vpn.ConnectionStatus -eq "Connected"){ rasdial $vpnName /DISCONNECT; } ...
<p><code>rasdial</code> has a parameter <code>/DISCONNECT</code> that should do what you want.</p> <p>You could rewrite your script to do the disconnect like this:</p> <pre><code>$vpnName = "MyVPN"; $vpn = Get-VpnConnection -Name $vpnName; if($vpn.ConnectionStatus -eq "Connected"){ rasdial $vpnName /DISCONNECT; } ...
526, 633, 1362, 107329
automation, powershell, vpn, windows-10
<h1>How to Disconnect VPN in Windows Via Powershell</h1> <p>I'm always connecting and disconnecting to my VPN and I have a powershell script that connects to the VPN profile and it's brilliant. I dont have to type anything just run it. </p> <p>However, I always needed to disconnected via the convoluted GUI. </p> <p>T...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,414
bash
# How to Disconnect VPN in Windows Via Powershell I'm always connecting and disconnecting to my VPN and I have a powershell script that connects to the VPN profile and it's brilliant. I dont have to type anything just run it. However, I always needed to disconnected via the convoluted GUI. The awesome script I use t...
`rasdial` has a parameter `/DISCONNECT` that should do what you want. You could rewrite your script to do the disconnect like this: ``` $vpnName = "MyVPN"; $vpn = Get-VpnConnection -Name $vpnName; if($vpn.ConnectionStatus -eq "Connected"){ rasdial $vpnName /DISCONNECT; } ``` I haven't tested this, but it should w...
48153565
.Net StopWatch and Powershell
7
2018-01-08 15:43:45
<p>I have a powershell script that is currently running every 4 hours via task scheduler. It cleans a drive and when it's done it fires off an email to me telling me what it moved and where and the amount of time it took to perform this task. </p> <p>However, I seem to be having issues with the time it displays at the...
8,243
8,285,969
2018-01-08 17:26:13
48,155,134
15
2018-01-08 17:26:13
3,515,885
2018-01-08 17:26:13
https://stackoverflow.com/q/48153565
https://stackoverflow.com/a/48155134
<p>Try using $StopWatch.Elapsed.TotalMinutes instead of $StopWatch.Elapsed.Minutes </p> <p>The latter will not count beyond 59 so for a task that took 64 minutes to run, the Minutes property will only show 4. The Hours property in this particular example however would have increased to 1, up from 0.</p> <p>You could ...
<p>Try using $StopWatch.Elapsed.TotalMinutes instead of $StopWatch.Elapsed.Minutes </p> <p>The latter will not count beyond 59 so for a task that took 64 minutes to run, the Minutes property will only show 4. The Hours property in this particular example however would have increased to 1, up from 0.</p> <p>You could ...
1, 526, 6809
.net, powershell, stopwatch
<h1>.Net StopWatch and Powershell</h1> <p>I have a powershell script that is currently running every 4 hours via task scheduler. It cleans a drive and when it's done it fires off an email to me telling me what it moved and where and the amount of time it took to perform this task. </p> <p>However, I seem to be having ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,415
bash
# .Net StopWatch and Powershell I have a powershell script that is currently running every 4 hours via task scheduler. It cleans a drive and when it's done it fires off an email to me telling me what it moved and where and the amount of time it took to perform this task. However, I seem to be having issues with the t...
Try using $StopWatch.Elapsed.TotalMinutes instead of $StopWatch.Elapsed.Minutes The latter will not count beyond 59 so for a task that took 64 minutes to run, the Minutes property will only show 4. The Hours property in this particular example however would have increased to 1, up from 0. You could easily verify/try ...
47144395
Git Bash Inserts Tilde
7
2017-11-06 19:32:11
<p>Does anyone know what could be causing git bash to randomly insert the tilde character in the terminal window. </p> <p>Also I am not sure if related, but when viewing log files in vim, the help dialog automatically opens in a split window in vim. </p> <p>Does anyone know what the issue could be? I suspect it co...
4,259
521,682
2022-08-14 05:34:32
47,183,365
15
2017-11-08 15:19:28
2,687,741
2017-11-08 15:19:28
https://stackoverflow.com/q/47144395
https://stackoverflow.com/a/47183365
<p>Same as above answer. </p> <p>Caffeine was causing it for me.<br> What I did was add a command argument <code>-useshift</code> and this stopped it completely.</p> <p>For more command line things: <a href="http://www.zhornsoftware.co.uk/caffeine/" rel="noreferrer">Caffeine command line arguments</a></p>
<p>Same as above answer. </p> <p>Caffeine was causing it for me.<br> What I did was add a command argument <code>-useshift</code> and this stopped it completely.</p> <p>For more command line things: <a href="http://www.zhornsoftware.co.uk/caffeine/" rel="noreferrer">Caffeine command line arguments</a></p>
370, 61874
git-bash, vim
<h1>Git Bash Inserts Tilde</h1> <p>Does anyone know what could be causing git bash to randomly insert the tilde character in the terminal window. </p> <p>Also I am not sure if related, but when viewing log files in vim, the help dialog automatically opens in a split window in vim. </p> <p>Does anyone know what the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,416
bash
# Git Bash Inserts Tilde Does anyone know what could be causing git bash to randomly insert the tilde character in the terminal window. Also I am not sure if related, but when viewing log files in vim, the help dialog automatically opens in a split window in vim. Does anyone know what the issue could be? I suspect i...
Same as above answer. Caffeine was causing it for me. What I did was add a command argument `-useshift` and this stopped it completely. For more command line things: [Caffeine command line arguments](http://www.zhornsoftware.co.uk/caffeine/)
46853748
How to make grep not interpret special characters in my search string?
7
2017-10-20 16:49:19
<p>When executing <code>./test.sh 12.34</code>, the grep should match <code>12.34</code> and not <code>12-34</code>. How can this be accomplished?</p> <pre><code>#!/bin/sh ip=$1 echo $ip if netstat | grep ssh | grep $ip; then netstat | grep ssh | grep $ip else echo 'No' fi </code></pre>
11,637
1,032,531
2017-10-20 17:48:29
46,853,946
15
2017-10-20 17:01:05
6,919,746
2017-10-20 17:25:47
https://stackoverflow.com/q/46853748
https://stackoverflow.com/a/46853946
<p>You could use <code>grep</code> with the <code>-F</code> option:</p> <p>From man grep:</p> <pre><code> -F, --fixed-strings Interpret pattern as a set of fixed strings (i.e. force grep to behave as fgrep). </code></pre> <p>Your example:</p> <pre><code>grep -F "$ip" </code></pre>
<p>You could use <code>grep</code> with the <code>-F</code> option:</p> <p>From man grep:</p> <pre><code> -F, --fixed-strings Interpret pattern as a set of fixed strings (i.e. force grep to behave as fgrep). </code></pre> <p>Your example:</p> <pre><code>grep -F "$ip" </code></pre>
387, 1271, 4804
bash, escaping, grep
<h1>How to make grep not interpret special characters in my search string?</h1> <p>When executing <code>./test.sh 12.34</code>, the grep should match <code>12.34</code> and not <code>12-34</code>. How can this be accomplished?</p> <pre><code>#!/bin/sh ip=$1 echo $ip if netstat | grep ssh | grep $ip; then ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,417
bash
# How to make grep not interpret special characters in my search string? When executing `./test.sh 12.34`, the grep should match `12.34` and not `12-34`. How can this be accomplished? ``` #!/bin/sh ip=$1 echo $ip if netstat | grep ssh | grep $ip; then netstat | grep ssh | grep $ip else echo 'No' f...
You could use `grep` with the `-F` option: From man grep: ``` -F, --fixed-strings Interpret pattern as a set of fixed strings (i.e. force grep to behave as fgrep). ``` Your example: ``` grep -F "$ip" ```
46814858
Toast notification not working on Windows fall creators update
7
2017-10-18 16:23:16
<p>I have a <code>PowerShell</code> code, which I called the <code>.NET</code> reference for doing the toast notification, it works good at previous update. but when got the windows 10 fall creators (FCU) update, it's gone, the same code not working now:<br /></p> <pre><code>$app = "HTML Report" [Windows.UI.Notificati...
10,574
7,453,565
2017-10-18 19:35:31
46,817,674
15
2017-10-18 19:19:42
170,183
2017-10-18 19:35:31
https://stackoverflow.com/q/46814858
https://stackoverflow.com/a/46817674
<p>As mentioned in the comments, this is something that recently had to be addressed in the <a href="https://github.com/Windos/BurntToast/commit/674b80c9fbbd689a729c1fd2c3dedd386843a5a4" rel="noreferrer">BurntToast</a> module. There's a <a href="https://king.geek.nz/2017/10/09/burnttoast-no-appid/" rel="noreferrer">blo...
<p>As mentioned in the comments, this is something that recently had to be addressed in the <a href="https://github.com/Windos/BurntToast/commit/674b80c9fbbd689a729c1fd2c3dedd386843a5a4" rel="noreferrer">BurntToast</a> module. There's a <a href="https://king.geek.nz/2017/10/09/burnttoast-no-appid/" rel="noreferrer">blo...
1, 64, 526
.net, powershell, windows
<h1>Toast notification not working on Windows fall creators update</h1> <p>I have a <code>PowerShell</code> code, which I called the <code>.NET</code> reference for doing the toast notification, it works good at previous update. but when got the windows 10 fall creators (FCU) update, it's gone, the same code not workin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,418
bash
# Toast notification not working on Windows fall creators update I have a `PowerShell` code, which I called the `.NET` reference for doing the toast notification, it works good at previous update. but when got the windows 10 fall creators (FCU) update, it's gone, the same code not working now: ``` $app = "HTML Report...
As mentioned in the comments, this is something that recently had to be addressed in the [BurntToast](https://github.com/Windos/BurntToast/commit/674b80c9fbbd689a729c1fd2c3dedd386843a5a4) module. There's a [blog post](https://king.geek.nz/2017/10/09/burnttoast-no-appid/) that accompanies this change too, but I'll do my...
46752794
Why does wait generate “<pid> is not a child of this shell” error if a pipe is used afterwards?
7
2017-10-15 07:38:15
<p>In the following I create a background process and wait for it to complete. </p> <pre><code>$ bash -c "sleep 5 | false" &amp; wait $! [1] 46950 [1]+ Exit 1 bash -c "sleep 5 | false" $ echo $? 1 </code></pre> <p>This works and the prompt returns after 5 seconds. </p> <p>However, <code>wait</cod...
14,236
5,771,861
2017-10-16 05:02:38
46,753,750
15
2017-10-15 09:52:49
404,556
2017-10-15 18:16:28
https://stackoverflow.com/q/46752794
https://stackoverflow.com/a/46753750
<p>There are two key points to observe here:</p> <ul> <li><code>wait</code> (a shell built-in) can wait only (the shell's) children</li> <li>each command in a pipeline runs in a separate subshell</li> </ul> <p>So, when you say:</p> <pre><code>cmd &amp; wait $! </code></pre> <p>then <code>cmd</code> is run in your c...
<p>There are two key points to observe here:</p> <ul> <li><code>wait</code> (a shell built-in) can wait only (the shell's) children</li> <li>each command in a pipeline runs in a separate subshell</li> </ul> <p>So, when you say:</p> <pre><code>cmd &amp; wait $! </code></pre> <p>then <code>cmd</code> is run in your c...
58, 387, 390, 2348, 5813
bash, linux, pipe, shell, subprocess
<h1>Why does wait generate “<pid> is not a child of this shell” error if a pipe is used afterwards?</h1> <p>In the following I create a background process and wait for it to complete. </p> <pre><code>$ bash -c "sleep 5 | false" &amp; wait $! [1] 46950 [1]+ Exit 1 bash -c "sleep 5 | false" $ echo $?...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,419
bash
# Why does wait generate “ is not a child of this shell” error if a pipe is used afterwards? In the following I create a background process and wait for it to complete. ``` $ bash -c "sleep 5 | false" & wait $! [1] 46950 [1]+ Exit 1 bash -c "sleep 5 | false" $ echo $? 1 ``` This works and the pro...
There are two key points to observe here: - `wait` (a shell built-in) can wait only (the shell's) children - each command in a pipeline runs in a separate subshell So, when you say: ``` cmd & wait $! ``` then `cmd` is run in your current shell, in background, and `wait` (being the shell's built-in) can wait on `cmd...
43938414
set FLASK_DEBUG=1 not working on Powershell
7
2017-05-12 13:00:04
<p>I'm building a Flask application and my file "<strong>helloworld.py</strong>" is:</p> <pre><code>from flask import Flask app = Flask(__name__) @app.route('/home') def hello_world(): return 'Home!' @app.route('/about') def about_us(): return 'aboutus!' </code></pre> <p>My Flask code after activating venv:...
11,941
7,732,877
2022-08-02 14:55:33
43,939,856
15
2017-05-12 14:10:33
400,617
2022-08-02 14:55:33
https://stackoverflow.com/q/43938414
https://stackoverflow.com/a/43939856
<p>The syntax for setting environment variables is different in PowerShell, use <code>$env:</code>.</p> <pre class="lang-none prettyprint-override"><code>&gt; $env:FLASK_APP = &quot;helloworld.py&quot; &gt; $env:FLASK_DEBUG = &quot;1&quot; &gt; flask run </code></pre> <p><code>set</code> is used for Windows CMD.</p> <p...
<p>The syntax for setting environment variables is different in PowerShell, use <code>$env:</code>.</p> <pre class="lang-none prettyprint-override"><code>&gt; $env:FLASK_APP = &quot;helloworld.py&quot; &gt; $env:FLASK_DEBUG = &quot;1&quot; &gt; flask run </code></pre> <p><code>set</code> is used for Windows CMD.</p> <p...
16, 526, 54712
flask, powershell, python
<h1>set FLASK_DEBUG=1 not working on Powershell</h1> <p>I'm building a Flask application and my file "<strong>helloworld.py</strong>" is:</p> <pre><code>from flask import Flask app = Flask(__name__) @app.route('/home') def hello_world(): return 'Home!' @app.route('/about') def about_us(): return 'aboutus!' <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,420
bash
# set FLASK_DEBUG=1 not working on Powershell I'm building a Flask application and my file "**helloworld.py**" is: ``` from flask import Flask app = Flask(__name__) @app.route('/home') def hello_world(): return 'Home!' @app.route('/about') def about_us(): return 'aboutus!' ``` My Flask code after activatin...
The syntax for setting environment variables is different in PowerShell, use `$env:`. ``` > $env:FLASK_APP = "helloworld.py" > $env:FLASK_DEBUG = "1" > flask run ``` `set` is used for Windows CMD. ``` > set FLASK_DEBUG=1 ``` `export` is used by most other shells, like Bash and Zsh, such as on Linux and MacOS. ``` ...
37411988
Move files that are 30 minutes old
7
2016-05-24 11:16:11
<p>I work on a server system that does not allow me to store files more than 50 gigabytes. My application takes 20 minutes to generate a file. Is there any way whereby I can move all the files that are more than 30 minutes old from source to destination? I tried <code>rsync</code>: </p> <pre><code>rsync -avP source/...
11,124
4,057,644
2016-05-24 13:41:42
37,412,139
15
2016-05-24 11:22:59
5,291,015
2016-05-24 11:59:40
https://stackoverflow.com/q/37411988
https://stackoverflow.com/a/37412139
<p>You can use <code>find</code> along with <code>-exec</code> for this:-</p> <p>Replace <code>/sourcedirectory</code> and <code>/destination/directory/</code> with the source and target paths as you need.</p> <pre><code>find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \; </co...
<p>You can use <code>find</code> along with <code>-exec</code> for this:-</p> <p>Replace <code>/sourcedirectory</code> and <code>/destination/directory/</code> with the source and target paths as you need.</p> <pre><code>find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \; </co...
58, 387, 390, 549, 2829
bash, csh, linux, shell, ubuntu
<h1>Move files that are 30 minutes old</h1> <p>I work on a server system that does not allow me to store files more than 50 gigabytes. My application takes 20 minutes to generate a file. Is there any way whereby I can move all the files that are more than 30 minutes old from source to destination? I tried <code>rsync...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,421
bash
# Move files that are 30 minutes old I work on a server system that does not allow me to store files more than 50 gigabytes. My application takes 20 minutes to generate a file. Is there any way whereby I can move all the files that are more than 30 minutes old from source to destination? I tried `rsync`: ``` rsync -a...
You can use `find` along with `-exec` for this:- Replace `/sourcedirectory` and `/destination/directory/` with the source and target paths as you need. ``` find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \; ``` What basically the command does is, it tries to find files in th...
35235707
Bash - how to avoid command "eval set --" evaluating variables
7
2016-02-06 00:19:30
<p>I just write a little bash script for managing multiple parallels ssh commands. In order to parse arguments I use this piece of code : </p> <pre><code>#!/bin/bash # replace long arguments for arg in "$@"; do case "$arg" in --help) args="${args}-h ";; --host|-hS) args="${args}-s ...
20,089
2,447,053
2017-10-18 18:04:16
35,235,757
15
2016-02-06 00:25:12
14,122
2017-10-18 18:04:16
https://stackoverflow.com/q/35235707
https://stackoverflow.com/a/35235757
<p>As you note, <A HREF="http://mywiki.wooledge.org/BashFAQ/048" rel="noreferrer"><code>eval</code> is evil</A> -- and there's no need to use it here.</p> <pre><code>#!/bin/bash # make args an array, not a string args=( ) # replace long arguments for arg; do case "$arg" in --help) args+=( -h ) ...
<p>As you note, <A HREF="http://mywiki.wooledge.org/BashFAQ/048" rel="noreferrer"><code>eval</code> is evil</A> -- and there's no need to use it here.</p> <pre><code>#!/bin/bash # make args an array, not a string args=( ) # replace long arguments for arg; do case "$arg" in --help) args+=( -h ) ...
34, 276, 387, 2631, 4413
bash, cmd, eval, unix, variables
<h1>Bash - how to avoid command "eval set --" evaluating variables</h1> <p>I just write a little bash script for managing multiple parallels ssh commands. In order to parse arguments I use this piece of code : </p> <pre><code>#!/bin/bash # replace long arguments for arg in "$@"; do case "$arg" in --help) ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,422
bash
# Bash - how to avoid command "eval set --" evaluating variables I just write a little bash script for managing multiple parallels ssh commands. In order to parse arguments I use this piece of code : ``` #!/bin/bash # replace long arguments for arg in "$@"; do case "$arg" in --help) args="${arg...
As you note, [`eval` is evil](http://mywiki.wooledge.org/BashFAQ/048) -- and there's no need to use it here. ``` #!/bin/bash # make args an array, not a string args=( ) # replace long arguments for arg; do case "$arg" in --help) args+=( -h ) ;; --host|-hS) args+=( -s ) ;; ...
29334851
Sed command not found
7
2015-03-29 21:08:03
<p>I have this code:</p> <pre><code>if [ -d "$PATH" ]; then ABSPATH=$( cd "`echo "$1" | sed 's/[^/]*$//'`";pwd) fi </code></pre> <p>when I run it, I get this <code>sed: command not found</code>.Any command I put inside this "if" blog writes this message, XXX:command not found. I have no idea why. I have exactly the s...
44,512
4,232,455
2015-03-29 21:18:43
29,334,955
15
2015-03-29 21:18:43
418,413
2015-03-29 21:18:43
https://stackoverflow.com/q/29334851
https://stackoverflow.com/a/29334955
<p>The nature of your program* snippet implies that you have just overwritten <code>PATH</code>. <code>PATH</code> is an important <a href="http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html" rel="noreferrer">environment variable</a> that lets the shell know where to find commands… commands like <code>sed</co...
<p>The nature of your program* snippet implies that you have just overwritten <code>PATH</code>. <code>PATH</code> is an important <a href="http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html" rel="noreferrer">environment variable</a> that lets the shell know where to find commands… commands like <code>sed</co...
387, 390
bash, shell
<h1>Sed command not found</h1> <p>I have this code:</p> <pre><code>if [ -d "$PATH" ]; then ABSPATH=$( cd "`echo "$1" | sed 's/[^/]*$//'`";pwd) fi </code></pre> <p>when I run it, I get this <code>sed: command not found</code>.Any command I put inside this "if" blog writes this message, XXX:command not found. I have no...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,423
bash
# Sed command not found I have this code: ``` if [ -d "$PATH" ]; then ABSPATH=$( cd "`echo "$1" | sed 's/[^/]*$//'`";pwd) fi ``` when I run it, I get this `sed: command not found`.Any command I put inside this "if" blog writes this message, XXX:command not found. I have no idea why. I have exactly the same code else...
The nature of your program* snippet implies that you have just overwritten `PATH`. `PATH` is an important [environment variable](http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html) that lets the shell know where to find commands… commands like `sed`. If you overwrite it, `sed` will not be found. Use another ...
28857244
bash: Split binary file at predefined positions
7
2015-03-04 14:40:49
<p>I have binary files which contain data structures <strong>of various length</strong>. I would like to save these blocks of data into separate files. The size of each block is known. The <code>split</code> command can, well, split a file but it does not stop after the first block of data. It slices the file into piec...
9,847
1,395,359
2023-01-09 19:39:25
28,859,713
15
2015-03-04 16:29:43
2,836,621
2015-03-06 09:24:12
https://stackoverflow.com/q/28857244
https://stackoverflow.com/a/28859713
<p>You can use two independent <code>dd</code> commands. One to seek arbitrarily, and another to copy arbitrary lengths.</p> <pre><code>SEEK=501 BYTES=387 dd if=yourfile bs=$SEEK skip=1 | dd bs=$BYTES count=1 &gt; lump.bin </code></pre> <p><strong>Note</strong>: Although counter-intuitive to what you are actually try...
<p>You can use two independent <code>dd</code> commands. One to seek arbitrarily, and another to copy arbitrary lengths.</p> <pre><code>SEEK=501 BYTES=387 dd if=yourfile bs=$SEEK skip=1 | dd bs=$BYTES count=1 &gt; lump.bin </code></pre> <p><strong>Note</strong>: Although counter-intuitive to what you are actually try...
368, 387, 2193
bash, binary, split
<h1>bash: Split binary file at predefined positions</h1> <p>I have binary files which contain data structures <strong>of various length</strong>. I would like to save these blocks of data into separate files. The size of each block is known. The <code>split</code> command can, well, split a file but it does not stop af...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,424
bash
# bash: Split binary file at predefined positions I have binary files which contain data structures **of various length**. I would like to save these blocks of data into separate files. The size of each block is known. The `split` command can, well, split a file but it does not stop after the first block of data. It s...
You can use two independent `dd` commands. One to seek arbitrarily, and another to copy arbitrary lengths. ``` SEEK=501 BYTES=387 dd if=yourfile bs=$SEEK skip=1 | dd bs=$BYTES count=1 > lump.bin ``` **Note**: Although counter-intuitive to what you are actually try to do, keep the blocksize high and the count low for ...
27989736
How do I make Powershell wait until a command is done before continuing?
7
2015-01-16 17:43:59
<p>My script uninstalls a Windows Store app before installing the newer version. I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough?</p> <pre class="lang-powershell prettyprint-override"><code>Remove-Appxpackage MyAppName # ~wait here~ Add-Appxpackage ...
36,696
3,165,621
2015-01-16 18:51:16
27,990,646
15
2015-01-16 18:41:24
null
2015-01-16 18:41:24
https://stackoverflow.com/q/27989736
https://stackoverflow.com/a/27990646
<p> You can do this with the <a href="http://technet.microsoft.com/en-us/library/hh849698.aspx" rel="noreferrer"><code>Start-Job</code></a> and <a href="http://technet.microsoft.com/en-us/library/hh849735.aspx" rel="noreferrer"><code>Wait-Job</code></a> cmdlets:</p> <pre class="lang-powershell prettyprint-override"><c...
<p> You can do this with the <a href="http://technet.microsoft.com/en-us/library/hh849698.aspx" rel="noreferrer"><code>Start-Job</code></a> and <a href="http://technet.microsoft.com/en-us/library/hh849735.aspx" rel="noreferrer"><code>Wait-Job</code></a> cmdlets:</p> <pre class="lang-powershell prettyprint-override"><c...
526
powershell
<h1>How do I make Powershell wait until a command is done before continuing?</h1> <p>My script uninstalls a Windows Store app before installing the newer version. I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough?</p> <pre class="lang-powershell prettypri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,425
bash
# How do I make Powershell wait until a command is done before continuing? My script uninstalls a Windows Store app before installing the newer version. I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough? ``` Remove-Appxpackage MyAppName # ~wait here~ A...
You can do this with the [`Start-Job`](http://technet.microsoft.com/en-us/library/hh849698.aspx) and [`Wait-Job`](http://technet.microsoft.com/en-us/library/hh849735.aspx) cmdlets: ``` Start-Job -Name Job1 -ScriptBlock { Remove-Appxpackage MyAppName } Wait-Job -Name Job1 Add-Appxpackage .\PathToNewVersion ``` `Start-...
25710640
How to redirect grep output to a variable?
7
2014-09-07 13:21:52
<p>I have some pipe. For example, I have this pipe:</p> <pre><code>user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" </code></pre> <p>For this pipe I get this result:</p> <pre><code>September </code></pre> <p>I want to store this result to a variable. I write the following commands:</p> <pre><code>user@user:~$ cal...
23,321
1,756,750
2014-09-07 13:25:10
25,710,660
15
2014-09-07 13:24:48
3,776,858
2014-09-07 13:24:48
https://stackoverflow.com/q/25710640
https://stackoverflow.com/a/25710660
<pre><code> month=$(cal | head -1 | grep -oP "[A-Za-z]+") </code></pre> <p>or</p> <pre><code> month=$(date +%B) </code></pre>
<pre><code> month=$(cal | head -1 | grep -oP "[A-Za-z]+") </code></pre> <p>or</p> <pre><code> month=$(date +%B) </code></pre>
276, 387, 1271, 5813, 84917
bash, grep, output, pipe, variables
<h1>How to redirect grep output to a variable?</h1> <p>I have some pipe. For example, I have this pipe:</p> <pre><code>user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" </code></pre> <p>For this pipe I get this result:</p> <pre><code>September </code></pre> <p>I want to store this result to a variable. I write the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,426
bash
# How to redirect grep output to a variable? I have some pipe. For example, I have this pipe: ``` user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" ``` For this pipe I get this result: ``` September ``` I want to store this result to a variable. I write the following commands: ``` user@user:~$ cal | head -1 | mon...
``` month=$(cal | head -1 | grep -oP "[A-Za-z]+") ``` or ``` month=$(date +%B) ```
25647806
Running Shell Script From External Directory: No such file or directory
7
2014-09-03 15:06:56
<p>I have a shell script file that i want to run from java. My java work space directory is different than the script's directory. </p> <pre><code>private final String scriptPath = "/home/kemallin/Desktop/"; public void cleanCSVScript() { String script = "clean.sh"; try { Process awk = new ProcessBui...
25,914
2,523,672
2014-09-04 08:42:36
25,648,452
15
2014-09-03 15:39:24
252,858
2014-09-03 15:39:24
https://stackoverflow.com/q/25647806
https://stackoverflow.com/a/25648452
<p>Your program <code>clean.sh</code> is not an executable as Java understands it, even though the underlying system understands it as executable.</p> <p>You need to tell Java what shell is needed to execute your command. Do (assuming you are using <code>bash</code> and it is installed at <code>/bin/bash</code>):</p> ...
<p>Your program <code>clean.sh</code> is not an executable as Java understands it, even though the underlying system understands it as executable.</p> <p>You need to tell Java what shell is needed to execute your command. Do (assuming you are using <code>bash</code> and it is installed at <code>/bin/bash</code>):</p> ...
17, 387, 390
bash, java, shell
<h1>Running Shell Script From External Directory: No such file or directory</h1> <p>I have a shell script file that i want to run from java. My java work space directory is different than the script's directory. </p> <pre><code>private final String scriptPath = "/home/kemallin/Desktop/"; public void cleanCSVScript() ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,427
bash
# Running Shell Script From External Directory: No such file or directory I have a shell script file that i want to run from java. My java work space directory is different than the script's directory. ``` private final String scriptPath = "/home/kemallin/Desktop/"; public void cleanCSVScript() { String script ...
Your program `clean.sh` is not an executable as Java understands it, even though the underlying system understands it as executable. You need to tell Java what shell is needed to execute your command. Do (assuming you are using `bash` and it is installed at `/bin/bash`): ``` private final String scriptPath = "/home/k...
25263521
How to read and split comma separated file in a bash shell script?
7
2014-08-12 11:48:29
<p>I want to read a file line by line, split each line by comma (,) and store the result in an array. How to do this in a bash shell script?</p> <p>Sample line in my comma separated file</p> <pre><code>123,2014-07-21 10:01:44,123|8119|769.00||456|S </code></pre> <p>This should be the output after splitting:</p> <pr...
24,551
3,492,304
2014-08-12 11:58:35
25,263,615
15
2014-08-12 11:53:06
445,221
2014-08-12 11:58:35
https://stackoverflow.com/q/25263521
https://stackoverflow.com/a/25263615
<p>Use <code>read -a</code> to split each line read into array based from IFS.</p> <pre><code>while IFS=, read -ra arr; do ## Do something with ${arr0]}, ${arr[1]} and ${arr[2]} ... done &lt; file </code></pre> <p>If the third field can also contain commas, you can prevent it from being split by using finite ...
<p>Use <code>read -a</code> to split each line read into array based from IFS.</p> <pre><code>while IFS=, read -ra arr; do ## Do something with ${arr0]}, ${arr[1]} and ${arr[2]} ... done &lt; file </code></pre> <p>If the third field can also contain commas, you can prevent it from being split by using finite ...
114, 387, 390, 2193
arrays, bash, shell, split
<h1>How to read and split comma separated file in a bash shell script?</h1> <p>I want to read a file line by line, split each line by comma (,) and store the result in an array. How to do this in a bash shell script?</p> <p>Sample line in my comma separated file</p> <pre><code>123,2014-07-21 10:01:44,123|8119|769.00|...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,428
bash
# How to read and split comma separated file in a bash shell script? I want to read a file line by line, split each line by comma (,) and store the result in an array. How to do this in a bash shell script? Sample line in my comma separated file ``` 123,2014-07-21 10:01:44,123|8119|769.00||456|S ``` This should be ...
Use `read -a` to split each line read into array based from IFS. ``` while IFS=, read -ra arr; do ## Do something with ${arr0]}, ${arr[1]} and ${arr[2]} ... done < file ``` If the third field can also contain commas, you can prevent it from being split by using finite non-array parameters: ``` while IFS=, re...
23656267
How to remove nth element from command arguments in bash
7
2014-05-14 13:36:36
<p>How to I remove the nth element from an argument list in bash?</p> <p>Shift only appears to remove the first n, but I want to keep some of the first. I want something like:</p> <pre><code>#!/bin/sh set -x echo $@ shift (from position 2) echo $@ </code></pre> <p>So when I call it - it removes "house" from the l...
3,028
439,497
2019-07-03 05:23:09
23,656,370
15
2014-05-14 13:41:02
2,235,132
2014-05-14 14:02:21
https://stackoverflow.com/q/23656267
https://stackoverflow.com/a/23656370
<p>Use the <a href="http://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin" rel="noreferrer"><code>set</code></a> builtin and <a href="http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html" rel="noreferrer">shell parameter expansion</a>:</p> <pre><code>set -- "${@:1:1}" "${@:3}...
<p>Use the <a href="http://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin" rel="noreferrer"><code>set</code></a> builtin and <a href="http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html" rel="noreferrer">shell parameter expansion</a>:</p> <pre><code>set -- "${@:1:1}" "${@:3}...
387, 13245
bash, shift
<h1>How to remove nth element from command arguments in bash</h1> <p>How to I remove the nth element from an argument list in bash?</p> <p>Shift only appears to remove the first n, but I want to keep some of the first. I want something like:</p> <pre><code>#!/bin/sh set -x echo $@ shift (from position 2) echo $@ <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,429
bash
# How to remove nth element from command arguments in bash How to I remove the nth element from an argument list in bash? Shift only appears to remove the first n, but I want to keep some of the first. I want something like: ``` #!/bin/sh set -x echo $@ shift (from position 2) echo $@ ``` So when I call it - it ...
Use the [`set`](http://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin) builtin and [shell parameter expansion](http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html): ``` set -- "${@:1:1}" "${@:3}" ``` would remove the second positonal argument. You could make it generic by ...
23412774
Linux sorting "ls -al" output by date
7
2014-05-01 17:15:18
<p>I want to sort the output of the "ls -al" command according to date. I am able to easily do that for one column with command: </p> <pre><code>$ ls -al | sort -k6 -M -r </code></pre> <p>But how to do it for both collumn 6 and 7 simultaneously? The command:</p> <pre><code>$ ls -al | sort -k6 -M -r | sort -k7 -r </c...
18,564
1,964,707
2024-10-13 04:34:28
23,412,887
15
2014-05-01 17:21:19
140,750
2021-03-04 21:50:58
https://stackoverflow.com/q/23412774
https://stackoverflow.com/a/23412887
<p>With sort, if you specify <code>-k6</code>, the key starts at field 6 and extends to the end of the line. To truncate it and only use field 6, you should specify <code>-k6,6</code>. To sort on multiple keys, just specify <code>-k</code> multiple times. Also, you need to apply the M modifier only to the month, and...
<p>With sort, if you specify <code>-k6</code>, the key starts at field 6 and extends to the end of the line. To truncate it and only use field 6, you should specify <code>-k6,6</code>. To sort on multiple keys, just specify <code>-k</code> multiple times. Also, you need to apply the M modifier only to the month, and...
58, 134, 387
bash, linux, sorting
<h1>Linux sorting "ls -al" output by date</h1> <p>I want to sort the output of the "ls -al" command according to date. I am able to easily do that for one column with command: </p> <pre><code>$ ls -al | sort -k6 -M -r </code></pre> <p>But how to do it for both collumn 6 and 7 simultaneously? The command:</p> <pre><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,430
bash
# Linux sorting "ls -al" output by date I want to sort the output of the "ls -al" command according to date. I am able to easily do that for one column with command: ``` $ ls -al | sort -k6 -M -r ``` But how to do it for both collumn 6 and 7 simultaneously? The command: ``` $ ls -al | sort -k6 -M -r | sort -k7 -r `...
With sort, if you specify `-k6`, the key starts at field 6 and extends to the end of the line. To truncate it and only use field 6, you should specify `-k6,6`. To sort on multiple keys, just specify `-k` multiple times. Also, you need to apply the M modifier only to the month, and the n modifier to the day. So: ``` l...
22803916
bash string comparison fails
7
2014-04-02 07:07:23
<p>I have a variable that stores the output of netcat</p> <pre><code>var=$(echo "flush_all" | nc localhost 111) echo $var # outputs "OK" if test "$var" != "OK"; then echo "failed" exit fi </code></pre> <p>it outputs that it passed but when I want to programmatically check it is true, it fails. What is wrong w...
6,988
2,260,362
2018-09-18 00:13:01
22,804,013
15
2014-04-02 07:12:03
2,235,132
2014-04-02 07:12:03
https://stackoverflow.com/q/22803916
https://stackoverflow.com/a/22804013
<p>It seems that the variable contains a carriage return from the command substitution. You have a couple of options. Ensure that the string starts with <code>OK</code>:</p> <pre><code>if [[ "$var" == "OK"* ]]; then </code></pre> <p>or, strip the CR during the variable assignment:</p> <pre><code>var=$(echo "flush_...
<p>It seems that the variable contains a carriage return from the command substitution. You have a couple of options. Ensure that the string starts with <code>OK</code>:</p> <pre><code>if [[ "$var" == "OK"* ]]; then </code></pre> <p>or, strip the CR during the variable assignment:</p> <pre><code>var=$(echo "flush_...
387
bash
<h1>bash string comparison fails</h1> <p>I have a variable that stores the output of netcat</p> <pre><code>var=$(echo "flush_all" | nc localhost 111) echo $var # outputs "OK" if test "$var" != "OK"; then echo "failed" exit fi </code></pre> <p>it outputs that it passed but when I want to programmatically check...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,431
bash
# bash string comparison fails I have a variable that stores the output of netcat ``` var=$(echo "flush_all" | nc localhost 111) echo $var # outputs "OK" if test "$var" != "OK"; then echo "failed" exit fi ``` it outputs that it passed but when I want to programmatically check it is true, it fails. What is wr...
It seems that the variable contains a carriage return from the command substitution. You have a couple of options. Ensure that the string starts with `OK`: ``` if [[ "$var" == "OK"* ]]; then ``` or, strip the CR during the variable assignment: ``` var=$(echo "flush_all" | nc localhost 111 | tr -d '\r') ``` --- You...
17754230
Closing All Explorer Windows in PowerShell
7
2013-07-19 19:41:47
<p>I am writing the following code to close all explorer windows with PowerShell:</p> <pre><code>(New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() } </code></pre> <p>But it does not close out all the open windows....
7,279
2,600,767
2020-10-15 12:42:34
17,754,697
15
2013-07-19 20:12:40
520,612
2013-07-19 20:12:40
https://stackoverflow.com/q/17754230
https://stackoverflow.com/a/17754697
<p>I think there's something in the pipeline that goes wrong. This code works:</p> <pre><code>$a = (New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } $a | % { $_.Quit() } </code></pre>
<p>I think there's something in the pipeline that goes wrong. This code works:</p> <pre><code>$a = (New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } $a | % { $_.Quit() } </code></pre>
526, 638, 24067
explorer, powershell, powershell-2.0
<h1>Closing All Explorer Windows in PowerShell</h1> <p>I am writing the following code to close all explorer windows with PowerShell:</p> <pre><code>(New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() } </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,432
bash
# Closing All Explorer Windows in PowerShell I am writing the following code to close all explorer windows with PowerShell: ``` (New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() } ``` But it does not close out al...
I think there's something in the pipeline that goes wrong. This code works: ``` $a = (New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('\explorer.exe') } $a | % { $_.Quit() } ```
13925879
What does $'\n' mean in bash?
7
2012-12-18 03:36:12
<p>An answer in this stackoverflow question <a href="https://stackoverflow.com/questions/5051556/in-a-linux-shell-how-can-i-process-each-line-of-a-multiline-string">In a Linux shell how can I process each line of a multiline string?</a> mentions that <code>$'\n'</code> is a special syntax "is not available in every she...
11,846
null
2012-12-18 05:12:56
13,925,899
15
2012-12-18 03:38:05
147,356
2012-12-18 05:12:56
https://stackoverflow.com/q/13925879
https://stackoverflow.com/a/13925899
<p>See the <code>QUOTING</code> section of the <code>bash</code> man page:</p> <pre class="lang-none prettyprint-override"><code> Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escap...
<p>See the <code>QUOTING</code> section of the <code>bash</code> man page:</p> <pre class="lang-none prettyprint-override"><code> Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escap...
34, 58, 387, 390
bash, linux, shell, unix
<h1>What does $'\n' mean in bash?</h1> <p>An answer in this stackoverflow question <a href="https://stackoverflow.com/questions/5051556/in-a-linux-shell-how-can-i-process-each-line-of-a-multiline-string">In a Linux shell how can I process each line of a multiline string?</a> mentions that <code>$'\n'</code> is a specia...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,433
bash
# What does $'\n' mean in bash? An answer in this stackoverflow question [In a Linux shell how can I process each line of a multiline string?](https://stackoverflow.com/questions/5051556/in-a-linux-shell-how-can-i-process-each-line-of-a-multiline-string) mentions that `$'\n'` is a special syntax "is not available in e...
See the `QUOTING` section of the `bash` man page: ``` Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: ... \n ...
11238255
here document and double backslash
7
2012-06-28 04:51:34
<p>If I use a here document in a shell script that contains multiple backslashes '\', the shell translates it into a single backslash. Can I work around this without changing the text ?</p> <pre><code>$ cat &lt;&lt;EOF &gt; Print \\hello \\world &gt; EOF Print \hello \world </code></pre>
2,139
352,403
2023-12-24 09:19:17
11,238,274
15
2012-06-28 04:54:15
26,428
2012-06-28 04:54:15
https://stackoverflow.com/q/11238255
https://stackoverflow.com/a/11238274
<p>Quote the beginning here document marker:</p> <pre><code>cat &lt;&lt;'EOF' Print \\hello \\world EOF </code></pre>
<p>Quote the beginning here document marker:</p> <pre><code>cat &lt;&lt;'EOF' Print \\hello \\world EOF </code></pre>
387, 390
bash, shell
<h1>here document and double backslash</h1> <p>If I use a here document in a shell script that contains multiple backslashes '\', the shell translates it into a single backslash. Can I work around this without changing the text ?</p> <pre><code>$ cat &lt;&lt;EOF &gt; Print \\hello \\world &gt; EOF Print \hello \w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,434
bash
# here document and double backslash If I use a here document in a shell script that contains multiple backslashes '\', the shell translates it into a single backslash. Can I work around this without changing the text ? ``` $ cat <<EOF > Print \\hello \\world > EOF Print \hello \world ```
Quote the beginning here document marker: ``` cat <<'EOF' Print \\hello \\world EOF ```
10520605
Bash's source command not working with a file curl'd from internet
7
2012-05-09 16:53:58
<p>I am trying to source a script file from the internet using curl, like this: <code>source &lt;( curl url ); echo done</code> , and what I see is that 'done' is echoed <em>before</em> the curl even starts to download the file!</p> <p>Here's the actual command and the output:</p> <pre><code>-bash-3.2# source &lt;( c...
7,240
382,700
2015-08-28 03:05:41
10,527,064
15
2012-05-10 03:17:29
26,428
2012-05-12 07:27:11
https://stackoverflow.com/q/10520605
https://stackoverflow.com/a/10527064
<p>At first, I failed to notice that you're using Bash 3.2. That version won't source from a process substitution, but later versions such as Bash 4 do.</p> <p>You can save the file and do a normal source of it:</p> <pre><code>source /tmp/del </code></pre> <p>(to use the file from your comment)</p> <p>Or, you can u...
<p>At first, I failed to notice that you're using Bash 3.2. That version won't source from a process substitution, but later versions such as Bash 4 do.</p> <p>You can save the file and do a normal source of it:</p> <pre><code>source /tmp/del </code></pre> <p>(to use the file from your comment)</p> <p>Or, you can u...
365, 387, 390
bash, shell, url
<h1>Bash's source command not working with a file curl'd from internet</h1> <p>I am trying to source a script file from the internet using curl, like this: <code>source &lt;( curl url ); echo done</code> , and what I see is that 'done' is echoed <em>before</em> the curl even starts to download the file!</p> <p>Here's ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,435
bash
# Bash's source command not working with a file curl'd from internet I am trying to source a script file from the internet using curl, like this: `source <( curl url ); echo done` , and what I see is that 'done' is echoed *before* the curl even starts to download the file! Here's the actual command and the output: `...
At first, I failed to notice that you're using Bash 3.2. That version won't source from a process substitution, but later versions such as Bash 4 do. You can save the file and do a normal source of it: ``` source /tmp/del ``` (to use the file from your comment) Or, you can use `/dev/stdin` and a here-string and a q...
10152512
What does "\2" mean at the end of a regular expression
7
2012-04-14 09:27:24
<p>I have the following assignment:</p> <p>Words of a song are in a file called stairway.txt. Which of the following lines will be printed out after this command: </p> <pre class="lang-none prettyprint-override"><code>grep -E '(^.{4})(.{2}).*[ ]\2' stairway.txt (a) Yes, there are two paths you can go by but in the l...
8,399
1,279,707
2012-09-16 08:55:40
10,152,521
15
2012-04-14 09:29:02
330,644
2012-04-14 09:29:02
https://stackoverflow.com/q/10152512
https://stackoverflow.com/a/10152521
<p>It is a backreference.</p> <p>From <a href="http://www.selectorweb.com/grep_tutorial.html">http://www.selectorweb.com/grep_tutorial.html</a>:</p> <blockquote> <p>Backreference is an expression \n where n is a number. It matches the contents of the n'th set of parentheses in the expression.</p> </blockquote> <p...
<p>It is a backreference.</p> <p>From <a href="http://www.selectorweb.com/grep_tutorial.html">http://www.selectorweb.com/grep_tutorial.html</a>:</p> <blockquote> <p>Backreference is an expression \n where n is a number. It matches the contents of the n'th set of parentheses in the expression.</p> </blockquote> <p...
18, 58, 387
bash, linux, regex
<h1>What does "\2" mean at the end of a regular expression</h1> <p>I have the following assignment:</p> <p>Words of a song are in a file called stairway.txt. Which of the following lines will be printed out after this command: </p> <pre class="lang-none prettyprint-override"><code>grep -E '(^.{4})(.{2}).*[ ]\2' stair...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,436
bash
# What does "\2" mean at the end of a regular expression I have the following assignment: Words of a song are in a file called stairway.txt. Which of the following lines will be printed out after this command: ``` grep -E '(^.{4})(.{2}).*[ ]\2' stairway.txt (a) Yes, there are two paths you can go by but in the long...
It is a backreference. From <http://www.selectorweb.com/grep_tutorial.html>: > Backreference is an expression \n where n is a number. It matches the contents of the n'th set of parentheses in the expression. Also, the answer is (d): ``` $ grep -E '(^.{4})(.{2}).*[ ]\2' test.txt If there's a bustle in your hedgerow....
9063730
How to change a word in a file with linux shell script
7
2012-01-30 12:14:55
<p>I have a text file which have lots of lines I have a line in it which is: MyCar on</p> <p>how can I turn my car off?</p>
17,618
1,137,103
2021-01-28 07:08:53
9,063,772
15
2012-01-30 12:19:16
112,968
2012-01-30 12:19:16
https://stackoverflow.com/q/9063730
https://stackoverflow.com/a/9063772
<p>You could use sed:</p> <pre><code>sed -i 's/MyCar on/MyCar off/' path/to/file </code></pre>
<p>You could use sed:</p> <pre><code>sed -i 's/MyCar on/MyCar off/' path/to/file </code></pre>
58, 390, 17938
linux, shell, text-files
<h1>How to change a word in a file with linux shell script</h1> <p>I have a text file which have lots of lines I have a line in it which is: MyCar on</p> <p>how can I turn my car off?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,437
bash
# How to change a word in a file with linux shell script I have a text file which have lots of lines I have a line in it which is: MyCar on how can I turn my car off?
You could use sed: ``` sed -i 's/MyCar on/MyCar off/' path/to/file ```
8163922
echo "string" > file in Windows PowerShell appends non-printable character to the file
7
2011-11-17 08:11:39
<p><strong>In Windows PowerShell:</strong></p> <pre><code>echo "string" &gt; file.txt </code></pre> <p><strong>In Cygwin:</strong></p> <pre><code>$ cat file.txt :::s t r i n g $ dos2unix file.txt dos2unix: Skipping binary file file.txt </code></pre> <p>I want a simple "string" in the file. How do I do it? I.e., w...
11,259
1,051,289
2013-01-29 18:14:25
8,164,072
15
2011-11-17 08:26:04
1,021,945
2011-11-17 08:57:18
https://stackoverflow.com/q/8163922
https://stackoverflow.com/a/8164072
<p>Try <code>echo "string" | out-file -encoding ASCII file.txt</code> to get a simple ASCII-encoded txt file.</p> <p><strong>Comparison of the files produced:</strong></p> <pre><code>echo "string" | out-file -encoding ASCII file.txt </code></pre> <p>will produce a file with the following contents:</p> <pre><code>73...
<p>Try <code>echo "string" | out-file -encoding ASCII file.txt</code> to get a simple ASCII-encoded txt file.</p> <p><strong>Comparison of the files produced:</strong></p> <pre><code>echo "string" | out-file -encoding ASCII file.txt </code></pre> <p>will produce a file with the following contents:</p> <pre><code>73...
526, 1731, 4113
cygwin, dos2unix, powershell
<h1>echo "string" > file in Windows PowerShell appends non-printable character to the file</h1> <p><strong>In Windows PowerShell:</strong></p> <pre><code>echo "string" &gt; file.txt </code></pre> <p><strong>In Cygwin:</strong></p> <pre><code>$ cat file.txt :::s t r i n g $ dos2unix file.txt dos2unix: Skipping binar...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,438
bash
# echo "string" > file in Windows PowerShell appends non-printable character to the file **In Windows PowerShell:** ``` echo "string" > file.txt ``` **In Cygwin:** ``` $ cat file.txt :::s t r i n g $ dos2unix file.txt dos2unix: Skipping binary file file.txt ``` I want a simple "string" in the file. How do I do it...
Try `echo "string" | out-file -encoding ASCII file.txt` to get a simple ASCII-encoded txt file. **Comparison of the files produced:** ``` echo "string" | out-file -encoding ASCII file.txt ``` will produce a file with the following contents: ``` 73 74 72 69 6E 67 0D 0A (string..) ``` however ``` echo "string" > fi...
7922854
While Do Statement with blank/empty grep return?
7
2011-10-27 21:48:12
<p>This is the code for my foobar.sh:</p> <pre><code>!#/bin/bash while [ 1 ] do pid=`ps -ef | grep "mylittleprogram" | grep -v grep | awk ' {print $2}'` echo $pid if [ "$pid"="" ] then echo "Process has ended lets get this show on the road..." exit else echo "Pro...
39,107
940,469
2018-11-13 10:17:31
7,922,889
15
2011-10-27 21:52:31
947,357
2018-11-13 10:17:31
https://stackoverflow.com/q/7922854
https://stackoverflow.com/a/7922889
<p>Instead of </p> <pre><code>if [ "$pid"="" ] </code></pre> <p>please try</p> <pre><code>if [ "$pid" = "" ] </code></pre> <p>The whitespace is around <code>=</code> is important. </p> <p>You can also try</p> <pre><code>if [ -z "$pid" ] </code></pre>
<p>Instead of </p> <pre><code>if [ "$pid"="" ] </code></pre> <p>please try</p> <pre><code>if [ "$pid" = "" ] </code></pre> <p>The whitespace is around <code>=</code> is important. </p> <p>You can also try</p> <pre><code>if [ -z "$pid" ] </code></pre>
387, 390, 2773, 17310
bash, if-statement, shell, while-loop
<h1>While Do Statement with blank/empty grep return?</h1> <p>This is the code for my foobar.sh:</p> <pre><code>!#/bin/bash while [ 1 ] do pid=`ps -ef | grep "mylittleprogram" | grep -v grep | awk ' {print $2}'` echo $pid if [ "$pid"="" ] then echo "Process has ended lets get this show on th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,439
bash
# While Do Statement with blank/empty grep return? This is the code for my foobar.sh: ``` !#/bin/bash while [ 1 ] do pid=`ps -ef | grep "mylittleprogram" | grep -v grep | awk ' {print $2}'` echo $pid if [ "$pid"="" ] then echo "Process has ended lets get this show on the road..." ...
Instead of ``` if [ "$pid"="" ] ``` please try ``` if [ "$pid" = "" ] ``` The whitespace is around `=` is important. You can also try ``` if [ -z "$pid" ] ```
5968107
Get everything in a file after a grep'd string
7
2011-05-11 17:19:24
<p>Yesterday a situation came up where someone needed me to separate out the tail end of a file, specified as being everything after a particular string (for sake of argument, "FOO"). I needed to do this immediately so went with the option that I knew would work and disregarded The Right Way or The Best Way, and went ...
9,366
144,642
2014-01-24 11:25:26
5,968,119
15
2011-05-11 17:21:13
643,977
2011-05-11 17:21:13
https://stackoverflow.com/q/5968107
https://stackoverflow.com/a/5968119
<pre><code>sed -n '/re/,$p' file </code></pre> <p>is what occurs to me right off.</p>
<pre><code>sed -n '/re/,$p' file </code></pre> <p>is what occurs to me right off.</p>
34, 387, 390, 1271
bash, grep, shell, unix
<h1>Get everything in a file after a grep'd string</h1> <p>Yesterday a situation came up where someone needed me to separate out the tail end of a file, specified as being everything after a particular string (for sake of argument, "FOO"). I needed to do this immediately so went with the option that I knew would work ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,440
bash
# Get everything in a file after a grep'd string Yesterday a situation came up where someone needed me to separate out the tail end of a file, specified as being everything after a particular string (for sake of argument, "FOO"). I needed to do this immediately so went with the option that I knew would work and disreg...
``` sed -n '/re/,$p' file ``` is what occurs to me right off.
5650112
How to replace string in files and file and folder names recursively with PowerShell?
7
2011-04-13 13:33:04
<p>With PowerShell (although other suggestions are welcome), how does one recursively loop a directory/folder and </p> <ol> <li>replace text A with B in all files, </li> <li>rename all files so that A is replaced by B, and last </li> <li>rename all folders also so that A is replaced by B?</li> </ol>
12,405
46,343
2014-10-13 15:54:55
5,802,513
15
2011-04-27 10:18:58
46,343
2011-04-27 10:18:58
https://stackoverflow.com/q/5650112
https://stackoverflow.com/a/5802513
<p>With a few requirements refinements, I ended up with this script:</p> <pre><code>$match = "MyAssembly" $replacement = Read-Host "Please enter a solution name" $files = Get-ChildItem $(get-location) -filter *MyAssembly* -Recurse $files | Sort-Object -Descending -Property { $_.FullName } | Rename-Item -new...
<p>With a few requirements refinements, I ended up with this script:</p> <pre><code>$match = "MyAssembly" $replacement = Read-Host "Please enter a solution name" $files = Get-ChildItem $(get-location) -filter *MyAssembly* -Recurse $files | Sort-Object -Descending -Property { $_.FullName } | Rename-Item -new...
526, 34595
powershell, windows-7
<h1>How to replace string in files and file and folder names recursively with PowerShell?</h1> <p>With PowerShell (although other suggestions are welcome), how does one recursively loop a directory/folder and </p> <ol> <li>replace text A with B in all files, </li> <li>rename all files so that A is replaced by B, and l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,441
bash
# How to replace string in files and file and folder names recursively with PowerShell? With PowerShell (although other suggestions are welcome), how does one recursively loop a directory/folder and 1. replace text A with B in all files, 2. rename all files so that A is replaced by B, and last 3. rename all folders a...
With a few requirements refinements, I ended up with this script: ``` $match = "MyAssembly" $replacement = Read-Host "Please enter a solution name" $files = Get-ChildItem $(get-location) -filter *MyAssembly* -Recurse $files | Sort-Object -Descending -Property { $_.FullName } | Rename-Item -newname { $_.name...
5376740
bash command and return status
7
2011-03-21 11:05:21
<p>pkill return status > 0 if error ( for example if not found process ). How to return 0 status independing result of pkill ?</p>
4,284
418,507
2011-03-21 11:09:32
5,376,765
15
2011-03-21 11:07:10
616,700
2011-03-21 11:07:10
https://stackoverflow.com/q/5376740
https://stackoverflow.com/a/5376765
<p>Either just don't test for the result, or do:</p> <pre><code>pkill whatever || true </code></pre>
<p>Either just don't test for the result, or do:</p> <pre><code>pkill whatever || true </code></pre>
387
bash
<h1>bash command and return status</h1> <p>pkill return status > 0 if error ( for example if not found process ). How to return 0 status independing result of pkill ?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,442
bash
# bash command and return status pkill return status > 0 if error ( for example if not found process ). How to return 0 status independing result of pkill ?
Either just don't test for the result, or do: ``` pkill whatever || true ```
5344710
recursive diff is extremely slow - checking contents of directories
7
2011-03-17 20:17:25
<p>I am running a diff on two directories, recursively, with a few options. The directories are somewhat large, however, I am trying to just see the differences in the contents of folders, not between the files, using the -q option (am i using this right?)</p> <p>I have also tried rsync dry run, that seems to take equa...
8,025
609,330
2020-11-05 10:34:39
5,344,869
15
2011-03-17 20:30:16
68,587
2015-03-23 00:00:43
https://stackoverflow.com/q/5344710
https://stackoverflow.com/a/5344869
<p>When files are different <code>diff</code> will be able to figure that out fairly quickly. When they're the same, though, it has to scan the files in full to verify that they are indeed byte-for-byte identical.</p> <p>If all you care about is differences in file names and don't want to inspect the contents of the f...
<p>When files are different <code>diff</code> will be able to figure that out fairly quickly. When they're the same, though, it has to scan the files in full to verify that they are indeed byte-for-byte identical.</p> <p>If all you care about is differences in file names and don't want to inspect the contents of the f...
387, 606, 1159
bash, diff, rsync
<h1>recursive diff is extremely slow - checking contents of directories</h1> <p>I am running a diff on two directories, recursively, with a few options. The directories are somewhat large, however, I am trying to just see the differences in the contents of folders, not between the files, using the -q option (am i using...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,443
bash
# recursive diff is extremely slow - checking contents of directories I am running a diff on two directories, recursively, with a few options. The directories are somewhat large, however, I am trying to just see the differences in the contents of folders, not between the files, using the -q option (am i using this rig...
When files are different `diff` will be able to figure that out fairly quickly. When they're the same, though, it has to scan the files in full to verify that they are indeed byte-for-byte identical. If all you care about is differences in file names and don't want to inspect the contents of the files, try something l...
4644350
Backspacing in Bash
7
2011-01-10 06:49:15
<p>How do you backspace the line you just wrote with bash and put a new one over its spot? I know it's possible, Aptitude (apt-get) use it for some of the updating stuff and it looks great.</p>
8,506
140,448
2024-02-08 23:43:47
4,644,497
15
2011-01-10 07:14:43
26,428
2011-01-10 07:14:43
https://stackoverflow.com/q/4644350
https://stackoverflow.com/a/4644497
<p>Try this:</p> <pre><code>$ printf "12345678\rABC\n" ABC45678 </code></pre> <p>As you can see, outputting a carriage return moves the cursor to the beginning of the same line.</p> <p>You can clear the line like this:</p> <pre><code>$ printf "12345678\r$(tput el)ABC\n" ABC </code></pre> <p>Using <code>tput</code>...
<p>Try this:</p> <pre><code>$ printf "12345678\rABC\n" ABC45678 </code></pre> <p>As you can see, outputting a carriage return moves the cursor to the beginning of the same line.</p> <p>You can clear the line like this:</p> <pre><code>$ printf "12345678\r$(tput el)ABC\n" ABC </code></pre> <p>Using <code>tput</code>...
387, 35759
backspace, bash
<h1>Backspacing in Bash</h1> <p>How do you backspace the line you just wrote with bash and put a new one over its spot? I know it's possible, Aptitude (apt-get) use it for some of the updating stuff and it looks great.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,444
bash
# Backspacing in Bash How do you backspace the line you just wrote with bash and put a new one over its spot? I know it's possible, Aptitude (apt-get) use it for some of the updating stuff and it looks great.
Try this: ``` $ printf "12345678\rABC\n" ABC45678 ``` As you can see, outputting a carriage return moves the cursor to the beginning of the same line. You can clear the line like this: ``` $ printf "12345678\r$(tput el)ABC\n" ABC ``` Using `tput` gives you a portable way to send control characters to the terminal....
3680226
How to read and extract information from a file that is being continuously updated?
7
2010-09-09 20:14:01
<p>This is how I am planning to build my utilities for a project :</p> <ul> <li><p><strong>logdump</strong> dumps log results to file <strong>log</strong>. The results are appended to the existing results if the file is already there (like if a new file is created every month, the results are appended to the same file...
3,611
113,124
2010-09-09 22:49:44
3,680,237
15
2010-09-09 20:16:26
68,587
2010-09-09 20:16:26
https://stackoverflow.com/q/3680226
https://stackoverflow.com/a/3680237
<p><code>tail -f</code> will read from a file and monitor it for updates when it reaches EOF instead of quitting outright. It's an easy way to read a log file "live". Could be as simple as:</p> <pre><code>tail -f log.file | extract </code></pre> <p>Or maybe <code>tail -n 0 -f</code> so it only prints new lines, not e...
<p><code>tail -f</code> will read from a file and monitor it for updates when it reaches EOF instead of quitting outright. It's an easy way to read a log file "live". Could be as simple as:</p> <pre><code>tail -f log.file | extract </code></pre> <p>Or maybe <code>tail -n 0 -f</code> so it only prints new lines, not e...
8, 10, 390, 580
c, c++, perl, shell
<h1>How to read and extract information from a file that is being continuously updated?</h1> <p>This is how I am planning to build my utilities for a project :</p> <ul> <li><p><strong>logdump</strong> dumps log results to file <strong>log</strong>. The results are appended to the existing results if the file is alread...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,445
bash
# How to read and extract information from a file that is being continuously updated? This is how I am planning to build my utilities for a project : - **logdump** dumps log results to file **log**. The results are appended to the existing results if the file is already there (like if a new file is created every mont...
`tail -f` will read from a file and monitor it for updates when it reaches EOF instead of quitting outright. It's an easy way to read a log file "live". Could be as simple as: ``` tail -f log.file | extract ``` Or maybe `tail -n 0 -f` so it only prints new lines, not existing lines. Or `tail -n +0 -f` to display the ...
74982074
How to resolve 'curl: option --data-raw: is unknown' error
6
2023-01-02 11:50:02
<p>I am trying to run shell script with a curl command as below with --data-raw as body.</p> <pre><code>curl --location --request POST '&lt;URL&gt;' \ --header 'Content-Type: application/json' \ --data-raw '{ &quot;blocks&quot;: [ { &quot;type&quot;: &quot;header&quot;, &quot;text&quot;: { &quot;type&quot;: &...
29,696
2,509,396
2025-02-19 12:33:35
74,982,136
15
2023-01-02 11:57:05
465,183
2023-01-02 11:57:05
https://stackoverflow.com/q/74982074
https://stackoverflow.com/a/74982136
<h4>Here, you have 2 issue.</h4> <ul> <li>your JSON is invalid, the <code>,</code> line 14 need to be removed</li> <li>use <code>--data</code> and a <em>heredoc</em> :</li> </ul> <pre><code>curl --location --request POST '&lt;URL&gt;' \ --header 'Content-Type: application/json' \ --data &quot;@/dev/stdin&quot;&lt;...
<h4>Here, you have 2 issue.</h4> <ul> <li>your JSON is invalid, the <code>,</code> line 14 need to be removed</li> <li>use <code>--data</code> and a <em>heredoc</em> :</li> </ul> <pre><code>curl --location --request POST '&lt;URL&gt;' \ --header 'Content-Type: application/json' \ --data &quot;@/dev/stdin&quot;&lt;...
390, 1554, 10327
curl, sh, shell
<h1>How to resolve 'curl: option --data-raw: is unknown' error</h1> <p>I am trying to run shell script with a curl command as below with --data-raw as body.</p> <pre><code>curl --location --request POST '&lt;URL&gt;' \ --header 'Content-Type: application/json' \ --data-raw '{ &quot;blocks&quot;: [ { &quot;type&q...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,446
bash
# How to resolve 'curl: option --data-raw: is unknown' error I am trying to run shell script with a curl command as below with --data-raw as body. ``` curl --location --request POST '<URL>' \ --header 'Content-Type: application/json' \ --data-raw '{ "blocks": [ { "type": "header", "text": { "type": "plain_t...
#### Here, you have 2 issue. - your JSON is invalid, the `,` line 14 need to be removed - use `--data` and a *heredoc* : ``` curl --location --request POST '<URL>' \ --header 'Content-Type: application/json' \ --data "@/dev/stdin"<<EOF { "blocks": [ { "type": "header", "text": { "type": ...
70236670
'DEBIAN_FRONTEND=noninteractive' not working inside shell script with apt-get
6
2021-12-05 17:15:36
<p>I'm buildinga a docker image using a Dockerfile to build it. I have put <code>ARG DEBIAN_FRONTEND=noninteractive</code> in the beginning of the Dockerfile to avoid debconf warnings while building.</p> <p>The warnings does not show up when using <code>apt-get install</code> inside the Dockerfile. However when executi...
20,990
15,387,588
2021-12-05 18:12:38
70,236,753
15
2021-12-05 17:24:35
3,691,891
2021-12-05 17:24:35
https://stackoverflow.com/q/70236670
https://stackoverflow.com/a/70236753
<p>Drop <code>sudo</code> in your script, there is point to use it if you're running as root. This is also the reason that DEBIAN_FRONTEND has no effect - sudo drops your current user's environment for security reasons, you'd have to use with -E option to make it work.</p>
<p>Drop <code>sudo</code> in your script, there is point to use it if you're running as root. This is also the reason that DEBIAN_FRONTEND has no effect - sudo drops your current user's environment for security reasons, you'd have to use with -E option to make it work.</p>
2080, 10327, 82135, 90304, 108477
apt, debconf, docker, dockerfile, sh
<h1>'DEBIAN_FRONTEND=noninteractive' not working inside shell script with apt-get</h1> <p>I'm buildinga a docker image using a Dockerfile to build it. I have put <code>ARG DEBIAN_FRONTEND=noninteractive</code> in the beginning of the Dockerfile to avoid debconf warnings while building.</p> <p>The warnings does not show...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,447
bash
# 'DEBIAN_FRONTEND=noninteractive' not working inside shell script with apt-get I'm buildinga a docker image using a Dockerfile to build it. I have put `ARG DEBIAN_FRONTEND=noninteractive` in the beginning of the Dockerfile to avoid debconf warnings while building. The warnings does not show up when using `apt-get in...
Drop `sudo` in your script, there is point to use it if you're running as root. This is also the reason that DEBIAN_FRONTEND has no effect - sudo drops your current user's environment for security reasons, you'd have to use with -E option to make it work.
68308822
Powershell: Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Uri"
6
2021-07-08 21:30:22
<p>Goal: I want to send a POST API request to JIRA with irm (Invoke-RestMethod).</p> <p>Environment:</p> <ul> <li>OS: Windows 10 64 bit</li> <li>Powershell 5 (I think it's 5, it's the default that comes with Windows)</li> </ul> <p>Script:</p> <pre><code>$Body = @{ 'fields' = @{ 'project' = @{'key' = 'ABC'} ...
13,159
10,968,292
2021-07-08 21:41:39
68,308,920
15
2021-07-08 21:41:39
16,106,482
2021-07-08 21:41:39
https://stackoverflow.com/q/68308822
https://stackoverflow.com/a/68308920
<p>Simply change the $params to @params, this is called splatting.</p> <p>&quot;Splatting is a method of passing a collection of parameter values to a command as a unit.&quot;</p> <p><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1" rel="no...
<p>Simply change the $params to @params, this is called splatting.</p> <p>&quot;Splatting is a method of passing a collection of parameter values to a command as a unit.&quot;</p> <p><a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1" rel="no...
526
powershell
<h1>Powershell: Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Uri"</h1> <p>Goal: I want to send a POST API request to JIRA with irm (Invoke-RestMethod).</p> <p>Environment:</p> <ul> <li>OS: Windows 10 64 bit</li> <li>Powershell 5 (I think it's 5, it's the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,448
bash
# Powershell: Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Uri" Goal: I want to send a POST API request to JIRA with irm (Invoke-RestMethod). Environment: - OS: Windows 10 64 bit - Powershell 5 (I think it's 5, it's the default that comes with Windows...
Simply change the $params to @params, this is called splatting. "Splatting is a method of passing a collection of parameter values to a command as a unit." <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1> ``` $response = irm @params ```
66780525
Exporting an env-file with values containing space
6
2021-03-24 11:56:15
<p>I'm using environment files to configure web apps. Recently i had the need to export a value like this:</p> <pre><code>RUBYOPT='-W:no-derecated -W:no-experimental' </code></pre> <p>This is contained in a file <code>test.env</code> with other config vars.</p> <p>I use this command to export all the env vars in the fi...
5,951
109,274
2021-03-24 12:41:16
66,780,625
15
2021-03-24 12:02:55
7,582,247
2021-03-24 12:41:16
https://stackoverflow.com/q/66780525
https://stackoverflow.com/a/66780625
<p>The construct with <code>export $(cat test.env | xargs)</code> is very fragile and you get shell interpretation of the <code>'</code> characters (and other special characters) so <code>RUBYOPT='-W:no-derecated -W:no-experimental'</code> therefore becomes <code>RUBYOPT=-W:no-derecated -W:no-experimental</code>. Note...
<p>The construct with <code>export $(cat test.env | xargs)</code> is very fragile and you get shell interpretation of the <code>'</code> characters (and other special characters) so <code>RUBYOPT='-W:no-derecated -W:no-experimental'</code> therefore becomes <code>RUBYOPT=-W:no-derecated -W:no-experimental</code>. Note...
387, 390, 9013, 10804, 31134
bash, command-line-arguments, environment-variables, quoting, shell
<h1>Exporting an env-file with values containing space</h1> <p>I'm using environment files to configure web apps. Recently i had the need to export a value like this:</p> <pre><code>RUBYOPT='-W:no-derecated -W:no-experimental' </code></pre> <p>This is contained in a file <code>test.env</code> with other config vars.</p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,449
bash
# Exporting an env-file with values containing space I'm using environment files to configure web apps. Recently i had the need to export a value like this: ``` RUBYOPT='-W:no-derecated -W:no-experimental' ``` This is contained in a file `test.env` with other config vars. I use this command to export all the env va...
The construct with `export $(cat test.env | xargs)` is very fragile and you get shell interpretation of the `'` characters (and other special characters) so `RUBYOPT='-W:no-derecated -W:no-experimental'` therefore becomes `RUBYOPT=-W:no-derecated -W:no-experimental`. Note the missing `'`. This was not a problem until y...
61571006
PowerShell JSON string escape (backslash)
6
2020-05-03 07:29:11
<p>I need to HttpPost a Json-body to a ASP.NET Core Web Api endpoint (controller) using a PowerShell script. </p> <pre><code>$CurrentWindowsIdentity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $CurrentPrincipalName = $CurrentWindowsIdentity.Identity.Name # Buil...
19,204
270,085
2023-08-10 15:45:46
61,571,069
15
2020-05-03 07:36:35
45,375
2023-08-10 15:45:46
https://stackoverflow.com/q/61571006
https://stackoverflow.com/a/61571069
<p>The robust way to create JSON text is to <strong>construct your data as a hash table (<code>@{ ... }</code>) or custom object ( <code>[pscustomobject] @{ ... }</code>)</strong> first and <strong>pipe to <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/ConvertTo-Json" rel="no...
<p>The robust way to create JSON text is to <strong>construct your data as a hash table (<code>@{ ... }</code>) or custom object ( <code>[pscustomobject] @{ ... }</code>)</strong> first and <strong>pipe to <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/ConvertTo-Json" rel="no...
526, 1508
json, powershell
<h1>PowerShell JSON string escape (backslash)</h1> <p>I need to HttpPost a Json-body to a ASP.NET Core Web Api endpoint (controller) using a PowerShell script. </p> <pre><code>$CurrentWindowsIdentity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $CurrentPrincipalN...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,450
bash
# PowerShell JSON string escape (backslash) I need to HttpPost a Json-body to a ASP.NET Core Web Api endpoint (controller) using a PowerShell script. ``` $CurrentWindowsIdentity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $CurrentPrincipalName = $CurrentWindows...
The robust way to create JSON text is to **construct your data as a hash table (`@{ ... }`) or custom object ( `[pscustomobject] @{ ... }`)** first and **pipe to [`ConvertTo-Json`](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/ConvertTo-Json)**: ``` $JsonString = @{ CurrentPrincipa...
60506222
encode / decode binary data in a qr-code using qrencode and zbarimg in bash
6
2020-03-03 11:26:34
<p>I have some binary data that I want to encode in a qr-code and then be able to decode, all of that in bash. After a search, it looks like I should use <code>qrencode</code> for encoding, and <code>zbarimg</code> for decoding. After a bit of troubleshooting, I still do not manage to decode what I had encoded</p> <p>A...
16,867
5,958,323
2024-02-22 21:27:29
60,518,608
15
2020-03-04 03:22:20
512,904
2020-04-29 03:34:33
https://stackoverflow.com/q/60506222
https://stackoverflow.com/a/60518608
<p>My pull request has been <a href="https://github.com/mchehab/zbar/pull/64#issuecomment-598644895" rel="noreferrer">applied</a>. ZBar <a href="https://github.com/mchehab/zbar/releases/tag/0.23.1" rel="noreferrer">version 0.23.1</a> and newer will be able to decode binary QR codes:</p> <pre><code>zbarimg --raw --onesh...
<p>My pull request has been <a href="https://github.com/mchehab/zbar/pull/64#issuecomment-598644895" rel="noreferrer">applied</a>. ZBar <a href="https://github.com/mchehab/zbar/releases/tag/0.23.1" rel="noreferrer">version 0.23.1</a> and newer will be able to decode binary QR codes:</p> <pre><code>zbarimg --raw --onesh...
368, 387, 1951, 4387, 4951
bash, binary, decode, encode, qr-code
<h1>encode / decode binary data in a qr-code using qrencode and zbarimg in bash</h1> <p>I have some binary data that I want to encode in a qr-code and then be able to decode, all of that in bash. After a search, it looks like I should use <code>qrencode</code> for encoding, and <code>zbarimg</code> for decoding. After ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,451
bash
# encode / decode binary data in a qr-code using qrencode and zbarimg in bash I have some binary data that I want to encode in a qr-code and then be able to decode, all of that in bash. After a search, it looks like I should use `qrencode` for encoding, and `zbarimg` for decoding. After a bit of troubleshooting, I sti...
My pull request has been [applied](https://github.com/mchehab/zbar/pull/64#issuecomment-598644895). ZBar [version 0.23.1](https://github.com/mchehab/zbar/releases/tag/0.23.1) and newer will be able to decode binary QR codes: ``` zbarimg --raw --oneshot -Sbinary qr.png zbarcam --raw --oneshot -Sbinary ``` --- QR code...
54289105
List all folders and subfolders in a given structure with filesize
6
2019-01-21 11:33:27
<p>I'm trying to list the folderstructure of a disc and each folders size.</p> <p>I've got the folderstructure down, now i just need to output each folders size. </p> <p>According to <a href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/dir" rel="noreferrer">https://learn.microsoft...
37,509
2,902,996
2021-09-08 18:04:53
54,297,192
15
2019-01-21 20:15:57
45,375
2021-09-08 18:04:53
https://stackoverflow.com/q/54289105
https://stackoverflow.com/a/54297192
<p>A <strong>PowerShell solution</strong> that builds on <a href="https://stackoverflow.com/a/54289749/45375">montonero's helpful answer</a> and improves the following aspects:</p> <ul> <li>control over the recursion depth</li> <li>improved performance</li> <li>better integration with other cmdlets for composable func...
<p>A <strong>PowerShell solution</strong> that builds on <a href="https://stackoverflow.com/a/54289749/45375">montonero's helpful answer</a> and improves the following aspects:</p> <ul> <li>control over the recursion depth</li> <li>improved performance</li> <li>better integration with other cmdlets for composable func...
64, 526, 1231, 2631
cmd, command-line, powershell, windows
<h1>List all folders and subfolders in a given structure with filesize</h1> <p>I'm trying to list the folderstructure of a disc and each folders size.</p> <p>I've got the folderstructure down, now i just need to output each folders size. </p> <p>According to <a href="https://learn.microsoft.com/en-us/windows-server/a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,452
bash
# List all folders and subfolders in a given structure with filesize I'm trying to list the folderstructure of a disc and each folders size. I've got the folderstructure down, now i just need to output each folders size. According to <https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/d...
A **PowerShell solution** that builds on [montonero's helpful answer](https://stackoverflow.com/a/54289749/45375) and improves the following aspects: - control over the recursion depth - improved performance - better integration with other cmdlets for composable functionality Sample calls, based on function `Get-Dire...
53921672
Splitting a list in bash
6
2018-12-25 10:53:51
<p>I have this script:</p> <pre><code>#!/bin/bash list="a b c d" for item in ${list[@]}; do echo "${item}" done </code></pre> <p>When I run it this is the output:</p> <pre><code>a b c d </code></pre> <p>This is <strong>exactly</strong> what I want. However, <code>shellcheck</code> hates this and throws an error...
5,168
3,691,698
2022-05-09 20:31:38
53,921,691
15
2018-12-25 10:56:04
5,958,455
2018-12-25 11:38:24
https://stackoverflow.com/q/53921672
https://stackoverflow.com/a/53921691
<p>This is not an array:</p> <pre><code>list="a b c d" </code></pre> <p>You're just assigning <code>list</code> to a string of length 7.</p> <p>To make it a real array:</p> <pre><code>list=(a b c d) </code></pre> <p>Then with <code>for item in "${list[@]}"</code>, you get the correct result.</p> <hr> <p>For your...
<p>This is not an array:</p> <pre><code>list="a b c d" </code></pre> <p>You're just assigning <code>list</code> to a string of length 7.</p> <p>To make it a real array:</p> <pre><code>list=(a b c d) </code></pre> <p>Then with <code>for item in "${list[@]}"</code>, you get the correct result.</p> <hr> <p>For your...
387, 117067
bash, shellcheck
<h1>Splitting a list in bash</h1> <p>I have this script:</p> <pre><code>#!/bin/bash list="a b c d" for item in ${list[@]}; do echo "${item}" done </code></pre> <p>When I run it this is the output:</p> <pre><code>a b c d </code></pre> <p>This is <strong>exactly</strong> what I want. However, <code>shellcheck</co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,453
bash
# Splitting a list in bash I have this script: ``` #!/bin/bash list="a b c d" for item in ${list[@]}; do echo "${item}" done ``` When I run it this is the output: ``` a b c d ``` This is **exactly** what I want. However, `shellcheck` hates this and throws an error: ``` for item in ${list[@]}; do ^...
This is not an array: ``` list="a b c d" ``` You're just assigning `list` to a string of length 7. To make it a real array: ``` list=(a b c d) ``` Then with `for item in "${list[@]}"`, you get the correct result. --- For your updated question, you should just use `$list` instead of `${list[@]}`, because `list` i...
51493815
Powershell capture first filename from a folder
6
2018-07-24 08:20:40
<p>Newbie to powershell I need to capture first file name from a directory. However my current script captures all file names. Please suggest changes to my code below.</p> <pre><code># Storing path of the desired folder $path = "C:\foo\bar\" $contents = Get-ChildItem -Path $path -Force -Recurse $contents.Name </code...
21,133
5,810,015
2020-06-25 05:14:30
51,493,908
15
2018-07-24 08:25:58
10,071,078
2020-06-25 05:14:30
https://stackoverflow.com/q/51493815
https://stackoverflow.com/a/51493908
<p>You could use Select-Object with the -first switch and set it to 1</p> <pre><code>$path = &quot;C:\foo\bar\&quot; $contents = Get-ChildItem -Path $path -Force -Recurse -File | Select-Object -First 1 </code></pre> <p>I've added the -File switch to <code>Get-ChildItem</code> as well, since you only want to return file...
<p>You could use Select-Object with the -first switch and set it to 1</p> <pre><code>$path = &quot;C:\foo\bar\&quot; $contents = Get-ChildItem -Path $path -Force -Recurse -File | Select-Object -First 1 </code></pre> <p>I've added the -File switch to <code>Get-ChildItem</code> as well, since you only want to return file...
526
powershell
<h1>Powershell capture first filename from a folder</h1> <p>Newbie to powershell I need to capture first file name from a directory. However my current script captures all file names. Please suggest changes to my code below.</p> <pre><code># Storing path of the desired folder $path = "C:\foo\bar\" $contents = Get-Ch...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,454
bash
# Powershell capture first filename from a folder Newbie to powershell I need to capture first file name from a directory. However my current script captures all file names. Please suggest changes to my code below. ``` # Storing path of the desired folder $path = "C:\foo\bar\" $contents = Get-ChildItem -Path $path ...
You could use Select-Object with the -first switch and set it to 1 ``` $path = "C:\foo\bar\" $contents = Get-ChildItem -Path $path -Force -Recurse -File | Select-Object -First 1 ``` I've added the -File switch to `Get-ChildItem` as well, since you only want to return files.
50765949
redirect stdout, stderr from powershell script as admin through start-process
6
2018-06-08 17:43:59
<p>Inside a powershell script, I'm running a command which starts a new powershell as admin (if I'm not and if needed, depending on <code>$arg</code>) and then runs the script.</p> <p>I'm trying to redirect stdout and stderr to the first terminal.</p> <p>Not trying to make things easier, there are arguments too.</p> ...
7,094
1,447,389
2024-10-28 20:43:58
50,770,757
15
2018-06-09 03:53:51
45,375
2024-10-28 20:43:58
https://stackoverflow.com/q/50765949
https://stackoverflow.com/a/50770757
<p>PowerShell's <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Start-Process" rel="nofollow noreferrer"><code>Start-Process</code></a> cmdlet:</p> <ul> <li>does have <code>-RedirectStandardOut</code> and <code>-RedirectStandardError</code> parameters,</li> <li>but <em>synta...
<p>PowerShell's <a href="https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Start-Process" rel="nofollow noreferrer"><code>Start-Process</code></a> cmdlet:</p> <ul> <li>does have <code>-RedirectStandardOut</code> and <code>-RedirectStandardError</code> parameters,</li> <li>but <em>synta...
526, 26462
powershell, start-process
<h1>redirect stdout, stderr from powershell script as admin through start-process</h1> <p>Inside a powershell script, I'm running a command which starts a new powershell as admin (if I'm not and if needed, depending on <code>$arg</code>) and then runs the script.</p> <p>I'm trying to redirect stdout and stderr to the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,455
bash
# redirect stdout, stderr from powershell script as admin through start-process Inside a powershell script, I'm running a command which starts a new powershell as admin (if I'm not and if needed, depending on `$arg`) and then runs the script. I'm trying to redirect stdout and stderr to the first terminal. Not trying...
PowerShell's [`Start-Process`](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Start-Process) cmdlet: - does have `-RedirectStandardOut` and `-RedirectStandardError` parameters, - but *syntactically* they cannot be combined with `-Verb Runas`, the argument required to start a proces...
45856411
Exclude a directory from find linux
6
2017-08-24 08:17:41
<p>I want to exclude all directories from the <code>find</code> command target. I can use this:</p> <pre><code>find / -not -path /my/path -name name </code></pre> <p>But this still keep looking at all subdirectories of <code>/my/path</code>. Is there a way to exclude the directory and all its subdirectories from <cod...
25,149
2,786,156
2018-08-31 04:00:14
45,856,447
15
2017-08-24 08:19:42
1,454,708
2017-08-24 08:19:42
https://stackoverflow.com/q/45856411
https://stackoverflow.com/a/45856447
<p>with <code>-prune</code></p> <pre><code>find . -name directory_to_exclude -prune -o ... </code></pre> <p>to exclude many directories</p> <pre><code>find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ... </code></pre>
<p>with <code>-prune</code></p> <pre><code>find . -name directory_to_exclude -prune -o ... </code></pre> <p>to exclude many directories</p> <pre><code>find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ... </code></pre>
58, 387, 10193
bash, find, linux
<h1>Exclude a directory from find linux</h1> <p>I want to exclude all directories from the <code>find</code> command target. I can use this:</p> <pre><code>find / -not -path /my/path -name name </code></pre> <p>But this still keep looking at all subdirectories of <code>/my/path</code>. Is there a way to exclude the d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,456
bash
# Exclude a directory from find linux I want to exclude all directories from the `find` command target. I can use this: ``` find / -not -path /my/path -name name ``` But this still keep looking at all subdirectories of `/my/path`. Is there a way to exclude the directory and all its subdirectories from `find`?
with `-prune` ``` find . -name directory_to_exclude -prune -o ... ``` to exclude many directories ``` find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ... ```
45593418
Register DLL in GAC (CMD or PowerShell)
6
2017-08-09 14:22:59
<p>I'm trying to register a <code>.DLL</code> in the <code>GAC</code>. Currently I'm having trouble to prove it has been added to the assembly.</p> <p>Using the command</p> <blockquote> <p>C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll"</p> </blockquot...
36,744
8,440,300
2022-04-14 16:20:18
45,594,261
15
2017-08-09 15:00:58
2,829,492
2017-08-09 15:00:58
https://stackoverflow.com/q/45593418
https://stackoverflow.com/a/45594261
<p>Remember to run PowerShell as administrator or this won't work.</p> <pre><code>$dllpath = c:\path\yourdll.dll [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") $publish = New-Object System.EnterpriseServices.Internal.Publis...
<p>Remember to run PowerShell as administrator or this won't work.</p> <pre><code>$dllpath = c:\path\yourdll.dll [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") $publish = New-Object System.EnterpriseServices.Internal.Publis...
64, 457, 526, 2640
dll, gac, powershell, windows
<h1>Register DLL in GAC (CMD or PowerShell)</h1> <p>I'm trying to register a <code>.DLL</code> in the <code>GAC</code>. Currently I'm having trouble to prove it has been added to the assembly.</p> <p>Using the command</p> <blockquote> <p>C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gac...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,457
bash
# Register DLL in GAC (CMD or PowerShell) I'm trying to register a `.DLL` in the `GAC`. Currently I'm having trouble to prove it has been added to the assembly. Using the command > C:\Windows\System32>%programfiles(x86)%\Microsoft > SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll" The prompt tells me tha...
Remember to run PowerShell as administrator or this won't work. ``` $dllpath = c:\path\yourdll.dll [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") $publish = New-Object System.EnterpriseServices.Internal.Publish ...
44838931
How to run a local script in mongo shell - Solution load()
6
2017-06-30 05:04:49
<p>I think this is a very basic question but I'm stuck. I'm connected to remote mongo instance (mLab) via a MongoDB shell. This has been fine for one-liners, but now I want to run larger commands but often, thus the need to do it from an already connected shell. </p> <p>How can I run my local script.js from the mongo ...
16,698
5,315,266
2019-04-11 14:26:12
44,838,983
15
2017-06-30 05:09:51
6,550,599
2019-04-11 14:26:12
https://stackoverflow.com/q/44838931
https://stackoverflow.com/a/44838983
<p>Execute a JavaScript file</p> <p>You can specify a .js file to the mongo shell, and mongo will execute the JavaScript directly. Consider the following example:</p> <pre><code>mongo localhost:27017/test myjsfile.js </code></pre> <p>Replace the Localhost URL with your Mlab URL </p> <p>Or if you are in the shell Yo...
<p>Execute a JavaScript file</p> <p>You can specify a .js file to the mongo shell, and mongo will execute the JavaScript directly. Consider the following example:</p> <pre><code>mongo localhost:27017/test myjsfile.js </code></pre> <p>Replace the Localhost URL with your Mlab URL </p> <p>Or if you are in the shell Yo...
30073, 69521
mongodb, mongo-shell
<h1>How to run a local script in mongo shell - Solution load()</h1> <p>I think this is a very basic question but I'm stuck. I'm connected to remote mongo instance (mLab) via a MongoDB shell. This has been fine for one-liners, but now I want to run larger commands but often, thus the need to do it from an already connec...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,458
bash
# How to run a local script in mongo shell - Solution load() I think this is a very basic question but I'm stuck. I'm connected to remote mongo instance (mLab) via a MongoDB shell. This has been fine for one-liners, but now I want to run larger commands but often, thus the need to do it from an already connected shell...
Execute a JavaScript file You can specify a .js file to the mongo shell, and mongo will execute the JavaScript directly. Consider the following example: ``` mongo localhost:27017/test myjsfile.js ``` Replace the Localhost URL with your Mlab URL Or if you are in the shell You can execute a .js file from within the m...
44634814
Get substring before last occurrence of a word in shell script
6
2017-06-19 15:45:24
<p>I have a string <code>/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw</code> in Linux.</p> <p>I want to extract the substring before the last occurrence of the string <code>xyz</code> using shell script.</p> <p>Example:</p> <p>Input:</p> <pre><code>/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw </code></pre> <p>Output:</p> <pr...
12,014
1,776,156
2022-07-28 11:24:43
44,636,600
15
2017-06-19 17:30:13
1,253,222
2022-07-28 11:24:43
https://stackoverflow.com/q/44634814
https://stackoverflow.com/a/44636600
<p>How about this:</p> <pre><code>$ x=/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw </code></pre> <br> <pre><code>$ echo ${x%xyz*} </code></pre> <blockquote> <pre><code>/abc/xyz/def/xyz/1234/lmn/ </code></pre> </blockquote> <pre><code>$ echo ${x%/xyz*} </code></pre> <blockquote> <pre><code>/abc/xyz/def/xyz/1234/lmn </code></p...
<p>How about this:</p> <pre><code>$ x=/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw </code></pre> <br> <pre><code>$ echo ${x%xyz*} </code></pre> <blockquote> <pre><code>/abc/xyz/def/xyz/1234/lmn/ </code></pre> </blockquote> <pre><code>$ echo ${x%/xyz*} </code></pre> <blockquote> <pre><code>/abc/xyz/def/xyz/1234/lmn </code></p...
34, 58, 390
linux, shell, unix
<h1>Get substring before last occurrence of a word in shell script</h1> <p>I have a string <code>/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw</code> in Linux.</p> <p>I want to extract the substring before the last occurrence of the string <code>xyz</code> using shell script.</p> <p>Example:</p> <p>Input:</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
9,459
bash
# Get substring before last occurrence of a word in shell script I have a string `/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw` in Linux. I want to extract the substring before the last occurrence of the string `xyz` using shell script. Example: Input: ``` /abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw ``` Output: ``` /abc/xy...
How about this: ``` $ x=/abc/xyz/def/xyz/1234/lmn/xyz/7890/uvw ``` ``` $ echo ${x%xyz*} ``` > ``` > /abc/xyz/def/xyz/1234/lmn/ > ``` ``` $ echo ${x%/xyz*} ``` > ``` > /abc/xyz/def/xyz/1234/lmn > ``` If you really don't want the `/` before the last `xyz`, then the second echo should be what you're looking for;...
43230731
How to remove the last line from a variable in bash or sh?
6
2017-04-05 12:06:44
<p>I have a variable that has few lines. I would like to remove the last line from the contents of the variable. I searched the internet but all the links talk about removing the last line from a file. Here is the content of my variable</p> <pre><code>$echo $var $select key from table_test UNION ALL select fob from ta...
13,558
5,658,836
2020-11-13 23:12:53
43,230,810
15
2017-04-05 12:10:34
2,106,703
2017-04-05 12:13:56
https://stackoverflow.com/q/43230731
https://stackoverflow.com/a/43230810
<p><code>sed</code> can do it the same way it would do it from a file :</p> <pre><code>&gt; echo "$var" | sed '$d' </code></pre> <p>EDIT : <code>$</code> represents the last line of the file, and <code>d</code> deletes it. See <a href="http://sed.sourceforge.net/sedfaq3.html#s3.1" rel="noreferrer">here</a> for detail...
<p><code>sed</code> can do it the same way it would do it from a file :</p> <pre><code>&gt; echo "$var" | sed '$d' </code></pre> <p>EDIT : <code>$</code> represents the last line of the file, and <code>d</code> deletes it. See <a href="http://sed.sourceforge.net/sedfaq3.html#s3.1" rel="noreferrer">here</a> for detail...
387, 1718
bash, text-processing
<h1>How to remove the last line from a variable in bash or sh?</h1> <p>I have a variable that has few lines. I would like to remove the last line from the contents of the variable. I searched the internet but all the links talk about removing the last line from a file. Here is the content of my variable</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
9,460
bash
# How to remove the last line from a variable in bash or sh? I have a variable that has few lines. I would like to remove the last line from the contents of the variable. I searched the internet but all the links talk about removing the last line from a file. Here is the content of my variable ``` $echo $var $select ...
`sed` can do it the same way it would do it from a file : ``` > echo "$var" | sed '$d' ``` EDIT : `$` represents the last line of the file, and `d` deletes it. See [here](http://sed.sourceforge.net/sedfaq3.html#s3.1) for details
42215604
Powershell: split string with newline, then use -contains
6
2017-02-13 23:54:29
<pre><code>$a = {aa bb cc} $a = $a -split "`n" $a -contains "aa" </code></pre> <p>This returns false, when the string "aa" is seemingly part of the list. Why is this? </p>
23,406
2,069,276
2021-12-27 15:51:39
42,216,677
15
2017-02-14 02:09:01
45,375
2021-12-27 15:51:39
https://stackoverflow.com/q/42215604
https://stackoverflow.com/a/42216677
<p>To complement <a href="https://stackoverflow.com/a/42216059/45375">Kory Gill's helpful answer</a>, which suggests that the <strong>problem may be that the input has CRLF (<code>&quot;`r`n&quot;</code>) line endings</strong>, in which case <code>-split &quot;`n&quot;</code> (splitting by LF only) would leave the resu...
<p>To complement <a href="https://stackoverflow.com/a/42216059/45375">Kory Gill's helpful answer</a>, which suggests that the <strong>problem may be that the input has CRLF (<code>&quot;`r`n&quot;</code>) line endings</strong>, in which case <code>-split &quot;`n&quot;</code> (splitting by LF only) would leave the resu...
526
powershell
<h1>Powershell: split string with newline, then use -contains</h1> <pre><code>$a = {aa bb cc} $a = $a -split "`n" $a -contains "aa" </code></pre> <p>This returns false, when the string "aa" is seemingly part of the list. Why is this? </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,461
bash
# Powershell: split string with newline, then use -contains ``` $a = {aa bb cc} $a = $a -split "`n" $a -contains "aa" ``` This returns false, when the string "aa" is seemingly part of the list. Why is this?
To complement [Kory Gill's helpful answer](https://stackoverflow.com/a/42216059/45375), which suggests that the **problem may be that the input has CRLF (`` "`r`n" ``) line endings**, in which case `` -split "`n" `` (splitting by LF only) would leave the resulting array elements with a trailing CR (`` "`r" ``), causing...
41994368
How to get the modified date and year of file in Unix?
6
2017-02-02 04:47:34
<p>I am looking for a command to get the modified date of file in Unix including the year. Currently when I am using <code>ls -lrt A.sh</code> we get following details: -rwxrwSrwx 1 infprdbi bis 34816 Jan 31 15:44 A.sh</p>
11,307
5,269,176
2017-02-02 04:53:47
41,994,429
15
2017-02-02 04:53:47
4,787,126
2017-02-02 04:53:47
https://stackoverflow.com/q/41994368
https://stackoverflow.com/a/41994429
<p>You can specify the time format via <code>--time-style</code> option:</p> <pre><code>ls -la --time-style=full-iso ls -la --time-style=+%Y-%m-%d </code></pre>
<p>You can specify the time format via <code>--time-style</code> option:</p> <pre><code>ls -la --time-style=full-iso ls -la --time-style=+%Y-%m-%d </code></pre>
34, 387
bash, unix
<h1>How to get the modified date and year of file in Unix?</h1> <p>I am looking for a command to get the modified date of file in Unix including the year. Currently when I am using <code>ls -lrt A.sh</code> we get following details: -rwxrwSrwx 1 infprdbi bis 34816 Jan 31 15:44 A.sh</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,462
bash
# How to get the modified date and year of file in Unix? I am looking for a command to get the modified date of file in Unix including the year. Currently when I am using `ls -lrt A.sh` we get following details: -rwxrwSrwx 1 infprdbi bis 34816 Jan 31 15:44 A.sh
You can specify the time format via `--time-style` option: ``` ls -la --time-style=full-iso ls -la --time-style=+%Y-%m-%d ```
40503713
Using powershell to connect to HTTPS sites
6
2016-11-09 09:35:32
<p>I have been provided a new Server 2012 box to setup. </p> <p>I'm trying to use powershell to install chocolatey </p> <p><code> iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) </code></p> <p>and getting the error</p> <p><code> Exception calling "DownloadString" with "1...
7,171
222,163
2017-05-02 20:45:33
40,507,904
15
2016-11-09 13:14:32
222,163
2017-05-02 20:45:33
https://stackoverflow.com/q/40503713
https://stackoverflow.com/a/40507904
<p>It turns out this was as a result of TLS 1.0 being disabled in our server images in order to comply with PCI DSS 3.1.</p> <p>Rolling back that change to the image resolved the powershell issue.</p> <p>In the short term we can run </p> <p><code>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTyp...
<p>It turns out this was as a result of TLS 1.0 being disabled in our server images in order to comply with PCI DSS 3.1.</p> <p>Rolling back that change to the image resolved the powershell issue.</p> <p>In the short term we can run </p> <p><code>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTyp...
526, 641, 96533
powershell, ssl, windows-server-2012-r2
<h1>Using powershell to connect to HTTPS sites</h1> <p>I have been provided a new Server 2012 box to setup. </p> <p>I'm trying to use powershell to install chocolatey </p> <p><code> iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) </code></p> <p>and getting the error</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,463
bash
# Using powershell to connect to HTTPS sites I have been provided a new Server 2012 box to setup. I'm trying to use powershell to install chocolatey `iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))` and getting the error `Exception calling "DownloadString" with "1" argu...
It turns out this was as a result of TLS 1.0 being disabled in our server images in order to comply with PCI DSS 3.1. Rolling back that change to the image resolved the powershell issue. In the short term we can run `[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12` before using `Syste...
39999237
zsh script parser error for nested if/else
6
2016-10-12 12:58:46
<p>I have the following humble zsh function:</p> <pre><code>function remember() { if [ "$1" != "" ] then if[ "$1" != "clean" ] then echo "Why"; #echo $1 &gt;&gt; {~/.remember_info}; else rm -r ~/.remember_info; touch ~/.remember_info; fi else cat .remember_info; fi }...
32,699
6,546,677
2022-12-01 00:12:10
39,999,545
15
2016-10-12 13:14:18
1,126,841
2022-12-01 00:12:10
https://stackoverflow.com/q/39999237
https://stackoverflow.com/a/39999545
<p>You forgot the space between <code>if</code> and <code>[</code> when comparing to <code>clean</code>.</p> <p>This is case, though, where your function can be made simpler by handling the <code>=</code> case first.</p> <pre><code>function remember() { if [ &quot;$1&quot; = &quot;&quot; ]; then cat ~/.remember_i...
<p>You forgot the space between <code>if</code> and <code>[</code> when comparing to <code>clean</code>.</p> <p>This is case, though, where your function can be made simpler by handling the <code>=</code> case first.</p> <pre><code>function remember() { if [ &quot;$1&quot; = &quot;&quot; ]; then cat ~/.remember_i...
387, 531, 3791
bash, scripting, zsh
<h1>zsh script parser error for nested if/else</h1> <p>I have the following humble zsh function:</p> <pre><code>function remember() { if [ "$1" != "" ] then if[ "$1" != "clean" ] then echo "Why"; #echo $1 &gt;&gt; {~/.remember_info}; else rm -r ~/.remember_info; touch ~/.remembe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,464
bash
# zsh script parser error for nested if/else I have the following humble zsh function: ``` function remember() { if [ "$1" != "" ] then if[ "$1" != "clean" ] then echo "Why"; #echo $1 >> {~/.remember_info}; else rm -r ~/.remember_info; touch ~/.remember_info; fi else ...
You forgot the space between `if` and `[` when comparing to `clean`. This is case, though, where your function can be made simpler by handling the `=` case first. ``` function remember() { if [ "$1" = "" ]; then cat ~/.remember_info elif [ "$1" = clean ]; then rm -r ~/.remember_info touch ~/.remember_...
39043429
chmod 777 -R on existing path getting chmod: -R: No such file or directory
6
2016-08-19 16:03:25
<p>I wanted to grant operation access using <code>sudo chmod 777 -R &lt;path&gt;</code> on mac, I double checked the given path, and it's existing and no typos, but I still got <code>chmod: -R: No such file or directory</code>. Any ideas about why I'm getting this error?</p>
29,518
3,781,320
2016-08-19 16:07:50
39,043,496
15
2016-08-19 16:07:50
1,047,662
2016-08-19 16:07:50
https://stackoverflow.com/q/39043429
https://stackoverflow.com/a/39043496
<p>If you look at the synopsis from the man page for <code>chmod</code> you will se the following:</p> <blockquote> <p>SYNOPSIS<br> chmod [OPTION]... MODE[,MODE]... FILE...<br> chmod [OPTION]... OCTAL-MODE FILE...<br> chmod [OPTION]... --reference=RFILE FILE...</p> </blockquote> <p>The <c...
<p>If you look at the synopsis from the man page for <code>chmod</code> you will se the following:</p> <blockquote> <p>SYNOPSIS<br> chmod [OPTION]... MODE[,MODE]... FILE...<br> chmod [OPTION]... OCTAL-MODE FILE...<br> chmod [OPTION]... --reference=RFILE FILE...</p> </blockquote> <p>The <c...
359, 369, 387, 12380
bash, chmod, macos, permissions
<h1>chmod 777 -R on existing path getting chmod: -R: No such file or directory</h1> <p>I wanted to grant operation access using <code>sudo chmod 777 -R &lt;path&gt;</code> on mac, I double checked the given path, and it's existing and no typos, but I still got <code>chmod: -R: No such file or directory</code>. Any idea...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
9,465
bash
# chmod 777 -R on existing path getting chmod: -R: No such file or directory I wanted to grant operation access using `sudo chmod 777 -R <path>` on mac, I double checked the given path, and it's existing and no typos, but I still got `chmod: -R: No such file or directory`. Any ideas about why I'm getting this error?
If you look at the synopsis from the man page for `chmod` you will se the following: > SYNOPSIS > chmod [OPTION]... MODE[,MODE]... FILE... > chmod [OPTION]... OCTAL-MODE FILE... > chmod [OPTION]... --reference=RFILE FILE... The `-R` flag should be used before the actual file mode, so you need to call the comman...