1

I have 4 shell variables set

remote_account="raccname"
remote_machine="server"
First_Name="firstname"
Last_Name="lastname"

when I call remote_account or remote_machine in my script they get used fine

echo "What directory shall you choose?"
  read dir
  scp -r ~/csc60/$dir $remote_account@$remote_machine:directoryA
  exit;;

but when I call the other two as such

echo "What directory shall you choose?"
  read dir
  scp $remote_account@$remote_machine:tars/$Last_Name_$First_Name_$dir.tar.z ~/tars
  exit;;

it grabs the tars file from tars/$dir.tar.z completely skipping $Last_Name_$First_Name_ when I throw an echo $Last_Name in it still shows it as "lastname"

Is there some rule using "_" between variables or something, or am I just missing something obvious?

Crippledsmurf
  • 3,982
  • 1
  • 31
  • 50
Justin D
  • 13
  • 2
  • Hint, check out question http://stackoverflow.com/questions/951336/how-to-debug-a-bash-script – hyde Sep 29 '13 at 06:56

2 Answers2

5

_ is a valid character for variable names, therefore you have to qualify which part is the variable.

scp "$remote_account@$remote_machine:tars/${Last_Name}_${First_Name}_$dir.tar.z" ~/tars
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

You need to delimit your variable value using ${}, as you declared $Last_Name_$First_Name_$dir is treated as one variable and shell put value for it. As in your case you did not defined value for it . It will be intepreted as "".

use ${LAST_NAME}_${FIRST_NAME}

Alpesh Gediya
  • 3,706
  • 1
  • 25
  • 38