当前位置:网站首页>awk从入门到入土(15)awk执行外部命令
awk从入门到入土(15)awk执行外部命令
2022-07-04 08:38:00 【奇妙之二进制】
这里的外部命令,是指shell命令。
方法1
如果不需要获取命令的输出而只是需要执行命令可以使用system()函数。
#!/usr/bin/awk -f
BEGIN {
system("touch test");
}
命令字符串必须由“”括起来。
甚至还能判断命令是否成功执行:
BEGIN{
fold = "/tmp/test";
# 调用系统命令mkdir创建文件夹
res = system("mkdir " fold);
print("res: " res);
if ( 0 == res ) {
print("文件夹创建成功");
}
# 再次创建同样的文件夹
res = system("mkdir " fold);
print("res: " res);
if ( 0 != res ) {
print("文件夹创建失败");
}
}
{
}
END{
}
方法2
"ls" | getline var
var是变量名,可以省略,相当于会将命令的执行结果赋值给var。
边栏推荐
- Codeforces Global Round 21(A-E)
- Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
- Conversion of yolov5 XML dataset to VOC dataset
- Moher College phpmailer remote command execution vulnerability tracing
- Example analysis of C # read / write lock
- The upper layer route cannot Ping the lower layer route
- [go basics] 1 - go go
- 广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
- Newh3c - network address translation (NAT)
- @Role of pathvariable annotation
猜你喜欢

C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code

Comprendre la méthode de détection des valeurs aberrantes des données

System disk expansion in virtual machine

snipaste 方便的截图软件,可以复制在屏幕上

Openfeign service interface call

没有Kubernetes怎么玩Dapr?

根据数字显示中文汉字

【性能测试】一文读懂Jmeter

How can we make a monthly income of more than 10000? We media people with low income come and have a look

How to re enable local connection when the network of laptop is disabled
随机推荐
Put a lantern on the website during the Lantern Festival
System disk expansion in virtual machine
@Role of pathvariable annotation
ES6 summary
From scratch, use Jenkins to build and publish pipeline pipeline project
string. Format without decimal places will generate unexpected rounding - C #
4 small ways to make your Tiktok video clearer
Use preg_ Match extracts the string into the array between: & | people PHP
Codeforces Round #803 (Div. 2)(A-D)
How can we make a monthly income of more than 10000? We media people with low income come and have a look
Scanf read in data type symbol table
A method for detecting outliers of data
A single element in an ordered array
一文了解数据异常值检测方法
DM8 command line installation and database creation
std::is_ union,std::is_ class,std::integral_ constant
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
MySQL relearn 1-centos install mysql5.7
DM8 tablespace backup and recovery
R language ggplot2 visualization: ggplot2 visualization grouping box diagram, place the legend and title of the visualization image on the top left of the image and align them to the left, in which th