How to execute .sh file in linux

Release: 2019-12-25 16:28:42
Original
10322 people have browsed it

How to execute .sh file in linux

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!