How to run shell program in linux

王林
Release: 2020-03-13 15:40:37
Original
3585 people have browsed it

How to run shell program in linux

There are three ways to run a program in Linux, namely:

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

The chmod command is used to modify the permissions of files. x gives the file executable permissions. Just like we ran the program above. But the results we saw were somewhat different from what we imagined.

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

As shown in the figure:

How to run shell program in linux

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

(The current working path has not changed)

(Recommended tutorial:linux tutorial)

3. Use source to execute the file.

As shown in the picture:

How to run shell program in linux

(The current working path has changed)

Three ways to run the shell program , the execution process of the first two methods is as follows:

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

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

(3) The sh process executes the built-in commands cd and echo in sequence. During this process, the environment variables of the sh process (child process) are changed by the cd command.

(4) After the child process is executed, it dies. The parent process that has been waiting wakes up and continues to accept commands.

Analysis:

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

Recommended related video tutorials:linux video tutorial

The above is the detailed content of How to run shell program 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!