您的位置:首页 > 运维架构 > Shell

[linux Shell] 判断当前运行的参数的个数

2014-01-12 18:10 190 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: