Request for best use of semicolon and fi in scripts
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 didn't come across with the option to not having a fi, but that may be possible and I'm just ignorant of the fact; I'd like to know if that's possible.
for every 'if' there must be a 'fi'
using the ';' gives a little extra 'continuity' since it tells the shell that something follows. using the '&' is similar. Using '&&' tells bash to run the following command only if the first was successful.
a ';' is not used after 'then'.
It's best to make sure there is a space between all commands and ; & &&
also fi should have a blank space after it and it's best to end a script with a blank line
One of the best script writers out there, Klaus Knopper, always uses the semicolon.
Your script got fouled up someway. there should be a 'fi' to finish that rc.cups call. look at the entries above and below. See how they all begin and end in a little group. the way yours is all the calls that follow the rc.cups call are dependent on cups being present. if you were to uninstall cups rc.M wouldn't find it and wouldn't start anything in the script after that.
Start at the top of the script and follow the if/fi combos. If they are nested then you may get the fis together at the end:
if 'something' ; then
if 'somethingelse' ; then
'do something'
fi
fi
It helps if the scripts are well indented. You can insert TABS to help
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.