1828961 Members
2294 Online
109986 Solutions
New Discussion

Re: Scripts and If

 
SOLVED
Go to solution
Ian Warner
Trusted Contributor

Scripts and If

Why does the following script fragment not work?

if [ $# -eq 0 ]
then
echo "No file name entered "
exit
else
echo "ok"
endif


If I run this, I get the error
Syntax error: `if' is not matched. every time.

Is it just me being exceedingly thick??

Ian Warner
Why did anyone invent unix?
3 REPLIES 3
Luk Vandenbussche
Honored Contributor

Re: Scripts and If

Ian,

IF loop ends with fi

if [ $# -eq 0 ]
then
echo "No file name entered "
exit
else
fi
V. Nyga
Honored Contributor
Solution

Re: Scripts and If

Hi,

it depends which shell you're running.
See also:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1026132
and for the options:
http://www.context-switch.com/reference/kshref/ch4.html

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Ian Warner
Trusted Contributor

Re: Scripts and If

Thank you,

I will put it down to me being thick.


Ian
Why did anyone invent unix?