Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 my bash script i want to execute command that will find lines in a file that starts with a keyword which is stored in a variable like this:

result=(`cat path/to/my/file | grep '^$keyword'`)
share|improve this question
Useless use of 'cat' :) grep $keyword < path/to/my/file – jscott Apr 19 '10 at 18:23
@jscott: useless use of redirection – Dennis Williamson Apr 19 '10 at 18:29
@Dennis: Indeed. I'm not sure the comments parse the ':)' humor markdown correctly. – jscott Apr 19 '10 at 19:45
up vote 3 down vote accepted

Single quotes inhibit substitution. Use double quotes instead:

grep "^$keyword"
share|improve this answer
oh, thanks it is even better solution – Skuja Apr 19 '10 at 18:18

Forgive me please, i figured it all out as soon as i posted my question: If has simular issue:

find_cmd = "cat path/to/my/file | grep '^$keyword'"
share|improve this answer
You can't put spaces around the equal sign. – Dennis Williamson Apr 19 '10 at 18:31

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.