writing about PATH is so funny, it's like
-
writing about PATH is so funny, it's like
1. just add “PATH=$PATH:/my/dir" to your shell config, no big deal
2. ok but also you need to worry about path ordering, maybe it has to be `PATH=/my/dir:$PATH` instead
3. oh also bash sometimes caches PATH lookups, so if that happens then you need to run `rehash`
4. oh yeah and also if there are spaces in your PATH, then you need to quote it every time you add to it, like `PATH=/my/dir:”$PATH”`
5. also if it's a cron job it'll use a different PATHetc
-
@b0rk or all the utilities that recommend adding a snippet to invoke them in your startup so they may modify PATH for you as well
-
Ryan Castellucci :nonbinary_flag:replied to rj last edited by
-
rjreplied to Ryan Castellucci :nonbinary_flag: last edited by
@ryanc @b0rk oh yeah I wound up building helper functions around this whole mess and left some...here: https://tacobelllabs.net/@arrjay/111825226689637081 (warning: very compacted bash functions/code)
-
Ryan Castellucci :nonbinary_flag:replied to rj last edited by
if [ -n "$BASH_VERSION" ]; then
pathlist_append() { [ -n "$1" -a -d "$2" ] && export "$1"="${!1:+${!1}:}$2"; }
pathlist_prepend() { [ -n "$1" -a -d "$2" ] && export "$1"="$2${!1:+:${!1}}"; }
else
# https://stackoverflow.com/a/36235741/370695
__var_safe() { expr "${1-}" : '[[:alpha:]_][[:alnum:]_]*$' > /dev/null; }
pathlist_append() {
if __var_safe "${1-}" && [ -d "${2-}" ]; then
eval "export ${1}=\"\${${1}:+\$${1}:}\$2\""
fi
}
pathlist_prepend() {
if __var_safe "${1-}" && [ -d "${2-}" ]; then
eval "export ${1}=\"\$2\${${1}:+:\$${1}}\""
fi
}
fi
path_append() { [ -d "$1" ] && PATH="$PATH:$1"; }
path_prepend() { [ -d "$1" ] && PATH="$1:$PATH"; } -
Ryan Castellucci :nonbinary_flag:replied to Ryan Castellucci :nonbinary_flag: last edited by
-
mx alex tax1a - 2020 (4)replied to Julia Evans last edited by
@b0rk
fish
shell has afish_add_path
command that ...helps, a bit.