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使用的环境变量文件不同,因此远程执行命令的时候会出现找不到命令的情况。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!