Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to write Linux shell script
How to write Linux shell script
Shell is often compared to a "translator" between human and computer hardware. As the communication medium between users and Linux system, Shell itself defines various variables and parameters, and provides the unique control structure characteristics of high-level languages such as loops and branches. How to use these functions correctly and give orders accurately is particularly important.

The Shell works in two ways.

1. Interactive: the user inputs the command, and the Shell interprets and executes the command.

2. Batch processing: The user writes a Shell script in advance, which contains many commands, and the Shell will execute all the commands at once.

Compile a simple script

Shell scripts should be written in the Vim text editor in the order in which the commands are executed, with one Linux command per line. A complete Shell script should include script declaration, comment information and executable statements.

Instructions for writing steps:

Script declaration (! ): Tell the system which shell to use for interpretation.

Note information (#): It is optional to introduce executable statements or program functions.

Executable statement: A specific command to be executed.

Write a simple Shell script, whose function is to display the current working path and list all files and properties in the current directory.

1

2

three

four

five

[root @ Linux probe ~]# vim example . sh

#! /bin/bash

# For example, linuxprobe.com

Displays the current working directory

ls -al

There are three ways to execute scripts:

Script file path:. /Example.sh

Sh script file path: sheexample.sh

Source script file path: sourceexample.sh