How to run shell program in linux
First, let’s take a look at a program test.sh
#!/bin/sh #this is a test. cd /tmp echo "hello,this is a test"
How to execute the program:
1. Make the file have Executable permissions, run the file directly.
The chmod command is used to modify the permissions of files.
x is the permission to make the file executable. Just like we ran the program above.
(Recommended tutorial: linux tutorial)
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 the file.
Explanation of program execution differences:
Among the three methods we use to run shell programs, the execution processes of the first two methods are as follows:
(1) The parent process received the command, and then found that it was not a built-in command, so it created a shell process like its own to execute the external command
(2) This shell child process uses /bin /sh replaces itself, 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.
So we understand the reason why the execution results of the first two methods are different from our expectations. 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →
