首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shell脚本-语法错误: Debian 11上意外的文件结束

Shell脚本-语法错误: Debian 11上意外的文件结束
EN

Server Fault用户
提问于 2022-10-27 17:26:53
回答 1查看 282关注 0票数 0

我在两个系统上有一个相同的文件,但是一个系统运行Debian 8,另一个系统运行11。

代码语言:javascript
复制
#!/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
to=warning@blabla.com
subject="$1"
from=`hostname`@blabla.com
daemail=$(cat <

现在在一个系统(deb8)上,它按预期工作,但在另一个系统上,我得到了一个错误

代码语言:javascript
复制
/etc/init.d/warner: 24: Syntax error: end of file unexpected (expecting ")")

现在,当我在deb11脚本上将中断改为/bin/bash时,它就能工作了。为什么/bin/sh会在更新的Debian上抛出这个错误?

EN

回答 1

Server Fault用户

发布于 2022-10-27 20:42:31

我猜是在破折号0.5.7-4 (debian8.11)和破折号0.5.11-git+20200708之间发生了一些变化。(Debian 11),它影响了结束标记和终止子shell的方式。我认为,Debian符号链接/bin/sh到/bin/dash从Jessie (Debian 8)开始。

试着在“!”之后添加一个LF。将“)”移至下一行。

我从shellcheck.net那里得到的

代码语言:javascript
复制
Line 20:
!)
 ^-- SC1119 (error): Add a linefeed between end token and terminating ')'.
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1114169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档