0

I am trying to connect SFTP server I am getting error: Syntax error at line 5 : `<' is not matched. I am using ksh.

while [ $counter -gt 0 ]; do 
    sftp user@host <<-EOF
       ls -ltr
    EOF
    counter=$(($counter-1))
done

But it works for below.

while [ $counter -gt 0 ]; do 
    sftp user@host
       ls -ltr
    EOF
    counter=$(($counter-1))
done
bhanu
  • 76
  • 10
  • `<<-EOF` only works if you use tabs, not spaces. It's better to just use `< – Charles Duffy Mar 04 '20 at 16:21
  • 1
    @KamilCuk, the `-` in `<<-EOF` tells it to ignore leading tabs. However, folks copying-and-pasting code following that often end up with non-tab whitespace, hence... – Charles Duffy Mar 04 '20 at 16:22
  • It absolutely does matter, insofar as it means there exists a circumstance where the `EOF` would still be recognized as closing the heredoc when *not* at the beginning of the line. – Charles Duffy Mar 04 '20 at 16:23
  • 1
    Is it good practice to rely on that? No, not at all. Is it legal, so the OP could have copied code that really did work (and then changed the whitespace type by mistake, or used an editor configured to do that implicitly, thus breaking it)? Yes. – Charles Duffy Mar 04 '20 at 16:24
  • You are right!. Copy from text editor didn't worked. It worked after typing it. Thanks for the pointers. – bhanu Mar 05 '20 at 02:56
  • Glad to hear that helped! Since we've locked down the problem, I closed it with a link to another instance (the other one is written up for bash rather than ksh, but they're fully compatible as to this syntax, and the answers written there are entirely applicable). – Charles Duffy Mar 05 '20 at 03:13

0 Answers0