问题描述
我每次运行使用脚本庆典scriptname.sh
从Debian的命令行中,我得到命令未找到
然后脚本的结果。所以脚本工作,但总是有打印屏幕上的命令未找到
语句。
Every time I run a script using bash scriptname.sh
from the command line in Debian, I get Command Not found
and then the result of the script. So the script works but there is always a Command Not Found
statement printed on screen.
我正在从剧本 / VAR
文件夹中。
I am running the script from the /var
folder.
下面是脚本:
#!/bin/bash
echo Hello World
我通过键入以下运行它:
I run it by typing the following:
bash testscript.sh
更新 - 问题出现在空行。每个空白行导致无法找到命令。为什么会发生这种情况?
UPDATE - the problem appears to the blank lines. Each blank line is resulting in a command not found. Why would this occur?
推荐答案
请确保您的第一行是:
#!/bin/bash
输入您的路径来砸如果不是 /斌/庆典
Enter your path to bash if it is not /bin/bash
尝试运行:
dos2unix script.sh
这WIL转换行尾等从Windows到UNIX格式。也就是说,它去掉从行结束符\\ R(CR),将它们从更改\\ r \\ n(CR + LF)
到 \\ n(LF)
。
That wil convert line endings, etc from Windows to unix format. i.e. it strips \r (CR) from line endings to change them from \r\n (CR+LF)
to \n (LF)
.
More details about the dos2unix
command (man page)
另一种方式告诉如果您的文件在DOS / Win的格式为:
Another way to tell if your file is in dos/Win format:
cat scriptname.sh | sed 's/\r/<CR>/'
输出会是这个样子:
The output will look something like this:
#!/bin/sh<CR>
<CR>
echo Hello World<CR>
<CR>
这将输出&LT整个文件文本; CR&GT;
文件中显示每个 \\ r
字符
This will output the entire file text with <CR>
displayed for each \r
character in the file.
的 P.S。很抱歉的穷人格式化,这是从我的iPhone,而开车上班书面:P 的
这篇关于bash脚本始终打印&QUOT;找不到命令&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!