March 31st, 2003, 09:55 AM
* in command line causes havoc
when a * is inputted as one of the arguments in a command line call odd things happen. this is from a command line version of a polish calculator (one of the k&r exercises) :
./a.out 1 2 - 4 5 + -
./a.out 1 2 - 4 5 + *
error: unknown command a
error: unknown command o
error: unknown command t
error: unknown command c
error: unknown command l
one previous not-working version of this code, outputted (that means was part of argv) everyone of the file names in my current directory when * was one of the command line arguments.
why should the * play such havoc? i get the feeling it must be something to do with the environement? that the * as one of the command line arguments is designed to do something i don't know about maybe?
i know it's a wildcard and therefore symbolises 'everything' on it's own but why should this effect anything in my particular situation?
Last edited by balance; March 31st, 2003 at 09:58 AM.
March 31st, 2003, 10:22 AM
It looks like the * is indeed being expanded to a file-list. It will need to be quoted to tell the shell to leave it alone.
./a.out 1 2 - 4 5 + \*
March 31st, 2003, 11:02 AM
yup, you're right. that got it. thanks.