Search code examples
bashcommand-linecontrols

How to save/acquire Bash post 'eval ' command line string that's about to be executed


How do we get/save final command line string accepted and executed by bash right after doing eval
very hard to explain, so really helps when xtrace is on, e.g:

$ cmd=ls; f=package.o ; eval $cmd $f
+ cmd=ls
+ f=package.o
+ eval ls package.o
++ ls package.o
package.o

We see xtrace print out 2nd last string (having dropped prefix ++):

 ls package.o

which must be in a Bash variable


Solution

  • You could redefine eval to save its arguments:

    eval(){
        eval_args=("$@")
        builtin eval "$@"
    }