A shell is software that provides an interface for users of an operating system to access the services of a kernel. The name shell originates from shells being an outer layer of interface between the user and the internals of the operating system (the kernel).
In this article we will discuss about shells and their role for basic FreeBSD understanding.
Command Line Interface
Mostly shells has Command Line Interface thus if you are people com from the beauty of Graphical User Interface, you must adapt to it.
Command Line Interface means there are only text running on your shell. No button or menus you can click.
To instructs machine, you need to type commands and enter it. Some command or program need arguments or parameter. An example of command and argument:
cp mytext /home/user/folder/newtext
The above command is a command for copying files or directory. There is 1 command (cp) followed by 2 arguments, first is for text in current directory which will be copied and second is the path and filename for new file.
There are many shell types: bash, csh, tcsh, etc. The default shell used by FreeBSD is tcsh. If you are familiar with bash shell on most linux distro, then you might use bash. Unfortunately bash is not installed by default so we must install it manually from ports. All shells available for FreeBSD is located at /usr/ports/shells.
Once you have installed a new shell you can set it as your default using
You will then prompt by a screen asking some information. Write the correct shell there.
A quick method to do so is write the shell name and it’s path directly as argument of chsh command, such as:
chsh -s /path/to/myshell
Make sure you write correct path and shell name. Failed to do so will lead your account inaccessible as the account can not execute appropriate shell. Also be careful for your root account.
If you are using tcsh you can change the default promp under ~/.cshrc. An example prompt is
set prompt = '%[email protected]%m:%/%# '
Some shells has built in features name auto completion. You do not need to write full name of the command just type a part of command and press TAB to make shell write the rest for you.
On some shells, if you write part of command name which lead to two or moresimilar name, these shells will print you list of command which has similar name.
Another feature of the shell is the use of environment variables. Environment variables are a variable/key pair stored in the shell’s environment. This environment can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and their meanings:
|USER||Current logged in user’s name.|
|PATH||Colon-separated list of directories to search for binaries.|
|DISPLAY||Network name of the Xorg display to connect to, if available.|
|SHELL||The current shell.|
|TERM||The name of the user’s type of terminal. Used to determine the capabilities of the terminal.|
|TERMCAP||Database entry of the terminal escape codes to perform various terminal functions.|
|OSTYPE||Type of operating system.|
|MACHTYPE||The system’s CPU architecture.|
|EDITOR||The user’s preferred text editor.|
|PAGER||The user’s preferred text pager.|
|MANPATH||Colon-separated list of directories to search for manual pages.|
How to set an environment variable differs between shells. In tcsh and csh, use setenv to set environment variables. In sh and bash, use export to set the current environment variables. This example sets the default EDITOR to /usr/local/bin/emacs for the tcsh shell:
setenv EDITOR /usr/local/bin/emacs
The equivalent command for bash would be:
To expand an environment variable in order to see its current setting, type a $ character in front of its name on the command line. For example, echo $TERM displays the current $TERM setting.
Shells treat special characters, known as meta-characters, as special representations of data. The most common meta-character is *, which represents any number of characters in a filename. Meta-characters can be used to perform filename globbing. For example, echo * is equivalent to ls because the shell takes all the files that match * and echo lists them on the command line.
To prevent the shell from interpreting a special character, escape it from the shell by starting it with a backslash (\). For example, echo $TERM prints the terminal setting whereas echo \$TERM literally prints the string $TERM.freebsd, shell