Linuxshell Programming 1 ---- basics of shell script programming

Source: Internet
Author: User
Tags processing text
Linuxshell Programming 1 ---- shell script programming basics 1 What is shell script 1shell? besides the command interpreter, it is also a programming language, a program written in shell is similar to a batch processing program in DOS. 2. you can store a series of commands in the file, usually she Linux shell Programming 1 ---- shell script programming basics 1 What is shell script 1 shell is a programming language besides a command interpreter, a program written in shell is similar to a batch processing program in DOS. 2. a user can store a series of commands in the file. generally, a program written in shell is called a shell script or a shell program 3, the combination of variables and flow control will produce a powerful programming tool. The shell scripting language is very good at processing text-type data. because all configuration files in Linux are plain text, therefore, the shell scripting language plays a huge role in the management of Linux systems. 2. Composition of shell scripts. 1. shell scripts are in the unit of action. when executing scripts, they are split into one row and one row for execution, the main components contained in the script include comments, commands, shell variables, and structure control statements. 2. note: The comments are used to explain and describe the script, add the symbol # before the comment line, so that shell will not explain the line when executing the script. 3 Command: in shell scripts, any interactive command 4 variables can be used: shell supports two data types: string variables and integer variables 5 structure control statements: create and execute a shell script 3. you can use any text editor to create a shell script file, such as vi, gedit and so on. There are two ways to execute shell scripts. one is to use the file name Shell command parameters, call format sh file name 2 another is. /file name. However, when we execute this part of the script file, we are prompted that we do not have the execution permission. Therefore, when we execute this part in the second method, we must change the permission of this file, so that it has the execution permission. 3. when a script file is executed, shell generates a sub-shell (that is, a sub-process) to execute commands in the command, therefore, the variable value in the file cannot be passed to the shell 4 shell script encoding specification 1 the correct starting part of a bash script should be #! Start :#! /Bin/bash 2 #! The statement at the beginning informs the system to use the interpreter to execute the script. 3 if the default shell is bash, you do not need to write it, however, a good shell coding specification requires that we must specify what interpreter is used to perform analysis on 5 shell instances. 1 First, the default shell in ubuntu is dash, the sh in ubuntu is only the link of the default shell, we can use ls/bin/sh-l to view the default shell 2. we can use the following two methods to change the default shell 1 sudo dpkg-reconfigure dash, then select no or no and confirm. In this way, dash will be reconfigured, and it will not be used as the default shell tool 2. you can also directly modify the/bin/sh link file, sudo ln-fs/bin/bash/bin/sh specify it to/bin/bash. 3. next we will create a shell script named s. sh 4. next we will use two methods to execute it. in the second method, we need to change the permission first.
 
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.