1

I need a small correction for my below code. I am trying to assign variable value to another variable, but it's not working. please help me.

Below is my script.

#!/bin/sh
choice=1
VAL1="test"
if [ "$choice" == 1 ];
then
   echo "insode"
   echo $choice
   purpose=$VAl1
   echo "*"
   echo $purpose
fi

Please help me, I'm new to shell scripting. I need to display purpose value as test.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Chandan Hp
  • 45
  • 1
  • 7

1 Answers1

1

You assign a value to VAL1:

VAL1="test"

But later you assign $VAl1 to purpose:

purpose=$VAl1

You just have to fix the case so the variable names match (fix lowercase l to uppercase L).

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • Additionally, you should properly quote the value when you use it; `echo "$VAL1"`. See also http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable – tripleee Jan 18 '16 at 10:45