Question

I use c shell (tcsh specifically).

I have the following alias in my .custom file, so that cp by default is always defined to have the -i flag:

alias cp cp -i

For a specific shell script I am trying to write it is desirable for cp to be forced to overwrite and not prompt me if I want to overwrite the destination file. I have tried using cp --remove-destination in my shell script but I was still being prompted whether to overwrite the destination files. What would be the correct flag to use to force an overwrite when -i is already the default behavior?

Was it helpful?

Solution 2

You have two possibilities:

First uses system cp instead of invoking your alias:

/bin/cp .....

Second overrides -i option (so it looks like cp -i -n instead)

cp -n ....

The second one is much less readable so I suggest using the first one.

OTHER TIPS

You can always invoke the original/un-aliased command by prefixing it with '\' (Try: which cp vs which \cp).

So running: \cp a b bypasses the alias, i.e. invokes the original command that would be invoked if you had no alias. This is better than explictly running /bin/cp because:

  • it is shorter and more intuitive (when you want to run cp, you want to run cp, not /bin/cp)
  • it does not require that you know the full path to the command
  • it also works for shell-builtins (e.g. cd), which are not executables, therefor don't have a "full path"

Aliasing to add a parameter might have unexpected results elsewhere, you're probably better off aliasing for example alias cpi cp -i. That way you will avoid possible conflicts and will also be able to use the command in the regular manner.
Alternatively, if you insist on keeping your alias, you can just use cp directly via /bin/cp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top