简体   繁体   中英

Argument separation in bash/command prompt

the other day I ran the following piece of code on the windows cmd :

$java -cp . myProgram > output.txt

I could do the same in unix bash.

My question is the following:

  • How is it that > and output.txt are not passed as an argument to myProgram ?

  • What if I wanted my program to receive > as an argument?

The metacharacter > is processed by the shell, and this character and the following filename are not included in the arguments when running the program. If you want it to be passed literally to the program, you need to quote it.

java -cp . myProgram ">" output.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM