rm: cannot remove '–rf': No such file or directory

不羁岁月 提交于 2019-12-12 04:38:14

问题


I have a Bash script that automates creating some SVN folders. In the course of doing so, it creates a temporary directory. When I try to delete that temp directory with the rm -rf command, I get the following error...

rm: cannot remove '–rf': No such file or directory

It seems to think that "-rf" is a file name. The command works fine on the command line.

Here is my script...

#!/bin/bash

if [ $# -lt 1 ]; then
  echo "Usage: $0 reponame1 reponame2 ..."

else
  for var in "$@"
  do
      REPONAME=$var

      mkdir -p ~/temp-$REPONAME/branches
      mkdir ~/temp-$REPONAME/tags
      mkdir ~/temp-$REPONAME/trunk

      svnadmin create $REPONAME
      svn import ~/temp-$REPONAME svn+ssh://username@192.168.123.234/home/username/svnrepos/$REPONAME -m "Initial structure"

      rm –rf ~/temp-$REPONAME/
  done
fi

And here is the output

$ ./mkrepo.sh mysvnrepo
username@192.168.123.234's password:
username@192.168.123.234's password:
Adding         /home/username/temp-mysvnrepo/branches
Adding         /home/username/temp-mysvnrepo/tags
Adding         /home/username/temp-mysvnrepo/trunk
Committing transaction...
Committed revision 1.
rm: cannot remove '–rf': No such file or directory
rm: cannot remove '/home/username/temp-mysvnrepo/': Is a directory

回答1:


You managed to type a unicode "EN DASH"(U+2013) which is not recognised by rm as a normal hyphen "-"(U+002D) so rm thinks it is the beginning of a file name and not of your parameters. They do look alike, but they are not the same for a program. To fix it, just erase it and type it again making sure you take the normal hyphen/minus key.




回答2:


The '-' in your script in rm –rf is not the one it expects. The correct one is rm -rf.

I hope you can spot the difference.

rm –rf rm -rf



来源:https://stackoverflow.com/questions/45592535/rm-cannot-remove-rf-no-such-file-or-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!