Re: Comparing strings
Lewis <[email protected]> Wed, 14 Jul 2021 00:07:14 -0000 (UTC)
| Newsgroups | alt.comp.lang.shell.unix.bourne-bash |
|---|---|
| Organization | Miskatonic U |
| Message-ID | <[email protected]> |
In message <[email protected]> Michael F. Stemper <[email protected]> wrote: > On 13/07/2021 12.46, ELCV wrote: >> If I do this: >> >> if [ "$1" != "FOO" ]; >> then >> echo "I can backup the 2nd volume"; >> else >> exit; >> fi >> >> It works. But if I add an "or" condition as follows: >> >> if [ "$1" != "FOO" ] || [ "$1" != "BAR" ] ; > I've never seen this syntax. I always thought that the "or" > needed to be within the test, as in: > if [[ "$1" != "FOO" ||$1 != "BAR" ]] There's a difference between [[ ]] and [ ] ([[ ]] is superior and you should probably just get used to using [[ ]] exclusively). But the syntax used in the sample above is incorrect, i believe, as single brackets require that you use -o for or. you really only need to deal with single [ ] if you want to be compatible with sh. -- "Are you pondering what I'm pondering?" "I think so, but where is a fish?"