使用常规的前pression在bash中,如果条件

编程入门 行业动态 更新时间:2024-10-27 06:32:31
本文介绍了使用常规的前pression在bash中,如果条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道的一般规则在bash使用常规的前pression在if语句?

I wonder the general rule to use regular expression in if clause in bash?

下面是一个例子。

$ gg=svm-grid-ch $ if [[ $gg == *grid* ]] ; then echo $gg; fi svm-grid-ch $ if [[ $gg == ^....grid* ]] ; then echo $gg; fi $ if [[ $gg == ....grid* ]] ; then echo $gg; fi $ if [[ $gg == s...grid* ]] ; then echo $gg; fi $

为什么最后三个不匹配?

Why the last three fails to match?

希望你可以给尽可能多的一般规则成为可能,不只是在这个例子。

Hope you could give as many general rules as possible, not just for this example.

推荐答案

在使用glob模式,一个问号重新presents单个字符,并重新$ P $星号psents零个或多个字符的序列:

When using a glob pattern, a question mark represents a single character and an asterisk represents a sequence of zero or more characters:

if [[ $gg == ????grid* ]] ; then echo $gg; fi

在使用常规的前pression,点重新presents单个字符,并重新presents零个或多个preceding字符的星号。因此,。* 重presents零个或多个任意字符, A * 重新presents零个或多个一, [0-9] * 重presents零个或多个数字。另一种有用的酮(其中许多)是重新presents一个或多个preceding字符的加号。因此, [A-Z] + 重presents一个或多个小写字母字符(在C语言环境 - 和其他一些)。

When using a regular expression, a dot represents a single character and an asterisk represents zero or more of the preceding character. So ".*" represents zero or more of any character, "a*" represents zero or more "a", "[0-9]*" represents zero or more digits. Another useful one (among many) is the plus sign which represents one or more of the preceding character. So "[a-z]+" represents one or more lowercase alpha character (in the C locale - and some others).

if [[ $gg =~ ^....grid.*$ ]] ; then echo $gg; fi

更多推荐

使用常规的前pression在bash中,如果条件

本文发布于:2023-06-10 16:30:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/615053.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:常规   条件   pression   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!