Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When i write scripts i want that some lines are colored in output. My questions is not about changing prompt (PS1) but for example how can i change that the output, let us say, "cat /var/run/reboot-required.pkgs" would be in red, for example.

Thx for answers

share|improve this question

4 Answers 4

$ cat .PS1 
   BLACK="\[\033[00;30m\]"
     RED="\[\033[00;31m\]"
   GREEN="\[\033[00;32m\]"
  YELLOW="\[\033[00;33m\]"
    BLUE="\[\033[00;34m\]"
 MAGENTA="\[\033[00;35m\]"
    CYAN="\[\033[00;36m\]"
   WHITE="\[\033[00;37m\]"

  BLACKb="\[\033[01;30m\]"
    REDb="\[\033[01;31m\]"
  GREENb="\[\033[01;32m\]"
 YELLOWb="\[\033[01;33m\]"
   BLUEb="\[\033[01;34m\]"
MAGENTAb="\[\033[01;35m\]"
   CYANb="\[\033[01;36m\]"
  WHITEb="\[\033[01;37m\]"

   BLANK="\[\033[00;00m\]"

export PS1="\w\n \[\033[01;32m\]rap\[\033[01;34m\] \W \$\[\033[00m\]"
export PS1="$BLACKb\h: $GREEN\w\n$BLACKb\$ $BLANK"

quick demo:

COLARZ

share|improve this answer

To sum up what tibike and enzotib said, to print some output in color - for example have the output of cat /var/run/reboot-required.pkgs be in red you can use this set of commands:

tput setaf 1; cat /var/run/reboot-required.pkgs; tput sgr0
share|improve this answer

Here are some tips:

http://linuxtidbits.wordpress.com/2008/08/13/output-color-on-bash-scripts-advanced/

You can change the output with: {ESC}[{attr};{bg};{256colors};{fg}m

Search for scripting tutorials for more details

share|improve this answer

This may help: How can I print text in various colors?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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