maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Newbie (https://talk.maemo.org/forumdisplay.php?f=26)
-   -   What is fi or "the fi command" in Linux/Unix? (https://talk.maemo.org/showthread.php?t=19674)

GeraldKo 2008-04-30 14:38

What is fi or "the fi command" in Linux/Unix?
 
fi shows up in scripts, and I'm finding it surprisingly hard to get a good explanation of what fi is doing in them. Is it a command? Is it short for something? What does it do?

Thanks.

qwerty12 2008-04-30 14:39

Re: What is fi or "the fi command" in Linux/Unix?
 
fi is used in scripts to end a if statement afaik so it will execute the rest of a script.

joepagiii 2008-04-30 14:41

Re: What is fi or "the fi command" in Linux/Unix?
 
dont know if this helps but i googled it http://linux.byexamples.com/archives/107/if-then-fi/

TA-t3 2008-04-30 14:54

Re: What is fi or "the fi command" in Linux/Unix?
 
'fi' is simply the sh-style name for 'endif', to finish an 'if' statement. E.g.:
Code:

#!/bin/sh
# Check if this file exists:
if test -e config.file
then
  echo "You have a config.file file"
else
  echo "No such file config.file"
fi
echo "Finished with my 'if' test"


sjgadsby 2008-04-30 14:56

Re: What is fi or "the fi command" in Linux/Unix?
 
Quote:

Originally Posted by GeraldKo (Post 176348)
fi shows up in scripts...

They're there to keep an eye out for the devious "esac".

penguinbait 2008-04-30 14:56

Re: What is fi or "the fi command" in Linux/Unix?
 
As mentioned "fi" is the end of a "if" statement

if something happens
then
do something
else
dont do something
fi

briand 2008-04-30 15:09

Re: What is fi or "the fi command" in Linux/Unix?
 
GeraldKo (and anyone else who wondered...) --

regarding the esac reference above: it performs the same function at the conclusion of a case statement. :)

sjgadsby 2008-04-30 15:14

Re: What is fi or "the fi command" in Linux/Unix?
 
Quote:

Originally Posted by briand (Post 176372)
regarding the esac reference above: it performs the same function at the conclusion of a case statement.

Killjoy! What, you gonna help him see the fnords next?

dneary 2008-04-30 15:31

Re: What is fi or "the fi command" in Linux/Unix?
 
Quote:

Originally Posted by GeraldKo (Post 176348)
fi shows up in scripts, and I'm finding it surprisingly hard to get a good explanation of what fi is doing in them. Is it a command? Is it short for something? What does it do?

Hi,

You already got the answer - fi ends an if, much like endif does in other languages (some would say endif would have been better for bash too).

There are four main conditional statements in shell scripts:
if... ; then...; else...; fi
for ...; do...; done
while...; do...; done
and

case ... in
...
esac

You can see that if ends in fi, and case in esac. for and while both use the more understandable do...done convention which is appropriate for loops.

Benson 2008-04-30 15:50

Re: What is fi or "the fi command" in Linux/Unix?
 
There's elif, too:
Code:

if ... ; then
  ...
elif ... ; then
  ...
elif ... ; then
  ...
elif ... ; then
  ...
else
  ...
fi

Yeah, it could be done with else and if, but then you'd have to go fi-fi-fi-fi at the end...

briand 2008-04-30 18:36

Re: What is fi or "the fi command" in Linux/Unix?
 
Quote:

but then you'd have to go fi-fi-fi-fi at the end...
or you could simply chant:

fi-fi-fo-fum,
I suspect a shell script-run.


sorry, couldn't resist

GeraldKo 2008-04-30 19:27

Re: What is fi or "the fi command" in Linux/Unix?
 
Quote:

Originally Posted by penguinbait (Post 176367)
As mentioned "fi" is the end of a "if" statement

if something happens
then
do something
else
dont do something
fi

If you look at question and answer #1 in this post, ... well, it seems to me that it went

(A) If ... fi; else ... fi

rather than

(B) If ... else ... fi

which is what I'd have expected. But when I went with (B) (that is, without the first fi), the script didn't work. With (A) I had success. Is there an "implicit if" in "RC=$?" or something like that?

m_stolle 2008-04-30 20:33

Re: What is fi or "the fi command" in Linux/Unix?
 
The if's and fi's have to be balanced. Assuming there are no more "if"'s in (A) in the dotted parts, then (A) will definitely NOT work.

In the original post, unless there is an additional "if" in the beginning, the first snippet is not valid. Which would explain why th unmounting didn't work. The second snippet looks correct (and is the one that is supposed to be working anways).

What's the problem?

Martin

mplawner 2008-05-02 03:47

Re: What is fi or "the fi command" in Linux/Unix?
 
Isn't it time to...

daerht


All times are GMT. The time now is 20:03.

vBulletin® Version 3.8.8