问题描述
我一直在尝试使用start-stop-daemon创建一个init脚本。我坚持对守护进程的论据。我想把这些变量放在脚本的顶部,但是我无法让引号正确地过滤掉。
I have been trying to make an init script using start-stop-daemon. I am stuck on the arguments to the daemon. I want to keep these in a variable at the top of the script but I can't get the quotations to filter down correctly.
我会在这里使用ls,所以我们不必看大多数人不知道或关心的二进制文件和论据。
I'll use ls here so we don't have to look at binaries and arguments that most people wont know or care about.
我正在寻找的最终结果是开始停止...到运行 ls -la/文件夹空格/
The end result I am looking for is for start-stop... to run ls -la "/folder with space/"
DAEMON=/usr/bin/ls
DAEMON_OPTS='-la "/folder with space/"'
start-stop-daemon --start --make-pidfile --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS
双重转义选项和尝试无数引用的变体不会帮助...然后他们结束在守护进程,他们总是搞砸了。在引号中加上 $ DAEMON_OPTS 会改变事物,那么他们被视为一个,因为引用...从来没有正确的数字:)
Double escaping the options and trying innumerable variations of quotations do not help... Then they end up at the daemon they are always messed up. Enclosing $DAEMON_OPTS in quotes changes things... then they are seen as one since quote... never the right number though :)
回到命令行(开始 - 停止...)打印正确的东西来屏幕。但是,守护进程(真正的,不是ls)抱怨错误的参数数量。
Echoing the command-line (start-stop...) prints exactly the right stuff to screen. But the daemon (the real one, not ls) complains about the wrong number of arguments.
如何指定一个变量,使其中的引号带到守护进程正确?
How do I specify a variable so that quotes inside it are brought along to the daemon correctly?
推荐答案
我以为我会发布我的工作初始化脚本中使用的最终报价:
I thought I'd post the final quotations used in my working init script:
COMMAND="/path/to/script -opt param param2 param3"
DAEMON_OPTS=" 0.0.0.0:$PORT -dest $OUTPUT_DIRECTORY -command"
start-stop-daemon --start --background --make-pidfile --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS "\"$COMMAND\""
显然是一个不完整和非功能的例子,但我希望你得到它的要点。内部对的双引号逃脱是诀窍。
Obviously an incomplete and non-functional example but I hope you get the gist of it. The double quotations with the inner pair escaped is what did the trick.
这篇关于start-stop-daemon引用的参数被误解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!