Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

217 votes
3 answers
105k 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?
xenoterracide's user avatar
25 votes
2 answers
12k views

Expansion of a shell variable and effect of glob and split on it

This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
Geek's user avatar
  • 6,778
38 votes
2 answers
51k views

What is the significance of single and double quotes in environment variables?

I defined some environment variables in my .profile like this: MY_HOME="/home/my_user" but the variable does not seem to evaluate unless I strip off the quotes and re-source the file. I believe the ...
2NinerRomeo's user avatar
3 votes
1 answer
370 views

Why does this variable have no value even though it is set in .bashrc?

If I append this: hi=11 export hi to the .bashrc and then I su to this user with: su - bela then I: echo $hi 11 Then it's working, the "hi" variable has the value of "11". But. When I: su -...
LanceBaynes's user avatar
  • 40.6k
2 votes
2 answers
734 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
user avatar
1 vote
2 answers
6k views

Why is this environment variable not set up?

When a shell runs an external executable as a command, we can pass environment variables into the executable. $ var=3 /bin/echo `$var` $ var=3 bash -c "/bin/echo '$var'" both don't output anything. ...
Tim's user avatar
  • 103k