Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to use eshell inside emacs, so I don't have to switch between emacs and a terminal. When using bash, I have few bash scripts I usually source to export some env variables (in order to switch between different tool-versions and build-environments). Is it possible to somehow execute my scripts with bash, and put the exports (or some of them) in eshell.

Basically I'm trying to source a bash-script in eshell.

Is there a way to do something like that?

share|improve this question
    
This seems to be a common misunderstanding for some reason, but "source" does not mean "set a few variables"; it means (in the context of sh) "execute the commands in this file in the current context". Therefore, the answer to the question "can I source a bash file in a program that uses some other incompatible language?" is no. –  LaC Apr 20 '11 at 14:56
    
@LaC - You should post your comment as an answer IMO –  Nifle Apr 20 '11 at 14:59
    
@Nifle - your wish is my command. –  LaC Apr 20 '11 at 15:01
add comment

2 Answers

This seems to be a common misunderstanding for some reason, but "source" does not mean "set a few variables"; it means (in the context of sh) "execute the commands in this file in the current context". Therefore, the answer to the question "can I source a bash file in a program that uses some other incompatible language?" is no.

share|improve this answer
    
I knew, what sourcing is, but was trying to find a solution/workaround. Anyway, thank you, for your reply! –  siddhadev Apr 20 '11 at 16:07
add comment

I think, I found a way. I've created a my-init.el script with this content:

  bash -c "source my-init.sh > /dev/null && env |                   \
           grep -E 'MY_ENV\=' |                                     \ 
           sed -e 's/\([^=]*\)=\(.*\)/(setenv \"\1\" \"\2\" \)/g'"  \
           > /tmp/my-init-env
  source /tmp/my-init-env

When sourced from within eshell, it will start a bash, source the my-init.sh there (thus setting the MY_ENV variable), and then call env to obtain MY_ENV, and convert it with sed to something like (setenv "MY_VAR" "value") which is than sourced in the original eshell.

Not beautiful, but it does the job!

share|improve this answer
    
I asked a mod to remove the "community wiki" status. Then I upvoted you.. –  Nifle Apr 21 '11 at 12:35
add comment

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.