[linux Shell] 判断当前运行的参数的个数
1.
$1--代表第一个参数
-n --表示非none
#!/bin/sh
if [ -n "$1" ]
then
echo "has params\n"
else
echo "no params"
fi
2.
$#代表参数个数
-ne表示非空且等于 not none and equal
if [ $# -ne 2 ]
then
echo "has params"
else
echo "no params"
fi
1.
$1--代表第一个参数
-n --表示非none
#!/bin/sh
if [ -n "$1" ]
then
echo "has params\n"
else
echo "no params"
fi
2.
$#代表参数个数
-ne表示非空且等于 not none and equal
if [ $# -ne 2 ]
then
echo "has params"
else
echo "no params"
fi