脚本中的Bash [英] Scripting in Bash

查看:124
本文介绍了脚本中的Bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在bash函数解析说,这需要一个参数和函数名称为f。我的文件要被处理有点像

I have a function in bash say parse which takes one argument and function name is f. My file to be processed is somewhat like

a@b@c@
a@d@e@g@
m@n@
t@

我想给输出

a@f(b)@f(c)@
a@f(d)@f(e)@f(g)@
m@f(n)@
t@

这是适用于函数f所有除第一。任何线索,所以我怎么能这样做呢?

That is apply function f to all except the first. Any clues so how can I do this?

推荐答案

也许这就是你想要什么?

maybe this is what you want?

例如。你有一个脚本调用sqr.sh:

e.g. you have a script called sqr.sh:

kent$  cat sqr.sh
#!/bin/bash
echo $(($1*$1))

现在要应用上面的功能您的输入:

now you want to apply the function above on your input:

kent$  echo "foo@2@3@4@
0@10@20@
x@"|awk -F'@' -v OFS=@ '{for(i=2;i<=NF;i++) if($i) "./sqr.sh "$i|getline $i; print}'

foo@4@9@16@
0@100@400@
x@

这篇关于脚本中的Bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆