I am running this bash command:
xe pbd-unplug uuid=$PBDUUID
PBDUUID
xe sr-forget uuid=$SRUUID
Error: No PBD.
sys.exit()
if else then
sys.exit()
if [ -z ${PBDUUID} ]; then
if xe pbd-unplug uuid="$PBDUUID"; then xe sr-forget "uuid=$SRUUID"; else echo "Error: No PBD."; exit 1; fi
More readably, that is:
if xe pbd-unplug uuid="$PBDUUID"; then
xe sr-forget "uuid=$SRUUID"
else
echo "Error: No PBD." >&2
exit 1
fi
BTW, if your goal is to check whether a variable is blank, that would look more like the following:
if [ -z "$PDBUUID" ]; then
xe pdb-unplug uuid="$PDBUUID" && xe sr-forget "uuid=$SRUUID"
else
echo "Error: No PBD." >&2
exit 1
fi
If exit
doesn't do as you intend, then this code is presumably running in a subshell, and thus exit
is exiting that subshell rather than your script as a whole. See SubShell or the "Actions that Create a Subshell" section of the processtree bash-hackers.org page.