当前位置:网站首页>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。
边栏推荐
- ctfshow web255 web 256 web257
- Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
- 2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
- 没有Kubernetes怎么玩Dapr?
- Flutter 集成 amap_flutter_location
- DM8 command line installation and database creation
- @Role of requestparam annotation
- 学习Nuxt.js
- Unity-写入Word
- C # implements a queue in which everything can be sorted
猜你喜欢
[go basics] 2 - go basic sentences
Question 49: how to quickly determine the impact of IO latency on MySQL performance
1. Qt入门
Unity text superscript square representation +text judge whether the text is empty
[CV] Wu Enda machine learning course notes | Chapter 9
Educational Codeforces Round 119 (Rated for Div. 2)
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
FOC控制
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
Snipaste convenient screenshot software, which can be copied on the screen
随机推荐
The right way to capture assertion failures in NUnit - C #
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Example analysis of C # read / write lock
How to re enable local connection when the network of laptop is disabled
Need help resetting PHP counters - PHP
SQL statement view SQL Server 2005 version number
High order phase difference such as smear caused by myopic surgery
Wechat has new functions, and the test is started again
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
L1 regularization and L2 regularization
NPM run build error
Li Kou today's question -1200 Minimum absolute difference
PHP session variable passed from form - PHP
How to improve your system architecture?
Newh3c - network address translation (NAT)
How to use C language code to realize the addition and subtraction of complex numbers and output structure
Comprendre la méthode de détection des valeurs aberrantes des données
1. Qt入门
转:优秀的管理者,关注的不是错误,而是优势
Learn nuxt js