Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EOF issue in shell script

Tags:

linux

bash

shell

This following code segment giving error:14: syntax error: unexpected end of file

#!/bin/bash
func_some()
{
    cd some_directory
    lftp -u user,'password' sftp://192.168.xx.xx <<EOF
    cd some_directory
    mget ADMS_report_*${2}${3}${4}*.txt
}
#------------------------------ Main function ------------------------------
func_some 2017 08 08 2017 08 07

But if I remove <<EOF then script just logging in but not executing subsequent command and staying logging in indefinitely.

What could be the solution for this? What mistakes I'm making?

like image 974
Milon Sarker Avatar asked Feb 06 '26 12:02

Milon Sarker


1 Answers

The <<EOF indicates the start of heredoc

A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.

You should then close your heredoc code block, like that:

func_some() 
{
    cd some_directory
    lftp -u user,'password' sftp://192.168.xx.xx <<EOF
    cd some_directory
    mget ADMS_report_*${2}${3}${4}*.txt
EOF
}

as otherwise it will keep on searching for the limit string (EOF), and fail with a syntax error, when the end of file is reached.

Note that the limit string, must be placed at the start of the line, with no spaces in front of it.

like image 156
zeppelin Avatar answered Feb 08 '26 03:02

zeppelin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!