1./dev/null/dev/zero
①/dev/null:/dev/null, called an empty device, is a special device file that discards everything written to it (but reports a successful write operation) and reads it immediately to get an EOF. In Unix jargon,/dev/null is called a bit bucket or black hole. Empty devices are often used to discard unwanted output streams, or as empty files for input streams. These operations are usually done by redirection.
# cat/dev/null >/var/log/messages Clears the contents of the file without deleting the file itself
#: >/var/log/messages has the same effect, but does not produce new processes. (Built-in)
# ln-s/dev/null test.c write anything to test.c will not be saved
②/dev/zero:/dev/zero is a special file that when you read it, it will provide unlimited null characters (null, ASCII NUL, 0x00). One typical usage is to overwrite information with a stream of characters it provides, and another common use is to produce a blank file of a specific size.
2. Use echo $? Check the exit code for the previous command: 0 for the command to execute normally, 1-255 for error.
# dd If=/dev/zero Of=/dev/sdb bs=4m to clear the entire USB stick.
3.echo $$ to print the PID of the process running the current script
4. required to run as root
The $UID of the Root_uid=0 # Root user is 0.
E_WRONG_USER=65 # not Root?
If ["$UID"-ne "$ROOT _uid"]
Then
Echo echo "You must is root to run this script."; Echo
Exit $E _wrong_user
Fi
Or:
E_NON_ROOT_USER=70 # must be run with ROOT.
Rootuser_name=root
Username= ' Id-nu '
If ["$username"! = "$ROOTUSER _name"]
Then
echo "must is root to run" "' BaseName $ '" "."
Exit $E _non_root_user
Fi
Shell Script Learning Notes