简体   繁体   English

如何在 ZSH 中加载 zsh/mapfile

[英]How to load zsh/mapfile in ZSH

I have installed zsh version 5.6.2 via brew.我已经通过 brew 安装了 zsh 5.6.2 版。 I am having trouble loading mapfile module.我在加载 mapfile 模块时遇到问题。

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添加zmodload zsh/mapfile mapfile给出错误~/.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 ?任何人都知道如何调试这个或修复?

To load the zsh/mapfile module, just run要加载zsh/mapfile模块,只需运行

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 .有关 mapfile 模块的说明,请参阅ZSH Gem #22:使用 mapfile 访问和编辑文件

For details about the Parameter Expansion Flags see the corresponding section in the Zsh documentation .有关参数扩展标志的详细信息,请参阅Zsh 文档中的相应部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM