הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Special Terminal Characters

The following lists some useful special characters.
When the terminal is to print the character on the left, it will actually print the character on the right (or perform the action).

Code Meaning
\n Newline
\t Tab
\b Backspace
\a alert (beep)
\a alert (beep)

Using Colors

Most terminals also support color codes. To print out text in color, prefix it with one of the following color codes:

Code Color
\e[0m Reset to default colors
\e[30m Black Text
\e[31m Red Text
\e[32m Green Text
\e[33m Yellow Text
\e[34m Blue Text
\e[35m Magenta Text
\e[36m Cyan Text
\e[37m White Text
\e[40m Black Background
\e[41m Red Background
\e[42m Green Background
\e[43m Yellow Background
\e[44m Blue Background
\e[45m Magenta Background
\e[46m Cyan Background
\e[47m White Background

Create Cool Prompts

Getting a customized prompt is as easy as setting a variable. In csh, it's called prompt, and in bash its name is PS1. Each shell also keeps a list of special characters which act as placeholders for real environmental data (such as the current directory, hostname, and more). A full list of the placeholders can be found in the relevant man pages.

Let's examine some cool shell prompts:

# CSH hostname is represented by %m. 
# As for colors, in csh we insert terminal command characters using
# a special %{<character code goes here%} syntax. 
# The following uses red text control char followed by the hostname

set prompt='%{\e[31m%}%m %{\e[0m%}% '

# And for bash - note the use of export, and no need for the %{...%}
export PS1='\e[31m\h\e[0m$ '

# This prompt displays the current working directory in green
set prompt='%{\e[32m%}%~%{\e[0m%}% '

# And the same in bash
export PS1='\e[32m\W\e[0m$ '
course: