[Server-devel] Fixing bash script bogosity - help?
Sean DALY
sdaly.be at gmail.com
Mon Apr 27 17:44:01 EDT 2009
I'm no maven, but the last time I was dealing with quoting issues with
"$*" expansion I had found this article helpful:
http://www.ibm.com/developerworks/library/l-bash-parameters.html?ca=drs-
Sean
On Mon, Apr 27, 2009 at 10:37 PM, Martin Langhoff
<martin.langhoff at gmail.com> wrote:
> Hi all,
>
> I have a simple shell scripting problem :-) you'll find attached a
> shell script that ships with ejabberd. It is a fairly straightforward
> bit of code, and allows us to control bits of the ejabberd internals
> with a nice cli interface. (Feel free to skip the start / stop bits of
> the code, I'm fighting with the ctrl function.)
>
> The problem it has is that the parameters are passed to a bash or
> runas invocation -- at which point the quoting is a mess. Currently I
> am working around it in the caller by doing some stupid
> nested-quoting. But this should be easy to cure -- if anyone knows a
> bit more bash (or portable shell!) than me :-)
>
> A minimal exposition of the problem is as follows:
>
> $ cat sample.sh
> #!/bin/bash -x
>
> # in the script, the CMD is built up as a string
> CMD="touch $@"
> # in practice we somtimes use /sbin/runuser -c
> # and other times plain bash -c
> bash -c "$CMD"
>
> # this invokation does the wrong thing -
> $ ./sample.sh ./sample.sh "this is file one" "this is file two"
> # the ugly workaround is
> ./sample.sh "'this is file one'" "'this is file two'"
>
> Any hints that don't involve a rewrite?
>
> cheers,
>
>
>
> martin-who's-easily-stumped-with-shell-backwardnesss
> --
> martin.langhoff at gmail.com
> martin at laptop.org -- School Server Architect
> - ask interesting questions
> - don't get distracted with shiny stuff - working code first
> - http://wiki.laptop.org/go/User:Martinlanghoff
>
> _______________________________________________
> Server-devel mailing list
> Server-devel at lists.laptop.org
> http://lists.laptop.org/listinfo/server-devel
>
>
More information about the Server-devel
mailing list