Deleting a file using LFTP using variables

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

The code:

USERNAME="theuser" PASSWORD="verygoodpassword" SERVER="example.com" BACKUPDIR="thebackups" FILETODELETE="uselessfile.obsolete" lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u $USERNAME,$PASSWORD $SERVER 

I want it to run:

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

But instead, it starts:

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

And because of this, he cannot find the literal file "/ $ {BACKUPDIR} / $ {FILETODELETE}" on the FTP server and complains in this way.

What am I doing wrong?

Hurrah!

+6
source share
1 answer

This is because you use a simple quote instead of double quotes.

Change it and you will work

 USERNAME="theuser" PASSWORD="verygoodpassword" SERVER="example.com" BACKUPDIR="thebackups" FILETODELETE="uselessfile.obsolete" lftp -e "rm /${BACKUPDIR}/${FILETODELETE}; bye" -u $USERNAME,$PASSWORD $SERVER 
+12
source

Source: https://habr.com/ru/post/911110/


All Articles