Path: bloom-beacon.mit.edu!senator-bedfellow.mit.edu!faqserv From: tmatimar@isgtec.com (Ted Timar) Newsgroups: comp.unix.questions,comp.unix.shell,comp.answers,news.answers Subject: Unix - Frequently Asked Questions (5/7) [Frequent posting] Supersedes: Followup-To: comp.unix.questions Date: 23 Sep 1994 19:34:38 GMT Organization: ISG Technologies, Inc Lines: 278 Approved: news-answers-request@MIT.Edu Distribution: world Expires: 21 Oct 1994 19:25:02 GMT Message-ID: References: NNTP-Posting-Host: bloom-picayune.mit.edu X-Last-Updated: 1994/09/08 Originator: faqserv@bloom-picayune.MIT.EDU Xref: bloom-beacon.mit.edu comp.unix.questions:32520 comp.unix.shell:13051 comp.answers:7427 news.answers:26211 Archive-name: unix-faq/faq/part5 Version: $Id: part5,v 2.5 1994/04/28 19:25:03 tmatimar Exp tmatimar $ 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. 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. All information here has been contributed with good intentions, but none of it is guaranteed either by the contributors or myself to be accurate. The users of this information take all responsibility for any damage that may occur. Many FAQs, including this one, are available on the archive site rtfm.mit.edu in the directory pub/usenet/news.answers. The name under which a FAQ is archived appears in the "Archive-Name:" line at the top of the article. This FAQ is archived as "unix-faq/faq/part[1-7]". 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@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. ------------------------------ End of unix/faq Digest part 5 of 7 ********************************** -- Ted Timar - tmatimar@isgtec.com ISG Technologies Inc., 6509 Airport Road, Mississauga, Ontario, Canada L4V 1S7