linux – bash脚本中的[…]代表什么?

linux – bash脚本中的[…]代表什么?,第1张

概述我正在阅读 this教程,我遇到了bash脚本使用[…]作为外卡字符.那么究竟什么[…]站在bash脚本中? 它是一种正则表达式的字符匹配语法;从 Bash Reference Manual, §3.5.8.1 (Pattern Matching): [...] Matches any one of the enclosed characters. A pair of characters sep 我正在阅读 this教程,我遇到了bash脚本使用[…]作为外卡字符.那么究竟什么[…]站在bash脚本中?解决方法 它是一种正则表达式的字符匹配语法;从 Bash Reference Manual,§3.5.8.1 (Pattern Matching):

[...]
Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range Expression; any character that sorts between those two characters,inclusive,using the current locale’s collating sequence and character set,is matched. If the first character following the ‘[’ is a ‘!’ or a ‘^’ then any character not enclosed is matched. A ‘−’ may be matched by including it as the first or last character in the set. A ‘]’ may be matched by including it as the first character in the set. The sorting order of characters in range Expressions is determined by the current locale and the value of the LC_ColLATE shell variable,if set.

For example,in the default C locale,‘[a-dx-z]’ is equivalent to ‘[abcdxyz]’. Many locales sort characters in dictionary order,and in these locales ‘[a-dx-z]’ is typically not equivalent to ‘[abcdxyz]’; it might be equivalent to ‘[aBbCcDdxXyYz]’,for example. To obtain the Traditional interpretation of ranges in bracket Expressions,you can force the use of the C locale by setting the LC_ColLATE or LC_ALL environment variable to the value ‘C’.

Within ‘[’ and ‘]’,character classes can be specifIEd using the Syntax [:class:],where class is one of the following classes defined in the posix standard:

alnum   Alpha   ascii   blank   cntrl   digit   graph   lower          print   punct   space   upper   word    xdigit

A character class matches any character belonging to that class. The word character class matches letters,digits,and the character ‘_’.

Within ‘[’ and ‘]’,an equivalence class can be specifIEd using the Syntax [=c=],which matches all characters with the same collation weight (as defined by the current locale) as the character c.

Within ‘[’ and ‘]’,the Syntax [.symbol.] matches the collating symbol symbol.

(重点添加到最常见的使用模式)

总结

以上是内存溢出为你收集整理的linux – bash脚本中的[…]代表什么?全部内容,希望文章能够帮你解决linux – bash脚本中的[…]代表什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1021388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存