Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

What should I do if print fails to interpret backslash and java exclamation mark?

Asked by Lisa Henderson Oct 10, 2022 1.3K views 1 answer
Share

About this question

I am writing a java program from terminal using printf and redirecting its output to a .java file but printf fails to interpret the horizontal backslash tab (t), and when I have an exclamation mark (!) in the string, it doesn't even print and fails with this error:

bash: !": event not found

How do I force printf to include a horizontal tab?

And how do I include an exclamation without getting the above error?

commandline argument:
$ printf "%sn" "public class {" "tpublic static void main(String[] args) {" "dogBark()" "}" "public static void dogBark() {" "System.out.println("Woof")" "}" "}" > barkingDog.java
output from .java file
$ less barkingDog.java
public class {
public static void main(String[] args) {
dogBark()
}
public static void dogBark() {
System.out.println(Woof)
}
}

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.