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

Re: [Xen-devel] [PATCH OSSTEST] standalone: Log things we are running via with_logging



On Thu, 2015-12-03 at 16:41 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST] standalone: Log things we are
> running via with_logging"):
> > Turning on set -x is too verbose, so just echo the command ourselves.
> 
> It's not clear to me from the context whether $@ might contain things
> which would require quoting.

It's stuff which is able to be run on the next line with:
    "$@" 2>&1 | tee "$log"
But I'm not sure that answers your question.

Are you worried about things being incorrectly expanded in the evaluation
of the echo, or just about being able to cut and paste a command directly
from this output into a shell? (or something else).

FWIW $@ is unlikely any $vars at this point or to contain spaces, quotes or
other special characters, although it's not totally impossible (it would
require job names, or idents, or ts-script arguments etc with such in
them).

> ÂÂset -x would quote them.
> 
> You can perhaps do something like this
> ÂÂÂbash -xc ': standalone-runs "$@"' x "$@" >&2
> ?ÂÂ(Sadly -n suppresses output from -x too.)

Sadly it also spews the contents of my .bashrc too. Weirdly (?) adding --
norc _and_ --noprofile to the mix doesn't change that, which seems rather
contrary to the manpage.

Invoking as sh instead produces unquoted results:

$ sh -xc ': standalone-runs "$@"' x "foo" "bar bar"
+ : standalone-runs foo bar bar

(this must be difference between bash and POSIX?)

This seems to work:

$ bash -c 'set -x ; : standalone-runs: "$@"' x "foo" "bar bar"
+ : standalone-runs: foo 'bar bar'

And this: (set -x ; : "$@") also looks to DTRT:

$ foo() { (set -x ; : "$@") }
$ foo "foo" "bar bar"
+ : foo 'bar bar'

coreutils' printf(1) also has %q, but it's a bit ugly to use and is
backslashy rather than quoting :
$ printf "%q " "foo bar" "baz" ; echo
foo\ bar bazÂ

This is a tricky thing to search for (you mostly just get stuff about
regular variable quoting).

Closest thing I found to a solution was:
http://stackoverflow.com/questions/12985178/bash-quoted-array-expansion


Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.