Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to execute sh File in linux system

Shulou Source: shulou.com Published: 2022-06-03 03:33:40 09月21日 Update

Linux, there are two ways to command how to run .sh files:

1. Directly. / add the file name .sh. For example, run hello.sh as. / hello.sh [hello.sh must have x permission]

2. Add the file name .sh directly to sh. For example, run hello.sh as sh hello.sh [hello.sh may not have x permission]

Method 1: execute .sh files 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 hello.sh files as an example

Chmod upright x hello.sh

[step 3]. / execute the .sh file

For example, take the hello.sh file as an example, the terminal executes the following command:

. / hello.sh

The hello.sh file can be executed

[step 4] sh executes the .sh file

Take the hello.sh file as an example, sh hello.sh can execute the hello.sh file

Method 2: execute .sh file by absolute path

The following three methods are fine

. / home/test/shell/hello.sh/home/test/shell/hello.shsh / home/test/shell/hello.sh

Matters needing attention

When executing with ". /" plus the file name .sh, you must add x execution permission to the .sh file.

These are the details of how to execute .sh files in linux. For more information, please pay attention to other related articles!

Tags: File method permission step file name run command directory item content is location article more precautions terminal path system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux Microsoft vpn MariaDB