#!/bin/ksh # List items in colon-separated list on one line per item. # With no arguments, lists contents of PATH variable. # Alternative strings can be passed, e.g: # path $CLASSPATH # William Robertson, www.williamrobertson.net usage="'${0##*/}' utility, William Robertson 2003, www.williamrobertson.net. \nUsage: ${0##*/} [ -u ] [ pathstring ] \nOptions: -u = Unique \nOptional pathstring defaults to \$PATH" while getopts ":u" opt; do case $opt in u ) unique=Y ;; * ) print -u2 ${usage}; exit 2;; esac done shift $(($OPTIND -1)) path=${1:-$PATH} accumulated="" standardIFS="${IFS}" IFS=':' for d in ${path} ; do if [[ :${accumulated}: = *:${d}:* ]] then [[ ${unique} = Y ]] || print ${d} else print $d accumulated=${accumulated}:${d} fi done IFS="${standardIFS}"