Changes

Jump to: navigation, search

BASH Variables

475 bytes added, 21:17, 21 September 2008
no edit summary
echo "Hooray!"
fi
 
Variables are interpolated when in double-quotes, but not when they are in single-quotes:
 
$ X="Test"
$ echo "$X"
Test
$ echo '$X'
$X
$ echo $X
Test
 
One advantage to using double-quotes is that the variable value will be treated as a single argument even when it contain spaces. For example:
 
$ touch "test file"
$ NAME="test file"
$ rm $NAME
rm: cannot remove `test': No such file or directory
rm: cannot remove `file': No such file or directory
$ rm "$NAME"
You may optionally place the variable name within curly-braces (useful if there is text immediately after the variable name):

Navigation menu