How to Set Linux/Unix
(adding colors and
|
More examples may be added and some examples changed,
if I re-visit or use this page.
INTRODUCTION : Below is information on setting Linux/Unix CLI (Command Line Interface) prompts --- the prompts that one sees in a 'terminal' when the terminal is waiting for your next command. The environment variable name for the 'primary' prompt is 'PS1'. The environment variable name for the 'secondary' prompt is 'PS2'. This page is mainly concerned with setting 'PS1'. The variable 'PS1' is typically set in an assignment statement (an equal sign statement) in a 'run-control' (rc) file in the user's home directory. The name of the 'rc' file is typically
The 'rc' file is usually a 'dot' file --- a 'hidden' file --- in the user's home directory. The default is usually to have the prompt occupy one line on the terminal per prompt --- with the prompt being a white dollar-sign on a black background --- or a black dollar-sign on a white backgroud. The image at the top of this page indicates that the prompt can 'occupy' multiple lines, such as, in the example image above:
Here is an image that shows how the directory changes as one uses the 'cd' command to change to different directories.
In this image, the first prompt shows that we are positioned in the home directory --- indicated by the tilde character, '~'. We issued the 'cd Documents' command and the next prompt shows that we are positioned at '~/Documents' --- the 'Documents' directory in the user's home directory. Then we issued the 'cd ..' command to move back up a directory and the next prompt shows that we are positioned back in the home directory --- indicated by the tilde, '~'. Then we issued the 'cd ..' command AGAIN to move up a directory level and the next prompt shows that we are positioned in the '/home' directory --- the parent directory of all the user home directories.
Here is how the 'PS1' prompt was set to do this. This is
a combined 'export' and assignment (equals sign) statement.
Note that it is 3 lines --- corresponding to the 3 lines
we see for each prompt in the image above.
Explanation: The second line requests the current working directory (\w) to be shown and then sets the text color back to white (37) with '\e[0;37;48m'. The line-feed at the end of that line causes the directory name to appear on the line by itself. The third line sets the command prompt to be a dollar-sign separated by a space. (The various back-slashes have special purposes and are needed.) A little more detailed description appears in the comment statements below.
Some handy Shell-Prompt-setting code ... to add to Here is a link to help search for more information on setting the PS1 and PS2 environment variables for the command-line prompts.
|
Bottom of this
To return to a previously visited web page location, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
< Go to Top of Page, above. >
|