In poking about with xargs
, as here:
nicholas@gondor:~/x$
nicholas@gondor:~/x$ xargs echo < list.txt
1 2 3
nicholas@gondor:~/x$
nicholas@gondor:~/x$ cat list.txt
1
2
3
nicholas@gondor:~/x$
how would xargs
give output like:
number is 1
number is 2
number is 3
rather than just the numbers as is currently the result?
I tried using the $
symbol with echo, but wasn't getting the correct output.
also tried:
nicholas@gondor:~/x$
nicholas@gondor:~/x$ printf '%s\n' "${list.txt[@]}" | xargs
bash: ${list.txt[@]}: bad substitution
nicholas@gondor:~/x$
but that's apparently not reading in the file correctly.
Would prefer to use echo
over printf
unless it's overly awkward.
another attempt:
nicholas@gondor:~/x$
nicholas@gondor:~/x$ xargs echo 'numbers are ${}' < list.txt
numbers are ${} 1 2 3
nicholas@gondor:~/x$
but not sure how to get each number above on a separate line.
see also:
Printing an array to a file with each element of the array in a new line in bash