linux - "<<"运算符如何在 linux shell 中工作?

标签 linux shell

我知道以下代码会在/opt/hadoop/conf 目录中创建一个文件 core-site.xml。有人可以用 linux shell 术语为我分解它吗?特别是 << 运算符 & CORE_EOF?这些标记是如何工作的?我有点理解这一点,但想了解得更多。

cat >/opt/hadoop/conf/core-site.xml <<CORE_EOF
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>fs.default.name</name>
    <value>hdfs://localhost:8020</value>
  </property>
</configuration>
CORE_EOF

最佳答案

带有 << 运算符的命令将执行以下操作:

  • 启动运算符左侧指定的程序,例如 cat。
  • 抓取用户输入,包括换行符,直到在一行中满足运算符右侧指定的内容,例如 EOF
  • 将读取到的除EOF值外的所有内容发送到左侧程序的标准输入。

    cat << EOF
    Hello
    World
    EOF
    

会发送“你好”

世界”

到猫的标准输入。

这和这样做是一样的:

cat < file

文件包含:

Hello
World

关于linux - "<<"运算符如何在 linux shell 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12168523/

相关文章:

linux - Linux 中的当前用户路径?

linux - rpmbuild 正在/usr/local 中构建我的目标目录,而不是我指定的位置

linux - Rider 没有看到 NetCore 3.0

linux - Vagrant.configure 的语法错误 ("2") do |config|, while trying to run a script file

linux - 记录 shell 脚本的参数

python - 用于组织音乐的 python 脚本中的缩进错误

linux - 如何终止 shell 脚本中的 fork 进程?

c - 在 C 中执行时显示完成百分比

bash - 如何使用 shell 脚本检查存储桶是否存在?

linux - 如何在 Shell 脚本中仅从变量返回整数并丢弃字母和前导零?