gpt4 book ai didi

linux - 在文件名中调用时 Shell 变量为空,但在回显或在其他地方调用时则不是

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:29:25 25 4
gpt4 key购买 nike

我设置了 4 个 shell 变量

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

当我在我的脚本中调用 remote_accountremote_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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com