Command not found when running with execSync in github Codespace
P粉306523969
P粉306523969 2024-03-20 11:52:18
0
1
427

I'm using the github codespace to test the Discord.js bot. In it, I used the command fortune | owsay and used the fortune and cowsay commands. The fortune command was installed using sudo apt install Fortune-mod. cowsay Use <代码>sudo apt to install cowsay. Their installation directory is under "/usr/games" instead of "/bin", so when I run the command fortune |Niu saidI understand

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

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

When I add "/usr/games" to the path in "/etc/profile" and "~/.profile", use export PATH="/usr/games:$PATH"Place at the bottom of both files, then use the command "source /etc/profile" and later test "source ~/.profile" these commands Works... but when I try to run the file using VScode's built-in runner (press f5 and click node.js), it automatically creates a new shell and uses node to run the file that is not found by its command.

I'm wondering how GitHub codespaces can create a new shell without the new path I added. And how to add the /usr/games directory to the path of the new shell that opens when vscode runs the file

P粉306523969
P粉306523969

reply all(1)
P粉579008412

Although the shells you use in Github Codespace are interactive, they are not login shells. Only the login shell runs the /etc/profile and ~/.profile files.

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

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

you can:

  1. Set PATH in .bashrc files etc.; interactive non-login files will run this file. Although I don't think it's best practice to set PATH in a file other than .profile.
  2. After connecting to Codespace through the terminal, run bash -l to start a new shell as the login shell.
  3. Create a new terminal profile in the remote .vscode-remote settings.json file - go to Settings and Remote [Codespaces] , clicking the Edit in settings.json button should get you here, then add the new profile to terminal.integrated.profiles.linux...
"terminal.integrated.profiles.linux": {

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

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template