Daniel Lizik
Daniel Lizik

Reputation: 3144

concat string with variables via xargs

Say I want to touch six files

one.html
one.css
two.html
two.css
three.html
three.css

How can I use xargs for this? I'm looking at the man page but I'm not sure on the syntax for getting the stdin pipe.

$ echo one two three | xargs -n 1 touch $1.html $1.css // nope

Upvotes: 2

Views: 1819

Answers (3)

John1024
John1024

Reputation: 113834

If it is important to use xargs:

printf "%s\n" one two three | xargs  -I{} touch {}.html {}.css

Upvotes: 7

anubhava
anubhava

Reputation: 785058

It is easier to do via shell ist:

touch {one,two,three}.{css,html}

This will create 6 files:

one.css one.html two.css two.html three.css three.html

Upvotes: 4

karakfa
karakfa

Reputation: 67467

alternative with for loop

for f in one two three; do touch $f.html $f.css; done

Upvotes: 1

Related Questions