linux – 命令在脚本中不起作用,但在shell中起作用

我正在编写一个使用SSH“配置文件”的脚本,〜/ scripts / ssh-profiled.sh

PROFILE=`cat ~/script/ssh-profiles/$1`
echo [ssh $PROFILE]
ssh $PROFILE

〜/脚本/ SSH型材/ tummi

-i ~/DropBox/security/key-nopass/key-nopass.pvt [email protected]

当我运行脚本时,它失败了:

bart@bart-laptop:~$script/ssh-profiled.sh tummi
[ssh -i ~/DropBox/security/key-nopass/key-nopass.pvt [email protected]]
Warning: Identity file ~/DropBox/security/key-nopass/key-nopass.pvt not accessible: No such file or directory.
[email protected]'s password:

但这有效:

bart@bart-laptop:~$ssh -i ~/DropBox/security/key-nopass/key-nopass.pvt [email protected]
Linux tummi 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to the Ubuntu Server!

我的脚本中是否有错误/陷阱?

解决方法:

将第1行更改为

eval PROFILE=`cat ~/script/ssh-profiles/$1`

有关解释,请参阅here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐