以下是shell脚本,不明白EOF的作用,脚本的大概作用我也理解,只想找人给我分析一下,我已经百度 google sogo so youdao过了,另复制了,举例说明最好了。
==================================================================
#!/bin/bash
TARGET_DIR=$PWD
cd /
list=`cat << EOF
usr/local/Trolltech/QtEmbedded-4.6.3-arm/examples/widgets/wiggly/wiggly
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/screenshots/raycasting.png
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/slides/demo_6.png
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/slides/demo_3.png
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/slides/demo_5.png
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/fluidlauncher
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/fluidlauncher/config.xml
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/embedded/styledemo/styledemo
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/pathstroke/pathstroke.html
usr/local/Trolltech/QtEmbedded-4.6.3-arm/demos/pathstroke/pathstroke
EOF
`
tar cfvz $TARGET_DIR/target-qte-4.6.3.tgz $list
这是 Here document 用法
EOF本意是 End Of File,表明到了文件末尾。
使用格式基本是这样的:
命令 << EOF
内容段
EOF
将“内容段”整个作为命令的输入。
你的代码里就是用cat命令读入整段字符串并赋值给list变量。
其实,不一定要用EOF,只要是“内容段”中没有出现的字符串,都可以用来替代EOF,只是一个起始和结束的标志罢了。
有个特殊用法不得不说:
: << COMMENTBLOCK
shell脚本代码段
COMMENTBLOCK
这个用来注释整段脚本代码。 : 是shell中的空语句。
搜索一下 Here document 你会明白更多。
明白一点了,你能给我举例说明吗,比如我上边的例子,如果很短 内容,就一行,不用EOF EOF会是什么写法,我就更明白了,我会加分的。真xin谢谢
如果就一行,那么直接赋值即可:
list="usr/local/Trolltech/QtEmbedded-4.6.3-arm/examples/widgets/wiggly/wiggly"
EOF相当于读文件的方式,适用于多行内容的操作。
太感谢了,真心有用
联系客服