Shell script notes

Source: Internet
Author: User

#! /Bin/sh
# The first line is to tell the system who will execute this dumb.

$ ## Number of parameters transferred to the script
$ # ID of the current process during script running, often used as the suffix of temporary variables, such as haison. $
$! # ID of the last process running in the background

Chmod U + x ABC. Sh # grant the user the execution permission
Chmod A + rwx ABC. Sh # grant all permissions to all users
./ABC. Sh

Who-A # Show all user information
Echo-e "\ 033 [31 m \ 033 [05 m error: No Log Type $1. \ 033 [0 m"; # Flashing in red (?)
Echo-e "\ 033 [31 m error: No Log Type $1."; # Red

Tail # only display the last 10 lines of the file

File Type:
B block C character d directory l link P pipe s socket
Permission type:
R read w write x excute
File status test:
-D directory-F Regular file-l symbol connection-s file length is greater than 0, non-empty-r readable
-W writable-x executable-u file with SUID bit settings
Example: [-r haison. C-a-W Hai. C]
String test:
= Two strings are equal! = Two strings are not equal-Z empty strings-N non-empty strings
Numerical test:
-Equal eq-ne unequal-GT greater than-lt less than-ge greater than-ge equal-Le smaller

The variable defined in the function starts with an underscore (_).

Kill process:
PS-Ef | grep XXX # pgrep xxx
Kill-S 9 PID
Or pgrep XXX | xargs kill-S 9 # note that pgrep must be accurate here, otherwise it will kill by mistake ..
Or kill-S 9 'pgrep XXX'
Or pkill-9 XXX # XXX must be accurate, otherwise it is very dangerous =

Curly braces tell shell that we want to print the num variable
Echo "this is the $ {num} Nd"

> Write the file and overwrite the old file
> Add the end Of the file

Hard drive mounting upon startup:
/Etc/fstab
/Dev/sdb/mnt ext3 defaults 0 0

Select usage
Echo "What's ur favorite OS? "
Select VaR in "Linux" "gnuhurd" "Free BSD" "other"; do
Break
Done
Echo "you have selected $ Var"

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.