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
9961291
Is this a bug in bash ?(up arrow)
9
2012-04-01 01:49:23
<p>As we know, press up arrow key can show history commands,but i found that when a command which starting with space will not show in "up arrow"'s history:</p> <p><code>$ls</code></p> <p><code>$(press up arrow key)</code></p> <p>bash will show:</p> <p><code>$ls</code></p> <p>however:</p> <p><code>$ps</code></p> ...
588
1,068,676
2012-04-01 01:53:16
9,961,313
12
2012-04-01 01:53:16
377,270
2012-04-01 01:53:16
https://stackoverflow.com/q/9961291
https://stackoverflow.com/a/9961313
<p>From <code>bash(1)</code>:</p> <pre><code> HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. </code></...
<p>From <code>bash(1)</code>:</p> <pre><code> HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. </code></...
58, 387
bash, linux
<h1>Is this a bug in bash ?(up arrow)</h1> <p>As we know, press up arrow key can show history commands,but i found that when a command which starting with space will not show in "up arrow"'s history:</p> <p><code>$ls</code></p> <p><code>$(press up arrow key)</code></p> <p>bash will show:</p> <p><code>$ls</code></p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,873
bash
# Is this a bug in bash ?(up arrow) As we know, press up arrow key can show history commands,but i found that when a command which starting with space will not show in "up arrow"'s history: `$ls` `$(press up arrow key)` bash will show: `$ls` however: `$ps` `$ ls(notice this command starts with a space)` now i ...
From `bash(1)`: ``` HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. ``` It's an intentional feature t...
8841195
How can I script file generation from a template using bash?
9
2012-01-12 19:36:56
<p>I am trying to automate the set up of site creation for our in-house development server.</p> <p>Currently, this consists of creating a system user, mysql user, database, and apache config. I know how I can do everything in a single bash file, but I wanted to ask if there was a way to more cleanly generate the apach...
9,518
245,163
2020-07-22 17:32:11
8,842,048
12
2012-01-12 20:46:41
15,168
2012-01-12 21:40:33
https://stackoverflow.com/q/8841195
https://stackoverflow.com/a/8842048
<p>Choose a way of marking parameters. One possibility is <code>:parameter:</code>, but any similar pair of markers that won't be confused with legitimate text for the template file(s) is good.</p> <p>Write a <code>sed</code> script (in <code>sed</code>, <code>awk</code>, <code>perl</code>, ...) similar to the follow...
<p>Choose a way of marking parameters. One possibility is <code>:parameter:</code>, but any similar pair of markers that won't be confused with legitimate text for the template file(s) is good.</p> <p>Write a <code>sed</code> script (in <code>sed</code>, <code>awk</code>, <code>perl</code>, ...) similar to the follow...
387, 990, 1156, 5282
awk, bash, printf, sed
<h1>How can I script file generation from a template using bash?</h1> <p>I am trying to automate the set up of site creation for our in-house development server.</p> <p>Currently, this consists of creating a system user, mysql user, database, and apache config. I know how I can do everything in a single bash file, but...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,874
bash
# How can I script file generation from a template using bash? I am trying to automate the set up of site creation for our in-house development server. Currently, this consists of creating a system user, mysql user, database, and apache config. I know how I can do everything in a single bash file, but I wanted to ask...
Choose a way of marking parameters. One possibility is `:parameter:`, but any similar pair of markers that won't be confused with legitimate text for the template file(s) is good. Write a `sed` script (in `sed`, `awk`, `perl`, ...) similar to the following: ``` sed -e "s/:param1:/$param1/g" \ -e "s/:param2:/$para...
8672039
See what process last touched a file
9
2011-12-29 18:48:41
<p>On a linux box that there is some process regularly changing permissions on directories and files, roughly daily. This is not a process that I set up and I have no idea what it is.</p> <p>I have root access and I can easily change permissions manually to get access back but it is a bit annoying.</p> <p>Is there an...
8,532
831,964
2011-12-29 19:12:44
8,672,155
12
2011-12-29 18:57:40
475,150
2011-12-29 19:12:44
https://stackoverflow.com/q/8672039
https://stackoverflow.com/a/8672155
<p>On a Fedora system, you can use:</p> <pre><code>sudo auditctl -p a -w /some/file # monitor attribute changes to /some/file </code></pre> <p>It's in the <code>audit</code> package, if you don't have that installed, then <code>sudo yum install audit</code></p> <p>The output goes into <code>/var/log/audit/audit.log...
<p>On a Fedora system, you can use:</p> <pre><code>sudo auditctl -p a -w /some/file # monitor attribute changes to /some/file </code></pre> <p>It's in the <code>audit</code> package, if you don't have that installed, then <code>sudo yum install audit</code></p> <p>The output goes into <code>/var/log/audit/audit.log...
58, 387
bash, linux
<h1>See what process last touched a file</h1> <p>On a linux box that there is some process regularly changing permissions on directories and files, roughly daily. This is not a process that I set up and I have no idea what it is.</p> <p>I have root access and I can easily change permissions manually to get access back...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,875
bash
# See what process last touched a file On a linux box that there is some process regularly changing permissions on directories and files, roughly daily. This is not a process that I set up and I have no idea what it is. I have root access and I can easily change permissions manually to get access back but it is a bit...
On a Fedora system, you can use: ``` sudo auditctl -p a -w /some/file # monitor attribute changes to /some/file ``` It's in the `audit` package, if you don't have that installed, then `sudo yum install audit` The output goes into `/var/log/audit/audit.log` in the form: ``` type=SYSCALL msg=audit(1325185116.524:1...
8081297
sed to change string in a file only once
9
2011-11-10 14:45:41
<p>suggest I have a file <code>example</code> as follows:</p> <pre><code>c a b a b d </code></pre> <p>and I want to change the first occurance of <code>a</code> to <code>e</code>. Then I do this:</p> <pre><code>sed -i 's/a/e/' example </code></pre> <p>and all <code>a</code> changed to <code>e</code>.</p> <p>So is ...
6,986
543,492
2024-03-12 08:33:03
8,081,372
12
2011-11-10 14:51:05
1,034,080
2011-11-10 14:51:05
https://stackoverflow.com/q/8081297
https://stackoverflow.com/a/8081372
<p>Applying the information from Aziz' duplicate link to your question, I think this will give you the desired result for your case:</p> <pre><code>sed -i '0,/a/s//e/' example </code></pre>
<p>Applying the information from Aziz' duplicate link to your question, I think this will give you the desired result for your case:</p> <pre><code>sed -i '0,/a/s//e/' example </code></pre>
387, 5282, 11225
bash, command-line-interface, sed
<h1>sed to change string in a file only once</h1> <p>suggest I have a file <code>example</code> as follows:</p> <pre><code>c a b a b d </code></pre> <p>and I want to change the first occurance of <code>a</code> to <code>e</code>. Then I do this:</p> <pre><code>sed -i 's/a/e/' example </code></pre> <p>and all <code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,876
bash
# sed to change string in a file only once suggest I have a file `example` as follows: ``` c a b a b d ``` and I want to change the first occurance of `a` to `e`. Then I do this: ``` sed -i 's/a/e/' example ``` and all `a` changed to `e`. So is there any way to make sed only replace once within a file? Thanks.
Applying the information from Aziz' duplicate link to your question, I think this will give you the desired result for your case: ``` sed -i '0,/a/s//e/' example ```
6704197
Why use a Groovy shell script over Bash (when memory footprint is important)?
9
2011-07-15 08:08:09
<p>I've got a Bash script (50 lines of code) that requires a bit of hacking due to limitations of bash. So someone said: "hey, use a better language than bash for that!"</p> <p>So, I looked at Groovy (Groovy/Grails is next up on my to-learn list, so maybe this is a good time). I can do more complex shell scripts, so t...
9,393
4,790,871
2013-08-24 17:41:19
6,704,238
12
2011-07-15 08:12:39
40,342
2011-07-15 08:19:40
https://stackoverflow.com/q/6704197
https://stackoverflow.com/a/6704238
<p>If memory is limited like that, then any language running on the JVM will be at a disadvantage. And Groovy is such a language.</p> <p>Other languages like Python or Perl have a leaner runtime and require less memory for simple scripts (my guess is that Python is still a bit leaner than Perl, but I can't back that u...
<p>If memory is limited like that, then any language running on the JVM will be at a disadvantage. And Groovy is such a language.</p> <p>Other languages like Python or Perl have a leaner runtime and require less memory for simple scripts (my guess is that Python is still a bit leaner than Perl, but I can't back that u...
58, 387, 849
bash, groovy, linux
<h1>Why use a Groovy shell script over Bash (when memory footprint is important)?</h1> <p>I've got a Bash script (50 lines of code) that requires a bit of hacking due to limitations of bash. So someone said: "hey, use a better language than bash for that!"</p> <p>So, I looked at Groovy (Groovy/Grails is next up on my ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,877
bash
# Why use a Groovy shell script over Bash (when memory footprint is important)? I've got a Bash script (50 lines of code) that requires a bit of hacking due to limitations of bash. So someone said: "hey, use a better language than bash for that!" So, I looked at Groovy (Groovy/Grails is next up on my to-learn list, s...
If memory is limited like that, then any language running on the JVM will be at a disadvantage. And Groovy is such a language. Other languages like Python or Perl have a leaner runtime and require less memory for simple scripts (my guess is that Python is still a bit leaner than Perl, but I can't back that up with num...
6239291
Logging in via a script to a remote server and execute a set of commands
9
2011-06-04 20:45:24
<p>How can I login to a remote server and execute a set of commands then when done logout and continue my script?</p> <p>Thanks.</p>
23,573
504,715
2013-06-06 21:01:35
6,239,313
12
2011-06-04 20:49:46
174,430
2011-06-04 20:49:46
https://stackoverflow.com/q/6239291
https://stackoverflow.com/a/6239313
<p>ssh can be used to execute a command, rather than start a remote interactive login shell. For example:</p> <pre><code>ssh user@host ls </code></pre> <p>Will log into host and execute the <code>ls</code> command.</p> <p>You can use this inside a bash script as normal:</p> <pre><code>#!/bin/bash # do local comman...
<p>ssh can be used to execute a command, rather than start a remote interactive login shell. For example:</p> <pre><code>ssh user@host ls </code></pre> <p>Will log into host and execute the <code>ls</code> command.</p> <p>You can use this inside a bash script as normal:</p> <pre><code>#!/bin/bash # do local comman...
386, 387, 1231
bash, command-line, ssh
<h1>Logging in via a script to a remote server and execute a set of commands</h1> <p>How can I login to a remote server and execute a set of commands then when done logout and continue my script?</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
10,878
bash
# Logging in via a script to a remote server and execute a set of commands How can I login to a remote server and execute a set of commands then when done logout and continue my script? Thanks.
ssh can be used to execute a command, rather than start a remote interactive login shell. For example: ``` ssh user@host ls ``` Will log into host and execute the `ls` command. You can use this inside a bash script as normal: ``` #!/bin/bash # do local commands ssh user@host "ls; grep something file.txt; copy a b...
4470673
bash, find, exec and echo
9
2010-12-17 13:02:32
<pre><code>find . \ -name 'user_prefs' \ -exec echo "whitelist_from basheer@hydrofitgroup.com" &gt;&gt; {} \;' </code></pre> <p>I would like to add the line <code>whitelist_from basheer@hydrofitgroup.com</code> to all files that are found by <code>find</code>, but my command does not work. It just creates the file...
12,226
383,908
2016-08-29 12:26:50
4,470,706
12
2010-12-17 13:07:32
119,797
2010-12-17 13:07:32
https://stackoverflow.com/q/4470673
https://stackoverflow.com/a/4470706
<p>You have to escape the '>>', for example like this:</p> <pre><code>find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" &gt;&gt; {}' \; </code></pre>
<p>You have to escape the '>>', for example like this:</p> <pre><code>find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" &gt;&gt; {}' \; </code></pre>
387, 1231, 2531, 10193
bash, command-line, find, for-loop
<h1>bash, find, exec and echo</h1> <pre><code>find . \ -name 'user_prefs' \ -exec echo "whitelist_from basheer@hydrofitgroup.com" &gt;&gt; {} \;' </code></pre> <p>I would like to add the line <code>whitelist_from basheer@hydrofitgroup.com</code> to all files that are found by <code>find</code>, but my command does...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,879
bash
# bash, find, exec and echo ``` find . \ -name 'user_prefs' \ -exec echo "whitelist_from basheer@hydrofitgroup.com" >> {} \;' ``` I would like to add the line `whitelist_from basheer@hydrofitgroup.com` to all files that are found by `find`, but my command does not work. It just creates the file '{}'. Shoud i use...
You have to escape the '>>', for example like this: ``` find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" >> {}' \; ```
2957828
Smart image search via Powershell
9
2010-06-02 12:56:46
<p>I am interested in file searching by custom properties. For example, I want to find all JPEG-images with certain dimensions. Something looks like</p> <pre><code>Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' } </code></pre> <p>I suspect it's about using of System.Draw...
3,169
148,405
2010-06-03 09:29:45
2,957,875
12
2010-06-02 13:03:45
73,070
2010-06-02 14:55:12
https://stackoverflow.com/q/2957828
https://stackoverflow.com/a/2957875
<p>That's actually pretty easy to do and your gut feeling about System.Drawing was in fact correct:</p> <pre><code>Add-Type -Assembly System.Drawing $input | ForEach-Object { [Drawing.Image]::FromFile($_) } </code></pre> <p>Save that as <code>Get-Image.ps1</code> somewhere in your path and then you can use it.</p> ...
<p>That's actually pretty easy to do and your gut feeling about System.Drawing was in fact correct:</p> <pre><code>Add-Type -Assembly System.Drawing $input | ForEach-Object { [Drawing.Image]::FromFile($_) } </code></pre> <p>Save that as <code>Get-Image.ps1</code> somewhere in your path and then you can use it.</p> ...
526, 4985, 21909
file-search, image, powershell
<h1>Smart image search via Powershell</h1> <p>I am interested in file searching by custom properties. For example, I want to find all JPEG-images with certain dimensions. Something looks like</p> <pre><code>Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' } </code></pre> <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,880
bash
# Smart image search via Powershell I am interested in file searching by custom properties. For example, I want to find all JPEG-images with certain dimensions. Something looks like ``` Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' } ``` I suspect it's about using of S...
That's actually pretty easy to do and your gut feeling about System.Drawing was in fact correct: ``` Add-Type -Assembly System.Drawing $input | ForEach-Object { [Drawing.Image]::FromFile($_) } ``` Save that as `Get-Image.ps1` somewhere in your path and then you can use it. Another option would be to add the followi...
2078059
Python/Django shell won't start
9
2010-01-16 16:23:44
<p>One of the great features of Django is that you can open a python interpreter set-up for use with your project. This can be used to analyse objects in a database and allows any python commands to be executed on your project. I find it essential for Django development. It is invoked in the project directory using thi...
14,765
166,210
2011-12-07 15:50:20
2,078,129
12
2010-01-16 16:43:08
104,349
2010-01-16 16:43:08
https://stackoverflow.com/q/2078059
https://stackoverflow.com/a/2078129
<p>It seems like IPython is installed wrongly somehow. Try starting the shell with:</p> <pre><code>./manage.py shell --plain </code></pre> <p>to start the standard Python shell, rather than IPython. If that works, then trying removing IPython completely and reinstalling it.</p>
<p>It seems like IPython is installed wrongly somehow. Try starting the shell with:</p> <pre><code>./manage.py shell --plain </code></pre> <p>to start the standard Python shell, rather than IPython. If that works, then trying removing IPython completely and reinstalling it.</p>
16, 243, 390
django, python, shell
<h1>Python/Django shell won't start</h1> <p>One of the great features of Django is that you can open a python interpreter set-up for use with your project. This can be used to analyse objects in a database and allows any python commands to be executed on your project. I find it essential for Django development. It is i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,881
bash
# Python/Django shell won't start One of the great features of Django is that you can open a python interpreter set-up for use with your project. This can be used to analyse objects in a database and allows any python commands to be executed on your project. I find it essential for Django development. It is invoked in...
It seems like IPython is installed wrongly somehow. Try starting the shell with: ``` ./manage.py shell --plain ``` to start the standard Python shell, rather than IPython. If that works, then trying removing IPython completely and reinstalling it.
1218907
How do I set a Windows Service to start automatically in PowerShell?
9
2009-08-02 13:34:12
<p>If I know a service name, and have enough permission, how do I set a Windows Service to be auto-restart in PowerShell?</p> <p>I am using PowerShell 1.0, and the OS is Windows Server 2003.</p>
15,398
63,235
2019-09-11 14:21:34
1,218,931
12
2009-08-02 13:46:22
118,959
2017-09-19 18:41:57
https://stackoverflow.com/q/1218907
https://stackoverflow.com/a/1218931
<p>You may be asking for:</p> <pre><code>Set-Service [service name] -startuptype automatic </code></pre> <p>See:</p> <pre><code>&gt; get-help set-service NAME Set-Service SYNOPSIS Starts, stops, and suspends a service, and changes its properties. SYNTAX Set-Service [-StartupType {Automatic | Manual |...
<p>You may be asking for:</p> <pre><code>Set-Service [service name] -startuptype automatic </code></pre> <p>See:</p> <pre><code>&gt; get-help set-service NAME Set-Service SYNOPSIS Starts, stops, and suspends a service, and changes its properties. SYNTAX Set-Service [-StartupType {Automatic | Manual |...
526, 2596
powershell, windows-services
<h1>How do I set a Windows Service to start automatically in PowerShell?</h1> <p>If I know a service name, and have enough permission, how do I set a Windows Service to be auto-restart in PowerShell?</p> <p>I am using PowerShell 1.0, and the OS is Windows Server 2003.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,882
bash
# How do I set a Windows Service to start automatically in PowerShell? If I know a service name, and have enough permission, how do I set a Windows Service to be auto-restart in PowerShell? I am using PowerShell 1.0, and the OS is Windows Server 2003.
You may be asking for: ``` Set-Service [service name] -startuptype automatic ``` See: ``` > get-help set-service NAME Set-Service SYNOPSIS Starts, stops, and suspends a service, and changes its properties. SYNTAX Set-Service [-StartupType {Automatic | Manual | Disabled}] [-DisplayName <string>] [-Pas...
766207
How can I escape characters in SQLite via bash shell?
9
2009-04-19 22:04:11
<p>I am trying to send a query to SQLite from the command line using bash. I need to escape both single quotes and double quotes, and escape them so that bash does not misinterpret them. Here is a typical query:</p> <pre><code>select * from contacts where source = "Nancy's notes"; </code></pre> <p>How can I send this...
14,888
82,056
2020-06-21 21:31:58
766,301
12
2009-04-19 22:53:28
15,168
2009-04-19 22:53:28
https://stackoverflow.com/q/766207
https://stackoverflow.com/a/766301
<p>The trouble with MarkusQ's solution is knowing which characters are special inside double quotes - there are quite a lot of them, including back-ticks, dollar-open parenthesis, dollar-variable, etc.</p> <p>I would suggest it is better to enclose the string inside single quotes; then, each single quote inside the st...
<p>The trouble with MarkusQ's solution is knowing which characters are special inside double quotes - there are quite a lot of them, including back-ticks, dollar-open parenthesis, dollar-variable, etc.</p> <p>I would suggest it is better to enclose the string inside single quotes; then, each single quote inside the st...
121, 387, 390, 1231, 4804
bash, command-line, escaping, shell, sqlite
<h1>How can I escape characters in SQLite via bash shell?</h1> <p>I am trying to send a query to SQLite from the command line using bash. I need to escape both single quotes and double quotes, and escape them so that bash does not misinterpret them. Here is a typical query:</p> <pre><code>select * from contacts where ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,883
bash
# How can I escape characters in SQLite via bash shell? I am trying to send a query to SQLite from the command line using bash. I need to escape both single quotes and double quotes, and escape them so that bash does not misinterpret them. Here is a typical query: ``` select * from contacts where source = "Nancy's no...
The trouble with MarkusQ's solution is knowing which characters are special inside double quotes - there are quite a lot of them, including back-ticks, dollar-open parenthesis, dollar-variable, etc. I would suggest it is better to enclose the string inside single quotes; then, each single quote inside the string needs...
68752743
I can't I use my code certificate to sign my .exe file (EKU filter)
8
2021-08-12 06:41:45
<p>I created a code certificate using:</p> <pre><code>$cert = New-SelfSignedCertificate -CertStoreLocation &quot;Cert:\CurrentUser\My&quot; -dnsname testcert.test.io $cert $secPassword = ConvertTo-SecureString -String 'password1234' -Force -AsPlainText $certPath = &quot;Cert:\CurrentUser\My\$($cert.Thumbprint)&quot;...
5,392
13,204,735
2021-08-13 10:00:42
68,758,472
12
2021-08-12 13:32:50
12,679
2021-08-13 10:00:42
https://stackoverflow.com/q/68752743
https://stackoverflow.com/a/68758472
<p>You need a<code>Code Signing</code>-Certificate, which means that it has an Extended Key Usage (EKU) with the Code signing Object Identifier (OID).</p> <pre><code>$ku_codeSigning = &quot;1.3.6.1.5.5.7.3.3&quot;; $codeSignCert = New-SelfSignedCertificate ` -Type &quot;CodeSigningCert&quot; ` -KeyExportPoli...
<p>You need a<code>Code Signing</code>-Certificate, which means that it has an Extended Key Usage (EKU) with the Code signing Object Identifier (OID).</p> <pre><code>$ku_codeSigning = &quot;1.3.6.1.5.5.7.3.3&quot;; $codeSignCert = New-SelfSignedCertificate ` -Type &quot;CodeSigningCert&quot; ` -KeyExportPoli...
64, 526, 5954, 14423
certificate, powershell, ssl-certificate, windows
<h1>I can't I use my code certificate to sign my .exe file (EKU filter)</h1> <p>I created a code certificate using:</p> <pre><code>$cert = New-SelfSignedCertificate -CertStoreLocation &quot;Cert:\CurrentUser\My&quot; -dnsname testcert.test.io $cert $secPassword = ConvertTo-SecureString -String 'password1234' -Force -...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,884
bash
# I can't I use my code certificate to sign my .exe file (EKU filter) I created a code certificate using: ``` $cert = New-SelfSignedCertificate -CertStoreLocation "Cert:\CurrentUser\My" -dnsname testcert.test.io $cert $secPassword = ConvertTo-SecureString -String 'password1234' -Force -AsPlainText $certPath = "Cer...
You need a`Code Signing`-Certificate, which means that it has an Extended Key Usage (EKU) with the Code signing Object Identifier (OID). ``` $ku_codeSigning = "1.3.6.1.5.5.7.3.3"; $codeSignCert = New-SelfSignedCertificate ` -Type "CodeSigningCert" ` -KeyExportPolicy "Exportable" ` -Subject "..." ` -...
64601031
how to escape single quote in `jq`
8
2020-10-30 00:18:04
<p>I am trying to format a json string using <code>jq</code> with expected output like this:</p> <pre><code>[ { &quot;command&quot;: [ &quot;printf 'this is a text'&quot; ] } ] </code></pre> <p>However, I cannot get it to work for the single quotes ('), e.g. <code>$ jq -n '[{&quot;command&quot;: [&qu...
14,839
1,234,376
2020-10-30 07:37:37
64,601,499
12
2020-10-30 01:23:58
997,358
2020-10-30 05:58:14
https://stackoverflow.com/q/64601031
https://stackoverflow.com/a/64601499
<p>Here are four alternatives that should work with a bash or bash-like shell. They can be adapted for other shells as well.</p> <pre><code>jq -n $'[{&quot;command&quot;: [&quot;printf \'this is a text\'&quot;]}]' </code></pre> <pre><code>cat &lt;&lt; EOF | jq . [{&quot;command&quot;: [&quot;printf 'this is a text'&quo...
<p>Here are four alternatives that should work with a bash or bash-like shell. They can be adapted for other shells as well.</p> <pre><code>jq -n $'[{&quot;command&quot;: [&quot;printf \'this is a text\'&quot;]}]' </code></pre> <pre><code>cat &lt;&lt; EOF | jq . [{&quot;command&quot;: [&quot;printf 'this is a text'&quo...
390, 555, 1508, 31796, 105170
formatting, jq, json, quotation-marks, shell
<h1>how to escape single quote in `jq`</h1> <p>I am trying to format a json string using <code>jq</code> with expected output like this:</p> <pre><code>[ { &quot;command&quot;: [ &quot;printf 'this is a text'&quot; ] } ] </code></pre> <p>However, I cannot get it to work for the single quotes ('), e.g....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,885
bash
# how to escape single quote in `jq` I am trying to format a json string using `jq` with expected output like this: ``` [ { "command": [ "printf 'this is a text'" ] } ] ``` However, I cannot get it to work for the single quotes ('), e.g. `$ jq -n '[{"command": ["printf 'this is a text'"]}]'` gives ...
Here are four alternatives that should work with a bash or bash-like shell. They can be adapted for other shells as well. ``` jq -n $'[{"command": ["printf \'this is a text\'"]}]' ``` ``` cat << EOF | jq . [{"command": ["printf 'this is a text'"]}] EOF ``` ``` jq --arg cmd "printf 'this is a text'" -n '[{command: [ ...
63704503
How do I remove a git branch whose name starts with a unicode character?
8
2020-09-02 11:24:43
<p>Using GfW I accidentally created a branch whose name begins with <code>&lt;U+0096&gt;</code>, which seems to be a unicode control-character.</p> <pre><code>$ git branch features/#72_some_branch * features/#73_another_branch master &lt;U+0096&gt;features/#73_another_branch </code></pre> <p>Now, in order to corr...
2,376
9,197,527
2020-09-02 14:12:48
63,704,632
12
2020-09-02 11:32:33
9,197,527
2020-09-02 11:49:29
https://stackoverflow.com/q/63704503
https://stackoverflow.com/a/63704632
<p>I have to admit, the answer was quite obvious. Using the built-in <code>echo</code> command of the bash shell, I was able to insert the desired symbol:</p> <pre><code>git branch -d &quot;$(echo -e '\u0096')features/#73_another_branch&quot; </code></pre>
<p>I have to admit, the answer was quite obvious. Using the built-in <code>echo</code> command of the bash shell, I was able to insert the desired symbol:</p> <pre><code>git branch -d &quot;$(echo -e '\u0096')features/#73_another_branch&quot; </code></pre>
119, 61874, 123373
git, git-bash, git-for-windows
<h1>How do I remove a git branch whose name starts with a unicode character?</h1> <p>Using GfW I accidentally created a branch whose name begins with <code>&lt;U+0096&gt;</code>, which seems to be a unicode control-character.</p> <pre><code>$ git branch features/#72_some_branch * features/#73_another_branch master ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,886
bash
# How do I remove a git branch whose name starts with a unicode character? Using GfW I accidentally created a branch whose name begins with `<U+0096>`, which seems to be a unicode control-character. ``` $ git branch features/#72_some_branch * features/#73_another_branch master <U+0096>features/#73_another_branc...
I have to admit, the answer was quite obvious. Using the built-in `echo` command of the bash shell, I was able to insert the desired symbol: ``` git branch -d "$(echo -e '\u0096')features/#73_another_branch" ```
60637859
Convert sequence of JSON lines (JSONL) to JSON array
8
2020-03-11 14:02:30
<p>I have a file where each line is a JSON object. I'd like to convert the file to a JSON array.</p> <p>The file looks something like this:</p> <pre><code>{"address":"email1@foo.bar.com", "topic":"Some topic."} {"address":"email2@foo.bar.com", "topic":"Another topic."} {"address":"email3@foo.bar.com", "topic":"Yet an...
8,547
1,536,611
2025-06-03 07:02:34
60,639,286
12
2020-03-11 15:18:41
14,122
2020-03-11 15:18:41
https://stackoverflow.com/q/60637859
https://stackoverflow.com/a/60639286
<pre><code>jq -n '[inputs]' &lt;in.jsonl &gt;out.json </code></pre> <p>...or, as <a href="https://stackoverflow.com/questions/60637859/convert-sequence-of-json-objects-to-json-array#comment107279792_60637859">suggested by @borrible</a>:</p> <pre><code>jq --slurp . &lt;in.jsonl &gt;out.json </code></pre>
<pre><code>jq -n '[inputs]' &lt;in.jsonl &gt;out.json </code></pre> <p>...or, as <a href="https://stackoverflow.com/questions/60637859/convert-sequence-of-json-objects-to-json-array#comment107279792_60637859">suggested by @borrible</a>:</p> <pre><code>jq --slurp . &lt;in.jsonl &gt;out.json </code></pre>
387, 1508, 105170, 118374
bash, jq, json, jsonlines
<h1>Convert sequence of JSON lines (JSONL) to JSON array</h1> <p>I have a file where each line is a JSON object. I'd like to convert the file to a JSON array.</p> <p>The file looks something like this:</p> <pre><code>{"address":"email1@foo.bar.com", "topic":"Some topic."} {"address":"email2@foo.bar.com", "topic":"Ano...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,887
bash
# Convert sequence of JSON lines (JSONL) to JSON array I have a file where each line is a JSON object. I'd like to convert the file to a JSON array. The file looks something like this: ``` {"address":"email1@foo.bar.com", "topic":"Some topic."} {"address":"email2@foo.bar.com", "topic":"Another topic."} {"address":"e...
``` jq -n '[inputs]' <in.jsonl >out.json ``` ...or, as [suggested by @borrible](https://stackoverflow.com/questions/60637859/convert-sequence-of-json-objects-to-json-array#comment107279792_60637859): ``` jq --slurp . <in.jsonl >out.json ```
59354806
'rm' is not recognized as an internal or external command when trying publish a capacitor plugin
8
2019-12-16 10:33:12
<p>I am trying to publish a capacitor plugin. According to the error it is not able to recognize <code>rm</code>. I am using Window's Powershell (VC Code) The following error is being generated in the powershell when npm publish in run</p> <pre><code>PS C:\Users\xxxxx\Documents\demo-plugin&gt; npm run build demo-plu...
19,950
10,506,473
2023-06-15 08:23:35
59,355,825
12
2019-12-16 11:34:47
7,356,355
2019-12-16 11:34:47
https://stackoverflow.com/q/59354806
https://stackoverflow.com/a/59355825
<p>In Windows you should use</p> <pre><code>rd /s /q dist </code></pre> <p><code>rm</code> is available in Linux and Mac.</p> <p>Reference: </p> <ul> <li><a href="https://stackoverflow.com/questions/41451884/how-to-run-rm-command-on-windows-10/41452647">How to run rm command on windows 10?</a></li> </ul>
<p>In Windows you should use</p> <pre><code>rd /s /q dist </code></pre> <p><code>rm</code> is available in Linux and Mac.</p> <p>Reference: </p> <ul> <li><a href="https://stackoverflow.com/questions/41451884/how-to-run-rm-command-on-windows-10/41452647">How to run rm command on windows 10?</a></li> </ul>
526, 61387, 100064, 132327
capacitor, ionic-framework, npm, powershell
<h1>'rm' is not recognized as an internal or external command when trying publish a capacitor plugin</h1> <p>I am trying to publish a capacitor plugin. According to the error it is not able to recognize <code>rm</code>. I am using Window's Powershell (VC Code) The following error is being generated in the powershell w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,888
bash
# 'rm' is not recognized as an internal or external command when trying publish a capacitor plugin I am trying to publish a capacitor plugin. According to the error it is not able to recognize `rm`. I am using Window's Powershell (VC Code) The following error is being generated in the powershell when npm publish in ru...
In Windows you should use ``` rd /s /q dist ``` `rm` is available in Linux and Mac. Reference: - [How to run rm command on windows 10?](https://stackoverflow.com/questions/41451884/how-to-run-rm-command-on-windows-10/41452647)
55729985
Change Ubuntu terminal to look like Git-bash of Window
8
2019-04-17 14:30:49
<p>Is there a way to change/replace the default Ubuntu terminal with Git-bash(look and behavior) of Window? Basically, the terminal should display all the necessary information related with current branch/repo, just like it does in Window. </p> <p>I am using VS Code and had configured Git-Bash with it for <a href="htt...
5,169
7,666,504
2019-04-22 09:41:26
55,792,362
12
2019-04-22 09:41:26
7,666,504
2019-04-22 09:41:26
https://stackoverflow.com/q/55729985
https://stackoverflow.com/a/55792362
<p>After <strong>@kostix</strong> suggestion, I searched the internet with proper key-words and found <a href="https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt">this question thread</a> and then finally to <a href="https://coderwall.com/p/fasnya/add-git-branch-name-to-bash...
<p>After <strong>@kostix</strong> suggestion, I searched the internet with proper key-words and found <a href="https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt">this question thread</a> and then finally to <a href="https://coderwall.com/p/fasnya/add-git-branch-name-to-bash...
119, 391, 61874, 132343
git, git-bash, terminal, ubuntu-18.04
<h1>Change Ubuntu terminal to look like Git-bash of Window</h1> <p>Is there a way to change/replace the default Ubuntu terminal with Git-bash(look and behavior) of Window? Basically, the terminal should display all the necessary information related with current branch/repo, just like it does in Window. </p> <p>I am us...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,890
bash
# Change Ubuntu terminal to look like Git-bash of Window Is there a way to change/replace the default Ubuntu terminal with Git-bash(look and behavior) of Window? Basically, the terminal should display all the necessary information related with current branch/repo, just like it does in Window. I am using VS Code and h...
After **@kostix** suggestion, I searched the internet with proper key-words and found [this question thread](https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt) and then finally to [this page](https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt). After trying a...
37045169
Powershell Scheduled Task "Delay task for" option
8
2016-05-05 07:42:04
<p>I need to create Task Schedule with "Delay task for" option for 1 min. I can see PowerShell cmdlet New-ScheduledTaskTrigger has an option -RandomDelay, but I don't think it's valid. I can't see another option in Documentation either (<a href="https://technet.microsoft.com/en-us/library/jj649816(v=wps.630).aspx" rel=...
20,565
6,294,429
2022-09-10 19:41:10
50,759,453
12
2018-06-08 11:16:16
9,913,725
2018-06-08 11:28:18
https://stackoverflow.com/q/37045169
https://stackoverflow.com/a/50759453
<p>Just add this part:</p> <pre><code>$T.Delay = 'PT1M' </code></pre>
<p>Just add this part:</p> <pre><code>$T.Delay = 'PT1M' </code></pre>
526
powershell
<h1>Powershell Scheduled Task "Delay task for" option</h1> <p>I need to create Task Schedule with "Delay task for" option for 1 min. I can see PowerShell cmdlet New-ScheduledTaskTrigger has an option -RandomDelay, but I don't think it's valid. I can't see another option in Documentation either (<a href="https://technet...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,891
bash
# Powershell Scheduled Task "Delay task for" option I need to create Task Schedule with "Delay task for" option for 1 min. I can see PowerShell cmdlet New-ScheduledTaskTrigger has an option -RandomDelay, but I don't think it's valid. I can't see another option in Documentation either (<https://technet.microsoft.com/en...
Just add this part: ``` $T.Delay = 'PT1M' ```
48998395
The best way to check that we have require version software in bash script
8
2018-02-26 22:52:00
<p>Which the best way to check that we have minimum require version software in bash script. E.g. git 2.16.2</p>
3,176
8,600,145
2022-09-21 17:54:17
48,998,537
12
2018-02-26 23:06:03
3,030,305
2022-08-23 21:27:14
https://stackoverflow.com/q/48998395
https://stackoverflow.com/a/48998537
<p><code>git</code> provides its version info like this:</p> <pre><code>$ git --version git version 2.11.0 </code></pre> <p>GNU <code>sort</code> understands version numbers and can sort them:</p> <pre><code>$ (echo min version 2.16.3; git --version) | sort -Vk3 git version 2.11.0 min version 2.16.3 $ (echo min version...
<p><code>git</code> provides its version info like this:</p> <pre><code>$ git --version git version 2.11.0 </code></pre> <p>GNU <code>sort</code> understands version numbers and can sort them:</p> <pre><code>$ (echo min version 2.16.3; git --version) | sort -Vk3 git version 2.11.0 min version 2.16.3 $ (echo min version...
387
bash
<h1>The best way to check that we have require version software in bash script</h1> <p>Which the best way to check that we have minimum require version software in bash script. E.g. git 2.16.2</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,892
bash
# The best way to check that we have require version software in bash script Which the best way to check that we have minimum require version software in bash script. E.g. git 2.16.2
`git` provides its version info like this: ``` $ git --version git version 2.11.0 ``` GNU `sort` understands version numbers and can sort them: ``` $ (echo min version 2.16.3; git --version) | sort -Vk3 git version 2.11.0 min version 2.16.3 $ (echo min version 2.9.3; git --version) | sort -Vk3 min version 2.9.3 git ...
47692263
How to do a specific action on the first iteration of a while loop in a bash script
8
2017-12-07 09:57:21
<p>I need to make a script do a specific action on first loop iteration.</p> <pre><code>for file in /path/to/files/*; do echo "${file}" done </code></pre> <p>I want this output:</p> <pre><code>First run: file1 file2 file3 file4 ... </code></pre>
5,774
9,053,600
2024-07-29 09:45:30
47,693,363
12
2017-12-07 10:51:20
874,188
2024-07-29 09:45:30
https://stackoverflow.com/q/47692263
https://stackoverflow.com/a/47693363
<p>A very common arrangement is to change a variable inside the loop.</p> <pre><code>noise='First run: ' for file in /path/to/files/*; do echo &quot;$noise$file&quot; noise='' done </code></pre> <p>Here's a variation using a <a href="https://www.gnu.org/s/bash/manual/html_node/Shell-Parameter-Expansion.html" re...
<p>A very common arrangement is to change a variable inside the loop.</p> <pre><code>noise='First run: ' for file in /path/to/files/*; do echo &quot;$noise$file&quot; noise='' done </code></pre> <p>Here's a variation using a <a href="https://www.gnu.org/s/bash/manual/html_node/Shell-Parameter-Expansion.html" re...
58, 387
bash, linux
<h1>How to do a specific action on the first iteration of a while loop in a bash script</h1> <p>I need to make a script do a specific action on first loop iteration.</p> <pre><code>for file in /path/to/files/*; do echo "${file}" done </code></pre> <p>I want this output:</p> <pre><code>First run: file1 file2 file...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,893
bash
# How to do a specific action on the first iteration of a while loop in a bash script I need to make a script do a specific action on first loop iteration. ``` for file in /path/to/files/*; do echo "${file}" done ``` I want this output: ``` First run: file1 file2 file3 file4 ... ```
A very common arrangement is to change a variable inside the loop. ``` noise='First run: ' for file in /path/to/files/*; do echo "$noise$file" noise='' done ``` Here's a variation using a [parameter expansion](https://www.gnu.org/s/bash/manual/html_node/Shell-Parameter-Expansion.html): ``` first="trve" for f...
47228304
How do we get a drive by its label in PowerShell 5.0?
8
2017-11-10 17:36:38
<p>I have an <code>autorun.inf</code> file with the following contents on my external hard drive:</p> <pre><code>[Autorun] Label=MasterSword </code></pre> <p>This labels my external hard drive once it's plugged in as, <code>MasterSword</code>. I want to store a few scripts on it and include them in my <code>$profile<...
16,423
3,605,159
2020-03-30 22:01:47
47,228,643
12
2017-11-10 18:00:30
3,605,159
2020-03-30 22:01:47
https://stackoverflow.com/q/47228304
https://stackoverflow.com/a/47228643
<p>I did a little more research and came up with this little snippet:</p> <p>To answer #1:</p> <pre><code>$scriptDrive = Get-Volume -FileSystemLabel MasterSword </code></pre> <p>To answer #2:</p> <pre><code>$scriptDriveLetter = $scriptDrive.DriveLetter </code></pre> <p>And together, they would be:</p> <pre><code>...
<p>I did a little more research and came up with this little snippet:</p> <p>To answer #1:</p> <pre><code>$scriptDrive = Get-Volume -FileSystemLabel MasterSword </code></pre> <p>To answer #2:</p> <pre><code>$scriptDriveLetter = $scriptDrive.DriveLetter </code></pre> <p>And together, they would be:</p> <pre><code>...
64, 526, 108010
powershell, powershell-5.0, windows
<h1>How do we get a drive by its label in PowerShell 5.0?</h1> <p>I have an <code>autorun.inf</code> file with the following contents on my external hard drive:</p> <pre><code>[Autorun] Label=MasterSword </code></pre> <p>This labels my external hard drive once it's plugged in as, <code>MasterSword</code>. 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
10,894
bash
# How do we get a drive by its label in PowerShell 5.0? I have an `autorun.inf` file with the following contents on my external hard drive: ``` [Autorun] Label=MasterSword ``` This labels my external hard drive once it's plugged in as, `MasterSword`. I want to store a few scripts on it and include them in my `$profi...
I did a little more research and came up with this little snippet: To answer #1: ``` $scriptDrive = Get-Volume -FileSystemLabel MasterSword ``` To answer #2: ``` $scriptDriveLetter = $scriptDrive.DriveLetter ``` And together, they would be: ``` $scriptDrive = Get-Volume -FileSystemLabel MasterSword $scriptDriveLe...
45481962
Adding to a datetime
8
2017-08-03 10:43:53
<p>Forgive me if it's already been asked here somewhere, but I couldn't find it, but here goes.</p> <p>In a log file I have, there's a time at which the values were logged and the time is written in <code>HH:mm:ss</code>.</p> <p>I need to parse multiple rows of that file, and so far the only way I can do that it adds...
13,486
4,550,628
2017-08-03 13:56:24
45,482,262
12
2017-08-03 10:58:59
1,630,171
2017-08-03 13:56:24
https://stackoverflow.com/q/45481962
https://stackoverflow.com/a/45482262
<p><a href="https://msdn.microsoft.com/en-us/library/system.datetime.aspx" rel="noreferrer"><code>DateTime</code></a> objects have methods to add seconds, minutes, hours, days, etc.</p> <pre><code>$a.AddMinutes(5) </code></pre> <p>The same methods can be used to subtract time from a timestamp by adding a negative val...
<p><a href="https://msdn.microsoft.com/en-us/library/system.datetime.aspx" rel="noreferrer"><code>DateTime</code></a> objects have methods to add seconds, minutes, hours, days, etc.</p> <pre><code>$a.AddMinutes(5) </code></pre> <p>The same methods can be used to subtract time from a timestamp by adding a negative val...
526, 1263
datetime, powershell
<h1>Adding to a datetime</h1> <p>Forgive me if it's already been asked here somewhere, but I couldn't find it, but here goes.</p> <p>In a log file I have, there's a time at which the values were logged and the time is written in <code>HH:mm:ss</code>.</p> <p>I need to parse multiple rows of that file, and so far the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,895
bash
# Adding to a datetime Forgive me if it's already been asked here somewhere, but I couldn't find it, but here goes. In a log file I have, there's a time at which the values were logged and the time is written in `HH:mm:ss`. I need to parse multiple rows of that file, and so far the only way I can do that it adds a f...
[`DateTime`](https://msdn.microsoft.com/en-us/library/system.datetime.aspx) objects have methods to add seconds, minutes, hours, days, etc. ``` $a.AddMinutes(5) ``` The same methods can be used to subtract time from a timestamp by adding a negative value: ``` $a.AddMinutes(-5) ``` The output format can be defined e...
44871264
How can I measure the window height (number of lines) in powershell?
8
2017-07-02 13:21:44
<p>The maximum number of lines in my environment is 47.</p> <p>Can I measure this value programmatically?</p>
3,169
2,049,426
2022-07-20 20:15:54
44,872,079
12
2017-07-02 14:52:26
45,375
2022-06-22 13:11:08
https://stackoverflow.com/q/44871264
https://stackoverflow.com/a/44872079
<p>To complement <a href="https://stackoverflow.com/a/44871337/45375">Christian.K's helpful answer</a>:</p> <ul> <li><p>A simpler and slightly more efficient method for obtaining the host object is to <strong>use the <code>$Host</code> <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powers...
<p>To complement <a href="https://stackoverflow.com/a/44871337/45375">Christian.K's helpful answer</a>:</p> <ul> <li><p>A simpler and slightly more efficient method for obtaining the host object is to <strong>use the <code>$Host</code> <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powers...
526, 22864, 40232
powershell, powershell-ise, windows-console
<h1>How can I measure the window height (number of lines) in powershell?</h1> <p>The maximum number of lines in my environment is 47.</p> <p>Can I measure this value programmatically?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,896
bash
# How can I measure the window height (number of lines) in powershell? The maximum number of lines in my environment is 47. Can I measure this value programmatically?
To complement [Christian.K's helpful answer](https://stackoverflow.com/a/44871337/45375): - A simpler and slightly more efficient method for obtaining the host object is to **use the `$Host` [automatic variable](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_v...
44524643
What does grep -Po '...\K...' do? How else can that effect be achieved?
8
2017-06-13 14:39:57
<p>I have this script <code>script.sh</code>:</p> <pre><code>#!/bin/bash file_path=$1 result=$(grep -Po 'value="\K.*?(?=")' $file_path) echo $result </code></pre> <p>and this file <code>text.txt</code>:</p> <pre><code>value="a" value="b" value="c" </code></pre> <p>When I run <code>./script.sh /file/directory/text.t...
14,248
7,971,026
2017-06-13 15:31:36
44,524,845
12
2017-06-13 14:48:00
14,122
2017-06-13 15:31:36
https://stackoverflow.com/q/44524643
https://stackoverflow.com/a/44524845
<ul> <li><code>grep -P</code> enables PCRE syntax. (This is a non-standard extension -- not even all builds of GNU grep support it, as it depends on the optional libpcre library, and whether to link this in is a compile-time option).</li> <li><code>grep -o</code> emits only matched text, and not the entire line contain...
<ul> <li><code>grep -P</code> enables PCRE syntax. (This is a non-standard extension -- not even all builds of GNU grep support it, as it depends on the optional libpcre library, and whether to link this in is a compile-time option).</li> <li><code>grep -o</code> emits only matched text, and not the entire line contain...
58, 387, 390
bash, linux, shell
<h1>What does grep -Po '...\K...' do? How else can that effect be achieved?</h1> <p>I have this script <code>script.sh</code>:</p> <pre><code>#!/bin/bash file_path=$1 result=$(grep -Po 'value="\K.*?(?=")' $file_path) echo $result </code></pre> <p>and this file <code>text.txt</code>:</p> <pre><code>value="a" value="b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,897
bash
# What does grep -Po '...\K...' do? How else can that effect be achieved? I have this script `script.sh`: ``` #!/bin/bash file_path=$1 result=$(grep -Po 'value="\K.*?(?=")' $file_path) echo $result ``` and this file `text.txt`: ``` value="a" value="b" value="c" ``` When I run `./script.sh /file/directory/text.txt`...
- `grep -P` enables PCRE syntax. (This is a non-standard extension -- not even all builds of GNU grep support it, as it depends on the optional libpcre library, and whether to link this in is a compile-time option). - `grep -o` emits only matched text, and not the entire line containing said text, in output. (This too ...
44099564
multi-line commands in Julia
8
2017-05-21 17:05:02
<p>You can run commands in Julia using the following syntax:</p> <pre><code>run(`echo 123`) </code></pre> <p>How can I easily run a long command with multiple arguments? It is convenient to split it up over multiple lines for readability purposes. Can I do this in Julia?</p>
14,416
130,111
2017-11-12 15:55:15
44,099,758
12
2017-05-21 17:26:10
6,172,490
2017-05-21 17:26:10
https://stackoverflow.com/q/44099564
https://stackoverflow.com/a/44099758
<p>Julia automatically continues parsing in the next line if the current expression is incomplete, e.g., </p> <pre><code>julia&gt; 1 + 2 3 </code></pre> <p>Therefore, you can simply do</p> <pre><code>julia&gt; run(` echo 123 345 678 `) 123 345 678 </code></p...
<p>Julia automatically continues parsing in the next line if the current expression is incomplete, e.g., </p> <pre><code>julia&gt; 1 + 2 3 </code></pre> <p>Therefore, you can simply do</p> <pre><code>julia&gt; run(` echo 123 345 678 `) 123 345 678 </code></p...
390, 77929
julia, shell
<h1>multi-line commands in Julia</h1> <p>You can run commands in Julia using the following syntax:</p> <pre><code>run(`echo 123`) </code></pre> <p>How can I easily run a long command with multiple arguments? It is convenient to split it up over multiple lines for readability purposes. Can I do this in Julia?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,898
bash
# multi-line commands in Julia You can run commands in Julia using the following syntax: ``` run(`echo 123`) ``` How can I easily run a long command with multiple arguments? It is convenient to split it up over multiple lines for readability purposes. Can I do this in Julia?
Julia automatically continues parsing in the next line if the current expression is incomplete, e.g., ``` julia> 1 + 2 3 ``` Therefore, you can simply do ``` julia> run(` echo 123 345 678 `) 123 345 678 ```
38584428
Security Warning when running scripts - Unblock-File not unblocking file
8
2016-07-26 08:11:32
<p>I suddenly started to recceive this warning when running any script on my computer:</p> <blockquote> <p>Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer...</p> </blockquote> <p>Screenshot:</p> <p><a href="https://i.sstatic.net/zP1UC.p...
28,505
6,135,048
2024-09-26 17:49:27
43,395,217
12
2017-04-13 14:38:46
4,102,857
2018-09-26 16:06:52
https://stackoverflow.com/q/38584428
https://stackoverflow.com/a/43395217
<p>After searching i found someone with similar issues and it was explained that Classic UNC paths will work without prompting to unblock the file:</p> <pre><code>\\Servername\Path... </code></pre> <p>However FQDN paths are not seen as safe by default and will prompt:</p> <pre><code>\\Servername.foo.local\Path... </...
<p>After searching i found someone with similar issues and it was explained that Classic UNC paths will work without prompting to unblock the file:</p> <pre><code>\\Servername\Path... </code></pre> <p>However FQDN paths are not seen as safe by default and will prompt:</p> <pre><code>\\Servername.foo.local\Path... </...
136, 526, 22864
powershell, powershell-ise, security
<h1>Security Warning when running scripts - Unblock-File not unblocking file</h1> <p>I suddenly started to recceive this warning when running any script on my computer:</p> <blockquote> <p>Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer.....
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,899
bash
# Security Warning when running scripts - Unblock-File not unblocking file I suddenly started to recceive this warning when running any script on my computer: > Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer... Screenshot: [![Powershell...
After searching i found someone with similar issues and it was explained that Classic UNC paths will work without prompting to unblock the file: ``` \\Servername\Path... ``` However FQDN paths are not seen as safe by default and will prompt: ``` \\Servername.foo.local\Path... ``` My own testing confirms this to be ...
43163225
Word splitting in Bash with IFS set to a non-whitespace character
8
2017-04-01 23:54:10
<p>I'm going through a Bash <a href="http://mywiki.wooledge.org/WordSplitting" rel="nofollow noreferrer">tutorial</a>, and specifically the subject of word splitting.</p> <p>This script, called "args", helps demonstrate word splitting examples:</p> <pre><code>#!/usr/bin/env bash printf "%d args:" $# printf " &lt;%s&g...
2,395
6,104,999
2020-12-30 07:55:51
43,163,356
12
2017-04-02 00:20:38
6,862,601
2018-05-24 22:33:20
https://stackoverflow.com/q/43163225
https://stackoverflow.com/a/43163356
<p>You can read more about word splitting <a href="https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html" rel="nofollow noreferrer">here</a>.</p> <blockquote> <p>The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quot...
<p>You can read more about word splitting <a href="https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html" rel="nofollow noreferrer">here</a>.</p> <blockquote> <p>The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quot...
367, 387, 390, 19749, 26793
bash, ifs, shell, syntax, variable-expansion
<h1>Word splitting in Bash with IFS set to a non-whitespace character</h1> <p>I'm going through a Bash <a href="http://mywiki.wooledge.org/WordSplitting" rel="nofollow noreferrer">tutorial</a>, and specifically the subject of word splitting.</p> <p>This script, called "args", helps demonstrate word splitting examples:...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,900
bash
# Word splitting in Bash with IFS set to a non-whitespace character I'm going through a Bash [tutorial](http://mywiki.wooledge.org/WordSplitting), and specifically the subject of word splitting. This script, called "args", helps demonstrate word splitting examples: ``` #!/usr/bin/env bash printf "%d args:" $# printf...
You can read more about word splitting [here](https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html). > The shell scans the results of parameter expansion, command substitution, > and arithmetic expansion that did not occur within double quotes for word splitting. When you pass the bare string `one:t...
41578517
Unary "Not" or bit-flip operator in PowerShell?
8
2017-01-10 21:13:24
<p>I have a decimal value 163 that I need to do a unary "not" operation on. In C++ and Java, this would look like <code>~(163)</code>. Essentially, I want every bit to flip.</p> <p>Is there a way to do this in PowerShell using a unary operator or, if needed, a subroutine? I would also need this to flip all the bits of...
2,650
4,081,647
2022-06-07 23:01:34
41,578,654
12
2017-01-10 21:22:35
3,905,079
2022-06-07 23:01:34
https://stackoverflow.com/q/41578517
https://stackoverflow.com/a/41578654
<p>As Bill_Stewart commented, <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.2#bitwise-operators" rel="nofollow noreferrer">the <code>-bnot</code> (binary not or bitwise not) operator</a> does what you want. It works in PowerShel...
<p>As Bill_Stewart commented, <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.2#bitwise-operators" rel="nofollow noreferrer">the <code>-bnot</code> (binary not or bitwise not) operator</a> does what you want. It works in PowerShel...
526, 4088, 14515, 24067
bit, bit-manipulation, powershell, powershell-2.0
<h1>Unary "Not" or bit-flip operator in PowerShell?</h1> <p>I have a decimal value 163 that I need to do a unary "not" operation on. In C++ and Java, this would look like <code>~(163)</code>. Essentially, I want every bit to flip.</p> <p>Is there a way to do this in PowerShell using a unary operator or, if needed, a s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,901
bash
# Unary "Not" or bit-flip operator in PowerShell? I have a decimal value 163 that I need to do a unary "not" operation on. In C++ and Java, this would look like `~(163)`. Essentially, I want every bit to flip. Is there a way to do this in PowerShell using a unary operator or, if needed, a subroutine? I would also nee...
As Bill_Stewart commented, [the `-bnot` (binary not or bitwise not) operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.2#bitwise-operators) does what you want. It works in PowerShell 2.0. Just be aware that PowerShell's default int...
37995856
Passing PSRemotingJob Object as Parameter in Powershell 4.0
8
2016-06-23 15:26:02
<p>I'm writing a Powershell Cmdlet for which I need to pass in a <code>PSRemotingJob</code> object as a parameter. The <a href="https://stackoverflow.com/help/mcve">MCVE</a> follows:</p> <pre><code>function My-Cmdlet { [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$true,...
2,158
1,843,248
2016-10-14 17:32:52
40,048,930
12
2016-10-14 17:32:52
4,003,407
2016-10-14 17:32:52
https://stackoverflow.com/q/37995856
https://stackoverflow.com/a/40048930
<p><code>System.Management.Automation.PSRemotingJob</code> is not public type and thus can not be expressed in PowerShell type syntax. But you can use its base public type instead: <code>[System.Management.Automation.Job]</code>.</p>
<p><code>System.Management.Automation.PSRemotingJob</code> is not public type and thus can not be expressed in PowerShell type syntax. But you can use its base public type instead: <code>[System.Management.Automation.Job]</code>.</p>
526
powershell
<h1>Passing PSRemotingJob Object as Parameter in Powershell 4.0</h1> <p>I'm writing a Powershell Cmdlet for which I need to pass in a <code>PSRemotingJob</code> object as a parameter. The <a href="https://stackoverflow.com/help/mcve">MCVE</a> follows:</p> <pre><code>function My-Cmdlet { [CmdletBinding()] Para...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,902
bash
# Passing PSRemotingJob Object as Parameter in Powershell 4.0 I'm writing a Powershell Cmdlet for which I need to pass in a `PSRemotingJob` object as a parameter. The [MCVE](https://stackoverflow.com/help/mcve) follows: ``` function My-Cmdlet { [CmdletBinding()] Param( [Parameter(Position=0, ...
`System.Management.Automation.PSRemotingJob` is not public type and thus can not be expressed in PowerShell type syntax. But you can use its base public type instead: `[System.Management.Automation.Job]`.
38959114
Unshift array element in Bash script
8
2016-08-15 16:33:49
<p>I would like to add elements to the beginning of an array instead of to the end. Is this possible in Bash?</p>
5,411
5,743,764
2024-04-19 18:21:05
38,959,226
12
2016-08-15 16:41:20
2,302,862
2016-08-15 18:00:16
https://stackoverflow.com/q/38959114
https://stackoverflow.com/a/38959226
<p>If your array is contiguous, you can use the <code>"${array[@]}"</code> syntax to construct a new array:</p> <pre><code>array=('a' 'b' 'c'); echo "${array[@]}"; # prints: a b c array=('d' "${array[@]}"); echo "${array[@]}"; # prints: d a b c </code></pre> <p>As <a href="https://stackoverflow.com/questions/38959114...
<p>If your array is contiguous, you can use the <code>"${array[@]}"</code> syntax to construct a new array:</p> <pre><code>array=('a' 'b' 'c'); echo "${array[@]}"; # prints: a b c array=('d' "${array[@]}"); echo "${array[@]}"; # prints: d a b c </code></pre> <p>As <a href="https://stackoverflow.com/questions/38959114...
114, 387, 390
arrays, bash, shell
<h1>Unshift array element in Bash script</h1> <p>I would like to add elements to the beginning of an array instead of to the end. Is this possible in Bash?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,903
bash
# Unshift array element in Bash script I would like to add elements to the beginning of an array instead of to the end. Is this possible in Bash?
If your array is contiguous, you can use the `"${array[@]}"` syntax to construct a new array: ``` array=('a' 'b' 'c'); echo "${array[@]}"; # prints: a b c array=('d' "${array[@]}"); echo "${array[@]}"; # prints: d a b c ``` As [chepner mentions](https://stackoverflow.com/questions/38959114/unshift-array-element-in-ba...
38843212
how to use echo with find in bash?
8
2016-08-09 06:06:31
<p>I have 10 files. I can list them with <code>find . -type f</code> and what I am trying to achieve is sending a message to all 10 files after finding them with find command. </p> <p>What I have tried, <code>find . -type f -exec echo "This file found" &gt;&gt; {} \;</code></p> <p>May be logically I am right but its ...
16,214
1,293,013
2016-08-09 06:16:55
38,843,259
12
2016-08-09 06:09:51
3,789,550
2016-08-09 06:15:19
https://stackoverflow.com/q/38843212
https://stackoverflow.com/a/38843259
<p>The shell redirection, <code>&gt;&gt;</code> is being done at first, a file named <code>{}</code> is being created before even the <code>find</code> starts and the strings (the number of files are in there) are being written to the file <code>{}</code>.</p> <p>You need:</p> <pre><code>find . -type f -exec bash -c ...
<p>The shell redirection, <code>&gt;&gt;</code> is being done at first, a file named <code>{}</code> is being created before even the <code>find</code> starts and the strings (the number of files are in there) are being written to the file <code>{}</code>.</p> <p>You need:</p> <pre><code>find . -type f -exec bash -c ...
387, 10193
bash, find
<h1>how to use echo with find in bash?</h1> <p>I have 10 files. I can list them with <code>find . -type f</code> and what I am trying to achieve is sending a message to all 10 files after finding them with find command. </p> <p>What I have tried, <code>find . -type f -exec echo "This file found" &gt;&gt; {} \;</code><...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,904
bash
# how to use echo with find in bash? I have 10 files. I can list them with `find . -type f` and what I am trying to achieve is sending a message to all 10 files after finding them with find command. What I have tried, `find . -type f -exec echo "This file found" >> {} \;` May be logically I am right but its not work...
The shell redirection, `>>` is being done at first, a file named `{}` is being created before even the `find` starts and the strings (the number of files are in there) are being written to the file `{}`. You need: ``` find . -type f -exec bash -c 'echo "This file found" >>"$1"' _ {} \; ```
38403090
Difference between x | y and y <(x) in bash?
8
2016-07-15 18:40:18
<p>Is there a difference between <code>command1 | command2</code> and <code>command2 &lt;(command1)</code>?</p> <p>For example, <code>git diff | more</code> vs <code>more &lt;(git diff)</code></p> <p>My understanding is that both take the stdout of <code>command2</code> and pipe it to the stdin of <code>command1</cod...
150
2,874,789
2016-07-16 15:19:14
38,403,153
12
2016-07-15 18:44:40
797,049
2016-07-16 15:19:14
https://stackoverflow.com/q/38403090
https://stackoverflow.com/a/38403153
<p>The main difference is that <code>&lt;(</code>...<code>)</code>, called "process substitution", is translated by the shell into a filename that is passed as a regular argument to the command; it doesn't send anything to the command's standard input. This means that it can't be used directly with commands such as <co...
<p>The main difference is that <code>&lt;(</code>...<code>)</code>, called "process substitution", is translated by the shell into a filename that is passed as a regular argument to the command; it doesn't send anything to the command's standard input. This means that it can't be used directly with commands such as <co...
387, 5813
bash, pipe
<h1>Difference between x | y and y <(x) in bash?</h1> <p>Is there a difference between <code>command1 | command2</code> and <code>command2 &lt;(command1)</code>?</p> <p>For example, <code>git diff | more</code> vs <code>more &lt;(git diff)</code></p> <p>My understanding is that both take the stdout of <code>command2<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,905
bash
# Difference between x | y and y <(x) in bash? Is there a difference between `command1 | command2` and `command2 <(command1)`? For example, `git diff | more` vs `more <(git diff)` My understanding is that both take the stdout of `command2` and pipe it to the stdin of `command1`.
The main difference is that `<(`...`)`, called "process substitution", is translated by the shell into a filename that is passed as a regular argument to the command; it doesn't send anything to the command's standard input. This means that it can't be used directly with commands such as `tr` which don't take a filenam...
37954868
How can I split my screen in 3 using tmux from a bash script
8
2016-06-21 21:26:43
<p>I'm writing a bash script that splits the screen in 3 and runs a command on each pane.</p> <p>I basically want to run the bash script and the bash script is supposed to split my screen in 3, and run top in a pane, htop in the other pane and a perl re.pl in the third pane for example</p> <p>any help or pointers are...
11,575
2,348,668
2024-04-02 02:59:55
37,979,685
12
2016-06-22 23:10:33
1,126,841
2016-06-22 23:10:33
https://stackoverflow.com/q/37954868
https://stackoverflow.com/a/37979685
<p>The direct way to do this is to create a detached session, create the panes, <em>then</em> attach to the session.</p> <pre><code># -d says not to attach to the session yet. top runs in the first # window tmux new-session -d top # In the most recently created session, split the (only) window # and run htop in the ne...
<p>The direct way to do this is to create a detached session, create the panes, <em>then</em> attach to the session.</p> <pre><code># -d says not to attach to the session yet. top runs in the first # window tmux new-session -d top # In the most recently created session, split the (only) window # and run htop in the ne...
58, 387, 60238
bash, linux, tmux
<h1>How can I split my screen in 3 using tmux from a bash script</h1> <p>I'm writing a bash script that splits the screen in 3 and runs a command on each pane.</p> <p>I basically want to run the bash script and the bash script is supposed to split my screen in 3, and run top in a pane, htop in the other pane and a per...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,906
bash
# How can I split my screen in 3 using tmux from a bash script I'm writing a bash script that splits the screen in 3 and runs a command on each pane. I basically want to run the bash script and the bash script is supposed to split my screen in 3, and run top in a pane, htop in the other pane and a perl re.pl in the t...
The direct way to do this is to create a detached session, create the panes, *then* attach to the session. ``` # -d says not to attach to the session yet. top runs in the first # window tmux new-session -d top # In the most recently created session, split the (only) window # and run htop in the new pane tmux split-win...
37367841
bash: How to add space in string?
8
2016-05-21 20:48:59
<p>I have a string like this:</p> <pre><code>string="aaa-bbb" </code></pre> <p>But I want to add space before char '-', so I want this:</p> <pre><code>aaa -bbb </code></pre> <p>I tried a lot of things, but I can't add space there. I tried with <code>echo $string | tr '-' ' -'</code>, and some other stuff, but it di...
64,559
6,244,712
2023-01-05 20:59:11
37,367,908
12
2016-05-21 20:55:41
1,426,891
2016-05-22 03:44:41
https://stackoverflow.com/q/37367841
https://stackoverflow.com/a/37367908
<p>No need to call <code>sed</code>, use <a href="http://wiki.bash-hackers.org/syntax/pe#search_and_replace" rel="noreferrer">string substitution</a> native in BASH:</p> <pre><code>$ foo="abc-def-ghi" $ echo "${foo//-/ -}" abc -def -ghi </code></pre> <p>Note the <em>two slashes</em> after the variable name: the first...
<p>No need to call <code>sed</code>, use <a href="http://wiki.bash-hackers.org/syntax/pe#search_and_replace" rel="noreferrer">string substitution</a> native in BASH:</p> <pre><code>$ foo="abc-def-ghi" $ echo "${foo//-/ -}" abc -def -ghi </code></pre> <p>Note the <em>two slashes</em> after the variable name: the first...
139, 387, 5162
bash, spaces, string
<h1>bash: How to add space in string?</h1> <p>I have a string like this:</p> <pre><code>string="aaa-bbb" </code></pre> <p>But I want to add space before char '-', so I want this:</p> <pre><code>aaa -bbb </code></pre> <p>I tried a lot of things, but I can't add space there. I tried with <code>echo $string | tr '-' '...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,907
bash
# bash: How to add space in string? I have a string like this: ``` string="aaa-bbb" ``` But I want to add space before char '-', so I want this: ``` aaa -bbb ``` I tried a lot of things, but I can't add space there. I tried with `echo $string | tr '-' ' -'`, and some other stuff, but it didn't work... I have Linu...
No need to call `sed`, use [string substitution](http://wiki.bash-hackers.org/syntax/pe#search_and_replace) native in BASH: ``` $ foo="abc-def-ghi" $ echo "${foo//-/ -}" abc -def -ghi ``` Note the *two slashes* after the variable name: the first slash replaces the first occurrence, where two slashes replace every occ...
37094195
Combine several files, with a separator, into one file
8
2016-05-07 22:05:21
<p>I have several (~300,000) files of individual JSON objects that I want to combine into a single file that is a JSON array. How can I do this on linux assuming they are all in the location "~/data_files"?</p> <p><strong>FileA</strong></p> <pre><code>{ name: "Test", age: 23 } </code></pre> <p><strong>FileB</st...
4,307
1,001,938
2020-01-23 05:56:10
37,094,923
12
2016-05-08 00:10:46
6,170,930
2019-05-19 13:03:11
https://stackoverflow.com/q/37094195
https://stackoverflow.com/a/37094923
<p>Since you seem a little new to unix I'll try to give you a solution that is simple and doesn't introduce too many new concepts. I'll leave clever and novel to the other posters. This solution will be <em>very</em> efficient since all I'm doing is streaming files into files.<br></p> <p>To start with we will create a...
<p>Since you seem a little new to unix I'll try to give you a solution that is simple and doesn't introduce too many new concepts. I'll leave clever and novel to the other posters. This solution will be <em>very</em> efficient since all I'm doing is streaming files into files.<br></p> <p>To start with we will create a...
58, 390, 1508, 22820
cat, json, linux, shell
<h1>Combine several files, with a separator, into one file</h1> <p>I have several (~300,000) files of individual JSON objects that I want to combine into a single file that is a JSON array. How can I do this on linux assuming they are all in the location "~/data_files"?</p> <p><strong>FileA</strong></p> <pre><code>{...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,908
bash
# Combine several files, with a separator, into one file I have several (~300,000) files of individual JSON objects that I want to combine into a single file that is a JSON array. How can I do this on linux assuming they are all in the location "~/data_files"? **FileA** ``` { name: "Test", age: 23 } ``` **FileB...
Since you seem a little new to unix I'll try to give you a solution that is simple and doesn't introduce too many new concepts. I'll leave clever and novel to the other posters. This solution will be *very* efficient since all I'm doing is streaming files into files. To start with we will create a new file in our home...
34912289
Case statement with extglob
8
2016-01-20 22:59:49
<p>With <em>extglob</em> on, I want to match a variable against </p> <pre><code>*( )x* </code></pre> <p>(In regex: <code>/^ *x.*/</code>)</p> <p>This:</p> <pre><code>main(){ shopt -s extglob local line=' x bar' case "$line" in *( )x*) ;; *) ;; esac } main "$@" </code></pre> <p>is giving me a syntax...
1,679
1,084,774
2016-01-21 01:08:54
34,913,651
12
2016-01-21 01:08:54
89,817
2016-01-21 01:08:54
https://stackoverflow.com/q/34912289
https://stackoverflow.com/a/34913651
<p>bash has to parse the function in order to create it, and since the extended glob syntax you're using would normally be invalid, it can't parse the function unless extglob is on <em>when the function is created</em>.</p> <p>Net result: extglob has to be on both when the function is declared <em>and</em> when it run...
<p>bash has to parse the function in order to create it, and since the extended glob syntax you're using would normally be invalid, it can't parse the function unless extglob is on <em>when the function is created</em>.</p> <p>Net result: extglob has to be on both when the function is declared <em>and</em> when it run...
387
bash
<h1>Case statement with extglob</h1> <p>With <em>extglob</em> on, I want to match a variable against </p> <pre><code>*( )x* </code></pre> <p>(In regex: <code>/^ *x.*/</code>)</p> <p>This:</p> <pre><code>main(){ shopt -s extglob local line=' x bar' case "$line" in *( )x*) ;; *) ;; esac } main "$@" </...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,909
bash
# Case statement with extglob With *extglob* on, I want to match a variable against ``` *( )x* ``` (In regex: `/^ *x.*/`) This: ``` main(){ shopt -s extglob local line=' x bar' case "$line" in *( )x*) ;; *) ;; esac } main "$@" ``` is giving me a syntax error. Either removing the extglob parenthese...
bash has to parse the function in order to create it, and since the extended glob syntax you're using would normally be invalid, it can't parse the function unless extglob is on *when the function is created*. Net result: extglob has to be on both when the function is declared *and* when it runs. The `shopt -s extglob...
34786585
PowerShell get weekday name from a date
8
2016-01-14 10:01:49
<p>Using powershell I want to get the week day name (Friday) from a date. Been googling and cant find this one. It so I can do an IF statement to do something if the date is a Friday.</p> <p>Can anyone help?</p>
15,732
2,050,577
2016-01-14 10:12:39
34,786,838
12
2016-01-14 10:12:39
3,122,744
2016-01-14 10:12:39
https://stackoverflow.com/q/34786585
https://stackoverflow.com/a/34786838
<p>Use <code>Get-Date</code> to produce a DateTime object, then call its DayOfWeek method. For example:</p> <pre><code>(get-date 01/01/2016).DayOfWeek </code></pre>
<p>Use <code>Get-Date</code> to produce a DateTime object, then call its DayOfWeek method. For example:</p> <pre><code>(get-date 01/01/2016).DayOfWeek </code></pre>
526
powershell
<h1>PowerShell get weekday name from a date</h1> <p>Using powershell I want to get the week day name (Friday) from a date. Been googling and cant find this one. It so I can do an IF statement to do something if the date is a Friday.</p> <p>Can anyone help?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,910
bash
# PowerShell get weekday name from a date Using powershell I want to get the week day name (Friday) from a date. Been googling and cant find this one. It so I can do an IF statement to do something if the date is a Friday. Can anyone help?
Use `Get-Date` to produce a DateTime object, then call its DayOfWeek method. For example: ``` (get-date 01/01/2016).DayOfWeek ```
34619486
enter-pssession invoke-command, when to use?
8
2016-01-05 19:12:00
<p>I am writing a script to stop and start services in two remote servers. Here's my question,</p> <p>in my script I did new-pssession and used invoke-command to stop and start services.</p> <p>Do I need to use enter-pssession? </p> <p><strong>Updates:</strong> Here's what my script needs to do. </p> <p>on server1...
34,119
3,939,140
2016-01-06 01:00:22
34,623,888
12
2016-01-06 00:49:05
3,337,258
2016-01-06 00:49:05
https://stackoverflow.com/q/34619486
https://stackoverflow.com/a/34623888
<p><code>Enter-PSSession</code> - Since this is an interactive session you type what you want at the console and immediately see the results in the console.(just like CMD). If its just 2 servers then you can use <code>enter-pssession</code> but it is always going to be serial meaning you do something on one server the...
<p><code>Enter-PSSession</code> - Since this is an interactive session you type what you want at the console and immediately see the results in the console.(just like CMD). If its just 2 servers then you can use <code>enter-pssession</code> but it is always going to be serial meaning you do something on one server the...
526, 43391
invoke-command, powershell
<h1>enter-pssession invoke-command, when to use?</h1> <p>I am writing a script to stop and start services in two remote servers. Here's my question,</p> <p>in my script I did new-pssession and used invoke-command to stop and start services.</p> <p>Do I need to use enter-pssession? </p> <p><strong>Updates:</strong> H...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,911
bash
# enter-pssession invoke-command, when to use? I am writing a script to stop and start services in two remote servers. Here's my question, in my script I did new-pssession and used invoke-command to stop and start services. Do I need to use enter-pssession? **Updates:** Here's what my script needs to do. on server...
`Enter-PSSession` - Since this is an interactive session you type what you want at the console and immediately see the results in the console.(just like CMD). If its just 2 servers then you can use `enter-pssession` but it is always going to be serial meaning you do something on one server then you move onto another. ...
33806488
Splitting a large CSV file with the command line
8
2015-11-19 14:21:00
<p>I know OS X supports the Linux-like <code>split</code> command.</p> <p>I have a huge file <code>file.csv</code>.</p> <p>When I run</p> <pre><code>split -l 1000 file.csv new_ </code></pre> <p>I get created one file <code>new_aa</code>, but this file is the same as <code>file.csv</code>. It is not split.</p> <p>When I...
21,435
1,275,959
2021-08-31 15:35:33
33,807,581
12
2015-11-19 15:11:05
1,983,854
2015-11-19 15:11:05
https://stackoverflow.com/q/33806488
https://stackoverflow.com/a/33807581
<p>Your command is just fine:</p> <pre><code>split -l 1000 file.csv new_ </code></pre> <p>However, it seems that you have some encoding problems. When you say <code>file file.csv</code> you get </p> <blockquote> <p>ASCII text, with CR line terminators</p> </blockquote> <p>So what you need is to port this file fro...
<p>Your command is just fine:</p> <pre><code>split -l 1000 file.csv new_ </code></pre> <p>However, it seems that you have some encoding problems. When you say <code>file file.csv</code> you get </p> <blockquote> <p>ASCII text, with CR line terminators</p> </blockquote> <p>So what you need is to port this file fro...
34, 369, 387, 2193
bash, macos, split, unix
<h1>Splitting a large CSV file with the command line</h1> <p>I know OS X supports the Linux-like <code>split</code> command.</p> <p>I have a huge file <code>file.csv</code>.</p> <p>When I run</p> <pre><code>split -l 1000 file.csv new_ </code></pre> <p>I get created one file <code>new_aa</code>, but this file is the sam...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,912
bash
# Splitting a large CSV file with the command line I know OS X supports the Linux-like `split` command. I have a huge file `file.csv`. When I run ``` split -l 1000 file.csv new_ ``` I get created one file `new_aa`, but this file is the same as `file.csv`. It is not split. When I run file file.csv, I get `ASCII te...
Your command is just fine: ``` split -l 1000 file.csv new_ ``` However, it seems that you have some encoding problems. When you say `file file.csv` you get > ASCII text, with CR line terminators So what you need is to port this file from MAC to UNIX. And this can be done with either of these: ``` mac2unix file.csv...
33111227
Why do scripts define common commands in variables?
8
2015-10-13 19:40:36
<p>I see this all the time at my place of work:</p> <pre><code>#!/bin/sh ..... CAT=/usr/bin/cat # An alias for cat MAIL=/usr/bin/mail # An alias for mail WC=/usr/bin/wc # An alias for word count GREP=/usr/bin/grep ...
111
3,412,229
2015-10-14 17:46:55
33,111,599
12
2015-10-13 20:02:41
1,491,895
2015-10-13 20:02:41
https://stackoverflow.com/q/33111227
https://stackoverflow.com/a/33111599
<p>Using the full pathname ensures that the script operates correctly even if it's run by a user who customizes their <code>PATH</code> environment variable so that it finds different versions of these commands than the script expects.</p> <p>Using variables simplifies writing the script, so you don't have to write th...
<p>Using the full pathname ensures that the script operates correctly even if it's run by a user who customizes their <code>PATH</code> environment variable so that it finds different versions of these commands than the script expects.</p> <p>Using variables simplifies writing the script, so you don't have to write th...
387, 390, 10327
bash, sh, shell
<h1>Why do scripts define common commands in variables?</h1> <p>I see this all the time at my place of work:</p> <pre><code>#!/bin/sh ..... CAT=/usr/bin/cat # An alias for cat MAIL=/usr/bin/mail # An alias for mail WC=/usr/bin/wc ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,913
bash
# Why do scripts define common commands in variables? I see this all the time at my place of work: ``` #!/bin/sh ..... CAT=/usr/bin/cat # An alias for cat MAIL=/usr/bin/mail # An alias for mail WC=/usr/bin/wc # An ali...
Using the full pathname ensures that the script operates correctly even if it's run by a user who customizes their `PATH` environment variable so that it finds different versions of these commands than the script expects. Using variables simplifies writing the script, so you don't have to write the full pathname of a ...
32202068
JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths'
8
2015-08-25 10:51:11
<p>I am trying to create a JMeter load test. I need the test to take a sample log file and change its name. The only way I could find to do this was to copy the file in a BeanShell Preprocessor but I am getting the following error: </p> <pre><code>ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: e...
6,866
5,243,809
2015-08-25 10:55:34
32,202,176
12
2015-08-25 10:55:34
22,656
2015-08-25 10:55:34
https://stackoverflow.com/q/32202068
https://stackoverflow.com/a/32202176
<p>My <em>guess</em> is that the problem is that it's not populating the varargs parameter. Try:</p> <pre><code>Path target = Paths.get(filename, new String[0]); </code></pre>
<p>My <em>guess</em> is that the problem is that it's not populating the varargs parameter. Try:</p> <pre><code>Path target = Paths.get(filename, new String[0]); </code></pre>
17, 8401, 13554, 70890
beanshell, java, java.nio.file, jmeter
<h1>JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths'</h1> <p>I am trying to create a JMeter load test. I need the test to take a sample log file and change its name. The only way I could find to do this was to copy the file in a BeanShell Preprocessor but I am getting the following...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,914
bash
# JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths' I am trying to create a JMeter load test. I need the test to take a sample log file and change its name. The only way I could find to do this was to copy the file in a BeanShell Preprocessor but I am getting the following error: ...
My *guess* is that the problem is that it's not populating the varargs parameter. Try: ``` Path target = Paths.get(filename, new String[0]); ```
32129369
How to run a command only if is the master branch in travis-ci?
8
2015-08-20 22:17:55
<p>I have a open-source project and i want to deploy the code just if the code is in the master branch, i already tried many approachs, like:</p> <pre><code>- if [[ $TRAVIS_BRANCH == 'master' ]]; then fab deploy; fi </code></pre> <p>Or something like:</p> <pre><code>BRANCH = "master" def _get_local_branch(): re...
3,446
1,530,565
2017-10-25 14:31:51
32,131,504
12
2015-08-21 02:34:02
213,272
2015-08-21 02:34:02
https://stackoverflow.com/q/32129369
https://stackoverflow.com/a/32131504
<p>I'm not sure why your first approach doesn't work but I would suggest using the <code>deploy:</code> directive in your .travis.yml file with a custom deployment script like this:</p> <pre><code>deploy: provider: script script: scripts/deploy.sh on: branch: master </code></pre> <p>Here is the <a href="htt...
<p>I'm not sure why your first approach doesn't work but I would suggest using the <code>deploy:</code> directive in your .travis.yml file with a custom deployment script like this:</p> <pre><code>deploy: provider: script script: scripts/deploy.sh on: branch: master </code></pre> <p>Here is the <a href="htt...
16, 10327, 42950, 74123
fabric, python, sh, travis-ci
<h1>How to run a command only if is the master branch in travis-ci?</h1> <p>I have a open-source project and i want to deploy the code just if the code is in the master branch, i already tried many approachs, like:</p> <pre><code>- if [[ $TRAVIS_BRANCH == 'master' ]]; then fab deploy; fi </code></pre> <p>Or something...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,915
bash
# How to run a command only if is the master branch in travis-ci? I have a open-source project and i want to deploy the code just if the code is in the master branch, i already tried many approachs, like: ``` - if [[ $TRAVIS_BRANCH == 'master' ]]; then fab deploy; fi ``` Or something like: ``` BRANCH = "master" de...
I'm not sure why your first approach doesn't work but I would suggest using the `deploy:` directive in your .travis.yml file with a custom deployment script like this: ``` deploy: provider: script script: scripts/deploy.sh on: branch: master ``` Here is the [documentation](http://docs.travis-ci.com/user/dep...
32120202
What is $? an alias for in Powershell?
8
2015-08-20 13:54:09
<p>Within a script I was shown today was the line:</p> <pre><code>If ($?) { #do some stuff } </code></pre> <p>I have never seen the dollar sign question mark alias $? before and am unable to ascertain via Google what it is for.</p> <p>When I execute it in a powershell window it typically returns True, however occasi...
1,009
2,796,058
2017-03-07 13:26:33
32,120,260
12
2015-08-20 13:56:42
613,928
2015-08-20 14:23:55
https://stackoverflow.com/q/32120202
https://stackoverflow.com/a/32120260
<p>From <a href="https://technet.microsoft.com/en-us/library/hh847768.aspx">about_automatic_variables</a>:</p> <blockquote> <p>$?<br> Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.</p> </blockquote> <pre><code>Get-Help about_automati...
<p>From <a href="https://technet.microsoft.com/en-us/library/hh847768.aspx">about_automatic_variables</a>:</p> <blockquote> <p>$?<br> Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.</p> </blockquote> <pre><code>Get-Help about_automati...
276, 526, 1448
alias, powershell, variables
<h1>What is $? an alias for in Powershell?</h1> <p>Within a script I was shown today was the line:</p> <pre><code>If ($?) { #do some stuff } </code></pre> <p>I have never seen the dollar sign question mark alias $? before and am unable to ascertain via Google what it is for.</p> <p>When I execute it in a powershell ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,916
bash
# What is $? an alias for in Powershell? Within a script I was shown today was the line: ``` If ($?) { #do some stuff } ``` I have never seen the dollar sign question mark alias $? before and am unable to ascertain via Google what it is for. When I execute it in a powershell window it typically returns True, howeve...
From [about_automatic_variables](https://technet.microsoft.com/en-us/library/hh847768.aspx): > $? > Contains the execution status of the last operation. It contains > TRUE if the last operation succeeded and FALSE if it failed. ``` Get-Help about_automatic_variables ```
29853399
Powershell - Get server name and IP from text list
8
2015-04-24 17:03:07
<p>I am using the following suggestion provided in this link: <a href="http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27722701.html" rel="noreferrer">Experts-Exchange</a></p> <p>I am trying to take a server (host name) list and save the host name and IP address in a .csv file.</p> <p>Usi...
56,138
538,029
2023-09-22 22:33:44
29,854,181
12
2015-04-24 17:46:37
2,690,128
2015-04-24 17:51:50
https://stackoverflow.com/q/29853399
https://stackoverflow.com/a/29854181
<p>Looks like some simple typos at work. </p> <ul> <li>$result was being reset inside the in the loop </li> <li>$addresses inside the loop wasn't assigned.</li> <li>$result.ipaddress was not assigned to $a.IPAddressToString for the output object.</li> </ul> <p>Try this:</p> <pre><code>$servers = get-content "X:\serv...
<p>Looks like some simple typos at work. </p> <ul> <li>$result was being reset inside the in the loop </li> <li>$addresses inside the loop wasn't assigned.</li> <li>$result.ipaddress was not assigned to $a.IPAddressToString for the output object.</li> </ul> <p>Try this:</p> <pre><code>$servers = get-content "X:\serv...
73, 526
csv, powershell
<h1>Powershell - Get server name and IP from text list</h1> <p>I am using the following suggestion provided in this link: <a href="http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27722701.html" rel="noreferrer">Experts-Exchange</a></p> <p>I am trying to take a server (host name) list and s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,917
bash
# Powershell - Get server name and IP from text list I am using the following suggestion provided in this link: [Experts-Exchange](http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27722701.html) I am trying to take a server (host name) list and save the host name and IP address in a .csv f...
Looks like some simple typos at work. - $result was being reset inside the in the loop - $addresses inside the loop wasn't assigned. - $result.ipaddress was not assigned to $a.IPAddressToString for the output object. Try this: ``` $servers = get-content "X:\servers.txt" $serversAndIps ="X:\test.csv" $results = @() ...
28098743
how to pass each shell parameter in new line
8
2015-01-22 21:10:43
<p>I had a shell script that takes 3 parameters</p> <pre><code>test.sh a b c </code></pre> <p>I want to give each parameter in a new line</p> <p>some thing like this :</p> <pre><code>test.sh a b c </code></pre> <p>i am on AIX Thanks.</p>
5,792
2,711,819
2015-01-22 23:54:49
28,098,836
12
2015-01-22 21:16:26
1,387,612
2015-01-22 23:54:49
https://stackoverflow.com/q/28098743
https://stackoverflow.com/a/28098836
<p>Just put <code>\</code> at the end of line, it "escapes" the meaning of the character following it, which in this case is a newline.</p> <pre><code>test.sh a \ b \ c </code></pre>
<p>Just put <code>\</code> at the end of line, it "escapes" the meaning of the character following it, which in this case is a newline.</p> <pre><code>test.sh a \ b \ c </code></pre>
58, 390, 989
aix, linux, shell
<h1>how to pass each shell parameter in new line</h1> <p>I had a shell script that takes 3 parameters</p> <pre><code>test.sh a b c </code></pre> <p>I want to give each parameter in a new line</p> <p>some thing like this :</p> <pre><code>test.sh a b c </code></pre> <p>i am on AIX Thanks.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,918
bash
# how to pass each shell parameter in new line I had a shell script that takes 3 parameters ``` test.sh a b c ``` I want to give each parameter in a new line some thing like this : ``` test.sh a b c ``` i am on AIX Thanks.
Just put `\` at the end of line, it "escapes" the meaning of the character following it, which in this case is a newline. ``` test.sh a \ b \ c ```
26509040
Check the last exit code of a command echoed by a bash script
8
2014-10-22 13:49:53
<pre><code>#!/bin/bash test(){ return 1; } VAR=$(expect -c 'puts &quot;Exiting&quot;; exit 1;'); echo &quot;$VAR&quot;; RETURN_CODE=$?; echo $RETURN_CODE; test RETURN_CODE=$?; echo $RETURN_CODE; </code></pre> <p>The output of this script will be:</p> <pre><code>Exiting 0 1 </code></pre> <p>My guess is that t...
7,416
3,125,731
2021-04-30 00:21:23
26,509,093
12
2014-10-22 13:51:46
548,225
2014-10-22 13:51:46
https://stackoverflow.com/q/26509040
https://stackoverflow.com/a/26509093
<p>Exit/Return code needs be extracted immediately after running any command.</p> <p>So use:</p> <pre><code>VAR=$(expect -c 'puts "Exiting"; exit 1;') RETURN_CODE=$? echo "$VAR" echo $RETURN_CODE </code></pre> <p>Since your code is doing <code>echo</code> right after <code>expect</code> call therefore <code>$?</code...
<p>Exit/Return code needs be extracted immediately after running any command.</p> <p>So use:</p> <pre><code>VAR=$(expect -c 'puts "Exiting"; exit 1;') RETURN_CODE=$? echo "$VAR" echo $RETURN_CODE </code></pre> <p>Since your code is doing <code>echo</code> right after <code>expect</code> call therefore <code>$?</code...
387, 9048, 9206
bash, expect, return-value
<h1>Check the last exit code of a command echoed by a bash script</h1> <pre><code>#!/bin/bash test(){ return 1; } VAR=$(expect -c 'puts &quot;Exiting&quot;; exit 1;'); echo &quot;$VAR&quot;; RETURN_CODE=$?; echo $RETURN_CODE; test RETURN_CODE=$?; echo $RETURN_CODE; </code></pre> <p>The output of this script ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,919
bash
# Check the last exit code of a command echoed by a bash script ``` #!/bin/bash test(){ return 1; } VAR=$(expect -c 'puts "Exiting"; exit 1;'); echo "$VAR"; RETURN_CODE=$?; echo $RETURN_CODE; test RETURN_CODE=$?; echo $RETURN_CODE; ``` The output of this script will be: ``` Exiting 0 1 ``` My guess is th...
Exit/Return code needs be extracted immediately after running any command. So use: ``` VAR=$(expect -c 'puts "Exiting"; exit 1;') RETURN_CODE=$? echo "$VAR" echo $RETURN_CODE ``` Since your code is doing `echo` right after `expect` call therefore `$?` is giving you exit status of `echo` rather than the `expect` comm...
26295148
Parsing MySQL output in Bash
8
2014-10-10 08:34:44
<p>How can I redirect output of mysql query with table border as separator? I try with this code :</p> <pre><code>mysql -u root -h localhost -D cronjob -e "select * from cron_list" &gt; query.txt </code></pre> <p>What I expect is output like :</p> <pre><code>| id | datetime | recurrency | command ...
8,533
3,843,630
2014-10-13 09:27:17
26,295,339
12
2014-10-10 08:45:16
1,983,854
2014-10-13 09:27:17
https://stackoverflow.com/q/26295148
https://stackoverflow.com/a/26295339
<p>From <code>man mysql</code>:</p> <blockquote> <p><strong>--table, -t</strong></p> <p>Display output in table format. This is the default for interactive use, but can be used to produce table output in batch mode.</p> </blockquote> <p>Note <code>-t</code> is the default behaviour, but not whenever you pipe...
<p>From <code>man mysql</code>:</p> <blockquote> <p><strong>--table, -t</strong></p> <p>Display output in table format. This is the default for interactive use, but can be used to produce table output in batch mode.</p> </blockquote> <p>Note <code>-t</code> is the default behaviour, but not whenever you pipe...
21, 387
bash, mysql
<h1>Parsing MySQL output in Bash</h1> <p>How can I redirect output of mysql query with table border as separator? I try with this code :</p> <pre><code>mysql -u root -h localhost -D cronjob -e "select * from cron_list" &gt; query.txt </code></pre> <p>What I expect is output like :</p> <pre><code>| id | datetime | ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,920
bash
# Parsing MySQL output in Bash How can I redirect output of mysql query with table border as separator? I try with this code : ``` mysql -u root -h localhost -D cronjob -e "select * from cron_list" > query.txt ``` What I expect is output like : ``` | id | datetime | recurrency | command | | 1 |...
From `man mysql`: > **--table, -t** > > Display output in table format. This is the default for interactive > use, but can be used to produce table output in batch mode. Note `-t` is the default behaviour, but not whenever you pipe to a file. That's why in that case you have to make it explicit. --- Other interesti...
26260581
What is the actual signal behind ERR
8
2014-10-08 15:21:08
<p>I've read in several places (including SO) that <code>-e</code> is considered "poor form" and is unreliable for exiting a script on any error. A better way to handle errors seems to be using <code>trap</code>, as such:</p> <pre><code>trap "echo there was an error; exit 1;" ERR </code></pre> <p>I can't seem to loca...
4,278
2,161,954
2017-02-23 13:43:07
26,261,518
12
2014-10-08 16:10:23
1,566,221
2014-10-08 16:10:23
https://stackoverflow.com/q/26260581
https://stackoverflow.com/a/26261518
<p>There is no signal corresponding to the <code>trap</code> signal specification <code>ERR</code>.</p> <p><code>ERR</code> is one of the signal specifications implemented internally by <code>bash</code>. [Note 1] If <code>trap ERR</code> is enabled, then bash will invoke the corresponding handler in exactly the same ...
<p>There is no signal corresponding to the <code>trap</code> signal specification <code>ERR</code>.</p> <p><code>ERR</code> is one of the signal specifications implemented internally by <code>bash</code>. [Note 1] If <code>trap ERR</code> is enabled, then bash will invoke the corresponding handler in exactly the same ...
58, 379, 387, 2481, 124485
bash, bash-trap, error-handling, linux, signals
<h1>What is the actual signal behind ERR</h1> <p>I've read in several places (including SO) that <code>-e</code> is considered "poor form" and is unreliable for exiting a script on any error. A better way to handle errors seems to be using <code>trap</code>, as such:</p> <pre><code>trap "echo there was an error; exit ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,921
bash
# What is the actual signal behind ERR I've read in several places (including SO) that `-e` is considered "poor form" and is unreliable for exiting a script on any error. A better way to handle errors seems to be using `trap`, as such: ``` trap "echo there was an error; exit 1;" ERR ``` I can't seem to locate in the...
There is no signal corresponding to the `trap` signal specification `ERR`. `ERR` is one of the signal specifications implemented internally by `bash`. [Note 1] If `trap ERR` is enabled, then bash will invoke the corresponding handler in exactly the same cases as it would have exited had `set -e` been enabled. (Consequ...
25645946
Bash redirect output to tty and file
8
2014-09-03 13:41:32
<p>I'm trying to log some part of script execution. Logs should be displayed at second tty, and also written to a log file.</p> <p>I can do it with a simple:</p> <pre><code>echo "Hello log" &gt; /dev/tty2 echo "Hello log" &gt; /var/log/my_logs </code></pre> <p>But it is very uncomfortable. I could also redirect echo...
16,671
784,345
2014-09-03 13:50:17
25,646,010
12
2014-09-03 13:44:26
1,126,841
2014-09-03 13:44:26
https://stackoverflow.com/q/25645946
https://stackoverflow.com/a/25646010
<p>Use <code>tee</code>.</p> <pre><code>echo "Hello log" | tee /dev/tty2 /var/log/my_logs &gt; /dev/null </code></pre> <p>(The final redirection is to prevent the output from appearing to standard output as well. You could also use <code>echo "Hello log" | tee /dev/tty2 &gt; /var/log/my_logs</code>; there's no real d...
<p>Use <code>tee</code>.</p> <pre><code>echo "Hello log" | tee /dev/tty2 /var/log/my_logs &gt; /dev/null </code></pre> <p>(The final redirection is to prevent the output from appearing to standard output as well. You could also use <code>echo "Hello log" | tee /dev/tty2 &gt; /var/log/my_logs</code>; there's no real d...
387, 4867
bash, stdout
<h1>Bash redirect output to tty and file</h1> <p>I'm trying to log some part of script execution. Logs should be displayed at second tty, and also written to a log file.</p> <p>I can do it with a simple:</p> <pre><code>echo "Hello log" &gt; /dev/tty2 echo "Hello log" &gt; /var/log/my_logs </code></pre> <p>But it is ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,922
bash
# Bash redirect output to tty and file I'm trying to log some part of script execution. Logs should be displayed at second tty, and also written to a log file. I can do it with a simple: ``` echo "Hello log" > /dev/tty2 echo "Hello log" > /var/log/my_logs ``` But it is very uncomfortable. I could also redirect echo...
Use `tee`. ``` echo "Hello log" | tee /dev/tty2 /var/log/my_logs > /dev/null ``` (The final redirection is to prevent the output from appearing to standard output as well. You could also use `echo "Hello log" | tee /dev/tty2 > /var/log/my_logs`; there's no real difference between the two. `tee` just writes it standar...
25563024
Optimize shell script for multiple sed replacements
8
2014-08-29 06:50:15
<p>I have a file containing a list of replacement pairs (about 100 of them) which are used by <code>sed</code> to replace strings in files.</p> <p>The pairs go like:</p> <pre><code>old|new tobereplaced|replacement (stuffiwant).*(too)|\1\2 </code></pre> <p>and my current code is:</p> <pre><code>cat replacement_list ...
3,934
556,065
2022-01-27 12:36:02
25,563,180
12
2014-08-29 07:02:51
1,648,033
2014-08-31 05:42:09
https://stackoverflow.com/q/25563024
https://stackoverflow.com/a/25563180
<p>You can use <code>sed</code> to produce correctly -formatted <code>sed</code> input:</p> <pre><code>sed -e 's/^/s|/; s/$/|g/' replacement_list | sed -r -f - file </code></pre>
<p>You can use <code>sed</code> to produce correctly -formatted <code>sed</code> input:</p> <pre><code>sed -e 's/^/s|/; s/$/|g/' replacement_list | sed -r -f - file </code></pre>
387, 390, 5282
bash, sed, shell
<h1>Optimize shell script for multiple sed replacements</h1> <p>I have a file containing a list of replacement pairs (about 100 of them) which are used by <code>sed</code> to replace strings in files.</p> <p>The pairs go like:</p> <pre><code>old|new tobereplaced|replacement (stuffiwant).*(too)|\1\2 </code></pre> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,923
bash
# Optimize shell script for multiple sed replacements I have a file containing a list of replacement pairs (about 100 of them) which are used by `sed` to replace strings in files. The pairs go like: ``` old|new tobereplaced|replacement (stuffiwant).*(too)|\1\2 ``` and my current code is: ``` cat replacement_list |...
You can use `sed` to produce correctly -formatted `sed` input: ``` sed -e 's/^/s|/; s/$/|g/' replacement_list | sed -r -f - file ```
23967619
Azure: Delete all *test.zip blobs from Azure Storage using Powershell
8
2014-05-31 07:33:16
<p>I would like to delete all files from an azure storage container where the filename includes test.zip</p> <p>I am able to get all the files and export them to a file like this:</p> <pre><code>$context = New-AzureStorageContext -StorageAccountName ACCOUNTNAME ` -StorageAccountKey ...
10,605
3,693,688
2021-12-31 13:28:03
23,967,645
12
2014-05-31 07:37:16
188,096
2018-10-22 21:34:38
https://stackoverflow.com/q/23967619
https://stackoverflow.com/a/23967645
<p>Since blob storage only support individual blob deletes at this moment (i.e. it doesn't support batch deletes), your only option would be to read individual blobs from the output file and delete the blob one by one.</p> <p>Based on your comments below, try the following:</p> <pre><code>$context = New-AzureStorageC...
<p>Since blob storage only support individual blob deletes at this moment (i.e. it doesn't support batch deletes), your only option would be to read individual blobs from the output file and delete the blob one by one.</p> <p>Based on your comments below, try the following:</p> <pre><code>$context = New-AzureStorageC...
526, 14158, 35808
azure, azure-storage, powershell
<h1>Azure: Delete all *test.zip blobs from Azure Storage using Powershell</h1> <p>I would like to delete all files from an azure storage container where the filename includes test.zip</p> <p>I am able to get all the files and export them to a file like this:</p> <pre><code>$context = New-AzureStorageContext -StorageA...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,924
bash
# Azure: Delete all *test.zip blobs from Azure Storage using Powershell I would like to delete all files from an azure storage container where the filename includes test.zip I am able to get all the files and export them to a file like this: ``` $context = New-AzureStorageContext -StorageAccountName ACCOUNTNAME ` ...
Since blob storage only support individual blob deletes at this moment (i.e. it doesn't support batch deletes), your only option would be to read individual blobs from the output file and delete the blob one by one. Based on your comments below, try the following: ``` $context = New-AzureStorageContext -StorageAccoun...
23024659
Powershell: Determine if a process is 32 or 64 bit
8
2014-04-12 00:30:40
<p>Is there a way to determine if a given process ID is for a 32 or a 64 bit process? I'm using Powershell v3.0</p>
6,117
21,539
2017-05-04 04:25:16
23,025,963
12
2014-04-12 04:02:06
153,982
2014-04-12 04:02:06
https://stackoverflow.com/q/23024659
https://stackoverflow.com/a/23025963
<p>Try this:</p> <pre><code>Add-Type -MemberDefinition @' [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Process( [In] System.IntPtr hProcess, [Out, MarshalAs(UnmanagedType.Bool)] out bool w...
<p>Try this:</p> <pre><code>Add-Type -MemberDefinition @' [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Process( [In] System.IntPtr hProcess, [Out, MarshalAs(UnmanagedType.Bool)] out bool w...
526, 73157
powershell, powershell-3.0
<h1>Powershell: Determine if a process is 32 or 64 bit</h1> <p>Is there a way to determine if a given process ID is for a 32 or a 64 bit process? I'm using Powershell v3.0</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,925
bash
# Powershell: Determine if a process is 32 or 64 bit Is there a way to determine if a given process ID is for a 32 or a 64 bit process? I'm using Powershell v3.0
Try this: ``` Add-Type -MemberDefinition @' [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Process( [In] System.IntPtr hProcess, [Out, MarshalAs(UnmanagedType.Bool)] out bool wow64Process); ...
22585091
Git-hooks pre-push script does not receive input via STDIN
8
2014-03-22 23:34:35
<p>The <a href="http://git-scm.com/docs/githooks#_pre_push" rel="noreferrer">git-hooks pre-push documentation</a> states that the first line of <em>stdin</em> will be populated with the local ref and sha, and the remote ref and sha as such:</p> <p><code>&lt;local ref&gt; SP &lt;local sha1&gt; SP &lt;remote ref&gt; SP ...
2,859
1,254,812
2014-03-23 01:03:52
22,585,746
12
2014-03-23 01:03:52
669,631
2014-03-23 01:03:52
https://stackoverflow.com/q/22585091
https://stackoverflow.com/a/22585746
<p>Apologies if this is stating the obvious, but if there's nothing to push, you won't get any lines on stdin. The sample <code>.git/hooks/pre-push.sample</code> has a while loop:</p> <pre><code>IFS=' ' while read local_ref local_sha remote_ref remote_sha do ... done </code></pre> <p>and that appears to work when...
<p>Apologies if this is stating the obvious, but if there's nothing to push, you won't get any lines on stdin. The sample <code>.git/hooks/pre-push.sample</code> has a while loop:</p> <pre><code>IFS=' ' while read local_ref local_sha remote_ref remote_sha do ... done </code></pre> <p>and that appears to work when...
119, 387, 43087
bash, git, githooks
<h1>Git-hooks pre-push script does not receive input via STDIN</h1> <p>The <a href="http://git-scm.com/docs/githooks#_pre_push" rel="noreferrer">git-hooks pre-push documentation</a> states that the first line of <em>stdin</em> will be populated with the local ref and sha, and the remote ref and sha as such:</p> <p><co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,926
bash
# Git-hooks pre-push script does not receive input via STDIN The [git-hooks pre-push documentation](http://git-scm.com/docs/githooks#_pre_push) states that the first line of *stdin* will be populated with the local ref and sha, and the remote ref and sha as such: `<local ref> SP <local sha1> SP <remote ref> SP <remot...
Apologies if this is stating the obvious, but if there's nothing to push, you won't get any lines on stdin. The sample `.git/hooks/pre-push.sample` has a while loop: ``` IFS=' ' while read local_ref local_sha remote_ref remote_sha do ... done ``` and that appears to work when I try it here with an echo inside tha...
22366622
Delete empty lines in csv file
8
2014-03-13 00:16:38
<p>I have a file with 4 million of lines, every line ends with the char $, but I mistakenly add a new line after the the line delimiter while scraping a website, so right now it is looking like this:</p> <pre><code>fist name, last name, phone, address, postal code, city, region,$ $ fist name, last name, phone, addr...
22,775
3,344,414
2024-08-31 11:23:07
22,367,848
12
2014-03-13 02:20:37
318,716
2014-03-13 02:20:37
https://stackoverflow.com/q/22366622
https://stackoverflow.com/a/22367848
<p>To remove blank lines with <code>sed</code>:</p> <pre><code>sed -i '/^$/d' yourfile.csv </code></pre> <p>To remove lines consisting of a single <code>$</code>:</p> <pre><code>sed -i '/^$$/d' yourfile.csv </code></pre> <p>Most versions of sed support the <code>-i</code> switch; if yours does not you will need e.g...
<p>To remove blank lines with <code>sed</code>:</p> <pre><code>sed -i '/^$/d' yourfile.csv </code></pre> <p>To remove lines consisting of a single <code>$</code>:</p> <pre><code>sed -i '/^$$/d' yourfile.csv </code></pre> <p>Most versions of sed support the <code>-i</code> switch; if yours does not you will need e.g...
58, 293, 387, 990, 5282
awk, bash, linux, sed, vi
<h1>Delete empty lines in csv file</h1> <p>I have a file with 4 million of lines, every line ends with the char $, but I mistakenly add a new line after the the line delimiter while scraping a website, so right now it is looking like this:</p> <pre><code>fist name, last name, phone, address, postal code, city, region...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,927
bash
# Delete empty lines in csv file I have a file with 4 million of lines, every line ends with the char $, but I mistakenly add a new line after the the line delimiter while scraping a website, so right now it is looking like this: ``` fist name, last name, phone, address, postal code, city, region,$ $ fist name, las...
To remove blank lines with `sed`: ``` sed -i '/^$/d' yourfile.csv ``` To remove lines consisting of a single `$`: ``` sed -i '/^$$/d' yourfile.csv ``` Most versions of sed support the `-i` switch; if yours does not you will need e.g. `sed '/^$$/d' yourfile.csv > newfile.csv`. Removing blank lines with white space ...
21437019
How to call an executable with parameters from powershell script
8
2014-01-29 16:33:57
<p>I am seeking help on how to call cmd with specific parameters from a powershell script. So far what I have written is below, but it gives me an error message saying $_cmd is not recognized.</p> <p>I am trying to pass the from date and to date to a an exe... The from date as you can see needs to be today - 1 and the...
21,000
377,771
2014-01-29 21:10:53
21,442,190
12
2014-01-29 20:42:53
1,630,171
2014-01-29 20:42:53
https://stackoverflow.com/q/21437019
https://stackoverflow.com/a/21442190
<p>Don't make a command string. Simply use the call operator (<code>&amp;</code>):</p> <pre><code>Write-Host 'Get data from service' $path = 'D:\DataService' Push-Location $path $Date = Get-Date $DateFrom = $Date.ToString('yyyy-MM-dd HH:mm:ss') $DateTo = $Date.AddDays(-1).ToString('yyyy-MM-dd') &amp; ReportG...
<p>Don't make a command string. Simply use the call operator (<code>&amp;</code>):</p> <pre><code>Write-Host 'Get data from service' $path = 'D:\DataService' Push-Location $path $Date = Get-Date $DateFrom = $Date.ToString('yyyy-MM-dd HH:mm:ss') $DateTo = $Date.AddDays(-1).ToString('yyyy-MM-dd') &amp; ReportG...
526, 24067
powershell, powershell-2.0
<h1>How to call an executable with parameters from powershell script</h1> <p>I am seeking help on how to call cmd with specific parameters from a powershell script. So far what I have written is below, but it gives me an error message saying $_cmd is not recognized.</p> <p>I am trying to pass the from date and to date...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,928
bash
# How to call an executable with parameters from powershell script I am seeking help on how to call cmd with specific parameters from a powershell script. So far what I have written is below, but it gives me an error message saying $_cmd is not recognized. I am trying to pass the from date and to date to a an exe... ...
Don't make a command string. Simply use the call operator (`&`): ``` Write-Host 'Get data from service' $path = 'D:\DataService' Push-Location $path $Date = Get-Date $DateFrom = $Date.ToString('yyyy-MM-dd HH:mm:ss') $DateTo = $Date.AddDays(-1).ToString('yyyy-MM-dd') & ReportGen.exe -ReportType Data -DateFrom...
21205723
how many ways we can create a process in linux using c
8
2014-01-18 14:56:49
<p>I have confusion in creating a process in Linux. Up to now I thought that we can create the process by calling the following system calls.</p> <ol> <li><code>system()</code></li> <li><code>exec()</code> family of system call</li> <li><code>fork()</code> system call</li> </ol> <p>but:</p> <ol> <li><p><strong>syste...
4,709
3,209,809
2014-01-18 21:16:30
21,205,784
12
2014-01-18 15:01:58
2,003,263
2014-01-18 15:12:36
https://stackoverflow.com/q/21205723
https://stackoverflow.com/a/21205784
<p><strong><code>exec</code> family of system call does not call <code>fork</code>, neither it creates a new process.</strong> It only overwrites the existing process with the new binary.</p> <p><strong>In <code>linux</code> user programs, <code>fork</code> is the only function to create new process.</strong> Though <...
<p><strong><code>exec</code> family of system call does not call <code>fork</code>, neither it creates a new process.</strong> It only overwrites the existing process with the new binary.</p> <p><strong>In <code>linux</code> user programs, <code>fork</code> is the only function to create new process.</strong> Though <...
8, 58, 390
c, linux, shell
<h1>how many ways we can create a process in linux using c</h1> <p>I have confusion in creating a process in Linux. Up to now I thought that we can create the process by calling the following system calls.</p> <ol> <li><code>system()</code></li> <li><code>exec()</code> family of system call</li> <li><code>fork()</code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,929
bash
# how many ways we can create a process in linux using c I have confusion in creating a process in Linux. Up to now I thought that we can create the process by calling the following system calls. 1. `system()` 2. `exec()` family of system call 3. `fork()` system call but: 1. **system():** But as "system" system cal...
**`exec` family of system call does not call `fork`, neither it creates a new process.** It only overwrites the existing process with the new binary. **In `linux` user programs, `fork` is the only function to create new process.** Though `fork` internally calls `clone` and other system calls. In other hands, `system`...
20179623
Bash: Remove headers from HTTP response
8
2013-11-24 19:09:11
<p>If I have some text containing HTTP headers and body, eg:</p> <pre><code>HTTP/1.1 200 OK Cache-Control: public, max-age=38 Content-Type: text/html; charset=utf-8 Expires: Fri, 22 Nov 2013 06:15:01 GMT Last-Modified: Fri, 22 Nov 2013 06:14:01 GMT Vary: * X-Frame-Options: SAMEORIGIN Date: Fri, 22 Nov 2013 06:14:22 GM...
6,626
1,851,186
2014-10-21 14:32:45
20,179,805
12
2013-11-24 19:24:44
1,945,981
2013-11-24 19:35:56
https://stackoverflow.com/q/20179623
https://stackoverflow.com/a/20179805
<p><a href="/questions/tagged/sed" class="post-tag" title="show questions tagged &#39;sed&#39;" rel="tag">sed</a> can do this:</p> <pre><code>sed '1,/^$/d' data.txt </code></pre> <p>This command deletes everything starting from line 1, and ending at the first occurrence of an empty line (<code>^$</code>). This works ...
<p><a href="/questions/tagged/sed" class="post-tag" title="show questions tagged &#39;sed&#39;" rel="tag">sed</a> can do this:</p> <pre><code>sed '1,/^$/d' data.txt </code></pre> <p>This command deletes everything starting from line 1, and ending at the first occurrence of an empty line (<code>^$</code>). This works ...
18, 387, 580, 1271, 5282
bash, grep, perl, regex, sed
<h1>Bash: Remove headers from HTTP response</h1> <p>If I have some text containing HTTP headers and body, eg:</p> <pre><code>HTTP/1.1 200 OK Cache-Control: public, max-age=38 Content-Type: text/html; charset=utf-8 Expires: Fri, 22 Nov 2013 06:15:01 GMT Last-Modified: Fri, 22 Nov 2013 06:14:01 GMT Vary: * X-Frame-Optio...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,930
bash
# Bash: Remove headers from HTTP response If I have some text containing HTTP headers and body, eg: ``` HTTP/1.1 200 OK Cache-Control: public, max-age=38 Content-Type: text/html; charset=utf-8 Expires: Fri, 22 Nov 2013 06:15:01 GMT Last-Modified: Fri, 22 Nov 2013 06:14:01 GMT Vary: * X-Frame-Options: SAMEORIGIN Date:...
[sed](/questions/tagged/sed "show questions tagged 'sed'") can do this: ``` sed '1,/^$/d' data.txt ``` This command deletes everything starting from line 1, and ending at the first occurrence of an empty line (`^$`). This works if you have `\n` as a newline character. If you have `\r\n` as a newline character, you ca...
18468637
Powershell - User Mapping SQL Server 2012
8
2013-08-27 14:44:30
<p>I am trying to script User Mapping for different Login accounts. I have scripted the creation of users and individual server roles, but I can't figure out how to set User Mapping with Powershell, I will also need to set the <code>Database Role membership</code>, in Particular, <code>db_backupoperator</code></p> <...
7,356
1,385,483
2013-08-27 16:27:28
18,470,681
12
2013-08-27 16:15:18
1,085,940
2013-08-27 16:27:28
https://stackoverflow.com/q/18468637
https://stackoverflow.com/a/18470681
<p>Supposing your login is created</p> <pre><code>## Creating database user and assigning database role #get variables $instanceName = "yourInstance" $loginName = "testLogin" $dbUserName = "testUserName" $databasename = "tempdb" $roleName = "db_backupoperator" $server = New-Object -TypeName Microsoft.SqlServer.Ma...
<p>Supposing your login is created</p> <pre><code>## Creating database user and assigning database role #get variables $instanceName = "yourInstance" $loginName = "testLogin" $dbUserName = "testUserName" $databasename = "tempdb" $roleName = "db_backupoperator" $server = New-Object -TypeName Microsoft.SqlServer.Ma...
22, 72, 526, 74269, 92919
powershell, sql, sqlps, sql-server, sql-server-2012
<h1>Powershell - User Mapping SQL Server 2012</h1> <p>I am trying to script User Mapping for different Login accounts. I have scripted the creation of users and individual server roles, but I can't figure out how to set User Mapping with Powershell, I will also need to set the <code>Database Role membership</code>, i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,931
bash
# Powershell - User Mapping SQL Server 2012 I am trying to script User Mapping for different Login accounts. I have scripted the creation of users and individual server roles, but I can't figure out how to set User Mapping with Powershell, I will also need to set the `Database Role membership`, in Particular, `db_back...
Supposing your login is created ``` ## Creating database user and assigning database role #get variables $instanceName = "yourInstance" $loginName = "testLogin" $dbUserName = "testUserName" $databasename = "tempdb" $roleName = "db_backupoperator" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.S...
9960465
How do I get a list of all available shell commands
8
2012-03-31 23:01:56
<p>In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands.</p> <p>Is there a command which has the same behaviour? I want to pipe it into <code>grep</code> and search it.</p>
14,221
552,671
2016-06-05 16:05:03
18,280,513
12
2013-08-16 19:12:22
465,035
2013-08-16 19:12:22
https://stackoverflow.com/q/9960465
https://stackoverflow.com/a/18280513
<p>You could use compgen. For example:</p> <pre><code>compgen -c </code></pre> <p>You also could grep it, like this:</p> <pre><code>compgen -c | grep top$ </code></pre> <p>Source: <a href="http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/" rel="noreferrer">http://www.cyberciti.biz/open-...
<p>You could use compgen. For example:</p> <pre><code>compgen -c </code></pre> <p>You also could grep it, like this:</p> <pre><code>compgen -c | grep top$ </code></pre> <p>Source: <a href="http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/" rel="noreferrer">http://www.cyberciti.biz/open-...
387, 390
bash, shell
<h1>How do I get a list of all available shell commands</h1> <p>In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands.</p> <p>Is there a command which has the same behaviour? I want to pipe it into <code>grep</code> and search it.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,932
bash
# How do I get a list of all available shell commands In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands. Is there a command which has the same behaviour? I want to pipe it into `grep` and search it.
You could use compgen. For example: ``` compgen -c ``` You also could grep it, like this: ``` compgen -c | grep top$ ``` Source: <http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/>
18101208
Bash script global redirection with exec and write to screen
8
2013-08-07 10:38:09
<p>I have a large bash script and I want to globally redirect all stdout/stderr to a file, <em>except</em> some progress indicators such specific echo messages. For example, consider the following script</p> <pre><code>#!/bin/bash # all stdout and stderr go to out.log exec &amp;&gt; out.log special_echo "starting" ...
4,822
2,660,278
2018-12-17 00:44:37
18,101,327
12
2013-08-07 10:43:34
1,030,675
2013-08-07 10:43:34
https://stackoverflow.com/q/18101208
https://stackoverflow.com/a/18101327
<p>Yes, using another file descriptor is the way to go:</p> <pre><code>#!/bin/bash exec 3&gt;&amp;1 special_echo () { echo "$@" &gt;&amp;3 } exec &amp;&gt; out.log special_echo "starting" echo "msg1" special_echo "middle" echo "msg2" &gt;&amp;2 special_echo "finished" </code></pre>
<p>Yes, using another file descriptor is the way to go:</p> <pre><code>#!/bin/bash exec 3&gt;&amp;1 special_echo () { echo "$@" &gt;&amp;3 } exec &amp;&gt; out.log special_echo "starting" echo "msg1" special_echo "middle" echo "msg2" &gt;&amp;2 special_echo "finished" </code></pre>
387
bash
<h1>Bash script global redirection with exec and write to screen</h1> <p>I have a large bash script and I want to globally redirect all stdout/stderr to a file, <em>except</em> some progress indicators such specific echo messages. For example, consider the following script</p> <pre><code>#!/bin/bash # all stdout and ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,933
bash
# Bash script global redirection with exec and write to screen I have a large bash script and I want to globally redirect all stdout/stderr to a file, *except* some progress indicators such specific echo messages. For example, consider the following script ``` #!/bin/bash # all stdout and stderr go to out.log exec &...
Yes, using another file descriptor is the way to go: ``` #!/bin/bash exec 3>&1 special_echo () { echo "$@" >&3 } exec &> out.log special_echo "starting" echo "msg1" special_echo "middle" echo "msg2" >&2 special_echo "finished" ```
18056286
why second time cp command is faster
8
2013-08-05 10:45:23
<p>When I execute <code>cp folder1 folder2 -rf</code>,for the first time it takes around 10 mins. But when it I execute the second command <code>cp folder1 folder3 -rf</code>, it takes around 1 min. <code>folder1</code> contains about 100 000 files.</p> <p>Why is there run time improvement for the second time? </p>
2,335
1,391,354
2022-05-24 14:26:59
18,056,360
12
2013-08-05 10:49:25
2,536,029
2013-08-05 11:15:08
https://stackoverflow.com/q/18056286
https://stackoverflow.com/a/18056360
<p>This is because of page caching. Run <code>sync ; echo 3 &gt; /proc/sys/vm/drop_caches</code> to make it slow again.</p> <p>Further reading:</p> <ul> <li><a href="http://jim.studt.net/depository/index.php/flushing-caches-for-benchmarking-in-linux" rel="nofollow noreferrer">http://jim.studt.net/depository/index.php...
<p>This is because of page caching. Run <code>sync ; echo 3 &gt; /proc/sys/vm/drop_caches</code> to make it slow again.</p> <p>Further reading:</p> <ul> <li><a href="http://jim.studt.net/depository/index.php/flushing-caches-for-benchmarking-in-linux" rel="nofollow noreferrer">http://jim.studt.net/depository/index.php...
58, 390, 722, 1763
benchmarking, caching, linux, shell
<h1>why second time cp command is faster</h1> <p>When I execute <code>cp folder1 folder2 -rf</code>,for the first time it takes around 10 mins. But when it I execute the second command <code>cp folder1 folder3 -rf</code>, it takes around 1 min. <code>folder1</code> contains about 100 000 files.</p> <p>Why is there run...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,934
bash
# why second time cp command is faster When I execute `cp folder1 folder2 -rf`,for the first time it takes around 10 mins. But when it I execute the second command `cp folder1 folder3 -rf`, it takes around 1 min. `folder1` contains about 100 000 files. Why is there run time improvement for the second time?
This is because of page caching. Run `sync ; echo 3 > /proc/sys/vm/drop_caches` to make it slow again. Further reading: - <http://jim.studt.net/depository/index.php/flushing-caches-for-benchmarking-in-linux> - <https://superuser.com/a/319287/236874>
15718756
Escaping pipe character in rsh
8
2013-03-30 12:55:49
<p>I am trying to run this bash command, but I cant get around the "|" pipe character</p> <p><code>rsh -l user machine "echo "PORTS = 123|456|789" &gt;&gt; conf.cfg"</code></p> <p>Getting:</p> <p><code>bash: 456 &gt;&gt; conf.cfg: No such file or directory</code></p> <p><code>bash: 789: command not found</code></p>...
22,720
247,041
2013-03-30 12:57:46
15,718,777
12
2013-03-30 12:57:46
1,983,854
2013-03-30 12:57:46
https://stackoverflow.com/q/15718756
https://stackoverflow.com/a/15718777
<p>Just escape the pipes and the quotes:</p> <pre><code>rsh -l user machine "echo \"PORTS = 123\|456\|789\" &gt;&gt; conf.cfg" </code></pre>
<p>Just escape the pipes and the quotes:</p> <pre><code>rsh -l user machine "echo \"PORTS = 123\|456\|789\" &gt;&gt; conf.cfg" </code></pre>
387, 2822
bash, rsh
<h1>Escaping pipe character in rsh</h1> <p>I am trying to run this bash command, but I cant get around the "|" pipe character</p> <p><code>rsh -l user machine "echo "PORTS = 123|456|789" &gt;&gt; conf.cfg"</code></p> <p>Getting:</p> <p><code>bash: 456 &gt;&gt; conf.cfg: No such file or directory</code></p> <p><code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,935
bash
# Escaping pipe character in rsh I am trying to run this bash command, but I cant get around the "|" pipe character `rsh -l user machine "echo "PORTS = 123|456|789" >> conf.cfg"` Getting: `bash: 456 >> conf.cfg: No such file or directory` `bash: 789: command not found` Would you know how I can echo `PORTS = 123|4...
Just escape the pipes and the quotes: ``` rsh -l user machine "echo \"PORTS = 123\|456\|789\" >> conf.cfg" ```
15708203
Powershell hashtable keys with special characters
8
2013-03-29 17:23:05
<p>I'm having trouble trying to access a hashtable with a / in the key. In my case the keys are mime types, and a simple example of the hashtable looks like:</p> <pre><code>PS H:\&gt; $h Name Value ...
5,976
1,635
2013-03-29 18:49:09
15,708,406
12
2013-03-29 17:34:58
9,833
2013-03-29 18:49:09
https://stackoverflow.com/q/15708203
https://stackoverflow.com/a/15708406
<p>In my opinion the Key is not a string but an object? I have no problems getting the value both ways:</p> <pre><code>PS&gt; $h=@{'application/pdf'='application/pdf'} PS&gt; $h["application/pdf"] application/pdf PS&gt; $h."application/pdf" application/pdf </code></pre>
<p>In my opinion the Key is not a string but an object? I have no problems getting the value both ways:</p> <pre><code>PS&gt; $h=@{'application/pdf'='application/pdf'} PS&gt; $h["application/pdf"] application/pdf PS&gt; $h."application/pdf" application/pdf </code></pre>
526
powershell
<h1>Powershell hashtable keys with special characters</h1> <p>I'm having trouble trying to access a hashtable with a / in the key. In my case the keys are mime types, and a simple example of the hashtable looks like:</p> <pre><code>PS H:\&gt; $h Name Value ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,936
bash
# Powershell hashtable keys with special characters I'm having trouble trying to access a hashtable with a / in the key. In my case the keys are mime types, and a simple example of the hashtable looks like: ``` PS H:\> $h Name Value ...
In my opinion the Key is not a string but an object? I have no problems getting the value both ways: ``` PS> $h=@{'application/pdf'='application/pdf'} PS> $h["application/pdf"] application/pdf PS> $h."application/pdf" application/pdf ```
15330402
/dev/stdin with herestring
8
2013-03-11 02:46:21
<p>I would like a Bash script that can take input from a file or stdin, much like <code>grep</code>, for example</p> <pre class="lang-none prettyprint-override"><code>$ cat hw.txt Hello world $ grep wor hw.txt Hello world $ echo 'Hello world' | grep wor Hello world $ grep wor &lt;&lt;&lt; 'Hello world' Hello world ...
12,107
1,002,260
2013-03-11 12:41:51
15,330,784
12
2013-03-11 03:35:59
302,243
2013-03-11 03:35:59
https://stackoverflow.com/q/15330402
https://stackoverflow.com/a/15330784
<p>Using <code>/dev/stdin</code> in this manner can be problematic because you are attempting to get a handle to stdin using a name in the filesystem (<code>/dev/stdin</code>) rather than using the file descriptor which bash has already handed you as stdin (file descriptor 0).</p> <p>Here's a small script for you to t...
<p>Using <code>/dev/stdin</code> in this manner can be problematic because you are attempting to get a handle to stdin using a name in the filesystem (<code>/dev/stdin</code>) rather than using the file descriptor which bash has already handed you as stdin (file descriptor 0).</p> <p>Here's a small script for you to t...
387, 1701, 1731, 7449
bash, cygwin, heredoc, stdin
<h1>/dev/stdin with herestring</h1> <p>I would like a Bash script that can take input from a file or stdin, much like <code>grep</code>, for example</p> <pre class="lang-none prettyprint-override"><code>$ cat hw.txt Hello world $ grep wor hw.txt Hello world $ echo 'Hello world' | grep wor Hello world $ grep wor &lt...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,937
bash
# /dev/stdin with herestring I would like a Bash script that can take input from a file or stdin, much like `grep`, for example ``` $ cat hw.txt Hello world $ grep wor hw.txt Hello world $ echo 'Hello world' | grep wor Hello world $ grep wor <<< 'Hello world' Hello world ``` all works beautifully. However with th...
Using `/dev/stdin` in this manner can be problematic because you are attempting to get a handle to stdin using a name in the filesystem (`/dev/stdin`) rather than using the file descriptor which bash has already handed you as stdin (file descriptor 0). Here's a small script for you to test: ``` #!/bin/bash echo "INF...
14717872
Split file into unequal chunks in Linux
8
2013-02-05 22:05:02
<p>I wish to split a large file (with ~ 17M Lines of Strings) into multiple files with varying number of lines in each chunk. Would it be possible to send in an array to the <strong>'<em>split -l</em>'</strong> command like this:</p> <pre><code>[ 1=&gt;1000000, 2=&gt;1000537, ... ] </code></pre> <p>so as to send t...
3,443
862,763
2013-02-06 21:33:43
14,718,746
12
2013-02-05 23:13:20
1,899,640
2013-02-06 21:33:43
https://stackoverflow.com/q/14717872
https://stackoverflow.com/a/14718746
<p>Use a compound command:</p> <pre><code>{ head -n 10000 &gt; output1 head -n 200 &gt; output2 head -n 1234 &gt; output3 cat &gt; remainder } &lt; yourbigfile </code></pre> <p>This also works with loops:</p> <pre><code>{ i=1 for n in 10000 200 1234 do head -n $n &gt; output$i let i++ ...
<p>Use a compound command:</p> <pre><code>{ head -n 10000 &gt; output1 head -n 200 &gt; output2 head -n 1234 &gt; output3 cat &gt; remainder } &lt; yourbigfile </code></pre> <p>This also works with loops:</p> <pre><code>{ i=1 for n in 10000 200 1234 do head -n $n &gt; output$i let i++ ...
34, 58, 387
bash, linux, unix
<h1>Split file into unequal chunks in Linux</h1> <p>I wish to split a large file (with ~ 17M Lines of Strings) into multiple files with varying number of lines in each chunk. Would it be possible to send in an array to the <strong>'<em>split -l</em>'</strong> command like this:</p> <pre><code>[ 1=&gt;1000000, 2=&gt;...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,938
bash
# Split file into unequal chunks in Linux I wish to split a large file (with ~ 17M Lines of Strings) into multiple files with varying number of lines in each chunk. Would it be possible to send in an array to the **'*split -l*'** command like this: ``` [ 1=>1000000, 2=>1000537, ... ] ``` so as to send those many ...
Use a compound command: ``` { head -n 10000 > output1 head -n 200 > output2 head -n 1234 > output3 cat > remainder } < yourbigfile ``` This also works with loops: ``` { i=1 for n in 10000 200 1234 do head -n $n > output$i let i++ done cat > remainder } < yourbigfile ``` This does no...
14664764
Passing arguments to Start-Job scriptblock?
8
2013-02-02 17:58:12
<p>I'd like to setup a cmdlet to start and stop mysql, and I'm trying to do so with Start-Job. the I've got the following in my Powershell profile:</p> <pre><code>$mysqlpath = "C:\Program Files\MySQL\MySQL Server 5.5\bin" Function Start-Mysql { Start-Job -ScriptBlock { &amp; "$mysqlpath\mysqld.exe" } } </code></pr...
11,699
1,572,795
2021-09-02 20:48:37
14,664,983
12
2013-02-02 18:21:17
381,149
2019-09-03 05:35:53
https://stackoverflow.com/q/14664764
https://stackoverflow.com/a/14664983
<p>you have to use the <code>-argumentlist</code> parameter see <a href="http://technet.microsoft.com/en-us/library/hh849698.aspx" rel="nofollow noreferrer">get-help start-job</a> :</p> <pre><code> start-job -ScriptBlock { &amp; $args[0] } -ArgumentList @($mysqlpath ) </code></pre> <p>note that in V3 you just have t...
<p>you have to use the <code>-argumentlist</code> parameter see <a href="http://technet.microsoft.com/en-us/library/hh849698.aspx" rel="nofollow noreferrer">get-help start-job</a> :</p> <pre><code> start-job -ScriptBlock { &amp; $args[0] } -ArgumentList @($mysqlpath ) </code></pre> <p>note that in V3 you just have t...
526, 24067
powershell, powershell-2.0
<h1>Passing arguments to Start-Job scriptblock?</h1> <p>I'd like to setup a cmdlet to start and stop mysql, and I'm trying to do so with Start-Job. the I've got the following in my Powershell profile:</p> <pre><code>$mysqlpath = "C:\Program Files\MySQL\MySQL Server 5.5\bin" Function Start-Mysql { Start-Job -Script...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,939
bash
# Passing arguments to Start-Job scriptblock? I'd like to setup a cmdlet to start and stop mysql, and I'm trying to do so with Start-Job. the I've got the following in my Powershell profile: ``` $mysqlpath = "C:\Program Files\MySQL\MySQL Server 5.5\bin" Function Start-Mysql { Start-Job -ScriptBlock { & "$mysqlpat...
you have to use the `-argumentlist` parameter see [get-help start-job](http://technet.microsoft.com/en-us/library/hh849698.aspx) : ``` start-job -ScriptBlock { & $args[0] } -ArgumentList @($mysqlpath ) ``` note that in V3 you just have to use the prefix `using:` before your varname ex: ``` Start-Job -ScriptBlock...
14408648
Use $RANDOM in a makefile
8
2013-01-18 22:23:35
<p>I am making a makefile to rename files with a random number in it (I am a newbie in shell script). I don't understand why, but when I run the file $rand is given the value 'ANDOM'. When I run this outside of the makefile it works.</p> <p>I run this in the Mac os terminal, in case it's helpful.</p> <pre><code>all: ...
16,086
1,123,278
2015-04-03 04:15:56
14,409,906
12
2013-01-19 00:41:34
15,168
2013-01-19 00:41:34
https://stackoverflow.com/q/14408648
https://stackoverflow.com/a/14409906
<ol> <li><p>Wouldn't it be easier/better to use a date/time stamp so that the renamed files are listed in date order?</p></li> <li><p>You need to use two <code>$</code> signs in the <code>makefile</code> for each <code>$</code> that you want the shell to see.</p></li> </ol> <p>Thus:</p> <pre><code>all: renamefiles r...
<ol> <li><p>Wouldn't it be easier/better to use a date/time stamp so that the renamed files are listed in date order?</p></li> <li><p>You need to use two <code>$</code> signs in the <code>makefile</code> for each <code>$</code> that you want the shell to see.</p></li> </ol> <p>Thus:</p> <pre><code>all: renamefiles r...
390, 391, 4301
makefile, shell, terminal
<h1>Use $RANDOM in a makefile</h1> <p>I am making a makefile to rename files with a random number in it (I am a newbie in shell script). I don't understand why, but when I run the file $rand is given the value 'ANDOM'. When I run this outside of the makefile it works.</p> <p>I run this in the Mac os terminal, in case ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,940
bash
# Use $RANDOM in a makefile I am making a makefile to rename files with a random number in it (I am a newbie in shell script). I don't understand why, but when I run the file $rand is given the value 'ANDOM'. When I run this outside of the makefile it works. I run this in the Mac os terminal, in case it's helpful. `...
1. Wouldn't it be easier/better to use a date/time stamp so that the renamed files are listed in date order? 2. You need to use two `$` signs in the `makefile` for each `$` that you want the shell to see. Thus: ``` all: renamefiles renamefiles: rand=$$RANDOM && \ mv myfile.css $$rand-myfile.css && \ ...
14340113
Bash (grep) regex performing unexpectedly
8
2013-01-15 14:41:36
<p>I have a text file, which contains a date in the form of <code>dd/mm/yyyy</code> (e.g 20/12/2012).</p> <p>I am trying to use <code>grep</code> to parse the date and show it in the terminal, and it is successful, until I meet a certain case:</p> <p>These are my test cases: </p> <ul> <li><code>grep -E "\d*"</code>...
4,952
1,426,969
2013-01-15 16:07:40
14,340,237
12
2013-01-15 14:49:17
115,845
2013-01-15 15:06:41
https://stackoverflow.com/q/14340113
https://stackoverflow.com/a/14340237
<p>The syntax you used (<code>\d</code>) is not recognised by <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_01.html#sect_04_01_03" rel="noreferrer">Bash's Extended regex</a>. </p> <p>Use <code>grep -P</code> instead which uses Perl regex (PCRE). For example:</p> <pre><code>grep -P "\d+/\d+/\d+" input...
<p>The syntax you used (<code>\d</code>) is not recognised by <a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_01.html#sect_04_01_03" rel="noreferrer">Bash's Extended regex</a>. </p> <p>Use <code>grep -P</code> instead which uses Perl regex (PCRE). For example:</p> <pre><code>grep -P "\d+/\d+/\d+" input...
18, 387, 390, 1271
bash, grep, regex, shell
<h1>Bash (grep) regex performing unexpectedly</h1> <p>I have a text file, which contains a date in the form of <code>dd/mm/yyyy</code> (e.g 20/12/2012).</p> <p>I am trying to use <code>grep</code> to parse the date and show it in the terminal, and it is successful, until I meet a certain case:</p> <p>These are my te...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,941
bash
# Bash (grep) regex performing unexpectedly I have a text file, which contains a date in the form of `dd/mm/yyyy` (e.g 20/12/2012). I am trying to use `grep` to parse the date and show it in the terminal, and it is successful, until I meet a certain case: These are my test cases: - `grep -E "\d*"` returns 20/12/201...
The syntax you used (`\d`) is not recognised by [Bash's Extended regex](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_01.html#sect_04_01_03). Use `grep -P` instead which uses Perl regex (PCRE). For example: ``` grep -P "\d+/\d+/\d+" input.txt grep -P "\d{2}/\d{2}/\d{4}" input.txt # more restrictive ``` Or, ...
14282208
How can I use Groovy to execute a shell command that has backticks?
8
2013-01-11 16:17:17
<p>I’m unable to use Groovy to execute a shell command that has backticks. A simplified example:</p> <pre><code>println "echo `date`".execute().text </code></pre> <p>I searched around and tried to figure out how to escape them somehow, but without luck.</p>
12,294
363,281
2013-01-14 22:36:28
14,282,313
12
2013-01-11 16:22:43
1,517,161
2013-01-11 16:50:40
https://stackoverflow.com/q/14282208
https://stackoverflow.com/a/14282313
<p>What happens if you try:</p> <pre><code>println ["bash", "-c", "echo `date`"].execute().text </code></pre> <p>My guess would be that with </p> <pre><code>"echo `date`".execute() </code></pre> <p>java's <code>Runtime#exec(String)</code> would be used underneath, if you were calling <code>execute()</code> on a St...
<p>What happens if you try:</p> <pre><code>println ["bash", "-c", "echo `date`"].execute().text </code></pre> <p>My guess would be that with </p> <pre><code>"echo `date`".execute() </code></pre> <p>java's <code>Runtime#exec(String)</code> would be used underneath, if you were calling <code>execute()</code> on a St...
387, 390, 849, 28438
backticks, bash, groovy, shell
<h1>How can I use Groovy to execute a shell command that has backticks?</h1> <p>I’m unable to use Groovy to execute a shell command that has backticks. A simplified example:</p> <pre><code>println "echo `date`".execute().text </code></pre> <p>I searched around and tried to figure out how to escape them somehow, but w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,942
bash
# How can I use Groovy to execute a shell command that has backticks? I’m unable to use Groovy to execute a shell command that has backticks. A simplified example: ``` println "echo `date`".execute().text ``` I searched around and tried to figure out how to escape them somehow, but without luck.
What happens if you try: ``` println ["bash", "-c", "echo `date`"].execute().text ``` My guess would be that with ``` "echo `date`".execute() ``` java's `Runtime#exec(String)` would be used underneath, if you were calling `execute()` on a String. In which case, this simply tokenizes the string and executes the prog...
13394196
How to check if a Powershell script is running remotely
8
2012-11-15 09:01:04
<p>I have a script that can be run either locally or remotely (via WinRM), however I would like it to behave slightly differently when run on a remote machine. I realise that I can pass in a switch to the script to identify whether it is running locally or remotely, but I want to know if it is possible for the script ...
7,009
83,282
2015-09-02 23:41:25
13,395,178
12
2012-11-15 10:04:52
67,392
2012-11-15 10:04:52
https://stackoverflow.com/q/13394196
https://stackoverflow.com/a/13395178
<p><code>Get-Host</code> returns, amongst other information a <code>Name</code>:</p> <pre> PS> (Get-Host).Name ConsoleHost PS> (Invoke-Command -ComputerName dev2 -Script {Get-Host}).Name ServerRemoteHost </pre>
<p><code>Get-Host</code> returns, amongst other information a <code>Name</code>:</p> <pre> PS> (Get-Host).Name ConsoleHost PS> (Invoke-Command -ComputerName dev2 -Script {Get-Host}).Name ServerRemoteHost </pre>
526, 63177
powershell, powershell-remoting
<h1>How to check if a Powershell script is running remotely</h1> <p>I have a script that can be run either locally or remotely (via WinRM), however I would like it to behave slightly differently when run on a remote machine. I realise that I can pass in a switch to the script to identify whether it is running locally ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,943
bash
# How to check if a Powershell script is running remotely I have a script that can be run either locally or remotely (via WinRM), however I would like it to behave slightly differently when run on a remote machine. I realise that I can pass in a switch to the script to identify whether it is running locally or remotel...
`Get-Host` returns, amongst other information a `Name`: ``` PS> (Get-Host).Name ConsoleHost PS> (Invoke-Command -ComputerName dev2 -Script {Get-Host}).Name ServerRemoteHost ```
13322119
How to make script in linux use my interpteter and work? (#!)
8
2012-11-10 12:36:40
<p>I've made a simple shell for linux. It's reading line by line with getline() until ctrl+d (eof/-1) is entered into standard input.</p> <p>While entering into stdin line by line code like that:</p> <pre><code>ls -al &amp; ls -a -l </code></pre> <p>My shell works pretty well.</p> <p>I've tried to run script throug...
267
1,162,289
2012-11-10 13:26:37
13,322,323
12
2012-11-10 13:09:08
856,199
2012-11-10 13:26:37
https://stackoverflow.com/q/13322119
https://stackoverflow.com/a/13322323
<p>Your shell must accept command line arguments. In this case, your program will be called like this:</p> <pre>/home/arbuz/Patryk/projekt/a.out your_script</pre> <p>So you'll need a <code>main()</code> of this signature:</p> <pre><code>int main(int argc, char* argv[]) </code></pre> <p>and then parse the arguments....
<p>Your shell must accept command line arguments. In this case, your program will be called like this:</p> <pre>/home/arbuz/Patryk/projekt/a.out your_script</pre> <p>So you'll need a <code>main()</code> of this signature:</p> <pre><code>int main(int argc, char* argv[]) </code></pre> <p>and then parse the arguments....
8, 58, 390
c, linux, shell
<h1>How to make script in linux use my interpteter and work? (#!)</h1> <p>I've made a simple shell for linux. It's reading line by line with getline() until ctrl+d (eof/-1) is entered into standard input.</p> <p>While entering into stdin line by line code like that:</p> <pre><code>ls -al &amp; ls -a -l </code></pre> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,944
bash
# How to make script in linux use my interpteter and work? (#!) I've made a simple shell for linux. It's reading line by line with getline() until ctrl+d (eof/-1) is entered into standard input. While entering into stdin line by line code like that: ``` ls -al & ls -a -l ``` My shell works pretty well. I've tried ...
Your shell must accept command line arguments. In this case, your program will be called like this: ``` /home/arbuz/Patryk/projekt/a.out your_script ``` So you'll need a `main()` of this signature: ``` int main(int argc, char* argv[]) ``` and then parse the arguments. `argc` contains the amount of arguments. The sc...
13241964
How do I get a user's friendly username on UNIX?
8
2012-11-05 23:17:18
<p>I want to get the "friendly" name, not the username, at least if such a string exists for the given user. Things I've tried:</p> <pre><code>whoami jamesarosen id -un jamesarosen id -p uid jamesarosen groups staff com.apple.access_screensharing ... id -P jamesarosen:********:501:20::0:0:James A. Rosen:/Users/jam...
8,541
1,190
2018-03-13 00:53:48
13,242,044
12
2012-11-05 23:24:24
1,301,972
2012-11-05 23:24:24
https://stackoverflow.com/q/13241964
https://stackoverflow.com/a/13242044
<h3>Parse the GECOS Field for User's Full Name</h3> <p>The format of /etc/passwd and most of the <a href="http://en.wikipedia.org/wiki/Gecos_field">GECOS field</a> is extremely well standardized across Unix-like systems. If you find an exception, by all means let us know. Meanwhile, the easiest way to get what you wan...
<h3>Parse the GECOS Field for User's Full Name</h3> <p>The format of /etc/passwd and most of the <a href="http://en.wikipedia.org/wiki/Gecos_field">GECOS field</a> is extremely well standardized across Unix-like systems. If you find an exception, by all means let us know. Meanwhile, the easiest way to get what you wan...
34, 387
bash, unix
<h1>How do I get a user's friendly username on UNIX?</h1> <p>I want to get the "friendly" name, not the username, at least if such a string exists for the given user. Things I've tried:</p> <pre><code>whoami jamesarosen id -un jamesarosen id -p uid jamesarosen groups staff com.apple.access_screensharing ... id -P ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,945
bash
# How do I get a user's friendly username on UNIX? I want to get the "friendly" name, not the username, at least if such a string exists for the given user. Things I've tried: ``` whoami jamesarosen id -un jamesarosen id -p uid jamesarosen groups staff com.apple.access_screensharing ... id -P jamesarosen:********...
### Parse the GECOS Field for User's Full Name The format of /etc/passwd and most of the [GECOS field](http://en.wikipedia.org/wiki/Gecos_field) is extremely well standardized across Unix-like systems. If you find an exception, by all means let us know. Meanwhile, the easiest way to get what you want on a Unix-like sy...
12693327
Running a PowerShell script as administrator without typing in passwords
8
2012-10-02 15:24:07
<p>I wrote a script that will switch between having a computer connect via Wi-Fi or wired Internet simply by running a batch file. I wrote this because I don't like having to type in my username and password to switch between the two every time.</p> <p>NOTE: I HAVE to have UAC enabled so unfortunately just turning it ...
103,305
1,315,828
2020-11-12 04:36:06
12,694,463
12
2012-10-02 16:34:01
153,982
2012-10-02 21:00:26
https://stackoverflow.com/q/12693327
https://stackoverflow.com/a/12694463
<p>You can start a new, elevated PowerShell process to run your script e.g.:</p> <pre><code>Start-Process PowerShell -verb runas -ArgumentList '-noexit','-File','path-to-script' </code></pre> <p>If you don't want the PowerShell window to hang around then get rid of the <code>'-noexit'</code> but for debugging the lau...
<p>You can start a new, elevated PowerShell process to run your script e.g.:</p> <pre><code>Start-Process PowerShell -verb runas -ArgumentList '-noexit','-File','path-to-script' </code></pre> <p>If you don't want the PowerShell window to hang around then get rid of the <code>'-noexit'</code> but for debugging the lau...
526, 1980
powershell, uac
<h1>Running a PowerShell script as administrator without typing in passwords</h1> <p>I wrote a script that will switch between having a computer connect via Wi-Fi or wired Internet simply by running a batch file. I wrote this because I don't like having to type in my username and password to switch between the two ever...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,946
bash
# Running a PowerShell script as administrator without typing in passwords I wrote a script that will switch between having a computer connect via Wi-Fi or wired Internet simply by running a batch file. I wrote this because I don't like having to type in my username and password to switch between the two every time. ...
You can start a new, elevated PowerShell process to run your script e.g.: ``` Start-Process PowerShell -verb runas -ArgumentList '-noexit','-File','path-to-script' ``` If you don't want the PowerShell window to hang around then get rid of the `'-noexit'` but for debugging the launch of your script, it is useful. If ...
12590490
Splitting Filename delimited by period (.)
8
2012-09-25 20:24:19
<p>I'm writting an sh file where I have var as: </p> <pre><code>c=aabbcc.DP.09-25-2012_14_17.dmp </code></pre> <p>i want to copy only initial part in another var like:</p> <pre><code>d = aabbcc </code></pre> <p>How should I trim my var?</p>
20,687
730,549
2012-10-01 08:35:54
12,590,520
12
2012-09-25 20:26:43
95,382
2012-09-25 20:26:43
https://stackoverflow.com/q/12590490
https://stackoverflow.com/a/12590520
<p>If by <code>sh</code> you mean <code>bash</code>, then</p> <pre><code>d="${c%%.*}" </code></pre> <p>otherwise</p> <pre><code>d="`echo "$d"|cut -d. -f1`" </code></pre> <p>will do, perhaps.</p>
<p>If by <code>sh</code> you mean <code>bash</code>, then</p> <pre><code>d="${c%%.*}" </code></pre> <p>otherwise</p> <pre><code>d="`echo "$d"|cut -d. -f1`" </code></pre> <p>will do, perhaps.</p>
990, 10327
awk, sh
<h1>Splitting Filename delimited by period (.)</h1> <p>I'm writting an sh file where I have var as: </p> <pre><code>c=aabbcc.DP.09-25-2012_14_17.dmp </code></pre> <p>i want to copy only initial part in another var like:</p> <pre><code>d = aabbcc </code></pre> <p>How should I trim my var?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,947
bash
# Splitting Filename delimited by period (.) I'm writting an sh file where I have var as: ``` c=aabbcc.DP.09-25-2012_14_17.dmp ``` i want to copy only initial part in another var like: ``` d = aabbcc ``` How should I trim my var?
If by `sh` you mean `bash`, then ``` d="${c%%.*}" ``` otherwise ``` d="`echo "$d"|cut -d. -f1`" ``` will do, perhaps.
11666070
Progress bar during smbclient put
8
2012-07-26 09:15:42
<p>I'm trying to show a progress bar during a remote copy using smbclient put, maybe using <strong>pv</strong> or <strong>dialog</strong>, or any other option.</p> <p>The smbclient-put command il working fine: </p> <pre><code>smbclient //usbrouter/backup --user=myusername mypassword -c "put /media/DOC/BackupAuto/work...
8,218
902,364
2020-04-12 22:09:05
11,666,660
12
2012-07-26 09:47:21
430,766
2017-06-20 09:34:02
https://stackoverflow.com/q/11666070
https://stackoverflow.com/a/11666660
<p>What I do when I want to check up on a file transfer operation that either doesn't support progress bars or I forgot to start it in a progress bar mode is this.</p> <p>Figure out the total size of your local copy of the file (<code>work_backup.tar.gz</code>) e.g. with <code>ls</code>, <code>stat</code> or <code>du<...
<p>What I do when I want to check up on a file transfer operation that either doesn't support progress bars or I forgot to start it in a progress bar mode is this.</p> <p>Figure out the total size of your local copy of the file (<code>work_backup.tar.gz</code>) e.g. with <code>ls</code>, <code>stat</code> or <code>du<...
58, 387
bash, linux
<h1>Progress bar during smbclient put</h1> <p>I'm trying to show a progress bar during a remote copy using smbclient put, maybe using <strong>pv</strong> or <strong>dialog</strong>, or any other option.</p> <p>The smbclient-put command il working fine: </p> <pre><code>smbclient //usbrouter/backup --user=myusername my...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,948
bash
# Progress bar during smbclient put I'm trying to show a progress bar during a remote copy using smbclient put, maybe using **pv** or **dialog**, or any other option. The smbclient-put command il working fine: ``` smbclient //usbrouter/backup --user=myusername mypassword -c "put /media/DOC/BackupAuto/work_backup.tar...
What I do when I want to check up on a file transfer operation that either doesn't support progress bars or I forgot to start it in a progress bar mode is this. Figure out the total size of your local copy of the file (`work_backup.tar.gz`) e.g. with `ls`, `stat` or `du`. Then go to the location of the target file (ei...
11618428
How to execute shell builtin from Scala
8
2012-07-23 18:37:10
<p>I need to check some system settings like <code>ulimit -n</code> from Scala script in Linux. Had I to deal with ordinary commands I would use <code>scala.sys.process</code> package like:</p> <pre><code>import scala.sys.process._ println("ls -lha".!!) </code></pre> <p>Unfortunately this doesn't work for shell built...
5,334
1,196,771
2012-07-23 19:06:59
11,618,758
12
2012-07-23 19:01:29
53,013
2012-07-23 19:06:59
https://stackoverflow.com/q/11618428
https://stackoverflow.com/a/11618758
<p>When strings are converted to a shell command, parameters are separated by space. The conventions you tried are <em>shell</em> conventions, so you'd need a shell to begin with to apply them.</p> <p>If you want more control over what each parameter is, use a <code>Seq[String]</code> instead of a <code>String</code>,...
<p>When strings are converted to a shell command, parameters are separated by space. The conventions you tried are <em>shell</em> conventions, so you'd need a shell to begin with to apply them.</p> <p>If you want more control over what each parameter is, use a <code>Seq[String]</code> instead of a <code>String</code>,...
58, 390, 3143
linux, scala, shell
<h1>How to execute shell builtin from Scala</h1> <p>I need to check some system settings like <code>ulimit -n</code> from Scala script in Linux. Had I to deal with ordinary commands I would use <code>scala.sys.process</code> package like:</p> <pre><code>import scala.sys.process._ println("ls -lha".!!) </code></pre> <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,949
bash
# How to execute shell builtin from Scala I need to check some system settings like `ulimit -n` from Scala script in Linux. Had I to deal with ordinary commands I would use `scala.sys.process` package like: ``` import scala.sys.process._ println("ls -lha".!!) ``` Unfortunately this doesn't work for shell builtins. I...
When strings are converted to a shell command, parameters are separated by space. The conventions you tried are *shell* conventions, so you'd need a shell to begin with to apply them. If you want more control over what each parameter is, use a `Seq[String]` instead of a `String`, or one of the `Process` factories that...
11369836
select -first 1 on a large file
8
2012-07-06 21:24:47
<p>I am trying to run the following command on a very large text file. However, it's very slow</p> <pre><code>((cat largefile.txt | select -first 1).split(",")).count() </code></pre> <p>Is an alternative fast way in powershell? It seems the command will scan the whole file no matter what. </p>
6,780
825,920
2016-05-13 18:34:25
11,369,924
12
2012-07-06 21:32:46
1,021,945
2012-07-06 21:45:12
https://stackoverflow.com/q/11369836
https://stackoverflow.com/a/11369924
<p>To only get the first x number of lines in a text file, use the –totalcount parameter:</p> <pre><code>((Get-Content largefile.txt -totalcount 1).split(",")).count </code></pre>
<p>To only get the first x number of lines in a text file, use the –totalcount parameter:</p> <pre><code>((Get-Content largefile.txt -totalcount 1).split(",")).count </code></pre>
526
powershell
<h1>select -first 1 on a large file</h1> <p>I am trying to run the following command on a very large text file. However, it's very slow</p> <pre><code>((cat largefile.txt | select -first 1).split(",")).count() </code></pre> <p>Is an alternative fast way in powershell? It seems the command will scan the whole file no ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,950
bash
# select -first 1 on a large file I am trying to run the following command on a very large text file. However, it's very slow ``` ((cat largefile.txt | select -first 1).split(",")).count() ``` Is an alternative fast way in powershell? It seems the command will scan the whole file no matter what.
To only get the first x number of lines in a text file, use the –totalcount parameter: ``` ((Get-Content largefile.txt -totalcount 1).split(",")).count ```
10840196
aborting git pre-commit hook when var_dump present
8
2012-05-31 19:39:36
<p>I am trying (but failing miserably) to make a git pre-commit hook that checks for the presence of a var_dump in my modified files and exits if it finds one. The problem that I'm having is that it appears to always be aborting the commit. Here is the contents of my pre-commit file:</p> <pre><code>VAR=$(git diff | gr...
5,260
435,471
2018-11-14 12:20:00
10,840,525
12
2012-05-31 20:05:44
718,180
2012-05-31 20:11:50
https://stackoverflow.com/q/10840196
https://stackoverflow.com/a/10840525
<p>First of all, note that plain <code>git diff</code> gives the difference between the working tree and the index (i.e. what can still be staged), not what is about to be committed. Use <code>git diff --cached</code> to see what is about to be committed.</p> <p>The second thing I encountered as I was experimenting w...
<p>First of all, note that plain <code>git diff</code> gives the difference between the working tree and the index (i.e. what can still be staged), not what is about to be committed. Use <code>git diff --cached</code> to see what is about to be committed.</p> <p>The second thing I encountered as I was experimenting w...
119, 387, 43087
bash, git, githooks
<h1>aborting git pre-commit hook when var_dump present</h1> <p>I am trying (but failing miserably) to make a git pre-commit hook that checks for the presence of a var_dump in my modified files and exits if it finds one. The problem that I'm having is that it appears to always be aborting the commit. Here is the content...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,951
bash
# aborting git pre-commit hook when var_dump present I am trying (but failing miserably) to make a git pre-commit hook that checks for the presence of a var_dump in my modified files and exits if it finds one. The problem that I'm having is that it appears to always be aborting the commit. Here is the contents of my p...
First of all, note that plain `git diff` gives the difference between the working tree and the index (i.e. what can still be staged), not what is about to be committed. Use `git diff --cached` to see what is about to be committed. The second thing I encountered as I was experimenting was that using `if [ -z $VAR ]` di...
10535816
My powershell script is printing a '1' before my expected output. Why?
8
2012-05-10 14:10:19
<p>I wrote a simple powershell script that checks the number of tickets in a PSA service board and outputs the number of tickets and a color associated with it. However, my script is printing a '1' before the results. I am very new to powershell, and I can't seem to find the line that would print this. Any help would b...
6,018
1,203,147
2018-12-04 09:23:00
10,536,005
12
2012-05-10 14:19:53
311,712
2012-05-10 14:19:53
https://stackoverflow.com/q/10535816
https://stackoverflow.com/a/10536005
<pre><code>$SqlAdapter.Fill($DataSet) | Out-Null </code></pre> <p>Read here about <a href="http://msdn.microsoft.com/en-us/library/zxkb3c3d.aspx">DbDataAdapter.Fill</a> and its return value:</p> <p>Type: System.Int32 The number of rows successfully added to or refreshed in the DataSet. This does not include rows affe...
<pre><code>$SqlAdapter.Fill($DataSet) | Out-Null </code></pre> <p>Read here about <a href="http://msdn.microsoft.com/en-us/library/zxkb3c3d.aspx">DbDataAdapter.Fill</a> and its return value:</p> <p>Type: System.Int32 The number of rows successfully added to or refreshed in the DataSet. This does not include rows affe...
526, 24067
powershell, powershell-2.0
<h1>My powershell script is printing a '1' before my expected output. Why?</h1> <p>I wrote a simple powershell script that checks the number of tickets in a PSA service board and outputs the number of tickets and a color associated with it. However, my script is printing a '1' before the results. I am very new to power...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,952
bash
# My powershell script is printing a '1' before my expected output. Why? I wrote a simple powershell script that checks the number of tickets in a PSA service board and outputs the number of tickets and a color associated with it. However, my script is printing a '1' before the results. I am very new to powershell, an...
``` $SqlAdapter.Fill($DataSet) | Out-Null ``` Read here about [DbDataAdapter.Fill](http://msdn.microsoft.com/en-us/library/zxkb3c3d.aspx) and its return value: Type: System.Int32 The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return ...
10405515
piping in shell via Python subprocess module
8
2012-05-01 22:53:29
<p>So I'm trying to query for the top 3 CPU "intensive" processes on a given machine, and I found this shell command to do it: <code>ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3</code></p> <p>I want to use this data inside a Python script, so I need to be able to capture the output of the above command via the <...
9,170
613,973
2013-02-26 22:29:40
10,405,562
12
2012-05-01 22:59:26
35,070
2012-05-01 22:59:26
https://stackoverflow.com/q/10405515
https://stackoverflow.com/a/10405562
<p>You can pass the <code>shell=True</code> argument to execute the plain shell command:</p> <pre><code>import subprocess subprocess.check_output('ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3', shell=True) </code></pre> <p>Alternatively, use the sorting options of ps and Python's built-i...
<p>You can pass the <code>shell=True</code> argument to execute the plain shell command:</p> <pre><code>import subprocess subprocess.check_output('ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3', shell=True) </code></pre> <p>Alternatively, use the sorting options of ps and Python's built-i...
16, 390, 2348, 5813
pipe, python, shell, subprocess
<h1>piping in shell via Python subprocess module</h1> <p>So I'm trying to query for the top 3 CPU "intensive" processes on a given machine, and I found this shell command to do it: <code>ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3</code></p> <p>I want to use this data inside a Python script, so I need to be abl...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,953
bash
# piping in shell via Python subprocess module So I'm trying to query for the top 3 CPU "intensive" processes on a given machine, and I found this shell command to do it: `ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3` I want to use this data inside a Python script, so I need to be able to capture the output of ...
You can pass the `shell=True` argument to execute the plain shell command: ``` import subprocess subprocess.check_output('ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3', shell=True) ``` Alternatively, use the sorting options of ps and Python's built-in string functions like this: ``` raw...
9217120
How to trigger T4 template from PowerShell script
8
2012-02-09 19:05:59
<p>In my VS2010 solution I have set of Powershell scripts and T4 templates based on T4Scaffolding NuGet, everything is working fine with scaffolding and related T4's, but in one of my scripts I need to trigger a T4 template located in another project. </p> <p>Any simple Powershel cmdlet for this? to just run the templ...
4,165
365,469
2022-08-30 16:36:07
9,251,834
12
2012-02-12 19:17:36
753,279
2012-02-12 19:17:36
https://stackoverflow.com/q/9217120
https://stackoverflow.com/a/9251834
<p>It looks like you can just invoke their command line utility, so you could create a script that just takes the location of your .tt file.</p> <pre><code>param([string] $T4Template) &amp; "C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe" $T4Template </code></pre> <p>Save ...
<p>It looks like you can just invoke their command line utility, so you could create a script that just takes the location of your .tt file.</p> <pre><code>param([string] $T4Template) &amp; "C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe" $T4Template </code></pre> <p>Save ...
526, 767, 2397, 14456
code-generation, powershell, t4, visual-studio-2010
<h1>How to trigger T4 template from PowerShell script</h1> <p>In my VS2010 solution I have set of Powershell scripts and T4 templates based on T4Scaffolding NuGet, everything is working fine with scaffolding and related T4's, but in one of my scripts I need to trigger a T4 template located in another project. </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,954
bash
# How to trigger T4 template from PowerShell script In my VS2010 solution I have set of Powershell scripts and T4 templates based on T4Scaffolding NuGet, everything is working fine with scaffolding and related T4's, but in one of my scripts I need to trigger a T4 template located in another project. Any simple Powers...
It looks like you can just invoke their command line utility, so you could create a script that just takes the location of your .tt file. ``` param([string] $T4Template) & "C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe" $T4Template ``` Save above as ExecTextTransform.ps1 ...
9117274
Do I need to generate a second file to sort a file?
8
2012-02-02 17:49:55
<p>I want to sort a bunch of files. I can do</p> <pre><code>sort file.txt &gt; foo.txt mv foo.txt file.txt </code></pre> <p>but do I need this second file? </p> <p>(I tried <code>sort file.txt &gt; file.txt</code> of course, but then I just ended up with an empty file.)</p>
5,177
662,939
2016-02-23 03:02:04
9,117,356
12
2012-02-02 17:54:59
377,639
2012-02-02 17:54:59
https://stackoverflow.com/q/9117274
https://stackoverflow.com/a/9117356
<p>Try:</p> <pre><code>sort -o file.txt file.txt </code></pre> <p>See <a href="http://ss64.com/bash/sort.html" rel="noreferrer">http://ss64.com/bash/sort.html</a></p> <pre><code>`-o OUTPUT-FILE' Write output to OUTPUT-FILE instead of standard output. If OUTPUT-FILE is one of the input files, `sort' copies...
<p>Try:</p> <pre><code>sort -o file.txt file.txt </code></pre> <p>See <a href="http://ss64.com/bash/sort.html" rel="noreferrer">http://ss64.com/bash/sort.html</a></p> <pre><code>`-o OUTPUT-FILE' Write output to OUTPUT-FILE instead of standard output. If OUTPUT-FILE is one of the input files, `sort' copies...
134, 387, 390, 724
bash, file-io, shell, sorting
<h1>Do I need to generate a second file to sort a file?</h1> <p>I want to sort a bunch of files. I can do</p> <pre><code>sort file.txt &gt; foo.txt mv foo.txt file.txt </code></pre> <p>but do I need this second file? </p> <p>(I tried <code>sort file.txt &gt; file.txt</code> of course, but then I just ended up with a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,955
bash
# Do I need to generate a second file to sort a file? I want to sort a bunch of files. I can do ``` sort file.txt > foo.txt mv foo.txt file.txt ``` but do I need this second file? (I tried `sort file.txt > file.txt` of course, but then I just ended up with an empty file.)
Try: ``` sort -o file.txt file.txt ``` See <http://ss64.com/bash/sort.html> ``` `-o OUTPUT-FILE' Write output to OUTPUT-FILE instead of standard output. If OUTPUT-FILE is one of the input files, `sort' copies it to a temporary file before sorting and writing the output to OUTPUT-FILE. ```
8333880
While loop, how to read from second line of text file
8
2011-11-30 22:28:38
<p>i've tried everything for the past 2 hours to get this working but my experience in shell and programming is limited.</p> <p>I have a loop</p> <pre><code>while IFS="," read var1 var2 var3 var4 var5 ; do statements here... done &lt; $file </code></pre> <p>Now the operation inside statement is to read from a text...
18,185
1,055,321
2014-06-09 17:57:28
8,334,030
12
2011-11-30 22:40:04
149,872
2011-11-30 22:40:04
https://stackoverflow.com/q/8333880
https://stackoverflow.com/a/8334030
<p>Use sed to "delete" the first line from the input passed to the while loop</p> <pre><code>sed 1d $file | while ... do your statements here done </code></pre>
<p>Use sed to "delete" the first line from the input passed to the while loop</p> <pre><code>sed 1d $file | while ... do your statements here done </code></pre>
387
bash
<h1>While loop, how to read from second line of text file</h1> <p>i've tried everything for the past 2 hours to get this working but my experience in shell and programming is limited.</p> <p>I have a loop</p> <pre><code>while IFS="," read var1 var2 var3 var4 var5 ; do statements here... done &lt; $file </code></pre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,956
bash
# While loop, how to read from second line of text file i've tried everything for the past 2 hours to get this working but my experience in shell and programming is limited. I have a loop ``` while IFS="," read var1 var2 var3 var4 var5 ; do statements here... done < $file ``` Now the operation inside statement is...
Use sed to "delete" the first line from the input passed to the while loop ``` sed 1d $file | while ... do your statements here done ```
8089351
exec() any command in C
8
2011-11-11 03:32:09
<p>Say in C, I want to call <code>execvp()</code> on any string command. Command can just be:</p> <pre><code>char command[] = "ls -l"; char command[] = "rm *.txt"; char command[] = "cat makefile"; </code></pre> <p>I want to put this command variable inside <code>execvp()</code>. So the <code>exec()</code> flavored ...
28,898
864,493
2011-11-12 09:12:55
8,089,381
12
2011-11-11 03:37:52
14,860
2011-11-12 09:12:55
https://stackoverflow.com/q/8089351
https://stackoverflow.com/a/8089381
<p>If you <em>have</em> to call <code>execvp()</code>, then you will need to split up those strings into an executable name and an array of arguments (the first being the "name" of the program and the last being a NULL pointer).</p> <p>That means something like:</p> <pre><code>char cmd1[] = "ls"; char *args1[] = {"l...
<p>If you <em>have</em> to call <code>execvp()</code>, then you will need to split up those strings into an executable name and an array of arguments (the first being the "name" of the program and the last being a NULL pointer).</p> <p>That means something like:</p> <pre><code>char cmd1[] = "ls"; char *args1[] = {"l...
8, 58, 390, 26596
c, execvp, linux, shell
<h1>exec() any command in C</h1> <p>Say in C, I want to call <code>execvp()</code> on any string command. Command can just be:</p> <pre><code>char command[] = "ls -l"; char command[] = "rm *.txt"; char command[] = "cat makefile"; </code></pre> <p>I want to put this command variable inside <code>execvp()</code>. So ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,957
bash
# exec() any command in C Say in C, I want to call `execvp()` on any string command. Command can just be: ``` char command[] = "ls -l"; char command[] = "rm *.txt"; char command[] = "cat makefile"; ``` I want to put this command variable inside `execvp()`. So the `exec()` flavored function can just run with any kind...
If you *have* to call `execvp()`, then you will need to split up those strings into an executable name and an array of arguments (the first being the "name" of the program and the last being a NULL pointer). That means something like: ``` char cmd1[] = "ls"; char *args1[] = {"ls", "-l", NULL}; char cmd1[] = "rm"; c...
6595429
Using sed to remove all console.log from javascript file
8
2011-07-06 11:10:00
<p>I'm trying to remove all my <code>console.log</code>, <code>console.dir</code> etc. from my JS file before minifying it with YUI (<strong>on osx</strong>).</p> <p>The regex I got for the console statements looks like this:</p> <pre><code>console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|tim...
7,895
388,026
2018-07-10 15:33:11
6,598,788
12
2011-07-06 15:16:57
119,159
2011-07-06 15:16:57
https://stackoverflow.com/q/6595429
https://stackoverflow.com/a/6598788
<p>Your original expression looks fine. You just need to pass the <code>-E</code> flag to <code>sed</code>, for <strong>extended</strong> regular expressions:</p> <pre><code>sed -E 's/console.(log|debug|info|...|count)\((.*)\);?//g' </code></pre> <p>The difference between these types of regular expressions is explain...
<p>Your original expression looks fine. You just need to pass the <code>-E</code> flag to <code>sed</code>, for <strong>extended</strong> regular expressions:</p> <pre><code>sed -E 's/console.(log|debug|info|...|count)\((.*)\);?//g' </code></pre> <p>The difference between these types of regular expressions is explain...
18, 387, 5282
bash, regex, sed
<h1>Using sed to remove all console.log from javascript file</h1> <p>I'm trying to remove all my <code>console.log</code>, <code>console.dir</code> etc. from my JS file before minifying it with YUI (<strong>on osx</strong>).</p> <p>The regex I got for the console statements looks like this:</p> <pre><code>console.(lo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,958
bash
# Using sed to remove all console.log from javascript file I'm trying to remove all my `console.log`, `console.dir` etc. from my JS file before minifying it with YUI (**on osx**). The regex I got for the console statements looks like this: ``` console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd...
Your original expression looks fine. You just need to pass the `-E` flag to `sed`, for **extended** regular expressions: ``` sed -E 's/console.(log|debug|info|...|count)\((.*)\);?//g' ``` The difference between these types of regular expressions is explained in `man re_format`. To be honest I have never read that pag...
5482513
Powershell add-content line breaks
8
2011-03-30 06:07:53
<p>I am trying to figure out how to eliminate line breaks when using add-content</p> <pre><code>echo $server "Uptime: " $uptime.days ", Days" $uptime.hours ", Hours" $uptime.minutes ", Minutes" | add-content $output_file </code></pre> <p>Basically I have been trying to get the uptime of a server to go to a text file,...
19,803
683,371
2013-06-22 23:11:15
5,482,616
12
2011-03-30 06:19:10
75,224
2011-03-30 07:11:21
https://stackoverflow.com/q/5482513
https://stackoverflow.com/a/5482616
<p>I guess you want to have one line with the info, then:</p> <pre><code>"$server Uptime: $($uptime.days) Days, $($uptime.hours) Hours, $($uptime.minutes) Minutes" | add-content $output_file </code></pre> <p>If every item should be on separate line, you might add <em>`n</em></p> <pre><code>"$server Uptime`n$($uptime...
<p>I guess you want to have one line with the info, then:</p> <pre><code>"$server Uptime: $($uptime.days) Days, $($uptime.hours) Hours, $($uptime.minutes) Minutes" | add-content $output_file </code></pre> <p>If every item should be on separate line, you might add <em>`n</em></p> <pre><code>"$server Uptime`n$($uptime...
526, 9313
line-breaks, powershell
<h1>Powershell add-content line breaks</h1> <p>I am trying to figure out how to eliminate line breaks when using add-content</p> <pre><code>echo $server "Uptime: " $uptime.days ", Days" $uptime.hours ", Hours" $uptime.minutes ", Minutes" | add-content $output_file </code></pre> <p>Basically I have been trying to get ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,959
bash
# Powershell add-content line breaks I am trying to figure out how to eliminate line breaks when using add-content ``` echo $server "Uptime: " $uptime.days ", Days" $uptime.hours ", Hours" $uptime.minutes ", Minutes" | add-content $output_file ``` Basically I have been trying to get the uptime of a server to go to a...
I guess you want to have one line with the info, then: ``` "$server Uptime: $($uptime.days) Days, $($uptime.hours) Hours, $($uptime.minutes) Minutes" | add-content $output_file ``` If every item should be on separate line, you might add *`n* ``` "$server Uptime`n$($uptime.days) Days`n$($uptime.hours) Hours`n$($uptim...
5343420
How to compare in shell script?
8
2011-03-17 18:19:27
<p>How to compare in shell script?</p> <p>Or, why the following script prints nothing?</p> <pre><code>x=1 if[ $x = 1 ] then echo "ok" else echo "no" fi </code></pre>
53,709
287,316
2018-08-08 07:25:24
5,343,461
12
2011-03-17 18:22:55
636,505
2011-03-17 18:29:03
https://stackoverflow.com/q/5343420
https://stackoverflow.com/a/5343461
<p>With numbers, use <code>-eq</code>, <code>-ne</code>, ... for equals, not equals, ...</p> <pre><code>x=1 if [ $x -eq 1 ] then echo "ok" else echo "no" fi </code></pre> <p>And for others, use <code>==</code> not <code>=</code>.</p>
<p>With numbers, use <code>-eq</code>, <code>-ne</code>, ... for equals, not equals, ...</p> <pre><code>x=1 if [ $x -eq 1 ] then echo "ok" else echo "no" fi </code></pre> <p>And for others, use <code>==</code> not <code>=</code>.</p>
58, 387, 390, 1231
bash, command-line, linux, shell
<h1>How to compare in shell script?</h1> <p>How to compare in shell script?</p> <p>Or, why the following script prints nothing?</p> <pre><code>x=1 if[ $x = 1 ] then echo "ok" else echo "no" fi </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,960
bash
# How to compare in shell script? How to compare in shell script? Or, why the following script prints nothing? ``` x=1 if[ $x = 1 ] then echo "ok" else echo "no" fi ```
With numbers, use `-eq`, `-ne`, ... for equals, not equals, ... ``` x=1 if [ $x -eq 1 ] then echo "ok" else echo "no" fi ``` And for others, use `==` not `=`.
5146721
Surgical XML editing with Powershell
8
2011-02-28 19:39:19
<p>I'm working with csproj files using Powershell to perform large-scale editing of project references. So far I've managed to edit the Include attributes on ProjectReferences using the following lines:</p> <pre><code> $projectXml = [xml](Get-Content $_.Project.FullName) Add-TfsPendingChange -edit $_.Project.Fu...
2,153
307,163
2011-11-01 01:24:44
5,149,368
12
2011-03-01 00:55:12
153,982
2011-03-02 23:13:04
https://stackoverflow.com/q/5146721
https://stackoverflow.com/a/5149368
<p>I did a lot of VS project manipulation a few years back. Seems like creating the XmlDocument and using Load directly (versus using Get-Content and casting to XML) worked better for me:</p> <pre><code>$path = "C:\temp\foo.csproj" $proj = new-object system.xml.xmldocument $proj.PreserveWhitespace = $true $proj.Load(...
<p>I did a lot of VS project manipulation a few years back. Seems like creating the XmlDocument and using Load directly (versus using Get-Content and casting to XML) worked better for me:</p> <pre><code>$path = "C:\temp\foo.csproj" $proj = new-object system.xml.xmldocument $proj.PreserveWhitespace = $true $proj.Load(...
19, 526, 555, 5991, 63767
formatting, powershell, select-xml, side-effects, xml
<h1>Surgical XML editing with Powershell</h1> <p>I'm working with csproj files using Powershell to perform large-scale editing of project references. So far I've managed to edit the Include attributes on ProjectReferences using the following lines:</p> <pre><code> $projectXml = [xml](Get-Content $_.Project.FullName...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,961
bash
# Surgical XML editing with Powershell I'm working with csproj files using Powershell to perform large-scale editing of project references. So far I've managed to edit the Include attributes on ProjectReferences using the following lines: ``` $projectXml = [xml](Get-Content $_.Project.FullName) Add-TfsPending...
I did a lot of VS project manipulation a few years back. Seems like creating the XmlDocument and using Load directly (versus using Get-Content and casting to XML) worked better for me: ``` $path = "C:\temp\foo.csproj" $proj = new-object system.xml.xmldocument $proj.PreserveWhitespace = $true $proj.Load($path) ... $pro...
5082149
Replace percent-escaped characters in string (%20, %5B, …) with bash
8
2011-02-22 18:19:28
<p>I have strings containing percent-escaped characters like <code>%20</code> and <code>%5B</code>, and I would like to transform it to "normal" characters like <code>\</code> for <code>%20</code> and <code>[</code> for <code>%5B</code>.</p> <p>How can I do that?</p>
17,186
407,213
2011-08-17 05:32:29
5,082,400
12
2011-02-22 18:42:06
115,405
2011-02-22 18:42:06
https://stackoverflow.com/q/5082149
https://stackoverflow.com/a/5082400
<p>The builtin printf in bash has a special format specifier (i.e. %b) which converts \x** to the corresponding value:</p> <pre><code>$ str='foo%20%5B12%5D' $ printf "%b\n" "${str//%/\\x}" foo [12] </code></pre>
<p>The builtin printf in bash has a special format specifier (i.e. %b) which converts \x** to the corresponding value:</p> <pre><code>$ str='foo%20%5B12%5D' $ printf "%b\n" "${str//%/\\x}" foo [12] </code></pre>
139, 387, 1843, 8944
ascii, bash, string, utf-8
<h1>Replace percent-escaped characters in string (%20, %5B, …) with bash</h1> <p>I have strings containing percent-escaped characters like <code>%20</code> and <code>%5B</code>, and I would like to transform it to "normal" characters like <code>\</code> for <code>%20</code> and <code>[</code> for <code>%5B</code>.</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,962
bash
# Replace percent-escaped characters in string (%20, %5B, …) with bash I have strings containing percent-escaped characters like `%20` and `%5B`, and I would like to transform it to "normal" characters like `\` for `%20` and `[` for `%5B`. How can I do that?
The builtin printf in bash has a special format specifier (i.e. %b) which converts \x** to the corresponding value: ``` $ str='foo%20%5B12%5D' $ printf "%b\n" "${str//%/\\x}" foo [12] ```
4953842
How to store result from SQLPlus to a shell variable
8
2011-02-10 05:51:04
<p>My requirement is to store the result of an sqlplus operation into a variable in my shell script. I need the result of the following operation which is in my .sh file</p> <pre><code>sqlplus 'user/pwd' @test.sql </code></pre> <p>I have already tried</p> <pre><code>testvar = 'sqlplus 'user/pwd' @test.sql' </code></pre...
95,705
16,488
2016-08-24 06:32:06
4,953,950
12
2011-02-10 06:13:10
199,305
2011-02-10 07:31:31
https://stackoverflow.com/q/4953842
https://stackoverflow.com/a/4953950
<p>Employ backticks:</p> <pre><code>testvar=`sqlplus foo/bar @test.sql` </code></pre> <p>or should that be of syntactical eyesore:</p> <pre><code>testvar=$(sqlplus foo/bar @test.sql) </code></pre> <p>You clearly know to take the right sql*plus commands to limit superfluous output, yes? :) and of course beware the b...
<p>Employ backticks:</p> <pre><code>testvar=`sqlplus foo/bar @test.sql` </code></pre> <p>or should that be of syntactical eyesore:</p> <pre><code>testvar=$(sqlplus foo/bar @test.sql) </code></pre> <p>You clearly know to take the right sql*plus commands to limit superfluous output, yes? :) and of course beware the b...
34, 390, 4480
shell, sqlplus, unix
<h1>How to store result from SQLPlus to a shell variable</h1> <p>My requirement is to store the result of an sqlplus operation into a variable in my shell script. I need the result of the following operation which is in my .sh file</p> <pre><code>sqlplus 'user/pwd' @test.sql </code></pre> <p>I have already tried</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,963
bash
# How to store result from SQLPlus to a shell variable My requirement is to store the result of an sqlplus operation into a variable in my shell script. I need the result of the following operation which is in my .sh file ``` sqlplus 'user/pwd' @test.sql ``` I have already tried ``` testvar = 'sqlplus 'user/pwd' @t...
Employ backticks: ``` testvar=`sqlplus foo/bar @test.sql` ``` or should that be of syntactical eyesore: ``` testvar=$(sqlplus foo/bar @test.sql) ``` You clearly know to take the right sql*plus commands to limit superfluous output, yes? :) and of course beware the backticking will collapse the whitespace of the outp...
1475366
BASH: Does it support conditional variables like var="test"?"1":"2"
8
2009-09-25 04:03:28
<p>I am new to bash but have done lots of PHP, and Javascript.</p> <p>Is there some sort of equivilent to this PHP?</p> <pre><code>$default = 10; $var = (!$var) ? $default : $var; </code></pre> <p>Thanks</p>
4,824
178,857
2013-01-25 13:58:28
1,475,388
12
2009-09-25 04:10:54
14,860
2013-01-25 13:58:28
https://stackoverflow.com/q/1475366
https://stackoverflow.com/a/1475388
<p>Yes, it does:</p> <pre><code>var=${var:-10} </code></pre> <p>Even with <em>other</em> variables:</p> <pre><code>unset var export def=99 echo ${var:-${def}} # gives '99' export var=7 echo ${var:-${def}} # gives '7' </code></pre>
<p>Yes, it does:</p> <pre><code>var=${var:-10} </code></pre> <p>Even with <em>other</em> variables:</p> <pre><code>unset var export def=99 echo ${var:-${def}} # gives '99' export var=7 echo ${var:-${def}} # gives '7' </code></pre>
276, 387, 39271
bash, conditional-statements, variables
<h1>BASH: Does it support conditional variables like var="test"?"1":"2"</h1> <p>I am new to bash but have done lots of PHP, and Javascript.</p> <p>Is there some sort of equivilent to this PHP?</p> <pre><code>$default = 10; $var = (!$var) ? $default : $var; </code></pre> <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
10,964
bash
# BASH: Does it support conditional variables like var="test"?"1":"2" I am new to bash but have done lots of PHP, and Javascript. Is there some sort of equivilent to this PHP? ``` $default = 10; $var = (!$var) ? $default : $var; ``` Thanks
Yes, it does: ``` var=${var:-10} ``` Even with *other* variables: ``` unset var export def=99 echo ${var:-${def}} # gives '99' export var=7 echo ${var:-${def}} # gives '7' ```
1087843
Run a script over multiple files in unix
8
2009-07-06 16:10:24
<p>Started to learn some shell scripting. I have a perl script that runs on one file. How would I write a shell script to run the perl script a bunch of times on all files with keyword "filename" in it?</p> <p>So in English, </p> <pre><code>for /filename/ in filenames perl myscript.pl completefilename </code>...
20,270
125,449
2017-07-02 11:31:40
1,087,880
12
2009-07-06 16:17:14
133,734
2017-07-02 11:31:30
https://stackoverflow.com/q/1087843
https://stackoverflow.com/a/1087880
<pre><code>find . -name "filename*" -exec perl myscript.pl '{}' \; </code></pre>
<pre><code>find . -name "filename*" -exec perl myscript.pl '{}' \; </code></pre>
34, 390
shell, unix
<h1>Run a script over multiple files in unix</h1> <p>Started to learn some shell scripting. I have a perl script that runs on one file. How would I write a shell script to run the perl script a bunch of times on all files with keyword "filename" in it?</p> <p>So in English, </p> <pre><code>for /filename/ in filenam...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,965
bash
# Run a script over multiple files in unix Started to learn some shell scripting. I have a perl script that runs on one file. How would I write a shell script to run the perl script a bunch of times on all files with keyword "filename" in it? So in English, ``` for /filename/ in filenames perl myscript.pl comp...
``` find . -name "filename*" -exec perl myscript.pl '{}' \; ```
1056440
undelete the deleted command in bash
8
2009-06-29 03:21:58
<p>If you have written a really long command, say <code>cd /very/long/path</code>, and then you do ctrl+c or ctrl+u (if the cursor is at the end), and then you realise that you want the command back, is there any way to get the full line back without re-typing. Is there any trick to change <code>.bashrc</code> so that ...
2,092
129,727
2013-11-20 07:19:48
1,056,445
12
2009-06-29 03:25:03
68,587
2013-11-20 07:19:48
https://stackoverflow.com/q/1056440
https://stackoverflow.com/a/1056445
<p>To undo, use either</p> <ul> <li><kbd>Ctrl</kbd>+<kbd>X</kbd>, <kbd>Ctrl</kbd>+<kbd>U</kbd>; or</li> <li><kbd>Ctrl</kbd>+<kbd>_</kbd> (underscore).</li> </ul> <p>See <code>bind -P</code> for a full list of keybindings in <code>bash</code>.</p>
<p>To undo, use either</p> <ul> <li><kbd>Ctrl</kbd>+<kbd>X</kbd>, <kbd>Ctrl</kbd>+<kbd>U</kbd>; or</li> <li><kbd>Ctrl</kbd>+<kbd>_</kbd> (underscore).</li> </ul> <p>See <code>bind -P</code> for a full list of keybindings in <code>bash</code>.</p>
58, 387, 1231
bash, command-line, linux
<h1>undelete the deleted command in bash</h1> <p>If you have written a really long command, say <code>cd /very/long/path</code>, and then you do ctrl+c or ctrl+u (if the cursor is at the end), and then you realise that you want the command back, is there any way to get the full line back without re-typing. Is there any...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,966
bash
# undelete the deleted command in bash If you have written a really long command, say `cd /very/long/path`, and then you do ctrl+c or ctrl+u (if the cursor is at the end), and then you realise that you want the command back, is there any way to get the full line back without re-typing. Is there any trick to change `.b...
To undo, use either - `Ctrl`+`X`, `Ctrl`+`U`; or - `Ctrl`+`_` (underscore). See `bind -P` for a full list of keybindings in `bash`.
572206
How do I check if certain files exist in Bash?
8
2009-02-21 03:53:29
<p>In a <code>bash</code> script, I have to check for the existence of several files.</p> <p>I know an awkward way to do it, which is as follows, but that would mean that my main program has to be within that ugly nested structure:</p> <pre><code>if [ -f $FILE1 ] then if [ -f $FILE2 ] then echo OK # MAIN PROGRAM ...
10,955
60,628
2018-03-31 22:03:51
572,225
12
2009-02-21 03:59:02
34,509
2009-02-21 14:53:57
https://stackoverflow.com/q/572206
https://stackoverflow.com/a/572225
<p>How about</p> <pre><code>if [[ ! ( -f $FILE1 &amp;&amp; -f $FILE2 ) ]]; then echo NOT FOUND exit 1 fi # do stuff echo OK </code></pre> <p>See <code>help [[</code> and <code>help test</code> for the options usable with the <code>[[</code> style tests. Also read <a href="http://mywiki.wooledge.org/BashFAQ/0...
<p>How about</p> <pre><code>if [[ ! ( -f $FILE1 &amp;&amp; -f $FILE2 ) ]]; then echo NOT FOUND exit 1 fi # do stuff echo OK </code></pre> <p>See <code>help [[</code> and <code>help test</code> for the options usable with the <code>[[</code> style tests. Also read <a href="http://mywiki.wooledge.org/BashFAQ/0...
379, 387, 390
bash, error-handling, shell
<h1>How do I check if certain files exist in Bash?</h1> <p>In a <code>bash</code> script, I have to check for the existence of several files.</p> <p>I know an awkward way to do it, which is as follows, but that would mean that my main program has to be within that ugly nested structure:</p> <pre><code>if [ -f $FILE1 ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,967
bash
# How do I check if certain files exist in Bash? In a `bash` script, I have to check for the existence of several files. I know an awkward way to do it, which is as follows, but that would mean that my main program has to be within that ugly nested structure: ``` if [ -f $FILE1 ] then if [ -f $FILE2 ] then echo OK...
How about ``` if [[ ! ( -f $FILE1 && -f $FILE2 ) ]]; then echo NOT FOUND exit 1 fi # do stuff echo OK ``` See `help [[` and `help test` for the options usable with the `[[` style tests. Also read [this faq entry](http://mywiki.wooledge.org/BashFAQ/031). Your version does not work because `(...)` spawns a ne...
81022
How to autocomplete at the KornShell command line with the vi editor
8
2008-09-17 08:10:54
<p>In the KornShell (ksh) on <b>AIX UNIX Version 5.3</b> with the editor mode set to vi using:</p> <pre><code>set -o vi </code></pre> <p>What are the key-strokes at the shell command line to autocomplete a file or directory name?</p>
30,408
381
2014-01-03 15:27:59
81,135
12
2008-09-17 08:30:02
14,860
2008-09-17 10:00:10
https://stackoverflow.com/q/81022
https://stackoverflow.com/a/81135
<p>ESC\ works fine on AIX4.2 at least. One thing I noticed is that it only autocompletes to the unique part of the file name.</p> <p>So if you have the files x.txt, x171go and x171stop, the following will happen:</p> <pre><code>Press keys: Command line is: x x &lt;ESC&gt;\ ...
<p>ESC\ works fine on AIX4.2 at least. One thing I noticed is that it only autocompletes to the unique part of the file name.</p> <p>So if you have the files x.txt, x171go and x171stop, the following will happen:</p> <pre><code>Press keys: Command line is: x x &lt;ESC&gt;\ ...
34, 293, 390, 989, 1964
aix, ksh, shell, unix, vi
<h1>How to autocomplete at the KornShell command line with the vi editor</h1> <p>In the KornShell (ksh) on <b>AIX UNIX Version 5.3</b> with the editor mode set to vi using:</p> <pre><code>set -o vi </code></pre> <p>What are the key-strokes at the shell command line to autocomplete a file or directory name?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,968
bash
# How to autocomplete at the KornShell command line with the vi editor In the KornShell (ksh) on **AIX UNIX Version 5.3** with the editor mode set to vi using: ``` set -o vi ``` What are the key-strokes at the shell command line to autocomplete a file or directory name?
ESC\ works fine on AIX4.2 at least. One thing I noticed is that it only autocompletes to the unique part of the file name. So if you have the files x.txt, x171go and x171stop, the following will happen: ``` Press keys: Command line is: x x <ESC>\ x 1 x1...
75251848
How do I add an atomic counter to a powershell ForEach -Parallel loop
7
2023-01-26 21:32:19
<p>In this question, it was explained how to add to a concurrent ThreadSafe collection <a href="https://stackoverflow.com/questions/68018202/powershell-how-to-add-result-to-an-array-foreach-object-parallel">Powershell: How to add Result to an Array (ForEach-Object -Parallel)</a></p> <p>I have a simpler use case , where...
1,865
5,198,805
2024-07-23 03:24:30
75,252,238
12
2023-01-26 22:20:54
15,339,544
2024-07-23 03:20:47
https://stackoverflow.com/q/75251848
https://stackoverflow.com/a/75252238
<p>In PowerShell when updating a single value from multiple threads you must use a locking mechanism, for example <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.mutex" rel="nofollow noreferrer"><code>Mutex</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaph...
<p>In PowerShell when updating a single value from multiple threads you must use a locking mechanism, for example <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.mutex" rel="nofollow noreferrer"><code>Mutex</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaph...
353, 526, 1381, 13829
multithreading, parallel-processing, powershell, thread-safety
<h1>How do I add an atomic counter to a powershell ForEach -Parallel loop</h1> <p>In this question, it was explained how to add to a concurrent ThreadSafe collection <a href="https://stackoverflow.com/questions/68018202/powershell-how-to-add-result-to-an-array-foreach-object-parallel">Powershell: How to add Result to a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,969
bash
# How do I add an atomic counter to a powershell ForEach -Parallel loop In this question, it was explained how to add to a concurrent ThreadSafe collection [Powershell: How to add Result to an Array (ForEach-Object -Parallel)](https://stackoverflow.com/questions/68018202/powershell-how-to-add-result-to-an-array-foreac...
In PowerShell when updating a single value from multiple threads you must use a locking mechanism, for example [`Mutex`](https://learn.microsoft.com/en-us/dotnet/api/system.threading.mutex), [`SemaphoreSlim`](https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim), [`Monitor`](https://learn.microso...
74216620
Powershell .contains() check without casesensitive
7
2022-10-27 03:52:18
<p>I'm having a larger foreach loop code but need to get below code executed without casesensitive.</p> <p>Below code snippet returns false, how can I ignore the casesensitive .contains() and the condition as true?</p> <pre><code>$a='aa0855' $b='AA0855 Sample' $b.Contains($a) </code></pre> <p>Expected value is true. Ab...
15,050
20,211,962
2024-11-19 22:40:05
74,216,683
12
2022-10-27 04:01:12
45,375
2024-11-19 22:40:05
https://stackoverflow.com/q/74216620
https://stackoverflow.com/a/74216683
<p>The <strong><a href="https://docs.microsoft.com/en-US/dotnet/api/System.String.Contains" rel="nofollow noreferrer"><code>.Contains()</code></a> .NET string method is indeed case-<em>sensitive</em> - <em>invariably</em> in <em>Windows PowerShell</em>, and <em>by default</em> in <em>PowerShell (Core) 7+</em></strong>....
<p>The <strong><a href="https://docs.microsoft.com/en-US/dotnet/api/System.String.Contains" rel="nofollow noreferrer"><code>.Contains()</code></a> .NET string method is indeed case-<em>sensitive</em> - <em>invariably</em> in <em>Windows PowerShell</em>, and <em>by default</em> in <em>PowerShell (Core) 7+</em></strong>....
526, 4371, 17150
powershell, string-matching, substring
<h1>Powershell .contains() check without casesensitive</h1> <p>I'm having a larger foreach loop code but need to get below code executed without casesensitive.</p> <p>Below code snippet returns false, how can I ignore the casesensitive .contains() and the condition as true?</p> <pre><code>$a='aa0855' $b='AA0855 Sample'...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,970
bash
# Powershell .contains() check without casesensitive I'm having a larger foreach loop code but need to get below code executed without casesensitive. Below code snippet returns false, how can I ignore the casesensitive .contains() and the condition as true? ``` $a='aa0855' $b='AA0855 Sample' $b.Contains($a) ``` Exp...
The **[`.Contains()`](https://docs.microsoft.com/en-US/dotnet/api/System.String.Contains) .NET string method is indeed case-*sensitive* - *invariably* in *Windows PowerShell*, and *by default* in *PowerShell (Core) 7+***. Thus, in **[*PowerShell (Core) 7*](https://github.com/PowerShell/PowerShell/blob/master/README.md...
71399918
replace match group using regex + powershell
7
2022-03-08 18:30:46
<p>I am trying to setup a PowerShell script that would replace a matching string from my GlobalAssemblyInfo.cs file. I am basically looking to update the Version number via powershell so I can do that in a post build automatically. Anyways, the input string from the cs file is this:</p> <pre><code>//-------------------...
6,882
3,263,488
2025-10-29 00:03:36
71,400,264
12
2022-03-08 19:06:33
15,339,544
2025-10-29 00:03:10
https://stackoverflow.com/q/71399918
https://stackoverflow.com/a/71400264
<p><a href="https://stackoverflow.com/questions/71399918/replace-match-group-using-regex-powershell#comment126203319_71399918">Abraham's helpful comment</a> already pointed out the key issue, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.replace?view=net-6.0" rel="nofollow noreferrer"><code>.Repla...
<p><a href="https://stackoverflow.com/questions/71399918/replace-match-group-using-regex-powershell#comment126203319_71399918">Abraham's helpful comment</a> already pointed out the key issue, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.replace?view=net-6.0" rel="nofollow noreferrer"><code>.Repla...
18, 526, 53034
powershell, ps1, regex
<h1>replace match group using regex + powershell</h1> <p>I am trying to setup a PowerShell script that would replace a matching string from my GlobalAssemblyInfo.cs file. I am basically looking to update the Version number via powershell so I can do that in a post build automatically. Anyways, the input string from the...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,971
bash
# replace match group using regex + powershell I am trying to setup a PowerShell script that would replace a matching string from my GlobalAssemblyInfo.cs file. I am basically looking to update the Version number via powershell so I can do that in a post build automatically. Anyways, the input string from the cs file ...
[Abraham's helpful comment](https://stackoverflow.com/questions/71399918/replace-match-group-using-regex-powershell#comment126203319_71399918) already pointed out the key issue, [`.Replace(..)`](https://learn.microsoft.com/en-us/dotnet/api/system.string.replace?view=net-6.0) is a string method for **literal replacement...
62464466
How to print bold and sized text in Bash?
7
2020-06-19 06:24:26
<p><em><strong>1st question</strong></em></p> <p>printing &quot;<strong>BOLD</strong>&quot; text...using <code>lp</code> if possible.</p> <p>example:</p> <p><code>echo -e &quot;\e[1mBOLD\e[0m&quot; | lp</code></p> <p>will print out this below on a white paper</p> <p><code>1mBOLD0m</code></p> <p>how to get:</p> <p><stro...
8,238
13,718,592
2022-03-01 19:40:28
62,573,221
12
2020-06-25 10:26:51
7,582,247
2020-08-04 11:44:51
https://stackoverflow.com/q/62464466
https://stackoverflow.com/a/62573221
<p>For starters, don't use the raw ANSI escape sequences directly since it makes it hard to read and maintain. Use <a href="https://linux.die.net/man/1/tput" rel="noreferrer"><code>tput</code></a> to produce the escape sequences for you.</p> <p>There's a tool called <a href="https://github.com/theZiz/aha" rel="noreferr...
<p>For starters, don't use the raw ANSI escape sequences directly since it makes it hard to read and maintain. Use <a href="https://linux.die.net/man/1/tput" rel="noreferrer"><code>tput</code></a> to produce the escape sequences for you.</p> <p>There's a tool called <a href="https://github.com/theZiz/aha" rel="noreferr...
87, 387, 555
bash, formatting, printing
<h1>How to print bold and sized text in Bash?</h1> <p><em><strong>1st question</strong></em></p> <p>printing &quot;<strong>BOLD</strong>&quot; text...using <code>lp</code> if possible.</p> <p>example:</p> <p><code>echo -e &quot;\e[1mBOLD\e[0m&quot; | lp</code></p> <p>will print out this below on a white paper</p> <p><c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,972
bash
# How to print bold and sized text in Bash? ***1st question*** printing "**BOLD**" text...using `lp` if possible. example: `echo -e "\e[1mBOLD\e[0m" | lp` will print out this below on a white paper `1mBOLD0m` how to get: **BOLD** ? ***2nd question*** Printing `[font size=33]SIZED TEXT[/font]`, how? the only...
For starters, don't use the raw ANSI escape sequences directly since it makes it hard to read and maintain. Use [`tput`](https://linux.die.net/man/1/tput) to produce the escape sequences for you. There's a tool called [aha](https://github.com/theZiz/aha) that can convert ANSI escape sequences into HTML. You can probab...
60543899
How to supply the password as an argument in realm join to active directory command
7
2020-03-05 11:03:08
<p>I am trying to automate few areas like joining the linux server to active directory. To join the server to AD, I am using the following command:</p> <p><code>realm join -U &lt;Username&gt; exmaple.com</code></p> <p>The above command will prompt for a password which need to provided during the execution time. My re...
18,048
7,405,974
2024-10-11 17:10:14
62,103,887
12
2020-05-30 14:31:38
7,405,974
2020-05-30 14:31:38
https://stackoverflow.com/q/60543899
https://stackoverflow.com/a/62103887
<p>This is resolved. Following is the answer</p> <p><code>echo $password | realm join -U &lt;Username&gt; example.com</code></p> <p>replace $password with your actual password</p>
<p>This is resolved. Following is the answer</p> <p><code>echo $password | realm join -U &lt;Username&gt; example.com</code></p> <p>replace $password with your actual password</p>
58, 390, 10401
active-directory, linux, shell
<h1>How to supply the password as an argument in realm join to active directory command</h1> <p>I am trying to automate few areas like joining the linux server to active directory. To join the server to AD, I am using the following command:</p> <p><code>realm join -U &lt;Username&gt; exmaple.com</code></p> <p>The abo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%bash%' OR '%shell%'; a.Body contains code block; q.Score > 5; a.Score > 10
10,973
bash
# How to supply the password as an argument in realm join to active directory command I am trying to automate few areas like joining the linux server to active directory. To join the server to AD, I am using the following command: `realm join -U <Username> exmaple.com` The above command will prompt for a password wh...
This is resolved. Following is the answer `echo $password | realm join -U <Username> example.com` replace $password with your actual password