Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> writes: > + # Turn foo/bar/baz into foo/bar to create foo/bar as a > + # directory structure. > + dirs=$(echo "$file" | sed -r 's!/[^/]+$!!') Let's not limit this script to GNUism systems. You want to see if $file has a slash followed by one or more non-slash letters to the end and strip the whole thing. We further know that at this point $file does not end with a slash. So perhaps dirs=${file%/*} is sufficient? Thanks.