Chinaunix

标题: where the bug in my tiny script [打印本页]

作者: wuxiaobo_2009    时间: 2012-03-09 11:56
标题: where the bug in my tiny script
#!/bin/bash
#Program:
#       This Program shows the "Hello,World"
#History:
#2012/03/09     Hacker          FirstRlease
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH

echo -e "I will use date touch three files\n"
read -p "Your filename:" filename

filename=${filename:-"filename"}

date1=$(date -d '-1 day'+%Y%m%d)
date2=$(date -d '-2 day'+%Y%m%d)
date3=$(date +%Y%m%d)
file1=${filename}${date1}
file2=${filename}${date21}
file3=${filename}${date3}

touch "$file1"
touch "$file2"
touch "$file3"
exit 0

作者: yangkyo821    时间: 2012-03-09 12:08
date1=$(date -d '-1 day'空格+%Y%m%d)
date2=$(date -d '-2 day'空格+%Y%m%d)

file2=${filename}${date21} 这个1去掉

另外,注释也错了。
#       This Program shows the "Hello,World"
不是shows hello world是touches three files

作者: jason680    时间: 2012-03-09 12:39
本帖最后由 jason680 于 2012-03-09 12:40 编辑

set -x

授之于鱼 授之于渔
作者: wuxiaobo_2009    时间: 2012-03-09 12:43
回复 2# yangkyo821


    Thank you !  
作者: Shell_HAT    时间: 2012-03-09 12:57
建议找个支持语法高亮的编辑器写脚本
作者: wuxiaobo_2009    时间: 2012-03-09 16:28
回复 5# Shell_HAT

能发一个vim 的配置吗? 您觉得好的,能高亮能检错的(语法)
   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2