Score:0

Shell script - Syntax error: end of file unexpected on Debian 11

cn flag

I have an identical file on two systems but one system is running Debian 8 and the other is 11

#!/bin/sh
### BEGIN INIT INFO
# Provides:          warner
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO
[email protected]
subject="$1"
from=`hostname`@blabla.com
daemail=$(cat <<!
From: $from
To: $to
Subject: $subject
$2
You might want to check this...
!)

echo "$daemail" | /usr/sbin/sendmail -t

Now on one system (deb8), it works as expected but on the other, I'm getting an error

/etc/init.d/warner: 24: Syntax error: end of file unexpected (expecting ")")

Now when I change the interpter to /bin/bash on the deb11 script, it works. Why the /bin/sh throws this error on newer Debian?

Score:0
in flag

I'm guessing some changes were made between dash 0.5.7-4 (Debian 8.11) and dash 0.5.11-git+20200708... (Debian 11) that have affected how end tokens and terminating a sub-shell. Debian symlinks /bin/sh to /bin/dash since before Jessie (Debian 8) I think.

Try adding a LF after the '!' to move the closing ')' to the next line.

I got this from shellcheck.net

Line 20:
!)
 ^-- SC1119 (error): Add a linefeed between end token and terminating ')'.
monkadelicd avatar
in flag
Reference for the ShellCheck error code: https://www.shellcheck.net/wiki/SC1119
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.