Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Apparent inconsistency in f/z expansion flags behavior
- X-seq: zsh-users 22235
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Apparent inconsistency in f/z expansion flags behavior
- Date: Sun, 18 Dec 2016 18:08:07 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=/6J7uWVryosJBluMSu6G4eaK4TKtBsO6m8khYD3f2E0=; b=kxQstZ2lz2UEaAxeWy76i/6zucx70OYTpw6/Ql10eUA6vjJbPqM2mk5AkhZEWgaoeB FZnwrc+q5Mup2FKbqAbRvaz00+jJ3b774WcRa/fEl7OWVOvZIoHyRn41XCZeJZ/2gFSO zRXITDvZ3u4yG8UZMQVEa8n+wLcb6hLDqkp2Nrt5wyqnWn8AkeTNylcXAFdyDCP8AAlu sQaECy/gJmzyH3TMpS5KeSFtdDmD5KUKiky3o/LpfPx5d6SeGPzS/Hxoml/CwDr7E1zJ MxkbZbXOKxBSwevPM9RZTCtB4IUd+i1eNj2cgPyAj29kkKI/BfaPqk+klvP48/MDkiss ugbA==
- In-reply-to: <CAAiKvi0Ge4-9016srG4K5-3-VnwCXN5FcKtsjGtE6GjG8ZwGsA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAAiKvi0Ge4-9016srG4K5-3-VnwCXN5FcKtsjGtE6GjG8ZwGsA@mail.gmail.com>
On Dec 18, 8:02pm, Pablo Lalloni wrote:
}
} words=(${(z)$(</proc/meminfo)})
}
} Which set words with the array of all the words in the file and that's
} great.
}
} lines=(${(f)$(</proc/meminfo)})
}
} But then I get an array with just one string containing all the lines
} concatenated (no NLs).
That's happening because $(</proc/meminfo) has replaced all the NLs with
spaces before (z) or (f) begin working. (z) doesn't care because it
splits on shell-syntax whitespace, but (f) has nothing to split on.
To get what you want, you have to quote the $(...) substitution so the
NLs are preserved:
lines=(${(f)"$(</proc/meminfo)"})
That would be "more correct" in the (z) use as well, just in case the
line breaks were e.g. inside quoted strings that would change the shell
parse. (Not an issue with /proc/meminfo, of course, but in general.)
} Note that if you split the last assignment in 2 steps, it works as expected:
}
} lines=$(</proc/meminfo)
} lines=(${(f)lines})
There you've done first an assignment to a scalar, which preserves the
NLs as if $(...) were quoted.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author