27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix G. A Sample .bashrc File<br />

The ~/.bashrc file determines the behavior of interactive shells. A good look at this file can lead to a<br />

better understanding of Bash.<br />

Emmanuel Rouat contributed the following very elaborate .bashrc file, written for a Linux system. He<br />

welcomes reader feedback on it.<br />

Study the file carefully, and feel free to reuse code snippets and functions from it in your own .bashrc file<br />

or even in your scripts.<br />

Example G−1. Sample .bashrc file<br />

#===============================================================<br />

#<br />

# PERSONAL $HOME/.bashrc FILE for bash−2.05a (or later)<br />

#<br />

# Last modified: Tue Apr 15 20:32:34 CEST 2003<br />

#<br />

# This file is read (normally) by interactive shells only.<br />

# Here is the place to define your aliases, functions and<br />

# other interactive features like your prompt.<br />

#<br />

# This file was designed (originally) for Solaris but based<br />

# on Redhat's default .bashrc file<br />

# −−> Modified for Linux.<br />

# The majority of the code you'll find here is based on code found<br />

# on Usenet (or internet).<br />

# This bashrc file is a bit overcrowded − remember it is just<br />

# just an example. Tailor it to your needs<br />

#<br />

#<br />

#===============================================================<br />

# −−> Comments added by HOWTO author.<br />

# −−> And then edited again by ER :−)<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# Source global definitions (if any)<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

if [ −f /etc/bashrc ]; then<br />

. /etc/bashrc # −−> Read /etc/bashrc, if present.<br />

fi<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# Automatic setting of $DISPLAY (if not set already)<br />

# This works for linux − your mileage may vary....<br />

# The problem is that different types of terminals give<br />

# different answers to 'who am i'......<br />

# I have not found a 'universal' method yet<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

function get_xserver ()<br />

{<br />

case $TERM in<br />

xterm )<br />

Appendix G. A Sample .bashrc File 418

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!