收集了二个参数传递的例子,供正在学习shell的朋友参考。
复制代码代码如下:
#!/bin/sh
echo "program name is $0" echo "there are totally $# parameters passed to this program"; echo "the last is $?"; echo "the parameter are $*";
位置参数:$0表示程序名字 ¥1表示传递给程序的第一个参数
利用内部变量和位置参数编写一个名为test2的简单删除程序,
复制代码代码如下:
#!/bin/sh
(责任编辑:IT)if test $# -eq 0 then ehco "please specify a file!" else gzip $1 //现对文件进行压缩 mv $1.gz $HOME $1 is deleted !" //移动到回收站 fi |