* at linux command line

I am making a small calculator in C, and I want to pass simple arithmetic formulas to my program. But I really don't like it when I pass the '*' character to my program. Why not? And how can I get around this without changing the asterisk to something else? Thanks

+5
source share
8 answers

A symbol *is a shell trigger for extending matching file names.

There are several ways to handle this:

  • Enter Escape mycalc 5 \* 3
  • Put the whole expression in quotation marks and make sure that the calculator parser works like this: myprog "5 * 3"
  • Do not use the command line: use your own input instead.
+9
source

* , ( "globbing" ). * .

+7

* globbing , . * ,

./yourprogram '10 * 10'

./yourprogram 10 '*' 10

, argv [1] "10 * 10",

+6

Linux (bash, tcsh, ksh, whatever) '*' , . - "x". .

+3

. , . , , :

# For bash
set -o noglob

# For csh/tcsh
set noglob

# Now that noglob is set, you can safely use *
calc 3 * 3
+2

* " " bash. , . - , .

+1

"calc", deb- apt-get install calc, 3 * 3, 3 * 3

0

, C

* \*

-1
source

All Articles