红联Linux门户
Linux帮助

为什么脚本这么奇怪呢

发布时间:2009-06-11 17:17:26来源:红联作者:sunzengbiao
脚本程序:
date2=20100212
declare -i date_dem=`date --date="$date2" +%s`
declare -i date_now=`date +%s`
declare -i date_total_s=$(($date_dem-$date_now))
declare -i date_d=$(($date_total_s/60/60/24))
执行后:
sun@sun:~$ sh -x sh05.sh
+ date2=20100212
+ date --date=20100212 +%s
+ declare -i date_dem=1265904000
sh05.sh: 1: declare: not found
+ date +%s
+ declare -i date_now=1244711526
sh05.sh: 1: declare: not found
sh05.sh: 4: arithmetic expression: expecting primary: "-"
而我把脚本程序一句一句的执行结果就出来了,一点问题都没有,可是为什么一起执行就不可以呢?
文章评论

共有 5 条评论

  1. 小普林斯 于 2009-06-11 21:06:37发表:

    :0w5ty(1

  2. sunzengbiao 于 2009-06-11 20:40:54发表:

    已经解决了,按我的理解是,你用的什么shell,执行指令就用什么

  3. 相思爱文 于 2009-06-11 20:19:48发表:

    不懂脚本,但我看过的脚本开头第一句都是
    #!/bin/bash

  4. sunzengbiao 于 2009-06-11 18:02:25发表:

    说是declare没有定义,我把它去了,结果执行起来没有问题,但是问题是declare是 shell的内置命令啊,怎么会not found呢

  5. wwl910 于 2009-06-11 17:53:27发表:

    嘿嘿