$ color = lavender
$ cat color1
echo you are now running program: color1
echo the value of the variable color is : $color
$ chmod +x color1
$ color1
you ar now running program : color1
the value of the variable color is :
$ export color
$ color1
you are now running program : color1
the value of the variable color is : lavender
echo The original value of
the variable color is $color
ech0 This program will set
the value of color to amber
color=amber
echo The value of color is now $color
echo When your program concludes,
display the value of the color variable
观察在你设置了color的值后有什么变化。输出这个变量,然后执行color2:
$ export color=lavender
$ echo $color
lanvender
$ color2
The original value of the
variable color is lavender
The program will set the
value of color to amber
The value of volor is now amber
When your progam concludes,
display the value of the color variable,
$ echo $color
lanvender
$ cat color3
echo you are now running program: $0
echo The value of command
line argument \#1 is: $1
echo The value of command
line argument \#2 is : $2
$ chmod +x color3
$ color3 red green
You are now running program: color3
The value of command line argument
#1 is : red
The value of command line argument
#2 is: green
大多数的UNIX系统命令可以接收命令行参数,这些参数通常告诉命令它将要操作的文件或目录(cp f1 f2),另外指定的参数扩展命令的能力(ls –l),或者提供文本字符串(banner hi there)
$ cat > my_install
echo $0 will install
$1 to your bin directory
chmod +x $1
mv $1 $HOME/bin
echo Installation of $1 is complete
ctrl + d
$ chmod +x my_intalll
$ my_install color3
my_install will install color3
to your bin directory
Installation of color3 is complete
$