Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Redirection and Variables



* Peter Stephenson <pws@xxxxxxx> [Oct 19, 2004 15:10]:
> > lookup () {
> >   echo "${(P)$(echo ${1}_programs\[xw\])}"
> > }

> Using eval would be nicer than the $(...), but actually there's a hack
> to avoid even that:

> lookup() {
>   echo ${(P)${:-$1_programs[xw]}}
> }

Ah, sweet.  Using eval always feels like a hack either way.  Maybe I
should stop thinking that.

> The empty nested substitution always returns the string after the :-,
> which undergoes expansion, so the (P) flag can operate on that.

> > If I have the following in a script that reads input from stdin:

> > sed -n "s/$REGEX/\1\n/gp" <&0 | sed "/$REGEX/!d" > $TMP
> > if [[ ! -s $TMP ]]; then
> >   rm -f $TMP
> >   exit 1
> > fi
> > ${EDITOR:-vi} $TMP

> > my $EDITOR (vim) will complain that
> > "Vim: Warning: Input is not from a terminal".  Is there a simple way to
> > get around this?

> Are you saying the early part is important, i.e. if you just run vi in
> the script without the earlier bit it works?  That sounds unlikely,
> although I haven't investigated in detail.  If that's not the case, you
> probably need to do some direction to force vi to use /dev/tty.

Well, the script is run like

url-extract <mail

and then sed processes the input from stdin and stores the result in
$TMP, then $EDITOR should be launched to edit the file.  The problem is,
since the script has stdin set, vim thinks that it's input isn't coming
from a terminal.  Any suggestions on how to solve that?  Vim can be told
to process stdin with - as the input file, but that doesn't really help
in this situation.  Anyway, the solution is to run

exec </dev/tty

before running $EDITOR, or is there perhaps a better one?

> I'm not sure why you have "<&0", that simply redirects standard input
> from standard input.

Oops, how very silly of me,
	nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}



Messages sorted by: Reverse Date, Date, Thread, Author