ref: 989dbedde74719cbb6c2d85316325b7db7621118
dir: /path/
#!/bin/rc rfork e . /sys/lib/x/lib.rc usage = ' x/path [-Pprl] ' if(! ~ $$#* -*) wd=$$#* if not wd=`{pwd} wd=`{cleanname $wd} if(! ~ $wd /x/*) exit 'invalid path' for(arg){ switch($arg){ case -P echo $wd | sed 's,/[^/]+/[^/]+(.*),\1,' case -p echo $wd | sed 's,/[^/]+/[^/]+/(.*),\1,' case -r echo $wd | sed 's,(/[^/]+/[^/]+).*,\1,' case -l echo $wd | awk -F/ '{if($3) print $3; else print $0}' } shift }