科技界 新科技新应用
首页 /  科普知识 /  内容

shell判断输入参数为空

科普知识 2024-10-04 23:02:10 安静观看

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

版权申明:文章由用户发布,不代表本网站立场,如果侵权请联系我们删除。