Exit 1 to end execution in the middle of the script
Cases:
[email protected] script]# cat usertest.sh
#!/bin/bash
#
Testuser=hbase
if! grep "^ $TESTUSER"/etc/passwd &>/dev/null; Then
echo "Not find User: $TESTUSER"
Exit 1
Fi
Useruid= ' grep ' ^ $TESTUSER "/etc/passwd | cut-d:-f3 '
Usergroupid= ' grep ' ^ $TESTUSER "/etc/passwd | cut-d:-f4 '
If [$USERUID-eq $USERGROUPID]; Then
echo "Good guy!"
Else
echo "Bed guy"
Fi
[Email protected] script]#
The first half of this script will execute exit 1 if the user is unable to find it. 0 The return value is executed for the correct state, and 1-255 is an error here, either one is OK. The rest does not explain hehe.
Common Test conditions for bash
Integer test
-GT Greater than
-lt less than
-ge greater than or equal to
-le less than or equal to
-ne Not equal to
-eq equals
Test mode 1. [Expression] 2. [[Expression]] 3. Test expression
The first two most commonly used
File test
-e file Test files exist
-F file Test files are normal files (non-linked files, device files, pipeline files)
-D path Tests whether the specified path is a directory
-R file tests whether the current user has read access to the specified file
-W file tests whether the current user has write access to the specified file
-X file tests whether the current user has execute permissions on the specified file
Cases:
[-e/etc/inittab] means testing whether the/etc/inittab file exists.
Linux exit file test test conditions