Home>
Question

I want to pass the contents of an array to xargs one by one with bash.
How can I solve it using xargs?

Although it can be solved by using other methods (for sentence etc.),
Please use xargs to check how to use xargs.

Script
#!/bin/bash
tmparr = (
aaa
bbb
ccc
)
echo "deli = *"
echo ${tmparr [*]} | xargs -n1 -t -i echo {}
echo
echo "deli = @"
echo ${tmparr [@]} | xargs -n1 -t -i echo {}
echo
echo "deli = * with quot"
echo "${tmparr [*]}" | xargs -n1 -t -i echo {}
echo
echo "deli = @ with quot"
echo "${tmparr [@]}" | xargs -n1 -t -i echo {}
echo

Result

deli = *
echo aaa bbb ccc
aaa bbb ccc
deli = @
echo aaa bbb ccc
aaa bbb ccc
deli = * with quot
echo aaa bbb ccc
aaa bbb ccc
deli = @ with quot
echo aaa bbb ccc
aaa bbb ccc

→ I want to process aaa, bbb, ccc line by line