From: Rick DeNatale Date: 2007-06-09T23:14:29+09:00 Subject: Re: using ` and the bash source command On 6/9/07, Kevin Jackson wrote: > Hi all, > > I have this code : > `source ~/.bash_profile` > > As part of a script. But when this line executes I get a sh: command > not found. This looks to me like ruby's ` is running /bin/sh instead > of /bin/bash > > So a bit of searching on google and I discover that it's possible to > do something like: > %x{/bin/bash -c "source ~/.bash_profile;"} > > This doesn't fail with the command not found, but it doesn't actually > source the file - so it's fairly useless. > > Does anyone have a workaround for getting ruby to exec the bash source > command correctly? I think I've tried every combination in the docs > and nothing seems to work. Because source isn't a command, it's a bash builtin, rick@bill:~$ man source No manual entry for source rick@bill:~$ which source rick@bill:~$ An excerpt from man bash SHELL BUILTIN COMMANDS ... source filename [arguments] Read and execute commands from filename in the current shell environment and return the exit status of the last command exe‐ cuted from filename. The source built-in in bash is roughly equivalent to include in C, or load in Ruby. Now I think that: %x{/bin/bash -c "source ~/.bash_profile;"} %x{/bin/bash -c "~/.bash_profile;"} do pretty much the same thing, they will execute ~/.bash_profile The problem is that most bash profiles are used primarily to set environment variables within a bash process, any such variables would only be in the environments of the bash process and it's children, not the parent process. What effect were you expecting to see? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/