Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a little new to Shell Scripting and I want to create a new file inside the script and want to add content and then close it. It should not take the arguments from the user. Everything from the path and content is predefined. Was it possible?

share|improve this question
up vote 8 down vote accepted

Just use output redirection. E.g.


echo "some file content" > /path/to/outputfile

The > will write all stdin provided by the stdout of echo to the file outputfile here.

Alternatively, you could also use tee and a pipe for this. E.g.

echo "some file content" | tee outputfile

Be aware that any of the examples will overwrite an existing outputfile.

If you need to append to a currently existing file, use >> instead of > or tee -a.

If you don't accept user input in this line, no user input can change the behaviour here.

share|improve this answer
And if you nee a multiline content which also contains quotes, etc. you can use echo with this option: echo -e "some \"file\" content\nsome more \"file\" content" > outputfile.txt – Sadi May 7 '15 at 9:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.