shell老报错,为什么?
本帖最后由 songkang666 于 2012-08-14 16:06:27 编辑 想做个类似于Makefile作用的shell脚本,当./comile.sh remove时可以删除除.c与.sh以外的所有文件,但为什么老出错,错误为:
./compile.sh: line 10: 在未预料的“(”附近出现语法错误
./compile.sh: line 10: `ls !(*.c|*.sh) | xargs rm'
代码为:
#read -p "which files are what you want to compile? "
case $# in
"1")
if [ "$1" == "remove" ]; then
ls !(*.c|*.sh) | xargs rm
if [ "$?" == "0" ]; then
echo "remove successfully"
else
echo "remove failure"
fi
else
gcc -o ${1%.c} $1
fi
;;
"2")
gcc -o ${1%.c} $1
gcc -o ${2%.c} $2
;;
*)
echo "usage: $0 para1 [para2 ....]"
;;
esac