Shell Programming for Linux

Source: Internet
Author: User

Basic knowledge of Shell programming

Three ways to empty a log

1.echo Cary >test.log

>test.log

2.echo Cary >http://www.qixoo.qixoo.com/test.log

Echo >test.log

3.echo Cary >test.log

Cat/dev/null >test.log

Shell scripts are good at working with plain text type data, while almost all files in Linux are stored as text files

There are 2 major classes of shells in Unix/linux

Bash and CSH

The Shell scripting language is a weakly typed language, and the more general Shell has the standard Bourne shell and CSH

Scripting languages commonly used by operations personnel

1.php----Web program, scripting language, more focused on web page development

2.perl-----Scripting language, more powerful than the shell, a few years ago is very fire, grammatical flexibility, complexity, the implementation of a lot of ways, difficult to read

3.python----In recent years very fire language, can do script development, also can do web development

What is the difference between shell scripts and Php,perl,python?

The advantages of the shell are in the business of handling the underlying operating system (a large number of commands support it, and more than 2000 commands support the shell)

grep,awk,sed), one-click installation, alarm scripting, general business applications, shell development fast.

Php,python's advantage lies in the development of operations tools, web interface management tools

You can see what shell the system is using with related commands

1.env----View variables for the entire system

2.echo $SHELL---Look at the shell variable to see the shell type inside.

Creation and execution of 4.shell scripts

Shell scripts are usually written in the editor (vi vim). Consists of UNIX/LINUX commands, bash shell commands, Program structure control statements, and annotations.

The first line in a canonical shell script is supported by that program to explain

Such as

#! /bin/bash or #! /bin/shell

#! ----is called a magic number, it confirms that the script content is interpreted using the SEHLL language when executing the bash script, and must be in the first line if

Content inside with #! is a comment.

In a shell script, the #后面的内容是注释内容 is not executed by the script.

Execution of Shell scripts

When a shell script runs in a non-interactive manner, it first takes the path under the environment variable env, which points to the

A. bashrc file.

The execution of a shell script can typically take three ways:

1.bash script-name or SH script-name (recommended)

2.path/script-name or. Script-name execution script under current path

Basic specifications and habits of shell script development

1. Start specifying the script interpreter

#!/bin/bash or #!/bin/sh

2. Beginning plus version copyright information

#date: 20151130

#Author: Cary.qin

#mail:
#function: This scripts function is ...

#version: 1.1

3. No Chinese comments in the script

4. Script to. SH for extension

such as. script-name.sh

5. Code writing Good Habits

1) The contents of the pair are written at once to prevent forgetting. such as: ' [] {} These

2) [echo] the brackets on the 2 end should have a space.

3) The Process Control statement is completed once, to prevent errors in forgetting.

If condition content

Then

Content

Fi

Shell Programming for Linux

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.