Bash 如何使用grep(将标准输出重定向到变量)从WHOIS记录回显数据

Bash 如何使用grep(将标准输出重定向到变量)从WHOIS记录回显数据,bash,shell,command-line,grep,stdout,Bash,Shell,Command Line,Grep,Stdout,我有一个bash脚本: 我如何在if-else语句中将其称为grep的输出?如果我用-q抑制grep命令的输出,也会起作用吗 #!/usr/bin/env bash DOMAINS=( '.com' '.biz' ) while read input; do for (( i=0;i<${#DOMAINS[@]};i++)); do jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$inpu

我有一个bash脚本:

我如何在if-else语句中将其称为
grep
的输出?如果我用
-q
抑制
grep
命令的输出,也会起作用吗

#!/usr/bin/env bash

DOMAINS=( '.com' '.biz' )

while read input; do
  for (( i=0;i<${#DOMAINS[@]};i++)); do
  jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$input${DOMAINS[$i]}" | MATCH="$(grep -oPa '^.*\b(clientTransferProhibited)\b.*$')"
  if [ $? -eq 0 ]; then
    echo -e "$input${DOMAINS[$i]}\tregistered\t" $(date +%y/%m/%d_%H:%M:%S) "\t" "$MATCH" |& tee --append output/registered.txt
  else
    echo -e "$input${DOMAINS[$i]}\tavailable\t" $(date +%y/%m/%d_%H:%M:%S) "\t" "$MATCH" |& tee --append output/available.txt
  fi
  done
done < "$1"
我想要的输出:

$ domain1.com       available       15/11/16_14:13:05
$ domain1.biz       available       15/11/16_14:13:05
$ domain2.com        registered      15/11/16_14:13:05       Status: clientTransferProhibited http://www.icann.org/epp#clientTransferProhibited
$ domain2.biz        registered      15/11/16_14:13:05       Status: clientTransferProhibited http://www.icann.org/epp#clientTransferProhibited

所以这一行的结果就是你想要存储在变量中的结果

  jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$input${DOMAINS[$i]}" | grep -oPa '^.*\b(clientTransferProhibited)\b.*$'
在这种情况下,您需要计算该行并将整个内容设置为所需的变量。在管道中间尝试的分配类型将无效。

  MATCH=$(jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$input${DOMAINS[$i]}" | grep -oPa '^.*\b(clientTransferProhibited)\b.*$')

这是两个不同的匹配变量,因为管道执行子shell:

试着这样做:

MATCH="$(jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$input${DOMAINS[$i]}" | grep -oPa '^.*\b(clientTransferProhibited)\b.*$')"
MATCH="$(jwhois --force-lookup --disable-cache --no-redirect -c jwhois.conf "$input${DOMAINS[$i]}" | grep -oPa '^.*\b(clientTransferProhibited)\b.*$')"