我正在尝试运行我在远程服务器上的主目录中安装的命令。它已经被添加到.bash_profile中的$ PATH中。我可以通过正常的ssh会话远程登录时使用它,但Fabric似乎没有拉我的$ PATH。因此,我尝试使用Fabric的path context manager将其添加到我的$ PATH中,如下所示:
def test_path():
print('My env.path setting: %(path)s' % env)
with path('/path/to/sources/drush'):
run('echo $PATH')
run('drush')
Fabric回复:
Executing task 'test_path'
My env.path setting:
run: echo $PATH
out: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
out:
run: echo $PATH
out: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/sources/drush
out:
run: drush
out: /bin/bash: drush: command not found
out:
Fatal error: run() received nonzero return code 127 while executing!
Requested: drush
Executed: /bin/bash -l -c "export PATH=\"\$PATH:\"/path/to/sources/drush\" \" && drush"
Aborting.
感谢您的期待...
答案 0 :(得分:2)
问题在于PATH变量的设置方式 - 在它的末尾有一个额外的空格字符:
/bin/bash -l -c "export PATH=\"\$PATH:\"/path/to/sources/drush\" \" && drush"
^HERE
搜索路径中的最后一个目录由bash
解释为“/ path / to / source / drush”(尾随空格) - 一个无效的目录。