Home > Operation and Maintenance > Linux Operation and Maintenance > What are the commands to run files in Linux?

What are the commands to run files in Linux?

青灯夜游
Release: 2023-01-28 17:42:10
Original
18722 people have browsed it

Linux running file commands are: 1. Use source to execute the file. The command syntax is "source file name". 2. Use "." to execute the file, and the command syntax is ". file name". 3. Use bash to execute the script file. The command syntax is "bash file name". 4. Use "./file" to execute the script file, and the command syntax is "./filename"; in this method, you must first add execution permission "chmod x filename" to the script.

What are the commands to run files in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Creating files

vi test.txt
# 按i切换insert模式
# 输入文本
#!/bin/bash
echo "Hello world!!!"
echo $$ # 打印当前进程id
echo $test
Copy after login

How to execute (run) files

1 , Use source to execute the script

test=100
source test.txt
Copy after login

Output:

Hello world!!!
37790
100
Copy after login

is using the current bash

2. Use . to execute the script

. test.txt 
Hello world!!!
37790
100
Copy after login

is using the current bash

3. Use bash to execute the script

bash test.txt 
Hello world!!!
47733
Copy after login

The process id is updated, and the value of the variable test is not obtained because it is started The bash execution script of the child process.

4. Use ./file to execute the script

Note: In this method, you must first add execution permissions to the script chmod x test.txt

./test.txt 
Hello world!!!
47758
Copy after login

The process id was updated, and the value of the variable test was not obtained because the bash execution script of the child process was started.

Recommended learning: Linux video tutorial

The above is the detailed content of What are the commands to run files 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template