奇怪的行为
我写了一个简单的脚本 test
echo hello #<-- inside test
如果我在 hello 之后按一次 Enter,我的脚本就会运行,如果我不按 - 它不会,如果两次我会收到我的 hello 并且 + 命令是未找到,有人可以向我解释一下这种行为吗?提前致谢
This is not a part of the code, this is actual code
,我通过 Windows 编辑器在 C-Shell 上运行它 命令:
source ./test
I wrote simple script test
echo hello #<-- inside test
if I press one time enter after hello, my script will run, if I don't press - it will not, if two times I'll receive my hello and + command was not found, can somebody please explain me this behavior thanks in advance
This is not a part of the code, this is actual code
and I run it on C-Shell, via editor of Windows
command:
source ./test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几点:
您不应该问同时带有 [csh] 和 [bash] 标签的问题 - 这些是完全不同的程序并实现完全不同的脚本编程语言
您永远不应该将脚本(或任何其他程序)命名为
test
,因为这是bash 的内置功能发布您所询问的实际代码,不带注释,并显示您如何运行它。
Some points:
You should not ask questions tagged with both the [csh] and [bash] tags - these are completely different programs and implement completely different script programming languages
You should never name a script (or any other program)
test
, as this is the name of a built-in feature of bashPost the actual code you are asking about, without annotations and show how you run it.
我曾经尝试过类似的案例。我编写了一个像您一样的脚本,使用 Windows 记事本(带有 CRLF 行终止符)保存它,并在 bash 中运行,其效果与您在 csh 中的效果相同。问题是 bash(csh 也是如此)不理解 Windows 的 2 字节行终止符,它们被解释为命令,显然不存在。
解决方案是:更改您的编辑器或将当前编辑器配置为使用 unix 行终止符。
您可以尝试例如 Notepad++。请记住将行终止符更改为 LF。
I have tried a similar case. I wrote a script like yours, saved it using Windows Notepad (with CRLF line terminators) and run in bash with the same effect as yours in csh. The problem is bash (so csh as well) does not understand Windows' 2-byte line terminators, which are interpreted as commands, which obviously do not exist.
The solution is: change your editor or configure your current editor to use unix line terminators.
You can try for example Notepad++. Remember to change the line terminators to LF.