From e783556e6b5ad9148b3bcc5ce57abb6d7ebc32d3 Mon Sep 17 00:00:00 2001 From: Aron Griffis <aron@arongriffis.com> Date: Wed, 19 Feb 2014 20:43:18 -0500 Subject: [PATCH] dotglob FTW. Doesn't expand . or .. but be explicit just in case. --- bin/utils | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/utils b/bin/utils index 19af53de..ac94949f 100755 --- a/bin/utils +++ b/bin/utils @@ -46,10 +46,10 @@ deep-cp() { # cp doesn't like being called without source params, # so make sure they expand to something first. - # subshell to avoid surprising caller with nullglob. + # subshell to avoid surprising caller with shopts. ( - shopt -s nullglob - set -- "$source"/!(tmp) "$source"/.{[!.],.?}* + shopt -s nullglob dotglob + set -- "$source"/!(tmp|.|..) [[ $# == 0 ]] || cp -a "$@" "$target" ) } @@ -62,7 +62,11 @@ deep-mv() { # Does some serious deleting. deep-rm() { - rm -rf "$1"/!(tmp) "$1"/.{[!.],.?}* + # subshell to avoid surprising caller with shopts. + ( + shopt -s dotglob + rm -rf "$1"/!(tmp|.|..) + ) } -- GitLab