- 论坛徽章:
- 0
|
大侠们好,我想完成这样的操作,运行一个脚本
test.sh 参数1 参数2 参数3
其中:参数1为任意字符串,参数2,参数3 为日期,格式为 2012-02-03
我想通过脚本,把日期的年,月,日分离出来,脚本如下
- #! /bin/bash
- str=$1
- start_time=$2
- if [ -n "$3" ];then
- end_time=$3
- else
- end_time=$start_time
- fi
- echo $start_time | awk -F'-' '{print $1,$2,$3}' | read start_year start_month start_day
- echo $end_time | awk -F'-' '{print $1,$2,$3}' | read end_year end_mount start_day
- echo $start_year
- echo $start_month
- echo $start_day
复制代码 可是我测试的时候,发现,输出的为空- ./test.sh aaa 2012-02-02 2012-02-03
复制代码 请大侠帮忙看看,是为啥? |
|