Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to get verbatim output in command substitution
- X-seq: zsh-users 12723
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Sharad Pratap <sh4r4d@xxxxxxxxx>
- Subject: Re: how to get verbatim output in command substitution
- Date: Tue, 25 Mar 2008 15:01:26 +0000
- Cc: zsh-users@xxxxxxxxxx, sharad.pratap@xxxxxxxxxx
- In-reply-to: <5fb1c7f40803250743u24479110v42bc00de2c2b22c9@xxxxxxxxxxxxxx>
- Mail-followup-to: Sharad Pratap <sh4r4d@xxxxxxxxx>, zsh-users@xxxxxxxxxx, sharad.pratap@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <5fb1c7f40803250743u24479110v42bc00de2c2b22c9@xxxxxxxxxxxxxx>
On Tue, Mar 25, 2008 at 08:13:45PM +0530, Sharad Pratap wrote:
[...]
> I wanted to use command substitution to assign to $mailpath array.
> but both of `...` and $(...) , failed to do so.
> I have checked about the usage of command substitution in section
> 5.1.5: Backquotes at http://zsh.sunsite.dk/Guide/zshguide05.html
[...]
in list contexts, command substitution is split according to the
$IFS special parameter.
IFS=$'\n'
lines=($(cmd))
$lines[<n>] will contain the <n>th non-empty line in cmd's
output.
To include empty lines:
IFS=$'\n\n'
output=$(cmd; echo .)
output=${output%?}
lines=(${=output%$'\n'})
We need this because $(...) removes all the trailing NL
characters, while we only want to remove the one for the last
line.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author