4

I want to automate one repeated task which I do regularly. That is creating rpm's for different architectures. To compile the code and create the rpm I need to set the project env. after setting the env I will create the rpm for the current architecture and again I should build rpms for other architecture by setting the env again.

I am trying to automate this process. The problem is once the env is set it I will be new shell so my script is not visible in the sub shell. How to automate this ??

This is what i tried.

cd $project_dir
setenv.sh x86      #creates new sub shell
make clean
make rpm
cp *rpm ~/

exit              #exit from the sub shell

setenv.sh x86_64     #creates new shell
make clean
make rpm
cp *.rpm ~/

exit

after setting the env to x86 , next commands are not getting executed.

Dinesh Reddy
  • 775
  • 1
  • 11
  • 25
  • 1
    What, exactly, does `setenv.sh` do? The next line of your script, `make clean`, won't run until `setenv.sh` returns, and it won't be running in any subshell; it will run the same shell that called `setenv.sh`. – chepner May 08 '14 at 19:11
  • setenv.sh will set the compilation environment in the new shell. – Dinesh Reddy May 09 '14 at 04:40
  • 1
    What does that mean? Are you just setting some environment variables? If so, those changes only last until `setenv.sh` exits, which is *before* `make clean` runs. – chepner May 09 '14 at 10:15

1 Answers1

6

You can force 2 parts to execute in sub-shells like this:

cd "$project_dir"

(. setenv.sh x86
make clean
make rpm
cp *rpm ~/)

(. setenv.sh x86_64
make clean
make rpm
cp *.rpm ~/)
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I tried it. ( ) will create sub-shell but in that sub-shell setenv.sh will create one more shell. so those make commands are not visible in that shell. – Dinesh Reddy May 08 '14 at 18:08
  • well i tried it. but now I couldn't set the env. I am getting errors `setenv.sh: line 464: svnenvopts.source: No such file or directory`. what does that '.' do ?? I think i lost the path after doing that. – Dinesh Reddy May 09 '14 at 04:39
  • 1
    I don't have access to `setenv.sh` so I cant guess why that error showed up. – anubhava May 09 '14 at 07:27