Index / Unix

sh

FreeBSD has two different shells in the base system. sh(1) is a Bourne type POSIX compatible shell and the default for new users. tcsh(1) on the other hand is an advanced version of the C shell and the default for the root user.

I use sh for both scripting and interactive use. Here follow some tips and tricks that I have found useful.

Color File Listings

This is actually a feature of ls(1). Color listings can be permanently enabled by setting the environment variable CLICOLOR, the actual colors used can be defined with the environment variable LSCOLORS.

Here is what I have in my .profile:

export CLICOLOR="1"
# ls(1) attr.key:1122334455667788990011
export LSCOLORS="Exfxcxdxbxegedabagacad"

Color Prompt

Many seem to think that this is impossible in sh, but the trick is to use the ^V[ESC] key combination to insert the necessary escape sequences. (Control-V followed by pressing Escape.)

Here is the simple prompt that I have in my .shrc:

PS1="^[[1;32m[\W]\$^[[0m "

The symbols ^[ represent the escape character. Note that it is a single character even though vi(1) will visually present it as two characters.

This page by Fabien Loison covers all the ANSI/VT100 formating control sequences in great detail.