[Debian] Vraagje over de command prompt

Pagina: 1
Acties:

  • DPLuS
  • Registratie: April 2000
  • Niet online
Hoi,

Ik heb zojuist e.e.a. gelezen in de Command Prompt HOWTO's.
Zodoende heb ik ook mijn eigen promptje gebouwd waar ik nu een vraag over heb:

code:
1
export PS1="\\[\e[1;32m\][\\[\e[1;33m\] \$(date +%d/%m/%y) \t\\[\e[1;32m\] / \\[\e[1;35m\]\u\\[\e[1;34m\]@\\[\e[1;31m\]\h\\[\e[1;34m\]:\\[\e[1;36m\]\w \\[\e[1;32m\]]\\[\e[0m\]\n\\[\e[1;37m\]\\$\\[\e[0m\]"


Het gaat nu eigenlijk om die laatste \$:
In de tutorial staat dat dat dollar-teken een hekje (#) wordt als UID = 0 (dus root).
Alleen werkt dat bij mij alleen als ik hem dubbel escape (dus: \\$).
Waarom moet ik hem dubbel escapen en werkt het zo niet: \$ ??

  • blaataaps
  • Registratie: Juli 2001
  • Niet online
Omdat de \ voor bash ook speciaal is, als je zonder meer \$ opgeeft, zal bash dat doorgeven aan $PS1 als $
code:
1
2
3
4
5
$ echo \$
$
$ echo \\$
\$
$

Je wil juist dat \$ in $PS1 terechtkomt, dus moet je de \ escapen met een \.

  • DPLuS
  • Registratie: April 2000
  • Niet online
Hmmja, maar het rare is dat het hier bijvoorbeeld WEL kan?!:

Bron: http://linux.about.com/li.../newbie/blnewbie3.4.2.htm

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
To customize the prompt, I can edit the file /etc/bashrc (as root) and insert almost any text inside the quotation marks. Here is the meaning of some special codes I may also choose to use: 

\u   -    username of the current user (= $LOGNAME), 
\h   -    the name of the computer running the shell (hostname), 
\H   -    entire hostname, 
\W   -    the base of the name of the current working directory, 
\w   -    the full name of the current working directory, 
\$   -    display "$" for normal users and "#" for the root, 
\!   -    history number of the current command, 
\#   -    number of the current command (as executed in the current shell), 
\d   -    current date, 
\t   -    current time (24-hr), 
\T   -    current time (12-hr) - bash 2.0 only, 
\@   -    current time (AM/PM format) - bash 2.0 only, 
\s   -    name of the shell, 
\a   -    sound alarm (beep), 
\j   -    number of jobs the user has, 
\n   -    new line, 
\\   -    backslash, 
\\[   -    begin a sequence of non-printable characters, 
\]   -    end a sequence of non-printable characters, 
\nnn -    the ASCII character corresponding to the octal number nnn. 
$(date) - output from the date command (or any other command for that matter), 
  

Here is an example on how to add colour. See the next chapter for details about colour: 

PS1="\\[\033[1;32m\][\u@\h \W]\$\\[\033[0m\] "