bash

Improving touch

I've sometimes wished that the UNIX touch command had the same -p option as mkdir. With a little bit of scripting, it can:

#!/bin/sh

mkdir="/bin/mkdir"
touch="/usr/bin/touch"

for arg in $*; do
    if [ "$arg" = "-p" ]; then
        opt_p=true
        continue
    fi
    if [ "$opt_p" = "true" ]; then
        $mkdir -p $(dirname $arg) && $touch $arg
    else
        $touch $arg
    fi
done