Shell programming needs to know

Source: Internet
Author: User

Recently, shell has been used. It is very simple and has no logic. I wrote it here just to help myself remember it. It's just a messy note. I hope this will help you. Please advise me more.

1 If else

If [$ #-lt 5]; then

Help
Exit 1

Else

Do something...
Fi

Where-lt is equivalent to <

-GT is equivalent to>

2 while

The followingProgramExecute the loop 101 times. Note that-Ge is greater than or equal

X = 100

While [$ X-GE 0]

Do

Something...

(X = x-1) // note that the operation in Shell needs to be written like this

Done

 

3 built-in Variables

$0 Equivalent to C LanguageMainFunctionArgv [0]
$1,$2... These are called positional parameter, which is equivalent to the C LanguageMainFunctionArgv [1],Argv [2]...
$ # Equivalent to C LanguageMainFunctionArgc-1, Note that#Not comment
$ @ Parameter List"$1" "$2 "...For exampleForIn the loopIn.
$? Exit status of the previous command
$ Process Number of the Current Shell

4. Date command usage

Common commands date-d "condition" Format

For example, date-d "yesterday" + % Y % m % d gets 20120201

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.