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
本文介绍如何使用Bash进行变量和参数的条件判断,包括检查输入是否为空及特定数值条件下的不同脚本执行流程。通过示例展示了在系统启动时根据不同输入参数执行不同应用程序的方法。
1万+

被折叠的 条评论
为什么被折叠?



