[fpc-pascal] Parsing commandline parameters with wildcards on Linux

Bart bartjunk64 at gmail.com
Sun Apr 10 01:34:02 CEST 2011

Hi all,

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 *
1: backup
2: lib
3: scopy
4: scopy.ico
5: scopy.lpi
6: scopy.lpr
7: scopy.res
8: x
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
1: 123
2: 1233
3: 12333
4: 123.bak
5: 123.tmp
6: 456.bak
7: backup
8: lib
9: scopy
10: scopy.ico
11: scopy.lpi
12: scopy.lpr
13: scopy.res
14: x
15: y
16: 123.bak
17: 456.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 mailing list