0

How do I save LFTP result in a variable so I can use it later in my script.

This is the basic command I have:

lftp -c 'open -e "mirror /path/to/remote /path/to/local/" ftp://username:password@ftp.domain.com:21'

This obviously this doesn't work:

#!/bin/bash

output=""
lftp -c 'open -e "mirror /path/to/remote /path/to/local/" ftp://username:password@ftp.domain.com:21' > $output
echo "Test: " $output

EDIT:

It seems the problem is using lftp -c doesn't create any output. Therefore the variable is empty. So the problem is to get output from lftp.

Cudos
  • 5,733
  • 11
  • 50
  • 77
  • Look up `how to save output of command to variable bash`. It has been answered multiple times. – 123 Jun 07 '16 at 09:40

1 Answers1

0

Use Command Substitution to store the output of a command in a variable:

output=`lftp -c 'open -e "mirror /path/to/remote /path/to/local/" ftp://username:password@ftp.domain.com:21'`
echo "Test: ${output}"