I need to touch a file with an absolute file name such as: /opt/test/test.txt, but I\'m not sure if there is /opt/test existed on the system. So the code should similar with thi
I have this shell function in my .zshalias file:
.zshalias
function touch-safe { for f in "$@"; do [ -d $f:h ] || mkdir -p $f:h && command touch $f done } alias touch=touch-safe
If either the test or the mkdir command fail, no touch command is invoked.
test
mkdir
touch