Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to run shell script in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

How does the shell script run in Linux? Many people don't know much about it. Today, in order to let you know more about the execution of Shell scripts, let's sum up the following contents. Let's move on.

How to run shell script in Linux

There are usually three ways to execute Shell scripts. Here are the characteristics of these three ways:

1. Bash script-name or sh script-name

This is a method that is often used when the script file itself does not have executable permissions (that is, the file permission attribute x bit is a-sign), or when an interpreter is not specified at the beginning of the script file. This method is recommended.

$bash test.sh

2. Path/script-name or. / script-name

Refers to the execution of the script under the current path (the script requires execution permission), and the permission of the script file needs to be executable (that is, the file permission attribute is x bit). The specific method is: chmod aquix script-name. The script can then be executed by executing either the absolute path or the relative path.

Note: in a production environment, an error occurs when the operator forgets to set the executable permission for the script and then uses it directly. Therefore, the first bash script-name is recommended.

$chmod + x test.sh$. / test.sh$ / home/me/test.sh

3. Source script-name or. Script-name

Source or "." The function of the command is to read and execute the script, that is, to execute source or "." in the current Shell. Loads and executes the commands and statements of the related script file, rather than generating a child Shell to execute the commands in the file.

Note: this is the biggest difference from several other ways of performing shell.

$source test.sh$. Test.sh

Other modes of operation:

Sh test.shdash test.shzsh test.sh...

About how the shell script runs in Linux is shared here, of course, not only the above and everyone's analysis methods, but the editor can ensure its accuracy is absolutely no problem. I hope that the above content can have a certain reference value for everyone, and can be put into practice. If you like this article, you might as well share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report