I'm using a piece of software (QIIME) that uses its own subshell to run commands:

You no-longer type "macqiime" before QIIME commands! Instead, you just type "macqiime" once when you start a new terminal session. That will start a new subshell with the QIIME environment variables sourced.

Once you've done that, you can run all the qiime commands you want without the "macqiime" command.

I'm developing a bash script which automatically launches jobs and which should automatically run a script through the QIIME environment. I know how to do it manually from the command line (as detailed above); however I don't know how to do it automatically from the bash script.

Can someone help? Thanks!


you can find a solution to what I'm trying to do by reading the section "Advanced MacQIIME hacking"


You want to run a script using macqiime as the interpreter.
That's what you can specify with the #! in the first line.

Start your script with this as the first line (with the real path):


If it's not clear where in PATH the program is, but it is in PATH, you can use

#!env macqiime

as first line - it has to be really the first line, with no blank lines, and no commented lines before.


It turned out that the command macqiime can not be used like described above, see below how it is used. But that it does not work like this seems to have no other reason than that it's a very minimal script that just does not implement reading from stdin.

So in the general case, for other programs that behave like described in the question, the answer above should apply.

In the special case of macqiime, the documentation explains what to do instead for using that software in a shell interpreter style:

You have to write your own script with something like:

source /macqiime/configs/bash_profile.txt
align_seqs.py -i "$@"

If the script is called qiime_script then you can call it from the command line with: qiime_script options where options gets passed to $1, $2 etc.

  • Ah yes, that makes sense; however my script has a mix of commands that use perl, python and macqiime; how do I account for this? – Constantino Sep 30 '14 at 19:26
  • I would normally use separate scripts to implement parts in other languages. If you insist to have it in one file, and the macqiime shell supports it, you could use here documents to include sections of other code. I think the shell does support it, because it seems to be bash or $SHELL with some extra variables set etc. – Volker Siegel Sep 30 '14 at 19:36
  • great! I'll split it up into two scripts. Thanks for the quick help. – Constantino Sep 30 '14 at 19:56
  • I'm having trouble finding my path/to/macqiime :( my $PATH is currently: //anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql-5.6.21-osx10.8-x86_64/bin:/usr/local/mysql/bin Also, your suggestion of #!env macqiime doesn't work either. – Constantino Sep 30 '14 at 20:08
  • Hmm... it's not 100% clear from the description whether the shell works like I think it does, but I still think it works that way. How do you normally start macqiime? What does command -v macqiime say? – Volker Siegel Sep 30 '14 at 20:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.