1 TITLE: How to install alternative shells on your LFS-system
3 AUTHOR: Björn Lindberg <d95-bli@nada.kth.se>
5 SYNOPSIS: A guide on how to install other shells than bash on an
12 A vanilla LFS only comes with one shell, namely bash (Bourne-again
13 shell). There are a lot of reasons why one would like to have
14 alternatives. Different shells are good at different things. You might
15 want to use one particular shell as your interactive shell, but another
16 one for scripting. There are some programs that have their compile
17 scripts written with a syntax that requires a certain shells. I will
18 give a brief description of each shell, listing some of their strong
22 1.1 The Almquist Shell (ash)
24 This is the shell that most closely tries to mimick the behaviour of
25 the original Bourne shell -- and no more. It is therefore Bourne shell
26 compliant, while being extraordinarily small and efficient. It is used
27 as the /bin/sh shell on NetBSD, who also currently maintains it. There
28 are two good reasons why you might want to consider installing ash:
30 (1) It is small. It's memory footprint is about a third of bigger more
31 feature-filled shells, like bash and Korn shell. On a less
32 powerful machine it could be installed as /bin/sh, causing all
33 common administration scripts, eg. boot scripts to be run with it.
35 (2) Portability. On Linux systems it is commonplace to begin a script
36 with /bin/sh, yet oftentimes bash-specific features will creep in,
37 since bash is the Linux standard shell. Those scripts should
38 arguably have /bin/bash at the top, because most of them won't run
39 as intended on other flavors of UNIX that don't use bash for their
40 /bin/sh, like the *BSDs and commercial Unices. Thus, using ash for
41 /bin/sh is an extra insurance that your scripts are portable in
42 the sense that they will generally work with the interpreter given
43 on the first line. this is good.
46 1.2 The Korn Shell (ksh)
48 Korn shell, like bash, is an improved Bourne shell derivative. It is
49 actually more than a shell, designed to be a very high-level
50 programming language while still maintaining Bourne shell
51 compatibility. Bash has borrowed a lot of the ksh functionality, so
52 the syntax is very similar. Korn shell is commonly used for more
53 advanced scripting on non-Linux platforms, and since ksh is frequently
54 available on commerical Unices, the portability for ksh scripts is
55 good. It is also a very good interactive shell, and has some distinct
56 features, like co-processes. See http://www.kornshell.com for more info.
59 1.3 The T C Shell (tcsh)
61 T C shell is the successor of the C shell, a competitor to the Bourne
62 shell but with C-like syntax. tcsh thus has a vastly different syntax
63 than the Bourne shell derivatives. Although shell afficionados
64 consider csh (and by extension tcsh) a bad scripting shell (see
65 http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/), it is a very
66 nice interactive shell with some unique features, like programmable
67 tab completion. Another good reason to have it is that you might
68 encounter scripts written in csh or tcsh. Such scripts won't run with
69 Bourne shell and compatibles, since the syntax is different. Some
70 program sources requires tcsh to build, eq xv (the image viewer), and
71 openoffice. See http://www.tcsh.org for more info on tcsh.
76 The Z shell is the most feature-filled (or bloated :-) of our
77 shells. It's syntax is mostly similar to the Korn shell, but also
78 borrowing elements from the C shell. It strongpoints are as an
79 interactive shell, where it incorporates features from all other
80 shells, while containing modules with a large variation of
81 functionality. As an example, zsh comes with it's built-in ftp-client!
82 See http://www.zsh.org for more info.
88 2.1 The Almquist Shell
90 As mentioned earlier, the most actively maintained ash is the one
91 NetBSD are using for their /bin/sh. Most Linux-distros are including
92 ash, and they are then typically keeping their sources in sync with
93 the NetBSD ones. We will use the Debian sources, since they are a bit
94 more Linux-friendly than NetBSD. :-)
96 It is still a lot of trouble to compile though, because the makefile
97 requires pmake, which is a make common on *BSDs. Gnu make won't
98 work. The tarballs we'll need, and the places I got them:
101 ftp://ftp.debian.org/debian/dists/potato/main/source/shells/\
102 ash_0.3.5.orig.tar.gz
104 ftp://ftp.debian.org/debian/dists/potato/main/source/shells/\
107 ftp://ftp.psychosis.com/linux/linux-router-devel/\
108 ash-hetios-0.5.1.diff.gz
110 ftp://ftp.debian.org/debian/dists/potato/main/source/devel/ \
111 pmake_1.45-3.2.tar.gz
113 We might as well use the Debian pmake, found at the same place. Don't
114 hesitate to use your local Debian mirror site instead of the main one.
116 The ash-hetios patch is a patch from the Linux Router Project that
117 enables history support and arrow keys. If you plan on using ash as an
118 interactive shell, you would want this patch, and if not, just don't
121 In the section below I will assume that you do not want to keep pmake
122 after using it to build ash. If you want to install pmake on your
123 system the procedure will actually be somewhat easier.
125 Unpack the pmake tarball and issue the following command:
129 We will need this later:
131 export PMAKE=<path-to-pmake>
132 export PATH=$PATH:$PMAKE
134 If you want to install pmake on your system, instead do the following:
136 install -m 755 bmake /usr/bin/pmake
137 install -m 755 mkdep /usr/bin/
138 install -m 644 make.1 /usr/share/man/man1/pmake.1
139 install -m 644 mkdep.1 /usr/share/man/man1/
140 install -d -m 755 /usr/share/mk/
141 for file in mk/*; do install -m 644 $file /usr/share/; done
143 Now unpack the ash tarball and apply first the debian diff, and then
144 the hetios diff. The hetios diff will not apply cleanly beacuse it was
145 made against a slightly different source tree. This is nothing to
148 We still have to make some small modifications:
150 mv Makefile Makefile.orig
151 sed 's/\(^CPPFLAGS.*$\)/\1 -DHETIO/' Makefile.orig > Makefile
152 echo -e "#endif\n" >> hetio.c
153 mv arith.y arith.y.orig
154 sed 's/\(yyerrok;\)/\/* \1 *\//' arith.y.orig > arith.y
155 $PMAKE/pmake -m $PMAKE/mk CFLAGS='-O2' CPPFLAGS='-DBSD \
156 -DSMALL -DSHELL -DHETIO -D__COPYRIGHT\(x\)= \
157 -D__RCSID\(x\)=' HOST_CPPFLAGS='-DBSD -DSMALL \
158 -DSHELL -DHETIO -D__COPYRIGHT\(x\)= \
159 -D__RCSID\(x\)=' YACC='bison -y'
161 Voilà! We now have a binary called sh and a manpage to go with
162 it. Install via the following:
164 install -m 755 sh /bin/ash
165 install -m 644 sh.1 /usr/share/man/man1/
166 cd /usr/share/man/man1 && ln sh.1 ash.1
168 If you would like to use ash as /bin/sh, either symlink it or install
169 it as sh directly. The manpage is a very good manpage for sh in either
175 The Korn SHell used to be a commercial closed-source shell. Because of
176 this, a free clone was written, pdksh (Public Domain Korn
177 Shell). pdksh supposedly has most of the original ksh's functionality,
178 but since early 2000 the source code for the original ksh is
179 available, so that is what we are going to install here. Note that ksh
180 is still under a license though. The following packages are needed:
182 http://www.research.att.com/~gsf/download/tgz/INIT.2002-06-28.tgz
183 http://www.research.att.com/~gsf/download/tgz/ast-ksh.2002-06-28.tgz
184 http://www.research.att.com/~gsf/download/tgz/ast-ksh-locale.2002-06-28.tgz
186 Note that the exact URL may change as a result of updates to the
187 source code packages. If the above links don't work you will have to
188 go to http://www.research.att.com/sw/download/ and manually download
189 the following packages: INIT, ast-ksh and ast-ksh-locale.
191 ksh is built using AT&T's particular build system. First you will need
192 to designate an empty build directory, eg <...>/src/ksh. The rest of
193 the install commands should be executed while standing in this
194 directory. Unpack the INIT package from this directory. Execute
196 mkdir lib/package/tgz
198 and move all three packages to this directory. Now issue
205 cp arch/linux.i386/bin/ksh /bin
206 cp arch/linux.i386/man/man1/sh.1 /usr/share/man/man1/ksh.1
208 To install the provided shell functions pushd, popd and dirs, do this
210 mkdir -p /usr/share/ksh/functions
211 cp arch/linux.i386/fun/* /usr/share/ksh/functions
213 you will then have to set the following environment variable to access
214 them, this can be done in one of the startup scripts
216 export FPATH=/usr/share/ksh/functions
218 The install management system supposedly will make it easier to
219 upgrade ksh to a newer version by the following command
221 bin/package update source http://www.research.att.com/sw/download
226 tcsh is by comparison easy to install. First we need the sources:
228 ftp://ftp.funet.fi/pub/unix/shells/tcsh/tcsh-6.11.tar.gz
232 ./configure --prefix=/usr --bindir=/bin --mandir=/usr/share/man
233 mv config_f.h config_f.h.orig
234 sed '/NLS_CATALOGS/s/undef/define/; /AUTOLOGOUT/s/define/undef/' \
235 config_f.h.orig > config_f.h
237 make install install.man
239 That's it! You now have a shiny new tcsh in your /bin directory. If
240 you have special considerations you might want to edit the settings in
241 config_f.h differently from mine, for instance it is possible to set
242 vi editing as default. If you want to play with the programmable tab
243 completion feature, have a look at the file complete.tcsh.
248 The sources are available for instance here:
250 ftp://sunsite.dk/pub/unix/shells/zsh/zsh-4.0.4.tar.bz2
252 Building and installation is straightforward
254 ./configure --prefix=/usr --bindir=/bin --mandir=/usr/share/man
258 This will install, in addition to the shell, the shell modules as well
259 as a lot of shell functions. To take advantage of the latter, you need
260 to set the following environment variable, and also "autoload" the
261 functions you would like to use
263 fpath=(/usr/share/zsh/4.0.4/functions/)
264 autoload zed # example
269 To learn more about the different shells, I recommend the manpages and
270 homepages for the shells, as well as the general web resources listed
271 in section 5. I will however say something about startup files, which
272 is otherwise often a source of confusion.
274 Beginning with ash and ksh, all shells (interactive, non-interactive
275 and login) will read the file specified in $ENV. A login shell will in
276 addition to this first read /etc/profile and .profile. It is common to
277 set $ENV from one of those two files with a command such as this
279 ENV=$HOME/.shrc; export ENV # or
280 export ENV=$HOME/.kshrc
282 To restrict parts of the $ENV file to interactive shells (that will
283 not be run for eg shell scripts), something like the following can be
287 # interactive commands
291 A tsch login shell will read the following files
295 ~/.tcshrc, or if not found, ~/.chsrc
298 a non-login shell will only read /etc/csh.cshrc and ~/.tcshrc (or
299 ~/.cshrc). On logout, a login shell will read /etc/csh.logout and
302 A zsh login shell reads the following files
313 an interactive (but non-login) shell will read all those but the
314 *profile and *login files. A non-interactive shell will not read
315 *zshrc. In addition, zsh login shells will also read ~/.zlogout and
316 /etc/zlogout on exit.
321 Shell In-memory size (kB) Binary size (kB)
322 -------------------------------------------
329 All binaries were stripped. The in-memory size is obtained from the
330 RSS column from 'top'. Sizes may vary slightly from system to system
331 and also depending on exact shell version. I am actually not certain
332 how relevant these figures are, but decided to include them for
333 comparison. Another thing to keep in mind is that zsh uses a lot of
334 modules that also takes up space, so the total disk space needed are
335 higher than the above figure. The total zsh installation uses over 3
341 http://www.shelldorado.com
342 http://www.faqs.org/faqs/unix-faq/shell/shell-differences/
343 http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
344 http://www.kornshell.com