zsh-users
 help / color / mirror / code / Atom feed
* 2 more questions
@ 1997-02-21 11:28 Uli Zappe
  1997-02-21 14:41 ` Tomas Gradin
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Uli Zappe @ 1997-02-21 11:28 UTC (permalink / raw)
  To: zsh-users

Hi,

sorry I have to bother you yet again, but I have two more problems  
left that I couldn't solve with the zsh documentation:

1. Is there a way in zsh to pass the standard output to a parameter 
   instead of the standard input of a command? I.e. I have

      command1 | command2 parameter

   and need the output of command1 as the parameter for command2

2. How do I pipe the elements of an array into a command? If I do a

      echo $ARRAY | command

   the elements are separated only by whitespace instead of newlines 
   which will not work correctly especially if the elements possibly
   contain whitespace themselves. It works, of course, with a for-do
   loop but that's not efficient enough.

Thank you very much for every hint!


                Bye
                        Uli

______________________________________________________________________

Uli Zappe               E-Mail: uli@tallowcross.uni-frankfurt.de
                                (NeXTMail,Mime,ASCII) PGP on request
Lorscher Strasse 5      WWW:    -
D-60489 Frankfurt       Fon:    +49 (69) 9784 0007
Germany                 Fax:    +49 (69) 9784 0042

staff member of NEXTTOYOU - the German NEXTSTEP/OPENSTEP magazine
______________________________________________________________________



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

* Re: 2 more questions
  1997-02-21 11:28 2 more questions Uli Zappe
@ 1997-02-21 14:41 ` Tomas Gradin
  1997-02-21 14:48 ` Duncan Sargeant
  1997-02-21 15:12 ` Zefram
  2 siblings, 0 replies; 14+ messages in thread
From: Tomas Gradin @ 1997-02-21 14:41 UTC (permalink / raw)
  To: zsh-users; +Cc: Uli Zappe


>1. Is there a way in zsh to pass the standard output to a parameter 
>   instead of the standard input of a command? I.e. I have
>
>      command1 | command2 parameter
>
>   and need the output of command1 as the parameter for command2

command2 =(command1)

>2. How do I pipe the elements of an array into a command? If I do a
>
>      echo $ARRAY | command
>
>   the elements are separated only by whitespace instead of newlines 
>   which will not work correctly especially if the elements possibly
>   contain whitespace themselves. It works, of course, with a for-do
>   loop but that's not efficient enough.

echo $ARRAY | xargs -n 1 command

/tg



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

* Re: 2 more questions
  1997-02-21 11:28 2 more questions Uli Zappe
  1997-02-21 14:41 ` Tomas Gradin
@ 1997-02-21 14:48 ` Duncan Sargeant
  1997-02-21 15:12 ` Zefram
  2 siblings, 0 replies; 14+ messages in thread
From: Duncan Sargeant @ 1997-02-21 14:48 UTC (permalink / raw)
  To: zsh-users

uli (Uli Zappe) scandalously alleged:                          (on Feb 21, 1997)
> Hi,
> 
> sorry I have to bother you yet again, but I have two more problems  
> left that I couldn't solve with the zsh documentation:
> 
> 1. Is there a way in zsh to pass the standard output to a parameter 
>    instead of the standard input of a command? I.e. I have
> 
>       command1 | command2 parameter
>
>    and need the output of command1 as the parameter for command2

command2 `command1`

I can see how you were probably looking in the wrong place :)

> 
> 2. How do I pipe the elements of an array into a command? If I do a
> 
>       echo $ARRAY | command
> 
>    the elements are separated only by whitespace instead of newlines 
>    which will not work correctly especially if the elements possibly
>    contain whitespace themselves. It works, of course, with a for-do
>    loop but that's not efficient enough.

echo ${(j:\n:)ARRAY} | command

umm, there may be a way to pipe the variable to stdin of command
without the use of echo ... I'd be interested to know what it is.

again you were probably looking in the wrong places for this answer
:)

I learnt these tricks and a whole lot more, or at least worked out
where to look for info in the man pages when I did a 
man -T ps zshall > zshdocs.ps (I think? from memory, anyway), to
create the man page as a postscript file, which I then printed, and
read like a book, making notes on all those cool features.  Its a
great way to more fully appreciate zsh, if you can afford the
paper.

,dunc

-- 
Duncan Sargeant, keraunothnetophobic.   WWW: http://www.ucc.gu.uwa.edu.au/~dunc/
Orr would be crazy to fly more missions and sane if he didnt, but if he was sane
he had to fly them.  If he flew then he was crazy and didn't have to; but if he
didn't want to he was sane and had to.  Yossarian was moved deeply and let out a
respectful whistle at the absolute simplicity of this clause of Catch-22. --jh


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

* Re: 2 more questions
  1997-02-21 11:28 2 more questions Uli Zappe
  1997-02-21 14:41 ` Tomas Gradin
  1997-02-21 14:48 ` Duncan Sargeant
@ 1997-02-21 15:12 ` Zefram
  1997-02-22  4:23   ` Uli Zappe
  2 siblings, 1 reply; 14+ messages in thread
From: Zefram @ 1997-02-21 15:12 UTC (permalink / raw)
  To: Uli Zappe; +Cc: zsh-users

Uli Zappe wrote:
>1. Is there a way in zsh to pass the standard output to a parameter 
>   instead of the standard input of a command? I.e. I have
>
>      command1 | command2 parameter
>
>   and need the output of command1 as the parameter for command2

command2 "$(command1)"

>2. How do I pipe the elements of an array into a command? If I do a
>
>      echo $ARRAY | command
>
>   the elements are separated only by whitespace instead of newlines 
>   which will not work correctly especially if the elements possibly
>   contain whitespace themselves.

print -l "$ARRAY[@]" | command

but in the case of zero elements this will provide a single newline,
and it will produce ambiguous output if the array elements can contain
newlines.

command "$ARRAY[@]"

is the best interface, if it is feasible.

-zefram


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

* Re: 2 more questions
  1997-02-21 15:12 ` Zefram
@ 1997-02-22  4:23   ` Uli Zappe
  1997-02-22  5:04     ` Tomas Gradin
  0 siblings, 1 reply; 14+ messages in thread
From: Uli Zappe @ 1997-02-22  4:23 UTC (permalink / raw)
  To: zsh-users

Hi,

first, a LOT of thanks to you all for all of your answers! :-))

My second problem was easily solved by print -l which fits my needs  
perfectly. It's the same as echo "$VARIABLE" in sh (the quotes make  
for a newline there) which doesn't work in zsh.


The first, however, proved more tricky, mainly because I failed to  
make clear that I'd really need the stdout of the foregoing process  
in a VARIABLE, because I need it TWO times in the command  
afterwards.

Actually, my task was the following:

    cat $FILE | mv $FIELD1_IN_LINEX_OF_FILE $FIELD2_IN_LINEX_OF_FILE

I thought I had read of such a variable in zsh somewhere and just  
couldn't find it anymore, but judging by your comments I was simply  
mistaken.

What I tried then was a

      $(cat $FILE | awk '{printf("mv %s %s\n",$1,$2)}')

This works perfectly with only one line in $FILE, but I couldn't  
get it to work with more than one. Obviously the shell interprets  
the WHOLE output of &(...) as always ONE SINGLE command no matter  
what I do.

So I ended up with

      IFS="
      "
      LINES=($(cat $FILE))
      IFS=$DEFAULT_IFS
      for LINE in $LINES
      do
      $(echo $LINE | awk '{printf("mv %s %s\n",$1,$2)}')
      done

which is the best solution I was able to find.

Thanks again!


                Bye
                        Uli

______________________________________________________________________

Uli Zappe               E-Mail: uli@tallowcross.uni-frankfurt.de
                                (NeXTMail,Mime,ASCII) PGP on request
Lorscher Strasse 5      WWW:    -
D-60489 Frankfurt       Fon:    +49 (69) 9784 0007
Germany                 Fax:    +49 (69) 9784 0042

staff member of NEXTTOYOU - the German NEXTSTEP/OPENSTEP magazine
______________________________________________________________________


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

* Re: 2 more questions
  1997-02-22  4:23   ` Uli Zappe
@ 1997-02-22  5:04     ` Tomas Gradin
  1997-02-22 10:02       ` Uli Zappe
  1997-02-22 16:39       ` gwing
  0 siblings, 2 replies; 14+ messages in thread
From: Tomas Gradin @ 1997-02-22  5:04 UTC (permalink / raw)
  To: Uli Zappe; +Cc: zsh-users


>Actually, my task was the following:
>
>    cat $FILE | mv $FIELD1_IN_LINEX_OF_FILE $FIELD2_IN_LINEX_OF_FILE

Ah, I see. I would do it like this:

cat $FILE | awk '{print $1,$2}' | xargs -n 2 mv

/tg



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

* Re: 2 more questions
  1997-02-22  5:04     ` Tomas Gradin
@ 1997-02-22 10:02       ` Uli Zappe
  1997-02-22 16:39       ` gwing
  1 sibling, 0 replies; 14+ messages in thread
From: Uli Zappe @ 1997-02-22 10:02 UTC (permalink / raw)
  To: zsh-users

Tomas Gradin <tg@bosun.bm.lu.se> wrote:

> Ah, I see. I would do it like this:
>
> cat $FILE | awk '{print $1,$2}' | xargs -n 2 mv

now, that was a good one! :-)

Thanks a lot!!


                Bye
                        Uli

______________________________________________________________________

Uli Zappe               E-Mail: uli@tallowcross.uni-frankfurt.de
                                (NeXTMail,Mime,ASCII) PGP on request
Lorscher Strasse 5      WWW:    -
D-60489 Frankfurt       Fon:    +49 (69) 9784 0007
Germany                 Fax:    +49 (69) 9784 0042

staff member of NEXTTOYOU - the German NEXTSTEP/OPENSTEP magazine
______________________________________________________________________


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

* Re: 2 more questions
  1997-02-22  5:04     ` Tomas Gradin
  1997-02-22 10:02       ` Uli Zappe
@ 1997-02-22 16:39       ` gwing
  1997-02-22 17:48         ` Vincent Lefevre
                           ` (3 more replies)
  1 sibling, 4 replies; 14+ messages in thread
From: gwing @ 1997-02-22 16:39 UTC (permalink / raw)
  To: zsh-users

Tomas Gradin wrote:
:>Actually, my task was the following:
:>    cat $FILE | mv $FIELD1_IN_LINEX_OF_FILE $FIELD2_IN_LINEX_OF_FILE
:Ah, I see. I would do it like this:
:cat $FILE | awk '{print $1,$2}' | xargs -n 2 mv

cat?  What command is that :-)
There are few, if any, reasons to use cat with zsh.  I can't think of any at
the moment, unless you're using options to it.

awk < $FILE '{print $1,$2}' | xargs -n 2 mv

-- 
Geoff Wing [mason@primenet.com.au]   Technical Manager
  Phone    : +61-3-9818 2977         PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788         Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441


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

* Re: 2 more questions
  1997-02-22 16:39       ` gwing
@ 1997-02-22 17:48         ` Vincent Lefevre
  1997-02-22 18:29         ` 2 more questions (and a bug report) Bart Schaefer
                           ` (2 subsequent siblings)
  3 siblings, 0 replies; 14+ messages in thread
From: Vincent Lefevre @ 1997-02-22 17:48 UTC (permalink / raw)
  To: zsh-users

On Feb 23, 1997 at 03:39:44AM +1100, gwing@primenet.com.au wrote:
> awk < $FILE '{print $1,$2}' | xargs -n 2 mv

or

awk '{print $1,$2}' $FILE | xargs -n 2 mv

-- 
Vincent Lefevre, vlefevre@ens-lyon.fr | Acorn Risc PC, StrongARM @ 202MHz
http://www.ens-lyon.fr/~vlefevre      | 20+1MB RAM, Eagle M2, TV + Teletext
PhD in Computer Science, 1st year     | Apple CD-300, SyQuest 270MB (SCSI)
-----------------------------------------------------------------------------


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

* Re: 2 more questions (and a bug report)
  1997-02-22 16:39       ` gwing
  1997-02-22 17:48         ` Vincent Lefevre
@ 1997-02-22 18:29         ` Bart Schaefer
  1997-02-22 19:49         ` 2 more questions Uli Zappe
  1997-02-23 15:28         ` Hrvoje Niksic
  3 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1997-02-22 18:29 UTC (permalink / raw)
  To: gwing, zsh-users

On Feb 23,  3:39am, gwing@primenet.com.au wrote:
} Subject: Re: 2 more questions
}
} Tomas Gradin wrote:
} :cat $FILE | awk '{print $1,$2}' | xargs -n 2 mv
} 
} There are few, if any, reasons to use cat with zsh.
} 
} awk < $FILE '{print $1,$2}' | xargs -n 2 mv

There aren't all that many reasons to use awk and xargs, either.

	while read f1 f2 ; do mv $f1 $f2 ; done < $FILE

You should even be able to say

	while read f1 f2; { mv $f1 $f2 } < $FILE

but the `while LIST { LIST }` syntax appears to have been broken in various
different ways since 3.0-pre2 or earlier.  Has this been deprecated while I
wasn't looking, and just never removed from the info file?

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern


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

* Re: 2 more questions
  1997-02-22 16:39       ` gwing
  1997-02-22 17:48         ` Vincent Lefevre
  1997-02-22 18:29         ` 2 more questions (and a bug report) Bart Schaefer
@ 1997-02-22 19:49         ` Uli Zappe
  1997-02-23 15:10           ` gwing
  1997-02-23 15:28         ` Hrvoje Niksic
  3 siblings, 1 reply; 14+ messages in thread
From: Uli Zappe @ 1997-02-22 19:49 UTC (permalink / raw)
  To: zsh-users

Geoff Wing wrote:

> There are few, if any, reasons to use cat with zsh.  I can't
> think of any at the moment, unless you're using options to it.

What about

   ARRAY=($(cat FILE))

?


                Bye
                        Uli

______________________________________________________________________

Uli Zappe               E-Mail: uli@tallowcross.uni-frankfurt.de
                                (NeXTMail,Mime,ASCII) PGP on request
Lorscher Strasse 5      WWW:    -
D-60489 Frankfurt       Fon:    +49 (69) 9784 0007
Germany                 Fax:    +49 (69) 9784 0042

staff member of NEXTTOYOU - the German NEXTSTEP/OPENSTEP magazine
______________________________________________________________________


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

* Re: 2 more questions
  1997-02-22 19:49         ` 2 more questions Uli Zappe
@ 1997-02-23 15:10           ` gwing
  0 siblings, 0 replies; 14+ messages in thread
From: gwing @ 1997-02-23 15:10 UTC (permalink / raw)
  To: Uli Zappe; +Cc: zsh-users

Uli Zappe wrote:
:Geoff Wing wrote:
:> There are few, if any, reasons to use cat with zsh.  I can't
:> think of any at the moment, unless you're using options to it.
:What about
:   ARRAY=($(cat FILE))

ARRAY=($(<FILE))

Redirection in zsh is very extensive.
-- 
Geoff Wing [mason@primenet.com.au]   Technical Manager
  Phone    : +61-3-9818 2977         PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788         Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441


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

* Re: 2 more questions
  1997-02-22 16:39       ` gwing
                           ` (2 preceding siblings ...)
  1997-02-22 19:49         ` 2 more questions Uli Zappe
@ 1997-02-23 15:28         ` Hrvoje Niksic
  1997-02-23 21:24           ` Zefram
  3 siblings, 1 reply; 14+ messages in thread
From: Hrvoje Niksic @ 1997-02-23 15:28 UTC (permalink / raw)
  To: gwing; +Cc: zsh-users

gwing@primenet.com.au writes:

> There are few, if any, reasons to use cat with zsh.  I can't think
> of any at the moment, unless you're using options to it.

I use it to concatenate several files, which is what it was meant for
originally.

cat file1 file2 file3 file4 > file

is said to be a little more efficient than

<file1 <file2 <file3 <file4 > file

Somehow the cat version looks nicer, too.

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Thou Who might be our Father Who perhaps may be in Heaven...
                                                  -- Zelazny


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

* Re: 2 more questions
  1997-02-23 15:28         ` Hrvoje Niksic
@ 1997-02-23 21:24           ` Zefram
  0 siblings, 0 replies; 14+ messages in thread
From: Zefram @ 1997-02-23 21:24 UTC (permalink / raw)
  To: Hrvoje Niksic; +Cc: gwing, zsh-users

Hrvoje Niksic wrote:
>cat file1 file2 file3 file4 > file
>
>is said to be a little more efficient than
>
><file1 <file2 <file3 <file4 > file

I've always thought cat ought to be a shell builtin.  It's a pity there
are so many options.

-zefram


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

end of thread, other threads:[~1997-02-23 21:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-21 11:28 2 more questions Uli Zappe
1997-02-21 14:41 ` Tomas Gradin
1997-02-21 14:48 ` Duncan Sargeant
1997-02-21 15:12 ` Zefram
1997-02-22  4:23   ` Uli Zappe
1997-02-22  5:04     ` Tomas Gradin
1997-02-22 10:02       ` Uli Zappe
1997-02-22 16:39       ` gwing
1997-02-22 17:48         ` Vincent Lefevre
1997-02-22 18:29         ` 2 more questions (and a bug report) Bart Schaefer
1997-02-22 19:49         ` 2 more questions Uli Zappe
1997-02-23 15:10           ` gwing
1997-02-23 15:28         ` Hrvoje Niksic
1997-02-23 21:24           ` Zefram

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).