求助:here scripts

sh/bash/dash/ksh/zsh等Shell脚本
回复
nigo
帖子: 104
注册时间: 2010-01-23 23:24

求助:here scripts

#1

帖子 nigo » 2011-05-08 9:48

http://linuxcommand.org/wss0030.php

A here script (also sometimes called a here document) is an additional form of I/O redirection. It provides a way to include content that will be given to the standard input of a command.

如何理解呢?不是太明白到底什么是here scripts,请教了
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 求助:here scripts

#2

帖子 lilydjwg » 2011-05-08 10:44

代码: 全选

cat <<HereDoc
This is the so-called heredoc writing in the script but as the input.
HereDoc
头像
xjack
帖子: 16
注册时间: 2007-11-28 13:04

Re: 求助:here scripts

#3

帖子 xjack » 2011-05-08 10:52

就是标记之间的所有命令被定向到<<符号之前的那个command

代码: 全选

#!/bin/bash
lftp << someMessHere
open http://mirror.bjtu.edu.cn/gnu/gcc
get -c README.olderversions
someMessHere
又比如

代码: 全选

:<<anyThingHere
被暂时屏蔽的代码
anyThingHere
我们走在囗囗主义光辉的大道上...
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 求助:here scripts

#4

帖子 fnan » 2011-05-08 22:28

简洁的说就是一种输入重定向。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
nigo
帖子: 104
注册时间: 2010-01-23 23:24

Re: 求助:here scripts

#5

帖子 nigo » 2011-05-09 10:05

昨天有事情,不能上网,不好意思啊。
我还是不理解,什么是here scripts呢?
比如下面一个脚本:
#!/bin/bash
命令一 << 标记号
命令二
命令三
标记号

是命令一被称为here script,还是这个脚本被称为here script呢?还是??
nigo
帖子: 104
注册时间: 2010-01-23 23:24

Re: 求助:here scripts

#6

帖子 nigo » 2011-05-09 10:45

已解决:
命令二,命令三 执行后,它的执行结果,被当做 标准输入 传送给 命令一
本来命令一是需要一个文件当参数的,可是这里没有文件,而是命令二和命令三执行的结果,这个结果被当做一个文件了,但是不是一个文件,而只是一个字符串(标准输入),这个重定向被叫做here script。
:em06
回复