1

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

1

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

1

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

1

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
-1
$ 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

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.