Linux Shell脚本编程之if用法示例

时间:2023-01-30 22:33:18

************************程序文件名:create**************************

#!/bin/bash
if [ -e $1 ] #注意if中的空格段
then
echo "the file is already exists!"
else
`touch $1`
`chmod u+x $1`
echo "Finish!"
fi

case "$2" in
"-g" ) `gedit $1`;;
"-v" ) `gnome-terminal -x vi $1`;;
"" ) echo "";;
* ) echo "command error!";;
esac
创建一个可执行文件,在文件名参数后可可以选用-o或者-g进行选择编辑工具打开;