Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resolve this error in shell scripting: "read: Illegal option -t"?

Tags:

bash

shell

ubuntu

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

like image 227
Utkarsh Parekh Avatar asked Aug 19 '13 07:08

Utkarsh Parekh


People also ask

What does read do in shell script?

The read command reads one line from standard input and assigns the values of each field in the input line to a shell variable using the characters in the IFS (Internal Field Separator) variable as separators.

What is $? == 0 in shell script?

$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.

What is $1 and $2 in shell script?

These are positional arguments of the script. Executing ./script.sh Hello World. Will make $0 = ./script.sh $1 = Hello $2 = World. Note. If you execute ./script.sh , $0 will give output ./script.sh but if you execute it with bash script.sh it will give output script.sh .


1 Answers

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.

like image 113
Karoly Horvath Avatar answered Sep 17 '22 08:09

Karoly Horvath