3
回答
fedora中shell 脚本的问题

最近在学习shell脚本,但写脚本的时候总是出现一些错误:(我用的是fedora18系统)

1,

#!/bin/bash
#Bash scrip program test,made by wxj
#until do ... done
number=0
until [ $number -gt 10 ] ; do
        echo $number
        number='expr $number + 1'
done

    运行bash until.sh 时总是出现提示:expr $number + 1
                                                   until.sh: 第 5 行:[: 参数太多

2.

#!/bin/bash
#Bash scrip program test,made by wxj
#if elif elif fi


echo 'word1:'
read word1
echo 'word2:'
read word2
echo 'word3:'
read word3
if [ "$word1" = "$word2" -a "$word2" = "%word3" ]; then
        echo 'match:words1,2&3'
elif [ "$word1" = "$word2" ];then
        echo 'match:words1&2'
elif [ "$word1" = "$word3" ];then
        echo 'match:words1&3'
elif [ "$word2" = "$word3" ];then
        echo 'match:words2&3'
else
        echo 'no match'
fi

运行bash if.sh时输入[wxj@localhost scrip]$ bash if.sh
                                                            word1:
                                                            a
                                                            word2:
                                                            a
                                                            word3:
                                                            a
                                                            match:words1&2

输入a a a不是应该输出match:words1,2&3么?

一二是不是说明fedora里面没有-a -gt -lt 之类的命令阿,怎么解决

3.

#!/bin/bash
#Bash scrip program , made by wxj
#fun()

hello()
{
        echo  "Hello today's date is 'date' "
}

echo "enter into hello()"
hello
echo "out of hello()"

运行bash fun.sh时出现:[wxj@localhost scrip]$ bash fun.sh
                                                                 enter into hello()
                                                                 Hello today's date is 'date'
                                                                 out of hello()

这和视频教程里面的结果不一样,输出的第二行不是应该是Hello today's date is 2011年 8月 15日 星期一 22:43:28 cst

初学嵌入式的这段时间以来,遇到了很多问题,多谢大家的帮助。

举报
wanxj
发帖于5年前 3回/641阅
顶部