How to separate command line args

  • Follow


Hi,

I have a very basic problem. I want to pass multiple arguments to a REXX script via a commandline. 
There is a chance that some arguments contain spaces, so I enclose them in quotes.
Now, I have the following problem:
At least under OS/2 (don't know about Windows versions of REXX), the whole commandline is passed as 
one single string, so:

1.) arg(1) will contain all args (not split into multiple arguments)
2.) arg(2) will contain nothing

If I use PARSE ARG arg1 arg2 arg3 (etc.) then I have the problem that if the arguments contain 
spaces, REXX will care about quotes and split the commandline according to the contained spaces.

Is this a bug or a shortcomming of REXX ? Does anyone have some simple code to handle this ?

Thanks, Lars
0
Reply Lars 2/16/2005 9:41:12 PM

 > At least under OS/2 (don't know about Windows versions of REXX),
 > the whole commandline is passed as one single string

 > Is this a bug or a shortcomming of REXX ? Does anyone have some simple code to handle this ?

/* Not tested, Windows or OS/2 shouldn't really matter */
PARSE ARG args
DO WHILE args<>''
   PARSE VAR args myarg args
   IF Left(myarg,1)='"' THEN DO /* " used?) */
      args=myarg args /* Reconstruct */
      PARSE VAR args '"' myarg '"' args /* Parse between "" */
   END
   SAY 'Found:' myarg
END



---
0
Reply spamgate 2/16/2005 10:07:00 PM


Welcome to the party! I happen to be changing the design behind our standard parm check right now, so I'll provide some sample code. Oh, and this is Object Rexx specific code, so lots of twiddles, and 
[] syntax for stems where I can do it.

Basically, we start the program and grab the args, then pass that to a parmcheck function. Based on how it returns, either the program continues or exits (due to a help screen having been requested, 
bad args, etc...)

/* main */
parse arg args
if \ parmcheck(args) then do
    exit 1
end

So, about this parm checker. I am switching to the "nibble method" where args is cut down over and over, and nothing better be left else the user passed in some trash.

/* parmcheck ideas */
parmcheck: procedure expose ..... bla bla bla
parse arg args

/* OS specific delim char, slash on DOS based, dash on *nix based */
DelimChar='-'

/* Set a var for the copy of Args we will hack up */
TheRest=Args

/* OK here is a chunk that accepts a directory in three different formats, LFN, FTP, or DOS mode */

/***************/
/* Handle DIR1 */
/***************/
/* do this in case there are lots of spaces before the "next arg" in TheRest */
TheRest=TheRest~strip()
/* because we are going to use left(1) to decide what to do and if it were a space, well... */
select
    /* LFN Mode */
    when TheRest~left(1)='"' then do
       parse var TheRest '"'DIR1'"' TheRest
       DIR1mode='DOS'
    end /* when */

    /* FTP Mode */
    when TheRest~left(1)='(' then do
       /* OK that really needs two parse lines else the comas are more critical */
       /* to parse than the () chars... helps spot when one is missing... */
       parse var TheRest '(' DIR1FTP ')' TheRest
       parse var DIR1FTP DIR1FTP.HOST ',' DIR1FTP.USERID ',' DIR1FTP.PASSWD ',' DIR1FTP.DIR ',' DIR1FTP.TYPE
       DIR1FTP.['HOST']=DIR1FTP.['HOST']~strip()
       DIR1FTP.['USERID']=DIR1FTP.['USERID']~strip()
       DIR1FTP.['PASSWD']=DIR1FTP.['PASSWD']~strip()
       DIR1FTP.['DIR']=DIR1FTP.['DIR']~strip()
       DIR1FTP.['TYPE']=DIR1FTP.['TYPE']~strip()
       parse upper var DIR1FTP.TYPE DIR1FTP.TYPE
       DIR1mode='FTP'

       /* Check the FTP args */
       check='HOST USERID PASSWD DIR'
       do c=1 to check~words()
          THIScheck=check~word(c)
          if DIR1FTP.[THIScheck]='' then do
             LOGmsg='DIR1FTP is missing the ' || THIScheck || ' arg, please check program usage for required args'
             LDSLogging~Error(LOGmsg)
             LDSLogging~Logger(LOGmsg)
             return 0
          end
       end /* do */
    end /* when */

    /* DOS Mode */
    otherwise do
       parse var TheRest DIR1 TheRest
       DIR1mode='DOS'
    end /* otherwise */
end /* select DIR1 */

/***************************************************************/
/* Now handle switches, longer switch strings must come first! */
/***************************************************************/
/* I mean this else -s causes -sos to trigger, etc... */


/* OK, now this code snips the simple ones out of TheRest. */
/* By default in this template it supports case insensitive*/
/* arg spotting ex: -DoIt counts as -DOIT and is processed */

/* Handle DoIt mode */
THISarg=DelimChar || 'DOIT'
if TheRest~translate()~pos(THISarg)\=0 then do
    parse caseless var TheRest BP (THISarg) AP
    DOITmode=1
    TheRest=BP AP
end /* if */
else DOITmode=0

/* Fast forward to the end of parmcheck */

/* Check that no extra switches were provided */
TheRest=TheRest~strip()
if TheRest\='' then do
    LOGmsg='Extra unexpected switches found: ' || TheRest
    LDSLogging~Error(LOGmsg)
    LDSLogging~Logger(LOGmsg)
    return 0
end /* Extra Switches Check */

That should be some good ideas for you to tinker with...

-- 
Michael Lueck
Lueck Data Systems

Remove the upper case letters NOSPAM to contact me directly.
0
Reply Michael 2/16/2005 10:26:15 PM

On Wed, 16 Feb 2005 22:41:12 +0100, Lars Erdmann <lars.erdmann@arcor.de> wrote:
<37hsvfF5en2ocU1@individual.net>

>Hi,
>
>I have a very basic problem. I want to pass multiple arguments to a REXX script via a commandline. 
>There is a chance that some arguments contain spaces, so I enclose them in quotes.
>Now, I have the following problem:
>At least under OS/2 (don't know about Windows versions of REXX), the whole commandline is passed as 
>one single string, so:
>
>1.) arg(1) will contain all args (not split into multiple arguments)
>2.) arg(2) will contain nothing
>
>If I use PARSE ARG arg1 arg2 arg3 (etc.) then I have the problem that if the arguments contain 
>spaces, REXX will care about quotes and split the commandline according to the contained spaces.

Are you saying you don't know what parms may be passed to your routine?  I think
that may be the 'shortcoming'.

For many years I have used a skeleton of basic parsing routines as the kernel
for all REXX code I write.  You can find REXXSKEL at
http://web.tampabay.rr.com/mvsrexx/REXX/ where you will also find a write-up
("How to REXXSKEL") on the facility it provides.  Several others have found it
worth their time.


(change Arabic number to Roman numeral to email)
0
Reply Frank 2/16/2005 11:16:22 PM

According to Frank Clarke in a posting to comp.lang.rexx:
>Are you saying you don't know what parms may be passed to your routine?  I think
>that may be the 'shortcoming'.

Consider a spec such as: "This program frobnicates the file(s) named
as arguments to the program."  Many Unix utilities do this, and the
Unix shell makes it easy for you to pass the arguments using a glob
(wildcard filename).

 frobnicate foo.txt bar.txt "My Documents/baz.txt"

You're in trouble here because not only will "parse arg a b c d"* split
the third filename up at the space, but the shell will remove the quotes
before passing it to the interpreter (at least it will if it's a Unix
shell) so it's impossible to parse the arguments correctly.

This is why Regina has the "-a" flag.
--
* Of course you wouldn't do it like that - you'd use a loop - but the
  point still stands.
-- 
---- Ian Collier : imc@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .
0
Reply imc 2/16/2005 11:51:52 PM

In article <27381-Koenigsberg.imc@comlab.ox.ac.uk>, Ian Collier
<imc@comlab.ox.ac.uk> wrote:

>  frobnicate foo.txt bar.txt "My Documents/baz.txt"

> You're in trouble here because not only will "parse arg a b c d"*
> split the third filename up at the space, but the shell will remove
> the quotes before passing it to the interpreter (at least it will if
> it's a Unix shell) so it's impossible to parse the arguments
> correctly.

Taking the last point first, isn't there some way of escaping the
quotes so that the Unix shell passes them over to the program eg using:

  frobnicate foo.txt bar.txt ""My Documents/baz.txt""

or 
    frobnicate foo.txt bar.txt \"My Documents/baz.txt\"

Secondly, surely all one needs to do is to run a loop that looks in the
first instance at the leading token in the string.  If it doesn't start
with " then it is the next argument, but if it does you read the whole
string up to the next quote?

-- 
Jeremy C B Nicoll - my opinions are my own.
0
Reply Jeremy 2/17/2005 12:47:49 AM

In article <4d3e60b50cJeremy@omba.demon.co.uk>,
Jeremy C B Nicoll  <Jeremy@omba.demon.co.uk> wrote:

% Taking the last point first, isn't there some way of escaping the
% quotes so that the Unix shell passes them over to the program eg using:
% 
%   frobnicate foo.txt bar.txt ""My Documents/baz.txt""

So all you need to do as the end user is to know that the application in
question was written in rexx, and so it requires unique quoting of file
names, then find out what quoting convention was used by the application
author.

It's a bit of a failing in the standard calling convention of the
language.
-- 

Patrick TJ McPhee
North York  Canada
ptjm@interlog.com
0
Reply ptjm 2/17/2005 3:33:52 AM

In Message-ID:<EQ8EClQNA9/V090yn@hotmai1.com>,
spamgate@hotmai1.com (ML) wrote: 

>
> > At least under OS/2 (don't know about Windows versions of REXX),
> > the whole commandline is passed as one single string
>
> > Is this a bug or a shortcomming of REXX ? Does anyone have some simple code to handle this ?
>
>/* Not tested, Windows or OS/2 shouldn't really matter */
>PARSE ARG args
>DO WHILE args<>''
>   PARSE VAR args myarg args
>   IF Left(myarg,1)='"' THEN DO /* " used?) */
>      args=myarg args /* Reconstruct */
>      PARSE VAR args '"' myarg '"' args /* Parse between "" */
>   END
>   SAY 'Found:' myarg
>END

     Tried using Regina in Win2K.  The REXX code is good, but the
OS has a problem.  (Actually it has two problems with this code.)

1.  I put a SAY ARGS line as line #2.  All quotes were missing.  I
changed the code to use single quotes, and got past that.

2.  All multiple spaces were reduced to a single space, even
within the quotes.

     Here's my modification and some output:

PARSE ARG args
say args
DO WHILE args<>''
   PARSE VAR args myarg args
   IF Left(myarg,1)="'" THEN DO /* ' used?) */
      args=myarg args /* Reconstruct */
      PARSE VAR args "'" myarg "'" args /* Parse between "" */
   END
   SAY 'Found:' || myarg || "-end"
END

F:\>arg2 a b '   c d ' ' e f   '
a b ' c d ' ' e f '
Found:a-end
Found:b-end
Found: c d -end
Found: e f -end

     The routine may work for you depending on the restrictions of
your OS and/or whether you can live with multiple spaces becoming
a single space.


-- 
Arthur T. - ar23hur "at" speakeasy "dot" net
Looking for a good MVS systems programmer position
0
Reply Arthur 2/17/2005 3:47:18 AM

With Regina:

regina -a myprog.rex arg1 "arg2 with  2  spaces " arg3
/* myprog.rex */
Do i = 1 To Arg()
  Say 'Arg' i 'is' '['Arg(i)']'
End

Results in:

Arg 1 is [arg1]
Arg 2 is [arg2 with  2  spaces ]
Arg 3 is [arg3]

Cheers, Mark.

Arthur T. wrote:
> In Message-ID:<EQ8EClQNA9/V090yn@hotmai1.com>,
> spamgate@hotmai1.com (ML) wrote:
>
> >
> > > At least under OS/2 (don't know about Windows versions of REXX),
> > > the whole commandline is passed as one single string
> >
> > > Is this a bug or a shortcomming of REXX ? Does anyone have some
simple code to handle this ?
> >
> >/* Not tested, Windows or OS/2 shouldn't really matter */
> >PARSE ARG args
> >DO WHILE args<>''
> >   PARSE VAR args myarg args
> >   IF Left(myarg,1)='"' THEN DO /* " used?) */
> >      args=myarg args /* Reconstruct */
> >      PARSE VAR args '"' myarg '"' args /* Parse between "" */
> >   END
> >   SAY 'Found:' myarg
> >END
>
>      Tried using Regina in Win2K.  The REXX code is good, but the
> OS has a problem.  (Actually it has two problems with this code.)
>
> 1.  I put a SAY ARGS line as line #2.  All quotes were missing.  I
> changed the code to use single quotes, and got past that.
>
> 2.  All multiple spaces were reduced to a single space, even
> within the quotes.
>
>      Here's my modification and some output:
>
> PARSE ARG args
> say args
> DO WHILE args<>''
>    PARSE VAR args myarg args
>    IF Left(myarg,1)="'" THEN DO /* ' used?) */
>       args=myarg args /* Reconstruct */
>       PARSE VAR args "'" myarg "'" args /* Parse between "" */
>    END
>    SAY 'Found:' || myarg || "-end"
> END
>
> F:\>arg2 a b '   c d ' ' e f   '
> a b ' c d ' ' e f '
> Found:a-end
> Found:b-end
> Found: c d -end
> Found: e f -end
>
>      The routine may work for you depending on the restrictions of
> your OS and/or whether you can live with multiple spaces becoming
> a single space.
>
>
> --
> Arthur T. - ar23hur "at" speakeasy "dot" net
> Looking for a good MVS systems programmer position

0
Reply markh 2/17/2005 4:32:12 AM

In <37ihl0F5c2um6U2@uni-berlin.de>, on 02/17/2005
   at 03:33 AM, ptjm@interlog.com (Patrick TJ McPhee) said:

>So all you need to do as the end user is to know that the application
>in question was written in rexx, and so it requires unique quoting of
>file names, then find out what quoting convention was used by the
>application author.

No. You need to know that your shell mucks with command line
arguments, and how to bypass that. It has nothing to do with REXX.

>It's a bit of a failing in the standard calling convention of the
>language.

It has nothing to do with the calling conventions of the language;
it's a generic Unix issue. You'd have the same problem in C or Perl.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 2/17/2005 5:37:26 AM

 > The routine may work for you depending on the restrictions of
 > your OS and/or whether you can live with multiple spaces
 > becoming a single space.
 
Original routine, ||'-end' added, OS/2 (O)REXX mentioned as environment
and using your args with "'s:

[C:\]args a b "   c d " " e f   "
Found: a-end
Found: b-end
Found:    c d -end
Found:  e f   -end

How many REXX programmers does it take to answer a simple
question? :-)



---
0
Reply spamgate 2/17/2005 7:28:09 AM

Shmuel (Seymour J.) Metz wrote:
> In <37ihl0F5c2um6U2@uni-berlin.de>, on 02/17/2005
>    at 03:33 AM, ptjm@interlog.com (Patrick TJ McPhee) said:
>
> >So all you need to do as the end user is to know that the
application
> >in question was written in rexx, and so it requires unique quoting
of
> >file names, then find out what quoting convention was used by the
> >application author.
>
> No. You need to know that your shell mucks with command line
> arguments, and how to bypass that. It has nothing to do with REXX.
>
> >It's a bit of a failing in the standard calling convention of the
> >language.
>
> It has nothing to do with the calling conventions of the language;
> it's a generic Unix issue. You'd have the same problem in C or Perl.

It has everything to do with how the application deals with the command
line parameters.
If you have a C program and pass: arg1 "arg2 with spaces" arg3 on the
command line to a C program,
then argv[1] = "arg1"
argv[2] = "arg2 with spaces"
argv[3] = "arg3"
(the quotes are not passed in)

In Rexx by default you get:
Arg(1) = "arg1 arg2 with spaces arg3"

The interpreter (if written in C or C++) specifically converts the
individual C arguments above into a single argument with a single space
between each argument.

Cheers, Mark.

>
> --
> Shmuel (Seymour J.) Metz, SysProg and JOAT
<http://patriot.net/~shmuel>
>
> Unsolicited bulk E-mail subject to legal action.  I reserve the
> right to publicly post or ridicule any abusive E-mail.  Reply to
> domain Patriot dot net user shmuel+news to contact me.  Do not
> reply to spamtrap@library.lspace.org

0
Reply markh 2/17/2005 7:55:56 AM

In article <1108626955.975981.282300@g14g2000cwa.googlegroups.com>,
   markh <rexx@users.sourceforge.net> wrote:

> If you have a C program and pass: arg1 "arg2 with spaces" arg3 on the
> command line to a C program,

I think the 'problem' is really more to do with the fact that people
generally didn't issue commands like that in the VM/CMS environment
where REXX was first used.  It's about 20 years since I last used a CMS
system so I can't quite remember the different ways in which things
like this were done, but I do recall that it was normal practice to
place parms in a stack before calling a rexx exec, which removed all of
this sort of problem. 

Also, under TSO, the standard way to pass parameters to a TSO command
processor allows you to work with positional parms (ie 1st/2nd/3rd
word) and keyword ones, ie those with an associated name.
The syntax there is name(values inside the brackets), eg:

  TSO %exec this that other cat(miaow miaow) dog(woof woof woof)

A programmer writing a rexx exec (or in any other language for TSO)
would choose that sort of parameter if space-delimited strings were
likely to need passed to clist, or PL/I or assembler or COBOL or ...
rexx.  The unix command-line is quite different, not least because of
the way that a shell gets a first look at a command and is able to
change it.

-- 
Jeremy C B Nicoll - my opinions are my own.
0
Reply Jeremy 2/17/2005 2:23:14 PM

Shmuel (Seymour J.) Metz entertained comp.lang.rexx with the following
story:
[talking about program parameters that may or may not be quoted or
have spaces in, and the way that the Unix shell parses your input
before passing it to the program]
>No. You need to know that your shell mucks with command line
>arguments, and how to bypass that. It has nothing to do with REXX.

>It has nothing to do with the calling conventions of the language;
>it's a generic Unix issue. You'd have the same problem in C or Perl.

You don't have the same problem in most other languages (including C and
Perl), or in Regina if you pass the "-a" flag.  In these cases you get
the arguments sliced and diced into an array.

Rexx is a problem because the standard insists that you only get one
argument string [or none at all], so the interpreter has to concatenate
the array back into a single string - and that's where the information
about embedded spaces in the arguments gets lost.
-- 
---- Ian Collier : imc@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .
0
Reply imc 2/17/2005 4:24:16 PM

markh schrieb:
> With Regina:
> 
> regina -a myprog.rex arg1 "arg2 with  2  spaces " arg3
> /* myprog.rex */
> Do i = 1 To Arg()
>   Say 'Arg' i 'is' '['Arg(i)']'
> End
> 
> Results in:
> 
> Arg 1 is [arg1]
> Arg 2 is [arg2 with  2  spaces ]
> Arg 3 is [arg3]
> 
> Cheers, Mark.

This certainly won't work in OS/2. The commandline interpreter under OS/2 doesn't have such an 
option "-a".

Lars

> 
> Arthur T. wrote:
> 
>>In Message-ID:<EQ8EClQNA9/V090yn@hotmai1.com>,
>>spamgate@hotmai1.com (ML) wrote:
>>
>>
>>>>At least under OS/2 (don't know about Windows versions of REXX),
>>>>the whole commandline is passed as one single string
>>>
>>>>Is this a bug or a shortcomming of REXX ? Does anyone have some
> 
> simple code to handle this ?
> 
>>>/* Not tested, Windows or OS/2 shouldn't really matter */
>>>PARSE ARG args
>>>DO WHILE args<>''
>>>  PARSE VAR args myarg args
>>>  IF Left(myarg,1)='"' THEN DO /* " used?) */
>>>     args=myarg args /* Reconstruct */
>>>     PARSE VAR args '"' myarg '"' args /* Parse between "" */
>>>  END
>>>  SAY 'Found:' myarg
>>>END
>>
>>     Tried using Regina in Win2K.  The REXX code is good, but the
>>OS has a problem.  (Actually it has two problems with this code.)
>>
>>1.  I put a SAY ARGS line as line #2.  All quotes were missing.  I
>>changed the code to use single quotes, and got past that.
>>
>>2.  All multiple spaces were reduced to a single space, even
>>within the quotes.
>>
>>     Here's my modification and some output:
>>
>>PARSE ARG args
>>say args
>>DO WHILE args<>''
>>   PARSE VAR args myarg args
>>   IF Left(myarg,1)="'" THEN DO /* ' used?) */
>>      args=myarg args /* Reconstruct */
>>      PARSE VAR args "'" myarg "'" args /* Parse between "" */
>>   END
>>   SAY 'Found:' || myarg || "-end"
>>END
>>
>>F:\>arg2 a b '   c d ' ' e f   '
>>a b ' c d ' ' e f '
>>Found:a-end
>>Found:b-end
>>Found: c d -end
>>Found: e f -end
>>
>>     The routine may work for you depending on the restrictions of
>>your OS and/or whether you can live with multiple spaces becoming
>>a single space.
>>
>>
>>--
>>Arthur T. - ar23hur "at" speakeasy "dot" net
>>Looking for a good MVS systems programmer position
> 
> 
0
Reply Lars 2/17/2005 7:08:21 PM

I take the complete opposite approach when dealing with OS/2 and Windows 
command lines. I parse them into an array the same way that C does. Here 
is my code.

/* parse the command line arguments into a .array similar to the way C 
does */
cmdLine = arg(1)
cmdArgs = .array~new
i = 1
do while cmdLine~length() > 0
    if cmdLine~left(1) = '"' then do
       parse var cmdLine '"' argument '"' cmdLine
       end
    else if cmdLine~left(1) = '{' then do
       parse var cmdLine '{' argument '}' cmdLine
       argument = '{' || argument || '}'
       end
    else do
       parse var cmdLine argument cmdLine
       end
    cmdArgs[i] = argument
    i = i + 1
    end

I hope you find this useful.

W. David Ashley
Open Object Rexx Team
0
Reply David 2/17/2005 7:36:56 PM

In <27383-terrify.imc@comlab.ox.ac.uk>, on 02/17/2005
   at 04:24 PM, imc@comlab.ox.ac.uk (Ian Collier) said:

>You don't have the same problem in most other languages (including C
>and Perl),

Are you a betting man? Specifically, how much are you willing to bet
that I don't have the same problem with Perl?

>In these cases you get the arguments sliced and diced into an array.

No. You get the results of the shells meddling, sliced and diced into
an array. If you  want the shell to keep it's mitts off, then you have
to type other grunge to escape its unwanted processing.

>Rexx is a problem because the standard insists that you only get one
>argument string [or none at all], so the interpreter has to
>concatenate the array back into a single string - and that's where
>the information about embedded spaces in the arguments gets lost.

Only between tokens[1][2], unless the shell has already discarded
spaces embedded within tokens. Those spaces are lost regardless of the
language.

[1] Counting a quoted string as a single token.

[2] Not even then if the shell provides access to the original
    command text.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 2/20/2005 12:16:42 AM

In a previous episode of comp.lang.rexx, Shmuel (Seymour J.) Metz was
heard to say:
>   at 04:24 PM, imc@comlab.ox.ac.uk (Ian Collier) said:
>>You don't have the same problem in most other languages (including C
>>and Perl),

>Are you a betting man? Specifically, how much are you willing to bet
>that I don't have the same problem with Perl?

The problem I was talking about when I originally introduced the subject
with the example:

 frobnicate foo.txt bar.txt "My Documents/baz.txt"

is not a problem you have in Perl.  You may have other problems with
what the shell does to your input, but any experienced user of a Unix
shell knows this and quotes the arguments as necessary to achieve the
desired result.  It's part of the Unix philosophy (which is not to say
it is a better philosophy, but it's been that way for 30 years and Unix
people generally understand it).

>>Rexx is a problem because the standard insists that you only get one
>>argument string [or none at all], so the interpreter has to
>>concatenate the array back into a single string - and that's where
>>the information about embedded spaces in the arguments gets lost.
>
>Only between tokens[1][2], unless the shell has already discarded
>spaces embedded within tokens. Those spaces are lost regardless of the
>language.

True, but the point is that Rexx loses the distinction between intra-token
spaces and inter-token spaces.

>[1] Counting a quoted string as a single token.
>[2] Not even then if the shell provides access to the original
>    command text.

I don't know of a standard Unix shell which does.
-- 
---- Ian Collier : imc@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .
0
Reply imc 2/20/2005 7:07:47 PM

Hi,

thanks a lot ! That did the trick. Very neat code. I'll keep this around :-)

Lars

ML schrieb:
>  > At least under OS/2 (don't know about Windows versions of REXX),
>  > the whole commandline is passed as one single string
> 
>  > Is this a bug or a shortcomming of REXX ? Does anyone have some simple code to handle this ?
> 
> /* Not tested, Windows or OS/2 shouldn't really matter */
> PARSE ARG args
> DO WHILE args<>''
>    PARSE VAR args myarg args
>    IF Left(myarg,1)='"' THEN DO /* " used?) */
>       args=myarg args /* Reconstruct */
>       PARSE VAR args '"' myarg '"' args /* Parse between "" */
>    END
>    SAY 'Found:' myarg
> END
> 
> 
> 
> ---
0
Reply Lars 2/20/2005 10:41:55 PM

In <27402-puritanic.imc@comlab.ox.ac.uk>, on 02/20/2005
   at 07:07 PM, imc@comlab.ox.ac.uk (Ian Collier) said:

>True, but the point is that Rexx loses the distinction between
>intra-token spaces and inter-token spaces.

So does Perl, unless you're talking about Unix token rules.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 2/20/2005 11:30:27 PM

Probably Shmuel (Seymour J.) Metz typed into a real computer:
>   at 07:07 PM, imc@comlab.ox.ac.uk (Ian Collier) said:
>>True, but the point is that Rexx loses the distinction between
>>intra-token spaces and inter-token spaces.

>So does Perl, unless you're talking about Unix token rules.

I am.  And the distinction in Perl (and most other languages) is that
an inter-token space ends the current argument and moves on to the next,
while intra-token spaces are preserved literally in the argument strings.
-- 
---- Ian Collier : imc@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .
0
Reply imc 2/21/2005 12:15:06 PM

In <27404-transgressor.imc@comlab.ox.ac.uk>, on 02/21/2005
   at 12:15 PM, imc@comlab.ox.ac.uk (Ian Collier) said:

>I am.  And the distinction in Perl (and most other languages)

ITYM languages in the Unix tradition. It certainly isn't true for
languages developed independently of Unix. REXX was developed for
operating systems that are not in the Unix traditions and that, in
fact, predate Unix. There's no reason to cripple it just to be
consistent with Unix.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 2/21/2005 6:19:33 PM

21 Replies
336 Views

(page loaded in 0.158 seconds)

Similiar Articles:


















7/19/2012 6:50:00 PM


Reply: