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.

4
  • What is the actual output of the script, and what would you expect for output? Commented Jan 16, 2016 at 14:04
  • Dear sir, thanks for reply. just i am trying to assign VA1L1 varibale value to purpose variable in if. when i echo $porpose it should display test. but now its not diplaying test. Commented Jan 16, 2016 at 14:06
  • 1
    Please take a look: shellcheck.net Commented Jan 16, 2016 at 14:15
  • Look at your VAL1 variable. You incorrectly set purpose. Commented Jan 16, 2016 at 17:15

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Additionally, you should properly quote the value when you use it; echo "$VAL1". See also stackoverflow.com/questions/10067266/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.