]> git.ipfire.org Git - thirdparty/bash.git/blob - examples/functions/pathfuncs
Imported from ../bash-2.04.tar.gz.
[thirdparty/bash.git] / examples / functions / pathfuncs
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
5
6
7 # NAME:
8 # add_path.sh - add dir to path
9 #
10 # DESCRIPTION:
11 # These functions originated in /etc/profile and ksh.kshrc, but
12 # are more useful in a separate file.
13 #
14 # SEE ALSO:
15 # /etc/profile
16 #
17 # AUTHOR:
18 # Simon J. Gerraty <sjg@zen.void.oz.au>
19
20 # @(#)Copyright (c) 1991 Simon J. Gerraty
21 #
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
27 # left intact.
28
29 # is $1 missing from $2 (or PATH) ?
30 no_path() {
31 eval "case :\$${2-PATH}: in *:$1:*) return 1;; *) return 0;; esac"
32 }
33 # if $1 exists and is not in path, append it
34 add_path () {
35 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
36 }
37 # if $1 exists and is not in path, prepend it
38 pre_path () {
39 [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
40 }
41 # if $1 is in path, remove it
42 del_path () {
43 no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
44 sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`
45 }