当前位置:网站首页>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。
边栏推荐
- 1、卡尔曼滤波-最佳的线性滤波器
- 力扣今日题-1200. 最小绝对差
- Leetcode 146. LRU 缓存
- R language uses cforest function in Party package to build random forest based on conditional inference trees, uses varimp function to check feature importance, and uses table function to calculate co
- C#实现一个万物皆可排序的队列
- How to play dapr without kubernetes?
- Codeforces Global Round 21(A-E)
- 09 softmax regression + loss function
- 学习Nuxt.js
- [BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
猜你喜欢

Codeforces Round #803 (Div. 2)(A-D)

C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,Gauss-Jordan消去法,源代码

User login function: simple but difficult

Moher College webmin unauthenticated remote code execution

MySQL relearn 1-centos install mysql5.7

What does range mean in PHP

DM8 database recovery based on point in time

Go h*ck yourself:online reconnaissance (online reconnaissance)

How college students choose suitable computers

Collections in Scala
随机推荐
Chrome is set to pure black
Question 49: how to quickly determine the impact of IO latency on MySQL performance
一文了解数据异常值检测方法
What if I forget the router password
Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid
NPM run build error
Educational Codeforces Round 119 (Rated for Div. 2)
How to send pictures to the server in the form of file stream through the upload control of antd
SQL statement view SQL Server 2005 version number
[go basics] 1 - go go
猜数字游戏
Flutter 集成 amap_flutter_location
埃氏筛+欧拉筛+区间筛
Comparison between sentinel and hystrix
Group programming ladder race - exercise set l1-006 continuity factor
Wechat has new functions, and the test is started again
Figure guessing game
Example analysis of C # read / write lock
C # implements a queue in which everything can be sorted
2022 tower crane driver examination and tower crane driver examination questions and analysis