I'm using function like this.$ find-grep () { find . -type f -name $1 -print0 | xargs -0 grep $2 ; }After I type:$ find-grep *.c fooI want to get expanded last command string. In this case:find . -type f -name *.c -print0 | xargs -0 grep fooIs there way to do it easily?
How to show last command with expanding function in bash
bash;command history;function
A saner version of @slm's:find-grep() {  cmd=(find . -type f -name $1 -exec grep $2 {})  printf '%q ' ${cmd[@]}  printf '+\n'  ${cmd[@]} +}(no need for pipes or xargs here) Or:find-grep () (  set -x  find . -type f -name $1 -exec grep $2 {} +)(note the () instead of {} to start a subshell to limit the scope of set -x. Note that it does not cause more processes to be forked it's just that the fork for the process that will execute find is done earlier).Remember you need to quote wildcard characters so they are not expanded by the shell:find-grep '*.c' patternIf instead, you want it to be pushed to the history, so that you see the expanded command when you press the Up key, you could write it:find-grep() {  cmd=$(printf '%q ' find . -type f -name $1 -exec grep $2 {})+  history -s $cmd  eval $cmd}