How to 'source' a shell script using bash from zsh?

06
2013-08
  • Gnurou

    I am using zsh and like it very much, but work a lot with Android source which has compilation scripts that require bash to be evaluated correctly. These scripts need to be sourced prior to compilation and define environment variables and shell functions that are used during compilation.

    Zsh cannot source these files, and if I try to issue emulate bash my shell becomes non-functionnal with plenty of these error every time I hit space (I am using oh-my-zsh, maybe that is a cause?):

    url-quote-magic:24: bad pattern: ( ):/(|/localhost)/*
    

    Is there a way for me not to switch to bash to evaluate these files, or to invoke a bash instance and import the new environments variables/functions it defined during sourcing into my zsh session? Or I am doomed to switch to bash every time I need to work on Android?

    EDIT: found an answer to my own question. Sourcing a file using another shell does not seem to be possible, but in the case of Android macro files failing, this page brought a fix:

    http://nilvec.com/building-cyanogen-from-source/

    Basically, simply setting unsetopt nomatch will ask zsh to stop complaining about unmatched wildcards, which is enough to bring the scripts to completion. There will still be one error remaining, about the use of the complete bash internal command to add completion capabilities to one Android macro, but it is absolutely not critical here.

  • Answers
  • Isaac

    You could put your compilation commandline in a bash script, which sources the compilation scripts bevor executing the compilation command.

    Something like

        #!/bin/bash
        . /path/to/environmentscript
        . /path/to/morefunctionsscript
    
        compile_command
    

    Then instead of invoking compile_command by hand, you just invoke your new bash script.


  • Related Question

    Bash autocomplete like zsh
  • G Gordon Worley III

    I'm using bash, but I'd like to have zsh style autocomplete (you hit tab and it tabs through the possibilities), rather than what bash seems to do, which is display a list of possibilities but not choose anything until I type some more to disambiguate. How can I get zsh type behavior in bash?

    Searching for a solution has turned up lots of answers to other questions, so I'm hoping I can get a simple answer here (i.e. what to paste into my .bashrc).

    (And to answer the obvious question, I need to use bash here because I just joined a team and they do some stuff to set up bash to make the environment easier to work in. I can probably eventually make sure I have it working the same way in zsh, but for now it's easier if I use bash and just get it behaving more like zsh during interactive use.)


  • Related Answers
  • Wuffers

    I use

    bind 'TAB:menu-complete'
    

    to achieve it