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

The method of running shell Program in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, the editor shares with you the method of running shell programs in linux, which many people don't know very well. Today, in order to make you know more about the methods of running shell programs in linux, I have summarized the following contents for you. Let's look down together. I'm sure you'll get something.

There are three ways for linux to run a program, which are:

1. Make the file executable and run the file directly.

The chmod command modifies the permissions of the file. + x gives the file executable permissions. Just like we run the program above. But the results we see are somewhat different from what we imagined.

2. Directly call the command interpreter to execute the program.

As shown in the figure:

Since our interpreter is / bin/sh, we use the sh command interpreter to execute the program.

(the current work path has not changed)

3. Use source to execute files.

As shown in the figure:

(the current work path has changed)

Of the three ways to run a shell program, the first two are executed as follows:

(1) the parent process receives the command and finds that it is not a built-in command, so it creates a shell process like itself to execute the external command.

(2) the shell subprocess replaces itself with / bin/sh, and the sh process sets its own runtime environment variables, including the $PWD variable.

(3) the sh process executes the built-in commands cd and echo in turn. During this process, the environment variable of the sh process (child process) is changed by the cd command.

(4) when the child process is finished, it dies, and the waiting parent process wakes up and continues to accept orders.

Analysis:

The current directory (environment variable) of the parent process cannot be changed by the child process. However, a child process is not created when executing a shell script using source, but is executed directly in the parent process.

The method of running shell programs on linux is shared here, of course, not only the above and everyone's analysis methods, but the editor can ensure that 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