2008 Oct 20 2008
Command in linux: The prompt
The shell is a black screen which only shows what is expected of the indicator command prompt which is called, most of Linux systems tend to show an indicator in the user name, the name of the machine and the current working directory, as shown in the picture below:
The form of display is given by the prompt shell variable called PS, this means that setting this variable to change the look of the prompt, to practice the commands are going to change this variable to show the results of the variation in the indicator system.
As this post is long click the link below to read the whole article.
If you enter values directly to the PS1 variable in the current session, as fixed without them mantedran only during the current session of the console commands, so when you leave this meeting and go into another will not reflect any change .
As we will change the PS1 variable is desirable to keep the value of it in a variable alternative for power restauralar at any time during the session. To make this first view the contents of it with the echo command is typed into the command line the following order:
echo $ PS1
which displays the contents of the variable, once the same, we assign a new variable to the contents of the variable $ PS1 as a precaution more than anything, to do this, type the following command:
RESTORE = $ PS1
which assigns to a variable called "restoration" (you can choose the variable name that you may believe appropriate) the contents or value of the variable $ PS1, and ultimately find that the latter created by us contains the same as the variable $ PS1, to perform this process again using the echo command:
echo $ RESTORE
The following image shows the entire process:
Then we will change the prompt for this consists solely of a single character, thus defining the prompt can be easier to establish. To make this process has only been assigned to the variable $ PS1 is the value you want as an indicator, in this example we will make the command line displays the following characters "->", therefore, type the following command:
PS1 ="->"
and see how we can change our indicator showing the characters selected by us, the image below shows this process:
Restaular to your previous configuration is to be apportioned to the new value of the variable we created above to the variable $ PS1, typing the following command:
PS1 = $ RESTORE
Escape sequences for the prompt
There are also a series of strings called escape sequences, which serve to add to a series of indicator values optional, then the escape sequences listed with its corresponding value:
\ d date format dia_letra months dia_numero
\ h the hostname up to the first point (.)
\ H Full hostname
\ n newline
\ r carriage return
\ s Shell name
\ t Current time (24 hours) HH: MM: SS
\ T current time (12 hours) HH: MM: SS
\ @ Current time (12 hours) AM / PM
\ u username
\ $ $ If the UID is 0, # if other
\ v bash version
\ V Bash version of the package
\ w the current directory or folder
\ W base name of the current directory or folder
\! number of the current command in the historic
\ \ Contrabarra
\ [Boot sequence unprintable
\] Final sequence unprintable
Then we will see examples of previous sequences combined.
Date and name of the machine completely enclosed in brackets:
Sequence: [\ d] - [\ H] \ $ "
The result is as shown in the picture below:
Sequence: "[\ t] <\ u> <- \ w -> \ $"
As mentioned earlier to leave the computer terminal, the changes you've made on this variable will be lost and starting a new terminal session, the prompt appears without reflecting any kind of change, so if you want to make the changes permanent for terminal sessions you use it to edit the file. bashrc located in the root directory of the user and normally find the reference to the variable PS1 with the settings to assign to it, change this to display the prompt that interest. The next picture shows. Bashrc linux test system with which I have evidence.


















