1. Judging variables
Copy Code code as follows:
Read-p "Input a word:" Word
if [!-n "$word"]; then
echo "You have not input a word!"
Else
echo "The word you are $word"
Fi
2. Judging input parameters
Copy Code code as follows:
#!/bin/bash
if [!-n ' $ ']; then
echo "You have not input a word!"
Else
echo "The word you are the input is $"
Fi
The following is not validated.
3. Directly through the variable judgment
As follows: The result is NULL
Copy Code code as follows:
#!/bin/sh
para1=
if [! $para 1]; Then
echo "is NULL"
Else
echo "Not NULL"
Fi
4. Use test to judge
The result is that DMin is not set!
Copy Code code as follows:
#!/bin/sh
dmin=
If Test-z "$dmin"
Then
echo "DMin is not set!"
Else
echo "DMin is set!"
Fi
5. Use "" to determine
Copy Code code as follows:
#!/bin/sh
dmin=
If ["$dmin" = ""]
Then
echo "DMin is not set!"
Else
echo "DMin is set!"
Fi
Here's a little bit of scripting code I wrote in a project that I used when the system started:
Copy Code code as follows:
#! /bin/bash
echo "Input Param is [$]"
if [!-n ' $ ']; then
echo "You have not input a null word!"
./app1; /APP12;. /app123
elif [$1-eq 2];then
./app12; /app123
elif [$1-eq];then
echo "YY";
Fi