(zsh 大括号扩展 | seq) 用于字符列表 - 如何?

发布于 2024-08-24 12:47:25 字数 175 浏览 5 评论 0原文

Bash 允许我编写语句,

$ for i in {h..k} ; do echo $i ; done

但 zsh 只允许数字列表扩展,例如 {8..13}

最好的解决方法是什么?类似于字符的 seq...

Bash allows me to write the statement,

$ for i in {h..k} ; do echo $i ; done

but zsh only allows number list expansion such as {8..13}.

What's the best workaround? Something like seq for characters...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗷兮 2024-08-31 12:47:25
zsh$ setopt BRACE_CCL
zsh$ echo {a-k}
a b c d e f g h i j k
zsh$ echo {1-9}
1 2 3 4 5 6 7 8 9

来自 ZSH 文档

BRACE_CCL

在大括号中展开表达式,否则不会
经过大括号扩展为所有按词法排序的列表
人物。请参阅大括号扩展

zsh$ setopt BRACE_CCL
zsh$ echo {a-k}
a b c d e f g h i j k
zsh$ echo {1-9}
1 2 3 4 5 6 7 8 9

From ZSH Documentation:

BRACE_CCL

Expand expressions in braces which would not otherwise
undergo brace expansion to a lexically ordered list of all the
characters. See Brace Expansion.

阿楠 2024-08-31 12:47:25

由于这仍然是 Google 的热门结果,因此更新了答案:

当前版本< /a> 支持 bash 样式 {c1..c2},其中 c1c2 是字符:

{c1..c2}”形式的表达式,其中 c1c2 是单个字符(可能是多字节)个字符),无论内部使用什么字符序列,都会扩展到从 c1c2 范围内的每个字符。对于代码点低于 128 的字符,这是 US ASCII(这是大多数用户需要的唯一情况)。如果任何中间字符不可打印,则使用适当的引号使其可打印。如果字符序列颠倒,则输出顺序相反,例如“{d..a}”将替换为“dcb a”。

这肯定是在 5.0.7 以后出现的。我似乎无法找到 zsh 发布历史记录 中引入此功能的时间,但是 第一个存档版本记录它 表示它是在 2012 年 7 月至 2014 年 11 月期间引入的。

As this is still a top google result, an updated answer:

The current release supports bash style {c1..c2} where c1 and c2 are characters:

An expression of the form ‘{c1..c2}’, where c1 and c2 are single characters (which may be multibyte characters), is expanded to every character in the range from c1 to c2 in whatever character sequence is used internally. For characters with code points below 128 this is US ASCII (this is the only case most users will need). If any intervening character is not printable, appropriate quotation is used to render it printable. If the character sequence is reversed, the output is in reverse order, e.g. ‘{d..a}’ is substituted as ‘d c b a’.

This is definitely present in 5.0.7 onwards. I can't seem to find when this was introduced in the zsh release history, but the first archived version documenting it indicates it was introduced between July 2012 and November 2014.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文