Artificial intelligent assistant

using heredoc in case statement for remote ssh host 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

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.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 6e20abd691876e602b6b03c2d3c12176