如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
深入浅出Shell编程:Shell变量HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"深入浅出Shell编程:Shell变量"深入浅出Shell编程:Shell变量HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"1系统变量"1系统变量HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"2Shell用户变量"2Shell用户变量HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"2.1基础"2.1基础HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"2.2使用技巧"2.2使用技巧HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"2.3shell中的数组"2.3shell中的数组HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro"\l"3shell环境变量"3shell环境变量先不要管Shell的版本,来看看Shell变量,在Shell中有三种变量:系统变量,环境变量,用户变量。其中用户变量在编程过程中使用最多,系统变量在对参数判断和命令返回值判断会使用,环境变量主要是在程序运行的时候需要设置。1系统变量Shell常用的系统变量并不多,但却十分有用,特别是在做一些参数检测的时候。下面是Shell常用的系统变量HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro?sortcol=0;table=1;up=0"\l"sorted_table"\o"Sortbythiscolumn"表示方法HYPERLINK"http://www.stlchina.org/twiki/bin/view.pl/Main/SSVariableIntro?sortcol=1;table=1;up=0"\l"sorted_table"\o"Sortbythiscolumn"描述$n$1表示第一个参数,$2表示第二个参数...$#命令行参数的个数$0当前程序的名称$?前一个命令或函数的返回码$*以"参数1参数2..."形式保存所有参数$@以"参数1""参数2"...形式保存所有参数$$本程序的(进程ID号)PID$!上一个命令的PID其中使用得比较多得是$n$#$0$?,看看下面的例子:BeautifierPluginError:Unabletohandle"bash"syntax.#!/bin/sh#Thisfileisusedtoexplaintheshellsystemvariable.echo"thenumberofparameteris$#";echo"thereturncodeoflastcommandis$?";echo"thescriptnameis$0";echo"theparametersare$*";echo"\$1=$1;\$2=$2";下面是运行结果:BeautifierPluginError:Unabletohandle"bash"syntax.-bash-2.05b$./chapter2.1.shwinterstlchinathenumberofparameteris2thereturncodeoflastcommandis0thescriptnameis./chapter2.1.shtheparametersarewinterstlchina$1=winter;$2=stlchina这个例子太简单了,一点也不实用,下面来个实用的,如果你看不懂,没有关系,后面的内容会有详细解释。BeautifierPluginError:Unabletohandle"bash"syntax.#!/bin/shif[$#-ne2];thenecho"Usage:$0stringfile";exit1;figrep$1$2;if[$?-ne0];th