Environment Setup
From DreamHost
| The instructions provided in this article or section require shell access unless otherwise stated. You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X. |
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
When installing in your home directory, you will need to change the environment variables for the installation to work.
Temporary session
In most cases, the change to setup environment should be temporary and once an installation is finished, it should be changed back for programs to run correctly. The reason that programs may fail is in LD_LIBRARY_PATH variable set to make installed software find libraries not present by default on DreamHost server. In case of newer version of there libraries with fixed bugs appear on DreamHost it could happen that your forgotten libraries will be used instead. It is not advisable to use LD_LIBRARY_PATH variable in production.
Bash Files
When logging into an interactive login shell, login will do the authentication, set the environment and start your shell. In the case of bash, the next step is reading the general profile from /etc, if that file exists. bash then looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. If none exists, /etc/bashrc is applied.
Shell Commands
export LD_LIBRARY_PATH=$HOME/lib/ export PATH="$HOME/bin:$PATH" source ~/.bash_profile
Setting a user-friendly prompt
Just change the PS1 variable in your ~/.bash_profile file. To see changes immediately after saving, run
. ~/.bash_profile
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation.
\e an ASCII escape character (033)
\h the hostname up to the first `.'
\H the hostname
\j the number of jobs currently managed by the shell
\l the basename of the shell's terminal device name
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\A the current time in 24-hour HH:MM format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchelvel (e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn
\\ a backslash
\[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\] end a sequence of non-printing characters
The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file, while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal.
Helpful Power Prompts
export PS1='\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]' user@host:~/bin/tools $
export PS1="\e[1;31m[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\]"
[lifesaver] tools >
export PS1="\n\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]\n$ \e[0m" [user@host][~/bin/tools] $
export PS1="\n[$?]\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]($SHLVL:\!)\n\[\033[0m\]\$ " [0][user@host][~/bin/tools](1:2130)
If you find yourself completely forgetting who and where you are, you can be constantly reminded by including user@hostname with:
export PS1='[\u@\h:\w]\$ '
Setting a Login Message
Just add code to execute to your ~/.bash_profile and it will run when an interactive shell logs in.
# Showing the DreamHost Message of the Day head -n 7 /etc/motd|tail -n 6
# Showing ascii text figlet -f smslant DreamHost
# Printing a calendar for the month cal $(date +"%m") $(date +"%Y")
# Display Historic events that happened on this day sed = $(echo /usr/share/calendar/calendar*) | sed -n "/$(date +%m\\/%d\\\|%b\*\ %d)/p"
# Display a riddle, literature snippet, or fortune /usr/games/fortune -s
# Display machine stats echo -e "Machine stats"; uptime procinfo|head -n 13|tail -n 11
Add color to directory listing
You can get color output from your shell to differentiate between files, directories, links, archives, etc.
Shell command:
vim ~/.bash_profile
Copy this code into ~/.bash_profile:
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias rm 'mv \!* ~/TRASH'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
fi
Editing Your Environment Profile
Shell Command:
vi ~/.bashrc
Add the following to the file.
export PATH=~/bin:$PATH
If you use the .bash_profile
Shell Command:
vi ~/.bash_profile
Add the following to the file.
. .bashrc
Type the following in the shell prompt to load the new changes.
. .bashrc
Directory Clutter
If you use the above commands you will have a lot of folders created on your home directory. If you don't like that then you can create a folder.
mkdir packages
Then set the PATH and LD_LIBRARY_PATH to include the new directory.
export LD_LIBRARY_PATH=$HOME/packages/lib/ export PATH="$HOME/packages/bin:$PATH"
A complete shell account setup based in this idea is explained also in Unix account setup. That setup is used in other how-to's in this wiki.
Disabling New Email Notifications
Add the following to .bash_profile.
unset MAILCHECK
Then log out and log back in again.
Changing your timezone
You may be confused when your environment reports that the time is something different than what your kitchen clock says. You can move to Los Angeles (where the Dreamhost resides) but there's an easier way to get the two to match. Type intzselectat the prompt and you'll be given instructions on how to configure your .bash_profile (or .bashrc) to your own timezone.
See Also
External Links
- Bash Prompt HOWTO Official tldp.org HOWTO
- Bash FAQ
- Bash home page
- Advanced Bash-Scripting Guide


