我正在使用 github 代码空间来测试 Discord.js 机器人。在其中我使用命令 fortune | owsay 使用了 fortune 和 cowsay 命令,fortune 命令使用 sudo apt install Fortune-mod 安装,cowsay 使用 <代码>sudo apt安装cowsay代码>。他们的安装目录位于“/usr/games”而不是“/bin”下,因此当我运行命令 fortune |牛说我明白了
bash: fortune: command not found bash: cowsay: command not found
这是因为在 Github 代码空间中 /usr/games 不在 $PATH 中
当我将“/usr/games”添加到“/etc/profile”和“~/.profile”中的路径时,使用
export PATH="/usr/games:$PATH"放在两个文件的底部,然后使用命令“source /etc/profile”并在稍后测试“source ~/.profile”这些命令有效...但当我尝试使用 VScode 的内置运行程序(按 f5 并单击 node.js)运行该文件时,它会自动创建一个新 shell 并使用 node 来运行它命令未找到的文件。
我想知道 GitHub codespaces 如何在没有我添加的新路径的情况下创建新的 shell。以及如何将 /usr/games 目录添加到 vscode 运行文件时打开的新 shell 的路径
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
虽然您在 Github Codespace 中使用的 shell 是交互式的,但它们不是登录 shell。只有登录 shell 才运行
/etc/profile和~/.profile文件。您可以通过运行以下命令来测试 shell 是否为登录 shell:
您可以:
.bashrc文件等中设置PATH;交互式非登录文件将运行此文件。尽管我认为在.profile以外的文件中设置PATH并不是最佳实践。bash -l以启动一个新 shell 作为登录 shell。.vscode-remotesettings.json文件中创建新的终端配置文件 - 转到Settings和Remote [ Codespaces],单击Edit in settings.json按钮应该可以到达这里,然后将新的配置文件添加到terminal.integrated.profiles.linux..."terminal.integrated.profiles.linux": { "bash (login)": { "path": "bash", "args": ["-l"], "icon": "terminal-bash" }, ... }然后在 VS Code 中使用
bash(登录)配置文件打开一个新终端。