当前位置:网站首页>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。
边栏推荐
- 2022 gas examination registration and free gas examination questions
- Group programming ladder race - exercise set l1-006 continuity factor
- [go basics] 2 - go basic sentences
- 一文了解數據异常值檢測方法
- DM8 database recovery based on point in time
- AcWing 244. Enigmatic cow (tree array + binary search)
- deno debugger
- Internal learning
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
- 2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
猜你喜欢
How to re enable local connection when the network of laptop is disabled
How can we make a monthly income of more than 10000? We media people with low income come and have a look
根据数字显示中文汉字
[go basics] 1 - go go
【性能測試】一文讀懂Jmeter
[attack and defense world | WP] cat
Moher college phpMyAdmin background file contains analysis traceability
What does range mean in PHP
【Go基础】1 - Go Go Go
Manjaro install wechat
随机推荐
Flutter 集成 amap_flutter_location
2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
string. Format without decimal places will generate unexpected rounding - C #
go-zero微服务实战系列(九、极致优化秒杀性能)
Codeforces Round #793 (Div. 2)(A-D)
转:优秀的管理者,关注的不是错误,而是优势
FOC控制
2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
Group programming ladder race - exercise set l2-002 linked list de duplication
How college students choose suitable computers
DM8 command line installation and database creation
C # implements a queue in which everything can be sorted
广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
Mouse over to change the transparency of web page image
Sort by item from the list within the list - C #
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
DM database password policy and login restriction settings
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
Leetcode 23. Merge K ascending linked lists