Linux study Note 4: Shell Programming

Source: Internet
Author: User
Linux study Note 4: What is Shell programming? To put it simply, shell is a command parser that parses the command you entered into the system, that is, execution. There are many types of shell, including Bourneshell (sh) Kornshell (ksh) Bourne...
Linux study Note 4: What is Shell programming? To put it simply, shell is a command parser that parses the command you entered to the system for "listening", that is, execution. There are many shell types, including Bourne shell (sh) Korn shell (ksh) Bourne Again shell (bash) www.2cto.com C shell (including csh and tcsh) TENEX/tops c shell (tcsh) and so on, among which bash is the most used. What is shell script? A shell script is a text file that contains a series of command sequences. like the bat batchcompute command file, all the task commands you want the system to help you complete are piled up in a small text, and then you can simply click the text, is it very efficient? Can it also be understood as a program? Shell scripts are the same thing. it's nothing. I was fooled by this term when I first learned it. Well, let's take a simple example to see how the syntax and framework of our shell script are: 1. the first line of shell script must appear in the following format :#! /Bin/sh where #! Number (overall) is used to specify the parsing program of the script file. In our example, we use/bin/sh to parse the script. Note that when we finish writing the shell script, remember to use the chmod command to add permissions to it (execute readable or writable) 2. # It is used for commenting, and the comment ends until the end of the line. of course, do not set the first line here #! Comments for errors. Overall !! Www.2cto.com 3. the variables in shell do not need to be declared. you can use them directly. you need to add a dollar sign $ to use them. here, you need to note that the variables and characters are mixed, for example, if you want to output 10nd (num = 10, $ numnd will output null characters, because the system will automatically search for the string followed by the $ symbol to determine the referenced variable, here, the system mistakenly believes that the variable we want to reference is numnd. In fact, we didn't assign a value to the numnd variable, so the system outputs null characters. The local keyword must be added when a local variable is assigned for the first time. This is different from programming languages such as c and java! Note that "=" cannot be left with spaces on both sides! The comparison statement "=" should contain spaces and "[" "]" on both sides. In fact, there are five default variables in shell: 1. $ #: number of command line parameters of the input script 2. $ * all command line parameter values 3. $0: Command itself (shell file name) 4. $1 the first parameter is similarly $2 as the second parameter... stewen_001 by author
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.