BBS水木清华站∶精华区
发信人: freedom@csie.nctu.edu.tw (Tan Koan-Sin), 信区: unix
标 题: UNIX FAQ 中文版 Part 5
发信站: Computer Sci. & Information Eng., NCTU, (Tue Jul 11 03:11:07 1995)
转信站: phoenix!news.csie.nctu!freedom
Origin: freedom@dragon.csie.nctu.edu.tw
这七篇文章包含一些在 comp.unix.questions 和 comp.unix.shell 常见到的问
题。请不再问这些问题,因为这些问题已经被回答过太多次了。但也请不要因为
有人问这些问题而发火,因为他们可能尚未读过这些文章。
This collection of documents is Copyright (c) 1994, Ted Timar, except
Part 6, which is Copyright (c) 1994, Pierre Lewis and Ted Timar.
All rights reserved. Permission to distribute the collection is
hereby granted providing that distribution is electronic, no money is
involved, reasonable attempts are made to use the latest version and
all credits and this copyright notice are maintained.
Other requests for distribution will be considered.
All reasonable requests will be granted.
中文翻译 by {chenjl,freedom,jjyang}@csie.nctu.edu.tw
若您对中文翻译有任何意见请发 e-mail 给 cfaq@csie.nctu.edu.tw
我们希望这些文件中的资讯能对你有所帮助,但是并不保证是正确的。若发生损
害请自行负责。
您可以在 rtfm.mit.edu 的 pub/usenet/news.answers 找到包括此文件在内的
许多 FAQ。 在此目录下的 FAQ 的名字可在文章的顶端的 "Archive-Name:"
那一行找到。
[译注: 在台湾请用 NCTUCCA.edu.tw:/USENET/FAQ,在交大的话
ftp.csie.nctu.edu.tw:/pub/FAQ 是从 CCCA mirror 来的]
此一 FAQ 是以"unix-faq/faq/part[1-7]" 为名。
这些文章大约分成:
1.*)一般性的问题
2.*)初学者可能会问的基本问题
3.*) 中级的问题
4.*) 自以为已经知道所有答案的人可能会问的高级问题
5.*) 关於各种 shell 的问题
6.*) 各式各样的 Unix
7.*) An comparison of configuration management systems (RCS, SCCS).
This article includes answers to:
5.1) shell 要如何分类呢?
5.2) 在一个 shell script 里面要如何 "include" 另一个 shell script 呢?
5.3) 是不是所有 shell 都有 alias,有没别的替代方案呢?
5.4) 要如何设定 shell 的变数呢?
5.5) 要如何得知是否是在一 interactive shell 中?
5.6) 那些以 "." 开始其档名的档案在各种 shell 中的用途为何?
5.7) 我想要知道更多各种 shell 的相异之处。请指点明路。
若要找问题 5.5 的答案, 用 regular expression 往前找 "^5.5)" 即可。
因为这些都是正当合理的问题, 所以在 comp.unix.questions 或是
comp.unix.shell 中。每隔一阵子, 就会有这些问题与答案出现, 紧接著就会
有人对同样问题一再出现发牢骚。关於 UNIX 代表啥呢? 请参考每月 post 在
news.announce.newusers 中名为 "Answers to Frequently Asked Questions"
的文章。
因为 Unix 有太多不同的种类了, 所以很难保证此文件所提供的答案必然会有
用。在尝试本文件提供的作法前, 请先读读你所使用系统的手册。若你对答案
有任何建议或更正, 请送 email 给 tmtaimar@isgtec.com.
----------------------------------------------------------------------
Subject: Can shells be classified into categories?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
Date: Wed, 7 Oct 92 14:28:18 -0500
5.1) shell 要如何分类呢?
一般来说,shell 可以分成两类。第一类是由 Bourne shell 衍生出来的包括
sh,ksh,bash,与 zsh。第二类是由 C shell 衍生出来的,包括 csh 与
tcsh。除此之外还有一个 rc,有人认为该自成一类,有人认为该归类在
Bourne shell。
把上面的分类法记住,就可以写出所有 Bourne shell类的 shell 或是所有 C
shell 类的 shell 都可用的 script。
------------------------------
Subject: How do I "include" one shell script from within another shell script?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
Date: Wed, 7 Oct 92 14:28:18 -0500
5.2) 在一个 shell script 里面要如何 "include" 另一个 shell script 呢?
由 Bourne shell 衍生者(包括 rc)用 "." 这个指令。由 C shell 衍生者则使
用 "source"。
------------------------------
Subject: Do all shells have aliases? Is there something else that can be used?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
Date: Wed, 7 Oct 92 14:28:18 -0500
5.3) 是不是所有 shell 都有 alias,有没别的替代方案呢?
除了 sh 外,主要的 shell 都有 alias,不过用法不大一样。例如有些 alias
不接受参数。
Bourne shell 类中 shell function 虽然严格说来不是 alias,不过也差不多
了。Shell function 还可以做到一些 alias 所做不到的事情。从 Version
7 Unix 的衍生出来的系统(包括 System III 与 4.2BSD) 里面的 Bourne shell
没有 shell function。System V 与 4.3BSD 的 sh 都有 shell function。
用 unalias 来去除 alias, 用 unset 来去除 shell function。
------------------------------
Subject: How are shell variables assigned?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
Date: Wed, 7 Oct 92 14:28:18 -0500
5.4) 要如何设定 shell 的变数呢?
在 C shell 类的 shell 中用 "set variable=value" 来设定只给这个 shell
看的变数,用 "setenv variable value" 来设定环境变数。要去除变数则以
unset 与 unsetenv 为之。在 Bourne shell 类的 shell 中则用
"variable=value" 来设定变数,若要将一变数并成环境变数则用 "export
VARIABLE_NAME"。要去除一个变数则用 unset。
------------------------------
Subject: How can I tell if I am running an interactive shell?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
>From: dws@ssec.wisc.edu (DaviD W. Sanderson)
Date: Fri, 23 Oct 92 11:59:19 -0600
5.5) 要如何得知是否是在一 interactive shell 中?
在 C shell 类中,看看 $prompt 这个变数便知分晓。
在 Bourne shell 类中,可以看 $PS1 这个变数,不过最好是检查 $- 这个变
数。假如 $- 里有 i,那就表示是在 interactive shell 中。作法如下:
case $- in
*i*) # do things for interactive shell
;;
*) # do things for non-interactive shell
;;
esac
------------------------------
Subject: What "dot" files do the various shells use?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
>From: tmb@idiap.ch (Thomas M. Breuel)
Date: Wed, 28 Oct 92 03:30:36 +0100
5.6) 那些以 "." 开始其档名的档案在各种 shell 中的用途为何?
下面的说明或许不尽完整,但应该讲的都讲了。
csh
有一些版本在系统中所有使用者都必须读取的 .cshrc 与 .login。不
过,每一个版本放置这些档案的地方不大相同。
启动 (依照所列顺序):
.cshrc - 每次都会读取
.login - login shell 才会读取
结束之前:
.logout - login shells.
其他:
.history - 储存history (根据 $savehist 的值决定大小).
tcsh
启动 (依照所列顺序):
/etc/csh.cshrc - 每次都会读取
/etc/csh.login - login shells 才会读取
.tcshrc - 每次都会读取
.cshrc - 假如没有 .tcshrc 在的话
.login - login shells 才会读取
结束之前:
.logout - login shells 才会读取.
其他:
.history - saves the history (based on $savehist).
.cshdirs - saves the directory stack.
sh
启动 (依照所列顺序):
/etc/profile - login shell 才会读取
.profile - login shell 才会读取
结束之前:
any command (or script) specified using the command:
trap "command" 0
ksh
启动 (依照所列顺序):
/etc/profile - login shells 才会读取
.profile - login shells 才会读取
$ENV - always, if it is set.
结束之前:
如果你用了 trap "command" 0,则结束之际会执行 "command" (
bash
启动 (依照所列顺序):
/etc/profile - login shell 才会读取
.bash_profile - login shell 才会读取
.profile - 如果没有 .bash_profile,则会在 login 时读取
.bashrc - interactive non-login shell 才会读取
$ENV - 若有设定则读取之
结束之前:
.bash_logout - login shell 读取之
其他:
.inputrc - Readline 初始化之时
zsh
启动 (依照所列顺序):
.zshenv - 若无 -f 就会读取
.zprofile - login shell 才会读取
.zshrc - interactive shell 若无 -f 就会读取
.zlogin - login shell 结束之前
结束之前:
.zlogout - login shell 才会读取
rc
启动 (依照所列顺序):
.rcrc - login shell 才会读取
------------------------------
Subject: I would like to know more about the differences ... ?
>From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
Date: Wed, 7 Oct 92 14:28:18 -0500
5.7) 我想要知道更多各种 shell 的相异之处。请指点明路。
你可以用 anonymous ftp 在下列地点取得一份有关 sh、tcsh、ksh、
bash、zsh 与 rc 的详细比较。
cs.uwp.edu (131.210.1.4):pub/vi/docs/shell-101.BetaA.Z
utsun.s.u-tokyo.ac.jp:misc/vi-archive/docs/shell-101.BetaA.Z
这个档案中比较了呼叫 shell 时的旗号、程式的文法、输出/入之转向、与环
境变数。不过这个档案并不讨论以 "." 为档名开头的档案以及环境变数与
函数的继承。
------------------------------
End of unix/faq Digest part 5 of 7
**********************************
BBS水木清华站∶精华区