[fpc-pascal] Parsing commandline parameters with wildcards on Linux
bartjunk64 at gmail.com
Sun Apr 10 01:34:02 CEST 2011
I ran into a problem with resolving commandline parameters, due to
wildcard expansion by bash.
Consider the following code:
for i := 1 to paramcount do writeln(i,': ',paramstr(i));
My program expects input from the commandline in the form
scopy source dest
when you now specify wildcards on the commandline, they will be
expanded by bash, so the output will be like this:
bart at simenon:~/LazarusProjecten/ConsoleProjecten/scopy> ./scopy *
bart at simenon:~/LazarusProjecten/ConsoleProjecten/scopy>
However from inside my program I cannot distinguish between the
followin 2 scenarios:
1: x is the last item in the list expanded by bash or
2: the commandline actually was "scopy * x"
Scenario 1 is a syntax error, and it should not be treated as if it
were scenario 2.
Things get even more confusing when i use a syntax like
scopy source dest excludefilter
bart at simenon:~/LazarusProjecten/ConsoleProjecten/scopy> ./scopy * y *.bak
Obviously this is a common scenario on Linux, so how to treat it?
I would prefer to expand the wildcards by myself, but it seems I have
no access to what the user actually typed on the commandline?
More information about the fpc-pascal