This article includes answers to:
If you're looking for the answer to, say, question 5.5, and want to skip everything else, you can search ahead for the regular expression "^5.5)". While these are all legitimate questions, they seem to crop up in comp.unix.questions or comp.unix.shell on an annual basis, usually followed by plenty of replies (only some of which are correct) and then a period of griping about how the same questions keep coming up. You may also like to read the monthly article "Answers to Frequently Asked Questions" in the newsgroup "news.announce.newusers", which will tell you what "UNIX" stands for. With the variety of Unix systems in the world, it's hard to guarantee that these answers will work everywhere. Read your local manual pages before trying anything suggested here. If you have suggestions or corrections for any of these answers, please send them to to tmatimar@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) Can shells be classified into categories? In general there are two main class of shells. The first class are those shells derived from the Bourne shell which includes sh, ksh, bash, and zsh. The second class are those shells derived from C shell and include csh and tcsh. In addition there is rc which most people consider to be in a "class by itself" although some people might argue that rc belongs in the Bourne shell class. With the classification above, using care, it is possible to write scripts that will work for all the shells from the Bourne shell category, and write other scripts that will work for all of the shells from the C shell category. ------------------------------ 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) How do I "include" one shell script from within another shell script? All of the shells from the Bourne shell category (including rc) use the "." command. All of the shells from the C shell category use "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) Do all shells have aliases? Is there something else that can be used? All of the major shells other than sh have aliases, but they don't all work the same way. For example, some don't accept arguments. Although not strictly equivalent, shell functions (which exist in most shells from the Bourne shell category) have almost the same functionality of aliases. Shell functions can do things that aliases can't do. Shell functions did not exist in bourne shells derived from Version 7 Unix, which includes System III and BSD 4.2. BSD 4.3 and System V shells do support shell functions. Use unalias to remove aliases and unset to remove functions. ------------------------------ Subject: How are shell variables assigned? >From: wicks@dcdmjw.fnal.gov (Matthew Wicks) Date: Wed, 7 Oct 92 14:28:18 -0500 5.4) How are shell variables assigned? The shells from the C shell category use "set variable=value" for variables local to the shell and "setenv variable value" for environment variables. To get rid of variables in these shells use unset and unsetenv. The shells from the Bourne shell category use "variable=value" and may require an "export VARIABLE_NAME" to place the variable into the environment. To get rid of the variables use 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) How can I tell if I am running an interactive shell? In the C shell category, look for the variable $prompt. In the Bourne shell category, you can look for the variable $PS1, however, it is better to check the variable $-. If $- contains an 'i', the shell is interactive. Test like so: 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) What "dot" files do the various shells use? Although this may not be a complete listing, this provides the majority of information. csh Some versions have system-wide .cshrc and .login files. Every version puts them in different places. Start-up (in this order): .cshrc - always. .login - login shells. Upon termination: .logout - login shells. Others: .history - saves the history (based on $savehist). tcsh Start-up (in this order): /etc/csh.cshrc - always. /etc/csh.login - login shells. .tcshrc - always. .cshrc - if no .tcshrc was present. .login - login shells Upon termination: .logout - login shells. Others: .history - saves the history (based on $savehist). .cshdirs - saves the directory stack. sh Start-up (in this order): /etc/profile - login shells. .profile - login shells. Upon termination: any command (or script) specified using the command: trap "command" 0 ksh Start-up (in this order): /etc/profile - login shells. .profile - login shells. $ENV - always, if it is set. Upon termination: any command (or script) specified using the command: trap "command" 0 bash Start-up (in this order): /etc/profile - login shells. .bash_profile - login shells. .profile - login if no .bash_profile is present. .bashrc - interactive non-login shells. $ENV - always, if it is set. Upon termination: .bash_logout - login shells. Others: .inputrc - Readline initialization. zsh Start-up (in this order): .zshenv - always, unless -f is specified. .zprofile - login shells. .zshrc - interactive shells, unless -f is specified. .zlogin - login shells. Upon termination: .zlogout - login shells. rc Start-up: .rcrc - login shells ------------------------------ 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) I would like to know more about the differences between the various shells. Is this information available some place? A very detailed comparison of sh, csh, tcsh, ksh, bash, zsh, and rc is available via anon. ftp in several places: cs.uwp.edu (131.210.1.4):pub/vi/docs/shell-100.BetaA.Z utsun.s.u-tokyo.ac.jp:misc/vi-archive/docs/shell-100.BetaA.Z This file compares the flags, the programming syntax, input/output redirection, and parameters/shell environment variables. It doesn't discuss what dot files are used and the inheritance for environment variables and functions. ------------------------------