Wondering what is wrong with my syntax.
Running this bash script works as expected and all of the commands are executed:
sftp -i ~/.ssh/my_private_key $username@$host <<EOF lcd /home/documents get * bye EOF
Trying to throw the EOF inside of an IF, however, makes it not execute:
sftp -i ~/.ssh/my_private_key $username@$host if [[ $? != 0 ]]; then echo "SFTP connection failed to establish." exit 10 else <<-EOF lcd /home/documents get * bye EOF echo "Files moved and connection closed." fi exit 0
All that happens is I see the "Connected to $host" message in terminal, and then it waits for input. If I type any commands like
pwd they execute, and finally typing
bye closes the connection and prints
"Connection closed.", but none of the commands inside EOF execute at any point.