9

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.

Tracker1
  • 335
  • 2
  • 4
  • 13

3 Answers3

14

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
glenn jackman
  • 18,218
1

Use

cat > some_file

to write into the file some_file. End your input with Ctrl+D

0

echo "Hello" > test.txt

This will OVERWRITE "hello" in to the test file. If the file did not exist it will create it

echo "Hello2" >> test.txt

This will add a NEW line in the file with hello2

wlraider70
  • 1,683