* Re: Perl like select()?
@ 1999-08-25 16:26 Jay Sekora
0 siblings, 0 replies; 9+ messages in thread
From: Jay Sekora @ 1999-08-25 16:26 UTC (permalink / raw)
To: Josh Howard; +Cc: zsh-users
> For instance: I have a shell script that I want to
> simply put ">log.file" at the top, and then start echo'ing and doing
> various output and expect everything to go to log.file, as opposed to
> doing something like "./script.sh >> log.file"
In the Bourne shell, you use "exec" with redirection and no command,
thusly:
#!/bin/zsh
exec > /tmp/foo
echo this is a test
And empirically, this works in zsh as well (3.0.5), although the section
on "exec" in zshmisc(1) doesn't seem to imply that it should.
-j.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 16:16 ` Zefram
` (2 preceding siblings ...)
1999-08-25 18:35 ` Josh Howard
@ 1999-08-27 10:56 ` Nemeth Ervin
3 siblings, 0 replies; 9+ messages in thread
From: Nemeth Ervin @ 1999-08-27 10:56 UTC (permalink / raw)
To: zsh-users
Hi!
>>>>> Zefram writes:
> Josh Howard wrote:
>> Is there any way, in a script, to use a "Perl-like" select() to
>> associate stdout with a particular file, before the execution of the
>> rest of the script?
> exec > file
> permanently redirects stdout. Any redirection can be used this way.
If you want to keep std{in,out,err}, you can also use a new descriptor.
Example:
# -*- sh -*-
local i file
file=~/.ssh/known_hosts
reply=()
[[ -r $file ]] || return
exec 5< $file
while read -u5 -A i
do
reply=($reply $i[1])
done
exec 5<&-
--
____ ____________________________________________________
/____| NEMETH, ERVIN |____________________________________________________|
// < airwin @ inf.bme.hu > http://www.inf.bme.hu/~airwin
||
|| "Nonsense. All you have to do is say 'Engage'"
|| -- Patrick Stewart about warp theory
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 16:16 ` Zefram
1999-08-25 16:48 ` Owen M. Astley
1999-08-25 16:49 ` Bart Schaefer
@ 1999-08-25 18:35 ` Josh Howard
1999-08-27 10:56 ` Nemeth Ervin
3 siblings, 0 replies; 9+ messages in thread
From: Josh Howard @ 1999-08-25 18:35 UTC (permalink / raw)
To: Zefram; +Cc: zsh-users
Well, my ignorance is now managable. Thanks.
Zefram <zefram@fysh.org> writes:
> Josh Howard wrote:
> >Is there any way, in a script, to use a "Perl-like" select() to
> >associate stdout with a particular file, before the execution of the
> >rest of the script?
>
> exec > file
>
> permanently redirects stdout. Any redirection can be used this way.
>
> > For instance: I have a shell script that I want to
> >simply put ">log.file" at the top, and then start echo'ing and doing
> >various output and expect everything to go to log.file,
>
> Interestingly enough, that's the syntax I used for this operation when
> designing a new shell from scratch[1].
>
> -zefram
>
> [1] The Elate shell. It's proprietary and doesn't run on Unix, so don't
> ask for it.
>
--
Josh Howard <jrh@vicor-nb.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 17:00 ` Bart Schaefer
@ 1999-08-25 17:08 ` Owen M. Astley
0 siblings, 0 replies; 9+ messages in thread
From: Owen M. Astley @ 1999-08-25 17:08 UTC (permalink / raw)
To: zsh-users
> On Aug 25, 5:48pm, Owen M. Astley wrote:
> > Subject: Re: Perl like select()?
> > On Wed, 25 Aug 1999, Zefram wrote:
> >
> > > exec > file
> >
> > This works in /bin/sh here, but not under zsh
>
> My guess would be that you have exec aliased to something.
Ahhhh. Yes, I wrote a function called exec() so that I didn't
try to execute non-existent commands by mistake!
Thanks
Owen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 16:48 ` Owen M. Astley
@ 1999-08-25 17:00 ` Bart Schaefer
1999-08-25 17:08 ` Owen M. Astley
0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 1999-08-25 17:00 UTC (permalink / raw)
To: Owen M. Astley, zsh-users
On Aug 25, 5:48pm, Owen M. Astley wrote:
> Subject: Re: Perl like select()?
> On Wed, 25 Aug 1999, Zefram wrote:
>
> > exec > file
>
> This works in /bin/sh here, but not under zsh
>
> alpha2----~/tmp% { exec >foo
> cursh> echo bar
> cursh> }
> zsh: command name expected
>
> So I guess that there is something odd with my setup. Does anybody
> have any ideas?
My guess would be that you have exec aliased to something.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 16:16 ` Zefram
1999-08-25 16:48 ` Owen M. Astley
@ 1999-08-25 16:49 ` Bart Schaefer
1999-08-25 18:35 ` Josh Howard
1999-08-27 10:56 ` Nemeth Ervin
3 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 1999-08-25 16:49 UTC (permalink / raw)
To: Zefram, Josh Howard; +Cc: zsh-users
On Aug 25, 5:16pm, Zefram wrote:
> Subject: Re: Perl like select()?
> Josh Howard wrote:
> >Is there any way, in a script, to use a "Perl-like" select() to
> >simply put ">log.file" at the top, and then start echo'ing and doing
> >various output and expect everything to go to log.file
>
> Interestingly enough, that's the syntax I used for this operation when
> designing a new shell
NULLCMD=exec
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 16:16 ` Zefram
@ 1999-08-25 16:48 ` Owen M. Astley
1999-08-25 17:00 ` Bart Schaefer
1999-08-25 16:49 ` Bart Schaefer
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Owen M. Astley @ 1999-08-25 16:48 UTC (permalink / raw)
To: zsh-users
On Wed, 25 Aug 1999, Zefram wrote:
> Josh Howard wrote:
> >Is there any way, in a script, to use a "Perl-like" select() to
> >associate stdout with a particular file, before the execution of the
> >rest of the script?
>
> exec > file
>
> permanently redirects stdout. Any redirection can be used this way.
This works in /bin/sh here, but not under zsh (I've tried
zsh-3.0.{0,5,6}), and I've always thought that it was a feature of zsh
that it didn't.
Example...
alpha2----~/tmp% { exec >foo
cursh> echo bar
cursh> }
zsh: command name expected
bar
alpha2----~/tmp% ls -l foo
-rw-r--r-- 1 oma1000 colloids 0 Aug 25 17:46 foo
So I guess that there is something odd with my setup. Does anybody
have any ideas? Just to start you off, these are the options that I am
setting...
alpha2----~/tmp% grep setop ~/.zshrc
compctl -o setopt unsetopt isset
#unsetopt AUTO_LIST
unsetopt BEEP # Don't beep ever.
setopt AUTO_LIST # Auto list ambiguous choices.
#setopt AUTO_MENU # Use menu completion for 2nd request.
unsetopt MENU_COMPLETE # Don't use menu completion for 1st request.
setopt ALWAYS_LAST_PROMPT # List completions after the prompt.
setopt AUTO_NAME_DIRS # ~dirname instead of absolute names.
setopt EXTENDED_GLOB # Extended filename globbing.
setopt NO_CLOBBER # Don't clobber files with >, or create with >>.
setopt LIST_TYPES # Completions get a trailing id symbol.
setopt INTERACTIVE_COMMENTS # Allow comments in interactive shells.
unsetopt NOTIFY # Wait before reporting status of background jobs.
unsetopt BG_NICE # Don't run background jobs at a lower priority.
setopt IGNORE_EOF # Don't exit on EOF.
setopt MULTIOS # Glob after redirection operator.
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT PUSHD_TO_HOME PUSHD_MINUS
setopt HIST_IGNORE_DUPS APPEND_HISTORY
Owen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Perl like select()?
1999-08-25 15:48 Josh Howard
@ 1999-08-25 16:16 ` Zefram
1999-08-25 16:48 ` Owen M. Astley
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Zefram @ 1999-08-25 16:16 UTC (permalink / raw)
To: Josh Howard; +Cc: zsh-users
Josh Howard wrote:
>Is there any way, in a script, to use a "Perl-like" select() to
>associate stdout with a particular file, before the execution of the
>rest of the script?
exec > file
permanently redirects stdout. Any redirection can be used this way.
> For instance: I have a shell script that I want to
>simply put ">log.file" at the top, and then start echo'ing and doing
>various output and expect everything to go to log.file,
Interestingly enough, that's the syntax I used for this operation when
designing a new shell from scratch[1].
-zefram
[1] The Elate shell. It's proprietary and doesn't run on Unix, so don't
ask for it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Perl like select()?
@ 1999-08-25 15:48 Josh Howard
1999-08-25 16:16 ` Zefram
0 siblings, 1 reply; 9+ messages in thread
From: Josh Howard @ 1999-08-25 15:48 UTC (permalink / raw)
To: zsh-users
Is there any way, in a script, to use a "Perl-like" select() to
associate stdout with a particular file, before the execution of the
rest of the script? For instance: I have a shell script that I want to
simply put ">log.file" at the top, and then start echo'ing and doing
various output and expect everything to go to log.file, as opposed to
doing something like "./script.sh >> log.file"
In perl, you can open() and select() a file to associate where stdout
is written to. This might be a useful feature in zsh if it doesn't
already exist.
--
Josh Howard <jrh@vicor-nb.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1999-08-27 10:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-25 16:26 Perl like select()? Jay Sekora
-- strict thread matches above, loose matches on Subject: below --
1999-08-25 15:48 Josh Howard
1999-08-25 16:16 ` Zefram
1999-08-25 16:48 ` Owen M. Astley
1999-08-25 17:00 ` Bart Schaefer
1999-08-25 17:08 ` Owen M. Astley
1999-08-25 16:49 ` Bart Schaefer
1999-08-25 18:35 ` Josh Howard
1999-08-27 10:56 ` Nemeth Ervin
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).