Another stty question....

Another stty question....

Post by Unix-Shel » Wed, 07 Jun 2006 00:21:56



AIX 5.2 (ksh)

Hello Everyone,

I have another question pertaining to stty. Here is what I have:

# a.sh
stty intr '^-' susp '^-' dsusp '^-' quit '^-'    # Disable ^C, ^Z, ^Y
and ^\.
/tmp/b.sh
echo "back to a.sh"

# b.sh
echo "inside b.sh...."
stty intr '^c'
sleep 30

After I execute a.sh (and when it is inside b.sh), if I hit Ctrl-C
while it is 'sleeping', I get back to the command prompt. Is there a
way I can prevent that and instead pass the control back to a.sh to the
line after /tmp/b.sh? (in this case, it would be the 'echo' command)

Thanks for any suggestions.
S

 
 
 

Another stty question....

Post by Stephane CHAZELA » Wed, 07 Jun 2006 03:10:13


2006-06-5, 08:21(-07), Unix-Shell:
Quote:> AIX 5.2 (ksh)

> Hello Everyone,

> I have another question pertaining to stty. Here is what I have:

> # a.sh
> stty intr '^-' susp '^-' dsusp '^-' quit '^-'    # Disable ^C, ^Z, ^Y
> and ^\.
> /tmp/b.sh
> echo "back to a.sh"

> # b.sh
> echo "inside b.sh...."
> stty intr '^c'
> sleep 30

> After I execute a.sh (and when it is inside b.sh), if I hit Ctrl-C
> while it is 'sleeping', I get back to the command prompt. Is there a
> way I can prevent that and instead pass the control back to a.sh to the
> line after /tmp/b.sh? (in this case, it would be the 'echo' command)

[...]

^- is not a character. Maybe your stty ignores it because of
that?

What about stty intr ''

or trap '' INT

--
Stphane

 
 
 

Another stty question....

Post by Unix-Shel » Wed, 07 Jun 2006 06:20:03



> ^- is not a character. Maybe your stty ignores it because of
> that?

> What about stty intr ''

> or trap '' INT

I tried stty intr '', but the behavior is the same. Ctrl-C brings me
back to the command prompt, instead of going back to the echo command
in a.sh.

If I use trap, setting the interrupt in b.sh has no effect. I cannot
Ctrl-C at all.

 
 
 

Another stty question....

Post by Stephane CHAZELA » Wed, 07 Jun 2006 06:29:37


2006-06-5, 14:20(-07), Unix-Shell:


>> ^- is not a character. Maybe your stty ignores it because of
>> that?

>> What about stty intr ''

>> or trap '' INT

> I tried stty intr '', but the behavior is the same. Ctrl-C brings me
> back to the command prompt, instead of going back to the echo command
> in a.sh.

> If I use trap, setting the interrupt in b.sh has no effect. I cannot
> Ctrl-C at all.

If you want Ctrl-C to interrup sleep and not the other
foreground processes, you can either do:

trap '' INT

in a.sh (ignore it there):

trap : INT

in b.sh (not ignore it but do nothing, this way, it will still
interrupt "sleep").

Or you can make sure "sleep" is started as a new process group
and that process group is the foreground process group of the
terminal (so that only that only that process group gets the
SIGINT upon the Ctrl-C).

For that, you can add a "set -m" in b.sh, but that will not work
with every shell (for the shell interpreting b.sh).

--
Stphane

 
 
 

Another stty question....

Post by Kenan Kalajdzi » Wed, 07 Jun 2006 06:47:50



> I tried stty intr '', but the behavior is the same. Ctrl-C brings me
> back to the command prompt, instead of going back to the echo command
> in a.sh.

> If I use trap, setting the interrupt in b.sh has no effect. I cannot
> Ctrl-C at all.

You can try this in b.sh:

    trap 'exit 0' INT

It will cause b.sh to exit successfully on SIGINT, so the execution
continues in a.sh.

--
Kenan Kalajdzic

 
 
 

Another stty question....

Post by Sven Maschec » Sat, 10 Jun 2006 07:39:56



>> stty intr '^-'  [...]  # Disable ^C
> ^- is not a character.  Maybe your stty ignores it because of that?

Depends on the implementation, some also and some even only accept
this as notation for <undef>.
 
 
 

Another stty question....

Post by Unix-Shel » Sat, 10 Jun 2006 22:57:19



> You can try this in b.sh:

>     trap 'exit 0' INT

> It will cause b.sh to exit successfully on SIGINT, so the execution
> continues in a.sh.

I tried trap '' INT in a.sh and trap 'exit 0' INT in b.sh, but it does
not work. I cannot Ctrl-C and interrupt sleep. However, when I do the
same on the command line, it works perfectly:

Quote:> trap '' INT
> trap 'exit 0' INT
> sleep 10

Ctrl-C

<Your 'TELNET' connection has terminated>

 
 
 

1. Another stty question.

Monday, I posted a question relating to the following:  

I'm trying to use stty to set the values of a terminal that I then
want to open with an application I've written.  

   I "stty blablabla < /dev/tty00" and when I then look at it with
"stty -a < /dev/tty00", it's values are as they were before my first
stty.  

   Several people have told me that this is the way it's supposed
to work.  As I now understand it, the stty opens the port and sets
it's values, but closes the port, undoing the changes, when it
exits.  

   I've looked at the man page for stty, and I just don't get it.  

   Is there a way to set a port's values, then open that port in
an app while preserving those values, and set additional values
with tcsetattr?  

   I've been contracted to do a small project.  I would like the
user to change the com port values without setting entries for
tcsetattr, and then recompiling.  My client wants this program to
be portable between Solaris to DOS, and I want to minimize the
volume of code in conditional compile clauses.  

                                                          Thanks
                                                          Larry

2. Mask User Input?

3. Stty Question

4. Sending all mail to mailhub

5. stty question

6. Mercury 1.30 won't talk to Linux sometimes

7. Slackware easy: NOT!!

8. An stty question

9. stty questions

10. Stty questions for serial port modem

11. Newbie stty question