I'm using a shell script from the answer to this post to re-start a process if it exits. I have several processes that I need to start with this script, so I'm writing another script to launch them in order. I want to check that each process is launched successfully before continuing in the launch order. I've written a script similar to this.
#!/bin/sh
launch() {
exec "$1" "$2" &!
local pid="$(pidof $2)"
echo "PID: $pid"
if [ "$pid" == "" ]; do
return 1
done
return 0
}
launch [looping-script.sh] [process-to-wrap]
exit 0
When I run this script with valid arguments for launch
the script and process start and show up in ps
output, but the value of $pid
is blank and the function return 1
. However, if I take the [looping-script.sh]
argument out of the equation, like so.
#!/bin/sh
launch() {
exec "$1" &!
local pid="$(pidof $1)"
echo "PID: $pid"
if [ "$pid" == "" ]; do
return 1
done
return 0
}
launch [process-to-wrap]
exit 0
Then $pid
matches the value output by ps
for the process and the function returns 0
. Is there something incorrect about my call in the first script?
bash --version
output if it's useful:
GNU bash, version 4.3.30(1)-release (arm-petalinux-linux-gnueabi)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>