exercism/website-copy

CLI walkthrough Adding ~/bin to $PATH in Bash

Opened this issue · 4 comments

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 commented

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

@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 commented

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?

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.