菜鸟求助

sh/bash/dash/ksh/zsh等Shell脚本
csbde
帖子: 27
注册时间: 2006-10-20 12:35

#16

帖子 csbde » 2007-05-10 23:06

ztf 写了:#! /bin/sh
# Strips off the header from a mail/News message i.e. till the first
# empty line
# Mark Moraes, University of Toronto

# ==> These comments added by author of this document.

if [ $# -eq 0 ]; then
# ==> If no command line args present, then works on file redirected to stdin.
sed -e '1,/^$/d' -e '/^[ ]*$/d' #空行的正则表达式^$,全空格行的表达式^[ ]*$,合起来就是删除没有类容的行,但这个sed似乎有问题,没有操作对象
# --> Delete empty lines and all lines until
# --> first one beginning with white space.
else
# ==> If command line args present, then work on files named.,
for i do #这个语法应该是错误的,.do前面应该有;
sed -e '1,/^$/d' -e '/^[ ]*$/d' $i #这个也是正则跟上面的一样,但这个是正确的,有操作对象
# --> Ditto, as above.
done
fi

# ==> Exercise: Add error checking and other options.
# ==>
# ==> Note that the small sed script repeats, except for the arg passed.
# ==> Does it make sense to embed it in a function? Why or why not?
请好心人解析一下sed的那两行
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System

#17

帖子 5451vs5451 » 2007-05-11 0:18

'1,/^$/d' 这个式子的意义,正如脚本开头的注释所述,是删除从第一行直到下一个空行之间的所有内容。

至于第一个 sed 命令没有操作对象,前一行的注释也说得很清楚了,是用来处理来自标准输入的内容。

后面的 for i do 也是合法的,虽然 for i 和 do 之间看似少了一个分号。但由于 i 后面没有 in,所以当 bash 看到 do 的时候,它很清楚地知道这是下一条语句的开始,因此分号在这里可以省略。
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#18

帖子 ztf » 2007-05-11 16:44

谢谢 :)
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#19

帖子 ztf » 2007-05-13 8:44

请问如果要在case语句了表示
Y或y 或yes 或Yes或yEs怎么写?
书上用 [Yy] | [Yy] [Ee] [Ss] ) then echo ;;
好像不行
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#20

帖子 ztf » 2007-05-13 8:46

请问如果要在case语句了表示
Y或y 或yes 或Yes或yEs怎么写?
书上用 [Yy] | [Yy] [Ee] [Ss] ) then echo ;;
好像不行
wkt
帖子: 849
注册时间: 2006-09-07 22:51
联系:

#21

帖子 wkt » 2007-05-13 9:30

这样
case $囗囗囗囗 in
[yY][Ee][sS]|[yY]) echo "\$囗囗囗囗 =$囗囗囗囗" ;;;
*) echo "\$囗囗囗囗 =囗囗囗囗" ;;
esac
头像
stlxv
论坛版主
帖子: 8275
注册时间: 2006-05-03 0:39
来自: المريخ

Re: 菜鸟求助

#22

帖子 stlxv » 2007-05-14 0:13

baggio081 写了:编了一个简单的shell脚本,然后执行的时候提示没找到命令.
文件名是rubbish,然后用./rubbish执行的.
怎么解决?

代码: 全选

sh rubbish
PHP是最好的语言!不服来战!
回复