The shift in the alias for cp emits an error message when cp is used without any arguments:
~ > cp
f:shift: shift count must be <= $#
cp: missing file operand
Try 'cp --help' for more information.
Furthermore, the aliases don't do what they say they do. The comment of Confirm before overwriting something does not apply, because the -i is only added if no other arguments are provided. This becomes clear when we try the function that cp is aliased to in the shell, but with calls to echo showing the argument array:
~ > cp_alias
initial:
modified: -i
cp_alias:shift: shift count must be <= $#
...
When called with any arguments at all, we no longer get -i:
~ > cp_alias x
initial: x
modified: x
...
I set up a couple of test files to try out the current cp alias, and it definitely doesn't add -i:
~ > touch x
~ > touch y
~ > cp x y
~ > # It should have asked if I want to overwrite!
Compare this to when we use cp -i:
~ > cp -i x y
cp: overwrite 'y'?
I understand that the original edits were intended to allow the arguments to be overridden, but the current aliases are incorrect and even give error messages. If users want to bypass the aliases, they can just use the built-in backslash feature: running \cp instead of cp will cause the alias to be ignored.
~ > alias cp="cp -i"
# With a backslash, we don't get a prompt
~ > \cp x y
# Without a backslash, we do get one
~ > cp x y
cp: overwrite 'y'?
The
shift
in the alias forcp
emits an error message whencp
is used without any arguments:Furthermore, the aliases don't do what they say they do. The comment of
Confirm before overwriting something
does not apply, because the-i
is only added if no other arguments are provided. This becomes clear when we try the function thatcp
is aliased to in the shell, but with calls toecho
showing the argument array:When called with zero arguments, we do get
-i
:When called with any arguments at all, we no longer get
-i
:I set up a couple of test files to try out the current
cp
alias, and it definitely doesn't add-i
:Compare this to when we use
cp -i
:I understand that the original edits were intended to allow the arguments to be overridden, but the current aliases are incorrect and even give error messages. If users want to bypass the aliases, they can just use the built-in backslash feature: running
\cp
instead ofcp
will cause the alias to be ignored.