Bash uses the regular matching method--shopt-s Extglob

Source: Internet
Author: User

Problem: A log directory with a lot of 00, 01, 02 ... 31 's Date directory, how to list all directories between 00 and 12th numbers. That is, how to use the regular on top of the file name.

Shopt (shell option so understand easy to remember)

$ shopt autocd off cdable_vars off Cdspell off Checkhash off Checkjobs        Off Checkwinsize on Cmdhist on compat31 out compat32 off COMPAT40 off compat41        Off Compat42 off Complete_fullquote on Direxpand out Dirspell off Dotglob off Execfail Off expand_aliases on Extdebug out Extglob on Extquote on Failglob off Force_fignore o N Globstar off globasciiranges off gnu_errfmt out histappend on Histreedit off histverify off H     Ostcomplete off Huponexit off interactive_comments on lastpipe off lithist off Login_shell        Off Mailwarn off no_empty_cmd_completion off Nocaseglob out nocasematch off Nullglob off Progcomp On Promptvars on Restricted_shell off shift_verbose out SourcePath on Xpg_echo off 

Only one configuration item is mentioned here: Extglob

Regular
shopt-u extglob   #关闭bash recognition of shopt-s Extglob #打开bash recognition

After opening, the following 5 pattern matching operators will be recognized:

? (pattern-list)     #所给模式匹配0次或1次
* (pattern-list)     #所给模式匹配0次以上包括0次
+ (pattern-list)     #所给模式匹配1次以上包括1次
@ ( pattern-list)     #所给模式仅仅匹配1次
! ( pattern-list)     #不匹配括号内的所给模式

Problem Resolution: How to List all directories between 00 and 12th.

Ls-al + (0[0-9]|1[0-2])

Description

At ordinary times, the wildcard character of the shell is just the wildcard semantics, not the regular semantics
After adding this extglob, the ability is the regular semantics
Syntax format is + regular

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.