加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 00:33:37 所属栏目:Linux 来源:网络整理
导读:我正在编写一个使用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 bart@example.com 当我运行脚本
我正在编写一个使用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 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!

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

解决方法

将第1行更改为

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

有关解释,请参阅here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读