Lpi linux certification in a nutshell by unknow

Lpi linux certification in a nutshell by unknow

Author:unknow
Language: eng
Format: epub
Tags: Sciences
ISBN: 9781449390136
Published: 2010-06-14T10:00:00+00:00


In practice, users will generally (and often unknowingly) use the system-wide /etc/profile configuration file to start. In addition, they’ll often have three personal files in their home directory: ~/.bash_profile, ~/.bashrc, and ~/.bash_logout. The local files are optional, and bash does not mind if one or all of them are not available in your directory.

Each of these configuration files consists entirely of plain text. They are typically simple, often containing just a few commands to be executed in sequence to prepare the shell environment for the user. Since they are evaluated by bash as lines of program code, they are said to be sourced, or interpreted, when bash executes them.

Like most programming languages, shell programs allow the use of comments. Most shells, including bash, consider everything immediately following the hash mark (#) on a single line to be a comment. An important exception is the $# variable, which has nothing to do with comments but contains the number of positional parameters passed to a function. Comments can span an entire line or share a line by following program code. All of your shell scripts and configuration files should use comments liberally.

Files sourced at login time are created mainly to establish default settings. These settings include such things as where to search for programs requested by the user (the PATH) and creation of shortcut names for commonly used tasks (aliases and functions). After login, files sourced by each subsequent shell invocation won’t explicitly need to do these things again, because they inherit the environment established by the login shell. Regardless, it isn’t unusual to see a user’s .bashrc file filled with all of their personal customizations. It also doesn’t hurt anything, provided the .bashrc file is small and quick to execute.

Although it is not necessary to have detailed knowledge of every item in your shell configuration files, Exam 102 requires that you understand them and that you can edit them to modify their behavior and your resulting operating environment. The following examples are typical of those found on Linux systems and are annotated with comments. Example 13-1 shows a typical Linux systemwide profile. This file is executed by every user’s bash process at login time. A few environment variables and other parameters are set in it.

Example 13-1. An example system-wide bash profile

#!/bin/bash # /etc/profile pathmunge () { if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi fi } # ksh workaround if [ -z "$EUID" -a -x /usr/bin/id ]; then EUID=`id -u` UID=`id -ru` fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /sbin pathmunge /usr/sbin pathmunge /usr/local/sbin fi # No core files by default ulimit -S -c 0 > /dev/null 2>&1 if [ -x /usr/bin/id ]; then USER="`id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi HOSTNAME=`/bin/hostname` HISTSIZE=1000 if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then INPUTRC=/etc/inputrc fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then .



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.