繁体   English   中英

直接命令行输入运行命令,但bash脚本不运行

[英]Direct command line input runs command but bash script does not

我能够成功运行

/opt/hbase/hbase_current/bin/hbase

在命令行上,当连接到GNU / Linux集群时。

但是,当我将此命令放在bash脚本的一行中时,错误是:

: No such file or directoryopt/hbase/hbase_current/bin/hbase

我究竟做错了什么?

当我基于“哪个bash”的结果向bash脚本添加标头时,出现以下错误:

bash: ./file.sh: /bin/bash^M: bad interpreter: No such file or directory

该文件的内容如下:

#!/bin/bash
ENTITY="'A.B.C'"
HBASE_SHELL="/opt/hbase/hbase_current/bin/hbase"
FILE="A.B.C.txt"
/opt/hbase/hbase_current/bin/hbase
#echo "scan $ENTITY" | $HBASE_SHELL > $FILE

哦,行尾有DOS风格的CR / LF。 您可以看到它们,因为它们显示为^M

做这个:

tr -d '\r' < file.sh > newfile.sh
chmod +x newfile.sh
./newfile.sh

tr命令以-d开头,这意味着删除所有后续出现的内容,在这种情况下,这是表示回车( CR )的序列。

看来您已从Windows框中复制了脚本。 尝试对文件执行dos2unix删除Windows行尾:

$ dos2unix file.sh

sudo apt-get install dos2unix如果没有的话)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM