[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#5926: feature request: mv -p to create missing target dir
From: |
Stefano Lattarini |
Subject: |
bug#5926: feature request: mv -p to create missing target dir |
Date: |
Sun, 25 Apr 2010 15:29:34 +0200 |
User-agent: |
KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.4; i686; ; ) |
Just a few obsevations on side issues...
Bob Proulx writes:
> Rodolfo Borges wrote:
>
> > cat <<EOF >> ~/.bashrc
> > function mv() {
> > local target="${!#}"
> > local dir
> > if [[ "$target" =~ '/$' ]]; then
> > dir="$target"
> > else
> > dir="$(dirname "$target")"
> > fi
> > test -d "$dir" || mkdir -vp "$dir"
> > $(which mv) "$@"
> > }
> > EOF
>
> Very good! I see that you have a solution to your problem.
>
> As a side comment I don't see the point of:
> > $(which mv) "$@"
I think that's needed because otherwise the shell function would end
up calling itself recursively, since it's named `mv' too.
> The 'which' command is another one of those simple but not very
> portable commands that does different things on different systems.
Since Rodolfo is assuming bash as his shell, he could have used:
$(type -P mv) "$@"
instead, which is more "portable" because it just uses bash builtins.
> In the simple case of reporting where the command is found on PATH
> the use here is redundant since the command would otherwise simply
> be found on PATH.
> mv "$@"
No, this would call the `mv' function, since shell functions take
precedence over external commands in bash.
Regards,
Stefano