Home >Operation and Maintenance >Linux Operation and Maintenance >What are the commands to run files in Linux?
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.
#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
How to execute (run) files
1 , Use source to execute the script
test=100 source test.txt
Output:
Hello world!!! 37790 100
is using the current bash
2. Use . to execute the script
. test.txt Hello world!!! 37790 100
is using the current bash
3. Use bash to execute the script
bash test.txt Hello world!!! 47733
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
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!