Re: Shell scripting in Bash
>>>>> "D" == Dale Scheetz <dwarf@polaris.net> writes:
D> I have been trying to learn shell scripting using the man page for
D> bash. Asside from the need for a lot of reading between the lines,
D> there seem to be several errors. == is declared to be the equality
D> operator, but = is the correct syntax. || is declared to be the or
D> operator, but although:
D> What is the correct syntax for this kind of statement?
I think I see the source of your confusion. As usual there is more
going on here than you thought. First you have to realize that
[ foo ]
is a special construct in bash, which is just a synonym for
test foo
So within the brackets, only the syntax that test can understand
applies. See the bash man page for more details, but basically, test
uses = for equality, but in other places (arithmetic "lets" etc.)
bash uses == for equality (nice huh?). Also, test doesn't understand
|| at all, instead it uses -o for or. The || syntax is generally used
for linking commands like:
netscape || shutdown -h now
<SARCASM INTENDED>
The test entry in the bash man page has a list of all the operators
that it can handle.
[Std disclaimer about personal conviction that perl is easier and
faster than the shell applies (of course there are good reasons to
ignore this disclaimer)]
Hope this helps,
--
Rob
Reply to: