Bash脚本编程

变量

局部变量和全局变量(环境变量)

declare -i int_var

Bash中的元字符

Bash中的元字符是一些有着特殊含意的字符, 在Bash的解释中不是按照字面含意来解释的:

Charactors Meaning
* ? [ ] ~ + - @ ! Filename metacharactors

Filename Metacharactors

In computer programming, the verb glob or globbing is used to refer to an instance of pattern matching behavior. The noun "glob" is sometimes used to refer to a particular pattern, e.g. "use the glob .log to match all those log files".

Bash用来匹配文件名的元字符:

               匹配零个或者多个字符
 ?              匹配单个字符
 [abc...]       匹配包含在集合中任意字符
 [!abc...]      匹配不包含在集合中的任意字符
 [a-zA-Z0-9]    匹配指定的字符范围中的字符
                (可移植性不强,根据区域设置,字符范围可能包含其他字符)
 ~              当前用户的Home目录
 ~name          name用户的Home目录
 ~+             当前的工作目录($PWD)
 ~-             上次的工作目录($OLDPWD)

如果打开Bash选项extglob

 ?(pattern)

glob

Bash中的特殊字符是由Bash解释的非字面意义的字符(或者字符组):

$

.

?

*

[]

()

^

Wiki comments powered by Disqus