help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to print the actual command for BASH_COMMAND in trap?


From: Peng Yu
Subject: How to print the actual command for BASH_COMMAND in trap?
Date: Sat, 12 Jun 2021 21:32:07 -0500

In the following script, 'true' is printed twice.

My understanding is that, for trapped command ('false' in this),
BASH_COMMAND is still the last command before the trap ('true'). Is it
the case?

$  ./main.sh
declare -- BASH_COMMAND="true"
declare -- BASH_COMMAND="true"
$ cat  ./main.sh
#!/usr/bin/env bash
trap 'false' EXIT
trap 'declare -p BASH_COMMAND' DEBUG
true

Is there a way to print 'false' instead of 'true' for the last print
of BASH_COMMAND?

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]