In article <[EMAIL PROTECTED]>, Dale Scheetz <[EMAIL PROTECTED]> wrote: >I have been trying to learn shell scripting using the man page for bash. >Asside from the need for a lot of reading between the lines, there seem to >be several errors. == is declared to be the equality operator, but = is >the correct syntax. || is declared to be the or operator, but although: > >if [ a != b ] > >works fine > >if [ a != b || c != d ] > >fails with several errors ( ']' not found, and != command not found )
'[' is really an alias for the "test" command, and there is a manpage for it -- "man test". When you realize that '[' is just a command (it is built in to most shells, but there probably _is_ a '[' in /usr/bin) you can see that if [ a != b || c != d ] ^ ^^ | End of command; shell starts interpreting next command +-- the command '[' doesn't work. The first '[' doesn't find a trailing ']' and tells you so, and the shell tries to interpret "c != d" as the next command. If it said "!= command not found" then you probably used $c != $d and $c was empty. Try: if [ "$a" != "$b" -o "$c" != "$d" ] or, calling the '[' command twice and using shell logic: if [ "$a" != "$b" ] || [ "$c" != "$d" ] then ... fi The quoting protects you when $a is empty - it produces an empty string instead of just nothing at all. Remember that the shell does substitution first before executing a command. Good luck -- Mike. -- + Miquel van Smoorenburg + Cistron Internet Services + Living is a | | [EMAIL PROTECTED] (SP6) | Independent Dutch ISP | horizontal | + [EMAIL PROTECTED] + http://www.cistron.nl/ + fall +

