Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I am working on a BASH script which creates automated backups via the crontab. I am trying to use

myVARIABLE=`grep backup /etc/crontab`

to return lines containing "backup" if an entry has already been made. Instead of returning lines from /etc/crontab it seems to be returning the output of multiple ls commands. I have run the command

grep backup /etc/crontab

from the command line and it works as expected. I can also grep other files via my BASH script and it returns expected results as well. Any thoughts as to why /etc/crontab causes grep problems within a script? Thanks!

share|improve this question
Chances are you are using myVARIABLE or quoting something incorrectly but without more information it's impossible to tell. Try adding snippets about what your script does after that line. Also make sure to describe the high-level goal you are trying to accomplish so people can suggest good ways to go about it. Putting multiple lines in a shell variable is clunky at best. – jw013 Dec 15 '11 at 2:18

That is because /etc/crontab contains asterisk characters (*), which, when not escaped, will be expanded by the shell.

Compare the output of these two commands:

echo $myVariable
echo "$myVariable"

The first command uses the variable unescaped, so the asterisk characters will be expanded to all files in the current directory. The second command is what you want, the real contents of the crontab file.

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.