I've got a command-line script that needs to run on multiple platforms, specifically Windows (both with and without Cygwin) and Un*x. The script takes a list of files and does some munging on them:
munge.pl a.txt b.txt c.txt
The issue arises when I process command-line args that contain wildcards:
munge.pl *.txt *.xml
bash seems to expand the wildcards into matching filenames before passing them to the perl script, whereas Windows just passes the arguments with wildcards intact.
Since I'd like behavior to be consistent (DWIM!) on both platforms, I experimented with using this code at the beginning of my script:
push @files, glob($_) foreach @ARGV;
This appears to have the desired effect: on Windows it forces the wildcards to expand, and on Cygwin/Linux it doesn't change anything because the wildcards have already been expanded.
My question for the wise folks here in the Monastery is: Is this a reasonably safe approach? Or have I opened myself up to sneaky problems I haven't thought about? Are there better ways to accomplish this task? (Search here didn't turn up much, but maybe I'm not asking the question in the right way...)
In reply to portable globbing behavior for command-line tool by seattlejohn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |