wildcard - The issue of * in Command line argument -


i wrote program in java accepts input via command line arguments. input of 2 numbers , operator command line. multiply 2 numbers, have give input e.g. 5 3 *, it's not working written.

why not accepting * command line?

that's because * shell wildcard: has special meaning shell, expands before passing on command (in case, java).

since need literal *, need escape shell. exact way of escaping varies depending on shell, can try:

java programname 5 3 "*" 

or:

java programname 5 3 \* 

by way, if want know shell *, try printing content of string[] args main method. you'll find contain names of files in directory.

this can handy if need pass filenames command line arguments.

see also

  • wikipedia: glob

    for example, if directory contains 2 files, a.log , b.log command cat *.log expanded shell cat a.log b.log

  • wikipedia: escape character

    in bourne shell (sh), asterisk (*) , question mark (?) characters wildcard characters expanded via globbing. without preceding escape character, * expand names of files in working directory don't start period if , if there such files, otherwise * remains unexpanded. refer file literally called "*", shell must told not interpret in way, preceding backslash (\).


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -