0

I have a list of ssh commands to run on remote server, so wrote this snippet.

#!/usr/bin/env bash


echo ''
echo "WOULD YOU LIKE TO PERFORM FILES CLEANUP: "
read choice


case $choice in
  yes|YES|y|Y )

    echo ''
    echo "Enter NAME OR IP OF REMOTE HOST: "
    read ls_host


    ssh -t ${ls_host} <<- IFF
      command 1
      command 2
      command 3
    IFF;;
  * )
    echo "YOU'VE MADE A WISE-CHOISE: SCRIPT IS SKIPPING CLEANUP";;
esac

below error

warning: here-document at line # delimited by end-of-file (wanted `IFF')

I tried quotes around IFF also

0

1 Answer 1

2

Here-docs are collected "outside" the normal syntax, based on just the input lines. So, you need to have the here-doc separator on a line of its own, and you can't combine that with other syntax. Also, the here-doc separator could itself contain syntax elements, like that ;;...

E.g. this should print wat and hi, hello.

#!/bin/sh

cat << "EOF;;"
wat
EOF;;

case x in 
 x) cat <<-EOF
        hi, hello
        EOF
    ;;
 y) false;;
esac

Note you need hard tabs before the second EOF and the hi, hello line, and since stackexchange changes tabs to spaces, copypasting this directly doesn't work. That may or may not be an argument for avoiding <<- and instead just shoving the here-doc data to the left edge.


Also read ls_host; ssh -t ${ls_host} would allow the user to enter options to ssh when entering the hostname, which may or may not be what you want. Might want to use "${ls_host}" there, too.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.