Linux 在文件名中调用Shell变量时为空,但在其他地方调用或回送时则为空

Linux 在文件名中调用Shell变量时为空,但在其他地方调用或回送时则为空,linux,bash,shell,variables,Linux,Bash,Shell,Variables,我有4个shell变量集 remote_account="raccname" remote_machine="server" First_Name="firstname" Last_Name="lastname" 当我在脚本中调用remote_帐户或remote_机器时,它们可以很好地使用 echo "What directory shall you choose?" read dir scp -r ~/csc60/$dir $remote_account@$remote_machin

我有4个shell变量集

remote_account="raccname"
remote_machine="server"
First_Name="firstname"
Last_Name="lastname"
当我在脚本中调用remote_帐户或remote_机器时,它们可以很好地使用

echo "What directory shall you choose?"
  read dir
  scp -r ~/csc60/$dir $remote_account@$remote_machine:directoryA
  exit;;
但是当我把另外两个也叫做

echo "What directory shall you choose?"
  read dir
  scp $remote_account@$remote_machine:tars/$Last_Name_$First_Name_$dir.tar.z ~/tars
  exit;;
它从tars/$dir.tar.z获取tars文件,完全跳过$Last\u Name\uu$First\u Name_ 当我在其中抛出echo$Last_Name时,它仍然显示为lastname

是否有一些规则在变量之间使用uu或其他什么,或者我只是缺少一些明显的东西?

\uu是变量名的有效字符,因此您必须限定哪个部分是变量

scp "$remote_account@$remote_machine:tars/${Last_Name}_${First_Name}_$dir.tar.z" ~/tars
_是变量名的有效字符,因此必须限定变量的组成部分

scp "$remote_account@$remote_machine:tars/${Last_Name}_${First_Name}_$dir.tar.z" ~/tars

您需要使用${}对变量值进行定界,因为您声明$Last\u Name\uu$First\u Name\uu$dir被视为一个变量,并为其指定shell put值。在您的案例中,您没有为它定义值。它将被解释为


使用${LAST\u NAME}{FIRST\u NAME}

您需要使用${}对变量值进行定界,因为您声明$LAST\u NAME\uu$FIRST\u NAME\uu$dir被视为一个变量,并为它提供shell put值。在您的案例中,您没有为它定义值。它将被解释为


使用${LAST\u NAME}{FIRST\u NAME}

提示,检查问题提示,检查问题啊,非常感谢朋友,我知道这很简单,非常感谢朋友,我知道这很简单,感谢深入的回答,非常感谢深入的回答,非常感谢