Skip to main content
343 votes
4 answers
194k views

Should or should I not wrap quotes around variables in a shell script? For example, is the following correct: xdg-open $URL [ $? -eq 2 ] or xdg-open "$URL" [ "$?" -eq "2"...
Cristian's user avatar
  • 7,257
963 votes
7 answers
475k views

In Bash, what are the differences between single quotes ('') and double quotes ("")?
jrdioko's user avatar
  • 33.9k
6278 votes
66 answers
5.2m views

How do I call an external command within Python as if I had typed it in a shell or command prompt?
freshWoWer's user avatar
  • 64.6k
2507 votes
16 answers
3.1m views

I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF When I run this script from the ...
John's user avatar
  • 25.5k
179 votes
7 answers
476k views

Here are a series of cases where echo $var can show a different value than what was just assigned. This happens regardless of whether the assigned value was "double quoted", 'single quoted' or ...
that other guy's user avatar
416 votes
7 answers
746k views

I found some ways to pass external shell variables to an awk script, but I'm confused about ' and ". First, I tried with a shell script: $ v=123test $ echo $v 123test $ echo "$v" 123test Then tried ...
hqjma's user avatar
  • 4,153
1919 votes
11 answers
887k views

When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know what's the difference between them. What's the main difference between Bash and sh? What do we ...
Weiwei Yang's user avatar
  • 19.3k
169 votes
9 answers
57k views

This is probably in many FAQs - instead of using: cat file | command (which is called useless use of cat), correct way supposed to be: command < file In the 2nd, "correct" way - OS does not have ...
Leonid Volnitsky's user avatar
323 votes
6 answers
109k views

I run across many shell scripts with variables in all caps, and I've always thought that there is a severe misunderstanding with that. My understanding is that, by convention (and perhaps by ...
JasonSmith's user avatar
729 votes
6 answers
481k views

I have this script called test.sh: #!/bin/bash STR = "Hello World" echo $STR when I run sh test.sh I get this: test.sh: line 2: STR: command not found What am I doing wrong? I look at extremely ...
Jake Wilson's user avatar
  • 91.8k
1487 votes
25 answers
2.0m views

I want to write a function that will execute a shell command and return its output as a string, no matter, is it an error or success message. I just want to get the same result that I would have ...
Silver Light's user avatar
  • 46.3k
3032 votes
40 answers
3.9m views

I have this string stored in a variable: IN="[email protected];[email protected]" Now I would like to split the strings by ; delimiter so that I have: ADDR1="[email protected]" ADDR2="[email protected]" I don't ...
stefanB's user avatar
  • 80.5k
2273 votes
21 answers
1.9m views

How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this (called "sequence expression" in the Bash documentation): for i in {1..5}; do ...
eschercycle's user avatar
  • 23.6k
115 votes
10 answers
132k views

I have a file like the following and I would like to print the lines between two given patterns PAT1 and PAT2. 1 2 PAT1 3 - first block 4 PAT2 5 6 PAT1 7 - second block PAT2 8 9 PAT1 10 - ...
fedorqui's user avatar
  • 294k
39 votes
2 answers
15k views

I see here that testing whether $? is zero (success) or something else (failure) is an anti-pattern, but I have not been able to find this anywhere else. Sticking to the definition of anti-pattern of ...
svye's user avatar
  • 493

15 30 50 per page
1
2 3 4 5
601