How to use commands to run .sh files under Linux, there are two methods:
1. Directly ./add the file name .sh, For example, when running hello.sh, it is ./hello.sh [hello.sh must have x permission]
2. Direct sh and add the file name.sh. For example, when running hello.sh, it is sh. hello.sh [hello.sh does not need x permission]
Method 1: Execute the .sh file in the current directory
[Step 1] cd to the directory where the .sh file is located
[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
[Step 3]./Execute the .sh file
For example, take the hello.sh file as an example. Run the following command on the terminal:
./hello.sh
to execute the hello.sh file
[Step 4] sh execute the .sh file
Take the hello.sh file as an example, sh hello.sh can execute the hello.sh file
Method 2: Execute the .sh file with absolute path
The following three methods are available;
./home/test/shell/hello.sh /home/test/shell/hello.sh sh /home/test/shell/hello.sh
Notes
When using "./" to add the file name .sh to execute, you must add x execution permissions to the .sh file
Related recommendations: linux tutorial
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!