#!/bin/bash # Written by Nick Boldt, codeslave@ca.ibm.com # $Id: lspathseg.txt,v 1.1 2006-11-24 19:34:17 nickb Exp $ # given a dir like /var/www/download.eclipse.org/htdocs/tools/emf # return .../htdocs/tools/emf for numsegs = 3 if [ "$(pwd)" = "/" ]; then echo "/"; else # get current dir dir=$(pwd); # collect commandline option (number of segments) or default 3 if [ "x$1" != "x" ]; then maxsegs=$1; else maxsegs=3; fi # calculate reduced path segs=""; while [ $maxsegs -gt 0 ]; do newseg=${dir##*/}; if [ "x$newseg" != "x" ]; then segs="/"${dir##*/}$segs; fi dir=${dir%/*}; (( maxsegs-- )); done # return result if [ "$segs" != "$(pwd)" ]; then echo "..."$segs; else echo $(pwd); fi fi