我对 shell 脚本编写比较陌生,所以如果这看起来是一个简单的问题,我深表歉意。我有一个 Linux VM ( debian, version 11 (bullseye)),我可以通过 ssh 进入 ( ssh <ip>),安装了一些依赖项(homebrew、pyenv 等),并且能够成功使用它们。ssh <user>@<ip> pyenv versions但是,当我尝试在脚本中或使用 Mac 终端从 VM ( ) 外部运行命令时,会收到bash: line 1: pyenv: command not found相关错误。
我认为这可能与此处解释的内容有关,但我不完全确定如何规避该问题。
在下面的评论中添加@terdon 询问的其他详细信息:
$ which pyenv
/home/linuxbrew/.linuxbrew/bin/pyenv
$ grep /home/linuxbrew/.linuxbrew/bin/ ~/.bashrc ~/.bash_profile ~/.profile /etc/bash.bashrc /etc/profile
grep: /home/f0p021s/.bash_profile: No such file or directory
/home/f0p021s/.profile:eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Run Code Online (Sandbox Code Playgroud)
我还意识到,如果我从虚拟机中查看路径,它看起来像这样:
$ echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Run Code Online (Sandbox Code Playgroud)
当我尝试从本地计算机运行类似的命令时,它看起来有所不同:
$ ssh <user>@<ip> 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/games
Run Code Online (Sandbox Code Playgroud)