当前位置:网站首页>Awk from entry to earth (15) awk executes external commands
Awk from entry to earth (15) awk executes external commands
2022-07-04 08:46:00 【Wonderful binary】
External commands here , Refer to shell command .
Method 1
If you don't need to get the output of the command but just need to execute the command, you can use system() function .
#!/usr/bin/awk -f
BEGIN {
system("touch test");
}
The command string must consist of “” Cover up .
It can even judge whether the command was successfully executed :
BEGIN{
fold = "/tmp/test";
# Invoking system commands mkdir Create folder
res = system("mkdir " fold);
print("res: " res);
if ( 0 == res ) {
print(" Folder created successfully ");
}
# Create the same folder again
res = system("mkdir " fold);
print("res: " res);
if ( 0 != res ) {
print(" Folder creation failed ");
}
}
{
}
END{
}
Method 2
"ls" | getline var
var Is a variable name. , It can be omitted , It is equivalent to assigning the execution result of the command to var.
边栏推荐
- Codeforces Round #803 (Div. 2)(A-D)
- Codeforces Global Round 21(A-E)
- 2022 tower crane driver examination and tower crane driver examination questions and analysis
- ES6 summary
- Live in a dream, only do things you don't say
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
- Codeforces Round #803 (Div. 2)(A-D)
- Three paradigms of database design
- FOC控制
- SSRF vulnerability exploitation - attack redis
猜你喜欢
How college students choose suitable computers
What if I forget the router password
yolov5 xml数据集转换为VOC数据集
System disk expansion in virtual machine
Question 49: how to quickly determine the impact of IO latency on MySQL performance
Codeforces Round #803 (Div. 2)(A-D)
[CV] Wu Enda machine learning course notes | Chapter 9
Ehrlich sieve + Euler sieve + interval sieve
地平线 旭日X3 PI (一)首次开机细节
FOC控制
随机推荐
DM8 uses different databases to archive and recover after multiple failures
How to solve the problem that computers often flash
Codeforces Global Round 21(A-E)
ES6 summary
Use Alibaba cloud NPM image acceleration
SQL statement view SQL Server 2005 version number
Relationship and operation of random events
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
Basic operations of databases and tables ----- view data tables
High order phase difference such as smear caused by myopic surgery
微服务入门:Gateway网关
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
awk从入门到入土(15)awk执行外部命令
Industry depression has the advantages of industry depression
【无标题】转发最小二乘法
[untitled] 2022 polymerization process analysis and polymerization process simulation examination
What if the wireless network connection of the laptop is unavailable
FOC control
Three paradigms of database design
Developers really review CSDN question and answer function, and there are many improvements~