Virtual FreeBSD part 2: Installing the BASH shell.

This is the second part of the “Virtual FreeBSD” tutorials series. In the first part we have installed the OS from the scratch by downloading most of it from the Internet. In this second tutorial we will customize the default shell and install a little bit more user-friendly one. But first thing first:

Requirements

  • A fresh (or not so fresh) installation of FreeBSD.
  • Recent ports collection.
  • Active connection to Internet.
  • Patience and if your system is rather slow – a LOT of patience.

Installing Bash

To install the bash shell we will use the ports collection that comes with the FreeBSD. Most of the times, when you need something installed, it would be already included into the ports. You will see how easy it is to manage your installations that way. Before actually installing and making the bash shell, we need to know where it port is located. Type the following:

[val@local] ~ $ whereis bash
bash: /usr/local/bin/bash /usr/local/man/man1/bash.1.gz /usr/ports/shells/bash
[val@local] ~ $

In my case there are 3 results that were returned. That is because I have already installed bash and is available on my system. If you haven’t installed it already though, there will be only 1 result – the last one:

/usr/ports/shells/bash

We have found out where bash is hiding and all we need to do is go there and ask it to compile (as root, hence su to root first) :

[val@local] ~ $ su
Password:

[val@local] ~ $ cd /usr/ports/shells/bash
[val@local] bash $ make install clean

Generally, when you need to compile and install a port you have to tell the system to:

  1. Make it by typing: make
  2. Install the compiled package by typing: make install
  3. Clean the garbage left after the install by typing: make clean

Since those are all ‘functions’ of the make script we can chain them into one command (as I’ve done above): make install clean.

Now that we have ran the make script, it will check the dependencies of the application we are compiling and download them as well. In this case, bash has several dependencies which needs to be downloaded before it is fully installed. You don’t need to do anything, apart from configuring one of those dependencies and instruct it how exactly to store its man (help) pages. It’s nothing you can’t handle :) Actually .. it doesn’t matter which option you choose.

The installation will take between 5 and 10 minutes and hopefully it will complete without an error. At that point you have bash installed but you will need to configure the system to use it.

Configuring the System

To change the actual shell you will need to execute a certain command as root:

[root@local] val $ chpass val

The above line will bring up your default editor and will edit the user file. In my case, the non-privileged user is called val. If your user is called john, you will need to enter: chpass john.

The file contains a lot of information, but the one we are interested in is the Shell one. Change it to look like this:

Shell: /usr/local/bin/bash

This tells the system that the shell for user Val can be actually found in /usr/local/bin/bash. Logout and login and you will see that the new shell has taken place. The next step is to configure Bash itself.

Additional Bash Configuration

BASH is rather powerful utility. It can do much and help you a lot. I will try to show you some of its features. First however we will need to create its configuration file. By default it will look for it in your home directory under the name of .bashrc. So go ahead and create it:

[val@local] ~ $ touch .bashrc

Below is my .bashrc file. Each one is explained in the ‘#Commented lines’

# .bashrc – Bourne Again SHell configuration file for interactive shells.

# file permissions: rwxr-xr-x
umask 022

#BlockSize in K. Environment variable.

BLOCKSIZE=K; export BLOCKSIZE

#Default editor. In this case its VIM, but you don’t have it yet installed. EDITOR=/usr/local/bin/vim; export EDITOR

#The pager. Again environment variable

PAGER=/usr/bin/less; export PAGER

# some useful aliases

#User friendly alias for updatedb in Linux systems.
alias updatedb=’/usr/libexec/locate.updatedb’

#Shutdown alias.
alias down=’shutdown -h now’

#Alias to show the recent history commands.
alias h=’fc -l’

#Alias to show the jobs.
alias j=jobs

#Alias to pager.
alias m=$PAGER

#Egrep alias.
alias g=’egrep -i’

#renew alias which will read the .bashrc and executes it

alias renew=’source ~/.bashrc’

#Colorful ls alias. Procuses nice colors :)
alias ls=’/bin/ls -aFG’

#Ailas to disksize i.e df command.
alias disksize=’df -kh’

#Same for the current dir.
alias dirsize=’du -h -d 1 .’

#alias to free command in Linux
alias free=’top -d1 | head -5 | tail -2′

#Display the path variable.
alias showpath=’echo $PATH | tr -s ”:” ”\012”’

#Counts the files in the directory i.e ls -la | wc -l
alias llc=’echo Total number of files `ll | wc -l` in `pwd`’

#Alias to vim instead of the default vi.
alias vi=vim

# set prompt. A very nice colors :)
PS1=”[33[1;30m][[33[1;34m]u[33[1;30m]@[33[0;35m]h[33[1;30m]] [33[0;37m]W [33[1;30m]$[33[0m] ”

#Three functions to ease your admin tasks. Found them out in the internet. Credits – unknown.

function findfile() { find . -type f -iname ‘*’$*’*’ -ls ;}
function findtext() { find . -exec egrep $* {} /dev/null ; ; }
function finddir () { find . -type d -iname ‘*’$*’*’ -ls ; }

You might also add the same .bashrc file in your root folder so that when you su to root to have a similar environment, but that’s optional.

Bookmark and Share

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top  banner ad


Leave a Reply