Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF string matching 3

Status
Not open for further replies.

grepper

Technical User
Jun 4, 2003
49
US
I'm blanking on this one. I know there is a better way to do this.

if [ $opt3 -eq "FAILED" -o $opt3 -eq "failed" ]

Something like

if [ $opt3 -eq "FAILED||failed" ]

or

if [ $opt3 -eq "FAILED" -o "failed" ]

but I can't get it to work.
 
case $opt3 in FAILED|failed)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Whilst PHV is right, case is usually best for multiple choices, to help understand the test syntax
'-eq' is numeric equality, '=' is string equality
The double pipe should be used for the 'or' condition
so your code should be
Code:
if [ "$opt3" = 'failed' || "$opt3" = 'FAILED' ]
Another answer to the case sensitive match problem is
Code:
set -u testvar # testvar is force into upper case
testvar=$opt3
if [ "$testvar" = 'FAILED' ]
The double quotes around $opt3 and $testvar is to stop the test failing with a missing value error if $opt3 is the null string

Ceci n'est pas une signature
Columb Healy
 
when comparing strings, I've found this usually works:

if [[ $opt3 -eq "FAILED" -o "failed" ]]
 
Thanks! All great suggestions. I took the idea of "set -u var" and added a "-u" to typeset command already used to set the varibles when the code was orginally written. It works like a champ.
 
wow - look at all those stars. we could start a new galaxy. :)

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top