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