Linux 帮助不断收到第 6 行的新行错误,不知道问题是什么
#!/bin/sh 如果($#argv == 0) echo 没有参数 如果($#argv!= 0) echo 有 $#argv 参数
#!/bin/sh
if ($#argv == 0)
echo There are no arguments
if ($#argv != 0)
echo There are $#argv arguments
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对你遇到错误并不感到惊讶;您有几个语法错误和不正确的构造,它们会阻止您的代码在 Bourne shell(由 shebang 行指示的解释器)上运行。我已经修复了下面的代码,因此
sh
将实际运行它:也就是说,您正在测试相同的条件两次(
"$#" == "0"
/"$#" != "0"
);我会将其重构为一个简单的 if/else,而不是您当前拥有的两个单独的条件。I'm not surprised you're getting errors; you have several syntax errors and incorrect constructs that would prevent your code from running on the Bourne shell (the interpreter indicated by your shebang line). I've fixed your code below so
sh
will actually run it:That being said, you're testing for the same condition twice (
"$#" == "0"
/"$#" != "0"
); I would refactor this to just a simple if/else instead of the two separate conditionals you have currently.