BASH redirect create folder
echo "something" | install -D /dev/stdin $f
try
mkdir -p `dirname $f` && echo "something" > $f
The other answers here are using the external command dirname
. This can be done without calling an external utility.
mkdir -p "${f%/*}"
You can also check if the directory already exists, but this not really required with mkdir -p
:
mydir="${f%/*}"
[[ -d $mydir ]] || mkdir -p "$mydir"