I have a problem with the Bash Terminal.

My Problem with details:

And yes, I am aware, that you could do it manual. But it would be a pain, if every user would have to do that by hand. I also tried it with "echo", but it didn't work, like i wanted it to.

I'd also be happy, if you could tell me, how to run a bash file with java. (I could figure out by myself though.)

Basically a color 0a for the linux bash terminal.

If possible, without any special software needed.

Maybe this would help. I cannot execute it though.

PS1="\[\033[34m\][\$(date +%H%M)][\u@\h:\w]$ "

I am able to execute with "exec" commands in the Terminal. Yet, the commands for color ect. do not work, after a ping or before a ping command too. Thank you for your reply!


The solution to my problem is:

public static final String ANSI_RESET = "\u001B[0m";

public static final String ANSI_BLACK = "\u001B[30m";

public static final String ANSI_RED = "\u001B[31m";

public static final String ANSI_GREEN = "\u001B[32m";

public static final String ANSI_YELLOW = "\u001B[33m";

public static final String ANSI_BLUE = "\u001B[34m";

public static final String ANSI_PURPLE = "\u001B[35m";

public static final String ANSI_CYAN = "\u001B[36m";

public static final String ANSI_WHITE = "\u001B[37m";


First you declare the color above. Then, you write:

System.out.println(ANSI_RED + "hello World");

Then you run your program and your good.

Originally from: https://stackoverflow.com/questions/5923436/change-color-of-java-console-output



You can run a shell script via Java pretty easily:


This will work as long as the shell script is not interactive (and in an applicable path). Things get weird when it's interactive, and you'd have to use Process Builder for that.

  • I am able to do that, but not the color changing. A person recommended to me, that a seperate sh file would be better. – HelpMeWithLinux Sep 23 '16 at 9:31

I believe this should work ( you need to escape the escape sequences as well - so they get carried through and java doesn't expand them ):

 p = Runtime.getRuntime().exec("/bin/bash -c 'echo -ne \"\\e[40m\\e[32m\"; ping " + b + "; echo -ne \"\\e[0m\"'");
  • It failed to compile 5 errors – HelpMeWithLinux Sep 23 '16 at 12:22
  • i had some errors with quotes with it before – Marek Rost Sep 23 '16 at 12:23
  • I am supposed, to put this into my Java code correct? – HelpMeWithLinux Sep 23 '16 at 12:25
  • yes - also don't forget that default behavior of ping is to continue forever - it might be good idea to add parameter -c <number> to it – Marek Rost Sep 23 '16 at 12:27
  • Oh! right thank you. (It doesn't compile though) – HelpMeWithLinux Sep 23 '16 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.