2017-10-16 81 views
0

我想创建一个bash脚本来执行特定的任务,同时检查一个具有特定名称的文件。我正在使用UTF-8编码并运行脚本“bash test.sh”。在Ubuntu机器上。bash脚本,语法错误:意外的文件结尾

#!/bin/bash 

echo "Starting..." 
while true 
do 
    echo "In loop..." 
    sleep 2 

    if 
    -e "./droneControl.py" 
    then 
    break 
    fi 
done 

echo "found..." 
+1

你'if'需要在括号:'如果[-e “./droneControl.py”]'。另外你为什么使用循环? – jackarms

+1

您使用“-e”作为“if”的参数,它是“test”命令的参数。尝试“如果[[-e ./drone control.py]]”。 –

+0

用四个空格前缀代码/数据。请看[编辑帮助](http://stackoverflow.com/editing-help)。 – Cyrus

回答

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..." 
相关问题