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'm trying to do something with a cron wrapper and my cron looks something like

* * * * * root /usr/bin/wrapper cd /tmp/ && ls 

Then wrapper looks like



When I run it I can't get the semi colon or && to work as I'm hoping.

[root@domain.net ~/test]# pwd
[root@domain.net ~/test]# ls
[root@domain.net ~/test]# ./test.sh cd /tmp && ls

So in that case it goes into tmp then the weapper script exits.. and it runs ls in my cwd.

If I add '' around the command I get

[root@domain.net ~/test]# ./test.sh 'cd /tmp && ls'
./test.sh: line 3: cd /tmp && ls: No such file or directory

I'm guessing with the "$@" it is trying to add in the single quote to the command being run

I support I can strip out the single quotes before the "$@" but I was hoping not to do that.. any tips or is this even solvable in bash?

share|improve this question
up vote 8 down vote accepted

/usr/bin/wrapper cd /tmp/ && ls gets parsed as (/usr/bin/wrapper cd /tmp/) && ls. Even if you do manage to pass the arguments to wrapper properly, it doesn't understand them; && is a shell construct. I'm not sure exactly what you were aiming for with this wrapper script, but I suspect you can just replace it with bash -c, which takes a string and tells bash to evaluate it as though you'd typed it directly into the shell:

* * * * * root bash -c "cd /tmp/ && ls"
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.