Hi all,
In a couple of Rexx scripts which I have written to use with Regina
under Linux, I am using the SysFileTree() function supplied by the Regutil
library.
Much to my dismay, it appears necessary to enclose in quotation marks a
filename mask passed to this function on the command line. For example:
#!/usr/bin/regina
call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs'
call sysloadfuncs
parse arg cmd_line_filemask
call SysFileTree cmd_line_filemask, 'filesfound.', 'fo'
say filesfound.0 'files found'
return
If you run this script in a given directory and you supply the filemask
*.* on the command line, it will return "0 files found" no matter how many
files it contains. However, if you supply as parameter "*.*", then it
returns the correct number of files. It seems impossible to circumvent
this behaviour, such as adding:
cmd_line_filemask = '"' || cmd_line_filemask || '"'
after the parse clause.
IIRC, quotation marks are not necessary with Rexx under OS/2. Is this an
anomaly of Linux, Regina, or Regutil?
Thanks for your time.
|
|
0
|
|
|
|
Reply
|
Colin
|
11/22/2004 3:01:12 AM |
|
"Colin" <cb@lim.nl> wrote in message
news:pan.2004.11.21.17.23.13.13923@lim.nl...
> Hi all,
>
> In a couple of Rexx scripts which I have written to use
> with Regina under Linux, I am using the SysFileTree()
> function supplied by the Regutil library.
>
> Much to my dismay, it appears necessary to enclose in
> quotation marks a filename mask passed to this function on
> the command line. For example:
>
> #!/usr/bin/regina
> call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs'
> call sysloadfuncs
> parse arg cmd_line_filemask
> call SysFileTree cmd_line_filemask, 'filesfound.', 'fo'
> say filesfound.0 'files found'
> return
>
> If you run this script in a given directory and you supply
> the filemask *.* on the command line, it will return "0 files found"
> no matter how many files it contains. However, if you supply
> as parameter "*.*", then it returns the correct number of files.
> It seems impossible to circumvent this behaviour, such as adding:
>
> cmd_line_filemask = '"' || cmd_line_filemask || '"'
>
> after the parse clause.
>
> IIRC, quotation marks are not necessary with Rexx under OS/2.
> Is this an anomaly of Linux, Regina, or Regutil?
>
No, it's a UNIX shell-related [Bourne, bash and similar] matter. Assuming
the current [or working] directory contains three regular files:
a.txt
b.txt
c.txt
then invoking your REXX procedure as follows:
./myProc *.*
sees the file mask expanded by the shell, so in fact your command line
consists of the following:
./myProc a.txt b.txt c.txt
To prevent this automatic shell expansion enclose the file mask in either
single or double quotes, though single quotes are preferred where the
intention is to ensure the argument is interpreted literally:
./myProc '*.*'
All perfectly normal behaviour under UNIX :) !
I hope this helps.
Anthony Borla
P.S.
You can quickly observe this behaviour by issuing the following commands:
echo '*.*'
echo "*.*"
echo *.*
at the shell prompt and observing the differences.
P.P.S.
On a related matter, you may consider invoking the interpreter using the
'-a' switch, as follows:
#!/usr/bin/regina -a
thus ensuring that if two or more arguments are passed on the command-line
that your procedure will recognise them as separate arguments.
|
|
0
|
|
|
|
Reply
|
Anthony
|
11/22/2004 5:49:20 AM
|
|
> parse arg cmd_line_filemask
> IIRC, quotation marks are not necessary with Rexx under OS/2.
> Is this an anomaly of Linux, Regina, or Regutil?
It's often an anomaly of OS/2 too, if you enter a HPFS filemask like
"This contains spaces.txt".
---
|
|
0
|
|
|
|
Reply
|
spamgate
|
11/22/2004 9:53:37 AM
|
|
On Mon, 22 Nov 2004 05:49:20 +0000, Anthony Borla wrote:
> You can quickly observe this behaviour by issuing the following commands:
>
> echo '*.*'
> echo "*.*"
> echo *.*
Thanks very much for the helpful explanation. Now I understand
that one needs the quotes to pass the filemask as a literal to
SysFileTree().
I suppose that if one didn't need all the functionality
of SysFileTree() one could dispense with it and just read the filenames
one by one as expanded from the command line by the shell. Food for
thought!
|
|
0
|
|
|
|
Reply
|
Colin
|
11/23/2004 3:12:06 PM
|
|
"Colin" <cb@lim.nl> wrote in message
news:pan.2004.11.23.15.00.50.33945@lim.nl...
> On Mon, 22 Nov 2004 05:49:20 +0000, Anthony Borla wrote:
>
> > You can quickly observe this behaviour by issuing the following
commands:
> >
> > echo '*.*'
> > echo "*.*"
> > echo *.*
>
> Thanks very much for the helpful explanation. Now I
> understand that one needs the quotes to pass the filemask
> as a literal to SysFileTree().
>
It's all too easy to make assumptions [based on previous experience] about
things like interactive environment [i.e. command shell] behaviour on other
platforms [a trap I've fallen into many times :)]. Some study of the target
platform before porting code might go some way in minimising this tendency,
though is probably easier said than done !
>
> I suppose that if one didn't need all the functionality
> of SysFileTree() one could dispense with it and just
> read the filenames one by one as expanded from the
> command line by the shell. Food for thought!
>
You're probably better off sticking to your current design. Having your code
rely on the behaviour of an external entity like the command shell will make
your code system-specific [and in this case, command shell-specific], and,
it would seem in this case, needlessly so.
Besides, you may want to use your newly-written code on non-UNIX systems in
future: why make it harder to do so ?
Cheers,
Anthony Borla
|
|
0
|
|
|
|
Reply
|
Anthony
|
11/23/2004 11:52:24 PM
|
|
|
4 Replies
301 Views
(page loaded in 0.111 seconds)
|