Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Here Document

Shulou Source: shulou.com Published: 2022-06-01 13:30:59 10月28日 Update

This article mainly introduces how to use Here Document, the introduction in the article is very detailed, has a certain reference value, interested friends must read!

Here Document is widely used in shell in Linux/Unix, especially to pass in multiline split parameters to execute commands. In addition to shell (including sh/csh/tcsh/ksh/bash/zsh, etc.), the functionality of this approach also affects many other languages such as Perl,PHP and Ruby.

The basic form of Here Document is as follows:

Command

Its purpose is to pass the content (document) between two delimiter as input to command.

Note:

The delimiter at the end must be written at the top, with no characters before it and no characters after it, including spaces and tab indentation. Spaces before and after the initial delimiter are ignored. The instance calculates the number of lines of Here Document through the wc-l command on the command line:

The output of $wc-l # is 3 lines $

We can also use Here Document in scripts, such as:

#! / bin/bash# author:# url: https://www.yisu.com/cat

Execute the above script and output the result:

Welcome to https://www.yisu.com/ above is all the content of this article "how to use Here Document". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Content commands characters spaces articles results scripts outputs two between values roles interests functions parameters examples guys buddies forms ways Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Linux MySQL Xiaomi