@nico @mcc I relied on https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html for availability.
That noted, "${file%/*}" is both faster and more elegant. I like it. (It does fail silently and probably bad if a pathname ends with a slash, though.)
@arielmt @mcc as a point of note, i think this makes much more sense to be written as
touchp() { for file; do mkdir -p "$(dirname "$file")" && >> "$file"; done; }
(a) in "$@" is extraneous
(b) so is touch. unless of course you are actually using touch for touching instead of just making files, but seeing as it's most likely a fresh directory, that's unlikely
@nabijaczleweli @mcc For (a): Today I learned. Thank you. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04
@arielmt @mcc Nitpicking, but dirname is non posix. ${file%/*} accomplishes the same though.