Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In a terminal I type:

grep '<td><a href="http://www.blabla.cc' file.txt

works fine. But if I type:

var= `grep '<td><a href="http://www.blabla.cc' file.txt`

I am unable to extract the variable, the result is:

<td><a: can not find command

I tried a backslash before the space "href" but

echo $var

shows an empty line. Any suggestions?

share|improve this question
    
It is the same command as given below, but for some reason askubuntu.com added a ";" –  bodhi.zazen Jan 24 at 21:57

1 Answer 1

up vote 3 down vote accepted

You should not be using spaces before the backtick. Additionally, use $( .. ) instead of backticks and quote it:

var="$(grep '<td><a href="http://www.blabla.cc' file.txt)"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.