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

A user crontab entry that reads:

0 */4 * * * $HOME/postscript/fprogcache-sync

works fine. Wanting to add a few environment variables to the cron-job context, I then tried

0 */4 * * * source $HOME/.profile; $HOME/postscript/fprogcache-sync

That did not work until I changed source for .. The error message (sent by postfix mail to root) was /bin/sh: 1: source: not found, followed by confirmation that the script went on to execute happily.

I remember having read somewhere that source is defined as an alias of the builtin . in the bash shell. If so, it would explain why source is not recognized in the cron context.

Is it the case? If so, where is the system wide alias for . defined?

share|improve this question
up vote 4 down vote accepted

Is it the case? If so, where is the system wide alias for . defined?

It is the case, but there's no such thing as a system-wide alias.

. and source are the same builtin in Bash, but that's defined directly at the source code's level (http://askubuntu.com/a/25491/380067).

The reason behind having two names for the same builtin most likely resides in the fact that Bash aims to be POSIX-compliant to some extent; so source for the sake of providing a mnemonic name and . for the sake of complying with POSIX's standards.

The real reason why source doesn't work in cron is that by default cron jobs in the crontab are excuted in sh, which is a symlink to /bin/dash (a shell that aims to be POSIX-compliant as well) which simply doesn't implement source. However it does implement ..

From man dash:

. file
       The commands in the specified file are read and executed by the
       shell.
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.