全部博文(298)
分类: Python/Ruby
2012-04-20 21:23:22
Shell行内输入的使用技巧
使用program << delimiter 或者program <<- delimiter,可以在Shell脚本正文内提供输入数据,这样的数据叫作嵌入文件默认情况下,Shell可以在嵌入文件正文内做变量、命令和算术替换。
(1) 使用行内输入提供脚本的帮助信息
usage() { cat <<-EOF To run a command as administrator
(user "root"), use "sudo See "man sudo_root" for details. EOF } |
(2) 使用行内输入为为mail命令提供邮件正文
sendmail() { mail -s "disk usage warning" $name << EOF Greetings. You are one of the top 10 comsumers of disk space on the system. Your home dtrectory uses $amount disk blocks. Please clean uo unneeded files, as soon as possible. Thanks. EOF } |
(3) 使用行内输入向文件写入内容
$cat << EOF >file >this is a file >test cat >EOF $cat file this is a file test cat $ |