shell - zsh:解析zsh命令参数中使用的变量中的通配符?
问题描述
ls *.txt
显示名称以结尾的所有文件.txt
但是,如果我在 zsh shell 上执行以下操作:(在我的情况下,在 macOS 10.15 Catalina 上)
a=*.txt
b='*.txt'
c="*.txt"
# trying no quotes, single quotes, double quotes
# although doesn't make any difference here
ls $a
ls $b
ls $c
ls "$a"
ls "$b"
ls "$c"
我越来越
ls: *.txt: 没有这样的文件或目录
在所有情况下。如何在变量中包含通配符,然后让命令像ls
实际将其作为通配符处理,而不是文字字符?
解决方案
您应该在和变量名~
之间使用(波浪号)$
在 zsh 中执行通配符。那是
ls $~a
推荐阅读
- python - Python 3:通过套接字发送文件。(客户端-服务器程序)
- r - 基于没有特定标题的excel电子表格组合文件夹中的多个excel文件
- amazon-web-services - 如何远程运行脚本?
- salesforce - 如何获取顶点页面中使用的所有自定义标签信息?
- scala - 如何检查akka actor中的存储大小
- json - 将嵌套的 JSON 解码为采用 Decodable 的结构
- highcharts - 具有绝对长度的连通向量的 Highcharts 向量图
- r - 使用空列表启动数据框中的元素
- cucumber - Gherkin:带有双引号元素的字符串的步骤定义
- json - package.json 出错