Current location - Recipe Complete Network - Complete breakfast recipes - What are the basic shell scripting in Linux?
What are the basic shell scripting in Linux?
A shell script is just a collection of commands.

For example, I want to do this:

1) into the /tmp/ directory;

2) List all file names in the current directory;

3) Copy all the current files to the /root/ directory;

4) Delete all files in the current directory.

The simple four steps in the shell window require you to type the command four times and press Enter four times. Is this very troublesome? Of course, these four steps are very simple. What if it takes dozens of operations to set more complicated commands? In that case, it will be very troublesome to type the keyboard again and again. So you might as well record all the operations in a document, and then call the commands in the document, so that one-step operation can be completed. In fact, this document is a shell script, but this shell script has its special format. That's how linux should learn.

Shell scripts usually have the suffix. sh. This does not mean that you can't execute without the script. sh. It's just a habit of everyone. So, if you find a file with the suffix. sh in the future, it must be a shell script. The first line in test.sh must be "#! /bin/bash "It means that the file uses bash syntax. If this line is not set, then your shell script cannot be executed. #' stands for comment, as mentioned earlier. Followed by some notes about the script, as well as the author, creation date or version and so on. Of course, these notes are not necessary. If you are lazy, you can omit them, but I don't recommend omitting them. Because with the increase of your working hours, you will write more and more shell scripts. If one day you look back at a script you wrote, you are likely to forget what the script was used for and when it was written. So it is necessary to write notes. In addition, you are not the only system administrator. If other administrators check your script, he will be very depressed if he can't understand it. Further down the script is the command to run.