bash中的for循环可在一个命令中使用多个变量 [英] for loop in bash to get more than 1 variables to use it in one command

查看:352
本文介绍了bash中的for循环可在一个命令中使用多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,我需要从同一文本中获取2个变量,并将它们放在一个命令中,例如

I have one text file and I need to get 2 variables from the same text and put them in one command like

for i in `cat TEXT | grep -i UID | awk '{print($2)}'` && 
x in `cat TEXT | grep -i LOGICAL | awk '{print($4)}'`
do 
  echo "naviseccli -h 10.1.1.37 sancopy -create -incremental -name copy_$i -srcwwn $x -destwwn xxxxxxxxxxxxxxxxxxxxxx -verify -linkbw 2048" >> OUTPUT
done

是否有任何可能的方法来完成存储管理员操作,并且需要执行大量命令,所以我需要获取此脚本才能实现

is there any possible way to accomplish that am storage admin and need to do tons of commands so i need to get this script to do it

推荐答案

您可以使用文件描述符.此外,您的 cat grep awk 命令可以组合为单个 awk 命令:

You could make use of file descriptors. Moreover, your cat, grep, awk command could be combined into a single awk command:

exec 5< <(awk '{IGNORECASE=1}/UID/ {print $2}' TEXT)
exec 6< <(awk '{IGNORECASE=1}/LOGICAL/ {print $4}' TEXT)
while read i <&5 && read x <&6
do
  echo command $i $x         # Do something with i and x here!
done

这篇关于bash中的for循环可在一个命令中使用多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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