Home > Article > Operation and Maintenance > How to execute sh file in linux
This article introduces how to execute .sh files using commands under Linux. There are two methods:
1. Directly add ./ to the file name .sh, such as Run hello.sh as ./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 You can not have x permissions】
Method 1: Execute the .sh file in the current directory
[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 For example, chmod u ./hello.sh can execute the hello.sh file, as shown below
[Step 4]sh executes the .sh file
To hello.sh file For example, sh hello.sh can execute the hello.sh file, as shown below
Method 2: Execute the .sh file with absolute pathThe following three methods are available, as shown in the figure below
./home/test/shell/hello.sh /home/test/shell/hello.sh sh /home/test/shell/hello.sh
Notes:
When executing "./" plus the file name .sh, You must add x execution permissions to the .sh file.
The above is the detailed content of How to execute sh file in linux. For more information, please follow other related articles on the PHP Chinese website!