Linked Questions

378 votes
6 answers
421k views

… or an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
Gilles 'SO- stop being evil''s user avatar
282 votes
3 answers
57k views

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
Stéphane Chazelas's user avatar
213 votes
3 answers
205k views

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. What is the correct way to quote my variables? And how should I do it if these are ...
CousinCocaine's user avatar
131 votes
8 answers
308k views

I am trying to get the output of a pipe into a variable. I tried the following things: echo foo | myvar=$(</dev/stdin) echo foo | myvar=$(cat) echo foo | myvar=$(tee) But $myvar is empty. I don’t ...
Parckwart's user avatar
  • 1,311
223 votes
3 answers
111k views

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
xenoterracide's user avatar
136 votes
4 answers
55k views

I'm confused with using single or double brackets. Look at this code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains a ...
Majid Azimi's user avatar
  • 3,198
42 votes
5 answers
84k views

I'm so confused with GNU sed, POSIX sed, and BSD sed's myriad of options. How do I replace literal \n with the newline character using these three sed types?
Avinash Raj's user avatar
  • 3,759
68 votes
2 answers
25k views

I see these pretty colors in manpages viewed with less when setting a bunch of these variables. What do they mean, where is the documentation? Is this interpreted by less or termcap? screenshot
anselm's user avatar
  • 783
73 votes
1 answer
14k views

Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do ...
Michael Homer's user avatar
29 votes
7 answers
47k views

I am trying to use a variable consisting of different strings separated with a | as a case statement test. For example: string="\"foo\"|\"bar\"" read choice case $choice in $string) echo "...
terdon's user avatar
  • 253k
32 votes
3 answers
79k views

I don't necessarily want the answer but if someone could point me to some literature or examples. I would like to figure it out. When I run the script I receive an error: Syntax error near ...
Christina A Guzman's user avatar
29 votes
6 answers
29k views

I want to write the following bash function in a way that it can accept its input from either an argument or a pipe: b64decode() { echo "$1" | base64 --decode; echo } Desired usage: $ ...
tyrondis's user avatar
  • 393
26 votes
5 answers
5k views

Let's say we have 2 integers in a bash script: value1=5 value2=3 Then why do we need to use double quotes in case of a test ? For example: if [[ "$value1" -eq "$value2" ]] Why not just use the ...
Meerkat's user avatar
  • 363
12 votes
6 answers
2k views

I have a project comprised of about 20 small .sh files. I name these "small" because generally, no file has more than 20 lines of code. I took a modular approach because thus I'm loyal to the Unix ...
Arcticooling's user avatar
  • 4,523
14 votes
3 answers
29k views

Hello I have this in my ~/.bash_profile export GOPATH="$HOME/go_projects" export GOBIN="$GOPATH/bin" program(){ $GOBIN/program $1 } so I'm able to do program "-p ...
nooby's user avatar
  • 151

15 30 50 per page
1 2 3
4
5
23