Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

* on the linux command line

Tags:

c

linux

I am making a little calculator in C, and i want to pass simple arithmetic formulae to my program. But it really does not like me passing character '*' to my program. Why not? And how can I work around this without changing the asterix to something else? Thanks

like image 305
Tom Avatar asked Feb 09 '10 19:02

Tom


2 Answers

The character * is the shell's trigger for expanding matching filenames.

There are several ways to deal with it:

  • Escape it when typing mycalc 5 \* 3
  • Place the whole expression in quotes and make sure the calculator's parser works that way: myprog "5 * 3"
  • Don't use the command line: use your own input instead.
like image 100
wallyk Avatar answered Sep 22 '22 14:09

wallyk


* gets expanded to match all files in the current directory (this is called "globbing"). You need to quote or escape the *, or use a different symbol.

like image 35
Paul R Avatar answered Sep 25 '22 14:09

Paul R