--//昨天看bash文档,,发现一些小细节,做一个记录,就是EOF加引号的问题.
command <<‘EOF‘
cmd1
cmd2 arg1
$var won‘t expand as parameter substitution turned off by single quoting
EOF
--//例子:
$ cat a.sh
#! /bin/bash
cat <<‘EOF‘
this is a test
hostname is $HOSTNAME
$(date)
EOF
$ . a.sh
this is a test
hostname is $HOSTNAME
$(date)
--//你可以发现$HOSTNAME,$(date)并没有展开或者执行转换.
--//如果写成如下:
cat <<EOF
this is a test
hostname is $HOSTNAME
$(date)
EOF
$ . a.sh
this is a test
hostname is xxxxxx
Mon Nov 20 09:22:06 CST 2017
--//可以发现现在是执行了里面的date命令,$HOSTNAME也发生了转换.
时间: 2024-10-07 08:32:28