#!/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".
#!/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".
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
.
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.