Reply
Thread Tools
Posts: 1,950 | Thanked: 1,174 times | Joined on Jan 2008 @ Seattle, USA
#1
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.
__________________
.
. .

Help Save This Forum
for N8x0/Diablo Users! Register and Vote for Solution #1 on this Brainstorm. (The Solution will let you see New Posts with any threads you choose -- like the N900 and Maemo5/Fremantle threads -- filtered out.) (To understand the Solution better, see these posts #17, #18, and #19.)
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#2
fi is used in scripts to end a if statement afaik so it will execute the rest of a script.
 

The Following 3 Users Say Thank You to qwerty12 For This Useful Post:
joepagiii's Avatar
Posts: 449 | Thanked: 51 times | Joined on Apr 2008 @ eastern north carolina usa
#3
dont know if this helps but i googled it http://linux.byexamples.com/archives/107/if-then-fi/
 

The Following User Says Thank You to joepagiii For This Useful Post:
Posts: 3,841 | Thanked: 1,079 times | Joined on Nov 2006
#4
'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"
__________________
N800/OS2007|N900/Maemo5
-- Metalayer-crawler delenda est.
-- Current state: Fed up with everything MeeGo.
 

The Following User Says Thank You to TA-t3 For This Useful Post:
Posts: 5,335 | Thanked: 8,187 times | Joined on Mar 2007 @ Pennsylvania, USA
#5
Originally Posted by GeraldKo View Post
fi shows up in scripts...
They're there to keep an eye out for the devious "esac".
 
penguinbait's Avatar
Posts: 3,096 | Thanked: 1,525 times | Joined on Jan 2006 @ Michigan, USA
#6
As mentioned "fi" is the end of a "if" statement

if something happens
then
do something
else
dont do something
fi
__________________
To all my Maemo friends. I will no longer be monitoring any of my threads here on a regular basis. I am no longer supporting anything I did under maemo at maemo.org. If you need some help with something you can reach me at tablethacker.com or www.facebook.com/penguinbait. I have disabled my PM's here, and removed myself from Council email and Community mailing list. There has been some fun times, see you around.
 
briand's Avatar
Posts: 566 | Thanked: 145 times | Joined on Feb 2008 @ Tallahassee, FL
#7
GeraldKo (and anyone else who wondered...) --

regarding the esac reference above: it performs the same function at the conclusion of a case statement.
 
Posts: 5,335 | Thanked: 8,187 times | Joined on Mar 2007 @ Pennsylvania, USA
#8
Originally Posted by briand View Post
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?
 

The Following User Says Thank You to sjgadsby For This Useful Post:
Posts: 263 | Thanked: 679 times | Joined on Apr 2008 @ Lyon, France
#9
Originally Posted by GeraldKo View Post
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's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#10
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...
 
Reply


 
Forum Jump


All times are GMT. The time now is 13:13.