Reputation: 780
I've got a script that writes to a file, like so:
cat >myfile <<EOF
some lines
and more lines
EOF
but I'm not sure whether this is a Useless Use of Cat or not...
Upvotes: 10
Views: 3586
Reputation: 8199
Even if this may not be a UUOC, it might be useful to use tee
instead:
tee myfile <<EOF
some lines
and more lines
EOF
It's more concise, plus unlike the redirect operator it can be combined with sudo
if you need to write to files with root permissions.
Upvotes: 8
Reputation: 10937
In zsh it is a UUOC because:
>myfile <<EOF
some lines
and more lines
EOF
Works fine.
Upvotes: 2
Reputation: 3974
UUOC is when you use cat
when it is not needed. As in:
cat file | grep "something"
Instead you can do it whithout cat:
grep "something" file
Look here for the original definition of UUOC.
Upvotes: 2
Reputation: 16389
It is not really a UUOC. You can also do the same with echo:
echo "this is line
this is another line
this is the last line" > somefile
Upvotes: 2