![](/img/trans.png)
[英]syntax error: unexpected end of file trying to run a simple bash script
[英]bash script, syntax error: unexpected end of file
我想创建一个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..."
您需要使用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..."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.