Linked Questions

4 votes
1 answer
500 views

What are the contexts where Bash doesn't perform word splitting and globbing?

Bash doesn't perform word splitting in globbing in these cases: LHS or RHS of an assignment, except for indexed arrays var=$value # simple variable declare -A hash key=&...
275 votes
4 answers
52k views

Security implications of forgetting to quote a variable in bash/POSIX shells

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 ...
46 votes
3 answers
35k views

Using shell variables for command options

In a Bash script, I'm trying to store the options I'm using for rsync in a separate variable. This works fine for simple options (like --recursive), but I'm running into problems with --exclude='.*': ...
216 votes
3 answers
103k views

$VAR vs ${VAR} and to quote or not to quote

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?
34 votes
2 answers
4k views

Where is "export var=value" not available?

I have picked up -- probably on Usenet in the mid-1990s (!) -- that the construct export var=value is a Bashism, and that the portable expression is var=value export var I have been advocating ...
204 votes
3 answers
186k views

Quoting within $(command substitution) in Bash

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 ...
1 vote
0 answers
51 views

Is there any point in quoting simple strings? [duplicate]

Is there any reason for doing something like: a="abc" or a='abc' The quotes seem completely superfluous, but then there might be some hideous corner case... I'm interested in Bash and Sh in ...
-1 votes
3 answers
27k views

How to add more directiories in PATH [closed]

Okay, first thing first, I'm new to Linux and I'm using Linux Mint. I learned that when I want to add more directories to my PATH (specifically my home directory) I need a Bash command that looks ...
9 votes
4 answers
5k views

back ticks vs double quotes

I've been wondering this for a long time but haven't figured out how to look it up - is this: x=`command -v r2g` the same as this: x="$(command -v r2g)" or is it the same as this: x=$(command -...
2 votes
2 answers
389 views

Why is it not required to double quote `$bar` in assignment `foo=$bar`? [duplicate]

From https://unix.stackexchange.com/a/32227/674 The main places where it's safe not to use the double quotes are: in an assignment: foo=$bar (but note that you do need the double quotes in ...
1 vote
2 answers
3k views

Saving Output In a Variable and Re-using it

page=`grep $x /var/www/vhosts/example.com/statistics/logs/access_log | awk '{print $7}'| sort |uniq -c |sort -nr` times=`$page | wc -l` I am trying to save output of grep in a variable as page. But ...
1 vote
2 answers
6k views

ls, mv, cp, cat, vi, command not found

I was trying to add a new path to my bashrc file but I have seemed to messed something up. after I $ source ~/.bashrc I no longer can use the commands ls, mv, cp, cat, vi, and probably others that I ...