1.代码块和I/O重定向
#! /bin/shFile=/etc/fstab{ read line1 read line2 } < $File
echo "First line in $File is:" echo "$line1" echo echo "Second line in $File is:" echo "$line2" echo
exit 0
2.将一个代码块的结果保存到一个文件里
#! /bin/shSUCCESS=0E_NOARGS=65if [ -z "$1" ]then echo "Usage: `basename $0` rpm-file" exit $E_NOARGSfi
{ echo echo "Archive Description:" rpm -qpi $1 echo echo "Archive Listing:" rpm -qpl $1 echo rpm -i --test $1 if [ "$?" -eq $SUCCESS ] then echo "$1 can be installed." else echo "$1 cannot be installed." fi
echo} > "$1.test"
echo "Results of rpm test in file $1.test"
exit 0
3.后台运行循环
#! /bin/shfor i in 1 2 3 4 5 6 7 8 9 10do echo -n "$i "done &
echoecho
for i in 11 12 13 14 15 16 17 18 19 20do echo -n "$i "done
echo
exit 0
4.备份最后一天所有修改文件
#! /bin/shBACKUPFILE=backup-$(date +%Y-%m-%d)archive=${1:-$BACKUPFILE} -----tar cvf - `find . -mtime -1 -type f -print` > $archive.tar ----查找24小时内修改的文件gzip $.archive.tarecho "Directory $PWD backed up in archive file /"$archive.tar.gz/"."exit 0