vote up 0 vote down star

In a given shell script I need to take a known path and check it upwards (to the file system root) for correct permissions. How would I split the path and walk upwards in a shell script (can be bash or a "lower common denominator")?

flag

1 Answer

vote up 0 vote down check

This should work:

unset path
parts=$(pwd | awk 'BEGIN{FS="/"}{for (i=1; i < NF; i++) print $i}')

for part in $parts
do
path="$path/$part"
ls -ld $path   # do whatever checking you need here
done
link|flag
Thanks, that works. Is there a (ba)sh-only solution? – k-fish Nov 5 at 21:12

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.