Re: logical OR in bash
- From: Dan Espen <daneNO@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 06 Feb 2008 15:50:33 GMT
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]
.
- Follow-Ups:
- Re: logical OR in bash
- From: Yanb
- Re: logical OR in bash
- References:
- logical OR in bash
- From: Yanb
- logical OR in bash
- Prev by Date: A friendly site Linux Learners(Lovers)
- Next by Date: Re: How often does NAGIOS wake up?
- Previous by thread: Re: logical OR in bash
- Next by thread: Re: logical OR in bash
- Index(es):
Relevant Pages
|