Shell Script Learning Notes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.