Bash konfiguratsioonifailid: Difference between revisions
No edit summary |
|||
Line 91: | Line 91: | ||
====/etc/profile==== | ====/etc/profile==== | ||
< | <source lang="bash"> | ||
# System wide environment variables and startup programs. | # System wide environment variables and startup programs. | ||
# System wide aliases and functions should go in /etc/bashrc. Personal | # System wide aliases and functions should go in /etc/bashrc. Personal | ||
Line 158: | Line 158: | ||
# End /etc/profile | # End /etc/profile | ||
</ | </source> | ||
====/etc/bashrc==== | ====/etc/bashrc==== |
Revision as of 14:14, 16 December 2012
Sissejuhatus
Shelli programm /bin/bash tarvitab alglaadimisel keskkonna loomiseks mitmeid faile. Igal failil on oma kindel otstarve, nad võivad mõjutada sisselogimis protsessi ja interaktiivse keskkonna ülesseadmist. /etc kaustas asuvad failid majutavad tavaliselt globaalseid seadeid sisaldavaid faile. Kui Teie kodukataloogis on olemas samaväärsed failid, siis kasutatakse neis leiduvaid seadeid globaalsete seadete asemel. Vaatlemegi neid kõigepealt, kuna reeglina kasutatakse kasutaja kodukataloogis olevaid bashi konfiguratsioonifaile. See muidugi sõltub distributsioonist ja ka adminstraatorist, kuidas süsteem on üles ehitatud.
Kasutajapõhised bashi konfiguratsioonifailid
Bash lubab .bash_profile failile kahte sünonüümi .bash_login ja . profile. Need tulenevad asjaolust, et C shelli vastava faili nimena on kasutusel .login ja Bourne shellil .profile. Loetakse aga ainult ühte faili nendest. Juhul kui .bash_profile faili ei leita siis otsitakse .bash_login ja seejärel .profile nimelist faili. .bash_profile loetakse ja käivitatakse vaid juhul kui toimub sisse logimine. Samas kui uus shell ehk alam-shell, trükkides "bash" käsurealt, loetakse käsud .bashrc failist. See anna võimaluse eristada peale sisselogimist kasutatavaid käske nendest mis on kasutatavad alam-shelli loomisel
kasutajapõhised failid kodukataloogis on järgmised:
~/.bash_profile
sisaldab käske mida loetakse ja täidetakse Bashi poolt iga kord kui kasutaja süsteemi sisse logib
# Personal environment variables and startup programs. # Personal aliases and functions should go in ~/.bashrc. System wide # environment variables and startup programs are in /etc/profile. # System wide aliases and functions are in /etc/bashrc. append () { # First remove the directory local IFS=':' local NEWPATH for DIR in $PATH; do if [ "$DIR" != "$1" ]; then NEWPATH=${NEWPATH:+$NEWPATH:}$DIR fi done # Then append the directory export PATH=$NEWPATH:$1 } if [ -f "$HOME/.bashrc" ] ; then source $HOME/.bashrc fi if [ -d "$HOME/bin" ] ; then append $HOME/bin fi unset append # End ~/.bash_profile
~/.bashrc
loetakse ja täidetakse Bashi poolt iga kord kui kasutaja algatab alam-shelli
# Personal aliases and functions. # Personal environment variables and startup programs should go in # ~/.bash_profile. System wide environment variables and startup # programs are in /etc/profile. System wide aliases and functions are # in /etc/bashrc. if [ -f "/etc/bashrc" ] ; then source /etc/bashrc fi # End ~/.bashrc
~/.bash_logout
faili loetakse ja täidetakse Bashi poolt iga kord kui shell väljub
# Personal items to perform on logout. # End ~/.bash_logout
Globaalsed bashi konfiguratsioonifailid
Vaikimisi pöördub bash sisselogimisel /etc kataloogis olevate konfiguratsioonifailide poole kui kasutaja kodukataloogis analoogi ei leita .
/etc/profile
# System wide environment variables and startup programs.
# System wide aliases and functions should go in /etc/bashrc. Personal
# environment variables and startup programs should go into
# ~/.bash_profile. Personal aliases and functions should go into
# ~/.bashrc.
# Functions to help us manage paths. Second argument is the name of the
# path variable to be modified (default: PATH)
pathremove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
pathprepend () {
pathremove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
pathappend () {
pathremove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
# Set the initial path
export PATH=/bin:/usr/bin
if [ $EUID -eq 0 ] ; then
pathappend /sbin:/usr/sbin
unset HISTFILE
fi
# Setup some environment variables.
export HISTSIZE=1000
export HISTIGNORE="&:[bf]g:exit"
# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
for script in /etc/profile.d/*.sh ; do
if [ -r $script ] ; then
. $script
fi
done
# Now to clean up
unset pathremove pathprepend pathappend
# End /etc/profile
/etc/bashrc
# System wide aliases and functions. # System wide environment variables and startup programs should go into # /etc/profile. Personal environment variables and startup programs # should go into ~/.bash_profile. Personal aliases and functions should # go into ~/.bashrc # Provides a colored /bin/ls command. Used in conjunction with code in # /etc/profile. alias ls='ls --color=auto' # Provides prompt for non-login shells, specifically shells started # in the X environment. [Review the LFS archive thread titled # PS1 Environment Variable for a great case study behind this script # addendum.] NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ $EUID == 0 ]] ; then PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" else PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi # End /etc/bashrc
Kasutatud materjalid
http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/profile.html
http://heimhardt.com/htdocs/bashrcs.html
http://www.hypexr.org/bash_tutorial.php
Autor
Hannes Kumari AK21