3 ms·
Sharing is caring? :)
by munchor 9y ago
Sharing is caring? :)
- koolba 9y agoAsk and ye shall receive! make-scratch-dir () { local name="$1" local pattern='^[a-z0-9\\-]+$' if [[ "$#" != 1 ]]; then echo "Usage: make-scratch-dir <name>" 1>&2 return 1 elif [[ ! "$name" =~ $pattern ]]; then echo "Invalid name: ${name}" fi local full_path="$HOME/tmp/scratch/$(date +%Y%m%d-%H%M%S)-${name}" mkdir -p "${full_path}" pushd "${full_path}" echo "Now in temp dir: ${full_path}" } The directory change is done via pushd so you can hop back via popd. Also, it restricts the suffixes to ensure the directories are all "simple" names.
- effie 9y agoI didn't know of pushd, very interesting, may be useful for directory traversal in general.