作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我可以在 Linux 命令行上运行以下命令,它会正确列出所有具有 ABC- 和 XYZ- 前缀的文件:
ls {ABC-,XYZ-}*.xml
Result: ABC-01.xml ABC-02.xml ABC-03.xml XYZ-01.xml XYZ-02.xml
现在,我想我可以使用如下变量:
file_pfx={ABC-,XYZ-}
然后将“ls”命令中的变量与“eval”结合使用:
eval 'ls ${file_pfx}*.xml'
Result: ls: {ABC-,XYZ-}*.xml: No such file or directory
我做错了什么?
谢谢
最佳答案
不要使用评估。您可以改用扩展的 globbing:
#! /bin/bash
shopt -s extglob
prefix='ABC-|XYZ-'
ls @($prefix)*.xml
关于Linux 庆典 : How can I use the eval command correctly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775995/
我是一名优秀的程序员,十分优秀!