tags:

views:

34

answers:

1

In executing the following line in bash:

set -e
p=$(mktemp -t "${1}.$$.XX")

mktemp fails with this message:

+++ mktemp -t cpfs.c.o.5643.XX
mktemp: too few X's in template `cpfs.c.o.5643.XX'

How can I have the error on fail include errors during command substitutions? Alternatively, how can I propagate the return code form mktemp back such that set -e, or my own code can act on the result?

+2  A: 

Return code of last command is always kept in $?.

do something like:

command
ERR=$?

To not to lose that return code for later use.

polemon
I think this works :P
Matt Joiner