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
61055196
How to start WSL terminal in a current powershell directory?
7
2020-04-06 07:50:40
<p>I can open a powershell and type </p> <pre><code>&gt; Ubuntu </code></pre> <p>to open a WSL ubuntu shell on windows 10. This will always take me to the WSL home directory. How would I instead open the terminal in the same location that the powershell is currently in? </p> <p>FYI. I need this for creating a right...
42,280
3,059,024
2021-04-25 03:02:52
61,073,056
12
2020-04-07 04:53:14
5,238,915
2021-04-10 17:16:15
https://stackoverflow.com/q/61055196
https://stackoverflow.com/a/61073056
<p>If we look at what running <code>ubuntu.exe</code> actually does:</p> <pre><code>PS C:\&gt; ubuntu.exe /? Launches or configures a Linux distribution. Usage: &lt;no args&gt; Launches the user's default shell in the user's home directory. install [--root] Install the distribution and do not ...
<p>If we look at what running <code>ubuntu.exe</code> actually does:</p> <pre><code>PS C:\&gt; ubuntu.exe /? Launches or configures a Linux distribution. Usage: &lt;no args&gt; Launches the user's default shell in the user's home directory. install [--root] Install the distribution and do not ...
526, 119526
powershell, windows-subsystem-for-linux
<h1>How to start WSL terminal in a current powershell directory?</h1> <p>I can open a powershell and type </p> <pre><code>&gt; Ubuntu </code></pre> <p>to open a WSL ubuntu shell on windows 10. This will always take me to the WSL home directory. How would I instead open the terminal in the same location that the powe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,974
bash
# How to start WSL terminal in a current powershell directory? I can open a powershell and type ``` > Ubuntu ``` to open a WSL ubuntu shell on windows 10. This will always take me to the WSL home directory. How would I instead open the terminal in the same location that the powershell is currently in? FYI. I need t...
If we look at what running `ubuntu.exe` actually does: ``` PS C:\> ubuntu.exe /? Launches or configures a Linux distribution. Usage: <no args> Launches the user's default shell in the user's home directory. install [--root] Install the distribution and do not launch the shell when complete. ...
60892593
Add-AzTableRow command is not available in Azure Cloud Shell
7
2020-03-27 19:05:11
<p>I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert.</p> <blockquote> <p>Blockquote</p> </blockquote> <pre><code> Add-AzTableRow: The term 'Add-AzTableRow' is not recognized as the name of a cmd...
9,088
1,583,834
2020-03-30 03:20:09
60,923,570
12
2020-03-30 03:20:09
10,505,040
2020-03-30 03:20:09
https://stackoverflow.com/q/60892593
https://stackoverflow.com/a/60923570
<p>According to the error, it seems that you do not install the module <a href="https://www.powershellgallery.com/packages/AzTable/2.0.2" rel="noreferrer"><code>AzTable</code></a>. Please run the command <code>Get-InstalledModule</code> to check if you have installed the module. <a href="https://i.sstatic.net/mO7hv.png...
<p>According to the error, it seems that you do not install the module <a href="https://www.powershellgallery.com/packages/AzTable/2.0.2" rel="noreferrer"><code>AzTable</code></a>. Please run the command <code>Get-InstalledModule</code> to check if you have installed the module. <a href="https://i.sstatic.net/mO7hv.png...
35808, 62065, 126343
azure-cloud-shell, azure-storage, azure-table-storage
<h1>Add-AzTableRow command is not available in Azure Cloud Shell</h1> <p>I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert.</p> <blockquote> <p>Blockquote</p> </blockquote> <pre><code> Add-AzTabl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,975
bash
# Add-AzTableRow command is not available in Azure Cloud Shell I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert. > Blockquote ``` Add-AzTableRow: The term 'Add-AzTableRow' is not recognized as t...
According to the error, it seems that you do not install the module [`AzTable`](https://www.powershellgallery.com/packages/AzTable/2.0.2). Please run the command `Get-InstalledModule` to check if you have installed the module. [![enter image description here](https://i.sstatic.net/mO7hv.png)](https://i.sstatic.net/mO7h...
57932053
Calling other PowerShell scripts within a PowerShell script
7
2019-09-14 02:39:15
<p>I'm trying to get one master PowerShell script to run all of the others while waiting 30-60 seconds to ensure that the tasks are completed. Everything else I tried wouldn't stop/wait for the first script and its processes to complete before going through all the others at the same time and would cause a restart auto...
18,567
12,065,653
2019-09-14 11:45:15
57,935,185
12
2019-09-14 11:45:15
1,630,171
2019-09-14 11:45:15
https://stackoverflow.com/q/57932053
https://stackoverflow.com/a/57935185
<p>PowerShell can run PowerShell scripts from other PowerShell scripts directly. The only time you need <code>Start-Process</code> for that is when you want to run the called script with elevated privileges (which isn't necessary here, since your parent script is already running elevated).</p> <p>This should suffice:<...
<p>PowerShell can run PowerShell scripts from other PowerShell scripts directly. The only time you need <code>Start-Process</code> for that is when you want to run the called script with elevated privileges (which isn't necessary here, since your parent script is already running elevated).</p> <p>This should suffice:<...
526
powershell
<h1>Calling other PowerShell scripts within a PowerShell script</h1> <p>I'm trying to get one master PowerShell script to run all of the others while waiting 30-60 seconds to ensure that the tasks are completed. Everything else I tried wouldn't stop/wait for the first script and its processes to complete before going t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,976
bash
# Calling other PowerShell scripts within a PowerShell script I'm trying to get one master PowerShell script to run all of the others while waiting 30-60 seconds to ensure that the tasks are completed. Everything else I tried wouldn't stop/wait for the first script and its processes to complete before going through al...
PowerShell can run PowerShell scripts from other PowerShell scripts directly. The only time you need `Start-Process` for that is when you want to run the called script with elevated privileges (which isn't necessary here, since your parent script is already running elevated). This should suffice: ``` foreach ($script...
57374562
Why does shell builtin colon command ":" after variable assignment on same line cause empty string value to be assigned?
7
2019-08-06 11:03:06
<p>If I add the <code>colon</code> (<code>:</code>) builtin shell command after an assignment, the variable gets assigned to the empty string (<code>""</code>). Why does it behave like that? I expected it to have no effect.</p> <pre class="lang-sh prettyprint-override"><code> set -vx MyVar1='my var 1' : colo...
492
875,915
2019-08-06 12:39:40
57,374,792
12
2019-08-06 11:15:43
2,088,135
2019-08-06 12:39:40
https://stackoverflow.com/q/57374562
https://stackoverflow.com/a/57374792
<p><code>:</code> is a built-in command which returns successfully (a shorthand version of <code>true</code>).</p> <p>When you do a variable assignment on the same line as a command, the assignment is only valid for the duration of the command (this is typically used to run commands with temporary environment variables...
<p><code>:</code> is a built-in command which returns successfully (a shorthand version of <code>true</code>).</p> <p>When you do a variable assignment on the same line as a command, the assignment is only valid for the duration of the command (this is typically used to run commands with temporary environment variables...
387, 390, 10327, 14036, 14334
bash, built-in, sh, shell, variable-assignment
<h1>Why does shell builtin colon command ":" after variable assignment on same line cause empty string value to be assigned?</h1> <p>If I add the <code>colon</code> (<code>:</code>) builtin shell command after an assignment, the variable gets assigned to the empty string (<code>""</code>). Why does it behave like that...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,977
bash
# Why does shell builtin colon command ":" after variable assignment on same line cause empty string value to be assigned? If I add the `colon` (`:`) builtin shell command after an assignment, the variable gets assigned to the empty string (`""`). Why does it behave like that? I expected it to have no effect. ``` ...
`:` is a built-in command which returns successfully (a shorthand version of `true`). When you do a variable assignment on the same line as a command, the assignment is only valid for the duration of the command (this is typically used to run commands with temporary environment variables set). So when you run: ``` M...
56166175
What is the difference between -contains vs .contains in powershell script?
7
2019-05-16 10:15:01
<p>What is the difference between .contains and -contains? One seems case sensitive while the other one is not.</p> <pre><code>PS C:\WINDOWS\system32&gt; ("jack", "john", "jill").contains("Jill") False PS C:\WINDOWS\system32&gt; "jack", "john", "jill" -contains "Jill" True </code></pre> <p>Why is there such a discr...
15,778
626,563
2019-05-16 10:53:03
56,166,481
12
2019-05-16 10:31:47
11,025,476
2019-05-16 10:37:56
https://stackoverflow.com/q/56166175
https://stackoverflow.com/a/56166481
<p>The <code>-Contains</code> operator compares one object against a collection. It returns true if that entire value exists as an item in a collection. It is case-insensitive and is not limited to strings. <code>-CContains</code> is the case-sensitive version. The <code>.Contains()</code> method is a .NET method from ...
<p>The <code>-Contains</code> operator compares one object against a collection. It returns true if that entire value exists as an item in a collection. It is case-insensitive and is not limited to strings. <code>-CContains</code> is the case-sensitive version. The <code>.Contains()</code> method is a .NET method from ...
526
powershell
<h1>What is the difference between -contains vs .contains in powershell script?</h1> <p>What is the difference between .contains and -contains? One seems case sensitive while the other one is not.</p> <pre><code>PS C:\WINDOWS\system32&gt; ("jack", "john", "jill").contains("Jill") False PS C:\WINDOWS\system32&gt; "ja...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,978
bash
# What is the difference between -contains vs .contains in powershell script? What is the difference between .contains and -contains? One seems case sensitive while the other one is not. ``` PS C:\WINDOWS\system32> ("jack", "john", "jill").contains("Jill") False PS C:\WINDOWS\system32> "jack", "john", "jill" -conta...
The `-Contains` operator compares one object against a collection. It returns true if that entire value exists as an item in a collection. It is case-insensitive and is not limited to strings. `-CContains` is the case-sensitive version. The `.Contains()` method is a .NET method from the String class. It compares a subs...
55057778
How can I split an mp4 video with ffmpeg every time the volume is zero?
7
2019-03-08 06:21:44
<p>I need to split a video into many smaller videos. I have tried PySceneDetect and its 2 scene detection methods don't fit my need.</p> <p>The idea is to trigger a scene cut/break every time the volume is very low, every time audio level is less than a given parameter. I think overall RMS dB volume level is what I me...
3,347
2,904,701
2019-03-14 21:09:01
55,145,388
12
2019-03-13 15:19:28
266,720
2019-03-14 21:09:01
https://stackoverflow.com/q/55057778
https://stackoverflow.com/a/55145388
<p>Use <code>silencedetect</code> audio filter and feed its debugging output to <code>segment</code> output format parameter.</p> <p>Here is a ready-made script:</p> <pre><code>#!/bin/bash IN=$1 OUT=$2 true ${SD_PARAMS:="-55dB:d=0.3"}; true ${MIN_FRAGMENT_DURATION:="20"}; export MIN_FRAGMENT_DURATION if [ -z "$OUT...
<p>Use <code>silencedetect</code> audio filter and feed its debugging output to <code>segment</code> output format parameter.</p> <p>Here is a ready-made script:</p> <pre><code>#!/bin/bash IN=$1 OUT=$2 true ${SD_PARAMS:="-55dB:d=0.3"}; true ${MIN_FRAGMENT_DURATION:="20"}; export MIN_FRAGMENT_DURATION if [ -z "$OUT...
387, 3847, 10327
bash, ffmpeg, sh
<h1>How can I split an mp4 video with ffmpeg every time the volume is zero?</h1> <p>I need to split a video into many smaller videos. I have tried PySceneDetect and its 2 scene detection methods don't fit my need.</p> <p>The idea is to trigger a scene cut/break every time the volume is very low, every time audio level...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,979
bash
# How can I split an mp4 video with ffmpeg every time the volume is zero? I need to split a video into many smaller videos. I have tried PySceneDetect and its 2 scene detection methods don't fit my need. The idea is to trigger a scene cut/break every time the volume is very low, every time audio level is less than a ...
Use `silencedetect` audio filter and feed its debugging output to `segment` output format parameter. Here is a ready-made script: ``` #!/bin/bash IN=$1 OUT=$2 true ${SD_PARAMS:="-55dB:d=0.3"}; true ${MIN_FRAGMENT_DURATION:="20"}; export MIN_FRAGMENT_DURATION if [ -z "$OUT" ]; then echo "Usage: split_by_silence...
52229808
Azure Cloud Shell Trouble running ps1 Scripts
7
2018-09-07 21:26:34
<p>In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc. Any Suggestions, what am I doing wrong.</p> <pre><code> PS Azure:\&gt; dir Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell ...
6,375
7,568,316
2019-05-27 22:27:32
53,260,864
12
2018-11-12 11:07:40
1,820,890
2018-11-12 11:07:40
https://stackoverflow.com/q/52229808
https://stackoverflow.com/a/53260864
<p>The example below is from <a href="https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cloud-shell/quickstart-powershell.md" rel="noreferrer">Microsoft Docs</a>. The trick is for the shell to be open in the location that the script is saved. This will only work if your script doesn't use libraries that...
<p>The example below is from <a href="https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cloud-shell/quickstart-powershell.md" rel="noreferrer">Microsoft Docs</a>. The trick is for the shell to be open in the location that the script is saved. This will only work if your script doesn't use libraries that...
126343
azure-cloud-shell
<h1>Azure Cloud Shell Trouble running ps1 Scripts</h1> <p>In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc. Any Suggestions, what am I doing wrong.</p> <pre><code> PS Azure:\&gt; dir Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuypt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,980
bash
# Azure Cloud Shell Trouble running ps1 Scripts In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc. Any Suggestions, what am I doing wrong. ``` PS Azure:\> dir Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfil...
The example below is from [Microsoft Docs](https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cloud-shell/quickstart-powershell.md). The trick is for the shell to be open in the location that the script is saved. This will only work if your script doesn't use libraries that are stored on your local device...
53069551
Is there a way in .bash_profile, to create two aliases that do the same thing?
7
2018-10-30 17:11:50
<p>I have some simple aliases in my <code>.bash_profile</code> (OS X El Capitan, 10.11.6). Sometimes, I want multiple aliases that do the same thing. I have, for example, a folder that is my starting point for programming projects. Currently, I have an alias for code and one for programming that do the same thing: </p>...
2,176
1,267,195
2018-10-30 23:56:43
53,074,458
12
2018-10-30 23:56:43
1,899,640
2018-10-30 23:56:43
https://stackoverflow.com/q/53069551
https://stackoverflow.com/a/53074458
<blockquote> <p>In short, is there something like this?</p> <p><code>alias code,programming='cd /path/to/Programming/; clear; pwd; ls'</code></p> </blockquote> <p>Yes, brace expansion:</p> <pre><code>alias {code,programming}='cd /path/to/Programming/; clear; pwd; ls' </code></pre>
<blockquote> <p>In short, is there something like this?</p> <p><code>alias code,programming='cd /path/to/Programming/; clear; pwd; ls'</code></p> </blockquote> <p>Yes, brace expansion:</p> <pre><code>alias {code,programming}='cd /path/to/Programming/; clear; pwd; ls' </code></pre>
369, 387, 1448
alias, bash, macos
<h1>Is there a way in .bash_profile, to create two aliases that do the same thing?</h1> <p>I have some simple aliases in my <code>.bash_profile</code> (OS X El Capitan, 10.11.6). Sometimes, I want multiple aliases that do the same thing. I have, for example, a folder that is my starting point for programming projects. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,981
bash
# Is there a way in .bash_profile, to create two aliases that do the same thing? I have some simple aliases in my `.bash_profile` (OS X El Capitan, 10.11.6). Sometimes, I want multiple aliases that do the same thing. I have, for example, a folder that is my starting point for programming projects. Currently, I have an...
> In short, is there something like this? > > `alias code,programming='cd /path/to/Programming/; clear; pwd; ls'` Yes, brace expansion: ``` alias {code,programming}='cd /path/to/Programming/; clear; pwd; ls' ```
52862376
What is the difference between `cat |` and `<`
7
2018-10-17 19:35:09
<p>I'd like to send the contents of <code>filename</code> to <code>some_cmd</code> on the command line. What's the difference between running this:</p> <pre><code>$ cat filename | some_cmd </code></pre> <p>and</p> <pre><code>$ some_cmd &lt; filename </code></pre> <p>Are there cases where I can or should use one and...
1,304
7,327,755
2018-10-18 03:10:06
52,862,425
12
2018-10-17 19:38:52
14,122
2018-10-17 19:58:31
https://stackoverflow.com/q/52862376
https://stackoverflow.com/a/52862425
<ul> <li><p><code>cat foo | somecmd</code> is running two programs—<code>/bin/cat</code>, and <code>somecmd</code>; and connecting the stdout of <code>cat</code> to the stdin of <code>somecmd</code> with a FIFO—which can be read only once, from start to back. That FIFO also doesn't expose metadata about the original fi...
<ul> <li><p><code>cat foo | somecmd</code> is running two programs—<code>/bin/cat</code>, and <code>somecmd</code>; and connecting the stdout of <code>cat</code> to the stdin of <code>somecmd</code> with a FIFO—which can be read only once, from start to back. That FIFO also doesn't expose metadata about the original fi...
34, 58, 387, 5813, 26698
bash, io-redirection, linux, pipe, unix
<h1>What is the difference between `cat |` and `<`</h1> <p>I'd like to send the contents of <code>filename</code> to <code>some_cmd</code> on the command line. What's the difference between running this:</p> <pre><code>$ cat filename | some_cmd </code></pre> <p>and</p> <pre><code>$ some_cmd &lt; filename </code></pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,982
bash
# What is the difference between `cat |` and `<` I'd like to send the contents of `filename` to `some_cmd` on the command line. What's the difference between running this: ``` $ cat filename | some_cmd ``` and ``` $ some_cmd < filename ``` Are there cases where I can or should use one and not the other?
- `cat foo | somecmd` is running two programs—`/bin/cat`, and `somecmd`; and connecting the stdout of `cat` to the stdin of `somecmd` with a FIFO—which can be read only once, from start to back. That FIFO also doesn't expose metadata about the original file—neither its name nor its size can be discovered by `somecmd` (...
51363155
Is it possible to write shell command within Pharo smalltalk?
7
2018-07-16 13:35:38
<p>Like in other programming language, is there a way of running linux shell command in Pharo smalltalk or a simple script ? I would like to have my Pharo image running a script that should be able to automate a tasks and return it to some value. I looked at almost all the documentation around and I couldn't find anyth...
1,921
8,895,287
2023-12-27 11:43:21
51,375,906
12
2018-07-17 07:45:30
6,059,896
2021-03-29 08:13:05
https://stackoverflow.com/q/51363155
https://stackoverflow.com/a/51375906
<p>Pharo does allow the OS interaction. The best way, in my eyes, is to use <code>OSProcess</code> (as <a href="http://stackoverflow.com/users/2012262/martinw">MartinW</a> already suggested).</p> <p>Those that think it is a duplicate are missing this part:</p> <blockquote> <p>... running a script that should be able t...
<p>Pharo does allow the OS interaction. The best way, in my eyes, is to use <code>OSProcess</code> (as <a href="http://stackoverflow.com/users/2012262/martinw">MartinW</a> already suggested).</p> <p>Those that think it is a duplicate are missing this part:</p> <blockquote> <p>... running a script that should be able t...
58, 390, 3186, 24949, 125535
linux, pharo, pharo-5, shell, smalltalk
<h1>Is it possible to write shell command within Pharo smalltalk?</h1> <p>Like in other programming language, is there a way of running linux shell command in Pharo smalltalk or a simple script ? I would like to have my Pharo image running a script that should be able to automate a tasks and return it to some value. I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,983
bash
# Is it possible to write shell command within Pharo smalltalk? Like in other programming language, is there a way of running linux shell command in Pharo smalltalk or a simple script ? I would like to have my Pharo image running a script that should be able to automate a tasks and return it to some value. I looked at...
Pharo does allow the OS interaction. The best way, in my eyes, is to use `OSProcess` (as [MartinW](http://stackoverflow.com/users/2012262/martinw) already suggested). Those that think it is a duplicate are missing this part: > ... running a script that should be able to automate a tasks and > return it to some value....
50768918
Using a shell script to replace tokens in a file
7
2018-06-08 22:00:36
<p>I have a file that holds token variables. When we switch environments we want to replace those tokens correctly for the environment we're in.</p> <p>How can I do this in a Linux shell? I'm thinking awk or sed.</p> <p>Example:</p> <p>File has this data:</p> <pre><code>DB_HOST=__HOST__ DB_PASSWORD=__PASSWORD__ </c...
10,601
4,484,623
2023-02-16 20:29:39
50,769,355
12
2018-06-08 22:58:30
1,566,221
2018-06-11 14:38:49
https://stackoverflow.com/q/50768918
https://stackoverflow.com/a/50769355
<p>The program <code>envsubst</code> was designed for roughly this purpose, but it wants to to use standard shell format for the strings to be substituted from the environment:</p> <pre><code># Here-doc delimiter quoted to avoid having the shell do the substitutions $ HOST=myhost PASSWORD=secret envsubst &lt;&lt;"EOF"...
<p>The program <code>envsubst</code> was designed for roughly this purpose, but it wants to to use standard shell format for the strings to be substituted from the environment:</p> <pre><code># Here-doc delimiter quoted to avoid having the shell do the substitutions $ HOST=myhost PASSWORD=secret envsubst &lt;&lt;"EOF"...
58, 387, 390, 990, 5282
awk, bash, linux, sed, shell
<h1>Using a shell script to replace tokens in a file</h1> <p>I have a file that holds token variables. When we switch environments we want to replace those tokens correctly for the environment we're in.</p> <p>How can I do this in a Linux shell? I'm thinking awk or sed.</p> <p>Example:</p> <p>File has this data:</p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,984
bash
# Using a shell script to replace tokens in a file I have a file that holds token variables. When we switch environments we want to replace those tokens correctly for the environment we're in. How can I do this in a Linux shell? I'm thinking awk or sed. Example: File has this data: ``` DB_HOST=__HOST__ DB_PASSWORD...
The program `envsubst` was designed for roughly this purpose, but it wants to to use standard shell format for the strings to be substituted from the environment: ``` # Here-doc delimiter quoted to avoid having the shell do the substitutions $ HOST=myhost PASSWORD=secret envsubst <<"EOF" DB_HOST=$HOST DB_PASSWORD=${PA...
40179884
Adding .inf drivers using PowerShell, possible?
7
2016-10-21 14:59:23
<p>Are we able to install drivers via their .inf files etc. using a PowerShell cmdlet? When Googling I found, Add-WindowsDriver but I think this one is for an offline Windows image. Does that mean an image that is not currently used on an OS? If not, please teach me how to write the parameters. Thank you!</p>
56,176
6,466,972
2024-05-30 15:13:27
50,515,657
12
2018-05-24 18:10:30
9,842,659
2018-05-24 18:18:24
https://stackoverflow.com/q/40179884
https://stackoverflow.com/a/50515657
<p>This PowerShell script will do what you want:</p> <pre><code>Get-ChildItem "C:\Driver File Location" -Recurse -Filter "*inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } </code></pre>
<p>This PowerShell script will do what you want:</p> <pre><code>Get-ChildItem "C:\Driver File Location" -Recurse -Filter "*inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } </code></pre>
526, 2034
drivers, powershell
<h1>Adding .inf drivers using PowerShell, possible?</h1> <p>Are we able to install drivers via their .inf files etc. using a PowerShell cmdlet? When Googling I found, Add-WindowsDriver but I think this one is for an offline Windows image. Does that mean an image that is not currently used on an OS? If not, please teach...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,985
bash
# Adding .inf drivers using PowerShell, possible? Are we able to install drivers via their .inf files etc. using a PowerShell cmdlet? When Googling I found, Add-WindowsDriver but I think this one is for an offline Windows image. Does that mean an image that is not currently used on an OS? If not, please teach me how t...
This PowerShell script will do what you want: ``` Get-ChildItem "C:\Driver File Location" -Recurse -Filter "*inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } ```
48864295
Powershell: convert a fraction to an integer - surprising rounding behavior
7
2018-02-19 10:40:02
<p>I have a interesting question on ints with decimals. </p> <p>Assuming I do the following: </p> <pre><code>[int] $a = 5/2 $a </code></pre> <p>I've tried it 10 times to be sure, and powershell always returns <code>2</code></p> <p>Is there a way to force Powershell to round up or down in such circumstances and by d...
7,680
8,538,746
2023-12-18 01:50:10
48,864,546
12
2018-02-19 10:53:32
6,947,281
2018-02-19 11:08:57
https://stackoverflow.com/q/48864295
https://stackoverflow.com/a/48864546
<pre><code>[Math]::Floor($a) --&gt; 2 [Math]::Ceiling($a)--&gt; 3 [Math]::Round($a) --&gt; 2 </code></pre> <p><code>Floor</code> will give you the preceding whole number and <code>Ceiling</code> will be providing the succeeding whole number. But if you want to round it up, using the <code>Round</code> function, it wi...
<pre><code>[Math]::Floor($a) --&gt; 2 [Math]::Ceiling($a)--&gt; 3 [Math]::Round($a) --&gt; 2 </code></pre> <p><code>Floor</code> will give you the preceding whole number and <code>Ceiling</code> will be providing the succeeding whole number. But if you want to round it up, using the <code>Round</code> function, it wi...
526, 2054, 2754, 8690, 9069
bankers-rounding, casting, integer, powershell, rounding
<h1>Powershell: convert a fraction to an integer - surprising rounding behavior</h1> <p>I have a interesting question on ints with decimals. </p> <p>Assuming I do the following: </p> <pre><code>[int] $a = 5/2 $a </code></pre> <p>I've tried it 10 times to be sure, and powershell always returns <code>2</code></p> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,986
bash
# Powershell: convert a fraction to an integer - surprising rounding behavior I have a interesting question on ints with decimals. Assuming I do the following: ``` [int] $a = 5/2 $a ``` I've tried it 10 times to be sure, and powershell always returns `2` Is there a way to force Powershell to round up or down in su...
``` [Math]::Floor($a) --> 2 [Math]::Ceiling($a)--> 3 [Math]::Round($a) --> 2 ``` `Floor` will give you the preceding whole number and `Ceiling` will be providing the succeeding whole number. But if you want to round it up, using the `Round` function, it will follow midpoint rounding (**Rounding at midpoint is historic...
47042350
BASH: Count identical lines
7
2017-10-31 18:33:22
<p>I have a file that contains:</p> <pre><code>VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoiceMailConfig60CharsTest VoicemailDefaultTypeTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMai...
8,382
2,340,022
2017-10-31 23:45:32
47,042,520
12
2017-10-31 18:44:30
7,116,369
2017-10-31 18:44:30
https://stackoverflow.com/q/47042350
https://stackoverflow.com/a/47042520
<p>Assuming the formatting of the output doesn't exactly have to match</p> <pre><code>VoicemailButtonTest (5) VoiceMailConfig60CharsTest (1) VoicemailDefaultTypeTest (1) VoiceMailIconSelectableTest (5) VoicemailSettingsFromMessageModeScreenTest (2) VoicemailSettingsTest (7) </code></pre> <p>you can just use</p> <pre...
<p>Assuming the formatting of the output doesn't exactly have to match</p> <pre><code>VoicemailButtonTest (5) VoiceMailConfig60CharsTest (1) VoicemailDefaultTypeTest (1) VoiceMailIconSelectableTest (5) VoicemailSettingsFromMessageModeScreenTest (2) VoicemailSettingsTest (7) </code></pre> <p>you can just use</p> <pre...
387, 990, 5282, 12147, 29837
awk, bash, duplicates, line-count, sed
<h1>BASH: Count identical lines</h1> <p>I have a file that contains:</p> <pre><code>VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoiceMailConfig60CharsTest VoicemailDefaultTypeTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,987
bash
# BASH: Count identical lines I have a file that contains: ``` VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoicemailButtonTest VoiceMailConfig60CharsTest VoicemailDefaultTypeTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMailIconSelectableTest VoiceMailIconSelect...
Assuming the formatting of the output doesn't exactly have to match ``` VoicemailButtonTest (5) VoiceMailConfig60CharsTest (1) VoicemailDefaultTypeTest (1) VoiceMailIconSelectableTest (5) VoicemailSettingsFromMessageModeScreenTest (2) VoicemailSettingsTest (7) ``` you can just use ``` sort <input_file> | uniq -c ```...
46808635
How to hide the PowerShell window when running a .ps1 script in Task Scheduler?
7
2017-10-18 10:59:54
<p>I am trying to run a PowerShell script using Task Scheduler and it pops up a PowerShell command console window.</p> <p>Is there a way to disable this while running the script and hide the window?</p> <p>I've tried <code>-WindowStyle Hidden</code> but the PowerShell command console window still pops up.</p>
15,277
8,427,443
2025-03-21 19:31:48
46,814,849
12
2017-10-18 16:22:54
2,102,693
2017-10-18 16:48:10
https://stackoverflow.com/q/46808635
https://stackoverflow.com/a/46814849
<p>Since <code>powershell.exe</code> is a console program, you can't execute it normally without its console window appearing (although you can hide it shortly after it starts by using <code>-WindowStyle Hidden</code>, as you have noted).</p> <p>The trick is to execute <code>powershell.exe</code> <em>itself</em> in a ...
<p>Since <code>powershell.exe</code> is a console program, you can't execute it normally without its console window appearing (although you can hide it shortly after it starts by using <code>-WindowStyle Hidden</code>, as you have noted).</p> <p>The trick is to execute <code>powershell.exe</code> <em>itself</em> in a ...
64, 526, 37086
powershell, windows, window-style
<h1>How to hide the PowerShell window when running a .ps1 script in Task Scheduler?</h1> <p>I am trying to run a PowerShell script using Task Scheduler and it pops up a PowerShell command console window.</p> <p>Is there a way to disable this while running the script and hide the window?</p> <p>I've tried <code>-WindowS...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,988
bash
# How to hide the PowerShell window when running a .ps1 script in Task Scheduler? I am trying to run a PowerShell script using Task Scheduler and it pops up a PowerShell command console window. Is there a way to disable this while running the script and hide the window? I've tried `-WindowStyle Hidden` but the Power...
Since `powershell.exe` is a console program, you can't execute it normally without its console window appearing (although you can hide it shortly after it starts by using `-WindowStyle Hidden`, as you have noted). The trick is to execute `powershell.exe` *itself* in a hidden state. One way to do this is by using the W...
46388010
How to connect to linux server using ssh with private key from PowerShell?
7
2017-09-24 08:15:07
<p>I have generated an ssh key pair using puttygen and can successfully connect to my CentOS server with my private key from putty on my Windows 10 workstation:</p> <p><a href="https://i.sstatic.net/cJ4fj.png" rel="noreferrer"><img src="https://i.sstatic.net/cJ4fj.png" alt="image of successful connection to CentOS"></...
27,763
38,211
2021-12-29 22:14:18
46,390,166
12
2017-09-24 12:45:19
1,630,171
2017-09-24 12:45:19
https://stackoverflow.com/q/46388010
https://stackoverflow.com/a/46390166
<p><code>New-SSHSession</code> doesn't recognize PuTTY's key format (unfortunately neither the Gallery nor the project page mention this, but I found it in a <a href="http://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/" rel="noreferrer">PowerShellMagazine article</a>). You need the ...
<p><code>New-SSHSession</code> doesn't recognize PuTTY's key format (unfortunately neither the Gallery nor the project page mention this, but I found it in a <a href="http://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/" rel="noreferrer">PowerShellMagazine article</a>). You need the ...
386, 526, 108010
powershell, powershell-5.0, ssh
<h1>How to connect to linux server using ssh with private key from PowerShell?</h1> <p>I have generated an ssh key pair using puttygen and can successfully connect to my CentOS server with my private key from putty on my Windows 10 workstation:</p> <p><a href="https://i.sstatic.net/cJ4fj.png" rel="noreferrer"><img src...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,989
bash
# How to connect to linux server using ssh with private key from PowerShell? I have generated an ssh key pair using puttygen and can successfully connect to my CentOS server with my private key from putty on my Windows 10 workstation: [![image of successful connection to CentOS](https://i.sstatic.net/cJ4fj.png)](http...
`New-SSHSession` doesn't recognize PuTTY's key format (unfortunately neither the Gallery nor the project page mention this, but I found it in a [PowerShellMagazine article](http://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/)). You need the private key in the OpenSSH format. You can...
45607911
LDAP query in PowerShell
7
2017-08-10 08:07:28
<p>I'm trying to run the below query in PowerShell with no success :(</p> <pre><code>((mailNickname=id*)(whenChanged&gt;=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(memberof=CN=VPN-2,OU=VpnAccess,OU=Do...
156,267
5,366,549
2021-04-08 00:07:55
45,608,229
12
2017-08-10 08:23:48
712,649
2017-08-10 08:23:48
https://stackoverflow.com/q/45607911
https://stackoverflow.com/a/45608229
<p>Given the contents of the query filter, I'd say you're looking for a user, so I'd suggest using the <code>Get-ADUser</code> cmdlet from the ActiveDirectory RSAT module:</p> <pre><code>Get-ADUser -LDAPFilter '((mailNickname=id*)(whenChanged&gt;=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))...
<p>Given the contents of the query filter, I'd say you're looking for a user, so I'd suggest using the <code>Get-ADUser</code> cmdlet from the ActiveDirectory RSAT module:</p> <pre><code>Get-ADUser -LDAPFilter '((mailNickname=id*)(whenChanged&gt;=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))...
526, 10401
active-directory, powershell
<h1>LDAP query in PowerShell</h1> <p>I'm trying to run the below query in PowerShell with no success :(</p> <pre><code>((mailNickname=id*)(whenChanged&gt;=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(me...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,990
bash
# LDAP query in PowerShell I'm trying to run the below query in PowerShell with no success :( ``` ((mailNickname=id*)(whenChanged>=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAccess,OU=Domain Global,OU=Groups,OU=01,DC=em,DC=pl,DC=ad,DC=mnl)(memberof=CN=VPN-2,OU=Vpn...
Given the contents of the query filter, I'd say you're looking for a user, so I'd suggest using the `Get-ADUser` cmdlet from the ActiveDirectory RSAT module: ``` Get-ADUser -LDAPFilter '((mailNickname=id*)(whenChanged>=20170701000000.0Z))(|(userAccountControl=514)(userAccountControl=66050))(|(memberof=CN=VPN,OU=VpnAcc...
44781847
How to disassemble a shellcode into assembly instruction?
7
2017-06-27 13:41:18
<p>Is there some tool to disassemble a raw hex into assembly instructions? for example: lets say we have <b>\xeb\x1d</b> that disassemble into <b>jmp 0x1f</b> according to <a href="http://shell-storm.org/online/Online-Assembler-and-Disassembler/" rel="noreferrer">this</a> online disassembler. So is there some offline t...
14,512
8,016,875
2017-06-27 15:05:13
44,783,138
12
2017-06-27 14:38:51
3,857,942
2017-06-27 15:05:13
https://stackoverflow.com/q/44781847
https://stackoverflow.com/a/44783138
<p>As the comments have suggested, your issue is that you have output the string <code>\xeb\x1d</code> as ASCII into the file you are trying to disassemble. You may have done something like:</p> <pre><code>echo '\xeb\x1d' &gt;foo </code></pre> <p>You can do this but you will want to tell <code>echo</code> to interpre...
<p>As the comments have suggested, your issue is that you have output the string <code>\xeb\x1d</code> as ASCII into the file you are trying to disassemble. You may have done something like:</p> <pre><code>echo '\xeb\x1d' &gt;foo </code></pre> <p>You can do this but you will want to tell <code>echo</code> to interpre...
823, 824, 19688, 78469
assembly, disassembly, shellcode, x86
<h1>How to disassemble a shellcode into assembly instruction?</h1> <p>Is there some tool to disassemble a raw hex into assembly instructions? for example: lets say we have <b>\xeb\x1d</b> that disassemble into <b>jmp 0x1f</b> according to <a href="http://shell-storm.org/online/Online-Assembler-and-Disassembler/" rel="n...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,991
bash
# How to disassemble a shellcode into assembly instruction? Is there some tool to disassemble a raw hex into assembly instructions? for example: lets say we have **\xeb\x1d** that disassemble into **jmp 0x1f** according to [this](http://shell-storm.org/online/Online-Assembler-and-Disassembler/) online disassembler. So...
As the comments have suggested, your issue is that you have output the string `\xeb\x1d` as ASCII into the file you are trying to disassemble. You may have done something like: ``` echo '\xeb\x1d' >foo ``` You can do this but you will want to tell `echo` to interpret the escape character `\`. This can be done with th...
44676356
How to wrap quotes around variable value in bash?
7
2017-06-21 12:37:14
<p>I have a variable</p> <pre><code>test=value.txt </code></pre> <p>I am using test as</p> <pre><code>$test </code></pre> <p>which gives me </p> <pre><code>value.txt </code></pre> <p>I want result as</p> <pre><code>'value.txt' </code></pre> <p>How can I achieve this?</p> <p><strong>Edit:</strong> Above is just...
33,239
6,534,673
2017-06-21 13:43:17
44,677,719
12
2017-06-21 13:36:01
6,309,601
2017-06-21 13:37:33
https://stackoverflow.com/q/44676356
https://stackoverflow.com/a/44677719
<p>Assignment using string:</p> <pre><code>test="'value.txt'" echo "$test" 'value.txt' </code></pre> <p>Assignment using variable:</p> <pre><code>var=value.txt test="'$var'" echo "$test" 'value.txt' </code></pre>
<p>Assignment using string:</p> <pre><code>test="'value.txt'" echo "$test" 'value.txt' </code></pre> <p>Assignment using variable:</p> <pre><code>var=value.txt test="'$var'" echo "$test" 'value.txt' </code></pre>
387
bash
<h1>How to wrap quotes around variable value in bash?</h1> <p>I have a variable</p> <pre><code>test=value.txt </code></pre> <p>I am using test as</p> <pre><code>$test </code></pre> <p>which gives me </p> <pre><code>value.txt </code></pre> <p>I want result as</p> <pre><code>'value.txt' </code></pre> <p>How can I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,992
bash
# How to wrap quotes around variable value in bash? I have a variable ``` test=value.txt ``` I am using test as ``` $test ``` which gives me ``` value.txt ``` I want result as ``` 'value.txt' ``` How can I achieve this? **Edit:** Above is just an example of the task I am trying to achieve. I can't change vari...
Assignment using string: ``` test="'value.txt'" echo "$test" 'value.txt' ``` Assignment using variable: ``` var=value.txt test="'$var'" echo "$test" 'value.txt' ```
43001805
What's the difference between 'eval $command' and $command?
7
2017-03-24 14:15:38
<p>What's the difference between:</p> <pre><code>eval echo lala </code></pre> <p>and:</p> <pre><code>command="echo lala" $command </code></pre> <p>They both seem to have the same effect but I might be missing something. Also, if they <strong>do</strong> have the same effect, what's the point of <code>eval</code> co...
5,272
1,030,598
2022-03-28 09:23:40
43,002,154
12
2017-03-24 14:31:09
4,323
2022-03-28 09:23:40
https://stackoverflow.com/q/43001805
https://stackoverflow.com/a/43002154
<p>Try this:</p> <pre><code>y='FOO=hello; echo $FOO' eval $y </code></pre> <p>It prints <code>hello</code>.</p> <p>But this:</p> <pre><code>$y </code></pre> <p>says:</p> <blockquote> <p>-bash: FOO=hello;: command not found</p> </blockquote> <p>So when you say <code>eval $y</code> it is just as if you had typed the cont...
<p>Try this:</p> <pre><code>y='FOO=hello; echo $FOO' eval $y </code></pre> <p>It prints <code>hello</code>.</p> <p>But this:</p> <pre><code>$y </code></pre> <p>says:</p> <blockquote> <p>-bash: FOO=hello;: command not found</p> </blockquote> <p>So when you say <code>eval $y</code> it is just as if you had typed the cont...
387, 4413
bash, eval
<h1>What's the difference between 'eval $command' and $command?</h1> <p>What's the difference between:</p> <pre><code>eval echo lala </code></pre> <p>and:</p> <pre><code>command="echo lala" $command </code></pre> <p>They both seem to have the same effect but I might be missing something. Also, if they <strong>do</s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,993
bash
# What's the difference between 'eval $command' and $command? What's the difference between: ``` eval echo lala ``` and: ``` command="echo lala" $command ``` They both seem to have the same effect but I might be missing something. Also, if they **do** have the same effect, what's the point of `eval` command?
Try this: ``` y='FOO=hello; echo $FOO' eval $y ``` It prints `hello`. But this: ``` $y ``` says: > -bash: FOO=hello;: command not found So when you say `eval $y` it is just as if you had typed the content of `$y` into the interpreter. But when you just say `$y` it needs to be a command that can be run, rather th...
39474047
sudo command on MacOS Sierra does not respect timestamp_timeout
7
2016-09-13 15:41:30
<p>After upgrading to MacOS Sierra (10.12), my <code>sudo</code> command seems to be acting differently. See the following test case:</p> <pre><code># Run in terminal pane #1: (should prompt for password) sudo -v # Run in terminal pane #2: (should NOT prompt for password) sudo -v </code></pre> <p>The above works as ...
6,231
3,247,081
2017-01-11 17:37:48
39,474,612
12
2016-09-13 16:11:29
3,247,081
2016-09-13 16:11:29
https://stackoverflow.com/q/39474047
https://stackoverflow.com/a/39474612
<p>After a ton of searching and comparing the <code>sudo</code> configuration on older OS versions to Sierra's (<code>sudo su; sudo -V</code>), it seems that Sierra enables <code>tty_tickets</code> by default now, causing the issues mentioned above. As far as I can tell, this was an undocumented change. To fix, the fol...
<p>After a ton of searching and comparing the <code>sudo</code> configuration on older OS versions to Sierra's (<code>sudo su; sudo -V</code>), it seems that Sierra enables <code>tty_tickets</code> by default now, causing the issues mentioned above. As far as I can tell, this was an undocumented change. To fix, the fol...
390, 1674, 120355
macos-sierra, shell, sudo
<h1>sudo command on MacOS Sierra does not respect timestamp_timeout</h1> <p>After upgrading to MacOS Sierra (10.12), my <code>sudo</code> command seems to be acting differently. See the following test case:</p> <pre><code># Run in terminal pane #1: (should prompt for password) sudo -v # Run in terminal pane #2: (shou...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,994
bash
# sudo command on MacOS Sierra does not respect timestamp_timeout After upgrading to MacOS Sierra (10.12), my `sudo` command seems to be acting differently. See the following test case: ``` # Run in terminal pane #1: (should prompt for password) sudo -v # Run in terminal pane #2: (should NOT prompt for password) sud...
After a ton of searching and comparing the `sudo` configuration on older OS versions to Sierra's (`sudo su; sudo -V`), it seems that Sierra enables `tty_tickets` by default now, causing the issues mentioned above. As far as I can tell, this was an undocumented change. To fix, the following needs to be added to the `/et...
38555554
Why is nvm command installed as root and also not found during vagrant bootstrap.sh?
7
2016-07-24 18:47:44
<p>When I try to install nvm and test that it's installed in my vagrant shell provisioning script, using:</p> <pre><code>sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash source ~/.bashrc nvm </code></pre> <p>I get:</p> <pre><code>==&gt; default: =&gt; Downloading nvm as scrip...
1,475
579,046
2016-07-24 18:49:57
38,555,578
12
2016-07-24 18:49:57
579,046
2016-07-24 18:49:57
https://stackoverflow.com/q/38555554
https://stackoverflow.com/a/38555578
<p>So first if you want to install somethnig as the vagrant user during a bootstrap.sh script, the easiest way to do that is to add another provisioner script to your Vagrantfile which is run in unprivileged mode:</p> <pre><code>config.vm.provision "ScriptRunAsRoot", type:"shell", path: "Vagrantdata/rootUserBootstrap....
<p>So first if you want to install somethnig as the vagrant user during a bootstrap.sh script, the easiest way to do that is to add another provisioner script to your Vagrantfile which is run in unprivileged mode:</p> <pre><code>config.vm.provision "ScriptRunAsRoot", type:"shell", path: "Vagrantdata/rootUserBootstrap....
387, 46426, 66981, 81748
bash, node.js, nvm, vagrant
<h1>Why is nvm command installed as root and also not found during vagrant bootstrap.sh?</h1> <p>When I try to install nvm and test that it's installed in my vagrant shell provisioning script, using:</p> <pre><code>sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash source ~/.bash...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,995
bash
# Why is nvm command installed as root and also not found during vagrant bootstrap.sh? When I try to install nvm and test that it's installed in my vagrant shell provisioning script, using: ``` sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash source ~/.bashrc nvm ``` I get: ...
So first if you want to install somethnig as the vagrant user during a bootstrap.sh script, the easiest way to do that is to add another provisioner script to your Vagrantfile which is run in unprivileged mode: ``` config.vm.provision "ScriptRunAsRoot", type:"shell", path: "Vagrantdata/rootUserBootstrap.sh" config.vm....
38483711
npm command not found error but node is installed
7
2016-07-20 14:12:40
<p>I installed node and npm with Homebrew a while ago, they both worked fine until today when I keep running into the <strong>npm command not found</strong> error. </p> <p>When is run <strong>$ whereis node</strong>, I get nothing back</p> <p>When I do <strong>$ which node</strong>, I see <strong>/usr/local/bin/node<...
41,641
4,996,722
2019-09-08 16:09:18
38,485,208
12
2016-07-20 15:51:20
4,996,722
2016-07-20 15:51:20
https://stackoverflow.com/q/38483711
https://stackoverflow.com/a/38485208
<p>Figured out the issue. So the root of the problem was that I installed npm using Homebrew and there are some issues with what goes on under the hood with Homebrew and npm. </p> <p>To fix this I did the following: </p> <pre><code>rm -rf /usr/local/lib/node_modules brew uninstall node brew install node --without-npm...
<p>Figured out the issue. So the root of the problem was that I installed npm using Homebrew and there are some issues with what goes on under the hood with Homebrew and npm. </p> <p>To fix this I did the following: </p> <pre><code>rm -rf /usr/local/lib/node_modules brew uninstall node brew install node --without-npm...
387, 1067, 46426, 61387, 115613
bash, homebrew, node.js, npm, npm-install
<h1>npm command not found error but node is installed</h1> <p>I installed node and npm with Homebrew a while ago, they both worked fine until today when I keep running into the <strong>npm command not found</strong> error. </p> <p>When is run <strong>$ whereis node</strong>, I get nothing back</p> <p>When I do <stron...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,996
bash
# npm command not found error but node is installed I installed node and npm with Homebrew a while ago, they both worked fine until today when I keep running into the **npm command not found** error. When is run **$ whereis node**, I get nothing back When I do **$ which node**, I see **/usr/local/bin/node** When I ...
Figured out the issue. So the root of the problem was that I installed npm using Homebrew and there are some issues with what goes on under the hood with Homebrew and npm. To fix this I did the following: ``` rm -rf /usr/local/lib/node_modules brew uninstall node brew install node --without-npm echo prefix=~/.npm-pac...
37852378
How to prompt for both user and password in curl command?
7
2016-06-16 07:18:29
<p>I am doing a post call to MarkLogic server using CURL command in Ubuntu.</p> <p>In the command if I'll write like </p> <pre><code>--user username </code></pre> <p>It will prompt for password.</p> <p>Is there any way to prompt for both username and password?</p> <p>Basically I don't want to hard code the usernam...
9,462
1,705,390
2020-09-29 06:20:14
37,853,021
12
2016-06-16 07:51:28
3,933,089
2020-09-29 06:20:14
https://stackoverflow.com/q/37852378
https://stackoverflow.com/a/37853021
<p>You'd have to do this in two steps: first read in the username, then use it in your <code>curl</code> command. So in <code>bash</code> it would come out something like this:</p> <pre><code>read -p &quot;Username: &quot; CURLUSER curl --user &quot;${CURLUSER}&quot; ... </code></pre> <p>If you wanted to, you could wra...
<p>You'd have to do this in two steps: first read in the username, then use it in your <code>curl</code> command. So in <code>bash</code> it would come out something like this:</p> <pre><code>read -p &quot;Username: &quot; CURLUSER curl --user &quot;${CURLUSER}&quot; ... </code></pre> <p>If you wanted to, you could wra...
58, 390, 549, 1554, 22082
curl, linux, marklogic, shell, ubuntu
<h1>How to prompt for both user and password in curl command?</h1> <p>I am doing a post call to MarkLogic server using CURL command in Ubuntu.</p> <p>In the command if I'll write like </p> <pre><code>--user username </code></pre> <p>It will prompt for password.</p> <p>Is there any way to prompt for both username an...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,997
bash
# How to prompt for both user and password in curl command? I am doing a post call to MarkLogic server using CURL command in Ubuntu. In the command if I'll write like ``` --user username ``` It will prompt for password. Is there any way to prompt for both username and password? Basically I don't want to hard code...
You'd have to do this in two steps: first read in the username, then use it in your `curl` command. So in `bash` it would come out something like this: ``` read -p "Username: " CURLUSER curl --user "${CURLUSER}" ... ``` If you wanted to, you could wrap this up in a little script, along these lines: ``` #!/bin/bash r...
36948220
Shell REGEX for date
7
2016-04-29 22:10:51
<p>I am trying to fix the users input if they input an incorrect date format that is not (YYYY-MM-DD) but I cant figure it out. Here is what I have:</p> <pre><code>while [ "$startDate" != "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" ] do echo "Please retype the start date (YYYY-MM-DD):" read startDate done </code></pre>
16,024
5,514,001
2018-03-30 04:29:50
36,948,243
12
2016-04-29 22:12:16
1,983,854
2016-04-29 22:17:31
https://stackoverflow.com/q/36948220
https://stackoverflow.com/a/36948243
<p>Instead of <code>!=</code>, you have to use <code>! $var =~ regex</code> to perform <a href="https://stackoverflow.com/a/21112809/1983854">regex comparisons</a>:</p> <pre><code>[[ $date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ^^ </code></pre> <p>So that your script can be like this:</p> <pre><code>date="" whi...
<p>Instead of <code>!=</code>, you have to use <code>! $var =~ regex</code> to perform <a href="https://stackoverflow.com/a/21112809/1983854">regex comparisons</a>:</p> <pre><code>[[ $date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ^^ </code></pre> <p>So that your script can be like this:</p> <pre><code>date="" whi...
18, 387, 390, 5002
bash, date, regex, shell
<h1>Shell REGEX for date</h1> <p>I am trying to fix the users input if they input an incorrect date format that is not (YYYY-MM-DD) but I cant figure it out. Here is what I have:</p> <pre><code>while [ "$startDate" != "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" ] do echo "Please retype the start date (YYYY-MM-DD):" read startD...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,998
bash
# Shell REGEX for date I am trying to fix the users input if they input an incorrect date format that is not (YYYY-MM-DD) but I cant figure it out. Here is what I have: ``` while [ "$startDate" != "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" ] do echo "Please retype the start date (YYYY-MM-DD):" read startDate done ```
Instead of `!=`, you have to use `! $var =~ regex` to perform [regex comparisons](https://stackoverflow.com/a/21112809/1983854): ``` [[ $date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ^^ ``` So that your script can be like this: ``` date="" while [[ ! $date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; do echo "enter da...
35141373
Toggle IIS Feature Delegation with Powershell
7
2016-02-01 22:10:47
<p>How can I change IIS "Feature Delegation" using Powershell. I want to change "Authentication - Anonymous" to read/write . I found this <a href="https://stackoverflow.com/questions/18136128/toggle-iis-7-5-authentication-anonymous-authentication-with-powershell-3-0">Toggle IIS 7.5 Authentication &quot;Anonymous Authe...
4,529
4,199,992
2016-02-23 22:50:02
35,169,293
12
2016-02-03 05:38:47
4,199,992
2016-02-03 05:38:47
https://stackoverflow.com/q/35141373
https://stackoverflow.com/a/35169293
<p>Finally found this link and it helped</p> <blockquote> <p><a href="http://forums.iis.net/t/1178408.aspx?PowerShell+command+Feature+Delegation+settings" rel="noreferrer">http://forums.iis.net/t/1178408.aspx?PowerShell+command+Feature+Delegation+settings</a></p> </blockquote> <p>Here are few examples.</p> <pre><c...
<p>Finally found this link and it helped</p> <blockquote> <p><a href="http://forums.iis.net/t/1178408.aspx?PowerShell+command+Feature+Delegation+settings" rel="noreferrer">http://forums.iis.net/t/1178408.aspx?PowerShell+command+Feature+Delegation+settings</a></p> </blockquote> <p>Here are few examples.</p> <pre><c...
215, 526
iis, powershell
<h1>Toggle IIS Feature Delegation with Powershell</h1> <p>How can I change IIS "Feature Delegation" using Powershell. I want to change "Authentication - Anonymous" to read/write . I found this <a href="https://stackoverflow.com/questions/18136128/toggle-iis-7-5-authentication-anonymous-authentication-with-powershell-3...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,000
bash
# Toggle IIS Feature Delegation with Powershell How can I change IIS "Feature Delegation" using Powershell. I want to change "Authentication - Anonymous" to read/write . I found this [Toggle IIS 7.5 Authentication "Anonymous Authentication" with Powershell 3.0?](https://stackoverflow.com/questions/18136128/toggle-iis-...
Finally found this link and it helped > <http://forums.iis.net/t/1178408.aspx?PowerShell+command+Feature+Delegation+settings> Here are few examples. ``` Set-WebConfiguration //System.WebServer/Security/Authentication/anonymousAuthentication -metadata overrideMode -value Allow -PSPath IIS:/ Set-WebConfiguration //Sy...
34751930
Read a python variable in a shell script?
7
2016-01-12 19:12:16
<p>my python file has these 2 variables:</p> <pre><code>week_date = "01/03/16-01/09/16" cust_id = "12345" </code></pre> <p>how can i read this into a shell script that takes in these 2 variables?</p> <p>my current shell script requires manual editing of "dt" and "id". I want to read the python variables into the she...
12,243
2,800,939
2023-12-04 07:36:19
34,752,001
12
2016-01-12 19:17:02
14,122
2023-12-03 22:35:40
https://stackoverflow.com/q/34751930
https://stackoverflow.com/a/34752001
<p>Consider something akin to the following:</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/bash # ^^^^ NOT /bin/sh, which doesn't have process substitution available. python_script=' import sys d = {} # create a dict to store values in exec(open(sys.argv[1], &quot;r&...
<p>Consider something akin to the following:</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/bash # ^^^^ NOT /bin/sh, which doesn't have process substitution available. python_script=' import sys d = {} # create a dict to store values in exec(open(sys.argv[1], &quot;r&...
16, 387, 390
bash, python, shell
<h1>Read a python variable in a shell script?</h1> <p>my python file has these 2 variables:</p> <pre><code>week_date = "01/03/16-01/09/16" cust_id = "12345" </code></pre> <p>how can i read this into a shell script that takes in these 2 variables?</p> <p>my current shell script requires manual editing of "dt" and "id...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,001
bash
# Read a python variable in a shell script? my python file has these 2 variables: ``` week_date = "01/03/16-01/09/16" cust_id = "12345" ``` how can i read this into a shell script that takes in these 2 variables? my current shell script requires manual editing of "dt" and "id". I want to read the python variables i...
Consider something akin to the following: ``` #!/bin/bash # ^^^^ NOT /bin/sh, which doesn't have process substitution available. python_script=' import sys d = {} # create a dict to store values in exec(open(sys.argv[1], "r").read(), d) # exec code with that dict as namespace for ...
34522426
Unable to write on /dev/* files
7
2015-12-30 03:14:22
<p>I'm writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows:</p> <ol> <li><code>alloc_chrdev_region()</code> -> to use dynamic allocation of major number</li> <li><code>class_create()</code> -> to create device class in sysfs</li> <li><code>device_creat()<...
8,400
4,204,404
2019-02-04 12:44:10
34,532,956
12
2015-12-30 16:07:10
5,466,118
2015-12-30 16:07:10
https://stackoverflow.com/q/34522426
https://stackoverflow.com/a/34532956
<p>I assume that you are normally not root on your bash shell. Then this command line</p> <pre><code>sudo echo 54 &gt; /dev/scull </code></pre> <p>does not what you think. The command is executed in two steps:</p> <ol> <li>The bash setups the output redirection, i.e., it tries to open <code>/dev/scull</code> with th...
<p>I assume that you are normally not root on your bash shell. Then this command line</p> <pre><code>sudo echo 54 &gt; /dev/scull </code></pre> <p>does not what you think. The command is executed in two steps:</p> <ol> <li>The bash setups the output redirection, i.e., it tries to open <code>/dev/scull</code> with th...
58, 387, 390, 21751, 21990
bash, linux, linux-device-driver, linux-kernel, shell
<h1>Unable to write on /dev/* files</h1> <p>I'm writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows:</p> <ol> <li><code>alloc_chrdev_region()</code> -> to use dynamic allocation of major number</li> <li><code>class_create()</code> -> to create device clas...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,002
bash
# Unable to write on /dev/* files I'm writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows: 1. `alloc_chrdev_region()` -> to use dynamic allocation of major number 2. `class_create()` -> to create device class in sysfs 3. `device_creat()` -> to create device und...
I assume that you are normally not root on your bash shell. Then this command line ``` sudo echo 54 > /dev/scull ``` does not what you think. The command is executed in two steps: 1. The bash setups the output redirection, i.e., it tries to open `/dev/scull` with the current user privileges. 2. The command `sudo ech...
34528572
Redirection to 'NUL' failed: FileStream will not open Win32 devices
7
2015-12-30 11:25:03
<p>I am trying to remove some verbosity from a <code>choco install</code> command within AppVeyor. Here is what I been trying (as suggested <a href="https://stackoverflow.com/a/4507627/136285">here</a>):</p> <pre><code>if (Test-Path "C:/ProgramData/chocolatey/bin/swig.exe") { echo "using swig from cache" } else { ...
3,397
136,285
2015-12-30 14:07:11
34,531,086
12
2015-12-30 14:05:26
1,630,171
2015-12-30 14:05:26
https://stackoverflow.com/q/34528572
https://stackoverflow.com/a/34531086
<p><code>nul</code> is batch syntax. In PowerShell you can use <code>$null</code> instead, as Mathias R. Jessen pointed out in his comment:</p> <pre><code>choco install swig &gt; $null </code></pre> <p>Other options are piping into the <code>Out-Null</code> cmdlet, collecting the output in a variable, or casting it t...
<p><code>nul</code> is batch syntax. In PowerShell you can use <code>$null</code> instead, as Mathias R. Jessen pointed out in his comment:</p> <pre><code>choco install swig &gt; $null </code></pre> <p>Other options are piping into the <code>Out-Null</code> cmdlet, collecting the output in a variable, or casting it t...
526, 80758, 107817
appveyor, chocolatey, powershell
<h1>Redirection to 'NUL' failed: FileStream will not open Win32 devices</h1> <p>I am trying to remove some verbosity from a <code>choco install</code> command within AppVeyor. Here is what I been trying (as suggested <a href="https://stackoverflow.com/a/4507627/136285">here</a>):</p> <pre><code>if (Test-Path "C:/Progr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,003
bash
# Redirection to 'NUL' failed: FileStream will not open Win32 devices I am trying to remove some verbosity from a `choco install` command within AppVeyor. Here is what I been trying (as suggested [here](https://stackoverflow.com/a/4507627/136285)): ``` if (Test-Path "C:/ProgramData/chocolatey/bin/swig.exe") { ech...
`nul` is batch syntax. In PowerShell you can use `$null` instead, as Mathias R. Jessen pointed out in his comment: ``` choco install swig > $null ``` Other options are piping into the `Out-Null` cmdlet, collecting the output in a variable, or casting it to `void`: ``` choco install swig | Out-Null $dummy = choco ins...
31913593
REGEX for multiple lines - powershell
7
2015-08-10 07:13:47
<p>I have a little problem with regex in powershell. My REGEX works only for one line. I need to work on multiple lines. </p> <p>For example html:</p> <pre><code>&lt;li&gt; test &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I want REGEX took everything, including "/ul>". My suggestion is:</p> <pre><code>'(^.*&lt;li&gt;....
12,944
4,229,913
2015-08-10 12:33:55
31,913,871
12
2015-08-10 07:29:00
1,163,423
2015-08-10 07:29:00
https://stackoverflow.com/q/31913593
https://stackoverflow.com/a/31913871
<p>It <strong>depends</strong> on what regex method you are using. </p> <p>If you use the .NET <code>Regex::Match</code>, there is a third parameter where you can define additional <code>regex</code>options. Use <code>[System.Text.RegularExpressions.RegexOptions]::Singleline</code> here:</p> <pre><code>$html = @' &l...
<p>It <strong>depends</strong> on what regex method you are using. </p> <p>If you use the .NET <code>Regex::Match</code>, there is a third parameter where you can define additional <code>regex</code>options. Use <code>[System.Text.RegularExpressions.RegexOptions]::Singleline</code> here:</p> <pre><code>$html = @' &l...
18, 526
powershell, regex
<h1>REGEX for multiple lines - powershell</h1> <p>I have a little problem with regex in powershell. My REGEX works only for one line. I need to work on multiple lines. </p> <p>For example html:</p> <pre><code>&lt;li&gt; test &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I want REGEX took everything, including "/ul>". My ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,004
bash
# REGEX for multiple lines - powershell I have a little problem with regex in powershell. My REGEX works only for one line. I need to work on multiple lines. For example html: ``` <li> test </li> </ul> ``` I want REGEX took everything, including "/ul>". My suggestion is: ``` '(^.*<li>.*</ul>)' ``` But it donesn't...
It **depends** on what regex method you are using. If you use the .NET `Regex::Match`, there is a third parameter where you can define additional `regex`options. Use `[System.Text.RegularExpressions.RegexOptions]::Singleline` here: ``` $html = @' <li> test </li> </ul> '@ $regex = '(^.*<li>.*\</ul>)' [regex]::Matc...
31534079
Use of $- in shell script
7
2015-07-21 08:34:52
<p>What is use of $- in Unix. In My system, the output is,</p> <pre><code>$ echo $- himBH $ </code></pre> <p>what is meant by himBH? what it stands for.</p> <p>Thanks in Advance...</p>
5,921
5,063,789
2015-07-21 08:56:14
31,534,141
12
2015-07-21 08:38:13
1,022,525
2015-07-21 08:56:14
https://stackoverflow.com/q/31534079
https://stackoverflow.com/a/31534141
<p>It returns the current shell's flags. The <code>$-</code> variable contains the shell's flags currently active in your terminal. These flags determine how your shell will function for you. In your case, these flags have the following meaning (note that all of these are defaults):</p> <ul> <li><p><strong>h</strong>:...
<p>It returns the current shell's flags. The <code>$-</code> variable contains the shell's flags currently active in your terminal. These flags determine how your shell will function for you. In your case, these flags have the following meaning (note that all of these are defaults):</p> <ul> <li><p><strong>h</strong>:...
34, 58, 387, 390
bash, linux, shell, unix
<h1>Use of $- in shell script</h1> <p>What is use of $- in Unix. In My system, the output is,</p> <pre><code>$ echo $- himBH $ </code></pre> <p>what is meant by himBH? what it stands for.</p> <p>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
11,005
bash
# Use of $- in shell script What is use of $- in Unix. In My system, the output is, ``` $ echo $- himBH $ ``` what is meant by himBH? what it stands for. Thanks in Advance...
It returns the current shell's flags. The `$-` variable contains the shell's flags currently active in your terminal. These flags determine how your shell will function for you. In your case, these flags have the following meaning (note that all of these are defaults): - **h**: Short for “hashall” (read that “hash all...
31478105
PowerShell Script to Delete XML Element
7
2015-07-17 14:23:56
<p>I have an XML doccument that looks like this:</p> <pre><code>&lt;Task&gt; &lt;Settings&gt; &lt;/Settings&gt; &lt;Sub&gt;foo&lt;/Sub&gt; &lt;Body&gt;bar&lt;/Body&gt; &lt;/Task&gt; </code></pre> <p>From PowerShell I can happily get the contents of 'Sub' and 'Body' using:</p> <pre><code>$Body = $XMLF...
21,652
3,012,508
2015-07-18 12:55:14
31,479,126
12
2015-07-17 15:16:32
712,649
2015-07-18 12:55:14
https://stackoverflow.com/q/31478105
https://stackoverflow.com/a/31479126
<p>You can use <code>Where-Object</code> to find the Child nodes you want to remove and then call <code>RemoveChild()</code>:</p> <pre><code>$Input = "C:\path\task.xml" $Output = "C:\path\newtask.xml" # Load the existing document $Doc = [xml](Get-Content $Input) # Specify tag names to delete and then find them $Dele...
<p>You can use <code>Where-Object</code> to find the Child nodes you want to remove and then call <code>RemoveChild()</code>:</p> <pre><code>$Input = "C:\path\task.xml" $Output = "C:\path\newtask.xml" # Load the existing document $Doc = [xml](Get-Content $Input) # Specify tag names to delete and then find them $Dele...
19, 526, 1227
powershell, xml, xpath
<h1>PowerShell Script to Delete XML Element</h1> <p>I have an XML doccument that looks like this:</p> <pre><code>&lt;Task&gt; &lt;Settings&gt; &lt;/Settings&gt; &lt;Sub&gt;foo&lt;/Sub&gt; &lt;Body&gt;bar&lt;/Body&gt; &lt;/Task&gt; </code></pre> <p>From PowerShell I can happily get the contents of 'Sub...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,006
bash
# PowerShell Script to Delete XML Element I have an XML doccument that looks like this: ``` <Task> <Settings> </Settings> <Sub>foo</Sub> <Body>bar</Body> </Task> ``` From PowerShell I can happily get the contents of 'Sub' and 'Body' using: ``` $Body = $XMLFile.Task.Body ``` But I am trying to REMOV...
You can use `Where-Object` to find the Child nodes you want to remove and then call `RemoveChild()`: ``` $Input = "C:\path\task.xml" $Output = "C:\path\newtask.xml" # Load the existing document $Doc = [xml](Get-Content $Input) # Specify tag names to delete and then find them $DeleteNames = "Sub","Body" ($Doc.Task.Ch...
31415158
Powershell - JSON file to table
7
2015-07-14 19:02:16
<p>I am trying to get into Powershell and am trying to convert a simple JSON file to table format.</p> <p>The json-file looks like this:</p> <pre><code>{ "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ] }, { "Id" : 2, "Details" : [ { "FirstName" : "Ben" }, { "LastName...
19,890
3,873,139
2015-07-14 19:43:36
31,415,897
12
2015-07-14 19:43:36
3,829,407
2015-07-14 19:43:36
https://stackoverflow.com/q/31415158
https://stackoverflow.com/a/31415897
<p>JSON is not my strength but if you look at the data structure ID is not on the same level as first and last name which is nested in details. I put the data in a here-string for testing. </p> <pre><code>$json = @" { "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ...
<p>JSON is not my strength but if you look at the data structure ID is not on the same level as first and last name which is nested in details. I put the data in a here-string for testing. </p> <pre><code>$json = @" { "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ...
526, 1508, 73157
json, powershell, powershell-3.0
<h1>Powershell - JSON file to table</h1> <p>I am trying to get into Powershell and am trying to convert a simple JSON file to table format.</p> <p>The json-file looks like this:</p> <pre><code>{ "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ] }, { "Id" : 2, "Details"...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,007
bash
# Powershell - JSON file to table I am trying to get into Powershell and am trying to convert a simple JSON file to table format. The json-file looks like this: ``` { "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ] }, { "Id" : 2, "Details" : [ { "FirstName" : "Ben" ...
JSON is not my strength but if you look at the data structure ID is not on the same level as first and last name which is nested in details. I put the data in a here-string for testing. ``` $json = @" { "Members" : [ { "Id" : 1, "Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ] }, { "Id"...
27683581
Why can't pgrep find this process?
7
2014-12-29 04:53:32
<p>If I execute the following, which is just a long command that will wait forever</p> <pre><code>grep 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa abcd' </code></pre> <p>then <code>pgrep -f</code> can't find the process, if I search for <code>abcd</code> which is contained in the last segm...
13,391
3,293,148
2014-12-29 14:03:31
27,684,015
12
2014-12-29 05:50:07
548,225
2014-12-29 05:50:07
https://stackoverflow.com/q/27683581
https://stackoverflow.com/a/27684015
<p>Your edited command is found by either of these commands:</p> <pre><code>pgrep -f abcd </code></pre> <p>or even:</p> <pre><code>ps uxww | grep '[a]bcd' </code></pre>
<p>Your edited command is found by either of these commands:</p> <pre><code>pgrep -f abcd </code></pre> <p>or even:</p> <pre><code>ps uxww | grep '[a]bcd' </code></pre>
58, 387, 1271, 12645
bash, grep, linux, ps
<h1>Why can't pgrep find this process?</h1> <p>If I execute the following, which is just a long command that will wait forever</p> <pre><code>grep 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa abcd' </code></pre> <p>then <code>pgrep -f</code> can't find the process, if I search for <code>abc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,008
bash
# Why can't pgrep find this process? If I execute the following, which is just a long command that will wait forever ``` grep 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa abcd' ``` then `pgrep -f` can't find the process, if I search for `abcd` which is contained in the last segment of the ...
Your edited command is found by either of these commands: ``` pgrep -f abcd ``` or even: ``` ps uxww | grep '[a]bcd' ```
26820590
How can i use XmlReader in PowerShell to stream big/huge XML files?
7
2014-11-08 18:31:08
<p>I have an XML of couple of gigabytes. There are no spaces in the XML.</p> <p>So I wrote a little C# code to split in single files (which has some additional code to perform some stuff e.g. randomizing while testing)</p> <pre><code>using (XmlReader MyReader = XmlReader.Create(@"d:\xml\test.xml")) { ...
11,626
121,626
2020-01-13 14:30:23
26,820,939
12
2014-11-08 19:05:20
2,627,148
2014-11-13 15:56:51
https://stackoverflow.com/q/26820590
https://stackoverflow.com/a/26820939
<p>This should be pretty close to what you wanted to do in Powershell:</p> <pre><code>$f = [System.Xml.XmlReader]::create("d:\xml\test.xml") while ($f.read()) { switch ($f.NodeType) { ([System.Xml.XmlNodeType]::Element) # Make sure to put this between brackets { if ($f.Name -eq "Cu...
<p>This should be pretty close to what you wanted to do in Powershell:</p> <pre><code>$f = [System.Xml.XmlReader]::create("d:\xml\test.xml") while ($f.read()) { switch ($f.NodeType) { ([System.Xml.XmlNodeType]::Element) # Make sure to put this between brackets { if ($f.Name -eq "Cu...
19, 526
powershell, xml
<h1>How can i use XmlReader in PowerShell to stream big/huge XML files?</h1> <p>I have an XML of couple of gigabytes. There are no spaces in the XML.</p> <p>So I wrote a little C# code to split in single files (which has some additional code to perform some stuff e.g. randomizing while testing)</p> <pre><code>using (...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,009
bash
# How can i use XmlReader in PowerShell to stream big/huge XML files? I have an XML of couple of gigabytes. There are no spaces in the XML. So I wrote a little C# code to split in single files (which has some additional code to perform some stuff e.g. randomizing while testing) ``` using (XmlReader MyReader = XmlRea...
This should be pretty close to what you wanted to do in Powershell: ``` $f = [System.Xml.XmlReader]::create("d:\xml\test.xml") while ($f.read()) { switch ($f.NodeType) { ([System.Xml.XmlNodeType]::Element) # Make sure to put this between brackets { if ($f.Name -eq "Customer") ...
26480004
Making paste command read from standard input
7
2014-10-21 06:11:56
<pre><code>$paste num let 1 a 2 b 3 c 4 d </code></pre> <p>So when I do</p> <pre><code>$ cat num | paste - - 1 2 3 4 </code></pre> <p>My question is why doesn't "<code>cat num | paste - -</code>" generate the output as:</p> <pre><code>1 1 2 2 3 3 4 4 </code></pre>
7,459
3,384,373
2021-12-20 10:05:38
26,480,035
12
2014-10-21 06:14:52
15,168
2014-10-21 06:33:23
https://stackoverflow.com/q/26480004
https://stackoverflow.com/a/26480035
<p>Clearly, <code>paste</code> reads a line from the first 'file' (which is standard input), and then a line from the second 'file' (which is also standard input) and pastes them to create the first line of output. Then it repeats.</p> <p>The POSIX specification for <a href="http://pubs.opengroup.org/onlinepubs/96999...
<p>Clearly, <code>paste</code> reads a line from the first 'file' (which is standard input), and then a line from the second 'file' (which is also standard input) and pastes them to create the first line of output. Then it repeats.</p> <p>The POSIX specification for <a href="http://pubs.opengroup.org/onlinepubs/96999...
58, 390, 10425
linux, paste, shell
<h1>Making paste command read from standard input</h1> <pre><code>$paste num let 1 a 2 b 3 c 4 d </code></pre> <p>So when I do</p> <pre><code>$ cat num | paste - - 1 2 3 4 </code></pre> <p>My question is why doesn't "<code>cat num | paste - -</code>" generate the output as:</p> <pre><code>1 1...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,010
bash
# Making paste command read from standard input ``` $paste num let 1 a 2 b 3 c 4 d ``` So when I do ``` $ cat num | paste - - 1 2 3 4 ``` My question is why doesn't "`cat num | paste - -`" generate the output as: ``` 1 1 2 2 3 3 4 4 ```
Clearly, `paste` reads a line from the first 'file' (which is standard input), and then a line from the second 'file' (which is also standard input) and pastes them to create the first line of output. Then it repeats. The POSIX specification for [`paste`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/paste...
26451551
How to convert multiline file into a string in bash with newline character?
7
2014-10-19 14:32:31
<p>How can I convert a file with multiple lines to a string with <code>\n</code> characters in bash? </p> <p>For example - I have a certificate that I need to configure in my configuration <code>JSON</code> file so instead of having </p> <pre class="lang-none prettyprint-override"><code>-----BEGIN CERTIFICATE----- ...
8,781
1,068,746
2020-08-24 15:35:49
26,451,573
12
2014-10-19 14:35:22
1,066,031
2014-10-19 14:38:59
https://stackoverflow.com/q/26451551
https://stackoverflow.com/a/26451573
<p>One way using <code>awk</code>:</p> <pre class="lang-none prettyprint-override"><code>$ awk '$1=$1' ORS='\\n' file -----BEGIN CERTIFICATE-----\nMIIDBjCCMIIDB\nMIIDBjCCMIIDB\n....\nMIIDBjCCMIIDB==\n-----END CERTIFICATE-----\n </code></pre>
<p>One way using <code>awk</code>:</p> <pre class="lang-none prettyprint-override"><code>$ awk '$1=$1' ORS='\\n' file -----BEGIN CERTIFICATE-----\nMIIDBjCCMIIDB\nMIIDBjCCMIIDB\n....\nMIIDBjCCMIIDB==\n-----END CERTIFICATE-----\n </code></pre>
58, 387
bash, linux
<h1>How to convert multiline file into a string in bash with newline character?</h1> <p>How can I convert a file with multiple lines to a string with <code>\n</code> characters in bash? </p> <p>For example - I have a certificate that I need to configure in my configuration <code>JSON</code> file so instead of having <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,011
bash
# How to convert multiline file into a string in bash with newline character? How can I convert a file with multiple lines to a string with `\n` characters in bash? For example - I have a certificate that I need to configure in my configuration `JSON` file so instead of having ``` -----BEGIN CERTIFICATE----- MIIDBjC...
One way using `awk`: ``` $ awk '$1=$1' ORS='\\n' file -----BEGIN CERTIFICATE-----\nMIIDBjCCMIIDB\nMIIDBjCCMIIDB\n....\nMIIDBjCCMIIDB==\n-----END CERTIFICATE-----\n ```
25828883
add a number in fish script
7
2014-09-14 00:02:55
<p>I want to have a function that gets the number of lines of output from a command and adds one to it. So far I have this:</p> <pre><code>function add1 set num (tmux list-sessions | wc -l) echo $num end </code></pre> <p>Now how do I add <code>1</code> to <code>$num</code>? (or while I'm assigning the variabl...
3,312
2,865,156
2014-09-14 00:06:36
25,828,897
12
2014-09-14 00:06:36
14,122
2014-09-14 00:06:36
https://stackoverflow.com/q/25828883
https://stackoverflow.com/a/25828897
<p>See the <code>math</code> command in the <A HREF="http://fishshell.com/docs/2.0/commands.html" rel="noreferrer">user documentation</A>:</p> <pre><code>set num (math $num + 1) </code></pre>
<p>See the <code>math</code> command in the <A HREF="http://fishshell.com/docs/2.0/commands.html" rel="noreferrer">user documentation</A>:</p> <pre><code>set num (math $num + 1) </code></pre>
390, 55824
fish, shell
<h1>add a number in fish script</h1> <p>I want to have a function that gets the number of lines of output from a command and adds one to it. So far I have this:</p> <pre><code>function add1 set num (tmux list-sessions | wc -l) echo $num end </code></pre> <p>Now how do I add <code>1</code> to <code>$num</code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,012
bash
# add a number in fish script I want to have a function that gets the number of lines of output from a command and adds one to it. So far I have this: ``` function add1 set num (tmux list-sessions | wc -l) echo $num end ``` Now how do I add `1` to `$num`? (or while I'm assigning the variable)
See the `math` command in the [user documentation](http://fishshell.com/docs/2.0/commands.html): ``` set num (math $num + 1) ```
25320047
Synchronous child process calls for shell scripting (including CLI) in Node.js 0.10.x
7
2014-08-15 01:32:21
<p>Synchronous child process calls <a href="http://strongloop.com/strongblog/whats-new-in-node-js-v0-12-execsync-a-synchronous-api-for-child-processes/">are now available</a> in the versions of Node.js that are under development (i.e. unstable). This is great news for writing shell scripts, as it will allow code like t...
7,084
null
2014-08-17 10:49:33
25,326,005
12
2014-08-15 11:58:04
null
2014-08-17 10:49:33
https://stackoverflow.com/q/25320047
https://stackoverflow.com/a/25326005
<p>Let's look at three options: the two mentioned in the question, plus <a href="https://www.npmjs.org/package/execsync">execsync</a>.</p> <h2><a href="https://www.npmjs.org/package/shelljs">shelljs</a></h2> <p><code>shelljs</code> is much more than a library for calling child processes. Primarily, it is a cross-plat...
<p>Let's look at three options: the two mentioned in the question, plus <a href="https://www.npmjs.org/package/execsync">execsync</a>.</p> <h2><a href="https://www.npmjs.org/package/shelljs">shelljs</a></h2> <p><code>shelljs</code> is much more than a library for calling child processes. Primarily, it is a cross-plat...
3, 390, 9696, 11225, 46426
command-line-interface, javascript, node.js, popen, shell
<h1>Synchronous child process calls for shell scripting (including CLI) in Node.js 0.10.x</h1> <p>Synchronous child process calls <a href="http://strongloop.com/strongblog/whats-new-in-node-js-v0-12-execsync-a-synchronous-api-for-child-processes/">are now available</a> in the versions of Node.js that are under developm...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,013
bash
# Synchronous child process calls for shell scripting (including CLI) in Node.js 0.10.x Synchronous child process calls [are now available](http://strongloop.com/strongblog/whats-new-in-node-js-v0-12-execsync-a-synchronous-api-for-child-processes/) in the versions of Node.js that are under development (i.e. unstable)....
Let's look at three options: the two mentioned in the question, plus [execsync](https://www.npmjs.org/package/execsync). ## [shelljs](https://www.npmjs.org/package/shelljs) `shelljs` is much more than a library for calling child processes. Primarily, it is a cross-platform JavaScript implementation of several POSIX u...
25150238
locate behavior with bash wildcards
7
2014-08-06 00:01:49
<p>I have</p> <pre><code>$ ls -l re*trict ls: cannot access re*trict: No such file or directory </code></pre> <p>Why does this give 0 matches?</p> <pre><code>$ locate -c 're*trict' 0 $ locate -c re*trict 0 $ locate -c re?trict 0 </code></pre> <p>This works though and gives 8351 matches:</p> <pre><code>$ locate -c ...
4,018
494,074
2014-08-06 00:25:40
25,150,322
12
2014-08-06 00:09:15
1,899,640
2014-08-06 00:09:15
https://stackoverflow.com/q/25150238
https://stackoverflow.com/a/25150322
<p><code>locate</code> matches against the full path name. To find <code>re*trict</code> as a substring, you have to add <code>*</code> before and after it:</p> <pre><code>locate '*re*trict*' </code></pre>
<p><code>locate</code> matches against the full path name. To find <code>re*trict</code> as a substring, you have to add <code>*</code> before and after it:</p> <pre><code>locate '*re*trict*' </code></pre>
58, 387, 390
bash, linux, shell
<h1>locate behavior with bash wildcards</h1> <p>I have</p> <pre><code>$ ls -l re*trict ls: cannot access re*trict: No such file or directory </code></pre> <p>Why does this give 0 matches?</p> <pre><code>$ locate -c 're*trict' 0 $ locate -c re*trict 0 $ locate -c re?trict 0 </code></pre> <p>This works though and giv...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,014
bash
# locate behavior with bash wildcards I have ``` $ ls -l re*trict ls: cannot access re*trict: No such file or directory ``` Why does this give 0 matches? ``` $ locate -c 're*trict' 0 $ locate -c re*trict 0 $ locate -c re?trict 0 ``` This works though and gives 8351 matches: ``` $ locate -c restrict 8351 ```
`locate` matches against the full path name. To find `re*trict` as a substring, you have to add `*` before and after it: ``` locate '*re*trict*' ```
24482137
What does "- < /dev/null" mean in "gcc -dM -E - < /dev/null"?
7
2014-06-30 02:13:25
<p>I know that using</p> <pre class="lang-bash prettyprint-override"><code>gcc -dM -E - &lt; /dev/null </code></pre> <p>can get the predifined macros of <code>gcc</code>, but what does the </p> <pre class="lang-bash prettyprint-override"><code>- &lt; /dev/null </code></pre> <p>mean in this command? Per my understan...
1,275
2,106,207
2014-06-30 09:04:45
24,482,299
12
2014-06-30 02:41:33
3,614,835
2014-06-30 02:41:33
https://stackoverflow.com/q/24482137
https://stackoverflow.com/a/24482299
<p>On its own, <code>-</code> means "read from standard input instead of the filename that would otherwise be provided on this command-line". This is a common Unix convention.</p> <p>The <code>&lt; /dev/null</code> redirects standard input from <code>/dev/null</code>, which is of length 0. Thus GCC will read from st...
<p>On its own, <code>-</code> means "read from standard input instead of the filename that would otherwise be provided on this command-line". This is a common Unix convention.</p> <p>The <code>&lt; /dev/null</code> redirects standard input from <code>/dev/null</code>, which is of length 0. Thus GCC will read from st...
8, 10, 387, 1477
bash, c, c++, gcc
<h1>What does "- < /dev/null" mean in "gcc -dM -E - < /dev/null"?</h1> <p>I know that using</p> <pre class="lang-bash prettyprint-override"><code>gcc -dM -E - &lt; /dev/null </code></pre> <p>can get the predifined macros of <code>gcc</code>, but what does the </p> <pre class="lang-bash prettyprint-override"><code>- ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,015
bash
# What does "- < /dev/null" mean in "gcc -dM -E - < /dev/null"? I know that using ``` gcc -dM -E - < /dev/null ``` can get the predifined macros of `gcc`, but what does the ``` - < /dev/null ``` mean in this command? Per my understanding, there should be a option behind `-`. I have tried to search on [gcc manual](...
On its own, `-` means "read from standard input instead of the filename that would otherwise be provided on this command-line". This is a common Unix convention. The `< /dev/null` redirects standard input from `/dev/null`, which is of length 0. Thus GCC will read from standard input and immediately reach the end of th...
22626932
expr: non-integer argument. How to subtract dot-decimal numbers
7
2014-03-25 06:28:09
<p>I am trying to subtract two numbers by running the following bash script:</p> <pre><code>#!/bin/bash -x cur_length=`cat length.txt` cur_pos=`cat pos.txt` diff=`$(expr $cur_length - $cur_pos)` echo "$diff" </code></pre> <p>But the output says expr has some issue:</p> <pre><code>+++ expr 235.68 - 145.9 expr: non-i...
16,145
3,343,273
2021-08-27 14:14:16
22,627,105
12
2014-03-25 06:38:19
3,030,305
2014-03-25 06:48:24
https://stackoverflow.com/q/22626932
https://stackoverflow.com/a/22627105
<p>Bash doesn't do fractions, just integers. Use <code>bc</code> instead:</p> <pre><code>$ echo '235.68 - 145.9' | bc 89.78 </code></pre> <p>That result can, of course, be put in a shell variable the same way that you were doing with <code>expr</code>:</p> <pre><code>$ diff="$(echo '235.68 - 145.9' | bc)" $ echo ...
<p>Bash doesn't do fractions, just integers. Use <code>bc</code> instead:</p> <pre><code>$ echo '235.68 - 145.9' | bc 89.78 </code></pre> <p>That result can, of course, be put in a shell variable the same way that you were doing with <code>expr</code>:</p> <pre><code>$ diff="$(echo '235.68 - 145.9' | bc)" $ echo ...
387
bash
<h1>expr: non-integer argument. How to subtract dot-decimal numbers</h1> <p>I am trying to subtract two numbers by running the following bash script:</p> <pre><code>#!/bin/bash -x cur_length=`cat length.txt` cur_pos=`cat pos.txt` diff=`$(expr $cur_length - $cur_pos)` echo "$diff" </code></pre> <p>But the output says...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,016
bash
# expr: non-integer argument. How to subtract dot-decimal numbers I am trying to subtract two numbers by running the following bash script: ``` #!/bin/bash -x cur_length=`cat length.txt` cur_pos=`cat pos.txt` diff=`$(expr $cur_length - $cur_pos)` echo "$diff" ``` But the output says expr has some issue: ``` +++ ex...
Bash doesn't do fractions, just integers. Use `bc` instead: ``` $ echo '235.68 - 145.9' | bc 89.78 ``` That result can, of course, be put in a shell variable the same way that you were doing with `expr`: ``` $ diff="$(echo '235.68 - 145.9' | bc)" $ echo $diff 89.78 ```
22039200
unix shell script for checking three variables are same
7
2014-02-26 10:56:28
<p>i want to check if all three variables are same then print msg</p> <pre><code>if [ "$x1" == "$x2" == "$3" ]; then echo "all are same" fi </code></pre> <p>I am getting this error:</p> <blockquote> <p>[: too many arguments</p> </blockquote>
6,773
3,250,373
2014-02-26 14:23:18
22,039,240
12
2014-02-26 10:58:16
1,983,854
2014-02-26 10:58:16
https://stackoverflow.com/q/22039200
https://stackoverflow.com/a/22039240
<p>You cannot compare three variables at the time. Instead, do compare them in blocks of two:</p> <pre><code>if [ "$x1" = "$x2" ] &amp;&amp; [ "$x2" = "$x3" ]; then echo "all are same" fi </code></pre>
<p>You cannot compare three variables at the time. Instead, do compare them in blocks of two:</p> <pre><code>if [ "$x1" = "$x2" ] &amp;&amp; [ "$x2" = "$x3" ]; then echo "all are same" fi </code></pre>
34, 387, 390
bash, shell, unix
<h1>unix shell script for checking three variables are same</h1> <p>i want to check if all three variables are same then print msg</p> <pre><code>if [ "$x1" == "$x2" == "$3" ]; then echo "all are same" fi </code></pre> <p>I am getting this error:</p> <blockquote> <p>[: too many arguments</p> </blockquote>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,017
bash
# unix shell script for checking three variables are same i want to check if all three variables are same then print msg ``` if [ "$x1" == "$x2" == "$3" ]; then echo "all are same" fi ``` I am getting this error: > [: too many arguments
You cannot compare three variables at the time. Instead, do compare them in blocks of two: ``` if [ "$x1" = "$x2" ] && [ "$x2" = "$x3" ]; then echo "all are same" fi ```
22003995
Replacing first column csv with variable
7
2014-02-25 03:29:38
<p>I can't believe I couldn't find my question anywhere else in the bash/linux community. I simply want to replace the first column of my csv file with a variable...</p> <pre><code>0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14...
6,158
2,143,205
2016-08-12 03:39:06
22,004,005
12
2014-02-25 03:31:04
970,195
2014-02-25 03:36:08
https://stackoverflow.com/q/22003995
https://stackoverflow.com/a/22004005
<p>This should work: </p> <pre><code>awk -v dt="$date" 'BEGIN{FS=OFS=","}{$1=dt}1' inputFile </code></pre> <p><strong>Explaination:</strong></p> <ul> <li>Use <code>-v</code> option to set an <code>awk</code> variable and assign it your <code>shell</code> variable. </li> <li>Set the Input Field Separator and Output F...
<p>This should work: </p> <pre><code>awk -v dt="$date" 'BEGIN{FS=OFS=","}{$1=dt}1' inputFile </code></pre> <p><strong>Explaination:</strong></p> <ul> <li>Use <code>-v</code> option to set an <code>awk</code> variable and assign it your <code>shell</code> variable. </li> <li>Set the Input Field Separator and Output F...
73, 387, 990, 5282
awk, bash, csv, sed
<h1>Replacing first column csv with variable</h1> <p>I can't believe I couldn't find my question anywhere else in the bash/linux community. I simply want to replace the first column of my csv file with a variable...</p> <pre><code>0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,018
bash
# Replacing first column csv with variable I can't believe I couldn't find my question anywhere else in the bash/linux community. I simply want to replace the first column of my csv file with a variable... ``` 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14...
This should work: ``` awk -v dt="$date" 'BEGIN{FS=OFS=","}{$1=dt}1' inputFile ``` **Explaination:** - Use `-v` option to set an `awk` variable and assign it your `shell` variable. - Set the Input Field Separator and Output Field Separator to `,` (since it is a csv) - Set the value of `$1` to your `awk` variable. - `...
21821968
Shell Script to get exception from logs for last one hour
7
2014-02-17 06:10:09
<p>I am developing script which will grep logs of last one hour and check any exception and send email for solaris platform.</p> <p>I did following steps</p> <pre><code>grep -n -h date +'%Y-%m-%d %H:%M' test.logs </code></pre> <p>above command gives me line number and then i do following</p> <pre><code>tail +618331...
21,023
627,855
2014-03-01 22:08:22
21,822,546
12
2014-02-17 06:51:02
3,030,305
2014-02-18 21:54:14
https://stackoverflow.com/q/21821968
https://stackoverflow.com/a/21822546
<p>With GNU <code>date</code>, one can use:</p> <pre><code> grep "^$(date -d -1hour +'%Y-%m-%d %H')" test.logs | grep 'exception'| mail -s "exceptions in last hour of test.logs" ImranRazaKhan </code></pre> <p>The first step above is to select all log entries from the last hour. This is done with <code>grep</code> by...
<p>With GNU <code>date</code>, one can use:</p> <pre><code> grep "^$(date -d -1hour +'%Y-%m-%d %H')" test.logs | grep 'exception'| mail -s "exceptions in last hour of test.logs" ImranRazaKhan </code></pre> <p>The first step above is to select all log entries from the last hour. This is done with <code>grep</code> by...
390, 1271, 1357, 2635, 7896
grep, parsing, shell, solaris, tail
<h1>Shell Script to get exception from logs for last one hour</h1> <p>I am developing script which will grep logs of last one hour and check any exception and send email for solaris platform.</p> <p>I did following steps</p> <pre><code>grep -n -h date +'%Y-%m-%d %H:%M' test.logs </code></pre> <p>above command gives ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,019
bash
# Shell Script to get exception from logs for last one hour I am developing script which will grep logs of last one hour and check any exception and send email for solaris platform. I did following steps ``` grep -n -h date +'%Y-%m-%d %H:%M' test.logs ``` above command gives me line number and then i do following ...
With GNU `date`, one can use: ``` grep "^$(date -d -1hour +'%Y-%m-%d %H')" test.logs | grep 'exception'| mail -s "exceptions in last hour of test.logs" ImranRazaKhan ``` The first step above is to select all log entries from the last hour. This is done with `grep` by looking for all lines beginning with the year-mon...
20657483
Unix equivalent of '@ECHO ON'
7
2013-12-18 11:53:33
<p>Need to confirm if there is a UNIX equivalent command for '<code>@ECHO ON</code>' in DOS. </p> <p>I am required to echo each command and then its O/P. I can do it by adding an echo statement for each command that I execute from my script. But I don't want to do it with a echo statement for each command in my script...
4,170
2,046,462
2013-12-18 12:30:07
20,658,269
12
2013-12-18 12:30:07
2,332,217
2013-12-18 12:30:07
https://stackoverflow.com/q/20657483
https://stackoverflow.com/a/20658269
<p>To turn on tracing</p> <pre><code>set -x </code></pre> <p>To turn off tracing</p> <pre><code>set +x </code></pre>
<p>To turn on tracing</p> <pre><code>set -x </code></pre> <p>To turn off tracing</p> <pre><code>set +x </code></pre>
34, 390
shell, unix
<h1>Unix equivalent of '@ECHO ON'</h1> <p>Need to confirm if there is a UNIX equivalent command for '<code>@ECHO ON</code>' in DOS. </p> <p>I am required to echo each command and then its O/P. I can do it by adding an echo statement for each command that I execute from my script. But I don't want to do it with a echo ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,020
bash
# Unix equivalent of '@ECHO ON' Need to confirm if there is a UNIX equivalent command for '`@ECHO ON`' in DOS. I am required to echo each command and then its O/P. I can do it by adding an echo statement for each command that I execute from my script. But I don't want to do it with a echo statement for each command i...
To turn on tracing ``` set -x ``` To turn off tracing ``` set +x ```
20437067
Testing against -n option in BASH scripts always returns true
7
2013-12-07 03:03:50
<p>I am writing a bash script, in which I am trying to check if there are particular parameters provided. I've noticed a strange (at least for me) behavior of <code>[ -n arg ]</code> test. For the following script:</p> <pre><code>#!/bin/bash if [ -n $1 ]; then echo "The 1st argument is of NON ZERO length" fi if ...
1,241
2,760,967
2016-07-06 10:12:08
20,437,193
12
2013-12-07 03:26:15
900,873
2013-12-07 03:26:15
https://stackoverflow.com/q/20437067
https://stackoverflow.com/a/20437193
<p>Quote it.</p> <pre><code>if [ -n "$1" ]; then </code></pre> <p>Without the quotes, if <code>$1</code> is empty, you execute <code>[ -n ]</code>, which is true*, and if <code>$1</code> is not empty, then it's obviously true.</p> <p>* If you give <code>[</code> a single argument (excluding <code>]</code>), it is a...
<p>Quote it.</p> <pre><code>if [ -n "$1" ]; then </code></pre> <p>Without the quotes, if <code>$1</code> is empty, you execute <code>[ -n ]</code>, which is true*, and if <code>$1</code> is not empty, then it's obviously true.</p> <p>* If you give <code>[</code> a single argument (excluding <code>]</code>), it is a...
387, 390, 10327
bash, sh, shell
<h1>Testing against -n option in BASH scripts always returns true</h1> <p>I am writing a bash script, in which I am trying to check if there are particular parameters provided. I've noticed a strange (at least for me) behavior of <code>[ -n arg ]</code> test. For the following script:</p> <pre><code>#!/bin/bash if [ ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,021
bash
# Testing against -n option in BASH scripts always returns true I am writing a bash script, in which I am trying to check if there are particular parameters provided. I've noticed a strange (at least for me) behavior of `[ -n arg ]` test. For the following script: ``` #!/bin/bash if [ -n $1 ]; then echo "The 1st...
Quote it. ``` if [ -n "$1" ]; then ``` Without the quotes, if `$1` is empty, you execute `[ -n ]`, which is true*, and if `$1` is not empty, then it's obviously true. * If you give `[` a single argument (excluding `]`), it is always true. (Incidentally, this is a pitfall that many new users fall into when they expec...
19683973
Is there a way to force Powershell to open a document as read-only and close without saving?
7
2013-10-30 13:43:49
<p>I have a script that parses data from Word documents. I arrived to the office this morning to realize that the script hadn't completed, hanging on a "File In Use" dialog box. I found a reference to the <code>$true</code> parameter -- open Read-Only -- on <a href="http://msdn.microsoft.com/en-us/library/microsoft.off...
20,070
1,267,125
2018-11-21 10:01:43
19,690,625
12
2013-10-30 18:07:48
2,934,206
2013-10-30 18:07:48
https://stackoverflow.com/q/19683973
https://stackoverflow.com/a/19690625
<p>For read only, try this:</p> <pre><code>$word.Documents.Open("$doc.Fullname", $false, $true) </code></pre> <p>For closing, try this:</p> <pre><code>$word.Documents.Close($false) </code></pre> <p>The MSDN links seem pretty clear about the order these parameters need to appear in and the above worked for me.</p>
<p>For read only, try this:</p> <pre><code>$word.Documents.Open("$doc.Fullname", $false, $true) </code></pre> <p>For closing, try this:</p> <pre><code>$word.Documents.Close($false) </code></pre> <p>The MSDN links seem pretty clear about the order these parameters need to appear in and the above worked for me.</p>
526, 724
file-io, powershell
<h1>Is there a way to force Powershell to open a document as read-only and close without saving?</h1> <p>I have a script that parses data from Word documents. I arrived to the office this morning to realize that the script hadn't completed, hanging on a "File In Use" dialog box. I found a reference to the <code>$true</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,022
bash
# Is there a way to force Powershell to open a document as read-only and close without saving? I have a script that parses data from Word documents. I arrived to the office this morning to realize that the script hadn't completed, hanging on a "File In Use" dialog box. I found a reference to the `$true` parameter -- o...
For read only, try this: ``` $word.Documents.Open("$doc.Fullname", $false, $true) ``` For closing, try this: ``` $word.Documents.Close($false) ``` The MSDN links seem pretty clear about the order these parameters need to appear in and the above worked for me.
16110431
Replace() question mark in image dimensions string from Shell
7
2013-04-19 17:36:46
<p>I'm trying to get the height of a bitmap by using the Shell object in VBA.</p> <p>Here is the relevant portion of code (<code>bmp</code> is a member of a custom class, and <code>.Width</code> is a property defined as an Integer.)</p> <pre><code>Set objImg = objShell.Namespace(subfs(sf)).ParseName(bmp.Name) tmpDim ...
5,107
657,668
2020-02-17 15:13:44
18,216,858
12
2013-08-13 18:48:33
2,250,183
2013-08-13 18:48:33
https://stackoverflow.com/q/16110431
https://stackoverflow.com/a/18216858
<p>The question mark you are seeing is not actually a question mark. The Asc() function will return a value of 63, but AscW() will probably return 8206, the unicode left-to-right mark.</p> <p>I believe VBA stores strings using two-byte wide characters. The Asc function will only return a value of 0-255 and appears to ...
<p>The question mark you are seeing is not actually a question mark. The Asc() function will return a value of 63, but AscW() will probably return 8206, the unicode left-to-right mark.</p> <p>I believe VBA stores strings using two-byte wide characters. The Asc function will only return a value of 0-255 and appears to ...
390, 522, 1449, 34595
excel, shell, vba, windows-7
<h1>Replace() question mark in image dimensions string from Shell</h1> <p>I'm trying to get the height of a bitmap by using the Shell object in VBA.</p> <p>Here is the relevant portion of code (<code>bmp</code> is a member of a custom class, and <code>.Width</code> is a property defined as an Integer.)</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
11,023
bash
# Replace() question mark in image dimensions string from Shell I'm trying to get the height of a bitmap by using the Shell object in VBA. Here is the relevant portion of code (`bmp` is a member of a custom class, and `.Width` is a property defined as an Integer.) ``` Set objImg = objShell.Namespace(subfs(sf)).Parse...
The question mark you are seeing is not actually a question mark. The Asc() function will return a value of 63, but AscW() will probably return 8206, the unicode left-to-right mark. I believe VBA stores strings using two-byte wide characters. The Asc function will only return a value of 0-255 and appears to return 63 ...
18182690
How to start remotely process in PowerShell
7
2013-08-12 08:39:14
<p>I have a problem, I have a <em>script</em> which:</p> <ul> <li>Connect with PSSession (I use <code>PSSession</code> with admin account)</li> <li>Stop 2 process</li> <li>Do change on them files</li> <li>Start the 2 process (Problem here)</li> </ul> <p>I want to start process on server, so i'm connect with PSSession...
31,614
2,558,648
2014-01-27 12:14:03
18,183,375
12
2013-08-12 09:15:35
520,612
2013-08-12 09:15:35
https://stackoverflow.com/q/18182690
https://stackoverflow.com/a/18183375
<p>You can try using WMI:</p> <pre><code>$command = "notepad.exe" $process = [WMICLASS]"\\$CompName\ROOT\CIMV2:win32_process" $result = $process.Create($command) </code></pre> <p>If you need passing credentials:</p> <pre><code>$cred = get-credential $process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __...
<p>You can try using WMI:</p> <pre><code>$command = "notepad.exe" $process = [WMICLASS]"\\$CompName\ROOT\CIMV2:win32_process" $result = $process.Create($command) </code></pre> <p>If you need passing credentials:</p> <pre><code>$cred = get-credential $process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __...
526, 837, 26462, 43391
invoke-command, powershell, remoting, start-process
<h1>How to start remotely process in PowerShell</h1> <p>I have a problem, I have a <em>script</em> which:</p> <ul> <li>Connect with PSSession (I use <code>PSSession</code> with admin account)</li> <li>Stop 2 process</li> <li>Do change on them files</li> <li>Start the 2 process (Problem here)</li> </ul> <p>I want to s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,024
bash
# How to start remotely process in PowerShell I have a problem, I have a *script* which: - Connect with PSSession (I use `PSSession` with admin account) - Stop 2 process - Do change on them files - Start the 2 process (Problem here) I want to start process on server, so i'm connect with PSSession (No problem) I do ...
You can try using WMI: ``` $command = "notepad.exe" $process = [WMICLASS]"\\$CompName\ROOT\CIMV2:win32_process" $result = $process.Create($command) ``` If you need passing credentials: ``` $cred = get-credential $process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __Class = 'Win32_Process'" -namespace "ro...
18115885
getopts not working in bash script
7
2013-08-08 00:11:28
<pre><code>#! bin/bash # code for train.sh while getopts "f:" flag do case $flag in f) echo "Hi" STARTPOINT = $OPTARG ;; esac done echo Test range: $4 echo Train range: $3 #path of experiment folder and data folder: ...
21,632
1,576,804
2013-08-08 05:14:36
18,116,001
12
2013-08-08 00:26:16
1,213,907
2013-08-08 00:32:01
https://stackoverflow.com/q/18115885
https://stackoverflow.com/a/18116001
<p>You need to put any options before naked parameters</p> <pre><code>./train.sh -f testf test1 test2 test3 test4 </code></pre> <p>with output</p> <pre><code>Hi Test range: test4 Train range: test3 Experiment: test1 DataSet: test2 file: testf </code></pre> <p>You need a couple of changes too</p> <pre><code>while ...
<p>You need to put any options before naked parameters</p> <pre><code>./train.sh -f testf test1 test2 test3 test4 </code></pre> <p>with output</p> <pre><code>Hi Test range: test4 Train range: test3 Experiment: test1 DataSet: test2 file: testf </code></pre> <p>You need a couple of changes too</p> <pre><code>while ...
34, 387
bash, unix
<h1>getopts not working in bash script</h1> <pre><code>#! bin/bash # code for train.sh while getopts "f:" flag do case $flag in f) echo "Hi" STARTPOINT = $OPTARG ;; esac done echo Test range: $4 echo Train range: $3 #...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,025
bash
# getopts not working in bash script ``` #! bin/bash # code for train.sh while getopts "f:" flag do case $flag in f) echo "Hi" STARTPOINT = $OPTARG ;; esac done echo Test range: $4 echo Train range: $3 #path of exper...
You need to put any options before naked parameters ``` ./train.sh -f testf test1 test2 test3 test4 ``` with output ``` Hi Test range: test4 Train range: test3 Experiment: test1 DataSet: test2 file: testf ``` You need a couple of changes too ``` while getopts "f:" flag do case $flag in f) ...
17075070
Paste side by side multiple files by numerical order
7
2013-06-12 20:47:54
<p>I have many files in a directory with similar file names like file1, file2, file3, file4, file5, ..... , file1000. They are of the same dimension, and each one of them has 5 columns and 2000 lines. I want to paste them all together side by side in a numerical order into one large file, so the final large file should...
12,778
1,687,130
2013-06-13 07:04:16
17,075,524
12
2013-06-12 21:17:04
7,552
2013-06-12 21:17:04
https://stackoverflow.com/q/17075070
https://stackoverflow.com/a/17075524
<p>If your current shell is bash: <code>paste -d " " file{1..1000}</code></p>
<p>If your current shell is bash: <code>paste -d " " file{1..1000}</code></p>
390, 10425
paste, shell
<h1>Paste side by side multiple files by numerical order</h1> <p>I have many files in a directory with similar file names like file1, file2, file3, file4, file5, ..... , file1000. They are of the same dimension, and each one of them has 5 columns and 2000 lines. I want to paste them all together side by side in a numer...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,026
bash
# Paste side by side multiple files by numerical order I have many files in a directory with similar file names like file1, file2, file3, file4, file5, ..... , file1000. They are of the same dimension, and each one of them has 5 columns and 2000 lines. I want to paste them all together side by side in a numerical orde...
If your current shell is bash: `paste -d " " file{1..1000}`
16919317
Catch failure in shell script
7
2013-06-04 13:34:03
<p>Pretty new to shell scripting. I am trying to do the following:</p> <pre><code>#!/bin/bash unzip myfile.zip #do stuff if unzip successful </code></pre> <p>I know that I can just chain the commands together in with <code>&amp;&amp;</code> but there is quite a chunk, it would not be terribly maintainable.</p>
12,096
445,126
2019-04-02 14:52:46
16,919,522
12
2013-06-04 13:44:20
null
2013-06-04 13:44:20
https://stackoverflow.com/q/16919317
https://stackoverflow.com/a/16919522
<p>You can use the exit status of the command explicitly in the test:</p> <pre><code>if ! unzip myfile.zip &amp;&gt; /dev/null; then # handle error fi </code></pre>
<p>You can use the exit status of the command explicitly in the test:</p> <pre><code>if ! unzip myfile.zip &amp;&gt; /dev/null; then # handle error fi </code></pre>
34, 387, 390
bash, shell, unix
<h1>Catch failure in shell script</h1> <p>Pretty new to shell scripting. I am trying to do the following:</p> <pre><code>#!/bin/bash unzip myfile.zip #do stuff if unzip successful </code></pre> <p>I know that I can just chain the commands together in with <code>&amp;&amp;</code> but there is quite a chunk, it would...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,027
bash
# Catch failure in shell script Pretty new to shell scripting. I am trying to do the following: ``` #!/bin/bash unzip myfile.zip #do stuff if unzip successful ``` I know that I can just chain the commands together in with `&&` but there is quite a chunk, it would not be terribly maintainable.
You can use the exit status of the command explicitly in the test: ``` if ! unzip myfile.zip &> /dev/null; then # handle error fi ```
16900675
Why does find . -not -name ".*" not exclude hidden files?
7
2013-06-03 15:43:59
<p>I want to ignore all hidden files, but especially .git and .svn ones when searching (and later replacing) files, not I have found that the most basic way to exclude such hidden files described in many online tutorials doesn't work here.</p> <pre><code>find . -not -name ".*" </code></pre> <p>will also print hidden ...
8,460
1,273,684
2013-06-03 17:04:22
16,900,768
12
2013-06-03 15:48:45
318,758
2013-06-03 15:48:45
https://stackoverflow.com/q/16900675
https://stackoverflow.com/a/16900768
<p>The thing is <code>-not -name ".*"</code> does match all files and directories that start with anything but "." - but it doesn't prune them from the search, so you'll get matches from inside hidden directories. To prune paths use <code>-prune</code>, i.e.:</p> <pre><code>find $PWD -name ".*" -prune -o -print </code...
<p>The thing is <code>-not -name ".*"</code> does match all files and directories that start with anything but "." - but it doesn't prune them from the search, so you'll get matches from inside hidden directories. To prune paths use <code>-prune</code>, i.e.:</p> <pre><code>find $PWD -name ".*" -prune -o -print </code...
387, 2498, 10193
bash, find, replace
<h1>Why does find . -not -name ".*" not exclude hidden files?</h1> <p>I want to ignore all hidden files, but especially .git and .svn ones when searching (and later replacing) files, not I have found that the most basic way to exclude such hidden files described in many online tutorials doesn't work here.</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
11,028
bash
# Why does find . -not -name ".*" not exclude hidden files? I want to ignore all hidden files, but especially .git and .svn ones when searching (and later replacing) files, not I have found that the most basic way to exclude such hidden files described in many online tutorials doesn't work here. ``` find . -not -name...
The thing is `-not -name ".*"` does match all files and directories that start with anything but "." - but it doesn't prune them from the search, so you'll get matches from inside hidden directories. To prune paths use `-prune`, i.e.: ``` find $PWD -name ".*" -prune -o -print ``` (I use `$PWD` because otherwise the s...
16803003
In place replace using powershell
7
2013-05-28 23:12:06
<p>I am trying to write an equivalent of </p> <pre><code>find -name "*.xml" | xargs grep -l "Search String" | xargs perl -p -i -e 's/Search String/Replace String/g' </code></pre> <p>in powershell. This is what I came up with.</p> <pre><code>Get-ChildItem 'D:\code\cpp\FileHandlingCpp\input - Copy' -Recurse | ...
5,522
124,797
2013-08-13 20:58:00
16,804,326
12
2013-05-29 01:59:46
251,123
2013-05-29 01:59:46
https://stackoverflow.com/q/16803003
https://stackoverflow.com/a/16804326
<p>Maybe it would help to get back to your original goal of implementing the equivalent of the Unix version. Here is essentially the equivalent PowerShell version.</p> <pre><code>$search = '&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt;' $replace = 'test' $dir = 'D:\code\cpp\FileHandlingCpp\input - Cop...
<p>Maybe it would help to get back to your original goal of implementing the equivalent of the Unix version. Here is essentially the equivalent PowerShell version.</p> <pre><code>$search = '&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt;' $replace = 'test' $dir = 'D:\code\cpp\FileHandlingCpp\input - Cop...
34, 526
powershell, unix
<h1>In place replace using powershell</h1> <p>I am trying to write an equivalent of </p> <pre><code>find -name "*.xml" | xargs grep -l "Search String" | xargs perl -p -i -e 's/Search String/Replace String/g' </code></pre> <p>in powershell. This is what I came up with.</p> <pre><code>Get-ChildItem 'D:\code\cp...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,029
bash
# In place replace using powershell I am trying to write an equivalent of ``` find -name "*.xml" | xargs grep -l "Search String" | xargs perl -p -i -e 's/Search String/Replace String/g' ``` in powershell. This is what I came up with. ``` Get-ChildItem 'D:\code\cpp\FileHandlingCpp\input - Copy' -Recurse | Se...
Maybe it would help to get back to your original goal of implementing the equivalent of the Unix version. Here is essentially the equivalent PowerShell version. ``` $search = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' $replace = 'test' $dir = 'D:\code\cpp\FileHandlingCpp\input - Copy' dir -Path $dir -...
16680134
Convert charset from a entire project to utf-8
7
2013-05-21 21:53:17
<p>Hi i have a project made in windows who uses windows 1252 charset and i need to convert all my .php file to utf-8 charset because my database is all utf-8 encoded. Is there a way to do that using linux commands or a software?</p>
5,084
1,208,060
2018-06-29 10:04:42
16,680,174
12
2013-05-21 21:56:57
135,724
2013-05-21 23:54:01
https://stackoverflow.com/q/16680134
https://stackoverflow.com/a/16680174
<p>In your project's root directory, use <a href="http://man7.org/linux/man-pages/man1/find.1.html" rel="noreferrer">find(1)</a> to list all <code>*.php</code> files and combine that with <a href="http://linux.die.net/man/1/recode" rel="noreferrer">recode(1)</a> to convert those files in place:</p> <pre><code>find . -...
<p>In your project's root directory, use <a href="http://man7.org/linux/man-pages/man1/find.1.html" rel="noreferrer">find(1)</a> to list all <code>*.php</code> files and combine that with <a href="http://linux.die.net/man/1/recode" rel="noreferrer">recode(1)</a> to convert those files in place:</p> <pre><code>find . -...
34, 58, 387, 12658
bash, character-encoding, linux, unix
<h1>Convert charset from a entire project to utf-8</h1> <p>Hi i have a project made in windows who uses windows 1252 charset and i need to convert all my .php file to utf-8 charset because my database is all utf-8 encoded. Is there a way to do that using linux commands or a software?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,030
bash
# Convert charset from a entire project to utf-8 Hi i have a project made in windows who uses windows 1252 charset and i need to convert all my .php file to utf-8 charset because my database is all utf-8 encoded. Is there a way to do that using linux commands or a software?
In your project's root directory, use [find(1)](http://man7.org/linux/man-pages/man1/find.1.html) to list all `*.php` files and combine that with [recode(1)](http://linux.die.net/man/1/recode) to convert those files in place: ``` find . -type f -name '*.php' -exec recode windows1252..utf8 \{} \; ``` As an alternative...
15428414
How to run a .sh file from Java?
7
2013-03-15 09:09:31
<p>I need to run a .sh file from my Java code with out passing any arguments. I already tried doing it with</p> <pre><code>Runtime.getRuntime().exec("src/lexparser.sh"); </code></pre> <p>and</p> <pre><code>ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh"); Process p = pb.start(); </code></pre> <p>Both of t...
49,316
2,111,009
2016-05-19 15:09:40
15,428,431
12
2013-03-15 09:10:57
1,581,576
2013-03-15 09:19:54
https://stackoverflow.com/q/15428414
https://stackoverflow.com/a/15428431
<pre><code>ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh", "myArg1", "myArg2"); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } </code></pre>
<pre><code>ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh", "myArg1", "myArg2"); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } </code></pre>
17, 390
java, shell
<h1>How to run a .sh file from Java?</h1> <p>I need to run a .sh file from my Java code with out passing any arguments. I already tried doing it with</p> <pre><code>Runtime.getRuntime().exec("src/lexparser.sh"); </code></pre> <p>and</p> <pre><code>ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh"); Process p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,031
bash
# How to run a .sh file from Java? I need to run a .sh file from my Java code with out passing any arguments. I already tried doing it with ``` Runtime.getRuntime().exec("src/lexparser.sh"); ``` and ``` ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh"); Process p = pb.start(); ``` Both of the above method...
``` ProcessBuilder pb = new ProcessBuilder("src/lexparser.sh", "myArg1", "myArg2"); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } ```
14196061
different behavior of which command in zsh and bash
7
2013-01-07 12:34:08
<p>By using zsh for some time along with oh-my-zsh framework, I noticed that which command behaves different in zsh, than in bash.</p> <p>What I mean:</p> <pre><code># on zsh ilias@ilias-pc ~ ➜ which ls ls: aliased to ls --color=auto ilias@ilias-pc ~ ➜ which which which: shell built-in command ilias@ilias-pc ~ ➜ b...
4,893
1,069,389
2013-01-07 12:43:40
14,196,219
12
2013-01-07 12:43:40
495,451
2013-01-07 12:43:40
https://stackoverflow.com/q/14196061
https://stackoverflow.com/a/14196219
<pre><code>$ zsh -c 'type which' which is a shell builtin $ bash -c 'type which' which is /usr/bin/which </code></pre> <p>The solution is to not use <code>which(1)</code>, which is a non-standard and not very useful command. The question of what you should use instead isn't the most straightforward due to the alternat...
<pre><code>$ zsh -c 'type which' which is a shell builtin $ bash -c 'type which' which is /usr/bin/which </code></pre> <p>The solution is to not use <code>which(1)</code>, which is a non-standard and not very useful command. The question of what you should use instead isn't the most straightforward due to the alternat...
58, 387, 3791
bash, linux, zsh
<h1>different behavior of which command in zsh and bash</h1> <p>By using zsh for some time along with oh-my-zsh framework, I noticed that which command behaves different in zsh, than in bash.</p> <p>What I mean:</p> <pre><code># on zsh ilias@ilias-pc ~ ➜ which ls ls: aliased to ls --color=auto ilias@ilias-pc ~ ➜ wh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,032
bash
# different behavior of which command in zsh and bash By using zsh for some time along with oh-my-zsh framework, I noticed that which command behaves different in zsh, than in bash. What I mean: ``` # on zsh ilias@ilias-pc ~ ➜ which ls ls: aliased to ls --color=auto ilias@ilias-pc ~ ➜ which which which: shell buil...
``` $ zsh -c 'type which' which is a shell builtin $ bash -c 'type which' which is /usr/bin/which ``` The solution is to not use `which(1)`, which is a non-standard and not very useful command. The question of what you should use instead isn't the most straightforward due to the alternatives being poorly specified and...
14130226
ERROR: Description = Invalid query
7
2013-01-02 22:25:46
<p>Because of a messed up group policy object, multiple computers have TightVNC installed when they shouldn't. The GPO is gone, so just removing the software from there isn't an option that I'm aware of. Therefore, I'm scripting things in order to remove PowerShell from a list of computers.</p> <p>This is my script:</...
18,419
535,892
2016-05-27 04:36:44
14,132,476
12
2013-01-03 03:01:53
153,982
2013-01-03 03:01:53
https://stackoverflow.com/q/14130226
https://stackoverflow.com/a/14132476
<p>You're running afoul of PowerShell's string parsing. Try this instead:</p> <pre><code>wmic /node:$pc product where name=`"TightVNC`" call uninstall </code></pre> <p>Note, for those on PowerShell V3, you can use:</p> <pre><code>wmic /node:$pc --% product where name="TightVNC" call uninstall </code></pre>
<p>You're running afoul of PowerShell's string parsing. Try this instead:</p> <pre><code>wmic /node:$pc product where name=`"TightVNC`" call uninstall </code></pre> <p>Note, for those on PowerShell V3, you can use:</p> <pre><code>wmic /node:$pc --% product where name="TightVNC" call uninstall </code></pre>
526, 24067
powershell, powershell-2.0
<h1>ERROR: Description = Invalid query</h1> <p>Because of a messed up group policy object, multiple computers have TightVNC installed when they shouldn't. The GPO is gone, so just removing the software from there isn't an option that I'm aware of. Therefore, I'm scripting things in order to remove PowerShell from a lis...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,033
bash
# ERROR: Description = Invalid query Because of a messed up group policy object, multiple computers have TightVNC installed when they shouldn't. The GPO is gone, so just removing the software from there isn't an option that I'm aware of. Therefore, I'm scripting things in order to remove PowerShell from a list of comp...
You're running afoul of PowerShell's string parsing. Try this instead: ``` wmic /node:$pc product where name=`"TightVNC`" call uninstall ``` Note, for those on PowerShell V3, you can use: ``` wmic /node:$pc --% product where name="TightVNC" call uninstall ```
13167580
Email with multiple attachments
7
2012-10-31 21:18:07
<p>I am working on a PowerShell script for the help desk to use when migrating userhome folders from a server to a NAS device. The help desk user enters the usernames into the "userhomelist.txt" file.</p> <p>My problem is that I'm not able to get the script to attach all of the log files. Only the last log file is a...
38,422
1,387,745
2012-10-31 22:35:01
13,167,847
12
2012-10-31 21:40:43
520,612
2012-10-31 21:40:43
https://stackoverflow.com/q/13167580
https://stackoverflow.com/a/13167847
<p>I suggest to use <a href="http://technet.microsoft.com/en-us/library/hh849925.aspx" rel="noreferrer"><code>send-mailmessage</code></a> cmdlet if you are in powershell v2 or v3. It has an <code>-attachments</code> parameter that accept array of string ( <code>string[]</code> ).</p> <p>You can change your variable <c...
<p>I suggest to use <a href="http://technet.microsoft.com/en-us/library/hh849925.aspx" rel="noreferrer"><code>send-mailmessage</code></a> cmdlet if you are in powershell v2 or v3. It has an <code>-attachments</code> parameter that accept array of string ( <code>string[]</code> ).</p> <p>You can change your variable <c...
146, 526, 6166, 28647
attachment, email, email-attachments, powershell
<h1>Email with multiple attachments</h1> <p>I am working on a PowerShell script for the help desk to use when migrating userhome folders from a server to a NAS device. The help desk user enters the usernames into the "userhomelist.txt" file.</p> <p>My problem is that I'm not able to get the script to attach all of th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,034
bash
# Email with multiple attachments I am working on a PowerShell script for the help desk to use when migrating userhome folders from a server to a NAS device. The help desk user enters the usernames into the "userhomelist.txt" file. My problem is that I'm not able to get the script to attach all of the log files. Only...
I suggest to use [`send-mailmessage`](http://technet.microsoft.com/en-us/library/hh849925.aspx) cmdlet if you are in powershell v2 or v3. It has an `-attachments` parameter that accept array of string ( `string[]` ). You can change your variable `$file` declaring it as `$file = @()` before the `foreach` user loop. Ins...
12587253
how to modify GOPATH in powershell
7
2012-09-25 16:31:10
<p>I am trying to add my project directory to GOPATH, in linux I can do </p> <p><code>export GOPATH=$HOME/mygo</code> in ~/.bashrc</p> <p>what is the equivalence in powershell</p>
7,299
1,149,981
2012-09-25 17:54:09
12,587,443
12
2012-09-25 16:44:06
6,309
2012-09-25 17:54:09
https://stackoverflow.com/q/12587253
https://stackoverflow.com/a/12587443
<p>This should follow the way you set any Environment variable with Powershell (as described in <a href="http://technet.microsoft.com/en-us/library/ff730964.aspx" rel="noreferrer">this article</a>):</p> <p>If you want it permanent (ie will apply for any future shell):</p> <pre><code>[Environment]::SetEnvironmentVaria...
<p>This should follow the way you set any Environment variable with Powershell (as described in <a href="http://technet.microsoft.com/en-us/library/ff730964.aspx" rel="noreferrer">this article</a>):</p> <p>If you want it permanent (ie will apply for any future shell):</p> <pre><code>[Environment]::SetEnvironmentVaria...
526, 15627
go, powershell
<h1>how to modify GOPATH in powershell</h1> <p>I am trying to add my project directory to GOPATH, in linux I can do </p> <p><code>export GOPATH=$HOME/mygo</code> in ~/.bashrc</p> <p>what is the equivalence in powershell</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,035
bash
# how to modify GOPATH in powershell I am trying to add my project directory to GOPATH, in linux I can do `export GOPATH=$HOME/mygo` in ~/.bashrc what is the equivalence in powershell
This should follow the way you set any Environment variable with Powershell (as described in [this article](http://technet.microsoft.com/en-us/library/ff730964.aspx)): If you want it permanent (ie will apply for any future shell): ``` [Environment]::SetEnvironmentVariable("GOPATH", "C:\Your\Path", "User") ``` > One ...
12075642
How to start process via SSH, so it keeps running?
7
2012-08-22 14:41:50
<p>I have three files: monitor.sh, which starts python scripts:</p> <pre><code>sudo python ./webCheck &amp; sudo python ./apiCheck &amp; </code></pre> <p>and the otherones, webCheck &amp; apiCheck: it is supposed to run in the background, after I close the terminal. It checks my other website's availability, in an en...
9,056
1,328,249
2019-02-22 00:00:44
12,075,799
12
2012-08-22 14:50:09
1,617,188
2019-02-22 00:00:44
https://stackoverflow.com/q/12075642
https://stackoverflow.com/a/12075799
<p>You should be able to use:</p> <p><code>sudo nohup python ./webCheck &amp;</code></p> <p><code>sudo nohup python ./apiCheck &amp;</code></p> <p>I don't think your monitor.sh will need it, since it should take a relatively short time to start the other two. However I'm not positive if the two checks would become ...
<p>You should be able to use:</p> <p><code>sudo nohup python ./webCheck &amp;</code></p> <p><code>sudo nohup python ./apiCheck &amp;</code></p> <p>I don't think your monitor.sh will need it, since it should take a relatively short time to start the other two. However I'm not positive if the two checks would become ...
386, 10327, 12375, 18860
amazon-ec2, bitnami, sh, ssh
<h1>How to start process via SSH, so it keeps running?</h1> <p>I have three files: monitor.sh, which starts python scripts:</p> <pre><code>sudo python ./webCheck &amp; sudo python ./apiCheck &amp; </code></pre> <p>and the otherones, webCheck &amp; apiCheck: it is supposed to run in the background, after I close the t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,036
bash
# How to start process via SSH, so it keeps running? I have three files: monitor.sh, which starts python scripts: ``` sudo python ./webCheck & sudo python ./apiCheck & ``` and the otherones, webCheck & apiCheck: it is supposed to run in the background, after I close the terminal. It checks my other website's availab...
You should be able to use: `sudo nohup python ./webCheck &` `sudo nohup python ./apiCheck &` I don't think your monitor.sh will need it, since it should take a relatively short time to start the other two. However I'm not positive if the two checks would become children of monitor.sh, which may end up being an issue...
11719011
sed - pass match to external command
7
2012-07-30 09:50:14
<p>I have written a little script using sed to transform this:</p> <pre><code>kaefert@Ultrablech ~ $ cat /sys/class/power_supply/BAT0/uevent POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Full POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MIN_DESIGN=7400000 POWER_SUP...
7,507
1,561,397
2015-02-09 13:48:40
11,719,531
12
2012-07-30 10:20:31
164,835
2012-07-30 10:20:31
https://stackoverflow.com/q/11719011
https://stackoverflow.com/a/11719531
<p>if your sed is GNU sed. you can use 'e' to pass matched group to external command/tools within sed command.</p> <p>an example might be helpful to make it clear:</p> <p>say, you have a problem:<br> you have a string <code>"120+20foobar"</code> now you want to get the calculation result of 120+20 part, and replace "...
<p>if your sed is GNU sed. you can use 'e' to pass matched group to external command/tools within sed command.</p> <p>an example might be helpful to make it clear:</p> <p>say, you have a problem:<br> you have a string <code>"120+20foobar"</code> now you want to get the calculation result of 120+20 part, and replace "...
4, 58, 387, 5282
bash, css, linux, sed
<h1>sed - pass match to external command</h1> <p>I have written a little script using sed to transform this:</p> <pre><code>kaefert@Ultrablech ~ $ cat /sys/class/power_supply/BAT0/uevent POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Full POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POW...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,037
bash
# sed - pass match to external command I have written a little script using sed to transform this: ``` kaefert@Ultrablech ~ $ cat /sys/class/power_supply/BAT0/uevent POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Full POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MI...
if your sed is GNU sed. you can use 'e' to pass matched group to external command/tools within sed command. an example might be helpful to make it clear: say, you have a problem: you have a string `"120+20foobar"` now you want to get the calculation result of 120+20 part, and replace "oo" to "xx" in "foobar" part. ...
10844707
Find and replace string in parameter bash
7
2012-06-01 05:07:32
<pre><code>$ ./myscript my.site.com </code></pre> <p>How do I replace all dots in the first parameter? Here's my current try but it's returning a <strong>bad substition</strong> error.</p> <pre><code>#!/bin/bash dbname=${$1//./_} echo $dbname </code></pre>
1,531
1,099,531
2015-06-30 22:55:15
10,844,737
12
2012-06-01 05:11:19
571,189
2012-06-01 05:11:19
https://stackoverflow.com/q/10844707
https://stackoverflow.com/a/10844737
<pre><code>dbname=${1//./_} </code></pre> <p>Remove <code>$</code> before 1 since <code>$1</code> and <code>${1}</code> are the same.</p>
<pre><code>dbname=${1//./_} </code></pre> <p>Remove <code>$</code> before 1 since <code>$1</code> and <code>${1}</code> are the same.</p>
18, 139, 387, 2498
bash, regex, replace, string
<h1>Find and replace string in parameter bash</h1> <pre><code>$ ./myscript my.site.com </code></pre> <p>How do I replace all dots in the first parameter? Here's my current try but it's returning a <strong>bad substition</strong> error.</p> <pre><code>#!/bin/bash dbname=${$1//./_} echo $dbname </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,038
bash
# Find and replace string in parameter bash ``` $ ./myscript my.site.com ``` How do I replace all dots in the first parameter? Here's my current try but it's returning a **bad substition** error. ``` #!/bin/bash dbname=${$1//./_} echo $dbname ```
``` dbname=${1//./_} ``` Remove `$` before 1 since `$1` and `${1}` are the same.
10458743
bash: reading text from a string one character at a time, with whitespace
7
2012-05-05 04:05:24
<p>I'm bored, and decided to write a script for a text-based adventure of mine using bash. Basically, it's supposed to animate a typewriter in certain cases for dramatic storytelling. I can do this manually in a file like so:</p> <pre><code>sleep 0.1 echo -n "h" sleep 0.1 echo -n "e" sleep 0.1 echo -n "l" sleep 0.1...
7,001
1,186,723
2013-01-21 23:06:51
10,458,814
12
2012-05-05 04:21:34
736,937
2012-05-05 04:32:37
https://stackoverflow.com/q/10458743
https://stackoverflow.com/a/10458814
<p>How about </p> <pre><code>#!/bin/bash function typewriter { text="$1" delay="$2" for i in $(seq 0 $(expr length "${text}")) ; do echo -n "${text:$i:1}" sleep ${delay} done } typewriter "Typewriters are cool." .1 echo # &lt;-- Just for a newline </code></pre>
<p>How about </p> <pre><code>#!/bin/bash function typewriter { text="$1" delay="$2" for i in $(seq 0 $(expr length "${text}")) ; do echo -n "${text:$i:1}" sleep ${delay} done } typewriter "Typewriters are cool." .1 echo # &lt;-- Just for a newline </code></pre>
387, 2221, 10256, 26793
bash, char, ifs, sleep
<h1>bash: reading text from a string one character at a time, with whitespace</h1> <p>I'm bored, and decided to write a script for a text-based adventure of mine using bash. Basically, it's supposed to animate a typewriter in certain cases for dramatic storytelling. I can do this manually in a file like so:</p> <pre><...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,039
bash
# bash: reading text from a string one character at a time, with whitespace I'm bored, and decided to write a script for a text-based adventure of mine using bash. Basically, it's supposed to animate a typewriter in certain cases for dramatic storytelling. I can do this manually in a file like so: ``` sleep 0.1 echo...
How about ``` #!/bin/bash function typewriter { text="$1" delay="$2" for i in $(seq 0 $(expr length "${text}")) ; do echo -n "${text:$i:1}" sleep ${delay} done } typewriter "Typewriters are cool." .1 echo # <-- Just for a newline ```
10329804
How do I loop through a CSV file with a batch or PowerShell script?
7
2012-04-26 08:32:40
<p>I have a CSV file with two different columns, one with PC names and one with MAC addresses like this:</p> <pre><code>PCxxxx 00-11-22-33-44-55 ... ... </code></pre> <p>These values should be placed into the following CLI command:</p> <pre><code>wdsutil /Set-Device /Device:PCxxxx /ID:00-11-22-33-44-55 </code></pre>...
21,560
906,738
2017-05-28 22:14:26
10,330,144
12
2012-04-26 08:53:30
73,070
2012-04-26 08:53:30
https://stackoverflow.com/q/10329804
https://stackoverflow.com/a/10330144
<p>In a batch file:</p> <pre><code>for /f "tokens=1,2 delims= " %%a in (foo.csv) do ( wdsutil /Set-Device /Device:%%a /ID:%%b ) </code></pre> <p>Actually, you can do that as a one-liner from <code>cmd</code> directly:</p> <pre><code>for /f "tokens=1,2 delims= " %a in (foo.csv) do wdsutil /Set-Device /Device:%a /...
<p>In a batch file:</p> <pre><code>for /f "tokens=1,2 delims= " %%a in (foo.csv) do ( wdsutil /Set-Device /Device:%%a /ID:%%b ) </code></pre> <p>Actually, you can do that as a one-liner from <code>cmd</code> directly:</p> <pre><code>for /f "tokens=1,2 delims= " %a in (foo.csv) do wdsutil /Set-Device /Device:%a /...
526, 2631, 7002
batch-file, cmd, powershell
<h1>How do I loop through a CSV file with a batch or PowerShell script?</h1> <p>I have a CSV file with two different columns, one with PC names and one with MAC addresses like this:</p> <pre><code>PCxxxx 00-11-22-33-44-55 ... ... </code></pre> <p>These values should be placed into the following CLI command:</p> <pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,040
bash
# How do I loop through a CSV file with a batch or PowerShell script? I have a CSV file with two different columns, one with PC names and one with MAC addresses like this: ``` PCxxxx 00-11-22-33-44-55 ... ... ``` These values should be placed into the following CLI command: ``` wdsutil /Set-Device /Device:PCxxxx /I...
In a batch file: ``` for /f "tokens=1,2 delims= " %%a in (foo.csv) do ( wdsutil /Set-Device /Device:%%a /ID:%%b ) ``` Actually, you can do that as a one-liner from `cmd` directly: ``` for /f "tokens=1,2 delims= " %a in (foo.csv) do wdsutil /Set-Device /Device:%a /ID:%b ``` In PowerShell you can use a similar id...
10076159
Python: switching from optparse to argparse
7
2012-04-09 16:16:20
<p>After switching from optparse to argparse - I'm experiencing strange errors. Argparse parse args only if leave no space:</p> <pre><code>myScript.py -oOpt </code></pre> <p>or put an equal sign:</p> <pre><code>myScript.py -o=Opt </code></pre> <p>and it doesn't work the normal way:</p> <pre><code>myScript.py -o Op...
5,114
788,700
2012-04-13 10:34:03
10,108,121
12
2012-04-11 14:36:05
410,889
2012-04-11 16:33:36
https://stackoverflow.com/q/10076159
https://stackoverflow.com/a/10108121
<p>First, it is necessary to make a small distinction. The <code>argparse</code> module does not parse your command-line arguments, the shell does. The shell is responsible for transforming the line you type in the shell into tokens, which are then passed to <code>sys.argv</code>, a python array/sequence of command-lin...
<p>First, it is necessary to make a small distinction. The <code>argparse</code> module does not parse your command-line arguments, the shell does. The shell is responsible for transforming the line you type in the shell into tokens, which are then passed to <code>sys.argv</code>, a python array/sequence of command-lin...
16, 390, 17418, 31134, 59189
argparse, command-line-arguments, optparse, python, shell
<h1>Python: switching from optparse to argparse</h1> <p>After switching from optparse to argparse - I'm experiencing strange errors. Argparse parse args only if leave no space:</p> <pre><code>myScript.py -oOpt </code></pre> <p>or put an equal sign:</p> <pre><code>myScript.py -o=Opt </code></pre> <p>and it doesn't w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,041
bash
# Python: switching from optparse to argparse After switching from optparse to argparse - I'm experiencing strange errors. Argparse parse args only if leave no space: ``` myScript.py -oOpt ``` or put an equal sign: ``` myScript.py -o=Opt ``` and it doesn't work the normal way: ``` myScript.py -o Opt ``` Here's m...
First, it is necessary to make a small distinction. The `argparse` module does not parse your command-line arguments, the shell does. The shell is responsible for transforming the line you type in the shell into tokens, which are then passed to `sys.argv`, a python array/sequence of command-line arguments. The `argpars...
10096785
Set Property in PowerShell Module
7
2012-04-10 21:34:41
<p>I have a PowerShell module called Test.psm1. I want to set a value on a variable and have that accessible when I call another method in that module.</p> <pre><code>#Test.psm1 $property = 'Default Value' function Set-Property([string]$Value) { $property = $Value } function Get-Property { Write-Host $prop...
4,908
46,420
2013-11-19 18:42:44
10,097,277
12
2012-04-10 22:18:23
284,111
2012-04-10 22:18:23
https://stackoverflow.com/q/10096785
https://stackoverflow.com/a/10097277
<p>Jamey is correct. In your example, in the first line, <code>$property = 'Default Value'</code> denotes a file-scoped variable. In <code>Set-Property</code> function, when you assign, you assign to localy scoped variable that is not visible outside the function. Finally, in <code>Get-Property</code>, since there is n...
<p>Jamey is correct. In your example, in the first line, <code>$property = 'Default Value'</code> denotes a file-scoped variable. In <code>Set-Property</code> function, when you assign, you assign to localy scoped variable that is not visible outside the function. Finally, in <code>Get-Property</code>, since there is n...
526, 24067
powershell, powershell-2.0
<h1>Set Property in PowerShell Module</h1> <p>I have a PowerShell module called Test.psm1. I want to set a value on a variable and have that accessible when I call another method in that module.</p> <pre><code>#Test.psm1 $property = 'Default Value' function Set-Property([string]$Value) { $property = $Value } fu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,042
bash
# Set Property in PowerShell Module I have a PowerShell module called Test.psm1. I want to set a value on a variable and have that accessible when I call another method in that module. ``` #Test.psm1 $property = 'Default Value' function Set-Property([string]$Value) { $property = $Value } function Get-Property ...
Jamey is correct. In your example, in the first line, `$property = 'Default Value'` denotes a file-scoped variable. In `Set-Property` function, when you assign, you assign to localy scoped variable that is not visible outside the function. Finally, in `Get-Property`, since there is no locally scoped variable with the s...
9216553
try-catch-fail with powershell and schtasks
7
2012-02-09 18:26:30
<p>I'm new to powershell, but I'm trying to output some simple logging in a ps I'm writing to create scheduled tasks. My code is below. It seems that it doesn't throw an exception when you get an error with schtasks. Another SO question mentioned this with fileIO actions and suggested doing "-ea stop" but that doesn...
7,022
null
2012-02-14 16:55:24
9,217,630
12
2012-02-09 19:45:54
1,192,681
2012-02-09 19:54:23
https://stackoverflow.com/q/9216553
https://stackoverflow.com/a/9217630
<p>In order for a Try/Catch to work, PowerShell needs a terminating exception. When running a cmdlet in a Try block you can make that happen by using -erroraction Stop (or use the -ea alias). As you already realize SCHTASKS.EXE can't do this. Without a terminating exception, the code in the Catch block will never run.<...
<p>In order for a Try/Catch to work, PowerShell needs a terminating exception. When running a cmdlet in a Try block you can make that happen by using -erroraction Stop (or use the -ea alias). As you already realize SCHTASKS.EXE can't do this. Without a terminating exception, the code in the Catch block will never run.<...
526, 24067
powershell, powershell-2.0
<h1>try-catch-fail with powershell and schtasks</h1> <p>I'm new to powershell, but I'm trying to output some simple logging in a ps I'm writing to create scheduled tasks. My code is below. It seems that it doesn't throw an exception when you get an error with schtasks. Another SO question mentioned this with fileIO ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,043
bash
# try-catch-fail with powershell and schtasks I'm new to powershell, but I'm trying to output some simple logging in a ps I'm writing to create scheduled tasks. My code is below. It seems that it doesn't throw an exception when you get an error with schtasks. Another SO question mentioned this with fileIO actions and ...
In order for a Try/Catch to work, PowerShell needs a terminating exception. When running a cmdlet in a Try block you can make that happen by using -erroraction Stop (or use the -ea alias). As you already realize SCHTASKS.EXE can't do this. Without a terminating exception, the code in the Catch block will never run. Wh...
8980791
Shell scripting - which word is first alphabetically?
7
2012-01-24 00:54:37
<p>How can you check which words is first alphabetically between two words? For example in the code</p> <pre><code>#!/bin/bash var1="apple" var2="bye" if [ $var1 \&gt; $var2 ] then echo $var1 else echo $var2 fi </code></pre> <p>I want it to print apple, since apple comes before bye alphabetically, but it isnt worki...
6,079
1,161,080
2018-02-08 00:38:56
8,980,915
12
2012-01-24 01:12:22
14,860
2018-02-08 00:38:56
https://stackoverflow.com/q/8980791
https://stackoverflow.com/a/8980915
<p>What you need to do to solve the immediate problem is reverse the sense of your statement, since the "less than" operator is <code>&lt;</code> rather than <code>&gt;</code>.</p> <p>Doing so will get it working correctly:</p> <pre><code>if [ $var1 \&lt; $var2 ] </code></pre> <hr> <p>Alternatively, you can use the...
<p>What you need to do to solve the immediate problem is reverse the sense of your statement, since the "less than" operator is <code>&lt;</code> rather than <code>&gt;</code>.</p> <p>Doing so will get it working correctly:</p> <pre><code>if [ $var1 \&lt; $var2 ] </code></pre> <hr> <p>Alternatively, you can use the...
387, 390, 27797
alphabetical, bash, shell
<h1>Shell scripting - which word is first alphabetically?</h1> <p>How can you check which words is first alphabetically between two words? For example in the code</p> <pre><code>#!/bin/bash var1="apple" var2="bye" if [ $var1 \&gt; $var2 ] then echo $var1 else echo $var2 fi </code></pre> <p>I want it to print apple,...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,044
bash
# Shell scripting - which word is first alphabetically? How can you check which words is first alphabetically between two words? For example in the code ``` #!/bin/bash var1="apple" var2="bye" if [ $var1 \> $var2 ] then echo $var1 else echo $var2 fi ``` I want it to print apple, since apple comes before bye alphab...
What you need to do to solve the immediate problem is reverse the sense of your statement, since the "less than" operator is `<` rather than `>`. Doing so will get it working correctly: ``` if [ $var1 \< $var2 ] ``` --- Alternatively, you can use the `[[` variant which *doesn't* require the escaping: ``` if [[ $va...
8919350
not able to source a property file in shell script
7
2012-01-19 00:04:27
<p>I tried the following two ways to source the property file </p> <pre><code>#!/bin/sh . import.properties echo $USER_ID echo $INPUT_FILE </code></pre> <p>It says :</p> <pre><code>./test.sh[3]: import.properties: not found </code></pre> <p>when tried using <code>source import.properties</code> it gave the message...
8,446
1,112,640
2015-08-24 00:59:06
8,919,451
12
2012-01-19 00:18:14
15,168
2012-01-19 00:18:14
https://stackoverflow.com/q/8919350
https://stackoverflow.com/a/8919451
<p>To be found by the dot <code>.</code> command, the file must be readable (not necessarily executable) and on your PATH (and to be safely usable, it must contain shell script).</p> <p>If the file is in your current directory and <code>.</code> (the directory, not the command) is not on your PATH, you can use:</p> <...
<p>To be found by the dot <code>.</code> command, the file must be readable (not necessarily executable) and on your PATH (and to be safely usable, it must contain shell script).</p> <p>If the file is in your current directory and <code>.</code> (the directory, not the command) is not on your PATH, you can use:</p> <...
34, 390
shell, unix
<h1>not able to source a property file in shell script</h1> <p>I tried the following two ways to source the property file </p> <pre><code>#!/bin/sh . import.properties echo $USER_ID echo $INPUT_FILE </code></pre> <p>It says :</p> <pre><code>./test.sh[3]: import.properties: not found </code></pre> <p>when tried usi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,045
bash
# not able to source a property file in shell script I tried the following two ways to source the property file ``` #!/bin/sh . import.properties echo $USER_ID echo $INPUT_FILE ``` It says : ``` ./test.sh[3]: import.properties: not found ``` when tried using `source import.properties` it gave the message as: ```...
To be found by the dot `.` command, the file must be readable (not necessarily executable) and on your PATH (and to be safely usable, it must contain shell script). If the file is in your current directory and `.` (the directory, not the command) is not on your PATH, you can use: ``` . ./import.properties ``` Otherw...
8157779
Output Cygwin/bash results to text file
7
2011-11-16 19:53:10
<p>I'm writing a script that will run from the Task Scheduler. It's not executing correctly from the Scheduler, but will execute correctly from the command line. (Possibly a permissions issue?) I wanted to redirect the output to a text file, but I'm getting an empty <code>results.txt</code> file when executed from ei...
17,310
263,000
2024-07-24 08:09:24
8,167,099
12
2011-11-17 12:30:21
843,804
2011-11-17 12:30:21
https://stackoverflow.com/q/8157779
https://stackoverflow.com/a/8167099
<p>Maybe your script writes to the standard error (<code>stderr</code>). Try changing</p> <pre><code>C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh &gt; results.txt </code></pre> <p>to</p> <pre><code>C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh &gt; results.txt 2&gt;&amp;1 </code></pre> <p>It's redir...
<p>Maybe your script writes to the standard error (<code>stderr</code>). Try changing</p> <pre><code>C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh &gt; results.txt </code></pre> <p>to</p> <pre><code>C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh &gt; results.txt 2&gt;&amp;1 </code></pre> <p>It's redir...
387, 1731, 5370, 7002
bash, batch-file, cygwin, dos
<h1>Output Cygwin/bash results to text file</h1> <p>I'm writing a script that will run from the Task Scheduler. It's not executing correctly from the Scheduler, but will execute correctly from the command line. (Possibly a permissions issue?) I wanted to redirect the output to a text file, but I'm getting an empty <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,046
bash
# Output Cygwin/bash results to text file I'm writing a script that will run from the Task Scheduler. It's not executing correctly from the Scheduler, but will execute correctly from the command line. (Possibly a permissions issue?) I wanted to redirect the output to a text file, but I'm getting an empty `results.txt`...
Maybe your script writes to the standard error (`stderr`). Try changing ``` C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh > results.txt ``` to ``` C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh > results.txt 2>&1 ``` It's redirects `stderr` too to the file.
8083014
Equivalent of net use (to list computer's connections) in powershell?
7
2011-11-10 16:39:01
<p>According to windows help NET USE, when used without options, lists the computer's connections. </p> <p>I'd like to find a way in powershell to get a list of the Remote entries in net use's output.</p> <p>I know that as an extreme measure I can parse the result of the "net use" command itself, but I'd rather not ...
12,050
117,126
2011-11-10 20:41:24
8,083,641
12
2011-11-10 17:21:56
608,772
2011-11-10 20:41:24
https://stackoverflow.com/q/8083014
https://stackoverflow.com/a/8083641
<p>For the mapped logical drive you can use WMI class <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394194%28v=vs.85%29.aspx" rel="noreferrer">Win32_MappedLogicalDisk</a> :</p> <pre><code>Get-WmiObject Win32_MappedLogicalDisk </code></pre> <p>Here is another way with <a href="http://msdn.microsof...
<p>For the mapped logical drive you can use WMI class <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394194%28v=vs.85%29.aspx" rel="noreferrer">Win32_MappedLogicalDisk</a> :</p> <pre><code>Get-WmiObject Win32_MappedLogicalDisk </code></pre> <p>Here is another way with <a href="http://msdn.microsof...
64, 526, 28183
net-use, powershell, windows
<h1>Equivalent of net use (to list computer's connections) in powershell?</h1> <p>According to windows help NET USE, when used without options, lists the computer's connections. </p> <p>I'd like to find a way in powershell to get a list of the Remote entries in net use's output.</p> <p>I know that as an extreme meas...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,047
bash
# Equivalent of net use (to list computer's connections) in powershell? According to windows help NET USE, when used without options, lists the computer's connections. I'd like to find a way in powershell to get a list of the Remote entries in net use's output. I know that as an extreme measure I can parse the resul...
For the mapped logical drive you can use WMI class [Win32_MappedLogicalDisk](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394194%28v=vs.85%29.aspx) : ``` Get-WmiObject Win32_MappedLogicalDisk ``` Here is another way with [Win32_LogicalDisk](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394173...
8059196
What does ${VARIABLE+set} mean?
7
2011-11-09 01:03:14
<p>I'm looking through someone else's code and am not sure what this means. It is either a variable call <code>VARIABLE+set</code> which is a strange variable name since is has a <code>+</code>, or is is evaluated and is hard to Google because it has ${} in it ;)</p>
1,800
616,644
2011-11-09 01:03:43
8,059,201
12
2011-11-09 01:03:43
616,644
2011-11-09 01:03:43
https://stackoverflow.com/q/8059196
https://stackoverflow.com/a/8059201
<p>It took be some time, but I found a <a href="http://tldp.org/LDP/abs/html/parameter-substitution.html" rel="noreferrer">link</a> explaining what this does. It is a form of bash parameter-substitution that will evaluate to <code>"set"</code> if <code>$VARIABLE</code> has been set and null otherwise. This allows you...
<p>It took be some time, but I found a <a href="http://tldp.org/LDP/abs/html/parameter-substitution.html" rel="noreferrer">link</a> explaining what this does. It is a form of bash parameter-substitution that will evaluate to <code>"set"</code> if <code>$VARIABLE</code> has been set and null otherwise. This allows you...
387
bash
<h1>What does ${VARIABLE+set} mean?</h1> <p>I'm looking through someone else's code and am not sure what this means. It is either a variable call <code>VARIABLE+set</code> which is a strange variable name since is has a <code>+</code>, or is is evaluated and is hard to Google because it has ${} in it ;)</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,048
bash
# What does ${VARIABLE+set} mean? I'm looking through someone else's code and am not sure what this means. It is either a variable call `VARIABLE+set` which is a strange variable name since is has a `+`, or is is evaluated and is hard to Google because it has ${} in it ;)
It took be some time, but I found a [link](http://tldp.org/LDP/abs/html/parameter-substitution.html) explaining what this does. It is a form of bash parameter-substitution that will evaluate to `"set"` if `$VARIABLE` has been set and null otherwise. This allows you to check if a variable is set by doing the following: ...
7879493
How to prevent Bash's while loop from trimming whitespace?
7
2011-10-24 17:36:47
<p>I need to pipe data into a while loop in a bash script, but it keeps trimming the whitespace. For example:</p> <pre><code>echo " test" | while read i; do echo "$i"; done </code></pre> <p>How can I prevent it from doing this?</p> <p>Thanks!</p>
1,277
1,011,363
2011-10-24 17:39:56
7,879,523
12
2011-10-24 17:39:56
430,749
2011-10-24 17:39:56
https://stackoverflow.com/q/7879493
https://stackoverflow.com/a/7879523
<pre><code>echo " test" | while IFS= read i; do echo "$i"; done </code></pre>
<pre><code>echo " test" | while IFS= read i; do echo "$i"; done </code></pre>
387
bash
<h1>How to prevent Bash's while loop from trimming whitespace?</h1> <p>I need to pipe data into a while loop in a bash script, but it keeps trimming the whitespace. For example:</p> <pre><code>echo " test" | while read i; do echo "$i"; done </code></pre> <p>How can I prevent it from doing this?</p> <p>Thanks!</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,049
bash
# How to prevent Bash's while loop from trimming whitespace? I need to pipe data into a while loop in a bash script, but it keeps trimming the whitespace. For example: ``` echo " test" | while read i; do echo "$i"; done ``` How can I prevent it from doing this? Thanks!
``` echo " test" | while IFS= read i; do echo "$i"; done ```
7128392
Making the title of a directory the date in bash?
7
2011-08-19 23:24:51
<p>I want to make the current date into the title of a directory in <code>/home/chris/Downloads</code> by using <code>mkdir</code> and <code>date -I</code></p> <p>I tried mkdir "date -I" that gets me a folder <i>named</i> "date -I" Without the quotes it gives the error</p> <pre><code>mkdir: invalid option -- 'I' ...
11,410
793,666
2014-01-12 02:27:15
7,128,418
12
2011-08-19 23:28:30
816,210
2011-08-19 23:28:30
https://stackoverflow.com/q/7128392
https://stackoverflow.com/a/7128418
<p>Your syntax is wrong:</p> <pre><code>mkdir -p /home/chris/downloads/$(date -I) </code></pre> <p>or</p> <pre><code>mkdir -p /home/chris/downloads/`date -I` </code></pre> <p>will work</p>
<p>Your syntax is wrong:</p> <pre><code>mkdir -p /home/chris/downloads/$(date -I) </code></pre> <p>or</p> <pre><code>mkdir -p /home/chris/downloads/`date -I` </code></pre> <p>will work</p>
58, 387, 390, 67982
bash, linux, shell, ubuntu-11.04
<h1>Making the title of a directory the date in bash?</h1> <p>I want to make the current date into the title of a directory in <code>/home/chris/Downloads</code> by using <code>mkdir</code> and <code>date -I</code></p> <p>I tried mkdir "date -I" that gets me a folder <i>named</i> "date -I" Without the quotes it gi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,050
bash
# Making the title of a directory the date in bash? I want to make the current date into the title of a directory in `/home/chris/Downloads` by using `mkdir` and `date -I` I tried mkdir "date -I" that gets me a folder *named* "date -I" Without the quotes it gives the error ``` mkdir: invalid option -- 'I' ``` Tryin...
Your syntax is wrong: ``` mkdir -p /home/chris/downloads/$(date -I) ``` or ``` mkdir -p /home/chris/downloads/`date -I` ``` will work
6573308
Removing all ACL on folder with powershell
7
2011-07-04 15:17:55
<p>I'm pretty new to powershell scripting (nearly 1 month since I started learning powershell.)</p> <p>I'm currently working on a script with powershell 2.0 to clean folder NTFS ACL. I want to delete every acl except the administrator one.</p> <p>My problem is that I can't find a way to delete every acl that are not ...
55,585
791,066
2017-12-14 07:18:41
6,579,461
12
2011-07-05 07:53:06
791,066
2011-07-05 07:59:46
https://stackoverflow.com/q/6573308
https://stackoverflow.com/a/6579461
<p>This code remove acl :</p> <pre><code>$acl = Get-Acl \\remote_server\share_folder\HAL.9000 $acl.Access | %{$acl.RemoveAccessRule($_)} </code></pre> <p>This code add administrator acl :</p> <pre><code>#BUILTIN administrator $acl = Get-Acl \\remote_server\share_folder\HAL.9000 $permission = "BUILTIN\Administrator...
<p>This code remove acl :</p> <pre><code>$acl = Get-Acl \\remote_server\share_folder\HAL.9000 $acl.Access | %{$acl.RemoveAccessRule($_)} </code></pre> <p>This code add administrator acl :</p> <pre><code>#BUILTIN administrator $acl = Get-Acl \\remote_server\share_folder\HAL.9000 $permission = "BUILTIN\Administrator...
64, 526, 1576, 3176, 36466
acl, ntfs, powershell, windows, windows-server-2008-r2
<h1>Removing all ACL on folder with powershell</h1> <p>I'm pretty new to powershell scripting (nearly 1 month since I started learning powershell.)</p> <p>I'm currently working on a script with powershell 2.0 to clean folder NTFS ACL. I want to delete every acl except the administrator one.</p> <p>My problem is that ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,051
bash
# Removing all ACL on folder with powershell I'm pretty new to powershell scripting (nearly 1 month since I started learning powershell.) I'm currently working on a script with powershell 2.0 to clean folder NTFS ACL. I want to delete every acl except the administrator one. My problem is that I can't find a way to d...
This code remove acl : ``` $acl = Get-Acl \\remote_server\share_folder\HAL.9000 $acl.Access | %{$acl.RemoveAccessRule($_)} ``` This code add administrator acl : ``` #BUILTIN administrator $acl = Get-Acl \\remote_server\share_folder\HAL.9000 $permission = "BUILTIN\Administrators","FullControl", "ContainerInherit,Ob...
6519224
bash: Variable name directly followed by other parameters?
7
2011-06-29 10:32:27
<p>My bash scripts has a variable <code>$c</code> which is called within a <code>sed</code>-line, <em>directly followed by another parameter</em> - and bash (actually fairly logical) seems to think that the <em>other parameter</em> belong to the variable name, rendering it useless/empty.</p> <pre><code>(...) c=$(print...
2,960
758,979
2011-06-30 07:20:56
6,519,268
12
2011-06-29 10:35:23
14,860
2011-06-30 07:20:56
https://stackoverflow.com/q/6519224
https://stackoverflow.com/a/6519268
<p>You need to use <code>${c}q</code> to prevent the greedy treatment (<code>bash</code> trying to use as many valid characters as possible):</p> <pre><code>pax$ export cq=111 pax$ export c=222 pax$ echo $cq 111 pax$ echo ${c}q 222q </code></pre> <hr> <p>I should also mention that, if performance is important to ...
<p>You need to use <code>${c}q</code> to prevent the greedy treatment (<code>bash</code> trying to use as many valid characters as possible):</p> <pre><code>pax$ export cq=111 pax$ export c=222 pax$ echo $cq 111 pax$ echo ${c}q 222q </code></pre> <hr> <p>I should also mention that, if performance is important to ...
276, 387
bash, variables
<h1>bash: Variable name directly followed by other parameters?</h1> <p>My bash scripts has a variable <code>$c</code> which is called within a <code>sed</code>-line, <em>directly followed by another parameter</em> - and bash (actually fairly logical) seems to think that the <em>other parameter</em> belong to the variab...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,052
bash
# bash: Variable name directly followed by other parameters? My bash scripts has a variable `$c` which is called within a `sed`-line, *directly followed by another parameter* - and bash (actually fairly logical) seems to think that the *other parameter* belong to the variable name, rendering it useless/empty. ``` (.....
You need to use `${c}q` to prevent the greedy treatment (`bash` trying to use as many valid characters as possible): ``` pax$ export cq=111 pax$ export c=222 pax$ echo $cq 111 pax$ echo ${c}q 222q ``` --- I should also mention that, if performance is important to you, you want to try and minimise how many externa...
6087421
ant Permission Denied problem
7
2011-05-22 10:46:42
<p>After extracting and saving the ant files into an opt/ directory and setting the path variable to <code>$ANT_HOME/bin</code></p> <p>I ran the following command on a CentOS 5</p> <pre><code>ant -version </code></pre> <p>and I am getting the following error</p> <pre><code>-bash:/path/opt/apache-ant-1.8.2/bin/ant: ...
16,871
648,927
2011-05-22 10:48:36
6,087,427
12
2011-05-22 10:48:36
217,588
2011-05-22 10:48:36
https://stackoverflow.com/q/6087421
https://stackoverflow.com/a/6087427
<p>If you own the file, try</p> <pre><code>chmod u+x /path/opt/apache-ant-1.8.2/bin/ant </code></pre> <p>If someone else owns it, either <code>sudo</code> or become root then</p> <pre><code>chmod 755 /path/opt/apache-ant-1.8.2/bin/ant </code></pre> <p>You need to have execute permissions on the file; the first give...
<p>If you own the file, try</p> <pre><code>chmod u+x /path/opt/apache-ant-1.8.2/bin/ant </code></pre> <p>If someone else owns it, either <code>sudo</code> or become root then</p> <pre><code>chmod 755 /path/opt/apache-ant-1.8.2/bin/ant </code></pre> <p>You need to have execute permissions on the file; the first give...
34, 58, 142, 390, 4956
ant, centos, linux, shell, unix
<h1>ant Permission Denied problem</h1> <p>After extracting and saving the ant files into an opt/ directory and setting the path variable to <code>$ANT_HOME/bin</code></p> <p>I ran the following command on a CentOS 5</p> <pre><code>ant -version </code></pre> <p>and I am getting the following error</p> <pre><code>-ba...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,053
bash
# ant Permission Denied problem After extracting and saving the ant files into an opt/ directory and setting the path variable to `$ANT_HOME/bin` I ran the following command on a CentOS 5 ``` ant -version ``` and I am getting the following error ``` -bash:/path/opt/apache-ant-1.8.2/bin/ant: Permission denied ``` ...
If you own the file, try ``` chmod u+x /path/opt/apache-ant-1.8.2/bin/ant ``` If someone else owns it, either `sudo` or become root then ``` chmod 755 /path/opt/apache-ant-1.8.2/bin/ant ``` You need to have execute permissions on the file; the first gives execute permissions to the owner only and is probably prefer...
5992638
Shell script random number generating
7
2011-05-13 13:31:33
<p><code>var=$RANDOM</code> creates random numbers but how can i specify a range like between 0 and 12 for instance?</p>
17,026
663,229
2014-10-14 05:17:32
5,992,686
12
2011-05-13 13:34:44
430,766
2011-05-13 14:33:44
https://stackoverflow.com/q/5992638
https://stackoverflow.com/a/5992686
<p>If you already have your random number, you can say</p> <pre><code>var=$RANDOM var=$[ $var % 13 ] </code></pre> <p>to get numbers from <code>0..12</code>.</p> <p><strong>Edit:</strong> If you want to produce numbers from <code>$x</code> to <code>$y</code>, you can easily modify this:</p> <pre><code>var=$[ $x + $...
<p>If you already have your random number, you can say</p> <pre><code>var=$RANDOM var=$[ $var % 13 ] </code></pre> <p>to get numbers from <code>0..12</code>.</p> <p><strong>Edit:</strong> If you want to produce numbers from <code>$x</code> to <code>$y</code>, you can easily modify this:</p> <pre><code>var=$[ $x + $...
197, 276, 387, 390
bash, random, shell, variables
<h1>Shell script random number generating</h1> <p><code>var=$RANDOM</code> creates random numbers but how can i specify a range like between 0 and 12 for instance?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,054
bash
# Shell script random number generating `var=$RANDOM` creates random numbers but how can i specify a range like between 0 and 12 for instance?
If you already have your random number, you can say ``` var=$RANDOM var=$[ $var % 13 ] ``` to get numbers from `0..12`. **Edit:** If you want to produce numbers from `$x` to `$y`, you can easily modify this: ``` var=$[ $x + $var % ($y + 1 - $x) ] ```
5987448
Use of the 'hash' command
7
2011-05-13 05:05:14
<p>I'm working on a small app based on ffmpeg, and I read a <a href="http://ubuntuforums.org/archive/index.php/t-1438052.html" rel="nofollow noreferrer">tutorial made for ubuntu</a> where they advise to use the command <code>hash</code> on the produced executable.</p> <p>I'm curious about that command, did you ever us...
17,737
237,447
2019-03-25 15:20:28
5,987,499
12
2011-05-13 05:13:54
377,270
2019-03-25 15:20:28
https://stackoverflow.com/q/5987448
https://stackoverflow.com/a/5987499
<p><code>hash</code> isn't actually your history; it is a <code>bash(1)</code> shell built-in that maintains a hash table of recently executed programs:</p> <blockquote> <p>Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the d...
<p><code>hash</code> isn't actually your history; it is a <code>bash(1)</code> shell built-in that maintains a hash table of recently executed programs:</p> <blockquote> <p>Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the d...
387, 581, 3847
bash, ffmpeg, hash
<h1>Use of the 'hash' command</h1> <p>I'm working on a small app based on ffmpeg, and I read a <a href="http://ubuntuforums.org/archive/index.php/t-1438052.html" rel="nofollow noreferrer">tutorial made for ubuntu</a> where they advise to use the command <code>hash</code> on the produced executable.</p> <p>I'm curious ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,055
bash
# Use of the 'hash' command I'm working on a small app based on ffmpeg, and I read a [tutorial made for ubuntu](http://ubuntuforums.org/archive/index.php/t-1438052.html) where they advise to use the command `hash` on the produced executable. I'm curious about that command, did you ever use it? For which purpose? Whe...
`hash` isn't actually your history; it is a `bash(1)` shell built-in that maintains a hash table of recently executed programs: > Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the directories in PATH is performed only if the co...
5933719
Parsing an XML file with PowerShell
7
2011-05-09 07:13:39
<p>One of my application is generating below XML file.</p> <pre><code>&lt;root&gt; &lt;command name="Set"&gt; &lt;property name="PWR.WakeupOnLAN" value="6" errorcode="0x0"/&gt; &lt;/command&gt; &lt;command name="Set"&gt; &lt;/command&gt; &lt;command name="biossettings"&gt; &lt;prope...
1,997
209,355
2013-05-24 08:18:08
5,933,939
12
2011-05-09 07:38:24
26,396
2011-05-09 07:43:56
https://stackoverflow.com/q/5933719
https://stackoverflow.com/a/5933939
<p>In PowerShell 2.0 you can solve this using the new <a href="http://technet.microsoft.com/en-us/library/dd347617.aspx" rel="nofollow">Select-Xml</a> cmdlet and an <a href="http://www.w3.org/TR/xpath/" rel="nofollow">XPath</a> expression:</p> <pre><code>[xml]$document = "&lt;root&gt;&lt;command name='Set'&gt;&lt;prop...
<p>In PowerShell 2.0 you can solve this using the new <a href="http://technet.microsoft.com/en-us/library/dd347617.aspx" rel="nofollow">Select-Xml</a> cmdlet and an <a href="http://www.w3.org/TR/xpath/" rel="nofollow">XPath</a> expression:</p> <pre><code>[xml]$document = "&lt;root&gt;&lt;command name='Set'&gt;&lt;prop...
1, 526, 24067
.net, powershell, powershell-2.0
<h1>Parsing an XML file with PowerShell</h1> <p>One of my application is generating below XML file.</p> <pre><code>&lt;root&gt; &lt;command name="Set"&gt; &lt;property name="PWR.WakeupOnLAN" value="6" errorcode="0x0"/&gt; &lt;/command&gt; &lt;command name="Set"&gt; &lt;/command&gt; &lt;comm...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,056
bash
# Parsing an XML file with PowerShell One of my application is generating below XML file. ``` <root> <command name="Set"> <property name="PWR.WakeupOnLAN" value="6" errorcode="0x0"/> </command> <command name="Set"> </command> <command name="biossettings"> <property name="task" valu...
In PowerShell 2.0 you can solve this using the new [Select-Xml](http://technet.microsoft.com/en-us/library/dd347617.aspx) cmdlet and an [XPath](http://www.w3.org/TR/xpath/) expression: ``` [xml]$document = "<root><command name='Set'><property name='PWR.WakeupOnLAN' value='6' errorcode='0x0'/></command><command name='S...
4921132
How to exit out of password mode?
7
2011-02-07 12:12:13
<p>If I Ctrl+C on a password prompt in shell (for eg during an scp or ssh), the shell is forever gone into the hidden characters (password) mode. There appears to be no way for me to start echoing the keystrokes to the display again and I have to logoff and log back in. Is there a simple way to force shell out of the p...
17,121
471,371
2011-02-07 12:16:31
4,921,166
12
2011-02-07 12:16:11
613,064
2011-02-07 12:16:11
https://stackoverflow.com/q/4921132
https://stackoverflow.com/a/4921166
<p>Whenever there is something wrong with the terminal, usually one of <code>reset</code> or <code>stty sane</code> will get it back to a usable state. Which it is depends on the problem at hand.</p>
<p>Whenever there is something wrong with the terminal, usually one of <code>reset</code> or <code>stty sane</code> will get it back to a usable state. Which it is depends on the problem at hand.</p>
34, 58, 387
bash, linux, unix
<h1>How to exit out of password mode?</h1> <p>If I Ctrl+C on a password prompt in shell (for eg during an scp or ssh), the shell is forever gone into the hidden characters (password) mode. There appears to be no way for me to start echoing the keystrokes to the display again and I have to logoff and log back in. Is the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,057
bash
# How to exit out of password mode? If I Ctrl+C on a password prompt in shell (for eg during an scp or ssh), the shell is forever gone into the hidden characters (password) mode. There appears to be no way for me to start echoing the keystrokes to the display again and I have to logoff and log back in. Is there a simp...
Whenever there is something wrong with the terminal, usually one of `reset` or `stty sane` will get it back to a usable state. Which it is depends on the problem at hand.
4905593
cannot type 'e' or 'P' in MinGW/msys shells or terminals
7
2011-02-05 07:02:00
<p>I have successfully installed and used MinGW and msys in the past to compile and link Windows executables. On a fresh installation for 32-bit Vista (the same platform as when I had previous success) I am getting some maddening behavior: when I type lower-case 'e' or upper-case 'P' in the provided shell environments...
2,187
65,781
2011-06-02 09:34:22
4,905,835
12
2011-02-05 08:15:18
26,428
2011-02-05 08:15:18
https://stackoverflow.com/q/4905593
https://stackoverflow.com/a/4905835
<p>I'm assuming you're using Bash. It sounds to me like the key bindings have gotten messed up for some reason.</p> <p>If you do this command:</p> <pre><code>bind -p|grep -i '"[pE]"' </code></pre> <p>you should get this result:</p> <pre><code>"E": self-insert "e": self-insert "P": self-insert "p": self-insert </cod...
<p>I'm assuming you're using Bash. It sounds to me like the key bindings have gotten messed up for some reason.</p> <p>If you do this command:</p> <pre><code>bind -p|grep -i '"[pE]"' </code></pre> <p>you should get this result:</p> <pre><code>"E": self-insert "e": self-insert "P": self-insert "p": self-insert </cod...
390, 391, 4086, 13232
mingw, msys, shell, terminal
<h1>cannot type 'e' or 'P' in MinGW/msys shells or terminals</h1> <p>I have successfully installed and used MinGW and msys in the past to compile and link Windows executables. On a fresh installation for 32-bit Vista (the same platform as when I had previous success) I am getting some maddening behavior: when I type l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,058
bash
# cannot type 'e' or 'P' in MinGW/msys shells or terminals I have successfully installed and used MinGW and msys in the past to compile and link Windows executables. On a fresh installation for 32-bit Vista (the same platform as when I had previous success) I am getting some maddening behavior: when I type lower-case ...
I'm assuming you're using Bash. It sounds to me like the key bindings have gotten messed up for some reason. If you do this command: ``` bind -p|grep -i '"[pE]"' ``` you should get this result: ``` "E": self-insert "e": self-insert "P": self-insert "p": self-insert ``` If the entries for "P" and "e" are missing th...
4904225
need help porting a sed command from debian to OSX
7
2011-02-05 00:22:15
<p>This is one for you sed gurus out there. I really don't know enough about sed to take this apart completely. It was written on some standard Linux distro and I need it to run on OSX. </p> <pre><code>COMPILE_FILES=$(sed -nr '/&lt;script type="text\/javascript"/ { s%^.*src="\{\$baseUrl\}/([^"]+)".*$%\1%p }' templates...
3,043
215,847
2025-06-24 15:04:24
4,904,510
12
2011-02-05 01:25:54
26,428
2025-06-24 15:04:24
https://stackoverflow.com/q/4904225
https://stackoverflow.com/a/4904510
<p>OS X <code>sed</code> is based on an older POSIX standard which forbade multiple sed-scripts separated by semicolons (instead of separate <code>-e</code> invocations) and requires newlines for sed-commands grouped in curly braces (which aren't necessary in the command you have). Try this:</p> <pre><code>COMPILE_FILE...
<p>OS X <code>sed</code> is based on an older POSIX standard which forbade multiple sed-scripts separated by semicolons (instead of separate <code>-e</code> invocations) and requires newlines for sed-commands grouped in curly braces (which aren't necessary in the command you have). Try this:</p> <pre><code>COMPILE_FILE...
369, 390, 1231, 5282
command-line, macos, sed, shell
<h1>need help porting a sed command from debian to OSX</h1> <p>This is one for you sed gurus out there. I really don't know enough about sed to take this apart completely. It was written on some standard Linux distro and I need it to run on OSX. </p> <pre><code>COMPILE_FILES=$(sed -nr '/&lt;script type="text\/javascri...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,059
bash
# need help porting a sed command from debian to OSX This is one for you sed gurus out there. I really don't know enough about sed to take this apart completely. It was written on some standard Linux distro and I need it to run on OSX. ``` COMPILE_FILES=$(sed -nr '/<script type="text\/javascript"/ { s%^.*src="\{\$bas...
OS X `sed` is based on an older POSIX standard which forbade multiple sed-scripts separated by semicolons (instead of separate `-e` invocations) and requires newlines for sed-commands grouped in curly braces (which aren't necessary in the command you have). Try this: ``` COMPILE_FILES=$(sed -n -E '/<script type="text\...
4741860
Concatenate strings and expression results in PowerShell
7
2011-01-19 23:08:11
<p>I want to write out the current process ID in PowerShell. This works:</p> <pre><code>$processId = $([System.Diagnostics.Process]::GetCurrentProcess()).Id Write-Output "My process ID is $processId" </code></pre> <p>However, I want to do it in one line, if possible. Substituting the <code>$([System.Diagnostics.Proce...
13,821
20,336
2011-01-20 14:44:49
4,743,529
12
2011-01-20 04:47:03
25,216
2011-01-20 06:05:42
https://stackoverflow.com/q/4741860
https://stackoverflow.com/a/4743529
<pre><code>'My process id is {0}' -f [System.Diagnostics.Process]::GetCurrentProcess().Id </code></pre> <p>And if we use automatic variables:</p> <pre><code>'My process id is {0}' -f $pid </code></pre>
<pre><code>'My process id is {0}' -f [System.Diagnostics.Process]::GetCurrentProcess().Id </code></pre> <p>And if we use automatic variables:</p> <pre><code>'My process id is {0}' -f $pid </code></pre>
526, 7792
powershell, string-concatenation
<h1>Concatenate strings and expression results in PowerShell</h1> <p>I want to write out the current process ID in PowerShell. This works:</p> <pre><code>$processId = $([System.Diagnostics.Process]::GetCurrentProcess()).Id Write-Output "My process ID is $processId" </code></pre> <p>However, I want to do it in one lin...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,060
bash
# Concatenate strings and expression results in PowerShell I want to write out the current process ID in PowerShell. This works: ``` $processId = $([System.Diagnostics.Process]::GetCurrentProcess()).Id Write-Output "My process ID is $processId" ``` However, I want to do it in one line, if possible. Substituting the ...
``` 'My process id is {0}' -f [System.Diagnostics.Process]::GetCurrentProcess().Id ``` And if we use automatic variables: ``` 'My process id is {0}' -f $pid ```
4691874
PowerShell 2.0 and how to handle exceptions?
7
2011-01-14 14:06:49
<p>Why I get error message printed on the console when running these two simple samples ? I want that I get "Error testing :)" printed on the console insted of:</p> <blockquote> <p>Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:3 char:15 + Get-WmiObject &lt;&lt...
15,394
423,278
2011-01-14 15:10:29
4,692,273
12
2011-01-14 14:48:38
323,582
2011-01-14 15:10:29
https://stackoverflow.com/q/4691874
https://stackoverflow.com/a/4692273
<p><strong>First example</strong></p> <p>The error happens at compile/parsing time (PowerShell is clever enough), so that the code is not even executed and it cannot catch anything, indeed. Try this code instead and you will catch an exception:</p> <pre><code>try { $x = 0 $i = 1/$x Write-Host $i } catch [...
<p><strong>First example</strong></p> <p>The error happens at compile/parsing time (PowerShell is clever enough), so that the code is not even executed and it cannot catch anything, indeed. Try this code instead and you will catch an exception:</p> <pre><code>try { $x = 0 $i = 1/$x Write-Host $i } catch [...
526, 5142, 24067
exception, powershell, powershell-2.0
<h1>PowerShell 2.0 and how to handle exceptions?</h1> <p>Why I get error message printed on the console when running these two simple samples ? I want that I get "Error testing :)" printed on the console insted of:</p> <blockquote> <p>Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,061
bash
# PowerShell 2.0 and how to handle exceptions? Why I get error message printed on the console when running these two simple samples ? I want that I get "Error testing :)" printed on the console insted of: > Get-WmiObject : The RPC server is > unavailable. (Exception from HRESULT: > 0x800706BA) At line:3 char:15 > + G...
**First example** The error happens at compile/parsing time (PowerShell is clever enough), so that the code is not even executed and it cannot catch anything, indeed. Try this code instead and you will catch an exception: ``` try { $x = 0 $i = 1/$x Write-Host $i } catch [Exception] { Write-Host "Error...
4673830
Random number between range in shell
7
2011-01-12 20:43:55
<p>How I can generate random number between 0-60 in sh (/bin/sh, not bash)? This is a satellite box, there is no <code>$RANDOM</code> variable, and other goods [cksum, od (od -vAn -N4 -tu4 &lt; /dev/urandom)].</p> <p>I want to randomize a crontab job's time.</p>
19,187
573,334
2025-07-11 13:38:58
4,674,128
12
2011-01-12 21:11:45
115,405
2011-01-12 21:11:45
https://stackoverflow.com/q/4673830
https://stackoverflow.com/a/4674128
<p>If you have tr, head and /dev/urandom, you can write this:</p> <pre><code>tr -cd 0-9 &lt;/dev/urandom | head -c 3 </code></pre> <p>Then you have to use the remainder operator to put in 0-60 range.</p>
<p>If you have tr, head and /dev/urandom, you can write this:</p> <pre><code>tr -cd 0-9 &lt;/dev/urandom | head -c 3 </code></pre> <p>Then you have to use the remainder operator to put in 0-60 range.</p>
58, 197, 390
linux, random, shell
<h1>Random number between range in shell</h1> <p>How I can generate random number between 0-60 in sh (/bin/sh, not bash)? This is a satellite box, there is no <code>$RANDOM</code> variable, and other goods [cksum, od (od -vAn -N4 -tu4 &lt; /dev/urandom)].</p> <p>I want to randomize a crontab job's time.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,062
bash
# Random number between range in shell How I can generate random number between 0-60 in sh (/bin/sh, not bash)? This is a satellite box, there is no `$RANDOM` variable, and other goods [cksum, od (od -vAn -N4 -tu4 < /dev/urandom)]. I want to randomize a crontab job's time.
If you have tr, head and /dev/urandom, you can write this: ``` tr -cd 0-9 </dev/urandom | head -c 3 ``` Then you have to use the remainder operator to put in 0-60 range.
3395374
Run/invoke windows batch script from sh or bash script
7
2010-08-03 09:53:49
<p>I have a sh/bash script that needs to call a batch file with parameters (parameters are file names and are given in DOS/Windows format).</p> <p>Basically I have: <strong>script.sh</strong></p> <pre><code>#!/bin/sh declare var1=$1 declare var2=$2 dosomething var1 var2 ... &lt;invoke batch script&gt; var1 var2 ... d...
6,546
23,795
2013-09-23 16:05:29
3,395,576
12
2010-08-03 10:21:04
23,795
2010-08-03 10:21:04
https://stackoverflow.com/q/3395374
https://stackoverflow.com/a/3395576
<p>It seems that I needed to escape the space from the cmd param:</p> <pre><code>$COMSPEC \/c batch-file\ \"$var1\"\ \"$var2\" </code></pre> <p>or</p> <pre><code>$COMSPEC /c batch-file\ \"$var1\"\ \"$var2\" </code></pre> <p>I'm not sure whether the / from /c needs to be escaped, but it works fine both ways escaped....
<p>It seems that I needed to escape the space from the cmd param:</p> <pre><code>$COMSPEC \/c batch-file\ \"$var1\"\ \"$var2\" </code></pre> <p>or</p> <pre><code>$COMSPEC /c batch-file\ \"$var1\"\ \"$var2\" </code></pre> <p>I'm not sure whether the / from /c needs to be escaped, but it works fine both ways escaped....
387, 2631, 7002, 21628
bash, batch-file, cmd, msysgit
<h1>Run/invoke windows batch script from sh or bash script</h1> <p>I have a sh/bash script that needs to call a batch file with parameters (parameters are file names and are given in DOS/Windows format).</p> <p>Basically I have: <strong>script.sh</strong></p> <pre><code>#!/bin/sh declare var1=$1 declare var2=$2 dosom...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,063
bash
# Run/invoke windows batch script from sh or bash script I have a sh/bash script that needs to call a batch file with parameters (parameters are file names and are given in DOS/Windows format). Basically I have: **script.sh** ``` #!/bin/sh declare var1=$1 declare var2=$2 dosomething var1 var2 ... <invoke batch scrip...
It seems that I needed to escape the space from the cmd param: ``` $COMSPEC \/c batch-file\ \"$var1\"\ \"$var2\" ``` or ``` $COMSPEC /c batch-file\ \"$var1\"\ \"$var2\" ``` I'm not sure whether the / from /c needs to be escaped, but it works fine both ways escaped.
2689537
Use the output of a command as input of the next command
7
2010-04-22 09:19:28
<p>So I call this PHP script from the command line:</p> <pre><code>/usr/bin/php /var/www/bims/index.php "projects/output" </code></pre> <p>and its output is:</p> <pre><code>file1 file2 file3 </code></pre> <p>What I would like to do is get this output and feed to the "rm" command but I think im not doing it right:</...
12,479
258,219
2023-12-14 12:59:51
2,689,573
12
2010-04-22 09:24:22
162,634
2010-04-22 09:24:22
https://stackoverflow.com/q/2689537
https://stackoverflow.com/a/2689573
<pre><code>/usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm </code></pre>
<pre><code>/usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm </code></pre>
58, 387
bash, linux
<h1>Use the output of a command as input of the next command</h1> <p>So I call this PHP script from the command line:</p> <pre><code>/usr/bin/php /var/www/bims/index.php "projects/output" </code></pre> <p>and its output is:</p> <pre><code>file1 file2 file3 </code></pre> <p>What I would like to do is get this output...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,064
bash
# Use the output of a command as input of the next command So I call this PHP script from the command line: ``` /usr/bin/php /var/www/bims/index.php "projects/output" ``` and its output is: ``` file1 file2 file3 ``` What I would like to do is get this output and feed to the "rm" command but I think im not doing it...
``` /usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm ```
2373561
Listing files and directories writable by the group in Linux
7
2010-03-03 17:39:36
<p>What's the easiest way to recursively list files in a given directory and its subdirectories, that are writable by the group which owns them? I'm using Debian 5.</p>
8,647
226,640
2010-03-03 17:51:39
2,373,607
12
2010-03-03 17:45:55
180,736
2010-03-03 17:51:39
https://stackoverflow.com/q/2373561
https://stackoverflow.com/a/2373607
<p>Something like</p> <pre><code>find /dir/ -perm /g=w </code></pre> <p>Or, for output like ls -l</p> <pre><code>find /dir/ -perm /g=w -exec ls -lLd {} + </code></pre>
<p>Something like</p> <pre><code>find /dir/ -perm /g=w </code></pre> <p>Or, for output like ls -l</p> <pre><code>find /dir/ -perm /g=w -exec ls -lLd {} + </code></pre>
58, 387, 1012, 10631
bash, console-application, debian, linux
<h1>Listing files and directories writable by the group in Linux</h1> <p>What's the easiest way to recursively list files in a given directory and its subdirectories, that are writable by the group which owns them? I'm using Debian 5.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,065
bash
# Listing files and directories writable by the group in Linux What's the easiest way to recursively list files in a given directory and its subdirectories, that are writable by the group which owns them? I'm using Debian 5.
Something like ``` find /dir/ -perm /g=w ``` Or, for output like ls -l ``` find /dir/ -perm /g=w -exec ls -lLd {} + ```
2021345
How do I execute (not import) a python script from a python prompt?
7
2010-01-07 15:25:15
<p>I need to execute a Python script from an already started Python session, as if it were launched from the command line. I'm thinking of similar to doing <code>source</code> in bash or sh.</p>
6,788
106,979
2015-09-22 01:52:25
2,021,400
12
2010-01-07 15:32:12
94,977
2015-09-22 01:52:25
https://stackoverflow.com/q/2021345
https://stackoverflow.com/a/2021400
<p>In Python 2, the builtin function <a href="http://docs.python.org/library/functions.html#execfile" rel="nofollow noreferrer"><code>execfile</code></a> does this.</p> <pre><code>execfile(filename) </code></pre>
<p>In Python 2, the builtin function <a href="http://docs.python.org/library/functions.html#execfile" rel="nofollow noreferrer"><code>execfile</code></a> does this.</p> <pre><code>execfile(filename) </code></pre>
16, 387, 432, 3849
bash, import, module, python
<h1>How do I execute (not import) a python script from a python prompt?</h1> <p>I need to execute a Python script from an already started Python session, as if it were launched from the command line. I'm thinking of similar to doing <code>source</code> in bash or sh.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,066
bash
# How do I execute (not import) a python script from a python prompt? I need to execute a Python script from an already started Python session, as if it were launched from the command line. I'm thinking of similar to doing `source` in bash or sh.
In Python 2, the builtin function [`execfile`](http://docs.python.org/library/functions.html#execfile) does this. ``` execfile(filename) ```
1817562
Execute a shell command from a .NET application
7
2009-11-30 02:11:30
<p>I need to execute a shell command from my .NET application, not unlike <a href="http://lua-users.org/wiki/OsLibraryTutorial" rel="nofollow noreferrer"><code>os.execute</code></a> (a little way down on that page) in <a href="http://en.wikipedia.org/wiki/Lua_%28programming_language%29" rel="nofollow noreferrer">Lua</a...
15,361
117,069
2015-08-30 19:46:35
1,817,573
12
2009-11-30 02:15:15
221,042
2015-08-30 19:46:35
https://stackoverflow.com/q/1817562
https://stackoverflow.com/a/1817573
<pre><code>System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "blah.lua arg1 arg2 arg3"; p.StartInfo.UseShellExecute = true; p.Start(); </code></pre> <p>Another way would be to use <a href="http://en.wikipedia.org/wiki/Platform_Invocation_Services" rel="nofollow noreferrer">P/Invok...
<pre><code>System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "blah.lua arg1 arg2 arg3"; p.StartInfo.UseShellExecute = true; p.Start(); </code></pre> <p>Another way would be to use <a href="http://en.wikipedia.org/wiki/Platform_Invocation_Services" rel="nofollow noreferrer">P/Invok...
1, 390, 488, 11844, 36252
.net, console, execution, shell, winforms
<h1>Execute a shell command from a .NET application</h1> <p>I need to execute a shell command from my .NET application, not unlike <a href="http://lua-users.org/wiki/OsLibraryTutorial" rel="nofollow noreferrer"><code>os.execute</code></a> (a little way down on that page) in <a href="http://en.wikipedia.org/wiki/Lua_%28...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,067
bash
# Execute a shell command from a .NET application I need to execute a shell command from my .NET application, not unlike [`os.execute`](http://lua-users.org/wiki/OsLibraryTutorial) (a little way down on that page) in [Lua](http://en.wikipedia.org/wiki/Lua_%28programming_language%29). However with a cursory search I co...
``` System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "blah.lua arg1 arg2 arg3"; p.StartInfo.UseShellExecute = true; p.Start(); ``` Another way would be to use [P/Invoke](http://en.wikipedia.org/wiki/Platform_Invocation_Services) and use ShellExecute directly: ``` [DllImport("she...
1334298
Running a script from Groovy
7
2009-08-26 12:21:41
<p>In order to get my setup a bit closer to "one click deployment", I would like to use groovy scripts to start/stop other processes controlled by bat scripts, running in different parts of the filesystem and even on different machines. </p> <p>How to execute these scripts and how to do it from <em>their</em> respecti...
19,708
132,396
2012-12-12 20:21:04
1,334,625
12
2009-08-26 13:18:15
12,591
2009-08-26 13:18:15
https://stackoverflow.com/q/1334298
https://stackoverflow.com/a/1334625
<p>Groovy added an execute() method to plain old String, so try this:</p> <pre><code>println "ls -la".execute().text </code></pre>
<p>Groovy added an execute() method to plain old String, so try this:</p> <pre><code>println "ls -la".execute().text </code></pre>
531, 849, 3951
groovy, groovyshell, scripting
<h1>Running a script from Groovy</h1> <p>In order to get my setup a bit closer to "one click deployment", I would like to use groovy scripts to start/stop other processes controlled by bat scripts, running in different parts of the filesystem and even on different machines. </p> <p>How to execute these scripts and how...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,068
bash
# Running a script from Groovy In order to get my setup a bit closer to "one click deployment", I would like to use groovy scripts to start/stop other processes controlled by bat scripts, running in different parts of the filesystem and even on different machines. How to execute these scripts and how to do it from *t...
Groovy added an execute() method to plain old String, so try this: ``` println "ls -la".execute().text ```
967369
python: find out if running in shell or not (e.g. sun grid engine queue)
7
2009-06-08 22:36:56
<p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p> <p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not.</p> <p>thanks!</p> <p>p.</p>
1,825
null
2013-07-20 00:27:32
967,384
12
2009-06-08 22:39:50
82,294
2013-01-28 04:07:59
https://stackoverflow.com/q/967369
https://stackoverflow.com/a/967384
<p>The standard way is <code>isatty()</code>.</p> <pre><code>import sys if sys.stdout.isatty(): print("Interactive") else: print("Non-interactive") </code></pre>
<p>The standard way is <code>isatty()</code>.</p> <pre><code>import sys if sys.stdout.isatty(): print("Interactive") else: print("Non-interactive") </code></pre>
16, 390, 391, 4867
python, shell, stdout, terminal
<h1>python: find out if running in shell or not (e.g. sun grid engine queue)</h1> <p>is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine?</p> <p>the idea is to decide on printing some progress bars and other ascii-interactive stuff, or ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,069
bash
# python: find out if running in shell or not (e.g. sun grid engine queue) is there a way to find out from within a python program if it was started in a terminal or e.g. in a batch engine like sun grid engine? the idea is to decide on printing some progress bars and other ascii-interactive stuff, or not. thanks! p...
The standard way is `isatty()`. ``` import sys if sys.stdout.isatty(): print("Interactive") else: print("Non-interactive") ```
330608
Changing IIS6 Site Home Directory with Powershell
7
2008-12-01 11:57:29
<p>I'm trying to change a site's home directory using powershell. This is what I have so far, but it isn't saving the changes...</p> <pre><code>$server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComme...
4,156
23,393
2015-11-01 21:28:12
330,842
12
2008-12-01 13:32:05
23,393
2008-12-01 13:32:05
https://stackoverflow.com/q/330608
https://stackoverflow.com/a/330842
<pre><code>$server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName } $path = [adsi]($site.psbase.path+"/ROOT") $path.path $path.psbase.properties.path[0] = "D:\Sites\$siteName\www2" $p...
<pre><code>$server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName } $path = [adsi]($site.psbase.path+"/ROOT") $path.path $path.psbase.properties.path[0] = "D:\Sites\$siteName\www2" $p...
215, 526, 531, 2304
iis, iis-6, powershell, scripting
<h1>Changing IIS6 Site Home Directory with Powershell</h1> <p>I'm trying to change a site's home directory using powershell. This is what I have so far, but it isn't saving the changes...</p> <pre><code>$server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where {...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,070
bash
# Changing IIS6 Site Home Directory with Powershell I'm trying to change a site's home directory using powershell. This is what I have so far, but it isn't saving the changes... ``` $server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIs...
``` $server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName } $path = [adsi]($site.psbase.path+"/ROOT") $path.path $path.psbase.properties.path[0] = "D:\Sites\$siteName\www2" $path.pat...
73034137
in bash what does the -n parameter in "local -n" mean?
6
2022-07-19 09:04:24
<p>in bash what does the -n parameter in <code>local -n var...</code> mean? - how does it differ from <code>local var...</code></p> <p>I can't find a good example / explanation for it. There are no man pages for keywords (it seems?). The closest I have found is a comment here: <a href="https://stackoverflow.com/questio...
5,590
2,298,137
2022-12-13 07:46:14
73,034,276
12
2022-07-19 09:14:10
1,030,675
2022-07-19 09:14:10
https://stackoverflow.com/q/73034137
https://stackoverflow.com/a/73034276
<p>Parameters to <code>local</code> are unfortunately not documented in <code>help local</code>, but in <code>help declare</code>:</p> <blockquote> <pre><code> `-n` make NAME a reference to the variable named by its value </code></pre> </blockquote> <p>How does it work?</p> <pre class="lang-bash prettyprint-override"><...
<p>Parameters to <code>local</code> are unfortunately not documented in <code>help local</code>, but in <code>help declare</code>:</p> <blockquote> <pre><code> `-n` make NAME a reference to the variable named by its value </code></pre> </blockquote> <p>How does it work?</p> <pre class="lang-bash prettyprint-override"><...
58, 387, 6923
bash, linux, local
<h1>in bash what does the -n parameter in "local -n" mean?</h1> <p>in bash what does the -n parameter in <code>local -n var...</code> mean? - how does it differ from <code>local var...</code></p> <p>I can't find a good example / explanation for it. There are no man pages for keywords (it seems?). The closest I have fou...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,071
bash
# in bash what does the -n parameter in "local -n" mean? in bash what does the -n parameter in `local -n var...` mean? - how does it differ from `local var...` I can't find a good example / explanation for it. There are no man pages for keywords (it seems?). The closest I have found is a comment here: [local: -n: inv...
Parameters to `local` are unfortunately not documented in `help local`, but in `help declare`: > ``` > `-n` make NAME a reference to the variable named by its value > ``` How does it work? ``` #! /bin/bash f () { local -n x=y y=12 x=42 echo $x $y # 42 42 } f ``` You can achieve similar behaviour w...
72104301
PowerShell Open URL in New Window - [system.Diagnostics.process]::Start("","")
6
2022-05-03 19:05:26
<p>So I'm using PowerShell (specifically version 5.1) in order to write a script for my work that essentially opens some websites depending on what the user selects from available options.</p> <p>In order to open the website (for this example, let's just say I'm going to Google), I'm using [system.Diagnostics.Process]:...
23,224
19,026,975
2025-05-20 22:31:16
72,104,697
12
2022-05-03 19:43:27
45,375
2023-05-07 20:31:23
https://stackoverflow.com/q/72104301
https://stackoverflow.com/a/72104697
<ul> <li><p>The Chrome CLI parameter that requests opening a given URL in a new window is <br><code>--new-window</code></p> </li> <li><p>It's simpler to use PowerShell's <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process" rel="noreferrer"><code>Start-Process</code></a>...
<ul> <li><p>The Chrome CLI parameter that requests opening a given URL in a new window is <br><code>--new-window</code></p> </li> <li><p>It's simpler to use PowerShell's <a href="https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process" rel="noreferrer"><code>Start-Process</code></a>...
526
powershell
<h1>PowerShell Open URL in New Window - [system.Diagnostics.process]::Start("","")</h1> <p>So I'm using PowerShell (specifically version 5.1) in order to write a script for my work that essentially opens some websites depending on what the user selects from available options.</p> <p>In order to open the website (for th...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,072
bash
# PowerShell Open URL in New Window - [system.Diagnostics.process]::Start("","") So I'm using PowerShell (specifically version 5.1) in order to write a script for my work that essentially opens some websites depending on what the user selects from available options. In order to open the website (for this example, let...
- The Chrome CLI parameter that requests opening a given URL in a new window is `--new-window` - It's simpler to use PowerShell's [`Start-Process`](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/start-process) cmdlet rather than the underlying .NET API directly. Therefore: ``` Star...
68907012
How to open installed Microsoft Store apps from powershell?
6
2021-08-24 11:47:07
<p>I'm getting the list of installed Microsoft Store apps with this command:</p> <pre><code>Get-AppxPackage -AllUsers </code></pre> <p>And then I try to open an app:</p> <pre><code>powershell -Command &quot;Start-Process 'C:\Program Files\WindowsApps\Microsoft.Windows.Photos_2021.21070.22007.0_x64__8wekyb3d8bbwe\Micros...
7,132
12,125,881
2022-09-13 16:50:32
68,907,604
12
2021-08-24 12:28:59
45,375
2022-09-13 16:50:32
https://stackoverflow.com/q/68907012
https://stackoverflow.com/a/68907604
<pre class="lang-bash prettyprint-override"><code># Use the URI scheme of the Microsoft.Photos application. # Note: Unfortunately, -Wait does *not* work in this case. Start-Process ms-photos: # Wait for the process to exit (from what I can tell there's only ever 1 # Microsoft.Photos process). # The relevant process n...
<pre class="lang-bash prettyprint-override"><code># Use the URI scheme of the Microsoft.Photos application. # Note: Unfortunately, -Wait does *not* work in this case. Start-Process ms-photos: # Wait for the process to exit (from what I can tell there's only ever 1 # Microsoft.Photos process). # The relevant process n...
64, 526, 84376
appx, powershell, windows
<h1>How to open installed Microsoft Store apps from powershell?</h1> <p>I'm getting the list of installed Microsoft Store apps with this command:</p> <pre><code>Get-AppxPackage -AllUsers </code></pre> <p>And then I try to open an app:</p> <pre><code>powershell -Command &quot;Start-Process 'C:\Program Files\WindowsApps\...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,073
bash
# How to open installed Microsoft Store apps from powershell? I'm getting the list of installed Microsoft Store apps with this command: ``` Get-AppxPackage -AllUsers ``` And then I try to open an app: ``` powershell -Command "Start-Process 'C:\Program Files\WindowsApps\Microsoft.Windows.Photos_2021.21070.22007.0_x6...
``` # Use the URI scheme of the Microsoft.Photos application. # Note: Unfortunately, -Wait does *not* work in this case. Start-Process ms-photos: # Wait for the process to exit (from what I can tell there's only ever 1 # Microsoft.Photos process). # The relevant process name was obtained with: Get-Process *Photos* (Ge...
67626879
[System.Collections.Generic.List[string]] as return value
6
2021-05-20 19:31:45
<p>I have a need/want to return a <code>[System.Collections.Generic.List[string]]</code> from a function, but it is being covered into a <code>System.Object[]</code></p> <p>I have this</p> <pre><code>function TestReturn { $returnList = New-Object System.Collections.Generic.List[string] $returnList.Add('Testing,...
19,950
4,552,490
2025-02-12 12:50:45
67,627,137
12
2021-05-20 19:55:28
4,749,264
2021-05-20 19:55:28
https://stackoverflow.com/q/67626879
https://stackoverflow.com/a/67627137
<p>If you remove the array subexpression <code>@(...)</code> and just precede with a comma. The below code seems to work:</p> <pre><code>function TestReturn { $returnList = New-Object System.Collections.Generic.List[string] $returnList.Add('Testing, one, two') return , $returnList } $testList = TestRetur...
<p>If you remove the array subexpression <code>@(...)</code> and just precede with a comma. The below code seems to work:</p> <pre><code>function TestReturn { $returnList = New-Object System.Collections.Generic.List[string] $returnList.Add('Testing, one, two') return , $returnList } $testList = TestRetur...
526, 8799, 9643
generic-list, powershell, return-type
<h1>[System.Collections.Generic.List[string]] as return value</h1> <p>I have a need/want to return a <code>[System.Collections.Generic.List[string]]</code> from a function, but it is being covered into a <code>System.Object[]</code></p> <p>I have this</p> <pre><code>function TestReturn { $returnList = New-Object Sy...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
11,074
bash
# [System.Collections.Generic.List[string]] as return value I have a need/want to return a `[System.Collections.Generic.List[string]]` from a function, but it is being covered into a `System.Object[]` I have this ``` function TestReturn { $returnList = New-Object System.Collections.Generic.List[string] $retu...
If you remove the array subexpression `@(...)` and just precede with a comma. The below code seems to work: ``` function TestReturn { $returnList = New-Object System.Collections.Generic.List[string] $returnList.Add('Testing, one, two') return , $returnList } $testList = TestReturn $testList.GetType().Ful...