Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a terminal I type:

grep '<td><a href="' file.txt

works fine. But if I type:

var= `grep '<td><a href="' 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 added a ";" – bodhi.zazen Jan 24 '14 at 21:57
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="' file.txt)"
share|improve this answer

Your Answer


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.