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

Bar*_*lom 4 linux ssh bash scripting ubuntu

我正在编写一个使用SSH"profiles"的脚本,〜/ scripts/ssh-profiled.sh

PROFILE=`cat ~/script/ssh-profiles/$1`
echo [ssh $PROFILE]
ssh $PROFILE
Run Code Online (Sandbox Code Playgroud)

〜/脚本/ SSH型材/ tummi

-i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com
Run Code Online (Sandbox Code Playgroud)

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

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:
Run Code Online (Sandbox Code Playgroud)

但这有效:

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!
Run Code Online (Sandbox Code Playgroud)

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

Vic*_*kin 5

将第1行更改为

eval PROFILE=`cat ~/script/ssh-profiles/$1`
Run Code Online (Sandbox Code Playgroud)

有关解释请参见此处