Shell script

Asked by peter

Hi

I developed a shell script with the following lines:

read x
if $x = a then
echo 'x ist a'
fi
read i

If I start the script, I can enter the key "a". I do this and press Enter. And the script will be finished immediately.

Why I don't get the echo? Where's the problem? Thanks.
Peter

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Solved by:
peter
Solved:
Last query:
Last reply:
Revision history for this message
Sam_ (and-sam) said :
#1
Revision history for this message
Andrea Francia (andrea-francia) said :
#2

I don't know what shell are you using but if you are using bash read the followings.

You should use the `test` command or the `[` command.

read a
if [ "$x" = "a" ]; then
   echo 'x ist a';
fi
read i

You can find more information typing `help test` or `help [`

Revision history for this message
peter (peter-neuweiler) said :
#3

Hi Sam

Thanks a lot.
Peter

Revision history for this message
peter (peter-neuweiler) said :
#4

Hi Andrea

Wow - thanks. You helped me. The brackets are important. Thanks a lot.
Peter

Revision history for this message
Sam_ (and-sam) said :
#5

My pleasure.
About Test Constructs
http://tldp.org/LDP/abs/html/testconstructs.html

Revision history for this message
peter (peter-neuweiler) said :
#6

Thanks Sam.
Peter