Chinaunix首页 | 论坛 | 博客
  • 博客访问: 582435
  • 博文数量: 109
  • 博客积分: 1463
  • 博客等级: 上尉
  • 技术积分: 859
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-22 13:21
个人简介

希望和广大热爱技术的童鞋一起交流,成长。

文章分类

全部博文(109)

文章存档

2017年(1)

2016年(2)

2015年(18)

2014年(1)

2013年(9)

2012年(15)

2011年(63)

分类:

2012-05-08 21:41:34

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

$

 

阅读(841) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~