2

I have a daemon that can be run manually from a bash shell like this:

daemon-binary --name some-name --separator '' /path/to/file

The command-line options for this daemon should be configured in /etc/default/daemonname like this:

DAEMON_OPTS="--name some-name --separator '' /path/to/file"

This config is sourced by an init-script that starts the daemon passing the commandline options found in DAEMON_OPTS like this:

daemon-binary "$DAEMON_OPTS"

The result is, that the string '' gets quoted again and instead of an empty string the daemon-binary gets passed two single. So in fact the result is the same as calling:

daemon-binary --name some-name --separator "''" /path/to/file

As far as I understand bash splits the DAEMON_OPTS at each whitespace, then quotes all the pieces and passes them to the daemon-binary.

Is there any way to write the bash variable DAEMON_OPTS such that what's currently being expanded to "''" will be expanded into an empty string?

migrated from stackoverflow.com Nov 8 '12 at 9:19

This question came from our site for professional and enthusiast programmers.

3

This is a case where you don't want to quote the expansion of DAEMON_OPTS:

DAEMON_OPTS="--name some-name --separator '' /path/to/file"
daemon-binary $DAEMON_OPTS
  • 1
    if this is bash, you can also use DAEMON_OPTS=("--name" "some-name" "--separator" "" "/path/to/file") and daemon-binary "${DAEMON_OPTS[@]}" – Andreas Rogge Feb 11 '18 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.