Variables in scripts
Dave Basener
dbasener at aurora.edu
Fri Oct 8 16:33:33 UTC 2004
Brian,
The script, exactly as you give it here fails with a syntax error in the
test command because you initialize "change" to 0 but then use
$changed. This, in /bin/sh will always cause a syntax error because
$changed has no value and the "-eq" is a binary operator.
I am unable to test your script on a Linux machine in true "sh" because
all of my systems have /bin/sh linked to /bin/bash. I was able to try
it on a TRU-64 (osf5.1) UNIX machine with a real "bin/sh".
Results:
Original script fails in both bash and true sh
After taking care of the apparent typo by changing "change=0" to
"changed=0" the script works in both environments. The final echo emits 1.
If your typo was only in the mail and not in the real script, the I have
no idea why it wouldn't work in /bin/sh on Linux.
Dave Basener
Brian McGrew wrote:
>I'm asking this question here becuase what I have works on Solaris but not Redhat 7.3
>
>I have a simple script:
>
>#!/bin/sh
>
>change=0
>
>while [ $changed -eq 0 ];
>do
> changed=1
> echo $changed
>done
>
>echo $changed
>exit
>
>When I come to the last echo $changed, it's back to 0. Any idea why that is? This works find on Solaris???
>
>-brian
>
>Brian D. McGrew { brian at doubledimension.com || brian at visionpro.com }
>---
>
>
>>YOU! Off my planet!
>>
>>
>
>
>
--
"... be the change you wish to see in the world." - Gandhi
David Basener http://www.aurora.edu/~dbasener
System Administrator Dave.Basener at aurora.edu
Aurora University 630 844 4889
More information about the redhat-list
mailing list