ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I'm unable to figure out where I'm going wrong in the if statement of my script. Could you please take a look and help me identify the what I'm doing wrong and in fixing the errors. Thanks in advance.
Code:
if ( "$1" == "-u" || "$1" == "-U" ) #line 17
then
echo "perform option 1"
elif ( "$1" == "-i" || "$1" == "-I" ) #line 20
then
echo "perform option 2"
elif ( "$1" == "-ui" || "$1" == "-UI" ) #line 23
then
echo "perform option 3"
else
echo "No argument. Valid optiosn are {-u|-U}, {-i|-I}, {-ui|-UI}"
fi
Below are the errors I'm getting
Code:
+ '' == -u
install_scrpt: line 17: : command not found
+ '' == -U
install_scrpt: line 17: : command not found
+ '' == -i
install_scrpt: line 20: : command not found
+ '' == -I
install_scrpt: line 20: : command not found
+ '' == -ui
install_scrpt: line 23: : command not found
+ '' == -UI
install_scrpt: line 23: : command not found
( string ) means you want to execute the string (inside) in a new shell.
As you can see the string is '' == -u (or similar) which cannot be executed. You need to change () to [[]] or use switch/case.
Hi new_user....! Welcome!
From the parentheses, I'm guessing you have *programming* experience [?]
In csh, a C-language-like shell a few pages down, in here, your code would *almost* work
(except csh uses "else if" and "endif", so the "elif/fi" makes it obvious you mean [ba]sh)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.