3

As an example: I have working shell script which starts up weblogic (which will continue to run) and then do deployment

At the end I bring background process back to foreground, so that shell script does not exit (Exited with code 0)

#!/bin/bash

set -m
startWebLogic.sh &

# create resources in weblogic
# deploy war
# ...

jobs -l
fg %1

I had to use set -m, to allow job control, but I also found it is not cleaniest way to use it in non-interactive shells.

Is there a better way to handle it?

2

As far as I understand your question you are looking for wait:

#!/bin/bash

startWebLogic.sh &

# create resources in weblogic
# deploy war
# ...

wait

It does not "bring the process to foreground". But it does wait until weblogic returns. So the shell script does not exit until weblogic exits. Which is the effect you achieved with fg %1.

from help wait:

Waits for each process identified by an ID, which may be a process ID or a job specification, and reports its termination status. If ID is not given, waits for all currently active child processes, and the return status is zero.

  • I wasn't aware of such feature of wait. Thanks a lot! – Patrik Mihalčin Nov 25 '16 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.