test.sh:

    1. #! /bin/sh
    2. #引入外部shell
    3. source ./test1.sh
    4. echo -------------------定义输入两个数字---------------------
    5. echo 'input number1:'
    6. read number1
    7. echo 'input number2:'
    8. read number2
    9. echo -------------------对两个数字参数进行算法相加-----------
    10. echo 'number1:',$number1
    11. echo 'number2:',$number2
    12. echo number1+number2:`expr $number1 + $number2`
    13. echo ----------------------------------------if else流程控制----------------------------------------
    14. if(($number1>20))
    15. then
    16. echo number1 too big than 20
    17. elif(($number1>10))
    18. then
    19. echo number1 tobig than 10
    20. else
    21. echo --------------------while循环控制-----------------------
    22. while (($number1>0))
    23. do
    24. #let关键字
    25. let "number1--"
    26. echo number1:$number1
    27. done
    28. fi
    29. echo ----------------------------------------case流程控制----------------------------------------
    30. echo 请输入一个数字:
    31. read number3
    32. case $number3 in
    33. 1) echo 你输入了1
    34. ;;
    35. 2) echo 你输入了2
    36. ;;
    37. *) echo 你输入了比2大的数字
    38. esac
    39. echo ------------------------------定义数组---------------------------------
    40. myArray=(a b2 c33 d444 e5555 f66666 g777777)
    41. echo myArray数组长度:${#myArray[*]}
    42. echo myArray[0]:${myArray[0]}
    43. echo myArray[0].length:${#myArray[0]}
    44. echo -----------------------------for循环数组-------------------------------
    45. for str in ${myArray[*]}
    46. do
    47. echo str:$str
    48. done
    49. for((i=0; i<${#myArray[*]}; i++))
    50. do
    51. echo myArray[$i]:${myArray[$i]}
    52. done
    53. echo -----------------------------调用外部shell中的函数取得返回值-------------------
    54. funTest a b c d e f g h i j k l m n o p q
    55. funReturnVal=$?
    56. echo "call fun return val:${funReturnVal}"

    test1.sh:

    1. #! bin/sh
    2. funTest(){
    3. echo 参数的个数:$#
    4. echo 所有的参数:$@
    5. return "100"
    6. }