In the fish shell, the actual command line is syntax highlighted:

enter image description here

Is there any way to get this same behavior in bash?

There is something just like this but for zsh, not bash. Is it possible that this could be ported to bash?

To clarify for those who don't understand the screenshot, explanation, or link provided: I want to highlight the actual text that is entered at the terminal. The commands, parentheses, quotes, etc.

  • Don't think bash accepts plugins like zsh does, so it may require a custom build of the bash shell/binary. Any reason not to just use fish instead? Also, thanks for pointing me to another shell to play around with and see if I can learn some advanced features of haha. – Matrix Mole Jul 11 '11 at 1:47
  • 1
    @Matrix: I can't use fish because I have a very complex bash configuration that I couldn't give up. – Wuffers Jul 11 '11 at 1:54
  • Unfortunately, I don't think that this is currently possible in bash. I'm sure that the research that you've done points to that as well. If you absolutely cannot switch to zsh, then that's understandable, but otherwise you may want to look at fizsh which incorporates some fish-like features into zsh, although it hasn't been updated since February, so perhaps the zsh-syntax-highlighting link that you provided would be more robust. – voithos Jul 19 '11 at 18:34
  • 1
    This would be hugely beneficial for learning bash, since it allows for playing around in a whole different way. Just easily spotting that you forgot to escape a special character would be valuable. – Andreas Oct 21 '17 at 23:46

Bash uses readline for interactive input, so syntax highlighting would need to be implemented in that program. I found a Google Groups discussion about how to code such a feature.

The fish shell uses its own line editor that is specific to that program, and can not be directly ported.

You may find that zsh is very similar to bash, and its line editor is extendable. I found zsh-syntax-highlighting to enable this feature in zsh.


There is no simple way to obtain syntax highlighting in GNU Bash (or GNU Readline), but it is in principle possible to implement your own line editor in Bash scripts by binding all the user inputs to shell functions using the builtin command bind -x 'BYTE: SHELL-COMMAND'. It is of course possible to integrate the feature of syntax highlighting in your own line editor.

In fact I implemented a line editor ble.sh with features like syntax highlighting and auto-suggestions. It supports Bash 3.0--5.0. Since it is written in (almost-)pure Bash scripts, you can just source the script in ~/.bashrc. Here is a sample to setup ble.sh in bashrc (see README for details):

$ git clone https://github.com/akinomyoga/ble.sh.git
$ cd ble.sh
$ make
$ make INSDIR="$HOME/.local/share/blesh" install
# bashrc

# Add the following line at the beginning of bashrc
[[ $- == *i* ]] &&
  source "$HOME/.local/share/blesh/ble.sh" --attach=none

# ... other bashrc settings ...

# Add the following line at the end of bashrc
[[ ${BLE_VERSION-} ]] && ble-attach

Note: I know that sometimes answering questions with links to own products is considered self-promotion and unpreferable, so I have been refraining from answering to this question. However, no other solutions did not appear long time, and also this question has many views (which reflects its significant demand). So I decided to answer to this question today. Referring the following meta questions/answers, I described the idea first and next provided a link to my project as an example implementation.

Yes, I have to admit that this is actually self-promotion, but I believe that this helps people who want the feature. If there are problems, I would appreciate it if you could tell me that by comments.


I dont think syntax highlighting should happen at the shell level but at the interface level (just my opinion -and someone else's it seems-), so I would look into "plugins" for Terminal or your favorite console, for example this plug in for Kate might help, or this other one which offers syntax highlighting in nano

Here is still more talk about how to syntax highlighting in Terminal:

Add alias ls='ls -G' to .bash_profile.

although here is better explained the how to

Hope it helps

  • 11
    It looks like you're answering how to set up syntax highlighting in editors, not in the shell. The ls-colorization isn't even "syntax" highlighting. – Kyle Strand Mar 25 '14 at 23:11
  • I think you're focusing on semantics more than on the solution, with the code from the links and suggested solution I get colors in bash, which I believe is what the OP wanted to know – Purefan Mar 26 '14 at 12:03
  • 10
    The original question is actually quite clearly about actual syntax highlighting. This is shown both by the screenshot of the fish shell and the final sentence: "I want to highlight the actual text that is entered at the terminal. The commands, parentheses, quotes, etc." – Kyle Strand Mar 26 '14 at 16:18
  • 10
    As I said, it's not "syntax" highlighting. Those are highlighting the output of the ls command based on file type, which has nothing to do with shell syntax. – Kyle Strand Mar 27 '14 at 20:17
  • 3
    Zsh (github.com/zsh-users/zsh-syntax-highlighting) and Fish (fishshell.com/docs/current/tutorial.html) both have syntax highlighting, this question is obviously asking about a similar feature for bash. It is a completely valid request to ask for a feature that is "hard to implement and keep consistent" especially when it already exists in other shells – Brandon Jan 12 '18 at 17:57

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.