Bash konfiguratsioonifailid: Difference between revisions
Created page with 'Hannes Kumari AK21.' |
mNo edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Hannes Kumari AK21 | ==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 | |||
<source lang="bash"> | |||
# 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 | |||
</source> | |||
====~/.bashrc==== | |||
loetakse ja täidetakse Bashi poolt iga kord kui kasutaja algatab alam-shelli | |||
<source lang="bash"> | |||
# 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 | |||
</source> | |||
====~/.bash_logout==== | |||
faili loetakse ja täidetakse Bashi poolt iga kord kui shell väljub | |||
<source lang="bash"> | |||
# Personal items to perform on logout. | |||
# End ~/.bash_logout | |||
</source> | |||
==Globaalsed bashi konfiguratsioonifailid== | |||
Vaikimisi pöördub bash sisselogimisel /etc kataloogis olevate konfiguratsioonifailide poole kui kasutaja kodukataloogis analoogi ei leita . | |||
====/etc/profile==== | |||
<source lang="bash"> | |||
# 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 | |||
</source> | |||
====/etc/profile.d==== | |||
kui /etc/profile failis defineeritakse baas parameetrid siis /etc/profile.d kataloogis peituvad täpsemad initsialseerimis skriptid, | |||
millega modifitseeritkase kasutajate keskkonda. Allpool mõned näited. | |||
=====/etc/profile.d/dircolors.sh===== | |||
skript kasutab ~/.dircolors ja /etc/dircolors faile, et määrata faili nimede värvi kataloogi nimekrirja kuvamisel. | |||
<source lang="bash"> | |||
# Setup for /bin/ls to support color, the alias is in /etc/bashrc. | |||
if [ -f "/etc/dircolors" ] ; then | |||
eval $(dircolors -b /etc/dircolors) | |||
if [ -f "$HOME/.dircolors" ] ; then | |||
eval $(dircolors -b $HOME/.dircolors) | |||
fi | |||
fi | |||
alias ls='ls --color=auto' | |||
</source> | |||
=====/etc/profile.d/readline.sh===== | |||
skript, mis määrab ära inputrc konfiguratsiooni vaikeväärtused juhul kui kasutajal ei ole individuaalseid väärtusi defineeritud. | |||
<source lang="bash"> | |||
# Setup the INPUTRC environment variable. | |||
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then | |||
INPUTRC=/etc/inputrc | |||
fi | |||
export INPUTRC | |||
</source> | |||
====/etc/bashrc==== | |||
<source lang="bash"> | |||
# 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 | |||
</source> | |||
==Kasutatud materjalid== | |||
http://bash.cyberciti.biz/guide//etc/profile.d | |||
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 | |||
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]] |
Latest revision as of 09:52, 7 April 2015
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/profile.d
kui /etc/profile failis defineeritakse baas parameetrid siis /etc/profile.d kataloogis peituvad täpsemad initsialseerimis skriptid, millega modifitseeritkase kasutajate keskkonda. Allpool mõned näited.
/etc/profile.d/dircolors.sh
skript kasutab ~/.dircolors ja /etc/dircolors faile, et määrata faili nimede värvi kataloogi nimekrirja kuvamisel.
# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
eval $(dircolors -b /etc/dircolors)
if [ -f "$HOME/.dircolors" ] ; then
eval $(dircolors -b $HOME/.dircolors)
fi
fi
alias ls='ls --color=auto'
/etc/profile.d/readline.sh
skript, mis määrab ära inputrc konfiguratsiooni vaikeväärtused juhul kui kasutajal ei ole individuaalseid väärtusi defineeritud.
# Setup the INPUTRC environment variable.
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
INPUTRC=/etc/inputrc
fi
export INPUTRC
/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://bash.cyberciti.biz/guide//etc/profile.d
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