Linux: Illegal option read -a

2019-09-22 09:24发布

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".

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.

Good luck!

标签: linux bash shell
1条回答
放我归山
2楼-- · 2019-09-22 09:59

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.

the command chmod +x script.sh has nothing to do with it. It just merely gives the script execution permission.

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.

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.

You can run it with bash main.sh instead of sh main.sh.

查看更多
登录 后发表回答