EOF in SHELL
Contents
SHELL中打印字符时用echo
, 当打印N多行字符时,显然ECHO有点吃力。这时候就需要EOF上场了。
|
|
Here Document
专业术语Here Document,是一种特殊的IO重定向,EOF=End of File
.
EOF
作为分隔符代号,可以写成任意字符,只需要保证前后一样即可.1 2 3 4
cat <<abcdefo Any char is OK! abcdefo
当不需要转义,即想输出变量值是。去掉双引号。 下面输出
echo HELLO WORLD
1 2 3 4
VAR="HELLO WORLD" cat <<var echo ${VAR} var
高级用法可以输出template文件。这们可以输出文件到
template.txt
。1 2 3 4 5 6
NAME=wxdlong AGE=18 cat <<template>template.txt Hello ${NAME} Your age is ${AGE} template
定义带换行的变量值。
echo "${variable}"
试试看输出?1 2 3 4 5
variable=$(cat <<SETVAR This variable runs over multiple lines. SETVAR )
当注释用.
1 2 3 4 5 6 7 8 9
: <<COMMENTBLOCK echo "This line will not echo." This is a comment line missing the "#" prefix. This is another comment line missing the "#" prefix. &*@!!++= The above line will cause no error message, because the Bash interpreter will ignore it. COMMENTBLOCK
替换交互输入。
Author wxdlong
LastMod 2019-08-05