From a270b086c552f24a01c9eb6009c9c610abea5f80 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Dec 2018 13:25:46 +1300 Subject: Refactor "path list" not to require a subshell --- sh/shrc.d/path.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'sh') diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh index b6b1820f..70947515 100644 --- a/sh/shrc.d/path.sh +++ b/sh/shrc.d/path.sh @@ -5,15 +5,16 @@ path() { case $1 in # List current directories in PATH - list|'') ( - path=$PATH: - while [ -n "$path" ] ; do - dir=${path%%:*} - path=${path#*:} - [ -n "$dir" ] || continue - printf '%s\n' "$dir" + list|'') + set -- "$PATH": + while [ -n "$1" ] ; do + case $1 in + :*) ;; + *) printf '%s\n' "${1%%:*}" ;; + esac + set -- "${1#*:}" done - ) ;; + ;; # Helper function checks directory argument makes sense _argcheck) -- cgit v1.2.3