emeraldemon emeraldemon - 2 months ago 10
Ruby Question

How can I change directories in a homebrew formula?

I am trying to create my own homebrew formula using

brew create
and
brew edit
.

As part of the install for this project I need to change into a sub directory and build things there, for example

cd sub/dir/place
make -f makefile otherMakeTarget


I tried adding to my formula.rb

system "cd", "sub/dir/place/"
system "make", "etc"


But it doesn't seem to do the cd correctly. The logfile 01.cd shows the cd and the argument on two separate lines, I'm not sure if that's the problem.

Answer

Calling system creates a subshell and any modifications to the working directory go away when that call completes.

You could try using chdir:

Dir.chdir('sub/dir/place')
Comments