To determine whether the variables in a script are empty, I wrote a shell script like this:
- #! /Bin/sh
- # Filename: Test. Sh
- Para1 =
- If [! -N $ para1]; then
- Echo "is null"
- Else
- Echo "not null"
- Fi
Then run the Script: test. sh uses chmod + X to change the script that can be executed. After execution, the output result is not null, which is very strange. Finally, it is found by querying some data, you can determine whether a shell variable is null by using the following method:
1. variables are enclosed by quotation marks.
The result is null.
- #! /Bin/sh
- Para1 =
- If [! -N "$ para1"]; then
- Echo "is null"
- Else
- Echo "not null"
- Fi
2. Directly determine through Variables
The result is: Is null.
- #! /Bin/sh
- Para1 =
- If [! $ Para1]; then
- Echo "is null"
- Else
- Echo "not null"
- Fi
3. Use test to determine
The result is: dmin is not set!
- #! /Bin/sh
- Dmin =
- If test-z "$ dmin"
- Then
- Echo "dmin is not set! "
- Else
- Echo "dmin is set! "
- Fi
4. Use "" to judge
- #! /Bin/sh
- Dmin =
- If ["$ dmin" = ""]
- Then
- Echo "dmin is not set! "
- Else
- Echo "dmin is set! "
- Fi