我想创建一个执行特定任务的bash脚本,同时检查具有特定名称的文件。我正在使用UTF-8编码并运行脚本" bash test.sh"。在Ubuntu机器上。
#!/bin/bash
echo "Starting..."
while true
do
echo "In loop..."
sleep 2
if
-e "./droneControl.py"
then
break
fi
done
echo "found..."
答案 0 :(得分:0)
您需要使用dos2unix
或等效命令转换脚本。
$ bash fromnotepad.sh
fromnotepad.sh: line 2: $'\r': command not found
Starting...
fromnotepad.sh: line 16: syntax error: unexpected end of file
$ sed 's/\r$//' fromnotepad.sh > fromunix.sh
$ bash fromunix.sh
Starting...
In loop...
found...
脚本:
$ cat fromunix.sh
#!/bin/bash
echo "Starting..."
while true
do
echo "In loop..."
sleep 2
if [ -e "./ls.txt" ]
then
break
fi
done
echo "found..."