Cygwin: the difference between the command "\ rm -fr" and "rm -fr"?

I have a shell script running in a windows environment in a cygwin environment. This script has one cleanup function that deletes a specific folder on a system basis under certain conditions.

I will prepare a list of the entire folder that I want to delete, and then use the following command:

rm -rfv $purge (where purge is the list of directories I want to delete)

Now that I have tested this script, directories are not deleted at all. At first I thought there was a problem with the cleanup list, but when debugging, I found out that the cleanup list is ok.

After a lot of debugging and testing, I just made a small change to the command:

\rm -rfv $purge 

This is just a hit and trial, and the script starts working fine. Now, as far as I know, \ rm and rm -f both mean force removal.

Now, how can I justify this why rm -f works, but rm -f works earlier. I want to know the main difference between the two teams.

+5
source share
2 answers

rm can be (theoretically) one of:

  • shell builtin command (however, I don’t know any shell with such built-in)
  • external command (most likely / bin / rm)
  • shell function
  • pseudonym

If you put \in front of it (or indicate any part of it, for example, "rm"or even 'r'm), the shell will ignore all aliases (but not functions).

As mentioned in jlliagre, you can ask the shell what rmand what \rmusing typebuiltin.

Experiment:

$ type rm
rm is /bin/rm
$ rm() { echo "FUNC"; command rm "$@"; }
$ type rm
rm is a function
$ alias rm='echo ALIAS; rm -i'
$ type rm
rm is aliased to `echo ALIAS; rm -i'

rm, function rm rm: , :

$ rm   # this will call alias, calling function calling real rm
$ rm
ALIAS
FUNC
rm: missing operand
$ \rm  # this will ignore alias, and call function calling real rm
FUNC
rm: missing operand
$ command rm  # this will ignore any builtin, alias or function and call rm according to PATH
rm: missing operand

, . help builtin, help command, help alias man sh.

+9

, rm . Backslashing rm.

: , rm type, :

$ type rm
rm is /bin/rm

.

$ type rm
rm is aliased to `rm -i'

.

$ type rm
rm is a function
...
+5

All Articles