Linux: Illegal option read
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!
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
.
上一篇: 'echo'在shell脚本中没有换行符
下一篇: Linux:非法选项读取