How to write scripts in linux

angryTom
angryTomOriginal
2020-03-10 15:54:3121453browse

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 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 bash

Recommended learning: "

Linux Video Tutorial"

3. A simple script program is written here as follows

How to write scripts in linux

Program part

How to write scripts in linux

#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.

How to write scripts in linux

How to write scripts in linux

A small Shell script was successful.


Related recommendations:


Introduction to programming tutorial, learning address:

//m.sbmmt.com/course.html

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn