"<<" 與 "<<<"

 

 


"<<"

 

It is known as here-document structure.

It tell wcprogram(cat) to wait for EOFstring

e.g.

cat << EOF
> test
> msg
> EOF

 


"<<<"

 

It is known as here-string.

功能: a pre-made string of text to a program.

e.g. 作為單純 string 的情況

bc <<< 5*4

原理

It implemented via temporary files, usually in the format /tmp/sh-thd.<random string>

e.g. 作為 pre-made string 的情況

bc <<< "$a*$b"

The word undergoes

  • tilde("~~") expansion               # ~ = $HOME
  • parameter and variable expansion
  • command substitution
  • arithmetic expansion              # $(( expression ))
  • quote removal
  • Filename expansion and word splitting are not performed