小编kra*_*kry的帖子

如何在 awk 内的 bash 脚本中调用 bash 函数?

此问题与在 AWK 中使用 bash shell 函数有关

我有这个代码

#!/bin/bash

function emotion() {
            #here is function code end with return value...
            echo $1
}

export -f emotion

#I've put all animals in array
animalList=($(awk '{print $1}' animal.csv)) 

#loop  array and grep all the lines form the file
for j in ${animalList[@]}
do
  :                                                     #here I'am running a bash script calling emotion function 
   grep $j animal.csv | awk '{for(i=2;i<=NF;i++){system("bash -c '\''emotion "$i"'\''")}}'
done
Run Code Online (Sandbox Code Playgroud)

我有这个文件:

cat    smile    happy   laugh
dog    angry    sad
mouse …
Run Code Online (Sandbox Code Playgroud)

bash awk function

4
推荐指数
1
解决办法
2958
查看次数

标签 统计

awk ×1

bash ×1

function ×1