Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Word splitting with command substitution
- X-seq: zsh-users 11864
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Word splitting with command substitution
- Date: Thu, 20 Sep 2007 17:56:29 +0100
- In-reply-to: <20070920163328.GA7470@cameron>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070920163328.GA7470@cameron>
Omari Norman wrote:
> % echo $(head -n 2 /etc/passwd)
> root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh
>
> % contents=$(head -n 2 /etc/passwd)
> % echo $contents
> root:x:0:0:root:/root:/bin/bash
> daemon:x:1:1:daemon:/usr/sbin:/bin/sh
>
> Why does the second example give me two separate lines, while the
> first is joined into one line?
In the second case the assignment is to a scalar, so is necessarily a
single word, hence there is no splitting and the newlines are left
intact. If you want multiple words, assign to an array:
contents=($(head -n 2 /etc/passwd))
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author