Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass commandline argument include "|" to java program

One of the arguments passed to my java program is like this, ab|cd. Initially, when I run the java program, like this,

$ java className ab|cd

it fails, since | is interpreted in the linux shell as a pipe symbol. So only ab is passed into java program. So I made a second attempt:

$ java className "ab|cd"

This time, "ab|cd" is passed in, but the value includes the double quotes. What the program is really intended to have is ab|cd. How can I pass in the correct value without the quotes?

like image 514
Richard Avatar asked Dec 13 '22 01:12

Richard


1 Answers

In the command shell, you can escape out characters using the '\' character.

 java className ab\|cd
like image 60
Steven Mastandrea Avatar answered Jan 01 '23 04:01

Steven Mastandrea