Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash脚本中使用awk时没有输出_Bash_Awk - Fatal编程技术网

在bash脚本中使用awk时没有输出

在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脚本中获得输出,

我的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"