📄 341.html
字号:
some text that contains<br>
several newlines.'<br>
<br>
<br>
As distributed, quoting history references is a challenge. Consider:<br>
<br>
% mail adec23!alberta!pixel.Convex.COM!tchrist<br>
alberta!pixel.Convex.COM!tchri: Event not found.<br>
<br>
<br>
5. VARIABLE SYNTAX<br>
<br>
There's this big difference between global (environment) and local<br>
(shell) variables. In csh, you use a totally different syntax<br>
to set one from the other. <br>
<br>
In the Bourne shell, this<br>
VAR=foo cmds args<br>
is the same as<br>
(export VAR; VAR=foo; cmd args)<br>
or csh's<br>
(setenv VAR; cmd args)<br>
<br>
You can't use :t, :h, etc on envariables. Watch:<br>
echo Try testing with $SHELL:t<br>
<br>
It's really nice to be able to say<br>
<br>
${PAGER-more}<br>
or<br>
FOO=${BAR:-${BAZ}}<br>
<br>
to be able to run the user's PAGER if set, and more otherwise.<br>
You can't do this in the csh. It takes more verbiage.<br>
<br>
You can't get the process number of the last background command from the<br>
csh, something you might like to do if you're starting up several jobs in<br>
the background. In the Bourne shell, the pid of the last command put in<br>
the background is available in $!.<br>
<br>
The csh is also flaky about what it does when it imports an<br>
environment variable into a local shell variable, as it does<br>
with HOME, USER, PATH, and TERM. Consider this:<br>
<br>
% setenv TERM '`/bin/ls -l / > /dev/tty`'<br>
% csh -f<br>
<br>
And watch the fun!<br>
<br>
<br>
6. EXPRESSION EVALUATION<br>
<br>
Consider this statement in the csh:<br>
<br>
<br>
if ($?MANPAGER) setenv PAGER $MANPAGER<br>
<br>
<br>
Despite your attempts to only set PAGER when you want<br>
to, the csh aborts:<br>
<br>
MANPAGER: Undefined variable.<br>
<br>
That's because it parses the whole line anyway AND EVALUATES IT!<br>
You have to write this:<br>
<br>
if ($?MANPAGER) then<br>
setenv PAGER $MANPAGER<br>
endif<br>
<br>
That's the same problem you have here:<br>
<br>
if ($?X && $X == 'foo') echo ok<br>
X: Undefined variable<br>
<br>
This forces you to write a couple nested if statements. This is highly<br>
undesirable because it renders short-circuit booleans useless in<br>
situations like these. If the csh were the really C-like, you would<br>
expect to be able to safely employ this kind of logic. Consider the<br>
common C construct:<br>
<br>
if (p && p->member)<br>
<br>
Undefined variables are not fatal errors in the Bourne shell, so<br>
this issue does not arise there.<br>
<br>
While the csh does have built-in expression handling, it's not<br>
what you might think. In fact, it's space sensitive. This is an<br>
error<br>
<br>
@ a = 4/2<br>
<br>
but this is ok<br>
<br>
@ a = 4 / 2<br>
<br>
<br>
The ad hoc parsing csh employs fouls you up in other places<br>
as well. Consider:<br>
<br>
% alias foo 'echo hi' ; foo<br>
foo: Command not found.<br>
% foo<br>
hi<br>
<br>
7. ERROR HANDLING<br>
<br>
Wouldn't it be nice to know you had an error in your script before<br>
you ran it? That's what the -n flag is for: just check the syntax.<br>
This is especially good to make sure seldom taken segments of code<br>
code are correct. Alas, the csh implementation of this doesn't work.<br>
Consider this statement:<br>
<br>
exit (i)<br>
<br>
Of course, they really meant<br>
<br>
exit (1)<br>
<br>
or just<br>
<br>
exit 1<br>
<br>
Either shell will complain about this. But if you hide this in an if<br>
clause, like so:<br>
<br>
#!/bin/csh -fn<br>
if (1) then<br>
exit (i)<br>
endif<br>
<br>
The csh tells you there's nothing wrong with this script. The equivalent<br>
construct in the Bourne shell, on the other hand, tells you this:<br>
<br>
<br>
#!/bin/sh -n<br>
if (1) then<br>
exit (i)<br>
endif<br>
<br>
/tmp/x: syntax error at line 3: `(' unexpected<br>
<br>
RANDOM BUGS<br>
<br>
Here's one:<br>
<br>
fg %?string<br>
^Z<br>
kill %?string<br>
No match.<br>
<br>
Huh? Here's another<br>
<br>
!%s%x%s<br>
<br>
Coredump, or garbage.<br>
<br>
If you have an alias with backquotes, and use that in backquotes in<br>
another one, you get a coredump.<br>
<br>
Try this:<br>
% repeat 3 echo "/vmu*"<br>
/vmu*<br>
/vmunix<br>
/vmunix<br>
What???<br>
<br>
<br>
Here's another one:<br>
<br>
% mkdir tst<br>
% cd tst<br>
% touch '[foo]bar'<br>
% foreach var ( * )<br>
> echo "File named $var"<br>
> end<br>
foreach: No match.<br>
<br>
<br>
8. SUMMARY<br>
<br>
<br>
While some vendors have fixed some of the csh's bugs (the tcsh also does<br>
much better here), many have added new ones. Most of its problems can<br>
never be solved because they're not actually bugs per se, but rather the<br>
direct consequences of braindead design decisions. It's inherently flawed.<br>
<br>
Do yourself a favor, and if you *have* to write a shell script, do it in the<br>
Bourne shell. It's on every UNIX system out there. However, behavior<br>
can vary.<br>
<br>
There are other possibilities.<br>
<br>
The Korn shell is the preferred programming shell by many sh addicts,<br>
but it still suffers from inherent problems in the Bourne shell's design,<br>
such as parsing and evaluation horrors. The Korn shell or its<br>
public-domain clones and supersets (like bash) aren't quite so ubiquitous<br>
as sh, so it probably wouldn't be wise to write a sharchive in them that<br>
you post to the net. When 1003.2 becomes a real standard that companies<br>
are forced to adhere to, then we'll be in much better shape. Until<br>
then, we'll be stuck with bug-incompatible versions of the sh lying about.<br>
<br>
The Plan 9 shell, rc, is much cleaner in its parsing and evaluation; it is<br>
not widely available, so you'd be significantly sacrificing portability.<br>
No vendor is shipping it yet.<br>
<br>
If you don't have to use a shell, but just want an interpreted language,<br>
many other free possibilities present themselves, like Perl, REXX, TCL,<br>
Scheme, or Python. Of these, Perl is probably the most widely available<br>
on UNIX (and many other) systems and certainly comes with the most<br>
extensive UNIX interface. Increasing numbers vendors ship Perl with<br>
their standard systems. (See the comp.lang.perl FAQ for a list.)<br>
<br>
If you have a problem that would ordinarily use sed or awk or sh, but it<br>
exceeds their capabilities or must run a little faster, and you don't want<br>
to write the silly thing in C, then Perl may be for you. You can get<br>
at networking functions, binary data, and most of the C library. There<br>
are also translators to turn your sed and awk scripts into Perl scripts,<br>
as well as a symbolic debugger. Tchrist's personal rule of thumb is<br>
that if it's the size that fits in a Makefile, it gets written in the<br>
Bourne shell, but anything bigger gets written in Perl.<br>
<br>
See the comp.lang.{perl,rexx,tcl} newsgroups for details about these<br>
languages (including FAQs), or David Muir Sharnoff's comparison of<br>
freely available languages and tools in comp.lang.misc and news.answers.<br>
<br>
NOTE: Doug Hamilton <hamilton@bix.com> has a program that he sells for<br>
profit for little toy non-UNIX systems. He calls it 'csh' or the<br>
'hamilton csh', but it's not a csh as it's neither bug nor feature<br>
compatible with the real csh. Actually, he's fixed a great deal, but<br>
in doing so, has created a totally different shell.<br>
-- <br>
Tom Christiansen Perl Consultant, Gamer, Hiker tchrist@mox.perl.com<br>
<br>
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -