大网数据广告活动
服务器运维问答

How to break complicated ExecStart line while still having comments in the middle?

· 52CE 我爱测

I have a long command-line to put into a systemd ExecStart entry. I understand I can break a long line into multiple ones by ending each non-final line with a backslash. However, how can I document the parts with comments? E.g. t…

问题原文

原帖链接 · Syncopated · CC BY-SA 3.0

I have a long command-line to put into a systemd ExecStart entry. I understand I can break a long line into multiple ones by ending each non-final line with a backslash.

However, how can I document the parts with comments? E.g. the following won't work:

ExecStart=/bin/ssh -NT -o ExitOnForwardFailure=yes -o ServerAliveInterval=60 -o ServerAliveCountMax=3 \
# local tunnel for this
    -L 172.16.12.34:10001:localhost:10001 \
# remote tunnel for that
    -R3128:127.0.0.1:3128 \
    someserver

If I remove the lines with '#', it works, but then I lose the documentation. If fine-grain in-place documentation of parts of a long command-line is fundamentally impossible, what are some useful alternatives?

社区高分解答

原帖链接 · artfulrobot · CC BY-SA 4.0

I think this is what @sven suggests:

#
# Listen locally on port 10001 and tunnel it to someserver
# Listen on someserver port 3128 and tunnel it to localhost
#
ExecStart=/bin/ssh -NT \
    -o ExitOnForwardFailure=yes \
    -o ServerAliveInterval=60 \
    -o ServerAliveCountMax=3 \
    -L 172.16.12.34:10001:localhost:10001 \
    -R3128:127.0.0.1:3128 \
    someserver

Doesn't look too bad to me.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。