I need to write a shell script where I read a variable from environment. If the file pointed by it doesn't exist, I want to create it.
This file path could contain some intermediate non-existent directories, so these also need to be created. So neither mkdir -p works here nor simple touch works here.
What is the workaround?
Thanks!
mkdir -p "`dirname $foo`"
touch "$foo"
dirname
works on arbitrary paths; it doesn't check whether the path is in use (whether the file pointed to exists).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With