Re: logical OR in bash



Yanb <Yanb@xxxxxxxxxxxxxxxx> writes:

Hi, a simple question, I'm new to bash (and linux completely:-)

How do I compare more things in bash?

this works fine:
---
echo "Are you sure? Type YES and press ENTER."
read LINE
if [ "$LINE" != "yes" ]; then
exit 1
fi
echo "great"
---

but what if I want to compare to "YES". I tried whatever I know from php or C, but anything like
if [ (("$LINE" != "yes") && ("$LINE" != "YES")) ]; then

does not work. I know I sloudh convert it to upper case for best result, whatever, but I need to know
how to make more conditions in single if :-)

So how to make it right? ;-) Thank you in advance.

Shell comparisons are done best with the case statement since it supports
regular expressions.

Example:

case $LINE in
YES | yes)
echo "matched"
;;
* )
echo "no match"
;;
esac

Another possibility:

[yY][eE][sS]


.



Relevant Pages

  • Tell Betty its romantic emphasizing in a meaning.
    ... If the comfortable requests can compare probably, ... techniques. ... runs to greek David, who's allowing worth the dose's benefit. ... easy myth won't review before I echo it. ...
    (sci.crypt)
  • Re: exiting a script
    ... >>echo I don\'t want to echo! ... >>I suppose in bash and sh, the exit 3 just gets out of the subshell ... >>I, using sh, do what I want, which is exit the entire script just as zsh ...
    (comp.unix.shell)
  • logical OR in bash
    ... Hi, a simple question, I'm new to bash (and linux completely:-) ... How do I compare more things in bash? ... echo "Are you sure? ...
    (comp.os.linux.misc)
  • Re: diff(ing) 2 directories ?
    ... compare directory trees recursively and report the differences. ... echo "softlink" ... # compare a file, directory, or softlink ... cat << EOU Usage: $0 dir1 dir2 Compare directory trees: files are binary compared directories are checked for identical content soft links are checked for identical targets ...
    (comp.lang.tcl)
  • Comparing file trees to check for compromised system.
    ... I ended up using Bit Twister's ideas to write a script to compare two ... for dir1 in $dirlist; do ... # echo "directory:" $dir1 ...
    (comp.os.linux.security)