Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of shell method to determine whether a variable is empty or not

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

How to determine whether a variable is empty in shell

In shell programming, the error check item of a parameter includes whether a variable is assigned (that is, whether a variable is empty). The method to determine whether a variable is empty is as follows:

1. Variables are enclosed in quotation marks

#! / bin/shpara1=if [!-n "$para1"]; then echo "IS NULL" else echo "NOT NULL" fi

[output result] "IS NULL"

two。 Judge directly by variables

#! / bin/shpara1=if [! $para1]; then echo "IS NULL" else echo "NOT NULL" fi

[output result] "IS NULL"

3. Use test to judge

#! / bin/shdmin=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!"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report