一个实用的shell脚本
刚写的一个编译C/C++用的脚本,觉得好用的话把它保存起来加上可执行权限放到$PATH目录中去。
emacs虽然mode-cc很不错,可惜执行还得另开一个shell的window,不如用这个了。
echo "Bad usage!"
exit 1
fi FILENAME=$1 CC="gcc" CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wnested-externs -Waggregate-return -Wundef -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wconversion -Winline -Wformat-nonliteral -Wformat-security -Wunknown-pragmas -Wredundant-decls -std=c99 -s -g3 -O" CPPFLAGS="-Wall -W -Wshadow -std=c++98 -ffor-scope -Wpointer-arith -s -g3 -O" while [[ "$FILENAME" != "" ]] doOUTFILE=${FILENAME%.*}
POSTFIX=${FILENAME##*.}
if [ $OUTFILE = $FILENAME ] || [ $POSTFIX = $FILENAME ] ||
[ -z $OUTFILE ] || [ -z $POSTFIX ];
then
echo "Bad file name!"
exit 2
fi
if [[ "$POSTFIX" = "cpp" ]] || [[ "$POSTFIX" = "cxx" ]] ||
[[ "$POSTFIX" = "cc" ]] ;
then
CC="g++"
CFLAGS=$CPPFLAGS
fi
$CC $CFLAGS -o $OUTFILE $FILENAME
if (($?!=0)); then
exit 1
fi
echo "Result of exec $OUTFILE:"
/bin/bash -c "./$OUTFILE"
echo "End of $FILENAME"
echo "========================"
rm -f $OUTFILE
shift
FILENAME=$1
done exit 0