ITPub博客

首页 > 数据库 > Oracle > [20171120]bash使用here documents的细节

[20171120]bash使用here documents的细节

原创 Oracle 作者:lfree 时间:2017-11-20 09:25:40 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也发生了转换.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2147457/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969456