You are not logged in.
Hi everyone
I would like my console prompt to look like this on vc1:
[1 14:25 root /usr/share/kbd/consolefonts]
And I would like my console prompt to look like this on vc2:
[2 14:25 root /usr/share/kbd/consolefonts]
The console prompt on vc3 will start with [3 ... , vc4 will be [4 ... etc.
The time, username and full directory paths are already in place.
I need help on how to add the number at the beginning which corresponds to the current console.
Thank you.
wickyd
Last edited by wickyd (2009-02-10 17:16:24)
Offline
you should be able to accomplish this with something like PS1='[$DISPLAY \u@\h \W]\$ ' in your .bashrc
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
maybe this would work:
who -m |awk {'print $2'}
Offline
Alternatively
tty
will give you the full device node path. So something like:
foo=$(tty); echo ${foo##/dev/}
will give you the same output as above.
Offline
who -m |awk {'print $2'}
works, but it displays vc/1, not 1.
1. How do you get awk to print a substring which only displays 1? who -m | awk {'print substr($2,3)'} did not work.
2. How could I implement this into .bashrc?
foo=$(tty); echo ${foo##/dev/vc/}
gives me exactly what I want.
3. Where can I read more about what you just did? I don't understand this.
4. How can I implement this into .bashrc?
Offline
who -m |awk {'print $2'}
works, but it displays vc/1, not 1.
1. How do you get awk to print a substring which only displays 1? who -m | awk {'print substr($2,3)'} did not work.
2. How could I implement this into .bashrc?
TERM_NO=$(who -m |grep -o /[[:digit:]] |sed 's|/||')
and add $TERM_NO to your PS1 line. But I would use phrakture's example:
foo=$(tty); echo ${foo##/dev/vc/}
gives me exactly what I want.
3. Where can I read more about what you just did? I don't understand this.
4. How can I implement this into .bashrc?
man bash
/##<ENTER>
${parameter##word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches the beginning of the value of
parameter, then the result of the expansion is the expanded
value of parameter with the shortest matching pattern (the ``#''
case) or the longest matching pattern (the ``##'' case) deleted.
If parameter is @ or *, the pattern removal operation is applied
to each positional parameter in turn, and the expansion is the
resultant list. If parameter is an array variable subscripted
with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant
list
Offline
who -m |awk {'print $2'}
works, but it displays vc/1, not 1.
1. How do you get awk to print a substring which only displays 1? who -m | awk {'print substr($2,3)'} did not work.
who | awk '{ split($2,s,/vc\//); print s[2]; }'
Offline
Thank you for showing me so many different ways to achieve the same result.
I added the following two lines to my .bashrc to achieve the prompt I wanted:
TERMNO=$(foo=$(tty); echo ${foo##/dev/vc/})
PS1='[$TERMNO \A \u \w] '
Offline