我设置了 4 个 shell 变量
remote_account="raccname"
remote_machine="server"
First_Name="firstname"
Last_Name="lastname"
当我在我的脚本中调用 remote_account
或 remote_machine
时,它们可以正常使用
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_Name_$First_Name_
当我在其中输入 echo $Last_Name
时,它仍然显示为“lastname”
是否有一些规则在变量之间使用“_”或其他东西,或者我只是遗漏了一些明显的东西?
最佳答案
_
是变量名的有效字符,因此您必须限定哪一部分是变量。
scp "$remote_account@$remote_machine:tars/${Last_Name}_${First_Name}_$dir.tar.z" ~/tars
关于linux - 在文件名中调用时 Shell 变量为空,但在回显或在其他地方调用时则不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19075286/