[root@work shell_example]# cat params.sh
#!/bin/bash
#传参测试脚本
echo "My name is `basename $0` -I was called as $0"
echo "My first parameter is : $1"
echo "My second parameter is : $2"
不穿入参数
[root@work shell_example]# sh params.sh
My name is params.sh -I was called as params.sh
My first parameter is :
My second parameter is :
传入两个参数
[root@work shell_example]# sh params.sh one two
My name is params.sh -I was called as params.sh
My first parameter is : one
My second parameter is : two
传入参数时间案例:不传入时间及当前时间,否则为传入时间
if [ -n "$1" ];
then
day=$1
else
day=$(date "+%Y%m%d" -d "-1day")
fi
echo "开始统计数据:" ${day}