linux shell编程中cat命令的问题........

安林 2013-04-28 02:47:51
就是编写的一个简单的help函数,如下:
#!/bin/sh

help()
{
cat <
rotatefile -- rotate the file name
USAGE: rotatefile [-h] filename
OPTIONS: -h help text
EXAMPLE: rotatefile out
This will e.g rename out.2 to out.3, out.1 to out.2, out to out.1
and create an empty out-file
The max number is 10
version $ver
HELP
exit 0
}
help

在我运行的时候,出错了,出错如下:
[root@localhost anlin]# ./hello
./hello: line 71: syntax error near unexpected token `newline'
./hello: line 71: `cat < '

这是个什么错呢?????

...全文
607 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
大家来学saas 2015-12-15
  • 打赏
  • 举报
回复
十小时掌握Linux命令和Shell编程 课程观看地址:http://www.xuetuwuyou.com/course/61 课程出自学途无忧网:http://www.xuetuwuyou.com/ 课程介绍 一、课程使用到的软件及版本: Centos6.5 + VMware 10 二、课程设计到的技术点: 命令大全详解、Shell编程和案例分享、Crontab调度详解 三、学完课程之后,您可以: ①熟练掌握Linux常用命令 ②熟练掌握Shell编程语法和技巧 ③掌握足够用的Linux技能 ④走上程序员进阶之路 四、课程目录: 第1课、搭建虚拟机,网络、域名设置及VI使用 第2课、Linux文件系统特点,Centos(Redhat)的特点 第3课、Linux命令大全一 第4课、Linux命令大全二 第5课、Shell编程1,条件控制,外部传参,返回码 第6课、Shell编程2,几种循环、脚本调试 第7课、Shell脚本案例和Crontab调度详解和使用
linux-c 2013-05-03
  • 打赏
  • 举报
回复
引用 12 楼 ljc007 的回复:
[quote=引用 11 楼 Mr_Ringht 的回复:] here str怎么使用?
http://www.tldp.org/LDP/abs/html/x17754.html[/quote] 感谢!讲的好!
ljc007 2013-05-02
  • 打赏
  • 举报
回复
引用 11 楼 Mr_Ringht 的回复:
here str怎么使用?
http://www.tldp.org/LDP/abs/html/x17754.html
linux-c 2013-05-02
  • 打赏
  • 举报
回复
引用 10 楼 ljc007 的回复:
[quote=引用 3 楼 Mr_Ringht 的回复:] 那是herestring吧,和cat命令没多大关系,只是利用了其语法特性而已,你看看herestring语法就知道了,是herestring还是heredocmement?好像拼写错了 - -!
here doc 是两个< here str 是三个<[/quote] here str怎么使用?
ljc007 2013-05-02
  • 打赏
  • 举报
回复
引用 3 楼 Mr_Ringht 的回复:
那是herestring吧,和cat命令没多大关系,只是利用了其语法特性而已,你看看herestring语法就知道了,是herestring还是heredocmement?好像拼写错了 - -!
here doc 是两个< here str 是三个<
lyyscf 2013-04-29
  • 打赏
  • 举报
回复
cat <<xxx >file.tmp aas bbb xxx
CyberLogix 2013-04-28
  • 打赏
  • 举报
回复
cat <<HELP rotatefile -- rotate the file name USAGE: rotatefile [-h] filename OPTIONS: -h help text EXAMPLE: rotatefile out This will e.g rename out.2 to out.3, out.1 to out.2, out to out.1 and create an empty out-file The max number is 10 version $ver HELP
Linux-Torvalds 2013-04-28
  • 打赏
  • 举报
回复
cat <<HELP help contents HELP
安林 2013-04-28
  • 打赏
  • 举报
回复
引用 5 楼 prohibit 的回复:
[quote=引用 4 楼 zhanganlin123 的回复:] [quote=引用 2 楼 justkk 的回复:] 不是那么用的 cat << ! abc 123 !
shell中的cat除了这种用法还有其他用法不?[/quote]
$ cat > intofile
first line
second line
print Ctrl+D to end input    
last line
$ cat intofile 
first line
second line
print Ctrl+D to end input
last line
[/quote]Thanks!除了这两种,还有吗?
prohibit 2013-04-28
  • 打赏
  • 举报
回复
引用 4 楼 zhanganlin123 的回复:
[quote=引用 2 楼 justkk 的回复:] 不是那么用的 cat << ! abc 123 !
shell中的cat除了这种用法还有其他用法不?[/quote]
$ cat > intofile
first line
second line
print Ctrl+D to end input    
last line
$ cat intofile 
first line
second line
print Ctrl+D to end input
last line
安林 2013-04-28
  • 打赏
  • 举报
回复
引用 2 楼 justkk 的回复:
不是那么用的 cat << ! abc 123 !
shell中的cat除了这种用法还有其他用法不?
linux-c 2013-04-28
  • 打赏
  • 举报
回复
那是herestring吧,和cat命令没多大关系,只是利用了其语法特性而已,你看看herestring语法就知道了,是herestring还是heredocmement?好像拼写错了 - -!
justkk 2013-04-28
  • 打赏
  • 举报
回复
不是那么用的

cat << !
abc
123
!
安林 2013-04-28
  • 打赏
  • 举报
回复
自己顶一下,期待高手解答啊!!

4,438

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧