linux - 命令在脚本中不起作用,但在 shell 中有效

标签 linux bash scripting ubuntu ssh

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

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

~/scripts/ssh-profiles/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`

有关解释,请参阅 here

关于linux - 命令在脚本中不起作用,但在 shell 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4557707/

相关文章:

linux - 如何学习 linux 中的构建工具?

linux - 如何从 Linux 命令行获取 exe 的编译日期

linux - 如何使用 sed 复制十六进制格式的行?

groovy - ElasticSearch:在禁用 Groovy 的 _score 字段上进行聚合

python - 如何在python中的文本文件中搜索行首先有空格

linux - EC2 : "Connection refused" to all instances after changing ownership of/var

linux - 安装带有 undefined symbol 的 R 包

bash - xargs 输出缓冲 -P parallel

linux - 执行 chmod 后 Bash 脚本执行突然停止

linux - 如何在我的应用程序的目录树中使源位置独立?