Shell脚本中判断输入变量或者参数是否为空的方法 这篇文章主要介绍了Shell脚本中判断输入变量或者参数是否为空的方法,本文总结了5种方法 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....
2.判断输入参数 复制代码代码如下: #!/bin/bash if [ ! -n "$1" ] ;then echo "you have not input a word!" else echo "the word you input is $1" fi 以下未验证。 3. 直接通过变量判断 如下所示:得到的结果为: IS NULL 复制代码代码如下: #!/bin/sh para1= if [ ! $para1 ]; then...
Shell脚本中判断输入变量或者参数是否为空的方法 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 "$...
shell判断⼀个变量是否为空⽅法总结 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" ] ;...
2.判断输入参数 复制代码代码如下: #!/bin/bash if [ ! -n "$1" ] ;then echo "you have not input a word!" else echo "the word you input is $1" fi 以下未验证。 3. 直接通过变量判断 如下所示:得到的结果为: IS NULL 复制代码代码如下: ...
shell判断一个变量是否为空方法总结 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 ...
2.判断输入参数 代码如下: #!/bin/bash if [ ! -n "$1" ] ;then echo "you have not input a word!" else echo "the word you input is $1" fi 以下未验证。 3. 直接通过变量判断 如下所示:得到的结果为: IS NULL 代码如下: #!/bin/sh ...