0

My bash script is:

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

The above script prints just a newline in my console whereas my required output is

$ curl -s http://www.espncricinfo.com/england-v-south-africa-2012/engine/current/match/534225.html | sed -nr 's/.*<title>(.*
?)<\/title>.*/\1/p' | awk '{print $1}'

SA

So, why am I not getting the output from my bash script whereas it works fine in terminal am I using echo"$output" in the wrong way.

1 Answer 1

2
#!/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"

Score variable was probably empty, since your syntax was wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

The syntax is not universally wrong, it just sets $score to echo$output and pipes the output of assignment (which is none) to awk ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.