Shell script learning notes series-1

Source: Internet
Author: User

I. Learn the knowledge reserve of shell programming

1. Related Linux system command applications;

2. Familiar with VI/Vim editor and related client software settings;

3. Basic services: NTP, crond, and network services: NFS, rsync, inotify, sersync, ssh, and lanmp.

Supplement: three methods for clearing logs:

1) echo ""> filename. Log

2)> filename. Log

3) CAT/dev/null> filename. Log

Note: You cannot delete (log) files at work, but can only clear the files!

2. Create and execute shell scripts

1. The first line of the script is generally :#! /Bin/bash or #! /Bin/sh;

2. execute shell scripts using bash script-name or sh script-name;

3. Execute the script in the current path. The shell script usually uses./script-name.

Shell script execution instructions (recommended ):

Example: 00 00 ***/Bin/bash/Server/scripts/bak. Sh>/dev/null 2> 1

III. Basic specifications and habits of shell script Development

1) Specify the script interpreter at the beginning

#! /Bin/sh or #! /Bin/bash

2) Add the copyright feature author and other information at the beginning

# Date:

# Author:

# Mail:

# Function:

# Version:

Tip: The above information is automatically added when you configure Vim to edit a file by modifying ~ /. Vimrc configuration file.

3) Chinese comments are not required in the script.

Try to use English comments to avoid Chinese garbled characters on the local machine or after switching the system environment.

4) The script uses. Sh as the extension name

5) Excellent coding habits

1. Write the paired content once to prevent omission;

2. [] There must be spaces at both ends of the brackets. When writing, you can leave a space [] and then write the content in the backspace;

3. After a flow control statement is written, add the content;

4. Make the code readable by indentation.


This article from the "empty valley orchid" blog, please be sure to keep this source http://2489843.blog.51cto.com/2479843/1539565

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.