bash Linux:非法选项读取 -a
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30554353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux: Illegal option read -a
提问by user3410687
I have found the answer for this question... Just want to provide some information for others, who met this problem too...
我已经找到了这个问题的答案......只是想为其他也遇到这个问题的人提供一些信息......
In my system, I got this problem because of I used the sh main.sh
to process my shell script and ignore the difference between "Bash" and "Shell".
在我的系统中,我遇到了这个问题,因为我使用sh main.sh
来处理我的 shell 脚本并忽略了“Bash”和“Shell”之间的区别。
In order to solve this problem, you might try to change the mode into executable, by using chmod +x
and using ./
to execute the program.
为了解决这个问题,您可以尝试将模式改为可执行,通过使用chmod +x
和使用./
来执行程序。
Good luck!
祝你好运!
回答by Jahid
The error:
错误:
Illegal option read -a
was shown because you were trying to run it in a shell where the -a
option for read
isn't defined.
显示是因为您试图在未定义-a
选项的 shell 中运行它read
。
the command chmod +x script.sh
has nothing to do with it. It just merely gives the script execution permission.
命令chmod +x script.sh
与它无关。它只是授予脚本执行权限。
You were trying to run the command in Bourne shell by the command sh script.sh
and Bourne shell read
doesn't have the -a
option for read. It's a Bash feature.
您试图通过命令在 Bourne shell 中运行该命令,sh script.sh
而 Bourne shellread
没有-a
读取选项。这是一个 Bash 功能。
Running with ./
is not quite an answer. You could say at least : run it with path_to_the_script
because not every time your script will end up in the current directory.
与一起跑步./
并不是一个很好的答案。你至少可以说:运行它,path_to_the_script
因为不是每次你的脚本都会在当前目录中结束。
You can run it with bash main.sh
instead of sh main.sh
.
您可以使用bash main.sh
代替sh main.sh
.