From: J G Miller on 3 Oct 2009 06:58 On Sat, 03 Oct 2009 10:44:14 +0000, no.top.post wrote: > But I dont know if/what to use to replace "HOSTNAME" to have PS1 > show the VTnumber. The tty command reports which tty you are on. The virtual consoles are on /dev/tty1 .. /dev/tty10, so check that tty reports back a /dev/ttyN and use that N for displaying "vtN" in your prompt. tt_number="`tty | sed -ne 's|/dev/tty||p'`" if [ -n ${tt_number} ] then echo "You are on virtual console number ${tt_number]" else echo "You are not on a virtucal console." fi When executed on a terminal emulator (et xterm, Eterm etc) tty will report /dev/pts/N where N is a number from 0 to ... N
From: J G Miller on 3 Oct 2009 07:32 On Sat, 03 Oct 2009 10:58:11 +0000, J G Miller wrote: > if [ -n ${tt_number} ] I omitted essential quotes -- that should be if [ -n "${tt_number}" ] otherwise the script will fall all when tt_number is blank.
From: Chris F.A. Johnson on 3 Oct 2009 14:48 On 2009-10-03, J G Miller wrote: > On Sat, 03 Oct 2009 10:44:14 +0000, no.top.post wrote: > >> But I dont know if/what to use to replace "HOSTNAME" to have PS1 >> show the VTnumber. > > The tty command reports which tty you are on. The virtual consoles > are on /dev/tty1 .. /dev/tty10, so check that tty reports back a > /dev/ttyN and use that N for displaying "vtN" in your prompt. > > tt_number="`tty | sed -ne 's|/dev/tty||p'`" > > if [ -n ${tt_number} ] > then > echo "You are on virtual console number ${tt_number]" > else > echo "You are not on a virtucal console." > fi > > When executed on a terminal emulator (et xterm, Eterm etc) tty > will report /dev/pts/N where N is a number from 0 to ... N TTY=$(tty) TTYNUM=${TTY##*[^0-9]} -- Chris F.A. Johnson, author | <http://cfaj.freeshell.org> Shell Scripting Recipes: | My code in this post, if any, A Problem-Solution Approach | is released under the 2005, Apress | GNU General Public Licence
From: J G Miller on 3 Oct 2009 16:05 On Sat, 03 Oct 2009 18:48:08 +0000, Chris F.A. Johnson wrote: > TTYNUM=${TTY##*[^0-9]} Yes that is much simpler but it is a Bashism which will not work under Bourne shell (or /bin/dash) and is therefore not portable.
From: pk on 3 Oct 2009 16:07 J G Miller wrote: > On Sat, 03 Oct 2009 18:48:08 +0000, Chris F.A. Johnson wrote: > >> TTYNUM=${TTY##*[^0-9]} > > Yes that is much simpler but it is a Bashism which will not work under > Bourne shell (or /bin/dash) and is therefore not portable. No.
|
Next
|
Last
Pages: 1 2 Prev: chroot = out of memory + change PS1 ? Next: Caitlyn Martin's review of Slack 13 |