Jamie
Jamie

Reputation: 7411

Is this a useless use of `cat`?

I can't figure out how to make the following work without using cat. I'm not worried about the forked process or anything, it just unsettles me:

$ printf "<format specification string>" $(cat source-file.txt)

Is there a better way?

Upvotes: 3

Views: 632

Answers (2)

Alex
Alex

Reputation: 11090

Even though it is useless use of cat, I would still use cat for outputting contents of a file instead of < in this case because it eliminates the possibility of overwriting the input file due to a redirect character typo (>)

Upvotes: 0

Adam Liss
Adam Liss

Reputation: 48290

Yes. You can accomplish the same thing, without creating a new process for cat, with:

$ printf "<format specification string>" $(<source-file.txt)

Upvotes: 7

Related Questions