linux - 如何将 ctrl+d 插入到我的 linux 脚本中?

标签 linux bash terminal cat

我想执行以下命令:

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

在脚本中。

有没有办法告诉脚本执行 enter\Ctrl d? 有没有办法创建一个文件并用脚本写入它?

我没有找到适合我的东西。

谢谢。

最佳答案

A Here Document我认为这有点像您所谈论内容的脚本版本,尽管从您的描述中我并不完全清楚。

#!/bin/bash

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

Ctrl-D 本身 EOF 字符,ASCII 4。

关于linux - 如何将 ctrl+d 插入到我的 linux 脚本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33459219/

相关文章:

terminal - 使用完整的 URL 作为 wget 保存的文件名

linux - 在 Linux/Bash 中随机改组行

linux - 如何在 bash 末尾使用没有参数的 getopts 选项

linux - Bash 脚本命令在 '<' 之后不显示

bash - 在 "vagrant ssh"时自动 chdir 到 vagrant 目录

linux - 如何从 tcl 脚本记录 xterm 窗口

macos - Mac OS X : Bring (non-bundle) GUI applications to foreground when launched from the command line

c - 如何读取用 popen 打开的进程的标准输出(with\r)

linux - 如何使用 grep 从特定字符串位置获取文本?

python - 使用 numpy.memmap 映射设备文件