[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash variable escaping



On Wed, Sep 11, 2013 at 10:46:38AM +0200, Denis Witt wrote:

||  I expect the program (salt) to see exactly '*' (single quote, asterisk,
||  single quote).

You may expect so, but salt does not.

||  See examples of the salt-syntax here:
||  http://docs.saltstack.com/topics/targeting/globbing.html

This line:

    You must wrap salt calls that use globbing in single-quotes to
    prevent the shell from expanding the globs before Salt is invoked.

implies that salt does *not* want to see the single quotes: they are
there to prevent the *shell* from expanding the asterisk, but the shell
removes the quotes before passing the argument to salt.

||  At the moment i can't see any way how to do this.
||  
||  machines="'*'"
||  salt $machines
||  salt ${machines}
||  salt "${machines}
||  salt "${machines}"
||  not working

All these will pass the single quotes to salt which is wrong. #3 also
misses the closing double quote.

||  machines='*'
||  salt $machines
||  salt ${machines}
||  salt "${machines}
||  salt "$machines"
||  not working

#4 should work. The value of the machine variable does not have the
single quotes. It turns out that without double quotes, the shell first
expands the variable, then expands the filename pattern (which is a
single asterisk). The double quotes prevent filename expansion.

||  salt '*'
||  works fine

Yes. The single quotes prevent filename expansion, but get stripped by
the shell, so salt sees the asterisk only.

Vincent.
-- 
Vincent Zweije <vincent@zweije.nl>   | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/>      | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] |            -- Paul Tomblin on a.s.r.

Attachment: signature.asc
Description: Digital signature


Reply to: