fish - 遍历鱼壳中的字母
问题描述
在 bash 中,我可以:
for i in /dev/sd{b..g}; do pvcreate $i; done
在鱼中寻找与此循环等效的内容。
for i in /dev/sd{b..g}
pvcreate $i
end
返回设备 /dev/sdb..g 未找到(或被过滤忽略)。错误
解决方案
没有直接翻译:fish 只在大括号内使用逗号分隔的元素——https: //fishshell.com/docs/current/index.html#expand-brace
你也不能这样做for i in /dev/sd[b-g]
,因为fish在通配符中不使用字符集作为通配符——https: //fishshell.com/docs/current/index.html#expand-wildcard
您最终会调用一些外部程序来生成该文件列表,并且您知道 bash 有效,因此:
for i in (bash -c 'printf "%s\n" /dev/sd{b..g}'); ...
这是fish的设计原则之一的示例:
可以在其他 shell 语言中完成的所有事情都应该可以在 fish 中完成,尽管 fish 在这样做时可能依赖外部命令。
推荐阅读
- java - 访问内部类变量到另一个方法
- android - 如何在 Kotlin Android 中为数据类创建构造函数?
- coq - 强制立即类型类实例解析
- ios - ios UITableview 单个单元格上的多个选择选项?
- docker - 如何从两台外部机器进行卷共享
- bootstrap-4 - bootstrap 如何知道屏幕尺寸是多少?
- kubernetes - Azure Functions 支持使用在 Kubernetes 中运行的 HTTP 触发器进行身份验证
- authentication - Okta 在登录特定操作后重新输入密码
- javascript - HTML属性值通过javascript更改后返回其初始值
- github - 如何获取 Github 提交的链接?