Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI walkthrough Adding ~/bin to $PATH in Bash #2154

Open
ghost opened this issue Feb 1, 2022 · 4 comments
Open

CLI walkthrough Adding ~/bin to $PATH in Bash #2154

ghost opened this issue Feb 1, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 1, 2022

Hi,
The instruction page (https://exercism.org/cli-walkthrough) shows:

echo 'export PATH=~/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile

But the next time you start a shell (not the login-shell) the PATH variable will not reflect the change as .bash_profile will only be invoked during the start of the **login-**shell. I solved this issue to put the required PATH-statement into .bashrc

Taken from the man:
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.

PS: I am running Arch linux.

@kotp
Copy link
Member

kotp commented Feb 7, 2022

@RikRoos So this issue can be closed? (You wrote that you solved this issue, so wondering if there is still an issue.)

@angelikatyborska
Copy link
Contributor

@kotp If putting the path export in .bashrc is the correct thing to do on Linux, then I would say this issue requires updating the instructions before closing: https://github.com/exercism/interactive-cli-walkthrough/blob/e3c243ef6f306f9bc376b109a480bdce82d39128/contents/linux/path.tw2#L19-L21

I've been a mac user forever, and I am sure that on older macOS .bash_profile is the correct file (however on newer macs with zsh being the default shell, .zshrc would be the correct file). But if I recall correctly, that was always somehow confusing because on Linux it's different?

@kotp
Copy link
Member

kotp commented Feb 11, 2022

Yeah, the whole BSD/SystemV/Linux differences are confusing. The profile is used if it is a login shell that is going on, the bashrc is a resource file for the shell in more general sense. So it depends on the intention, what and when you want those settings.

I believe the instructions are correct for what we generally want to do. The OP had their own desires, and so not sure if they are using it in a typical fashion. They said that they solved the issue as it pertains to their personal needs. I am not positive anything needs to be changed. (And no, the export in .bashrc would not be the general way to work, since the user is probably using a login shell.) Of course the instructions are biased to bash rather than fish, zsh, sh, korn, c, or some other shell.

Would not the ~/.zprofile be analogous with zshell instead?

@IsaacG
Copy link
Member

IsaacG commented Feb 12, 2022

https://mywiki.wooledge.org/DotFiles

Neither is more correct. The .profile is the correct place to set up the environment. That way you set it once and it's done. There's no need to update the $PATH every time you open a new terminal.

On the other hand, the .profile only takes effect on login and setting the $PATH on every shell spawn is relatively cheap. While less "efficient" and less "clean", it's pretty cheap and slightly more convenient.

Any argument that one is correct and the other is wrong is pretty hand wavy and I could argue for or against either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants