Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference the output of the previous command twice in Linux command?

For instance, if I'd like to reference the output of the previous command once, I can use the command below:

ls *.txt | xargs -I % ls -l %

But how to reference the output twice? Like how can I implement something like:

ls *.txt | xargs -I % 'some command' % > %

PS: I know how to do it in shell script, but I just want a simpler way to do it.

like image 356
injoy Avatar asked Dec 06 '25 11:12

injoy


1 Answers

You can pass this argument to bash -c:

ls *.txt | xargs -I % bash -c 'ls -l "$1" > "out.$1"' - %
like image 171
anubhava Avatar answered Dec 07 '25 23:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!