I have the following code in my .bash_profile that automates a couple of file write tasks I need to run.

# Compile cron jobs for server
cd ~/Sites/MAMP/mywebsite/.ebextensions && sed 's/WEBSITE_URL/mywebsite.com/g' ./cron_jobs_sample.txt > ./cron_jobs.txt

# Compile config file so that we push to the right server
cd ~/Sites/MAMP/mywebsite/.elasticbeanstalk/ && echo "[global]
Region=xxxx" > ./config

# Do compiling
alias websitecompile=do_cron && do_config

I simply call:

$ websitecompile

And it runs my tasks.

The issue is it runs do_cron just fine, but do_config does not run. If I switch my code to run do_config first, both run fine.

alias websitecompile=do_config && do_cron

So something in do_cron seems to kill the process. I want to keep expanding on these commands so is there any way to stop it from stopping.

I am running Max OS X Mavericks.

Any ideas on what I can do to make this work as expected?

  • 1
    Using && between commands means the next command will only run if the first has no errors (exits with code 0). Have you gone through each command to verify they work? Run each command one at a time and do echo $? immediately after running it so verify the exit code is 0. Also, this is probably better suited for superuser as there's nothing specific to server administration here.
    – yoonix
    Apr 30, 2014 at 23:23
  • Thanks for your help. Whoops, I'm still very new with the command line so apologies if I'm on the wrong site. Yes I have verified they all work. I just ran cd ~/Sites/MAMP/mywebsite/.ebextensions && sed 's/WEBSITE_URL/mywebsite.com/g' ./cron_jobs_sample.txt > ./cron_jobs.txt && echo $? and it returned 0. Anything else I could try?
    – Ben Sinclair
    Apr 30, 2014 at 23:34

3 Answers 3


Are there missing quotes in the script excerpt? Because the command:

alias websitecompile=do_cron && do_config

will alias websitecompile to do_cron, and immediately execute do_config (not include it in the alias). What you want is:

alias websitecompile='do_cron && do_config'

...which will include both commands in the alias.

  • 1
    Nice catch. I missed that entirely.
    – yoonix
    Apr 30, 2014 at 23:50
  • That was it! Thanks so much! I'm a bit of a n00b but learning fast!
    – Ben Sinclair
    May 1, 2014 at 0:16

From the Bash documentation for aliases:

For almost every purpose, shell functions are preferred over aliases.

websitecompile () { do_cron && do_config; }

I would check exit status for each command executed inside do_cron() and return a right function status if they are well executed. I think some command is exiting with a n unexpected status that makes fail the do_cron && do_config condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy