1 #From: "Simon J. Gerraty" <sjg@zen.void.oz.au>
2 #Message-Id: <199510091130.VAA01188@zen.void.oz.au>
3 #Subject: Re: a shell idea?
4 #Date: Mon, 09 Oct 1995 21:30:20 +1000
8 # add_path.sh - add dir to path
11 # These functions originated in /etc/profile and ksh.kshrc, but
12 # are more useful in a separate file.
18 # Simon J. Gerraty <sjg@zen.void.oz.au>
20 # @(#)Copyright (c) 1991 Simon J. Gerraty
22 # This file is provided in the hope that it will
23 # be of use. There is absolutely NO WARRANTY.
24 # Permission to copy, redistribute or otherwise
25 # use this file is hereby granted provided that
26 # the above copyright notice and this notice are
29 # is $1 missing from $2 (or PATH) ?
31 eval "case :\$${2-PATH}: in *:$1:*) return 1;; *) return 0;; esac"
33 # if $1 exists and is not in path, append it
35 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
37 # if $1 exists and is not in path, prepend it
39 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
41 # if $1 is in path, remove it
43 no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
44 sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`