Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Read file with escaped newlines into array



On 10 May 2016 at 18:15, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, May 10, 2016 at 7:26 AM, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
>> On 19 November 2015 at 20:17, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>>
>>>     () { fc -ap -R the_given_file ; the_desired_array=( ${history} ) }
>>
>> This works, but I wonder, how it's possible that zsh/parameter
>> variables such as $historywords are made local?
>
> Special parameters can be made local simply by declaring them so.  Or
> are you asking "how" in the sense of what is done internally to make
> it work?
>
> In the case of $history et al., internally they reference the history
> data structures directly, so "fc -p" implicitly makes $history refer
> to the new temporary history, and then switch back to the real history
> on "fc -P"; it isn't necessary to declare it local when using "fc
> -ap".

I use $history to refer to main history and also load a private
history by using the code you gave, and they don't interfere. You used
anonymous function suggesting $history is being localized and that's
how it in practice works. Read the manual (second time), it's -a that
makes the temporary structure switched to by fc -p to be automatically
dropped. Convenient.

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author