最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Unix shell 使用 Bash 中的 globstart 选项使用教程
时间:2015-03-10 编辑:简简单单 来源:一聚教程网
在使用一些命令时(如:ls、git),刚好遇到一些需求是想很方便地遍历所有的目录和文件,后来经过搜索,终于找到了一个“神奇”的通配符 “**”(两个星号),在设置了Bash的globstar选项后,**就可以匹配任当前何目录(包括子目录)以及其中的文件。所以,了解了一下 globstar这个选项,当未设置globstar时,**通配符的作用和*是相同的,而设置了globstar后,**的匹配范围不同了(更广一些)。注意:globstar是Bash 4.0才引入的选项,之前的老版本是不支持的,使用“bash –version”可产看当前使用的Bash的版本。
关于glob这个词,我也觉得好奇,中文不好解释,大致就是“对通配符展开”的意思,如下的英文吧:
In shell-speak, globbing is what the shell does when you use a wildcard in a command (e.g. * or ?). Globbing is matching the wildcard pattern and returning the file and directory names that match and then replacing the wildcard pattern in the command with the matched items.
在bash的man page中,对globstar的说明提到只两次,说的都是同一件事情,如下:
代码如下 | 复制代码 |
Pathname Expansion ...... * Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories. ...... globstar If set, the pattern ** used in a pathname expansion context will match a files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match. |
写了个测试和学习globstar的shell脚本如下:
代码如下 | 复制代码 |
#!/bin/bash
|
相关文章
- scp命令报“bash: scp: command not found lost connection”解决办法 04-17
- Bash 如何批量 disable/enable Jenkins jobs 03-08
- win11内核隔离和内存完整性介绍 10-31
- win10全屏缩放设置教程 10-31
- win10系统备份出错解决教程 10-31
- win10打开软件每次都要询问解决教程 10-31