I am looking at how to generically print in the Bash script the command input which has failed.
So instead of:
date -q || { echo "date -q"; return 1; }
I would like to have in my script something like
date -q || { echo !!; return 1; }
or
date -q || { fc -ln -1; return 1; }
Then, I can use compactly always the same code to print the command input which has failed in the script.
However, both attempts above, echo !! and fc -ln -1, do not solve the problem
echo !!to work you'd needset -o history -o histexpandbut it can't work on the same line because the whole line is a command, you'd have to use a condition with$?in a separate lineevalor better an array, see unix.stackexchange.com/a/444949/198262