From: tmatimar@empress.com (Ted M A Timar)
Newsgroups: comp.unix.questions,comp.unix.shell,news.answers
Subject: Unix - Frequently Asked Questions (5/7) [Frequent posting]
Supersedes: <unix-faq/faq/part5_726386543@athena.mit.edu>
Followup-To: comp.unix.questions
Date: 21 Jan 1993 06:03:06 GMT
Organization: Empress Software
Distribution: world
Expires: 18 Feb 1993 06:02:22 GMT
NNTP-Posting-Host: pit-manager.mit.edu
X-Last-Updated: 1992/12/09

Archive-name: unix-faq/faq/part5
Version: $Id: part5,v 2.1 92/12/04 07:43:55 tmatimar Exp $

These seven articles contain the answers to some Frequently Asked
Questions often seen in comp.unix.questions and comp.unix.shell.
Please don't ask these questions again, they've been answered plenty
of times already - and please don't flame someone just because they may
not have read this particular posting.  Thank you.

These articles are divided approximately as follows:

      1.*) General questions.
      2.*) Relatively basic questions, likely to be asked by beginners.
      3.*) Intermediate questions.
      4.*) Advanced questions, likely to be asked by people who thought
	   they already knew all of the answers.
      5.*) Questions pertaining to the various shells, and the differences.
      6.*) An overview of Unix variants.
      7.*) An comparison of configuration management systems (RCS, SCCS).

This article includes answers to:

      5.1)  Can shells be classified into categories?
      5.2)  How do I "include" one shell script from within another
            shell script?
      5.3)  Do all shells have aliases?  Is there something else that
            can be used?
      5.4)  How are shell variables assigned?
      5.5)  How can I tell if I am running an interactive shell?
      5.6)  What "dot" files do the various shells use?
      5.7)  I would like to know more about the differences between the
            various shells.  Is this information available some place?

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@empress.com.

5.1)  Can shells be classified into categories?

      From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
      Date: Wed, 7 Oct 92 14:28:18 -0500

      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.

5.2)  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

      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".

5.3)  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

      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
      all shells from the Bourne shell category) have almost the same
      functionality of aliases.  Shell functions can do things that
      aliases can't do.
      
      Use unalias to remove aliases and unset to remove functions.

5.4)  How are shell variables assigned?

      From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
      Date: Wed, 7 Oct 92 14:28:18 -0500

      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.

5.5)  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

      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

5.6)  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

      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

5.7)  I would like to know more about the differences between the
      various shells.  Is this information available some place?

      From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
      Date: Wed, 7 Oct 92 14:28:18 -0500

      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/shell-100.BetaA.Z
      alf.uib.no (129.177.30.3):pub/lpf/misc/shell-100.BetaA.Z
      utsun.s.u-tokyo.ac.jp (133.11.11.11):misc/vi/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.

-- 
Ted Timar - tmatimar@empress.com
Empress Software, 3100 Steeles Ave E, Markham, Ont., Canada L3R 8T3
Newsgroups: comp.unix.questions