-
Notifications
You must be signed in to change notification settings - Fork 88
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
bash: Build new PATH the smart way #3096
base: main
Are you sure you want to change the base?
Conversation
**Summary** The goal with this PR is to ensure that any existing user-set PATH is respected to the widest extent possible. Any elements of the default PATH which have not already been added, will be added to the new PATH in (what I hope to be) a sane way. In the case of no user-set PATH, prepare a sane default PATH. I have left the debug statements in for now to provide visibility to the various test cases. Naturally, these debug statements will need to disappear before the commit is merged to main. Signed-off-by: Rune Morling <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm missing from the PR description is where the user's $PATH
would be coming from. It's can't be set by the user's Bash config (see Bash Startup Files):
When Bash is invoked [...] it first reads and executes commands from the file /etc/profile, if that file exists.
The linked issue could be resolved as follows, which keeps this file much simpler and (importantly) more predictable for the user:
if [ -z ${PATH+x} ]
then
# Insert old implementation here
fi
Edit: the issue describes that path would be overridden somewhere else though, so I think its probably worthwhile to figure out where.
@@ -1,20 +1,64 @@ | |||
# Begin /usr/share/defaults/etc/profile.d/10-path.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File should start with a shebang to clarify that this is a bash script:
# Begin /usr/share/defaults/etc/profile.d/10-path.sh | |
#!/usr/bin/env bash | |
# Begin /usr/share/defaults/etc/profile.d/10-path.sh |
Additionally, please pass the file through shellcheck.
Summary
The goal with this PR is to ensure that any existing user-set PATH is respected to the widest extent possible. Any elements of the default PATH which have not already been added, will be added to the new PATH in (what I hope to be) a sane way.
In the case of no user-set PATH, prepare a sane default PATH.
I have left the debug statements in for now to provide visibility to the various test cases. Naturally, these debug statements will need to disappear before the commit is merged to main.
Test Plan
Open a new virtual terminal with the new 10-path.sh file in place in /usr/share/defaults/etc/profile.d/
Checklist