#1
  1. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12

    * 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 + -
    results in:
    -10

    ./a.out 1 2 - 4 5 + *
    results in:
    error: unknown command a
    error: unknown command o
    error: unknown command t
    error: unknown command c
    error: unknown command l
    9

    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 08:58 AM.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,183
    Rep Power
    2222
    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.

    Try:
    ./a.out 1 2 - 4 5 + \*
  4. #3
  5. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    yup, you're right. that got it. thanks.

IMN logo majestic logo threadwatch logo seochat tools logo