read command in shell script what to do for reading a particular char
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
read command in shell script what to do for reading a particular char
What is the shell command like read to read a particular char from input
like if i want c to be entered to go forward and execute another shell commands.
read Value
if(($value=="c"))
then
echo "move forward"
fi
m not sure of scripting syntax here
but using "read <variable-name>" will read the standard input into <variable-name>.
I have written the code as
date
read value1
if [ $value1="acd" ]
then
who
fi
exit
now it should print only the date and exit but instead it is printing date and then executing who command.
so what should be the testing conditions in if [..] to compare with value1
and then decide whether to execute who or not.
date
read value1
if [ $value1="acd" ]
then
who
fi
exit
now it should print only the date and exit but instead it is printing date and then executing who command.
so what should be the testing conditions in if [..] to compare with value1
and then decide whether to execute who or not.
the IF statement synatax is :
if[$value -eq <your-string>]
then
<statements>
fi
<more - statements>
#!/bin/bash
read value
if [[ "$value" == "anda" ]]; then
echo "You entered anda"
else
echo "You didn't entered anda, instead you entred $value"
fi
Thanks for your valuable help but it won't work unless there are spaces b/w
"$value" and '==' & '==' and "anda"
for the expected comparison "$value"="anda" the condition must be like this.
Of course it won't work if you don't have spaces between them. That is why there are spaces between them. I don't understand what you mean.
Yes you are absolutely right but can u get me understood why the gcc compiler making the condition always true when there are no spaces whether the strings are same or different . Like
read value1
echo "value is $value1"
if [[ "$value1"=="acd" ]];
then
pwd
else
who
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.