user1972031
user1972031

Reputation: 557

Redirect argument from a file to a Linux command

I searched the Internet, but maybe I used the wrong keyword, but I couldn't find the syntax to my very simple problem below:

How do I redirect a file as command line arguments to the Linux command "touch"? I want to create a file with "touch abc.txt", but the filename should come from the filename "file.txt" which contains "abc.txt", not manually typed-in.


[root@machine ~]# touch < file.txt
touch: missing file operand
Try `touch --help' for more information.
[root@machine ~]# cat file.txt
abc.txt

Upvotes: 1

Views: 913

Answers (2)

Thomas Dickey
Thomas Dickey

Reputation: 54563

Alternatively, if you have multiple filenames stored in a file, you could use xargs, e.g.,

xargs touch <file.txt

(It would work for just one, but is more flexible than a simple "echo").

Upvotes: 1

damienfrancois
damienfrancois

Reputation: 59250

Try

$ touch $(< file.txt)

to expand the content of file.txt and give it as argument to touch

Upvotes: 5

Related Questions