2

I have seen questions about passing arguments with quotes to a shell script (e.g., this question).

My situation is slightly different:

I am passing an argument to my java program from the bash terminal. The number of possible arguments is finite (20, to be precise), and one of them is "alzheimer's". But if I type

java -cp ... myclass --term alzheimer's

this is what I see: enter image description here

.. and then I have to ctrl+C out of it.

Everything works fine if it's a single word with all alphanumeric characters. What should I do for this one case with the apostrophe?

Community
  • 1
  • 1
Chthonic Project
  • 8,216
  • 1
  • 43
  • 92

1 Answers1

5

Quote it; the single apostrophe, when it itself is not quoted, is treated as the beginning of a quoted string. bash is waiting for you to complete the quoted string.

java -cp ... myclass --term "alzheimer's"

or

java -cp ... myclass --term alzheimer\'s
chepner
  • 497,756
  • 71
  • 530
  • 681
  • Gah, thanks! I always escape single quotes (while grepping, for instance), but this time, my mind was calling it "apostrophe", and I never thought of it as a single quote! Now I have to wait for 7 minutes before I can accept this answer. Will this work with non-bash shells? – Chthonic Project May 15 '15 at 21:18