#!/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 the-t
option for theread
builtin since versionbash-2.04
(see ChangeLog), so either you are using an ancient version ofbash
(<=2.03
) or are not really running your script underbash
.Run
bash --version
to check the version and double-check that your shebang really looks like#!/bin/bash
in your script.Bash supports
-t
, so it looks like you're trying to execute it withsh
or some other shell, which is odd, since you have the correct shebang.Make sure you run it with
./script
orpath_to_script/script
. If you just run it in the terminal, first startbash
.