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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doing a condition with begins and an AND

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
I currently have the following:
Code:
if [ "$srcdb" = "$desdb" ]
then
  echo "Start normal"
else
  echo "Start control"
fi

Which works.

However, it should only do the "start normal" of $srcdb=$desdb AND both srcdb and desdb begin with IFS.

Could someone please demonstrate how this may be achieved?

thanks






Applications Support
UK
 
AND both srcdb and desdb begin with IFS
???
Can you please elaborate the context of this test ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok, if the value of both variables beging with the literal "IFS" and the two values are different, then do it.. else don't.




Applications Support
UK
 
if [ "`expr substr $srcdb 1 3`" = "IFS" -a "`expr substr $desdb 1 3`" = "IFS" -a "$srcdb" != "$desdb" ]
then
echo "do it"
else
echo "don't"
fi

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Many thanks, it works!


Can I confirm...

The -a means AND like || means OR?

Why one has to have "$srcdb" != "$desdb" but when looking for the IFS, we use $srcdb (not "$srcdb"). is it because it is already in "" from the "`...`" section?

Thanks


Applications Support
UK
 
The -a means AND like || means OR
-a is inside the brackets ([ ... ]): man test
|| is a shell operator : man yourshell
Why one has to have "$srcdb" != "$desdb" ...
OK, if srcdb or desdb may contains space:
if [ "`expr substr \"$srcdb\" 1 3`" = "IFS" -a "`expr substr \"$desdb\" 1 3`" = "IFS" -a "$srcdb" != "$desdb" ]


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top