Re: Variables in scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx || brian@xxxxxxxxxxxxx }
---


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@xxxxxxxxxx
Aurora University                              630 844 4889

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux