shell脚本--01处理用户输入


#!/bin/bash
#using one command line parameter
#循环
# factorial=1 for ((number = 1; number <= $1 ; number++)) do factorial = $[ $factorial * $number ] done echo The factorial of $1 is $factorial
 

$ ./test1/sh 5
The factorial of 5 is 120
#!bin/bash
#Testing a Multi-function script
#条件
# name
=$(basename $0) # if [ $name = "addem" ] then total=$[ $1 + $2 ] elif [ $name = "multem" ] then total=$[ $1 * $2 ] fi # echo The calculated value is $total
$ ./addem 2 5
The calculated value is 7
$ ./multem 2 5
The caloulated value is 10
#!bin/bash
#testing parameters before use
#判断参数存在吗
#
if [ -n "$1" ] then echo Hello $1, glad to meet you. else echo "Sorry,you did not identify yourself" fi

$ ./tst.sh Rich

Hello Rich ,glad to meet you.

原文地址:https://www.cnblogs.com/cevinchen/p/9410380.html