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.
root@***'s password:
-----------Select (em) or (e) or (cm)---------
em
[: 24: em: unexpected operator
[: 27: em: unexpected operator
Script code:
Code:
echo "-----------Select (em) or (e) or (cm)---------"
read dom
if [ "$dom" == "em" ];then
mplayer sshfs/Hudba/*
exit
fi
if [ "$dom" == "e" ];then
exit
fi
i want to ask why it sends unexpected operator when i type "em"?
Always verify your test criteria first. Since I don't know what lines 24 and 27 exactly are in your script, I can't say anything specific about them.
Why does it show something appearing to be root password being entered? You should not be running scripts as root, and if there's a command in that script requiring root privileges, then you should be using sudo.
I'm guessing that the unexpected operator has more to do with your call to mplayer versus your test, because if you examine the tests, they work.
Consider using elif.
Consider using exit a bit less:
Code:
#!/bin/sh
echo "-----------Select (em) or (e) or (cm)---------"
read dom
if [ "$dom" == "em" ];then
echo "user entered em"
elif [ "$dom" == "e" ];then
echo "user entered e"
elif [ "$dom" == "cm" ]; then
echo "user entered cm"
else
echo "user entered something else"
fi
exit 0;
Sample outputs:
Code:
~/testcode$ mplayer.sh
-----------Select (em) or (e) or (cm)---------
em
user entered em
~/testcode$ mplayer.sh
-----------Select (em) or (e) or (cm)---------
e
user entered e
~/testcode$ mplayer.sh
-----------Select (em) or (e) or (cm)---------
cm
user entered cm
~/testcode$ mplayer.sh
-----------Select (em) or (e) or (cm)---------
other
user entered something else
echo "-----------Select (em) or (e) or (cm)---------"
read dom
if [ "$dom" == "em" ];then
mplayer sshfs/Hudba/*
exit
fi
if [ "$dom" == "e" ];then
exit
fi
This worked for me flawlessly, except I have replaced "mplayer sshfs/Hudba/*" with "echo Hello".
So may be it is something related with mplayer.
Try using "=" instead of "==".
"unexpected operator" is not a bash error message. However dash gives that message if '==' is used instead of '=' in a test. Bash supports '==' but dash doesn't.
If dash is the default shell and the script was started with sh then the script will be running in dash, not bash.
Error message strings can be extracted from shells with od
If you wish to keep formatting so everyone can see the difference in what you have typed, you will need to use [code][/code] tags around your code / data.
Remember to mark as SOLVED once you have a solution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.