全部博文(362)
分类:
2010-10-05 16:41:09
#!/bin/bash # weirdvars.sh: Echoing weird variables. echo var="'(]\\{}\$\"" echo $var # '(]\{}$" echo "$var" # '(]\{}$" Doesn't make a difference. echo IFS='\' echo $var # '(] {}$" \ converted to space. Why? echo "$var" # '(]\{}$"
IFS='$'
echo $var # '(]\{} " \ converted to $. Why?
echo "$var" # '(]\{}$"
# Examples above supplied by Stephane Chazelas.
echo
var2="\\\\\""
echo $var2 # "
echo "$var2" # \\"
echo
# But ... var2="\\\\"" is illegal. Why?
var3='\\\\'
echo "$var3" # \\\\
# Strong quoting works, though.
exit
NO.2
echo "Why can't I write 's between single quotes"
echo
# The roundabout method.
echo 'Why can'\''t I write '"'"'s between single quotes'
# |-------| |----------| |-----------------------|
# Three single-quoted strings, with escaped and quoted single quotes between.
# This example courtesy of St閜hane Chazelas.
N0.3
bash$ echo hello\!
hello!
bash$ echo "hello\!"
hello\!
bash$ echo -e x\ty
xty
bash$ echo -e "x\ty"
x y