🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
6 messages
6 total messages Started by Jon Deutsch Wed, 14 Nov 1990 17:12
IF syntax
#1213
Author: Jon Deutsch
Date: Wed, 14 Nov 1990 17:12
26 lines
987 bytes
OK, second try at the question:

I'm using sh to impliment an IF statement.  Can't get it to work.
Here's the code:


#!/bin/sh
if [$temp != '']  then
        echo 'remote-caller' >> .people;
else
	echo 'inside-caller' >> .people;
fi


I keep getting an ELSE UNEXPECTED.  
So, I tried an ELIF, but no go.
Any answers?
(as you can see, I'm new to sh!)
thanx


       X-------------------+--------------+-----------------------X
       |  |   |\       |>jon@brahms.udel.edu<|  "For my 2 cents,  |
       | \|on |/eutsch |>>-----------------<<|  I'd pay a dollar" |
       X------+--------------------+--------------------+---------X
Re: IF syntax
#1219
Author: Paul Harsha
Date: Wed, 14 Nov 1990 18:39
26 lines
689 bytes
jon@brahms.udel.edu (Jon Deutsch) writes:



>#!/bin/sh
>if [$temp != '']  then
>        echo 'remote-caller' >> .people;
>else
>	echo 'inside-caller' >> .people;
>fi

>I keep getting an ELSE UNEXPECTED.  

You need to put the "then" on a seperate line

#!/bin/sh
if [$temp != '']  
then
        echo 'remote-caller' >> .people;
else
        echo 'inside-caller' >> .people;
fi

works just fine.

-Paul
Re: IF syntax
#1215
Author: stetner Douglas Stetner
Date: Wed, 14 Nov 1990 22:18
30 lines
1222 bytes
In article <15796@brahms.udel.edu> jon@brahms.udel.edu (Jon Deutsch) writes:
>
>OK, second try at the question:
>
>I'm using sh to impliment an IF statement.  Can't get it to work.
>Here's the code:
>
>
>#!/bin/sh
>if [$temp != '']  then
>        echo 'remote-caller' >> .people;
>else
>	echo 'inside-caller' >> .people;
>fi
>
Try (note quotes and spaces):

#!/bin/sh
if [ "$temp" != "" ]
then
	echo 'remote-caller' >> .people;
else
	echo 'inside-caller' >> .people;
fi

--
--------------------------------------------------------------------------------
Douglas G. Stetner, 4S75  |  Bell-Northern Research  | My opinions are my own.
      stetner@bnr.ca      |  P.O. Box 3511, Stn. C   | (613) 828-6321  (home)
 ..!uunet!bnrgate!stetner |  Ottawa, ON, CANADA      | (613) 763-8396  (work)
Re: IF syntax
#1220
Author: Earl Chew
Date: Thu, 15 Nov 1990 01:41
27 lines
964 bytes
In <965@ksr.com> harsha@ksr.com (Paul Harsha) writes:

>#!/bin/sh
>if [$temp != '']  
>then
>        echo 'remote-caller' >> .people;
>else
>        echo 'inside-caller' >> .people;
>fi

>works just fine.

#!/bin/sh
if [ $temp != '' ]
then
        echo 'remote-caller' >> .people;
else
        echo 'inside-caller' >> .people;
fi

works better when temp != '' :-)

Earl
-- 
Earl Chew, Dept of Computer Science, Monash University, Australia 3168
EMAIL: cechew@bruce.cs.monash.edu.au PHONE: 03 5655447 FAX: 03 5655146
----------------------------------------------------------------------
Re: IF syntax
#1222
Author: Hamish Macdonald
Date: Thu, 15 Nov 1990 15:19
36 lines
1469 bytes
>>>>> In article <965@ksr.com>, harsha@ksr.com (Paul Harsha) writes:

Paul> You need to put the "then" on a seperate line

Paul> #!/bin/sh
Paul> if [$temp != '']  
Paul> then
Paul>         echo 'remote-caller' >> .people;
Paul> else
Paul>         echo 'inside-caller' >> .people;
Paul> fi

How about 'can put the "then" on a separate line':

if [ "$temp" != "" ]; then

works just fine.  The semicolon terminates the list of statements
forming the condition of the if.

I think there is a problem if you don't double-quote your variable or
leave white space around the "[" and "]" too:

1>@maytag[3]% echo a${temp}a
aa
1>@maytag[4]% if [$temp != '']; then echo blug; else echo bleah; fi
blug

It should echo "bleah"

1>@maytag[12]% if [ "$temp" != "" ]; then echo blug; else echo bleah; fi
bleah

Hamish.
--
--------------------------------------------------------------------
himacdon@maytag.uwaterloo.ca                 watmath!maytag!himacdon
Re: IF syntax
#1314
Author: Wai Yeung
Date: Sat, 01 Dec 1990 23:05
24 lines
969 bytes
In article <15796@brahms.udel.edu>, jon@brahms.udel.edu (Jon Deutsch) writes:
> 
> #!/bin/sh
> if [$temp != '']  then
>         echo 'remote-caller' >> .people;
> else
> 	echo 'inside-caller' >> .people;
> fi
> 
The "then" has to be on the next line. Also, for [ ... ] to check for an
empty string, it isn't necessary to compare with "" (or '').

The following should work.
#
#!/bin/sh
if [ "$temp" ] # Note the quotes
then
    echo 'remote-caller' >> .people
else
    echo 'inside-caller' >> .people
fi
#

Chee Wai
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads