shell判断输入的参数是否为空

2025-01-01 00:01:36 手机知识百科

shell判断输入变量或者参数是否

判断变量为空

1. 。if [ ! -n "$word" ] ;then echo "you have not input a word" else echo "the word you input is $word" fi

2. 直接判断。if [ ! "$word" ] ;then echo "you have not input a word" else echo "the word you input is $word" fi

3. 通过test判断。if test -z "$word" ;then echo "you have not input a word" else echo "the word you input is $word" fi

版权说明: 本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。