Deleting a file with LFTP using variables

17,323

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
Share:
17,323
Svante
Author by

Svante

Updated on June 04, 2022

Comments

  • Svante
    Svante almost 2 years

    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.

    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.

    What am I doing wrong???

    Cheers!