在學(xué)習(xí)shell腳本可以輕松實(shí)現(xiàn)簡(jiǎn)化我們?cè)诰幊踢^(guò)程中的復(fù)雜操作.
下面是mygcc的代碼:
value=$1 value1="${value:0-2}" filestyle=".c" if [ $# -eq 1 ] then if [ $value1 == $filestyle ] then if [ -e $1 ] then if [ -f $1 ] then if [ -e ./a.out ] then rm ./a.out fi gcc $1 if [ -e ./a.out ] then ./a.out fi fi else echo "$1 :not such file or directory" fi else echo "$1 not .c file" fi elif [ $# -eq 0 ] then echo "which file to be edited?" else echo "error:too many arguments." fi
此shell腳本的實(shí)現(xiàn)的偽代碼:
- 判斷文件的個(gè)數(shù)
- 判斷文件是否是'.c'類(lèi)型的文件;
- 判斷文件是否存在;
- 文件如果存在是否是普通文件
- 判斷./a.out文件是否存在
- 如果存在的話就刪除掉
- 然后gcc 文件名
- 判斷./a.out文件存在,一旦存在就可以執(zhí)行./a.out