Using less in environment without controlling tty

Harald Becker ralda at gmx.de
Wed Jul 31 20:19:15 UTC 2013


Hi Sam !

>> Then try:
>>
>> cmd | setsid sh -c 'exec >/dev/tty12 2>&1 ; exec less'
>>
>Just for my own education, how would you know to
>use /dev/tty12 ? It would want to be whatever /dev/??? stdout
>is, maybe it is /dev/ttyS0

tty12 has just been chosen for example, programmer needs to know
where he wants to send the data to display.

And as you are requesting how to get the name of a used tty, try:

  tty

gives tty of stdin

  tty 0<&1

gives name of stdout

  tty 0<&2

gives name of stderr


This all relies on the C library function ttyname(), see man page
for tty(1), and ttyname(3).

The problem is, depending on implementation of this function it
doesn't work when /proc and/or /sys is not mounted properly, or
not accessible (like in chroot).

--
Harald


More information about the busybox mailing list