Artificial intelligent assistant

Is it possible for a function to distinguish if it is run like this? "${@}" This is my simplified script. **I am wondering if the proc() can know if it is run directly or through the runner.** #!/bin/bash runner () { "${@}" } proc() { eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")' echo -e "$version"; return 0 } runner proc proc What do you think?

`proc` is not a separate process in your example. It's just a function, run in the same process as the main shell.

The `$FUNCNAME` array gives it access to its backtrace:


foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }

$ foo
proc baz bar foo main


So yes, it can:


case ${FUNCNAME[1]} in runner) ...


If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:


foo(){ (bar &) | cat; }
=> same output

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a9d3cf4490d5c3b59a8e844df5f8fd60