linux-tutorial/codes/shell/demos/function/function-demo2.sh

24 lines
348 B
Bash
Raw Normal View History

2019-03-01 14:43:49 +08:00
#!/usr/bin/env bash
2019-03-01 15:27:33 +08:00
x=0
if [[ -n $1 ]]; then
echo "第一个参数为:$1"
x=$1
else
echo "第一个参数为空"
fi
y=0
if [[ -n $2 ]]; then
echo "第二个参数为:$2"
y=$2
else
echo "第二个参数为空"
fi
2019-03-01 14:43:49 +08:00
paramsFunction(){
echo "函数第一个入参:$1"
echo "函数第二个入参:$2"
}
2019-03-01 15:27:33 +08:00
paramsFunction ${x} ${y}