LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I make a text file in Bash? (https://www.linuxquestions.org/questions/programming-9/how-do-i-make-a-text-file-in-bash-517070/)

RAdams 01-07-2007 01:39 AM

How do I make a text file in Bash?
 
All I want to do is write a script that makes a text file called "test" containing the text:
Code:

Hello World!
This is my stupid text file.

in the directory /foo/bar

I know it can be done easily... but I don't know how.

:newbie:

RAdams 01-07-2007 01:44 AM

Solved. Thanks to Google, I remembered something very basic I had forgotten:
Code:

>>
le sigh. So the solution is this:

Code:

echo -e "Hello World!\nThis is my stupid text file." >> /foo/bar/test

fotoguy 01-14-2007 05:56 AM

There is also another way that works better especially if you need to add lots of lines of text, you can use the cat commad and run it through a script.

Code:

#!/bin/sh
cat > test << EOF
Hello World!
This is my stupid text file.

You
can also
have
a whole lot
more text and
lines
EOF

You can also point it to a directory that you want the file created in.

Code:

#!/bin/sh
cat > /home/billy/test << EOF
Hello World!
This is my stupid text file.

You
can also
have
a whole lot
more text and
lines
EOF



All times are GMT -5. The time now is 04:38 PM.