分页: 2 / 2

发表于 : 2007-05-10 23:06
csbde
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的那两行

发表于 : 2007-05-11 0:18
5451vs5451
'1,/^$/d' 这个式子的意义,正如脚本开头的注释所述,是删除从第一行直到下一个空行之间的所有内容。

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

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

发表于 : 2007-05-11 16:44
ztf
谢谢 :)

发表于 : 2007-05-13 8:44
ztf
请问如果要在case语句了表示
Y或y 或yes 或Yes或yEs怎么写?
书上用 [Yy] | [Yy] [Ee] [Ss] ) then echo ;;
好像不行

发表于 : 2007-05-13 8:46
ztf
请问如果要在case语句了表示
Y或y 或yes 或Yes或yEs怎么写?
书上用 [Yy] | [Yy] [Ee] [Ss] ) then echo ;;
好像不行

发表于 : 2007-05-13 9:30
wkt
这样
case $囗囗囗囗 in
[yY][Ee][sS]|[yY]) echo "\$囗囗囗囗 =$囗囗囗囗" ;;;
*) echo "\$囗囗囗囗 =囗囗囗囗" ;;
esac

Re: 菜鸟求助

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

代码: 全选

sh rubbish