Is there a way that I can make a heredoc in a script interactive as if I am at the prompt?
This is over ssh from linux to an ssh server runing on android connecting through mosh.
I'm making a set of a few small scripts to allow me to reasonably sms over ssh on my android from my laptop using bash under the app termux.
While testing the send command at the prompt all works well:
termux-sms-send -n "$(tail -n1 number | tr -d ' ')" << ''
However, when inside a script this no longer works. This is the result:
./main.sh: line 34: warning: here-document at line 33 delimited by end-of-file (wanted `')
./main.sh: line 35: syntax error: unexpected end of file
I could of course do it another way but it's so neat and simple with the heredoc method and it's something I haven't really used before in bash and I am unsure how to get the read command to work nicely with multi line input in such a graceful way as this.
__
Edit Addition:
In case anyone is interested and for context this is the script:
searchTxt=""
contacts="$(termux-contact-list | jq -r '.[].name')"
clear
while :; do
echo -ne "\nEnter searchterm: $searchTxt"
read -rsn1 ret; clear
if [ ${#ret} -eq 0 ]; then
if [ $(wc -l <<< "$choice") -gt 1 ]; then
echo -en "type enough characters to narrow down selecton until only 1 remains\n\n"
else
echo "choice = $choice"
number="$(termux-contact-list | jq -r ".[] | select(.name==\"$choice\") | .number")"
echo "using number: $number"
echo "$choice" > number
echo "$number" >> number
break
fi
fi
searchTxt+=$ret
choice=$(grep -i "$searchTxt" <<< "$contacts")
echo "$choice"
done
while :; do
clear
echo "Type message to send, enter a blank line to send message"
echo -n "message: "
termux-sms-send -n "$(tail -n1 number | tr -d ' ')" << ''
done
termux-sms-send ... <<< ''termux-sms-sendinherit its standard input from the script, in which case you don't need to do anything?jq -r "...\"$choice\"..."; that's prone to injection issues, which could turn into security bugs if future versions ofjqadd file I/O extensions or the ability to execute external programs. Instead, usejq --arg choice "$choice" '...$choice...', where$choiceis passed as ajqvariable separate from the code.