在bash脚本中使用awk时没有输出
我的bash脚本是:在bash脚本中使用awk时没有输出,bash,awk,Bash,Awk,我的bash脚本是: output=$(curl -s http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html | sed -nr 's/.*<title>(.*?)<\/title>.*/\1/p') score=echo"$output" | awk '{print $1}' echo $score 那么,为什么我不能从bash脚本中获得输出,
output=$(curl -s http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html | sed -nr 's/.*<title>(.*?)<\/title>.*/\1/p')
score=echo"$output" | awk '{print $1}'
echo $score
那么,为什么我不能从bash脚本中获得输出,而它在终端中运行良好?我是否以错误的方式使用了echo“$output”
。#/bin/bash
#!/bin/bash
output=$(curl -s http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html | sed -nr 's/.*<title>(.*?)<\/title>.*/\1/p')
score=$( echo "$output" | awk '{ print $1 }' )
echo "$score"
输出=$(curl-s)http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html |sed-nr的s/*(.*?./\1/p')
分数=$(回显“$output”| awk'{print$1}')
回显“$score”
Score变量可能是空的,因为您的语法是错误的。语法并非普遍错误,它只是将
$Score
设置为echo$output
,并将赋值的输出(无)传输到awk
;-)
#!/bin/bash
output=$(curl -s http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html | sed -nr 's/.*<title>(.*?)<\/title>.*/\1/p')
score=$( echo "$output" | awk '{ print $1 }' )
echo "$score"