I want to write a bash script that prints some information to the terminal STDOUT. For better readability and structure, I would like to color the different items and highlight them this way.  Now, is there a Bash equivalent to the Windows-CMD/DOS command COLOR which sets the currently used background and font color? And how do I reset the color back to the terminal default after finishing my script?  Edit: I have read , but only some answers are written in Bash so that they can be easily included in my script. Besides this, the answers there lack the following points I want:   change background color display white foreground color, the default color set in gnome-terminal gets displayed instead (which is neon green for me) make all available colors accessible somehow, not only a small subset by keywords. I could imagine e.g. some kind of RGB encoding to pass as function argument for easily specifying a color.
122736
I'm a bit new to bash scripting, and I'm wondering if there is a program or built-in command to pipe to that will print in a specified color? Or is there an echo argument to do so?  Like I could do:  echo Hi | commandhere -arguement blue   and it would print "Hi" in the color blue?
32104
I'm aware of libraries in languages such as Ruby and Javascript to make colorizing your terminal scripts easier by using color names like "red".  But is there something like this for shell scripts in Bash, or Ksh, or whatever?
6109
I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command line, because color makes the output more useful and intuitive.  What options exist to add color to my terminal environment? What tricks do you use? What pitfalls have you encountered?  Unfortunately, support for color varies depending on terminal type, OS, TERM setting, utility, buggy implementations, etc.  Here are some tips from my setup, after a lot of experimentation:   I tend to set TERM=xterm-color, which is supported on most hosts (but not all). I work on a number of different hosts, different OS versions, etc. I use everything from macOS X, Ubuntu Linux, RHEL/CentOS/Scientific Linux and FreeBSD. I'm trying to keep things simple and generic, if possible. I do a bunch of work using GNU screen, which adds another layer of fun. Many OSs set things like dircolors and by default, and I don't want to modify this on a hundred different hosts. So I try to stick with the defaults. Instead, I tweak my terminal's color configuration. Use color for some  (ls, grep, less, vim) and the . These commands seem to use the standard "". For example:  alias less='less --RAW-CONTROL-CHARS' export LS_OPTS='--color=auto' alias ls='ls ${LS_OPTS}'    I'll post my .bashrc and answer my own question Jeopardy Style.
58001
I have followed the instructions  and in the  that is provided there. However nowhere does it appear to say how I can change the colours of the different parts, because currently I set it to:  PS1='${debian_chroot:+($debian_chroot)}[\t] \u@\h:\w\$ '   But the text is still all white, how could I perhaps make the numbers for the time green, and my username and computer name light blue? I am running Ubuntu GNOME 15.04.
27410
I am using  to show the branch name in gnome terminal (Ubuntu 15.10) when working in a git repository. Based on the above I now have the below in my ~/.bashrc file:  # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes    ...  # Add git branch if its present to PS1 parse_git_branch() {  git branch 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } if [ "$color_prompt" = yes ]; then  PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' else  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' fi unset color_prompt force_color_prompt   As a result I now get:    so it works. But why has the coloring of my user@host been removed? And I would also expect that the branch name should be colored. Before it looked like this:    UPDATE: I have now tried this guide instead:    adding this to .bashrc:  parse_git_branch() {      git branch 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "   and that works:    Notice in .bashrc I also have this (default):  # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes   I have yet to find the reason why that snippet gives the correct result and the other version does not. Any input on this?  Here is the version of my .bashrc that has the old snippet enabled that does not work:
83042
Is there a way to copy the currently written content of the bash prompt? Say I wrote:  ping www.google.com   so that the lines in terminal looks like:  petr@sova:~$ ping www.google.com   and didn't hit return yet. I want to copy that text to clipboard. Is that possible?  The usual usecase would be hitting up several times and finding a command which I want to copy.
64393
As of late, and without my deliberately doing anything to make it happen, my Bash prompt has an  (i.e. @) prepended to it. This did not previously happen. Nor can I see anything in my ~/.bashrc that seems as though it ought to be making this happen.  This is on Debian Jessie GNU/Linux, using GNU Bash.  For example, my current Bash sessions look like this:  @sampablokuper@debianbox:~$ python3 Python 3.4.2 (default, Oct  8 2014, 13:14:40)  [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. @&gt;&gt;&gt; 1+2 3 @&gt;&gt;&gt; exit() @sampablokuper@debianbox:~$    whereas originally, they would have looked like this:  sampablokuper@debianbox:~$ python3 Python 3.4.2 (default, Oct  8 2014, 13:14:40)  [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; 1+2 3 &gt;&gt;&gt; exit() sampablokuper@debianbox:~$    Here are all the lines from my ~/.bashrc that appear to in any way relate to the Bash prompt:  # set variable identifying the chroot you work in (used in the prompt below) if [ -z "${debian_chroot:-}" ] &amp;&amp; [ -r /etc/debian_chroot ]; then     debian_chroot=$(cat /etc/debian_chroot) fi  # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in     xterm-color) color_prompt=yes;; esac  # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes  if [ -n "$force_color_prompt" ]; then     if [ -x /usr/bin/tput ] &amp;&amp; tput setaf 1 &gt;&amp;/dev/null; then         # We have color support; assume it's compliant with Ecma-48         # (ISO/IEC-6429). (Lack of such support is extremely rare, and such         # a case would tend to support setf rather than setaf.)         color_prompt=yes     else         color_prompt=     fi fi  if [ "$color_prompt" = yes ]; then     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt  # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*)     PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"     ;; *)     ;; esac   How can I get my Bash prompt to appear as it did originally?
38049
I added color on the gnome-terminal as in the picture and now I want to delete the custom colors added    I want to have the colors as in this picture
115653
When I execute a command from a terminal that prints coloured output (such as ls or gcc), the coloured output is printed. From my understanding, the process is actually outputting , and the terminal formats the colour.  However, if I execute the same command by another process (say a custom C application) and redirect the output to the application's own output, these colours do not persist.  How does a program decide whether or not to output text with colour format? Is there some environment variable?
40250
I use bash on both my Mac and as my cygwin shell. Overall, I'm quite pleased with it.  My one complaint however is that its TAB completion isn't as good as Windows Command Line TAB completion.   For example, if there are two files with the same prefix, then bash just beeps at me when I try to TAB complete. If I keep nailing TAB, then it will eventually show me a list of potential files.  I definately prefer how Windows will cycle through potential files right on the command line.   Is there a way to get bash to operate similar to Windows Command Line in this regard?  If there isn't (I do not want to switch shells), am I missing something about TAB completion in bash? Is there a more efficient way to use it?
68999
Rather than rephrasing my question, let me describe to you the desired user-case:  I create a short shell-script to run command "gnome-terminal --someoptionflagname 'my text to be posted'", and execute this script.  Gnome-terminal pops up, with command-line prompt followed by my text.   ie: fields@mycomputer:/$ my text to be posted  Can this be done?
113826
To the disappointment of many, tab/window title can't be set anymore with --title  I use bash. I have had a few aliases I have used to connect to remote servers with.  alias c:prod='gnome-terminal --hide-menubar --profile=Production \ --title="Production Server" -e "ssh &lt;url&gt;" &amp;'   I found a workaround for GNOME 3.14+ to set title which works well in the command line once put in .bashrc  function set-title() {   if [[ -z "$ORIG" ]]; then     ORIG=$PS1   fi   TITLE="\[\e]2;$@\a\]"   PS1=${ORIG}${TITLE} }   However, this only seems to be effective if placed and called in the remote server's .bashrc i.e. I can only change the title after login.  It has no effect, whatsoever if I attempt to change the title of the new window before connecting:  alias c:prod='gnome-terminal --hide-menubar --profile=Production \ -e "bash -c \"source ~/.bashrc;set-title Production;ssh &lt;url&gt;\"" &amp;'   Setting window title on the remote feels wrong, when the terminal is running on my box, and I cannot make it work on servers either where my user does not happen to have a home directory to put a .bashrc in.  Is there a forest I can't see for the trees?
20196
I need to set a number of Environment variables that can be seen by GUI apps (i.e. Xcode). When running from a terminal this is trivial and is simply a case of adding a. number of export commands to my .bash_profile e.g.  export BOOST_INCLUDE=~/boost/boost-XXXX/boost   Unfortunately GUI apps do not see values set in .bash_profile. I am using Catalina and it appears that Apple modifies the mechanism every time MacOs is updated. Many online guides are out of date....  This article:  suggests that launchctl should do what I need but even the following simple example does not work:  In a terminal:  /bin/launchctl setenv FOO BAR   Then close the terminal and open a new one  Check the value:  echo $FOO   The output should be   BAR   But it is unset. Note it is also unset in the original terminal so I am not convinced that the command /bin/launchctl setenv FOO BAR is doing anything.  Note: This is about setting the environment variable for GUI apps NOT just for the terminal.
10057
I'm currently using Debian 7 Wheezy, and I've noticed that the colors palette on terminal (which might be useful to identify among a large set of files and folders) are not enabled once I log as root.  Same, I've noticed the tab completion doesn't work the same in this situation.  How can I configure these issues?
73683
Short question:  Using bash, is it possible to print a sentence such that each individual word has a different color?   I.e; print a word in-line, change the text color, repeat?
108513
I have in my .bashrc  export TERM=xterm-256color   but this cause blinking all colored text (ls --color, in vim etc.) in a Linux console (Ctrl+Alt+F1).  So is there any possibility to recognize in which terminal I am (Linux console or a pseudo-tty) so I can export TERM variable with valid value?  [EDIT]  I found alternative solution only:  for vim user (in .vimrc)  set t_Co=256   or for xterm in .Xdefaults (after that xrdb -load .Xdefaults)  XTerm*termName:         xterm-256color   or for screen (.screenrc)  term screen-256color
96815
By default, man uses less to output text. How can I tell it to just output to stdout? My terminal emulator has a scroll bar and search function and I want to use those instead of the arrow keys.