Shell Primer Basics

Source: Internet
Author: User
Tags command line linux

1. Build and run the shell program

What is a shell program? Simply put, a shell program is one that contains several lines

File for Shell or Linux commands.

As with programs written in high-level languages, writing a shell program requires a text editor. such as VI.

In the text editing environment, according to the Shell's syntax rules, enter some shell/linux command line, form a complete

's Program Files.

There are three methods of executing shell program Files

(1) #chmod +x file (in/etc/profile, add export Path=${path}:~/yourpath, you can run directly under the command line, like the normal command)

(2) #sh file

(3) #. File

(4) #source file

When writing a shell, the first line must indicate that the system needs that shell to explain your shell program, such as: #! /bin/bash,

#! /BIN/CSH,/BIN/TCSH, or #!. /bin/pdksh.

Variables in the 2.shell

(1) Common system variables

$ #: The number of command line arguments to save the program

$ ? : Save the return code of the previous command

$0: Save program Name

$ *: to ("$ $ ...") To save all the input command-line arguments in the form

$ @: to ("$" ...) To save all the input command-line arguments in the form

(2) Defining variables

Shell language is an interpretive language of non-type, and it is not necessary to declare variables in advance when programming in C++/java languages. Give a

A variable is actually defined as a variable.

In all shells supported by Linux, you can assign values to variables using the assignment symbol (=).

Such as:

Abc=9 (Bash/pdksh cannot leave spaces on both sides of the equals sign)

Set ABC = 9 (tcsh/csh)

Because the variables of the shell program are of no type, users can use the same variable and store the characters sometimes

Integer.

Such as:

NAME=ABC (Bash/pdksh)

Set name = ABC (TCSH)

After the variable is assigned, simply precede the variable with a $ to reference.

Such as:

Echo $ABC

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.