test.sh:
#! /bin/sh
#引入外部shell
source ./test1.sh
echo -------------------定义输入两个数字---------------------
echo 'input number1:'
read number1
echo 'input number2:'
read number2
echo -------------------对两个数字参数进行算法相加-----------
echo 'number1:',$number1
echo 'number2:',$number2
echo number1+number2:`expr $number1 + $number2`
echo ----------------------------------------if else流程控制----------------------------------------
if(($number1>20))
then
echo number1 too big than 20
elif(($number1>10))
then
echo number1 tobig than 10
else
echo --------------------while循环控制-----------------------
while (($number1>0))
do
#let关键字
let "number1--"
echo number1:$number1
done
fi
echo ----------------------------------------case流程控制----------------------------------------
echo 请输入一个数字:
read number3
case $number3 in
1) echo 你输入了1
;;
2) echo 你输入了2
;;
*) echo 你输入了比2大的数字
esac
echo ------------------------------定义数组---------------------------------
myArray=(a b2 c33 d444 e5555 f66666 g777777)
echo myArray数组长度:${#myArray[*]}
echo myArray[0]:${myArray[0]}
echo myArray[0].length:${#myArray[0]}
echo -----------------------------for循环数组-------------------------------
for str in ${myArray[*]}
do
echo str:$str
done
for((i=0; i<${#myArray[*]}; i++))
do
echo myArray[$i]:${myArray[$i]}
done
echo -----------------------------调用外部shell中的函数取得返回值-------------------
funTest a b c d e f g h i j k l m n o p q
funReturnVal=$?
echo "call fun return val:${funReturnVal}"
test1.sh:
#! bin/sh
funTest(){
echo 参数的个数:$#
echo 所有的参数:$@
return "100"
}