C Programming series in linuxl-shell

Source: Internet
Author: User

Shell script (. Sh): similar to the bat. File batch processing in Windows
It is more powerful than batch processing and is already a powerful programming language.

Echo "Please enter your name :";
Read fname;
Echo $ {fname} // {} can be omitted

The default data type is character.

Env view environment variables
Echo $ home view current user directory
Echo $ path

./Execute; you can also modify
VI/etc/profile

Add Path = $ path :.
Export the export path as a global variable. (You need to restart) so you don't need to add ./.

Echo 'date' shows the date (the quotation mark below the wavy line)

Expt 4 + 5 calculates 9, and there must be spaces around +
You can also: Echo $(4 + 5 ))

Example 1:
Echo "Please enter sore :"
Read score

If [$ score-lt 80] // if it is less than 80
Then
Echo "bad! ";
Elif [$ score Ge 80-A $ score-lt 90] // if it is greater than or equal to 80 and less than 90
Echo "Good! ";
Else
Echo "very good! ";
Fi // end judgment

Set the row number in VI: Set nu
: WQ save and exit

Example 2:
Echo "serices :"
Echo-n "1) ls" //-N indicates no line feed
Echo-n "2) ls-l"
Echo-n "3) Exit"
Echo "Please chioce [1-3]"
Read choice

Case $ choice in
1) ls ;;
2) ls-L ;;
3) exit;
*) Echo "wrong input ";;
Esac // end

Example 3:
Ecode = 1000
While [$ ecode-Le 1002] // [] There are spaces before and after
Do
Echo "Please enter info ecode = $ ecode"
Echo "Enter name :"
Read name
Echo "Enter age :"
Read age
Echo "Name: $ name age = $ age"> AA. dat
(Ecode = $ ecode + 1 ))
Done

 

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.