bash rm -r 在 shell 脚本中(我的第一个 *.sh)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28853830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rm -r in shell script (my first *.sh)
提问by JLN
I would like to delete some folder on an Ubuntu 8.04 Server.
我想删除 Ubuntu 8.04 服务器上的某个文件夹。
I would like to start a script to delete this folder.
我想启动一个脚本来删除这个文件夹。
I start an ssh session to the server.
我开始与服务器的 ssh 会话。
My script looks like this:
我的脚本如下所示:
#!/bin/bash
rm -r /var/lib/backuppc/pc/PC1/
rm -r /var/lib/backuppc/pc/PC2/
I run the script like this:
我像这样运行脚本:
sh scriptname.sh
But I get this message:
但我收到这条消息:
rm: cannot remove `/var/lib/backuppc/pc/PC1/\r': No such file or directory
rm: cannot remove `/var/lib/backuppc/pc/PC1/\r': No such file or directory
I'm sorry but I don't use ever a shell script on linux. I think it my fault because I don't know the basics :-(
对不起,我从来没有在 linux 上使用过 shell 脚本。我认为这是我的错,因为我不知道基础知识:-(
Can somebody help me? I've to delete ~80 folder... :-(
有人可以帮助我吗?我必须删除 ~80 文件夹... :-(
回答by TomCho
It looks like there is some "junk" characters after your folder name (namely, \r
). To be sure, type cat -A scriptname.sh
and check if you can see some weird characters in the end of the lines. If so, I think the easiest thing for you (since you have few lines) is to manually delete the ending of those lines and re-type again. (I'm talking about the last two or three characters only)
Type cat -A scriptname.sh
and see if the characters disappeared. If so, you should be good to go with your code.
看起来您的文件夹名称(即\r
)后面有一些“垃圾”字符。可以肯定的是,键入cat -A scriptname.sh
并检查是否可以在行尾看到一些奇怪的字符。如果是这样,我认为对您来说最简单的事情(因为您只有几行)是手动删除这些行的结尾并再次重新键入。(我只说最后两三个字符)键入cat -A scriptname.sh
并查看字符是否消失。如果是这样,您应该很好地使用您的代码。