Most shells, including Bash support here documents which enable you to embed text as part of a command using the << operator and some text to use as a delimiter.
In the following example, text is passed to the tr command using a here document and END_TEXT as the delimiting identifier which specifies the start and end of the here document.
$ tr a-z A-Z <> one two three
> uno dos tres
> END_TEXT
ONE TWO THREE
UNO DOS TRES
The output lines produced from tr after execution are ONE TWO THREE and UNO DOS TRES.
A common use of here documents is to add text to a file. By default variables and also commands in backticks are evaluated:
$ cat << EOF
> Working dir $PWD
> EOF
Working dir /home/user
This can be disabled by setting the label in the command line in single or double quotes:
$ cat << "EOF"
> Working dir $PWD
> EOF
Working dir $PWD
In the following example, text is passed to the tr command using a here document and END_TEXT as the delimiting identifier which specifies the start and end of the here document.
$ tr a-z A-Z <
> uno dos tres
> END_TEXT
ONE TWO THREE
UNO DOS TRES
The output lines produced from tr after execution are ONE TWO THREE and UNO DOS TRES.
A common use of here documents is to add text to a file. By default variables and also commands in backticks are evaluated:
$ cat << EOF
> Working dir $PWD
> EOF
Working dir /home/user
This can be disabled by setting the label in the command line in single or double quotes:
$ cat << "EOF"
> Working dir $PWD
> EOF
Working dir $PWD
Comments
Post a Comment
https://gengwg.blogspot.com/