#!/bin/sh # # @(#)$Id: procs.sh,v 1.1 2001/07/03 16:38:45 sander Exp $ # # Some helper shell functions for the contelligent import scripts. # # author: Robin Sander # # # Processes the given variable so that it contains an absolute path afterwards. # (obsolete '/./' sequences are also removed) # # This is done by simulating a 'call by reference' which means the contents of # the first param is expected to contain the name of the variable and not the # path to process! # For example if a variable 'test' contains './testdir/a' and you call this # functions with pwd=/tmp, then calling 'makeabs test' (not makeabs $test) # will result in 'test' containing '/tmp/testdir/a'. # # $1 : name of the variable containing the path to process # makeabs() { eval tmp_contents=\$"$1" # get the contents of the variable # make path absolute: expr "x$tmp_contents" : x/ > /dev/null || tmp_contents=`pwd`/"$tmp_contents" # remove obsolete '.': first replace '/./' with '/', then remove '/.' and '/' from the end tmp_contents=`printf '%s\n' "$tmp_contents" | sed -e 's,/\./,/,g' -e 's,/\.$,,' -e 's,/$,,'` eval $1="$tmp_contents" # set var with new contents unset tmp_contents }