shell_script showing errors in the below mentioned script while executing in linux

code:

IMAGE=$imgvalue;
 if [ $imgvalue :=1 ] 
then 
echo DO=ABC; 
elif [ $imgvalue :=2 ] 
then echo DO=ETC; 
elif [ $imgvalue :=3 ] 
then echo DO=XYZ; 
else 
echo "$imgvalue is unsupported"; 
exit 1; 
fi

in above script IMAGE=1 , IMAGE=2, IMAGE=3 whatever may be the value i have assigned it's showing only DO=ABC other conditions not working . any one pls check.

try this.

 
 
IMAGE=$imgvalue;
if [ "$imgvalue" -eq "1" ] 
then 
 echo DO=ABC; 
elif [ "$imgvalue" -eq "2" ] 
then 
 echo DO=ETC; 
elif [ "$imgvalue" -eq "3" ] 
then 
 echo DO=XYZ; 
else 
 echo "$imgvalue is unsupported"; 
 exit 1; 
fi

use [code] tag

Try:

case $imgvalue in
  1) echo DO=ABC;;
  2) echo DO=ETC;; 
  3) echo DO=XYZ;;
  *) echo "$imgvalue is unsupported" 
     exit 1
esac

i have tried all possibilities and solutions mentioned above . it's not working .

can any one help the make script coding with the above requirement.only in below senario it's working and displaying DO=ABC for all inputs like IMAGE=1 or IMAGE=2 or IMAGE=3

IMAGE=$imgvalue;
if  [ $imgvalue =:1 ]
then
echo DO=ABC;
elif [ $imgvalue =:2 ]
then
echo DO=ETC;
elif [ $imgvalue =:3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1; 
fi

Hi,

I have tried the *two* solutions posted above and they both work. So can you be more specific about how it is not working.

If you are getting errors then post them.

what is the problem?

imgvalue=$1
 if [ $imgvalue = 1 ]
then
echo DO=ABC
elif [ $imgvalue = 2 ]
then echo DO=ETC
elif [ $imgvalue = 3 ]
then echo DO=XYZ
else
echo "$imgvalue is unsupported"
exit 1
fi
# ./script 1
DO=ABC
# ./script 2
DO=ETC
# ./script 3
DO=XYZ
# ./script 4
4 is unsupported

Hi,

cmd i am executing in linux:
and make is the file which having these changes.

$./make rel sapqe1 IMAGE=2
DO=ABC
$./make rel sapqe1 IMAGE=1
DO=ABC
$./make rel sapqe1 IMAGE=3
DO=ABC
$./make rel sapqe1 IMAGE=5
is unsupported

the problem is for every input of image only output i am getting DO=ABC

IMAGE=$imgvalue;
if  [ $imgvalue =:1 ]
then
echo DO=ABC;
elif [ $imgvalue =:2 ]
then
echo DO=ETC;
elif [ $imgvalue =:3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1; 
fi

i am getting below error if i use if [ "$imgvalue" -eq "1" ] or if [ "$imgvalue" -eq "1" ]

error :
[: =: unary operator expected

firstly we must get the IMAGE value and its represented to $3
so $3="IMAGE=2"
and we must cut the value from IMAGE express with `imgvalue=${3/*=/}`
then imgvalue equals to 2..then go to if-elif..
try this...

imgvalue=${3/*=/}
if  [ $imgvalue = 1 ]
then
echo DO=ABC;
elif [ $imgvalue = 2 ]
then
echo DO=ETC;
elif [ $imgvalue = 3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1;
fi