shopt -s -o nounset: 开启变量检查,如果一个使用的变量没有值,则会报错。unbound variable
<<'HERE' : 这样的用法,则所有的内容都会被认为是纯文本。
<<-EOF : 则默认会在每行前面加上indent.
但是很奇怪的是,在here document里面的echo -e good\t也无法正常的输出了。输出是goodt, \t没有被解释为tab.
-
shopt -s -o nounset
-
-
Script="$( cat <<'HERE'
-
hostname;
-
cat /etc/issue;
-
id root
-
HERE
-
)"
-
-
cat <<-HERE>command.hist
-
#cat <<-'HERE'>command.hist
-
echo $SHELL
-
`hostname`;
-
`cat /etc/issue`;
-
id root
-
`echo -e good\t`
-
HERE
-
-
root=`id`
-
echo $root
-
-
#ssh -t root@192.168.0.102 ${Script}
我本来想用here document 生成文件里面含有tab,或者空格,但是感觉还是不方便。
还是只能用echo 或者printf 实现。
-
echo -e "email\tlast\tfirst
-
kobe@example.com\tkobe\the
-
jason@example.com\x09jason\011kid" >tab_delim.txt
-
printf "email\tlast\tfirst
-
kobe@example.com\tkobe\the
-
jason@example.com\x09jason\011kid" > tab_delim.txt
-
#\x09 或者\011 \t 都是tab
查看文件的不可打印字符:
-
cat -A tab_delim.txt
-
vim: set list
-
vim: set nolist
-
vim: digraph #查看可以输入的特殊字符
最后介绍下shopt的几个用法:shopt 是bash的builtin.
-
man builtin #可以寻找shopt
-
shopt -p #查看当前设置
-
shopt -o
-
shopt -s #enable a set
-
shopt -u #disable a set
-
-
shopt [-pqsu] [-o] [optname ...]
-
Toggle the values of settings controlling optional shell behavior. The settings can be either those listed below, or, if the -o option is used, those available with the -o option to the set builtin com‐
-
mand. With no options, or with the -p option, a list of all settable options is displayed, with an indication of whether or not each is set. The -p option causes output to be displayed in a form that
-
may be reused as input. Other options have the following meanings:
-
-s Enable (set) each optname.
-
-u Disable (unset) each optname.
-
-q Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple optname arguments are given with -q, the return status is zero if all optnames
-
are enabled; non-zero otherwise.
-
-o Restricts the values of optname to be those defined for the -o option to the set builtin.
阅读(1311) | 评论(0) | 转发(0) |