LDP/LDP/guide/docbook/abs-guide/weirdvars.sh

51 lines
1.0 KiB
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2001-09-04 13:27:31 +00:00
# weirdvars.sh: Echoing weird variables.
2001-07-10 14:25:50 +00:00
2008-11-23 22:43:47 +00:00
echo
2001-07-10 14:25:50 +00:00
var="'(]\\{}\$\""
echo $var # '(]\{}$"
echo "$var" # '(]\{}$" Doesn't make a difference.
2002-01-07 15:24:19 +00:00
echo
2001-07-10 14:25:50 +00:00
IFS='\'
2005-03-21 13:51:11 +00:00
echo $var # '(] {}$" \ converted to space. Why?
2002-01-07 15:24:19 +00:00
echo "$var" # '(]\{}$"
2001-09-04 13:27:31 +00:00
2005-03-21 13:51:11 +00:00
# Examples above supplied by Stephane Chazelas.
2001-07-10 14:25:50 +00:00
2008-11-23 22:43:47 +00:00
echo
var2="\\\\\""
echo $var2 # "
echo "$var2" # \\"
echo
# But ... var2="\\\\"" is illegal. Why?
var3='\\\\'
echo "$var3" # \\\\
# Strong quoting works, though.
2012-11-27 14:56:18 +00:00
# ************************************************************ #
# As the first example above shows, nesting quotes is permitted.
echo "$(echo '"')" # "
# ^ ^
# At times this comes in useful.
var1="Two bits"
echo "\$var1 = "$var1"" # $var1 = Two bits
# ^ ^
# Or, as Chris Hiestand points out ...
2014-03-07 02:24:29 +00:00
if [[ "$(du "$My_File1")" -gt "$(du "$My_File2")" ]]
# ^ ^ ^ ^ ^ ^ ^ ^
then
...
fi
2012-11-27 14:56:18 +00:00
# ************************************************************ #