O'Reilly logo

Shell Scripting: Expert Recipes for Linux, Bash, and More by Steve Parker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting Up the Environment

Unix and Linux are very customizable systems. You can set the environment (settings and variables that define how the shell behaves) to your liking in a number of ways. If there is something that you find yourself repeatedly setting or changing, it is usually possible to have that automatically done for you by the system. Here some of the most useful are explored.

The Shell Profile

One of the main places for putting your personalized tweaks is the ~/.profile ($HOME/.profile) file. When a new interactive shell is started, /etc/profile, followed by /etc/bash.bashrc (if a bash shell), ~/.profile, and finally ~/.bashrc are executed in that order. ~/.profile is read by all shells so it is best to put generic settings in there, and then bash-specific settings in ~/.bashrc. You can set variables and aliases here, and even run commands if you want to. Because the local (user-specific) versions of these files all reside in the home directory and begin with a period (.) so that a regular ls does not list them, they are often referred to as “dotfiles.” There are many examples of dotfiles around the net; http://dotfiles.org/ is one useful repository.

Environment Variables

There are many environment variables that change the way the system works. You can set these interactively, or more usefully in your ~/.bashrc file.

PS1 Prompt

PS1 is the basic shell prompt; you can customize this. The default for bash is \s-\v\$, or “shell-version-dollar” — for example, bash-4.1$ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required