Makefile errors while executing in Linux

2019-09-22 13:31发布

I have one requirement in my automation.

I need to pass values like 1, 2, 3 to MY_IMAGE in command line in Linux.

I had defines activities for all these inputs in other make file.

The code similar to below i wrote for my requirement. Issue was whenever I passes values like MY_IMAGE=1, MY_IMAGE=2, MY_IMAGE=3

it's printing only echo ACT_DO=XYZ;

It's not displaying the other info whenever I selected 2 or 3. Can anyone check and correct my code.

export MY_IMAGE
MY_IMAGE=$img_value;
if [ $img_value :="1" ]
then
echo ACT_DO=XYZ;
else 
if [ $img_value :="2 ] 
then
echo ACT_DO=ABC;
else 
if [ $img_value :=3 ] 
then
echo ACT_DO=ETC;
else
echo ""$img_value" is unsupported";
exit 1; 
fi
fi
fi

标签: linux shell
1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-22 14:14

Your code has a quote in the wrong place, and uses := which doesn't mean anything, as far as I know. It's also implemented confusingly.

Try this:

export MY_IMAGE
MY_IMAGE=$img_value

case "$img_value" in
1 ) echo ACT_DO=XYZ ;;
2 ) echo ACT_DO=ABC ;;
3 ) echo ACT_DO=ETC ;;
* )
  echo "\"$img_value\" is unsupported"
  exit 1
  ;;
esac

The first two lines are not required for this code, but I presume you wanted that for something else.

查看更多
登录 后发表回答