#!/bin/ksh # Uses companion script 'path -u' to list distinct items in colon-separated list # on one line per item, # and returns a string in the form of a colon-separated # list of entries. # # This is useful when configuring path settings, as you typically want to append # an item to the path # only if it is not already present. # e.g: # CLASSPATH=$(newpath ${CLASSPATH}:${ORACLE_HOME}/some/other/dir:~/java/wherever) # # I have not allowed spaces e.g. "newpath ${PATH} /otherdir /thirdplace" because # (1) it complicates things, and # (2) it would be ambiguous since a directory name could potentially include spaces. # # William Robertson, www.williamrobertson.net usage="'${0##*/}' utility, William Robertson 2003, www.williamrobertson.net. \nUsage: ${0##*/} [ pathstring ] \nOptional pathstring defaults to \$PATH" # Default argument is the PATH variable: oldpath="${1:-${PATH}}" newpath="" for d in $(path -u ${oldpath}) do newpath=${newpath}:${d} done newpath=${newpath#:} newpath=${newpath%:} print ${newpath}