Created
March 11, 2024 19:21
-
-
Save subfission/5a66680b9ea4354dd32a45aa999f950b to your computer and use it in GitHub Desktop.
Best way to source a file or directory after null checking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Example ternary to source a directory into PATH if it exists | |
# | |
[ -d $HOME/custom/dir ] && export PATH=$PATH:${HOME}/custom/dir | |
# | |
# Better way to source a path into the global environment through function calls | |
# | |
add_to_path() { [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]] && export PATH="$1:$PATH"; } | |
# | |
# Better way to source a bash config | |
# | |
resource() { [ -f "$1" ] && source "$1"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finish with: