| end | \e[m | \x1b[m | \033[m | 0 is appended if you omit it | | start | \E | \x1B | - | x cannot be capital | The escape character in bash, hex and octal respectively: | | bash | hex | octal | NOTE | (The corresponding tput command is listed in the Cap-name column of the huge table that starts at line 81.) See man 5 terminfo for the complete list of commands and more details on these options.Tput accepts scripts containing one command per line, which are executed in order before tput exits.Īvoid temporary files by echoing a multiline string and piping it: echo -e "setf 7\nsetb 1" | tput -S # set fg white and bg red With compiz wobbly windows, the bel command makes the terminal wobble for a second to draw the user's attention. Other commands tput sgr0 # Reset text format to the terminal's default Tput ich N # Insert N characters (moves rest of line forward!) Tput clear # Clear screen and move the cursor to 0,0 Tput cols # Output the number of columns of the terminalĬlear and insert commands tput ech N # Erase N characters Tput lines # Output the number of lines of the terminal Tput ll # Move to last line, first column (if no cup) Tput cub N # Move N characters back (left) Tput cuf N # Move N characters forward (right) Text mode commands tput bold # Select bold modeĬursor movement commands tput cup Y X # Move cursor to screen postion X,Y (top left is 0,0) There are also non-ANSI versions of the colour setting functions ( setb instead of setab, and setf instead of setaf) which use different numbers, not given here. Tput setaf # Set the foreground colour using ANSI escapeĬolours are as follows: Num Colour #define R G B The above command produces this on Ubuntu:įoreground & background colour commands tput setab # Set the background colour using ANSI escape It may be more convenient to insert tput's output directly into your echo strings using command substitution: echo "$(tput setaf 1)Red text $(tput setab 7)and white background$(tput sgr 0)" Note that they can still be saved into files or processed as input by programs other than the terminal. Tput produces character sequences that are interpreted by the terminal as having a special meaning. Shell variablesĪnother option is to use shell variables: red=`tput setaf 1`Įcho "$"
Use instead of & so if tput errors the text still shows. DirectĬall tput as part of a sequence of commands: tput setaf 1 echo "this is red text" Specific tput sub-commands are discussed later. You can use the awesome tput command (suggested in Ignacio's answer) to produce terminal control codes for all kinds of things.