0

I am using a github codespace to test a discord.js bot. In it i use the command fortune | cowsay which uses the fortune and cowsay commands, the fortune command is installed with sudo apt install fortune-mod and cowsay with sudo apt install cowsay. Their install directory is under "/usr/games" and not "/bin" therefore when I run the command fortune | cowsay I get

bash: fortune: command not found
bash: cowsay: command not found

This is because in Github codespaces /usr/games is not in the $PATH

When I added "/usr/games" to the path in both "/etc/profile" and "~/.profile" using export PATH="/usr/games:$PATH"put at the bottom of both the files and then used the command "source /etc/profile" and in later testing "source ~/.profile" The commands work... but it is when I try to run the file using VScode's built in runner (hitting f5 and clicking on node.js) where it automatically makes a new shell and uses node to run the file it commands not found.

I am wondering how GitHub codespaces makes their new shells without the new path I added. And how I might be able to add the /usr/games directory to the path for the new shell that opens when vscode runs the file

theyobros
  • 1
  • 1

1 Answers1

0

While the shells that you use within a Github Codespace are interactive, they are not login shells. Only login shells run the /etc/profile and ~/.profile files.

You can test whether a shell is a login shell or not by running the following command:

shopt -q login_shell && echo 'login shell' || echo 'not login shell'

You can either:

  1. Set the PATH in a .bashrc file or the like; interactive non-login files will run this file. Although I believe it is not best practice to set PATH in a file other than .profile.
  2. Once connected to your Codespace via a terminal, run bash -l to start a new shell as a login shell.
  3. Create a new terminal profile in the remote .vscode-remote settings.json file - going to Settings and Remote [Codespaces], click the Edit in settings.json button should get you here, then add a new profile to terminal.integrated.profiles.linux...
"terminal.integrated.profiles.linux": {

        "bash (login)": {
            "path": "bash",
            "args": ["-l"],
            "icon": "terminal-bash"
        },
        ...
    }

Then in VS Code open a new terminal with the bash (login) profile.

James Webster
  • 4,046
  • 29
  • 41