DevSupport
asked on
using asteriks in if statement in bash scripting
Hi Experts,
if [[ "$DBS" -eq 1 && "$DBS" -ne VFEEDBACK* ]]
then
DS=`echo "$i"`
How do I write the if statement in the correct way
if [[ "$DBS" -eq 1 && "$DBS" -ne VFEEDBACK* ]]
then
DS=`echo "$i"`
How do I write the if statement in the correct way
ASKER
@Pawan Kumar: Thank You, but I tried it and got an error, line 51: [[: VFEEDBACK*: syntax error: operand expected (error token is "*")
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice work, DevSupport.
Do you understand the reason your answer works? If not, read on...
If you run the command:
man test
you'll see that operators like "==" and "!=" are for comparing strings, and "-eq", "-ne", etc, are for comparing integers.
Also note that if, for example, "VFEEDBACK*" had a space (or various other characters) in it, like "VFEED BACK*" or "VFEEDBACK *", you'd need to surround it with quotes.
Do you understand the reason your answer works? If not, read on...
If you run the command:
man test
you'll see that operators like "==" and "!=" are for comparing strings, and "-eq", "-ne", etc, are for comparing integers.
Also note that if, for example, "VFEEDBACK*" had a space (or various other characters) in it, like "VFEED BACK*" or "VFEEDBACK *", you'd need to surround it with quotes.
ASKER
because my response works
if [[ "$DBS" -eq '1' && "$DBS" -ne 'VFEEDBACK*' ]]