Re: Yet another "stop the bash quoting" post
From: Allen Kistler (ackistler_at_oohay.moc)
Date: 11/28/04
- Next message: rakesh sharma: "Re: Passing arguments to functions"
- Previous message: Bill Marcum: "Re: how to use sed to replace a single occurrence in a file"
- In reply to: rakesh sharma: "Re: Yet another "stop the bash quoting" post"
- Next in thread: Paul Colquhoun: "Re: Yet another "stop the bash quoting" post"
- Reply: Paul Colquhoun: "Re: Yet another "stop the bash quoting" post"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: rakesh sharma: "Re: Passing arguments to functions"
- Previous message: Bill Marcum: "Re: how to use sed to replace a single occurrence in a file"
- In reply to: rakesh sharma: "Re: Yet another "stop the bash quoting" post"
- Next in thread: Paul Colquhoun: "Re: Yet another "stop the bash quoting" post"
- Reply: Paul Colquhoun: "Re: Yet another "stop the bash quoting" post"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|