首页 > 其他 > 详细

[20171120]bash使用here documents的一个小细节.txt

时间:2017-11-20 12:11:58      阅读:227      评论:0      收藏:0      [点我收藏+]

[20171120]bash使用here documents的一个小细节.txt

--//昨天看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也发生了转换.

[20171120]bash使用here documents的一个小细节.txt

原文:http://www.cnblogs.com/lfree/p/7865314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!