Re: Yet another "stop the bash quoting" post

From: Allen Kistler (ackistler_at_oohay.moc)
Date: 11/28/04


Date: Sun, 28 Nov 2004 19:48:22 GMT

rakesh sharma wrote:
>
> Try this:
>
> ##### file1.sh ####
> #!/bin/bash -u
> CMD="./zxc.sh \"-o'a b'\""
> echo "\$CMD=|$CMD|"
> eval "
> set -x
> $CMD
> set +x
> "
> ######### end of file1.sh ##########
>
> ####### zxc.sh ########
> echo "Inside the file... '$0'"
> for arg
> do
> echo "arg=|$arg|"
> done
> ############ end of zxc.sh ###########
>
> Output from running the file1.sh command is:
>
> $CMD=|./zxc.sh "-o'a b'"|
> + ./zxc.sh -o'a b'
> Inside the file... './zxc.sh'
> arg=|-o'a b'|
> + set +x
>
>
>
> Is this what you wanted? But remember that here the argumetnt
> contains the a real single quote.
>
> Even from the command line when you say:
> command -o'a b'
>
> the argument doesn't contain those single quotes; they"re there to protect
> the spaces between a and b & prevent wildcard expansions.
> So I still feel that my previous reply is what you really need.
>
>
> What you see is not what the command sees because the entity shell is
> performing some operations silently/behind the scenes.
>
> command -o'A B'
>
> will entail 'command' being passed only 1 argument
> "-oA B" (double quotes for emphasis not part of the argument)
>
> In the case I showed today, .... ok it prints -o'a b' but the argument
> that 'command' gets from the shell contains those single quotes too.
>
> Unless you intend to do 2/more levels of evaling it's an error.

By using set -x in the bash script and running /command/ without the
eval, I can see that bash sees this as
'"-oa b"'
Assigning it to CMD and using eval, I get
'-o'\''a b'\'''

Unfortunately the binary (sendmail BTW, just to make it real) is still
not recognizing either as a switch, probably because they start with a
quote, not a dash. It interprets, e.g., '-oa b' as a recipient, not an
option. The same problem exists for any binary that takes switches, not
just sendmail, though.

Maybe the better way to pose the problem is:
Is there any way to make bash be satisfied that the quotes around a
space are *not* the outermost characters in a string.
-o'a b' still has quotes around the space, after all, which is probably
why it works fine on the command line.



Relevant Pages

  • Re: confused with BASH shell in Redhat
    ... It is not a matter of bash. ... the "-" for the cd command built into tcsh, ... not a marker for a switch. ... the command that hyphens following it are text ...
    (comp.os.linux.networking)
  • Re: confused with BASH shell in Redhat
    ... It is not a matter of bash. ... the "-" for the cd command built into tcsh, ... not a marker for a switch. ... the command that hyphens following it are text ...
    (alt.os.linux)
  • Parsing a bash string?
    ... For my application, which is a wrapper over bash, ... I have to be able to parse a command line typed by the user. ... I.e., I need a function that, when given a typical bash command string like ... I have to remove the quotes (notice the last ...
    (comp.unix.shell)
  • Re: [SLE] bash Script Using Filenames with Embedded Spaces
    ... If it is a literal space for the ls command, ... wonder what effect the quotes will have placed in different places ... Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings College ...
    (SuSE)
  • Re: [SLE] bash Script Using Filenames with Embedded Spaces
    ... If it is a literal space for the ls command, ... wonder what effect the quotes will have placed in different places ... Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings College ...
    (SuSE)