Avatar of DevSupport
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
Shell Scripting

Avatar of undefined
Last Comment
DevSupport

8/22/2022 - Mon
Pawan Kumar

Pls try-

if [[ "$DBS" -eq '1' && "$DBS" -ne 'VFEEDBACK*' ]]
DevSupport

ASKER
@Pawan Kumar: Thank You, but I tried it and got an error, line 51: [[: VFEEDBACK*: syntax error: operand expected (error token is "*")
SOLUTION
Pawan Kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
DevSupport

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
tel2

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
DevSupport

ASKER
because my response works