Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a file with "echo" or "cat" ?

Status
Not open for further replies.

hpaille

Programmer
Apr 16, 2003
37
FR
I have a script creating a file, but I am not sure of the best way to do it. Should it be
echo "...." > test
or
cat filename <<EOF
...
EOF

The file is a script itself containing quotes.

Thanks for your answers
 
Hi

It is not matter of "best way", but the "easiest way". But as you put the question like that, I would like to mention that [tt]echo[/tt] is a shell built-in function while [tt]cat[/tt] is an executable. That means that [tt]echo[/tt] should be faster, while [tt]cat[/tt] should be more portable between shells.
Code:
[blue]master #[/blue] type echo
echo is a shell builtin

[blue]master #[/blue] type cat
cat is /usr/bin/cat

Feherke.
 
For just creating an empty file, I use [tt]touch[/tt]. See the man page for usage.
Code:
touch filename
That also has the advantage of not clearing out a file if it already exists (if that's what you want).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top