[20171120]bash使用here documents的细节

简介: [20171120]bash使用here documents的一个小细节.txt --//昨天看bash文档,,发现一些小细节,做一个记录,就是EOF加引号的问题. command

[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也发生了转换.

目录
相关文章
|
9月前
|
监控 安全 Shell
防止员工泄密的措施:在Linux环境下使用Bash脚本实现日志监控
在Linux环境下,为防止员工泄密,本文提出使用Bash脚本进行日志监控。脚本会定期检查系统日志文件,搜索敏感关键词(如&quot;password&quot;、&quot;confidential&quot;、&quot;secret&quot;),并将匹配项记录到临时日志文件。当检测到可疑活动时,脚本通过curl自动将数据POST到公司内部网站进行分析处理,增强信息安全防护。
216 0
|
9月前
|
Linux Shell Windows
4:Bash shell命令-步入Linux的现代方法
4:Bash shell命令-步入Linux的现代方法
122 0
|
Ubuntu 安全 Linux
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
378 0
|
关系型数据库 MySQL Shell
【Linux命令】-bash: mysql: command not found
【Linux命令】-bash: mysql: command not found
158 0
|
9月前
|
存储 Shell Linux
Linux Bash 脚本中的 IFS 是什么?
【4月更文挑战第25天】
199 0
Linux Bash 脚本中的 IFS 是什么?
|
7月前
|
存储 Shell Linux
Linux|创建和使用 Bash 别名
Linux|创建和使用 Bash 别名
82 6
|
9月前
|
Java Shell Linux
【linux进程控制(三)】进程程序替换--如何自己实现一个bash解释器?
【linux进程控制(三)】进程程序替换--如何自己实现一个bash解释器?
|
9月前
|
Shell Linux
【Linux】Bash支持各种指令选项的原理:命令行参数
【Linux】Bash支持各种指令选项的原理:命令行参数
|
9月前
|
存储 Shell Linux
【攻防世界】unseping (反序列化与Linux bash shell)
【攻防世界】unseping (反序列化与Linux bash shell)
|
9月前
|
Linux Shell 开发工具
linux】-bash:vim:未找到命令
linux】-bash:vim:未找到命令
134 0