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. How can I do it?
Shell Scripting – Creating a File with Some Content in Shell Scripting
bash
Best Answer
Just use output redirection. E.g.
The
>
will write allstdin
provided by thestdout
ofecho
to the fileoutputfile
here.Alternatively, you could also use
tee
and a pipe for this. E.g.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>
ortee -a
.If you don't accept user input in this line, no user input can change the behaviour here.