4

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?

1
  • you can also quote("ab|cd" or 'ab|cd') the commandline arguments Commented Jun 22, 2012 at 16:53

4 Answers 4

8

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

 java className ab\|cd
Sign up to request clarification or add additional context in comments.

Comments

3

Try (for Linux):

$ java className ab\|cd

For Windows:

java className ab^|cd

Comments

2

Try this,

"\" is used inorder to nullify the effect of the characters which have special meanings.

java className ab\|cd

Comments

-2

Maybe try this:

arg="ab|cd"
java className $arg

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.