Date: Mon, 30 Sep 1996 09:16:31 -0400 (EDT) From: Thomas David Rivers <ponds!rivers@dg-rtp.dg.com> To: tcg@ime.net, ponds!freebsd.org!questions Subject: Re: sh shell script help needed! Message-ID: <199609301316.JAA02770@lakes.water.net>
next in thread | raw e-mail | index | archive | help
>
>
> What am I doing wrong here?? (Yes, I know it's me :)
> Such a simple thing and I can't get it to work!
>
> # test script
> # based on /etc/rc usage of if
> if [ $1 = yes ] then
Here's your problem..
the 'then' part of an 'if' must be on a separate 'line'. This can be
accomplished by physically moving the then to the next line (which is
what I prefer) or by inserting the ';' separator...
As in:
if [ $1 = yes ]
then
echo Yes
fi
or
if [ $1 = yes ] ; then
echo Yes
fi
Now, your next question should be "That seems pretty dumb - why is it so?"
The problem is that (logically, if not actually) the 'if' statement
actually runs a program, in this instance, a program named '[' which is
a link to a program named 'test'. This program is presumed to accept
arguments, which are in your case "$1 = yes ]". (Note that ']' is not
the close of '[', it is an (ignored) argument to the 'test' program.)
So, the shell needs to determine when the arguments are over, and
where the 'then' is. You do that by inserting a command separator (the ';')
or by putting the 'then' on the next line.
Hope this helps
- Dave Rivers -
> ramillia {1377} ./test yes
> if: Expression Syntax
> ramillia {1378}
>
> Such an easy thing... ... I've tried every variation I can think of while
> crusing through stuff in /etc
>
> Thanks.
>
> -Enjoy
> Gary
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609301316.JAA02770>
