Ubuntu – How to input to a file directly from the terminal

bashcommand linefilesinput

Other than bringing up a text editor, is there a way I can input text in a linux terminal directly to a file? (then enter a control code such as ctrl-c, to end the input)

I'm pretty sure there's a way to do this… I am SSH'd to a server with Docker, and running bash inside a container, so that I can test some stuff, I just want to be able to paste a small script in my terminal window, and have that output to a file inside the container's shell.

Thanks.

Best Answer

a useful use of cat: provide input on stdin

cat > filename
enter text
hit Ctrl-D to stop

or use a heredoc

cat > filename << END
enter text
provide the terminating word to stop
END