方法一:使用echo
++++++++++++
#!/bin/bash
echo "123
456
789
123
`ls`">>test.txt
方法二:使用cat(也可以直接命令行手打了)
++++++++++++
#!/bin/bash
cat <>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