zsh for 循环排除
这是一个有点简单的问题,但对于我来说,我无法弄清楚如何从 zsh for 循环中排除某些内容。例如,假设我们有这样的情况:
for $package in /home/user/settings/*
do
# do stuff
done
假设在 /home/user/settings/
中,有一个我想忽略的特定目录(“os”)。从逻辑上讲,我尝试了以下变体:
for $package in /home/user/settings/^os (works w/ "ls", but not with a foor loop)
for $package in /home/user/settings/*^os
for $package in /home/user/settings/^os*
......但这些似乎都不起作用。有人可以引导我的语法朝正确的方向发展吗?
This is somewhat of a simple question, but for the life of me, I cannot figure out how to exclude something from a zsh for loop. For instance, let's say we have this:
for $package in /home/user/settings/*
do
# do stuff
done
Let's say that in /home/user/settings/
, there is a particular directory ("os") that I want to ignore. Logically, I tried the following variations:
for $package in /home/user/settings/^os (works w/ "ls", but not with a foor loop)
for $package in /home/user/settings/*^os
for $package in /home/user/settings/^os*
...but none of those seem to work. Could someone steer my syntax in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,额外的
$
可能是导致你悲伤的原因。试试这个:
如果您想将
${package}
限制为仅目录,请使用/home/user/settings/^os(/)
。还要确保您设置了
extendedglob
(我认为您这样做是因为ls
适合您):It looks to me that the extra
$
may be what's causing your grief.Try this:
If you want to limit
${package}
to just directories, use/home/user/settings/^os(/)
.Also ensure that you have
extendedglob
set (which I think you do sincels
works for you):如果我
set -o EXTENDED_GLOB
(或setopt EXTENDED_GLOB
),那么 for 循环对我有用。That for loop works for me if I
set -o EXTENDED_GLOB
(orsetopt EXTENDED_GLOB
).