From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9548 invoked by alias); 19 Nov 2015 20:15:03 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20968 Received: (qmail 23155 invoked from network); 19 Nov 2015 20:15:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=/RFpV4/izv4pvzpyRCQDxj9g7mASusFklxPNLvZmlNU=; b=0slDJH9/nHn7ySSfHNLDHzQAY3tQNw0Pj5birUSwZk8fgHjcYcK7VKdFq4pqWOiKav 1nIGDGtbf4e86x9vSFeK+sZNVAFM9ipcEo7Y+XNWGkklvkNQLHlEESyLaJkXZ6V0q7bn GQKMKqlgNc7JWNskK9Hp8DoA+CgUdFLxHsjXd9YizLOml7GRY1xmNxoKeYFJ0WzXiuCY U4koU6vbesI1uPapqPvC1ycA7kq2Qoar9/0+Vfb+LAROx0gMCqZ9T8W7YndAHGKcbuXK cl6Va/e9r+J1rAM0uH7wyOupi+eqLAqMSoY//kmOKvvUjZHz8uW6tnQ38lC7Gv9I7B6o vf0g== X-Received: by 10.112.205.10 with SMTP id lc10mr4203387lbc.31.1447964099267; Thu, 19 Nov 2015 12:14:59 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <151119111749.ZM8874@torch.brasslantern.com> References: <151119111749.ZM8874@torch.brasslantern.com> From: Sebastian Gniazdowski Date: Thu, 19 Nov 2015 21:14:39 +0100 Message-ID: Subject: Re: Read file with escaped newlines into array To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 On 19 November 2015 at 20:17, Bart Schaefer wrote: > On Nov 19, 6:34pm, Sebastian Gniazdowski wrote: > } > } fc -W stores history to a given file. It escapes newlines with \. How > } to read such file into array and have "\^M" lines put back together > } into single array entries? > > The best way is probably to use the history mechanism to read it: > > () { fc -ap -R the_given_file ; the_desired_array=( ${history} ) } > > Although the docs don't yet say so, the special associative array > $history is not implemented as a hash table, so the entries are > guaranteed to be in a fixed order from most recent (largest history > number) to longest ago. Which is the reverse of the way you'd read > them from the file, so you might want ${(Oa)the_desired_array} when > referencing. The way $history is implemented is crucial to me and solves my problem. I needed ordered history started from most recent, without "\n" substituted for newlines, and "$history[@]" does that. Thanks. This could be mentioned in documentation just to protect that functionality Best regards, Sebastian Gniazdowski