I have read about 15 chapters of your book (Teach Yourself UNIX in 24 Hours) so far. We are using vi. On the PS1 command, how do I see what is in it so I can add to it and not change what is already there?
We are using bash. What I see now is: ctdaywbsdv:/u/gwilki$
When I enter ‘echo $PS1’ I get: $ \[\e[0m\]
How do I keep the above and add the histcmd option? What does the \e and 0m\ mean? What do the [] the square brackets mean? I can’t find a man page for PS1. How do I find the rest of the options for this PS1?
You’re right that there’s no man page for the PS1 prompt setting in Bash, but the bash man page itself (type man bash) is incredibly long, and one section explains all the features and capabilities of the PS1 prompt variable. In that it notes, for example, that:
The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$
Going down to the section labeled PROMPTING, it explains all the different variables you can utilize to set or customize your own Bash prompt. It’s incredibly long:
Code | Explanation |
---|---|
\a | an ASCII bell character (07) |
\d | the date in “Weekday Month Date” format (e.g., “Tue May 26”) |
\D{format} | the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required |
\e | an ASCII escape character (033) |
\h | the hostname up to the first `.’ |
\H | the hostname |
\j | the number of jobs currently managed by the shell |
\l | the basename of the shell’s terminal device name |
\n | newline |
\r | carriage return |
\s | the name of the shell, the basename of $0 (the portion following the final slash) |
\t | the current time in 24-hour HH:MM:SS format |
\T | the current time in 12-hour HH:MM:SS format |
\@ | the current time in 12-hour am/pm format |
\A | the current time in 24-hour HH:MM format |
\u | the username of the current user |
\v | the version of bash (e.g., 2.00) |
\V | the release of bash, version + patchelvel (e.g., 2.00.0) |
\w | the current working directory |
\W | the basename of the current working directory |
\! | the history number of this command |
\# | the command number of this command |
\$ | if the effective UID is 0, a #, otherwise a $ |
\nnn | the character corresponding to the octal number nnn |
\\ | a backslash |
\[ | begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt |
\] | end a sequence of non-printing characters |
To see the current value of your prompt, just type echo $PS1 in the Bash shell. To change it, simply change the value of that variable. To make the change automatic each time you log in, add that to your ~/.profile and it’s done.
Now you have enough information to learn what the \e and \0m mean too. The former is the ASCII escape character and is likely being used to start a sequence to put your prompt in bold or inverse video, and \0m is indeed the sequence required to do just that, it’s the \000 format being used.
I hope that helps you fine-tune your Bash prompt as needed!
can you get a cds music on the psp