Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run commands in subshell

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.

like image 447
Dinesh Reddy Avatar asked Oct 16 '25 19:10

Dinesh Reddy


1 Answers

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 ~/)
like image 158
anubhava Avatar answered Oct 18 '25 11:10

anubhava