Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load zsh/mapfile in ZSH

I have installed zsh version 5.6.2 via brew. I am having trouble loading mapfile module.

adding zmodload zsh/mapfile mapfile gives error ~/.zshrc:15: failed to load module 'mapfile': dlopen(/usr/local/Cellar/zsh/5.6.2_1/lib/mapfile.bundle, 9): image not found

Anyone know how to debug this or a fix ?

like image 350
Moulick Avatar asked Sep 05 '25 20:09

Moulick


1 Answers

To load the zsh/mapfile module, just run

zmodload zsh/mapfile

You can check that it's correctly loaded with:

zmodload

You should then see the following list of loaded modules:

zsh/complete
zsh/main
zsh/mapfile
zsh/parameter
zsh/zle
zsh/zutil

You can then use it, for example, such as:

# Define a file named pp with three lines
echo yay1 >> pp                                                                     
echo yay2 >> pp
echo yay3 >> pp

# Build the associative array
arr=("${(f@)mapfile[pp]}")

# Show the content
echo $arr[1]
echo $arr[2]
echo $arr[3]

For explanation about the mapfile module see ZSH Gem #22: Accessing and editing files with mapfile.

For details about the Parameter Expansion Flags see the corresponding section in the Zsh documentation.

like image 131
Ortomala Lokni Avatar answered Sep 09 '25 15:09

Ortomala Lokni