Link to home
Start Free TrialLog in
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
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Pls try-

if [[ "$DBS" -eq '1' && "$DBS" -ne 'VFEEDBACK*' ]]
Avatar of DevSupport
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
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
because my response works