how to insert ctrl+d into my linux script?

女生的网名这么多〃 提交于 2019-12-02 08:08:06

A Here Document is kind of like a script version of what you're talking about, I think, although it is not entirely clear to me from your description.

#!/bin/bash

cat > template.txt <<- EOF
    Here
    is some 
    text.
EOF

Ctrl-D itself is the EOF character, ASCII 4.

When you want an interactieve user enter lines and add them to your file until the user enters an ^D you can use the next 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 have to check for ^D, that will be recognized by read without doing something extra.So you do not need to use CTRL-V CTRL-D in vi.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!