Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Jun 2003 05:05:26 -0400
From:      Chuck Swiger <cswiger@mac.com>
To:        freebsd-questions@freebsd.org, freebsd@mcesr.etat.lu
Subject:   Re: dot.bashrc, where is it?
Message-ID:  <3EDDB656.1010104@mac.com>
In-Reply-To: <20030604151820.7c775d94.y2kbug@ms25.hinet.net>
References:  <200306031321.h53DLacQ003274@peedub.jennejohn.org> <000401c329d9$1afc72e0$bd2b6e94@lucy> <20030604151820.7c775d94.y2kbug@ms25.hinet.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 3 Jun 2003 16:04:53 +0200
"Didier Wiroth" <freebsd@mcesr.etat.lu> wrote:
[ ... ]
> For a beginner (coming from a windows world) who doesn't know which shell is
> better, sorry more adequate, it is easier to have a sample config file, to
> start learning how to configure you shell!

Hi, Didier--

The standard shell under FreeBSD is the Bourne shell, or /bin/sh. (*)  It's 
useful to know if only for the sake of comparison to other shells, since it's 
the standard reference.

BASH is closely related to the classic Bourne shell, and is sometimes installed 
as /bin/sh on some platforms-- various Linux flavors, mostly.  The Korn shell, 
/bin/ksh or pdksh, is also compatible with the Bourne shell syntax and added 
named procedures, and was heavily used by SysV Unices like Solaris, particularly 
in their package installation and system startup scripts.  I believe Microsoft 
also picked up a slightly(?) broken version of KSH for their POSIX environment 
under Windows NT and later.

Finally, I happen to use and recommend the Z Shell (/bin/zsh), which is being 
used as the default shell under Darwin and MacOS X; like bash, you can even 
install ZSH in place of /bin/sh.  ZSH can emulate sh, bash, ksh, and even the 
csh/tcsh shells, and thus is one of the most configurable shells available.

As you may have gathered, there are two major groupings of shells, the /bin/sh 
family described above, and a second grouping consisting of the C shell 
(/bin/csh) and derivatives like /bin/tcsh, which is what FreeBSD comes with as 
an alternative to /bin/sh.  At one time, /bin/sh was intended for shell scripts 
and was poorly suited for interactive use; /bin/csh was created with a lot more 
features and was more usable than the classic /bin/sh.

-----
(*): FreeBSD now uses something called the "Ash shell" as /bin/sh, which targets 
the POSIX shell standard and thus includes a number of interactive features that 
people like-- command.com + DOSKEYS? in Didier's frame of reference.  These 
include command history, interactive filename completion, job control, named 
procedures, fancier substitution and env variable handling, etc.
-----

Unfortunately, /bin/csh suffered from a misguided attempt to blend the syntax of 
the C programming language with the Bourne shell syntax, and is not recommended 
for scripting use.  (From the vantage of hindsight, "horribly misguided attempt" 
might be more accurate. :-)  Also, trying to learn both SH and CSH at the same 
time is likely to be very confusing due to these differences.

--
-Chuck

PS: Here's some sample system-wide shell script examples:

# /etc/profile: system wide startup file for /bin/sh and friends.
#####
#
# This file sets critical environment variables exported to all processes,
# such as the search path, user identity, process limits, umask, etc.
#
# Important:  This file must not produce any output!  Do **NOT** assume
#             the shell is interactive or attached to a terminal (tty).
#
# Copyright (c) 2003 Charles Swiger <chuck@pkix.net>
# $Id: profile,v 1.3 2003/05/16 04:03:28 chuck Exp $
####

####
# ignore signals
trap "" 2 3

# Default permissions.
umask 022

# Set reasonable soft process limits.
ulimit -Sc 0
ulimit -Sd 512000
ulimit -Ss 16384
ulimit -Sn 256
ulimit -Su 100

# Please note: Most platforms have the system hard resource limits
# configured via OS-specific files like /etc/login.conf (BSD),
# /etc/system (Solaris), compilation-time configuration of /etc/init,
# /bin/sh, and/or the kernel.  That is to say, changing the values
# above without also tuning other aspects of the system-- appropriate
# to the situation-- may not produce the results one would expect.

####
# Configure critical environment variables.

PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
export PATH

# setup (unqualified) hostname if we can, else localhost
if [ "$HOST" = "" ]; then
         HOST="`hostname | awk -F. '{print $1}'`"
         if [ "$HOST" = "" ]; then
                 HOST="localhost"
         fi
fi
export HOST

# setup username
if [ "$USER" = "" ]; then
         USER="`id -un`"
         if [ "$USER" = "" ]; then
                 USER="`whoami`"
         fi
fi
export USER

UNAME_P="`uname -p`"; export UNAME_P
UNAME_S="`uname -s`"; export UNAME_S
BLOCKSIZE="K"; export BLOCKSIZE         # inndf ergo sum
RSYNC_RSH="ssh"; export RSYNC_RSH
CVS_RSH="ssh"; export CVS_RSH
# Add other protocols which can tunnel via rsh or ssh here.  Per IESG
# recommendations, unencrypted plain text passwords should be avoided.

####
# look for per-platform, per-machine, or per-user localizations
if [ -r /etc/profile."$UNAME_S" ]; then
         . /etc/profile."$UNAME_S"
fi

# Note: it might be reasonable to replace "elif" with "fi;if"
if [ -r /etc/profile_localhost ]; then
         . /etc/profile_localhost
elif [ -r /etc/profile_"$HOST" ]; then
         . /etc/profile_"$HOST"
fi

if [ -r /etc/profile_"$USER" ]; then
         . /etc/profile_"$USER"
fi

####
# If this is a login or "su -" shell, perform more expensive tasks (once).
# Note: do not enable a restricted/"-r"/-rsh shell in the following list.

case "$0" in
-sh | -ksh | -jsh | -zsh | -bash | -csh | -tcsh | -pdksh)

         if [ -r /etc/profile.login ]; then
                 . /etc/profile.login
         fi
esac


trap 2 3
# fini
####

	...and:

# /etc/profile.login: system wide startup file for login shells.
#####
#
# This file is invoked for "login" shells and should be used for more
# expensive tasks or things appropriate for an interactive shell-- in
# particular, commands that might produce output or depend on a tty.
#
# Copyright (c) 2003 Charles Swiger <chuck@pkix.net>
# $Id: profile.login,v 1.3 2003/05/17 02:55:12 chuck Exp $
####

####
# ignore signals
trap "" 2 3

####
# Normally, platform-specific stuff (like /etc/login.conf under BSD)
# will configure the TERM environment variable for local console logins.
# SSH and other forms of remote terminal access should pass TERM via
# their environment.  However, if TERM is not set by now, configure
# for a generic 80-column ANSI terminal as a last resort.

if [ "$TERM" = "" ]; then
         TERM=ansi
fi

####
# Note: this section is for interactive shells.
case $- in *i*)
         eval `tset -s` 2> /dev/null
         if [ ! -f .hushlogin ]; then

# IMPORTANT: place commands that might produce output here.
quota -q
mesg y
msgs -fp 2> /dev/null
uptime

# allow the user to break the Message-Of-The-Day display.
#trap "trap '' 2" 2
#/bin/cat -s /etc/motd
#trap '' 2

         fi
esac


trap 2 3
# fini
####

PPS: Anyone read this far?  More?  :-)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3EDDB656.1010104>