Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

bash - What does "cat > somefilename <<EOF" (particularly, the greater-than and double less-than symbols) do in shell?

Just came across the following command:

cat > myspider.py <<EOF

But I'm not sure of the use of > and <<.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

<<EOF is the start of a heredoc. Content after this line and prior to the next line containing only EOF is fed on stdin to the process cat.

> myspider.py is a stdout redirection. myspider.py will be truncated if it already exists (and is a regular file), and output of cat will be written into it.

Since cat with no command-line arguments (which is the case here because the redirections are interpreted as directives to the shell on how to set up the process, not passed to cat as arguments) reads from its input and writes to its output, the <<EOF indicates that following lines should be written into the process as input, and the >myspider.py indicates that output should be written to myspider.py, this thus writes everything up to the next EOF into myspider.py.


See:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...