方法一:使用echo
++++++++++++
#!/bin/bash
echo "123
456
789
123
`ls`">>test.txt
方法二:使用cat(也可以直接命令行手打了)
++++++++++++
#!/bin/bash
cat <<ENDOF >>test.txt
1234
456
789
123
`ls`
ENDOF
cat a.sh
#!/bin/bash
cat << EOF >> $1
define service{
use generic-service
`egrep "^[^#].*host_name" $1 |tail -1`
service_description Physical Memory
check_command CheckWindowsPhysicalMem!80!90
}
define service{
use lg-service,srv-pnp4
`egrep "^[^#].*host_name" $1 |tail -1`
service_description E:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l e -w 80 -c 95
}
EOF
for i in `ls *.cfg`;do ./a.sh $i;done
本文转自leonardos51CTO博客,原文链接:http://blog.51cto.com/leomars/1891403 ,如需转载请自行联系原作者