How can I resolve this error in shell scripting: “

2019-07-02 05:57发布

#!/bin/bash
echo -n "Hurry up and type something! > "
if read -t 10 response ; then
echo "Greate, you made it in time!"
else
echo "sorry, you are too slow!"
fi

I have written above code in terminal and got error "read: Illegal option -t".

2条回答
Ridiculous、
2楼-- · 2019-07-02 06:28

bash supports the -t option for the read builtin since version bash-2.04 (see ChangeLog), so either you are using an ancient version of bash (<= 2.03) or are not really running your script under bash.

Run bash --version to check the version and double-check that your shebang really looks like #!/bin/bash in your script.

查看更多
你好瞎i
3楼-- · 2019-07-02 06:39

Bash supports -t, so it looks like you're trying to execute it with sh or some other shell, which is odd, since you have the correct shebang.

Make sure you run it with ./script or path_to_script/script. If you just run it in the terminal, first start bash.

查看更多
登录 后发表回答