Shell Programming 01-shell Basics

Source: Internet
Author: User
Tags posix rsync

01. Learn the knowledge storage required for Shell programming

1.VI, VIM editor commands, VIMRC settings

2. Command base, more than 100 commands

3. Basic, high-end network services, Nfs,rsync,inotify,lanmp,sersync,sshkey batch distribution management

02.shell Scripting Concepts

1. What is a shell

The shell is a command interpreter, at the outermost end of the operating system, that is responsible for directly talking to the user, explaining the user's input to the operating system, and outputting the various processing results of the operating system, output to the screen and returned to the user. This type of conversation can be interactive (keyboard input command, can immediately get the shell's response), or non-interactive (script) way

2. What is a shell script

When a command or statement is not executed in the command line, but is executed through a program file, the program is called a shell or shell script, and the shell program is similar to a DOS batch program (*.BAT)

A user can enter a series of commands or statements in a shell script. The combination of these commands, variable flow control statements, and so on, forms a powerful Shell program

3. Example

#!/bin/bash"Hello world!"

The position of 03.shell program in operation and maintenance work

Shell is good at handling plain text type data, and almost all configuration files, log Files (NFS, rsync, httpd, Nginx, LVS, etc.) in Linux are plain text files. Shell scripts are a huge part of Linux

types and descriptions of 04.shell scripting languages

1. There are two main categories in Unix/linux

Bourne Shell (including sh, ksh, bash): Bourne shell (SH), Kor n Shell (ksh), Bourne Again Shell (bash), POSIX shell (SH)

C Shell (including CSH, tcsh): C shell,tenex/tops C Shell

2.shell scripting language is a weakly typed language, when you define a variable, you do not need to specify a type, and if you do not define it, you will get an error. For example, let the string and the integer number want to add

3. The more general Shell has standard Bourne shell (SH) and C shell, where the Bourne shell has been replaced by Bourne Again Shell (bash)

The advantage of the 4.shell is that it handles the underlying business of the operating system (many commands support it, and more than 2000 commands are shell-supported)

05. Default shell for common operating systems

Linux is Bourne Again shell (bash)

Unix:solaris, FreeBSD default is the Bourne shell (SH), AIX is Korn shell (Ksh), HP-UX is the POSIX shell (SH)

View commands: Echo $SHELL (System variables are all uppercase)

Creation and execution of 06.shell scripts

1.shell Scripts (bash shell programs) are typically written in an editor such as Vi/vim, consisting of unix/linux commands, bash shell commands, Program structure control statements, and annotations.

2. First line at the beginning of the script

How 3.shell scripts are executed:

1) as an executable program

Save the code as test.sh and CD to the appropriate directory:

+./test.  #使脚本具有执行权限./test.  #执行脚本      

Note, be sure to write./test.sh, not test.sh, run other binary programs as well, direct write Test.sh,linux system will go to the path to find there is no test.sh, and only/bin,/sbin,/USR/BIN,/USR /sbin wait in path, your current directory is usually not in path, so write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory.

2) as an interpreter parameter

This works by running the interpreter directly, whose parameters are the file names of the shell scripts, such as:

/bin/sh test.  Sh

The script that runs this way does not need to specify the interpreter information in the first line, and it is useless to write.

Shell Programming 01-shell Basics

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.