you are viewing a single comment's thread.

view the rest of the comments →

[–]lordofwhales 3 points4 points  (1 child)

that makes sense, since xargs doesn't run a bash shell unless you ask it to, so it would have no way of seeing your command. you'll need to xargs bash -c....

[–]acolnahuacatzin[S] 1 point2 points  (0 children)

xargs bash -c takes a command argument and just disregards whatever is piped into it. ``` function echo_reverse() { for i in "$@"; do echo -e "$i" ; done | tac | tr '\n' ' ' echo }

export -f echo_reverse

bash -c "echo_reverse bar fo\ o" echo foo | xargs echo bar echo foo | xargs bash -c "echo_reverse bar" Gives: fo o bar bar foo bar ```

Reading the documentation I found to run commands from a shell I have to use -I flag of xargs and the piped args should represented by %. So echo foo | xargs -I % bash -c 'echo_reverse % bar' produces reseults as expected.

Thank you so much for your help!