gpt4 book ai didi

Linux 庆典 : How can I use the eval command correctly?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:37 26 4
gpt4 key购买 nike

我可以在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com