我设置了一个包含空格的env-var。我可以正确输出。
export dpath="/path/with/spaces/is here/clear"
echo $dpath
/path/with/spaces/is here/clear
现在在这里使用env-var:
sshpass -p 'xxxx' sftp -q -a -P22 -r "account@12.34.56.78:${dpath}" .
File "/path/with/spaces/is" not found.
现在,空间被忽略(并被拆分(。我该怎么解决这个问题?
为了使其不分裂,我们需要引号。尝试将env-var存储为:export dpath='"/path/with/spaces/is here/clear"'
使用"内部"。
或者,如果不能以这种方式存储导出var,请尝试在scp命令中的变量周围使用双引号:sshpass -p 'xxxx' sftp -q -a -P22 -r account@12.34.56.78:"${dpath}" .
希望这能帮助