安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 1.3 shell中的变量 1.3.1 Environment variables ①可写的环境变量 在用户登陆的过程中执行/etc/profile文件进行初始化 ■各个用户自身的启动文件/home/username/.bash profile 可通过set命令显示当前己经设置的环境变量及其值。 7
7 1.3 shell中的变量 1.3.1 Environment variables ①可写的环境变量 ◼ 在用户登陆的过程中执行/etc/profile文件进行初始化 ◼ 各个用户自身的启动文件/home/username/.bash_profile 可通过set命令显示当前已经设置的环境变量及其值
安藏理工大学 ANHUI UNIVERSITY OF SCIKNCE TECHNOLOGY 1.3 shelli中的变量 1.3.1 Environment variables ②只读的环境变量 环境变量 含义 $0 Shell script filename $1~$9 First-ninth command line arguments $* All value of command line arguments $# The number of command line arguments $$ The current process ID $? The exit status of the last command,"O"indicates "success","1"indicates "failure" $刺 the process ID of the last background process Shift < Shift position argument 8
8 1.3 shell中的变量 1.3.1 Environment variables ②只读的环境变量 环境变量 含义 $0 Shell script filename $1~$9 First-ninth command line arguments $* All value of command line arguments $# The number of command line arguments $$ The current process ID $? The exit status of the last command, “0” indicates “success”, “1” indicates “failure” $! the process ID of the last background process Shift <> Shift position argument
安藏理工大学 ANHUI UNIVERSTTY OF SCIENCE TECHNOLOGY 1.3 shelli中的变量 1.3.2 Shell variables defined by Users ■definition: Variable name=string #delimiter may not be used ■citation √$variable name √As a part of a string #at the end of a string string $variable name #at the head of a string or in the middle of a string string1$(variable name)string2 9
9 1.3 shell中的变量 1.3.2 Shell variables defined by Users ◼definition: Variable name=string #delimiter may not be used ◼citation ✓$variable name ✓As a part of a string #at the end of a string ✓string $variable name #at the head of a string or in the middle of a string ✓string1${variable name}string2
安藏理工大学 ANHUI UNIVERSTTY OF SCIENCE TECHNOLOGY 1.4shel川中的特殊字符 1.4.1 Wildcard characters in Shell ■星号* ■问号? ■一对方括号[] 其作用是匹配该字符组所限定的任何一个字符,例如: f[abcd]可以匹配fa,fb,fc,fd f[a-d]与f[abcd]作用相同 ■感叹号 表示否定,例如fa-d].c表示以f打头、第二个字符不是a-d的.c文件名 10
10 1.4 shell中的特殊字符 1.4.1 Wildcard characters in Shell ◼ 星号* ◼问号? ◼一对方括号[ ] 其作用是匹配该字符组所限定的任何一个字符,例如: f[abcd]可以匹配fa,fb,fc,fd f[a-d]与f[abcd]作用相同 ◼感叹号 表示否定,例如f[!a-d].c表示以f打头、第二个字符不是a-d的.c文件名
安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 1.4shel‖中的特殊字符 1.4.2Shel中的引号 双引号” 由它括起来的字符,除$,`,仍保留其特殊功能外,其余字符通常作为普通 字符 ■单引号” 由它括起来的所有字符或字符串都作为普通字符出现。 ■倒引号 由此括起来的字符串被shel解释为命令行,其执行结果取代整个倒引号部 分。例如: Secho current directory is pwd 如果当前工作目录为home/wang的话则输出结果为 current directory is /home/wang 11
11 1.4 shell中的特殊字符 1.4.2 Shell中的引号 ◼ 双引号”” 由它括起来的字符,除$, `, \仍保留其特殊功能外,其余字符通常作为普通 字符 ◼单引号’’ 由它括起来的所有字符或字符串都作为普通字符出现。 ◼倒引号`` 由此括起来的字符串被shell解释为命令行,其执行结果取代整个倒引号部 分。例如: $echo current directory is `pwd` 如果当前工作目录为/home/wang的话则输出结果为 current directory is /home/wang