ssh远程执行找不到命令(交互式和非交互式shell)—— 筑梦之路

背景说明

ssh远程某台主机去执行命令时提示找不到命令,而手动登陆主机可以正常执行命令。

问题原因

  • An interactive shell reads user input typed on a keyboard. Commands run in the current shell and the system waits for further instructions from the user. A Bash shell is an interactive shell.

  • A non-interactive shell executes commands read from a file in a new subshell. The shell executes commands from the file and exits. Init, startup, and executed shell scripts start non-interactive shells.

使用xshell这样的工具登陆服务器后就是交互式shell,如果在当前shell中再启动一个shell,这个子shell就是非交互式shell

如何区别交互式和非交互式shell

$ ssh test@127.0.0.1 'echo $0'
bash

$ echo $0
-bash

-bash的输出就是交互式shell,反之就是非交互式shell
  • .bashrc defines the settings for a user when running a subshell. Add custom configurations to this file to make parameters available in subshells for a specific user.

  • .bash_profile defines the settings for a user when running a login shell. Add custom configurations to this file to make parameters available to a specific user when running a login shell.

 交互式shell会执行 .bash_profile(其中包含了.bashrc),而非交互式shell只会执行.bashrc

简单地来说,交互式shell和非交互式shell使用的环境变量文件不同,因此远程执行命令的时候会出现找不到命令的情况。

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值