Home  >  Article  >  Operation and Maintenance  >  How to execute sh file in linux

How to execute sh file in linux

藏色散人
藏色散人Original
2019-05-29 16:56:5644849browse

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

How to execute sh file in linux

[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

How to execute sh file in linux

[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

How to execute sh file in linux

Method 2: Execute the .sh file with absolute path

The following three methods are available, as shown in the figure belowHow to execute sh file in linux

./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!

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