1.判断变量
read -p "input a word :" word
if [ ! -n "$word" ] ;then
echo "you have not input a word!"
else
echo "the word you input is $word"
fi
2.判断输入参数
#!/bin/bash
if [ ! -n "$1" ] ;then
echo "you have not input a word!"
else
echo "the word you input is $1"
fi
下面是我在某项目中写的一点脚本代码, 用在系统启动时:
#! /bin/bash
echo "Input Param Is [$1]"
if [ ! -n "$1" ] ;then
echo "you have not input a null word!"
./app1;./app12;./app123
elif [ $1 -eq 2 ];then
./app12;./app123
elif [ $1 -eq 90 ];then
echo "yy";
fi