How to determine whether a variable is empty in shell In shell programming, the error checking items for parameters include whether the variable is assigned a value (that is, whether a variable is empty). The method to determine whether a variable is empty is as follows: 1. Variables are enclosed in " " quotes #!/bin/sh para1= if [ ! -n "$para1" ]; then echo "IS NULL" else echo "NOT NULL" fi [Output result] "IS NULL" 2. Judge directly by variables #!/bin/sh para1= if [ ! $para1 ]; then echo "IS NULL" else echo "NOT NULL" fi [Output result] "IS NULL" 3. Use test to judge #!/bin/sh dmin= if test -z "$dmin" then echo "dmin is not set!" else echo "dmin is set !" fi 【Output result】"dmin is not set!" 4. Use "" to judge #!/bin/sh dmin= if [ "$dmin" = "" ] then echo "dmin is not set!" else echo "dmin is set !" fi 【Output result】"dmin is not set!" You may also be interested in:
|
<<: How to use regular expression query in MySql
>>: A brief talk about the knowledge you need to master when getting started with Vue
Create a project directory mkdir php Create the f...
1. Download the corresponding installation file f...
Download tutorial of mysql-connector-java.jar pac...
DIV background is semi-transparent, but the words ...
Table of contents What is VUE Core plugins in Vue...
Table of contents Preface Setting up slow query l...
Table of contents 1. watch monitoring properties ...
They are all web page templates from the foreign ...
This article shares the specific code of Vue to i...
Preface In order to follow the conventional WEB l...
Table of contents 1. Overview 2. Name field 3. Ve...
Mixins provide distributed reusable functionality...
When starting MongoDB, the prompt is: error while...
Table of contents 1. Demo Project 1.1 Interface P...
1. Introduction People who are not used to Englis...