linux shell脚本 linux不识别,在Linux中命令在脚本中不起作用,但在shell中起作用

博主在尝试编写一个使用SSH配置文件的脚本时遇到问题。脚本旨在通过读取指定的配置文件来执行SSH连接,但运行时提示身份文件无法访问。尽管直接使用相同的命令在终端中可以成功连接,脚本执行时却失败。博主考虑将脚本的第一行改为`eval`来解决可能的环境问题。
摘要由CSDN通过智能技术生成

我正在编写一个使用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]

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

[email protected]:~$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:

但这有效:

[email protected]:~$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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值