Operating System - HP-UX
1833803 Members
2409 Online
110063 Solutions
New Discussion

Terminal losing carriage-return under "script"?

 
SOLVED
Go to solution
Simon Hargrave
Honored Contributor

Terminal losing carriage-return under "script"?

Okay. If I telnet to the same server twice, I can execute "who am i" on one to see which terminal device it is using (eg /dev/pts/20). I can then output stuff to that from the other terminal eg: -

ls -1 > /dev/pts/20

All fine. Now, if I run "script" on the pts/20 terminal such that it's recording a typescript, the next time I do the ls command above, the carriage-returns aren't displayed. So the output on the destination screen is like: -

file1
file2
file3
file4 etc...

I know this echoing won't be recorded in the typescript, I'm not bothered about that. I just want the echoes to look correct on a terminal that's under a "script" session.

Any ideas why this is happening, and how I can overcome it?
6 REPLIES 6
Simon Hargrave
Honored Contributor

Re: Terminal losing carriage-return under "script"?

Okay I've found a workaround (typical, spent all yesterday thinking about it and figured a solution 5 minutes after posting!!)

Workaround is to pipe the output through ux2dos before redirecting.

Still interested to know _why_ it behaves this way, though.
Stanimir
Trusted Contributor

Re: Terminal losing carriage-return under "script"?

Hi !

I'm trying this:

1. On command line:

#tty
/dev/pts/0
#ls -1 > /dev/pts/0

file1
file2
....

2. Using script:
#vi ./script
a=`tty`
ls -1 > $a

#chmod +x ./script
#./script

file1
file2
....

The output is the same.Where is the problem?

Regards, Stan















Simon Hargrave
Honored Contributor

Re: Terminal losing carriage-return under "script"?

I think you misunderstand (or i didn't state it very well).

To reproduce:

# tty
/dev/pts/17
# script
Script started, file is typescript
# ls -1 > /dev/pts/17
file1
file2
file3
file4
Simon Hargrave
Honored Contributor

Re: Terminal losing carriage-return under "script"?

the forum isn't displaying the spaces correctly, the output looks like: -

file1
____file2
_________file3
______________fil4

(the underscores are blanks)
Stephen Keane
Honored Contributor

Re: Terminal losing carriage-return under "script"?

Funnily enough if you direct your output to a different tty (not the one running the script command), but one you have permission to write to, it works fine as the other tty is not running script.

The output of the ls command has each line terminated by a LF, your stty settings translate a LF to a LF+CR. When you write to the device 'raw' like you are doing, within a script, the terminal running the script is no longer following its stty settings and doesn't do the translation. I don't know whether I explained that very well.
Bill Hassell
Honored Contributor
Solution

Re: Terminal losing carriage-return under "script"?

This is a case of what you see is not what you get. The script command does not look at your screen. Instead, it tracks I/O transactions. When text is read or written, the strings are terminated by LF, the standard Unix terminator character. That is captured by script but the I/O is further processed by the device driver (telnet, serial, etc) where cannonicasl processing takes place. The "stairstep" effect you see is exactly what a standard ASCII file looks like: text LF text LF

The stty command changes the device driver rules (see man stty and man termio) so it makes more sense. For instance, you type: text CR, but without a LF supplied automatically by the driver, all commands would be on 1 line.

So as you've discovered, ux2dos will translate LF to CR LF.


Bill Hassell, sysadmin