动手写SHELL脚本

从当前目录中,查找包含字符串“include”的文件:

 

#!/bin/sh for file in * do if grep -l include $file then echo $file fi done exit 0 

如果使用shell命令解决这个问题,另几个好的实现:

#!/bin/sh for file in * do if grep -l include $file then echo $file fi done exit 0


$@和$*的区别:前者不受IFS的影响,一直用空格分隔,例如:

$ IFS='' $ set foo bar bam $ echo "$@" foo bar bam $ echo "$*" boobarbam $ unset IFS $ echo "$*" foo bar bam

 

if语句:

if test -f test.c then ... fi 可以简写为: if [ -f test.c] then ... fi

 

#!/bin/sh echo "Input yes or no?" read timeofday case "$timeofday" in yes) echo "11111111";; no ) echo "222222";; y ) echo "11111111";; n ) echo "222222";; esac exit 0

 

#!/bin/sh echo "...........?" read timeofday case "$timeofday" in yes|y|YES|Y) echo "11111111111111111" ;; *) echo "00000000000000000" ;; esac exit 0

 

你可能感兴趣的:(Linux有关)