Linux 使用变量通过 LFTP 删除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9773454/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:16:04  来源:igfitidea点击:

Deleting a file with LFTP using variables

linuxbashshellftplftp

提问by Svante

I'm trying to delete a file from an FTP server in my shell scrip using LFTP, but for some reason it will not use my variables, and takes them as literals.

我正在尝试使用 LFTP 从我的 shell 脚本中的 FTP 服务器中删除一个文件,但由于某种原因它不会使用我的变量,而是将它们作为文字。

The code:

编码:

USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"

lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u $USERNAME,$PASSWORD $SERVER

What I want it to do is run:

我想要它做的是运行:

lftp -e 'rm /thebackups/uselessfile.obsolete; bye' -u theuser,verygoodpassword example.com

But instead it runs:

但它运行:

lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u theuser,verygoodpassword example.com

And of cause it can not find the literal file "/${BACKUPDIR}/${FILETODELETE}" on the FTP server and complains thus.

并且因为它无法在 FTP 服务器上找到文字文件“/${BACKUPDIR}/${FILETODELETE}”并因此抱怨。

What am I doing wrong???

我究竟做错了什么???

Cheers!

干杯!

采纳答案by Arnaud F.

That's because you are using simple quote instead of double quotes.

那是因为您使用的是简单引号而不是双引号。

Change this and will work

改变这一点,将工作

USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"

lftp -e "rm /${BACKUPDIR}/${FILETODELETE}; bye" -u $USERNAME,$PASSWORD $SERVER