我正在编写脚本,但在第 2-3 行出现错误。错误是这样打印的:
./ex6.sh: line2: $'\r': command not found
./ex6.sh: line3: syntax error near unexpected token '$'\r''
./ex6.sh: line3: 'fund ()
Run Code Online (Sandbox Code Playgroud)
该文件名为ex6.sh. 有人可以就为什么会发生此错误提供一些指导吗?
#!/bin/sh
func ()
{
if [ "$1" == "" ]; then
echo "Default";
for i in `find` ;
do
if [ -d $i ]; then
echo $i "is a directory";
fi
if [ -f $i ]; then
if [ "$i" != "./script.sh" ]; then
echo $i "is a file";
fi
fi
done
fi
if [ "$1" == "--long" ]; then
echo "--long";
for i in `find` ;
do
if [ -d $i ]; then
echo $i "is a directory";
fi
if [ -f $i ]; then
echo $i "is a file";
fi
done
fi
if [ "$1" == "--rm" ]; then
echo "--rm";
for i in `find` ;
do
if [ -d $i ]; then
echo $i "is a directory";
fi
if [ -f $i ]; then
echo $i "is a file";
fi
done
fi
}
getArgs () {
if [ "$1" == "--long" ]; then
echo "got the first param $1";
else
if [ "$1" == "--rm" ]; then
echo "got the second param $1";
else
if [ "$1" == "" ]; then
echo "got default param";
else
echo "script.sh: unknown option $1";
exit;
fi
fi
fi
}
getArgs $1;
#ARGS=$1;
func $1;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25639 次 |
| 最近记录: |