Week - 2 1
Configuring the Bash Shell 2
Environment Variables Bash variables are local to a single shell by default Set with VARIABLE= VALUE Environment variables are inherited by child shells Set with export VARIABLE=VALUE Accessed by some programs for configuration 3
Some Common Variables Configuration variables PS1:Appearance of the bash prompt PATH: Directories to look for executables in EDITOR: Default text editor HISTFILESIZE: Number of commands in bash history Information variables Home: Users home directory EUID: Users effective UID 4
Aliases Aliases let you create shortcuts to commands $alias dir=ls –laF Use alias by itself to see all set aliases Use alias followed by an alias name to see alias value $alias dir alias dir = ls – laF 5
How bash expands a command line 1. Split the line into words 2. Expand aliases 3. Expand curly-brace statements({}) 4. Expand tilde statements(~) 5. Expand variables($) and Command – substitution($() and ) 6. Split the lint into words again 7. Expand file globs(*,?,[abc],etc) 8. Prepare I/O redirections( ) 9. Run the command! 6
Preventing Expansion Backslash(\) makes the next character literal $echo your cost:\$5.00 Your cost:$5.00 Quoting prevents expansion Single quotes() inhibit all expansion Double quotes() inhibit all expansion, except: $(dollar sign)- variable expansion (back quotes)- command substitution \(backslash) –single character inhibition !(Exclamation point)- history substitution 7
Login vs non-login shells Startup is configured differently for login and non-login shells Login shells are: Any shell created at login(includes X login) Su- Non-login shells are: Su Graphical terminals Executed scripts Any other bash instances 8
Bash startup tasks:profile Stored in /etc/profile(global) and ~/.bash_profile(user) Run for login shells only Used for Setting environment variables Running commands(eg :mail-checker script) 9
Bash startup tasks:bashrc Stored in /etc/bashrc(global) and ~/.bashrc(user) Run for all shells Used for Setting local variables Defining aliases 10
Sourcing files Changes to profile and bashrcfiles need to be sourced Two methods:. Source Shell scripts can source other files:.~/.bashrc 11
Bash exit tasks Stored in ~/.bash_logout(user) Run when a login shell exits Used for Creating automatic backups Cleaning out temporary files 12