Create a simple shell script file
Placing the shell command in a text file requires first using a text editor (VIM)
When you create a shell script file, you must specify the shell (#!/bin/bash) to be used in the first line of the file
The format is:
You can also use semicolons to enter the 2 commands you want to use on a single line
#号为脚本的注释 (except for the first line)
Now it's possible to run the next try and be a little disappointed. The following results occur:
So the first hurdle is getting the bash shell to find the script file (the shell will find the command through the PATH environment variable) to quickly look at the path to solve our problem:
The PATH environment variable is set to find commands only in a set of directories. To have the shell find the Test1 script, we can only use:
1. Add the directory where the shell script file resides to the PATH environment variable
2. Introduce the shell script file in the prompt with an absolute or relative file path
In this example, using the second way to tell the exact location of the shell script file, remember to refer to the file in the current directory, you need to use the single point operator in the shell:
The script has now been found. But there is another reason why you can view the permissions of the following files without permission:
You can modify the permissions by chmod command below.
You can then perform the following:
OK, a simple shell script for getting started is a success!!!
Building Shell Basic Scripts