Home >Operation and Maintenance >Linux Operation and Maintenance >How to write scripts in linux
Shell is both a command interpretation tool and a script programming language. You can use various shell commands and some specific grammatical structures to form a Shell script program. The shell script program is a plain text file. , let’s take a look at how to write scripts in Linux.
How to write a script in Linux
1. Open the terminal, enter the directory where the program is saved, and enter # on the command line ## vi test.sh (The suffix of the Shell script program is .sh, .sh is for people to see, you can also name it .txt or do not write the suffix)
2. In Shell programming, the characters after # can be used as comments, so we can write some comments in the program. Note that # needs to be declared in the first line of the program! /bin/bash(csh,zsh..), use #! Used to show that our program is executed using bashRecommended learning: "Linux Video Tutorial"
3. A simple script program is written here as follows Program part #4. You can run it directly after writing. ./ represents the current directory, enter./ When test.sh is executed, you will find that there is no permission (permission denied). Then we grant ourselves permission and we can run it.
A small Shell script was successful.Related recommendations:Introduction to programming tutorial, learning address:
The above is the detailed content of How to write scripts in linux. For more information, please follow other related articles on the PHP Chinese website!