Re: Question - reading command line parms inside a script.

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 03/11/04


Date: 11 Mar 2004 00:11:37 GMT

On Thu, 11 Mar 2004 at 00:05 GMT, Nick Landsberg wrote:
> Chris F.A. Johnson wrote:
>> On Wed, 10 Mar 2004 at 19:33 GMT, Ken Andrews wrote:
>> [snip]
>>
>>
>>>Inside the script, I need the following parms (or any possible
>>>permutation, sequence is variable):
>>>
>>>1) a
>>>2) b
>>>3) "C"
>>>4) -f="d"
>>>
>>>The nearest solution I've found is using a line like:
>>>
>>>y.y a b \"C\" -f=\"d\"
>>>
>>>but it's a suboptimal result as it requires modifying several hundred
>>>scripts. The objective is to use the original lines as written in the
>>>scripts, and build a new script that intercepts the given command and
>>>receives the command-line parms exactly as written.
>>
>>
>> Unless you quote the quotes, your program CANNOT see them. If you
>> have a program that expects to see them without having them
>> escaped, you need to fix that program, it's broken.
>>
>> If you have scripts that expect to pass quotes without escaping
>> them, they are broken and need to be fixed.
>>
>>
>
> Correct on point one. The shell (whatever shell) uses
> escapes to determine whether to interpret the argument
> as a shell directive or an argument to pass to the
> program. It strips off the escapes. An additional problem
> is that there is usually more than one form of escape.
>
> The following illustrates that:
>
> MyMachine% cat xxx
> echo $@
>
> MyMachine% sh xxx a "<" b
> a < b
>
> MyMachine% sh xxx a \< b
> a < b
>
> so any scheme to preserve the escapes would have to
> emulate the shell's escape processing and then
> put the original argument strings back the way
> they were.
>
> As to the second point. I believe the original poster
> has a need to somehow convert the scripts, thus needs
> the original strings as written, rather than the
> scripts being broken.

    If he's converting scripts (i.e., reading the strings from a
    file), then there's no need to do anything; the quotes will not be
    stripped (unless he's using eval).

    His problem is preserving them on the command line; that requires
    escaping.

> This may be possible in awk (altho I'm not sure) but
> it almost seems like a c-program would have to be built
> to do the complete job.

    Before we can diagnose the OP's problem any further, we need to
    know more about what he's doing, and what the problem is exactly.

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: rename statement in script
    ... >> and mv will look for files with quotes in their names. ... >> It will not work for renaming directories, ... My code in this post is copyright 2003, Chris F.A. Johnson ...
    (comp.os.linux.misc)
  • Re: problem with spaces in quoted string arguments
    ... are in double quotes. ... As can be seen in the output, the server called "photon hub" did not ... Chris F.A. Johnson, author ...
    (comp.unix.shell)
  • A critique of cgi.escape
    ... The ones that need escaping are '<', ... cgi.escape only escapes the quote character if you pass a second ... Nevertheless, even in that situation, escaped quotes are acceptable. ...
    (comp.lang.python)
  • Re: wildcards in scripts
    ... > tried quotes, both single & double and it didn't work. ... My code in this post is copyright 2005, Chris F.A. Johnson and may be copied under the terms of the GNU General Public License ...
    (comp.unix.shell)
  • Re: [PHP] htmlentities() does not remove escape
    ... entities to change these characters into html entities. ... But the function does not remove the escapes added ... Browser doesn't escape those quotes. ... You're PHP configuration has magic ...
    (php.general)