1


My BASH script doesn't exit properly.

#!/bin/bash  
#bootstrapper.sh
PIDD="$5"
while sleep 1; do kill -0 $PIDD || break; done
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
POSPAR1="$1" #-l
POSPAR2="$2" #location
POSPAR3="$3" #-d
POSPAR4="$4" #directory
cp -r -f $SCRIPTPATH/$4/* $2
rm -r -f $SCRIPTPATH/$4

The line:

while sleep 1; do kill -0 $PIDD || break; done

Is supposed to wait until the PID (stored in variable $PIDD) closes. It waits until it doesn't exist (the PID), but when it finally doesn't exist, it outputs: kill: 4: No such process. The rest of the script works as intended, but then the script doesn't terminate. Can I make the script terminate properly and not have that No such process be outputted?
Thanks again for all your help - I'm new to BASH/Linux.

1 Answer 1

3
while sleep 1; do kill -0 $PIDD 2>/dev/null || break; done

or

while kill -0 $PIDD 2>/dev/null; do sleep 1; done
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.