Home > Article > Operation and Maintenance > How to run .sh file under linux
1. Directly ./ and add the file name .sh. For example, when running hello.sh, it is ./hello.sh [hello.sh must have x permissions]
2. Direct sh plus the file name .sh, for example, run hello.sh as sh hello.sh [hello.sh does not need x permission]
Method 1: Execute the .sh file in the current directory
Recommended linux video tutorial: linux video tutorial
[Step 1] cd to the directory where the .sh file is located
For example, take the hello.sh file as an example, as shown below
[Step 2] Add x execution permissions to the .sh file
For example, take the hello.sh file as an example, chmod u x hello.sh, as shown below
[Step 3]./Execute the .sh file
For example, take the hello.sh file as an example, ./hello.sh can execute hello.sh file, as shown below
[Step 4]sh executes the .sh file
Take the hello.sh file as an example, sh hello.sh can execute hello .sh file, as shown below
Method 2: Execute .sh file with absolute path
The following three methods are available, as shown below:
./home/test/shell/hello.sh /home/test/shell/hello.sh sh /home/test/shell/hello.sh
Recommended related articles and tutorials: linux tutorial
The above is the detailed content of How to run .sh file under linux. For more information, please follow other related articles on the PHP Chinese website!