Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try</p> <pre><code>DAEMON_OPTS="-la '/folder with space/'" start-stop-daemon --start ... -- $DAEMON_OPTS </code></pre> <p>What happens is that the outer quotes of <code>DAEMON_OPTS</code> are stripped but the inner (single quotes) remain. So the next line will read:</p> <pre><code>start-stop-daemon --start ... -- -la '/folder with space/' </code></pre> <p>which is what you want.</p> <p>It is also possible to achieve the same effect with escaping but you need a lot of escapes for this: First, to protect the quotes during the assignment, then later when the start line is parsed and variables are expanded and maybe even once more or less. :) <code>bash -x</code> is your friend for things like that.</p> <p>[EDIT] The code above does work with Bourne and Korn shell on anything but Linux. On Linux, with <code>ksh</code> or <code>bash</code>, the shell will add additional quotes which mess up the whole thing:</p> <pre><code>FOLDER="/folder with space/" DAEMON_OPTS="-la $FOLDER" start-stop-daemon --start ... -- $DAEMON_OPTS </code></pre> <p>If you run it with <code>-x</code>, you'll see:</p> <pre><code>FOLDER='/folder with space/' DAEMON_OPTS='-la ~/folder with space/' ls -la '~/folder' with space/ </code></pre> <p>So only the first word gets protection (probably because it contains a special character). If I add single quotes around <code>$FOLDER</code>, I get:</p> <pre><code>FOLDER='/folder with space/' DAEMON_OPTS='-la '\''~/folder with space/'\''' ls -la ''\''~/folder' with 'space/'\''' </code></pre> <p>Well done. Workaround: Split the options into two variables: One with the options and the other with the path:</p> <pre><code>start-stop-daemon --start ... -- $DAEMON_OPTS "$DAEMON_PATH" </code></pre> <p>[EDIT2] This works, too:</p> <pre><code>FOLDER="$HOME/folder with space/" opt[0]=-la opt[1]=$FOLDER ls "${opt[@]}" </code></pre> <p>i.e. put the words into an array.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload