Behavior Return key


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Behavior Return key
# 1  
Old 04-11-2006
Behavior Return key

Hi all!

Well, you might have guessed it, I am looking for a way to control the return key under Solaris 8 and using telnet connections.
I notice a difference between Solaris and System V but I don't know exactly where to look for changes. The stty params are slightly different but as far as I can see, nothing concerning the returnkey. If necessary I can show how these are looking.

What I would like to obtain is a return key jumping to the next field and cutting all behind the cursor.

Would be great!

Tnx for help! Smilie

Peter
# 2  
Old 04-15-2006
You need to clarify this question. Solaris is based on System V Release 4. The return key completes an input line. There is no general notion of fields under any unix tty driver that I have ever seen. "Cutting all behing the cursor"... I can't imagine what that is supposed to mean.

If you are complaing that a curses based program is behaving differently between two unix systems, the issue is most likely related to the terminfo database entry for the terminal. Make sure that your TERM environment is the same. Run "untic" to see the database entries...if these are different this difference may be your problem.
# 3  
Old 04-18-2006
Not sure this is even remotely what your looking for. I found it on the net and it has some interesting things to know either way.

Using stty to Your Advantage
The stty (set the options for a terminal) command can be very useful once you get the knack of using it. Stty can give you quick manual control over the characteristics of your terminal. If ever you have found yourself working on a terminal in which the terminal settings did not match your actual terminal, you will know how annoying this situation can be. It is often experienced when you attempt to backspace to fix a typo on the command line and, instead of seeing the cursor move backwards on the line erasing characters, you see an increasingly long string of ^H or ^? characters appearing at the end of your command line.

boson> echo "Please send me the lsit^H^H^H

What this tells you is that ^H (control-H) is not functioning as an erase. Using stty, however, you can reset your erase character like this:

boson> stty erase \^h

To see a list of your current stty settings, type the following command:
stty -a

This command will list your current settings in a format like this:

boson> stty -a
speed 38400 baud;
rows = 80; columns = 132; ypixels = 0; xpixels = 0;
csdata ?
eucw 1:0:0:0, scrw 1:0:0:0
intr = ^c; quit = ^\; erase = ^h; kill = ^u;
eof = ^d; eol = <<undef> eol2 = <undef> swtch = <undef>
start = ^q; stop = ^s; susp = ^z; dsusp = ^y;
rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;
-parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk -crtscts -crtsxoff -parext
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
ixon -ixany -ixoff imaxbel
isig icanon -xcase echo echoe echok -echonl -noflsh
-tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten
opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3


The standard control characters are:
control-d end of file (eof)
control-h backspace (erase)
control-z suspend (susp)
control-u delete text from start of line (kill)
control-c interrupt


The most commonly used stty command is undoubtedly the "stty erase ^h" command which is often used in scripts

if [ `tty | grep -ci console` -eq 0 ]
then
stty ERASE ^H
TERM=SUN
fi


You can also display your settings in a format which allows you to restore them at a later time. This is done with the "stty -g" command, the output of which (on one of my Solaris systems) looks like this:

boson> stty -g
2502:1805:f00bf:8a3b:17:1c:7f:15:4:0:0:0:11:13:1a:19:12:f:17:16:0:0:1:1:0:00:0
:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

If you want to save and restore your terminal settings, you can use the output of the stty -g command to create a command that will do this for you. First, let's examine what the command would look like:

boson> echo stty `stty -g`
stty 2502:1805:f00bf:8a3b:3:1c:f:15:4:0:0:0:11:13:1a:19:12:f:17:16:0:0:1:1:0:00
:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

The "stty 2502:1805 ..." command can be used to restore the current settings at a later time. So, let's store that command in a file and make it work as a script:

boson> echo stty `stty -g` > restore-tty; chmod 755 restore-tty

Now, let's test the script by first resetting our erase character from ^H to ^A and then restoring it back to its previous setting using our script.

boson> stty erase \^a
boson> echo This is a mess^H^H^H
This is a mess

Obviously, control-H isn't working any longer as a backspace character, though control-A should work just fine. To restore the previous settings, we invoke our script:

boson> ./restore-tty

Control-H should now work as before.

If you want to change your stty settings in a script and then restore them, you don't have to build a script to preserve the initial settings. You can save your settings in a variable and then use the stty command to restore from that:
oldSettings=`stty -g` # save stty settings
stty -echo raw
<other commands>
stty $oldSettings # restore stty settings

Other stty settings allow you to change the usable size of your terminal. For example, if you need a narrower display, you could set your terminal width to be narrower by setting your columns from the normal 80 to something more narrow:

stty columns 60

If you list your files after running this command, you will note the changes in your display.
boson> ls /etc
SnmpAgent.d labelit rc1.d
TIMEZONE lib rc2
TIMEZONE.temp link rc2.d
acct llc2 rc3
aliases log rc3.d

becomes this:

boson> ls /etc
SnmpAgent.d nodename
TIMEZONE nscd.conf
TIMEZONE.temp nsswitch.conf
acct nsswitch.dns
aliases nsswitch.files

If you have ever worked in a terminal in which you noticed data scrolling off the top of your screen when piped to the more or the less command, you have probably suspected that your terminal settings were wrong. Whenever you see this behavior, you should look at your stty rows variable; it is likely to be set too high.

Similarly, if you notice that the lines in your display wrap around the edge of your screen, your columns setting may be too large.

The stty command can also come in handy for scripts in which you wish to hide text that is entered by a user. By using the stty echo and -echo commands, you can turn input echoing on and off as you see fit. If you want to prompt a user to enter a password, for example, you can do something like this:

echo -n "Enter you very secret password: "
stty -echo
read password
stty echo

The "stty -echo" command turns off input echoing and the "stty echo" command turns it back on again.

You can then proceed with the remainder of the script knowing that the password was not displayed on the screen where someone who should not know it might have noticed.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write a shell script to automatically accept return key with out user intervention?

Hi Friends, i am creating a shell script which is accepting file name as input parameter from Java and invoking finacle service. The service will accpet text file,B2k_session id,etc and upload the text file data in finacle database. My shell script looks like this:- #! /bin/ksh... (2 Replies)
Discussion started by: vadlamudy
2 Replies

2. Shell Programming and Scripting

enter key or carriage return as input in perl

hi experts Question in perl i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step it something like that chomp ($input = <STDIN>); if ($input =~... (3 Replies)
Discussion started by: doubando
3 Replies

3. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

4. Shell Programming and Scripting

How to enter a return key in bash script?

Hi, I'm porting an install script from AIX to Red Hat (2.6.18-164.el5 #1 SMP) I have this script working in both AIX and HP-UX. The script is a wrapper for a Micro Focus Server Express install program. It responds to the install program questions with a here-now list. Responses includes... (14 Replies)
Discussion started by: duker61
14 Replies

5. UNIX for Dummies Questions & Answers

Weird home key behavior

Hi there, I'm using putty to connect to several servers. On every remote machine, the home key takes me at the beginning of a command line. Exept on one machine where a press on the home key outputs the tilde sign (~). Is there any place where I can override this behavior, I really prefer my... (6 Replies)
Discussion started by: chebarbudo
6 Replies

6. Shell Programming and Scripting

date and time on every time pressing return key

Hi all, I have a situation here, I want that every time when i press "enter key" in bash prompt i want the date command to be executed. i have tried to make some changes in "/etc/bashrc" but no luck. Thanx in advance (1 Reply)
Discussion started by: xander
1 Replies

7. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

8. Shell Programming and Scripting

How to identify whether the return key is pressed ??

I want my program(ksh) to execute further only if the return key is pressed. Please help. i have already tried "\n", "\r", "^M" . Thanks in advance (2 Replies)
Discussion started by: AiK
2 Replies

9. Shell Programming and Scripting

Return Key

Is it possible to enter data into a read command and automatically enter, for instance read name echo "Andy" /r could this work cos it doesn't seem to be working for me! (2 Replies)
Discussion started by: chapmana
2 Replies
Login or Register to Ask a Question