In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Today, the editor shares an introduction about how to run shell programs in linux. Maybe you are no stranger to the methods of running shell programs in linux, or you have never known the methods of running shell programs in linux. But don't worry, the editor will explain it in the simplest description today. Let's take a look.
First of all, let's look at a program called test.sh.
#! / bin/sh#this is a test.cd / tmpecho "hello,this is a test"
The method of executing the program:
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.
2. Directly call the command interpreter to execute the program.
Since our interpreter is / bin/sh, we use the sh command interpreter to execute the program.
3. Use source to execute files.
Program execution difference description:
Of the three ways we run the shell program, the execution of the first two methods is 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.
So we understand why the execution results of the first two methods are different from what we expected, and 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 above is a brief introduction to the methods of running shell programs in linux. Of course, the differences in the detailed use of the above have to be understood by everyone. If you want to know more, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.