-3

I'm trying to execute below bash shell script, but not getting the expected output. Possible i'm doing something wrong or it's not the way of doing this.

 #bin/bash
#set -x

path1_one=/home/dell/scripts
echo $path1_one
param_val=path1_one
param1=$( echo "$param_val" | awk -F '_' '{ print $0 }' )

#path2="$path1"
echo $param1

#echo $path2

Output:

/home/dell/scripts

path1_one

Expected Output:

/home/dell/scripts

/home/dell/scripts

Both variable value should be same,but don't know why param1 value is not reflecting with path1_one

9
  • 1
    Use path2="$path1" Commented Mar 24, 2017 at 10:51
  • It isn't obvious why you think your "expected" output is more correct than your actual output. param_val=path1_one assigns the string path1_one to param_val; why would anything "reflect"? Commented Mar 24, 2017 at 16:02
  • ...if you want indirect assignment or indirect expansion, we already have questions unambiguously asking how to do those things and with clear and readable answers. Commented Mar 24, 2017 at 16:04
  • @CharlesDuffy, param1=path1_one, so it should print the path1_one value which is /home/dell/scripts Commented Mar 24, 2017 at 16:11
  • use param_val="$path1_one" instead of param_val=path1_one. as everybody told you. they just used different variables to demonstrate that and expected you to adapt it to your script. Commented Mar 24, 2017 at 16:20

1 Answer 1

3

You need to tell the script that you want to use the value of the variable path1, not the name path1.

Use:

path2="$path1" 
Sign up to request clarification or add additional context in comments.

4 Comments

NullDev,Thanks for your quick response, please see my updated complete script. please suggest me, how to get the value from path1.
still the same... param_val="$path1" but where is path1_one defined?
i'm expecting param1 to be path1_one value
Why do you expect that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.