相关疑难解决方法(0)

语法错误:文件结束意外(期待"fi")

我正在用bash编写一个makefile,我有一个目标,我试图找到一个文件是否存在,即使我认为语法是正确的,我仍然给我一个错误.

这是我试图运行的脚本

read: 
        if [ -e testFile] ; then \ 
        cat testFile\ 
        fi
Run Code Online (Sandbox Code Playgroud)

我正在使用制表符,这不是问题.

错误是(当我输入:"make read")

if [ -e testFile] ; then \
        cat testFile \
        fi
/bin/sh: Syntax error: end of file unexpected (expecting "fi")
make: *** [read] Error 2
Run Code Online (Sandbox Code Playgroud)

bash makefile

13
推荐指数
3
解决办法
4万
查看次数

为什么正确的shell脚本会给出包装/截断/损坏的错误消息?

我有一个带有命令的shell脚本,它看起来应该可以正常工作,但是它会因奇怪的包装/截断/损坏错误消息而失败.例:

$ ls -l myfile
-rw-r----- 1 me me 0 Aug  7 12:36 myfile
$ cat myscript 
ls -l myfile
$ bash myscript
: No such file or directory
Run Code Online (Sandbox Code Playgroud)

该文件显然存在,但即使我没有,这是我通常会收到的错误消息:

$ ls -l idontexist
ls: cannot access idontexist: No such file or directory
Run Code Online (Sandbox Code Playgroud)

请注意它包含工具名称ls,消息字符串和文件名,而我的文件名不包含.

如果我尝试使用,这就是我得到的mysql.错误消息看起来已被包装,现在以引用开头:

Command:  mysql -h myhost.example.com
Expected: ERROR 2005 (HY000): Unknown MySQL server host 'myhost.example.com' (0)
Actual:   ' (0) 2005 (HY000): Unknown MySQL server host 'myhost.example.com
Run Code Online (Sandbox Code Playgroud)

这是我的琐碎的ssh命令应该工作,或者至少给出一个正常的错误信息,但是它被包裹起来以冒号开头并以奇怪的破坏结束:

Command:  ssh myhost
Expected: ssh: Could …
Run Code Online (Sandbox Code Playgroud)

bash shell sh carriage-return

7
推荐指数
1
解决办法
1873
查看次数

标签 统计

bash ×2

carriage-return ×1

makefile ×1

sh ×1

shell ×1