遍历 fish 中的字母 shell

Iteration through letters in fish shell

在bash我可以:

for i in /dev/sd{b..g}; do pvcreate $i; done

在 fish 中寻找这个循环的等价物。

for i in /dev/sd{b..g}
    pvcreate $i
end

Returns 设备/dev/sdb..g 未找到(或被过滤忽略)。 错误

没有直接翻译:fish 只处理大括号内的逗号分隔元素 -- https://fishshell.com/docs/current/index.html#expand-brace

你也不能 for i in /dev/sd[b-g] 因为 fish 不使用字符集作为 globbing 中的通配符 -- https://fishshell.com/docs/current/index.html#expand-wildcard

您最终调用了一些外部程序来生成该文件列表,并且您知道 bash 有效,所以:

for i in (bash -c 'printf "%s\n" /dev/sd{b..g}'); ...

这是fish's design principles之一的示例:

Everything that can be done in other shell languages should be possible to do in fish, though fish may rely on external commands in doing so.