I want to get the pids of two background processes,
sleep 20 & pid1=$\\!; sleep 10 & pid2=$\\!; echo \"pid1: $pid1, pid2: $pid2\"
and
The backslash is causing the value to be the string $!
verbatim. Don't put a backslash in the assignment.
On the command line, you may want to temporarily set +H
to avoid getting event not found
warnings; but this only affects the interactive shell. In a script, set -H
is never active (and would be meaningless anyway).
(I'm speculating this is the reason you put the backslash there in the first place. If not, simply just take it out.)