zsh-users
 help / color / mirror / code / Atom feed
* How to "STTY" when "setopt nointeractive"?
@ 2005-10-18 19:17 DervishD
  2005-10-18 22:47 ` Philippe Troin
  2005-10-19  1:45 ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: DervishD @ 2005-10-18 19:17 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    In a shell script, this command:

    STTY=-onlcr stty -a

    doesn't have the desired effect (it doesn't deactivate onlcr). It
has to do with the INTERACTIVE option, because if the bangpath in the
script is "#!/bin/zsh -i" instead of the usual "#!/bin/zsh", it
works. Is it my fault,a desired behaviour or a bug?

    I was testing Bart's suggestion for my problematic "zpty" command
and I found that, after succesfully testing in the command line, it
didn't work in the script. I tried to change a couple of options that
may be slightly related with the terminal but it was "INTERACTIVE"
who made it work. Since I cannot "setopt interactive" within a
script, the only way is to change the bangpath.

    Thanks in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-18 19:17 How to "STTY" when "setopt nointeractive"? DervishD
@ 2005-10-18 22:47 ` Philippe Troin
  2005-10-18 23:08   ` DervishD
  2005-10-19  1:45 ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Philippe Troin @ 2005-10-18 22:47 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh Users

DervishD <zsh@dervishd.net> writes:

>     Hi all :)
> 
>     In a shell script, this command:
> 
>     STTY=-onlcr stty -a
> 
>     doesn't have the desired effect (it doesn't deactivate onlcr). It
> has to do with the INTERACTIVE option, because if the bangpath in the
> script is "#!/bin/zsh -i" instead of the usual "#!/bin/zsh", it
> works. Is it my fault,a desired behaviour or a bug?

I guess the STTY special environment variable has no effect if
interactive is not set.

>     I was testing Bart's suggestion for my problematic "zpty" command
> and I found that, after succesfully testing in the command line, it
> didn't work in the script. I tried to change a couple of options that
> may be slightly related with the terminal but it was "INTERACTIVE"
> who made it work. Since I cannot "setopt interactive" within a
> script, the only way is to change the bangpath.

Why not simply:

        stty -onlcr

in your script?

If you're worried about resetting the terminal state on exit (which
you shouldn't in a zpty session), you always can:

        savedstty=''
        trap 'stty $savedstty' EXIT
        savedstty=$(stty -g)
        stty -onlcr

Phil.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-18 22:47 ` Philippe Troin
@ 2005-10-18 23:08   ` DervishD
  0 siblings, 0 replies; 9+ messages in thread
From: DervishD @ 2005-10-18 23:08 UTC (permalink / raw)
  To: Philippe Troin; +Cc: Zsh Users

    Hi Philippe :)

 * Philippe Troin <phil@fifi.org> dixit:
> >     STTY=-onlcr stty -a
> > 
> >     doesn't have the desired effect (it doesn't deactivate onlcr). It
> > has to do with the INTERACTIVE option, because if the bangpath in the
> > script is "#!/bin/zsh -i" instead of the usual "#!/bin/zsh", it
> > works. Is it my fault,a desired behaviour or a bug?
> 
> I guess the STTY special environment variable has no effect if
> interactive is not set.

    Well, yes, I've deduced that ;) I don't really know why, anyway
:?
 
> >     I was testing Bart's suggestion for my problematic "zpty" command
> > and I found that, after succesfully testing in the command line, it
> > didn't work in the script. I tried to change a couple of options that
> > may be slightly related with the terminal but it was "INTERACTIVE"
> > who made it work. Since I cannot "setopt interactive" within a
> > script, the only way is to change the bangpath.
> 
> Why not simply:
> 
>         stty -onlcr
> 
> in your script?

    Because I don't want to mess with the terminal just to avoid some
\C-M characters that can be eliminated using a simple shell
substitution. Using STTY in the "zpty" command is more convenient
than the substitution, using "stty" in the whole script is not.
 
> If you're worried about resetting the terminal state on exit (which
> you shouldn't in a zpty session), you always can:
> 
>         savedstty=''
>         trap 'stty $savedstty' EXIT
>         savedstty=$(stty -g)
>         stty -onlcr

    I can use ttyctl, too. That's not the problem (but anyway thanks
a lot for the idea), I just was curious about the STTY behaviour. I'm
not sure whether that's a desired behaviour.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-18 19:17 How to "STTY" when "setopt nointeractive"? DervishD
  2005-10-18 22:47 ` Philippe Troin
@ 2005-10-19  1:45 ` Bart Schaefer
  2005-10-19  7:24   ` DervishD
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2005-10-19  1:45 UTC (permalink / raw)
  To: DervishD, Zsh Users

On Oct 18,  9:17pm, DervishD wrote:
}
}     I was testing Bart's suggestion for my problematic "zpty" command
} and I found that, after succesfully testing in the command line, it
} didn't work in the script.

Remember (again :-) that the arguments to zpty are processed as if with
eval.  So

    zpty cdda2wav STTY=-onlcr cdda2wav -v toc,sectors -J -H

is the same as

    zpty cdda2wav "stty -onlcr; cdda2wav -v toc,sectors -J -H"


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-19  1:45 ` Bart Schaefer
@ 2005-10-19  7:24   ` DervishD
  2005-10-19 15:36     ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: DervishD @ 2005-10-19  7:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Oct 18,  9:17pm, DervishD wrote:
> }
> }     I was testing Bart's suggestion for my problematic "zpty" command
> } and I found that, after succesfully testing in the command line, it
> } didn't work in the script.
> 
> Remember (again :-) that the arguments to zpty are processed as if with
> eval.  So
> 
>     zpty cdda2wav STTY=-onlcr cdda2wav -v toc,sectors -J -H
> 
> is the same as
> 
>     zpty cdda2wav "stty -onlcr; cdda2wav -v toc,sectors -J -H"

    OK, that works. So STTY doesn't work if the shell is not
interactive, right? I don't understand why :?

    Thanks for pointing, I wasn't sure if "zpty" worked with lists.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-19  7:24   ` DervishD
@ 2005-10-19 15:36     ` Bart Schaefer
  2005-10-19 19:33       ` DervishD
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2005-10-19 15:36 UTC (permalink / raw)
  To: Zsh Users

On Oct 19,  9:24am, DervishD wrote:
}
}     OK, that works. So STTY doesn't work if the shell is not
} interactive, right? I don't understand why :?

It's because scripts don't have ZLE to automatically reset the tty again
after the change for that one command.

The real intended usage of STTY is either to be typed at the prompt as a 
prefix to some command you know to need it, or to be included in aliases
(which are expected only to be used interactively) in the same way.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-19 15:36     ` Bart Schaefer
@ 2005-10-19 19:33       ` DervishD
  2005-10-20  1:01         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: DervishD @ 2005-10-19 19:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Oct 19,  9:24am, DervishD wrote:
> }     OK, that works. So STTY doesn't work if the shell is not
> } interactive, right? I don't understand why :?
> 
> It's because scripts don't have ZLE to automatically reset the tty
> again after the change for that one command.

    But the problem I'm seeing is not that, the tty doesn't remain
"changed" after the STTY use. The problem is that STTY doesn't do
anything.

    Do you mean that STTY doesn't work *on purpose* because ZLE
couldn't reset the tty if STTY were used?

> The real intended usage of STTY is either to be typed at the prompt
> as a prefix to some command you know to need it, or to be included
> in aliases (which are expected only to be used interactively) in
> the same way.

    I understand, but from the manual I suppose it worked in scripts,
too. I took a look at the source code, just in case, but I didn't
discovered any hint about STTY and INTERACTIVE relations.

    Thanks for the explanation, Bart :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-19 19:33       ` DervishD
@ 2005-10-20  1:01         ` Bart Schaefer
  2005-10-20  9:08           ` DervishD
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2005-10-20  1:01 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh Users

On Oct 19,  9:33pm, DervishD wrote:
}
}     Do you mean that STTY doesn't work *on purpose* because ZLE
} couldn't reset the tty if STTY were used?

That is what I meant.

} I took a look at the source code, just in case, but I didn't
} discovered any hint about STTY and INTERACTIVE relations.

It's actually not scripts/interactive, it's that STTY only applies
to the foreground job process leader, and commands in scripts do not
normally become process leaders.  Forcing zsh to think that it is
interactive causes the script to put the commands in their own
process groups (for job control).

    /* If the parameter STTY is set in the command's environment, *
     * we first run the stty command with the value of this       *
     * parameter as it arguments.                                 */
    if ((s = STTYval) && isatty(0) && (GETPGRP() == getpid())) {


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to "STTY" when "setopt nointeractive"?
  2005-10-20  1:01         ` Bart Schaefer
@ 2005-10-20  9:08           ` DervishD
  0 siblings, 0 replies; 9+ messages in thread
From: DervishD @ 2005-10-20  9:08 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Oct 19,  9:33pm, DervishD wrote:
> } I took a look at the source code, just in case, but I didn't
> } discovered any hint about STTY and INTERACTIVE relations.
> It's actually not scripts/interactive, it's that STTY only applies
> to the foreground job process leader

    Ah, that's ok then :) I just didn't imagine that the entire thing
had to do with process groups instead of just an option. My fault O:)

    Thanks a lot for the explanation, Bart :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-10-20 11:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-18 19:17 How to "STTY" when "setopt nointeractive"? DervishD
2005-10-18 22:47 ` Philippe Troin
2005-10-18 23:08   ` DervishD
2005-10-19  1:45 ` Bart Schaefer
2005-10-19  7:24   ` DervishD
2005-10-19 15:36     ` Bart Schaefer
2005-10-19 19:33       ` DervishD
2005-10-20  1:01         ` Bart Schaefer
2005-10-20  9:08           ` DervishD

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).