Fixing bash script bogosity - help?

Martin Langhoff martin.langhoff at
Mon Apr 27 16:37:47 EDT 2009

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
#!/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 -
$ ./ ./ "this is file one" "this is file two"
# the ugly workaround is
./ "'this is file one'" "'this is file two'"

Any hints that don't involve a rewrite?


 martin.langhoff at
 martin at -- School Server Architect
 - ask interesting questions
 - don't get distracted with shiny stuff  - working code first
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ejabberdctl
Type: application/octet-stream
Size: 5226 bytes
Desc: not available
URL: <>

More information about the Devel mailing list