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>
21 # $Id: add_path.sh,v 1.1 1995/09/30 12:45:23 sjg Exp $
23 # @(#)Copyright (c) 1991 Simon J. Gerraty
25 # This file is provided in the hope that it will
26 # be of use. There is absolutely NO WARRANTY.
27 # Permission to copy, redistribute or otherwise
28 # use this file is hereby granted provided that
29 # the above copyright notice and this notice are
32 # is $1 missing from $2 (or PATH) ?
34 eval "case :\$${2-PATH}: in *:$1:*) return 1;; *) return 0;; esac"
36 # if $1 exists and is not in path, append it
38 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
40 # if $1 exists and is not in path, prepend it
42 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
44 # if $1 is in path, remove it
46 no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
47 sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`