How to insert ctrl + d in my linux script?

I want to do the following commands:

cat> template.txt [type in terminal] text [Ctrl + d in terminal]

in the script.

Is there a way to tell the script to do enter \ Ctrl d? Is there a way to create a file and write it to a script?

I did not find anything that would work for me.

Thank.

+1
linux bash terminal cat
Nov 01 '15 at 4:30
source share
2 answers

A Here, the Document is similar to the script version of what you are talking about, I think, although this is not entirely clear to me from your description.

#!/bin/bash cat > template.txt <<- EOF Here is some text. EOF 

Ctrl-D itself is a symbol of EOF, ASCII 4.

+6
Nov 01 '15 at 4:37
source share

If you want the user user to enter lines and add them to your file until the user enters ^ D, you can use the following script:

 echo "Please give input" while read -r line; do echo "Enter next line or ^D" echo "${line}" > template.txt done echo "After loop" 

You do not need to check for the presence of ^ D, which will be recognized by reading without doing anything extra. Therefore, you do not need to use CTRL-V CTRL-D in vi .

0
Nov 01 '15 at 10:31 on
source share



All Articles