[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

posted @ 2013-11-27 22:18  akingseu  阅读(1278)  评论(0编辑  收藏  举报