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

我正在编写使用SSH“configuration文件” 〜/ 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 bart@example.com 

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

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

但是这个工作:

 bart@bart-laptop:~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com 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! 

脚本中是否有错误/遗漏?

将第一行更改为

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

为了解释在这里看到

文件中的〜需要是完整的主目录路径,它不会被扩展。

我的猜测是“〜/”没有按照预期的方式被解释。 尝试使用明确的完整路径。

什么是.pvt文件的权限? 如果只有读取权限,没有人可以执行,那么脚本可能无法看到文件。 这可能是你为什么得到"...not accessible: No such file or directory." 信息。