How to execute .sh file in Linux system?
In Linux systems, the .sh
file is a file called a Shell script, which is used to execute a series of commands. Executing the .sh
file is a very common operation. This article will introduce how to execute the .sh
file in the Linux system and provide specific code examples.
To execute a .sh
file in the Linux system, you can use the absolute path to specify the location of the file. The following are the specific steps:
.sh
file is stored. ./
plus the file name to execute the .sh
file, that is, ./filename.sh
, where filename. sh
is the name of your .sh
file. Sample code:
cd /path/to/your/sh_file/folder ./example.sh
In addition to using the absolute path to execute .sh
file, you can also add the .sh
file to the PATH environment variable of the system so that it can be executed directly under any path. The following are the specific steps:
.bashrc
file. You can use the command nano ~/.bashrc
to open the file. export PATH=$PATH:/path/to/your/sh_file/folder
, where /path/to/your/sh_file/folder
is the path where you store the .sh
file. .bashrc
file, then run the source ~/.bashrc
command for the changes to take effect. .sh
file in any path, just enter the file name. Sample code:
source ~/.bashrc example.sh
Sometimes when trying to execute .sh
Insufficient permissions may occur when accessing a file. In this case, you can use the chmod
command to grant execution permissions to the file. The following are the specific steps:
.sh
file is stored in the terminal. chmod x filename.sh
command, where filename.sh
is your .sh
file name. This command will give the file execution permissions. .sh
file directly through the file name. Sample code:
cd /path/to/your/sh_file/folder chmod +x example.sh ./example.sh
Summary:
This article introduces three methods of executing .sh
files in Linux systems, and Specific code examples are provided. Through these methods, you can easily execute the .sh
file and perform customized script operations. Hope this article helps you!
The above is the detailed content of How to execute .sh file in Linux system?. For more information, please follow other related articles on the PHP Chinese website!