hi,
I need to create an IF condition. I read a line from a file and get the 5 word using space as a delimited. This word can have only two values either '*' or '1-5'
I need to write an IF condition for two cases. I can either compare it to * or 1-5(or even 1 by cutting and getting only the first character).
But when I write it
eg, if [$var -eq '*' ]
If the value is 1-5 it says integer argument expected. If I write
if [ $var == 1 ]
In this case when the value is '' it says string expected. How can I resolve this. Cannt I declare that the $var is always goiing to be a char. So I can use -eq '' and -eq '1-5'.
> var1="*"
> if [ "$var1" = "*" ] ; then echo "match"; fi
match
> if [ "$var1" = "1" ] ; then echo "match"; fi
>
> var1="1"
> if [ "$var1" = "*" ] ; then echo "match"; fi
> if [ "$var1" = "1" ] ; then echo "match"; fi
match
> var1=1
> if [ "$var1" = "1" ] ; then echo "match"; fi
match