Command Line Studey (learning written by sheel file):

1.

first shell script

Open a text editor (you can use the vi/vim command to create a file), create a new file test.sh with the extension sh (sh stands for shell), the extension does not affect the execution of the script, it is good to know the name, if you Use php to write shell scripts, and use php for the extension.

Enter some code, the first line is generally like this:

#!/bin/bash
echo "Hello World !"

#! is a convention mark that tells the system what interpreter this script needs to execute, i.e. what kind of shell to use.

The echo command is used to output text to the window.

There are two ways to run a shell script:

1. As an executable program

Save the above code as test.sh and cd to the corresponding directory:

chmod + x ./test.sh #make the script have execute permission./test.sh #execute the script 

Note that it must be written as  ./test.sh, not test.sh. The  same is true for running other binary programs. Write test.sh directly. The Linux system will go to the PATH to find out if there is a file called test.sh, but only /bin , /sbin, /usr/bin, /usr/sbin, etc. are in the PATH, your current directory is usually not in the PATH, so if you write test.sh, you will not find the command, use ./test.sh to tell the system to say , just look in the current directory.

2. As an interpreter parameter

This mode of operation is to run the interpreter directly, and its parameter is the file name of the shell script, such as:

/bin/sh test.sh

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325237033&siteId=291194637