[f8d632ac] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[6732c094] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[f8d632ac] | 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
[78b3cd61] | 8 | <sect1 id="postlfs-config-profile" xreflabel="The Bash Shell Startup Files">
|
---|
[2753b70b] | 9 | <?dbhtml filename="profile.html"?>
|
---|
| 10 |
|
---|
| 11 | <sect1info>
|
---|
| 12 | <othername>$LastChangedBy$</othername>
|
---|
| 13 | <date>$Date$</date>
|
---|
| 14 | </sect1info>
|
---|
| 15 |
|
---|
| 16 | <title>The Bash Shell Startup Files</title>
|
---|
| 17 |
|
---|
| 18 | <para>The shell program <filename>/bin/bash</filename> (hereafter
|
---|
| 19 | referred to as just "the shell") uses a collection of startup files to
|
---|
| 20 | help create an environment. Each file has a specific use and
|
---|
| 21 | may affect login and interactive environments differently. The files in
|
---|
[384039a] | 22 | the <filename class="directory">/etc</filename> directory generally provide
|
---|
[2753b70b] | 23 | global settings. If an equivalent file exists in your home directory it may
|
---|
| 24 | override the global settings.</para>
|
---|
| 25 |
|
---|
| 26 | <para>An interactive login shell is started after a successful login, using
|
---|
[6f36554] | 27 | <filename>/bin/login</filename>, by reading the
|
---|
| 28 | <filename>/etc/passwd</filename> file. This shell invocation normally reads
|
---|
| 29 | <filename>/etc/profile</filename> and its private equivalent
|
---|
| 30 | <filename>~/.bash_profile</filename> (or <filename>~/.profile</filename> if
|
---|
| 31 | called as <command>/bin/sh</command>) upon startup.</para>
|
---|
[2753b70b] | 32 |
|
---|
| 33 | <para>An interactive non-login shell is normally started at the command-line
|
---|
[ba0deaad] | 34 | using a shell program (e.g.,
|
---|
| 35 | <prompt>[prompt]$</prompt><command>/bin/bash</command>) or by the
|
---|
[2753b70b] | 36 | <command>/bin/su</command> command. An interactive non-login shell is also
|
---|
| 37 | started with a terminal program such as <command>xterm</command> or
|
---|
| 38 | <command>konsole</command> from within a graphical environment. This type of
|
---|
| 39 | shell invocation normally copies the parent environment and then reads the
|
---|
[6f36554] | 40 | user's <filename>~/.bashrc</filename> file for additional startup
|
---|
| 41 | configuration instructions.</para>
|
---|
[2753b70b] | 42 |
|
---|
| 43 | <para>A non-interactive shell is usually present when a shell script is
|
---|
| 44 | running. It is non-interactive because it is processing a script and not
|
---|
| 45 | waiting for user input between commands. For these shell invocations, only
|
---|
| 46 | the environment inherited from the parent shell is used.</para>
|
---|
| 47 |
|
---|
| 48 | <para> The file <filename>~/.bash_logout</filename> is not used for an
|
---|
| 49 | invocation of the shell. It is read and executed when a user exits from an
|
---|
| 50 | interactive login shell.</para>
|
---|
| 51 |
|
---|
[a05dbe6] | 52 | <para>Many distributions use <filename>/etc/bashrc</filename> for system wide
|
---|
| 53 | initialization of non-login shells. This file is usually called from the
|
---|
| 54 | user's <filename>~/.bashrc</filename> file and is not built directly into
|
---|
| 55 | <command>bash</command> itself. This convention is followed in this
|
---|
| 56 | section.</para>
|
---|
[2753b70b] | 57 |
|
---|
[384039a] | 58 | <para>For more information see <command>info bash</command> --
|
---|
[2753b70b] | 59 | <emphasis role="strong">Nodes: Bash Startup Files and Interactive
|
---|
[ba0deaad] | 60 | Shells</emphasis>.</para>
|
---|
| 61 |
|
---|
| 62 | <note>
|
---|
| 63 | <para>Most of the instructions below are used to create files located in
|
---|
| 64 | the <filename class='directory'>/etc</filename> directory structure which
|
---|
| 65 | requires you to execute the commands as the
|
---|
| 66 | <systemitem class='username'>root</systemitem> user. If you elect to create
|
---|
| 67 | the files in user's home directories instead, you should run the commands
|
---|
| 68 | as an unprivileged user.</para>
|
---|
| 69 | </note>
|
---|
[2753b70b] | 70 |
|
---|
[5c3f3856] | 71 | <para condition="html" role="usernotes">User Notes:
|
---|
| 72 | <ulink url="&blfs-wiki;/bash-shell-startup-files"/></para>
|
---|
| 73 |
|
---|
[2753b70b] | 74 | <sect2 id="etc-profile-profile">
|
---|
| 75 | <title>/etc/profile</title>
|
---|
| 76 |
|
---|
| 77 | <indexterm zone="postlfs-config-profile etc-profile-profile">
|
---|
| 78 | <primary sortas="e-etc-profile">/etc/profile</primary>
|
---|
| 79 | </indexterm>
|
---|
| 80 |
|
---|
| 81 | <para>Here is a base <filename>/etc/profile</filename>. This file starts by
|
---|
| 82 | setting up some helper functions and some basic parameters. It specifies some
|
---|
[ba0deaad] | 83 | <command>bash</command> history parameters and, for security purposes,
|
---|
[384039a] | 84 | disables keeping a permanent history file for the <systemitem
|
---|
[2753b70b] | 85 | class="username">root</systemitem> user. It also sets a
|
---|
| 86 | default user prompt. It then calls small, single purpose scripts in the
|
---|
| 87 | <filename class='directory'>/etc/profile.d</filename> directory to provide most
|
---|
[ba0deaad] | 88 | of the initialization.</para>
|
---|
[2753b70b] | 89 |
|
---|
| 90 | <para>For more information on the escape sequences you can use for your prompt
|
---|
[ba0deaad] | 91 | (i.e., the <envar>PS1</envar> environment variable) see <command>info
|
---|
[2753b70b] | 92 | bash</command> -- <emphasis role="strong">Node: Printing a
|
---|
[ba0deaad] | 93 | Prompt</emphasis>.</para>
|
---|
[2753b70b] | 94 |
|
---|
[8e37798] | 95 | <screen role="root"><?dbfo keep-together="auto"?><userinput>cat > /etc/profile << "EOF"
|
---|
[2753b70b] | 96 | <literal># Begin /etc/profile
|
---|
[b554263] | 97 | # Written for Beyond Linux From Scratch
|
---|
| 98 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[1a396398] | 99 | # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
---|
[384039a] | 100 |
|
---|
[b554263] | 101 | # System wide environment variables and startup programs.
|
---|
[384039a] | 102 |
|
---|
[b554263] | 103 | # System wide aliases and functions should go in /etc/bashrc. Personal
|
---|
| 104 | # environment variables and startup programs should go into
|
---|
| 105 | # ~/.bash_profile. Personal aliases and functions should go into
|
---|
| 106 | # ~/.bashrc.
|
---|
[384039a] | 107 |
|
---|
[1a396398] | 108 | # Functions to help us manage paths. Second argument is the name of the
|
---|
| 109 | # path variable to be modified (default: PATH)
|
---|
| 110 | pathremove () {
|
---|
| 111 | local IFS=':'
|
---|
| 112 | local NEWPATH
|
---|
| 113 | local DIR
|
---|
| 114 | local PATHVARIABLE=${2:-PATH}
|
---|
| 115 | for DIR in ${!PATHVARIABLE} ; do
|
---|
| 116 | if [ "$DIR" != "$1" ] ; then
|
---|
| 117 | NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
---|
| 118 | fi
|
---|
| 119 | done
|
---|
| 120 | export $PATHVARIABLE="$NEWPATH"
|
---|
[b554263] | 121 | }
|
---|
[384039a] | 122 |
|
---|
[1a396398] | 123 | pathprepend () {
|
---|
| 124 | pathremove $1 $2
|
---|
| 125 | local PATHVARIABLE=${2:-PATH}
|
---|
| 126 | export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
---|
| 127 | }
|
---|
[384039a] | 128 |
|
---|
[1a396398] | 129 | pathappend () {
|
---|
| 130 | pathremove $1 $2
|
---|
| 131 | local PATHVARIABLE=${2:-PATH}
|
---|
| 132 | export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
---|
| 133 | }
|
---|
[384039a] | 134 |
|
---|
[ec7940be] | 135 | export -f pathremove pathprepend pathappend
|
---|
[e9ef7b5e] | 136 |
|
---|
| 137 | # Set the initial path
|
---|
| 138 | export PATH=/bin:/usr/bin
|
---|
| 139 |
|
---|
[1a396398] | 140 | if [ $EUID -eq 0 ] ; then
|
---|
[e9ef7b5e] | 141 | pathappend /sbin:/usr/sbin
|
---|
[1a396398] | 142 | unset HISTFILE
|
---|
[b554263] | 143 | fi
|
---|
[384039a] | 144 |
|
---|
[1a396398] | 145 | # Setup some environment variables.
|
---|
| 146 | export HISTSIZE=1000
|
---|
| 147 | export HISTIGNORE="&:[bf]g:exit"
|
---|
[0d7ec6f1] | 148 |
|
---|
[97c713e] | 149 | # Set some defaults for graphical systems
|
---|
[caee7667] | 150 | export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
|
---|
| 151 | export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
|
---|
| 152 | export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
|
---|
[97c713e] | 153 |
|
---|
[410e228b] | 154 | # Setup a red prompt for root and a green one for users.
|
---|
[0d7ec6f1] | 155 | NORMAL="\[\e[0m\]"
|
---|
| 156 | RED="\[\e[1;31m\]"
|
---|
| 157 | GREEN="\[\e[1;32m\]"
|
---|
| 158 | if [[ $EUID == 0 ]] ; then
|
---|
| 159 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
| 160 | else
|
---|
| 161 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
| 162 | fi
|
---|
[384039a] | 163 |
|
---|
[1a396398] | 164 | for script in /etc/profile.d/*.sh ; do
|
---|
[d3880c0] | 165 | if [ -r $script ] ; then
|
---|
[1a396398] | 166 | . $script
|
---|
| 167 | fi
|
---|
| 168 | done
|
---|
[384039a] | 169 |
|
---|
[f91e4b98] | 170 | unset script RED GREEN NORMAL
|
---|
[dc53944] | 171 |
|
---|
[2753b70b] | 172 | # End /etc/profile</literal>
|
---|
| 173 | EOF</userinput></screen>
|
---|
[1a396398] | 174 |
|
---|
[2753b70b] | 175 | <sect3 id="etc-profile.d">
|
---|
| 176 | <title>The /etc/profile.d Directory</title>
|
---|
[99e8a229] | 177 |
|
---|
[2753b70b] | 178 | <indexterm zone="postlfs-config-profile etc-profile.d">
|
---|
| 179 | <primary sortas="e-etc-profile.d">/etc/profile.d</primary>
|
---|
| 180 | </indexterm>
|
---|
[1a396398] | 181 |
|
---|
[384039a] | 182 | <para>Now create the <filename class='directory'>/etc/profile.d</filename>
|
---|
[ba0deaad] | 183 | directory, where the individual initialization scripts are placed:</para>
|
---|
[1a396398] | 184 |
|
---|
[2753b70b] | 185 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/profile.d</userinput></screen>
|
---|
[1a396398] | 186 |
|
---|
[2753b70b] | 187 | </sect3>
|
---|
[1a396398] | 188 |
|
---|
[931a597] | 189 | <sect3 id="etc-profile.d-bash-completion.sh">
|
---|
| 190 | <title>/etc/profile.d/bash_completion.sh</title>
|
---|
| 191 |
|
---|
| 192 | <indexterm zone="postlfs-config-profile etc-profile.d-bash-completion.sh">
|
---|
| 193 | <primary sortas="e-etc-profile.d-bash-completion.sh">/etc/profile.d/bash_completion.sh</primary>
|
---|
| 194 | </indexterm>
|
---|
| 195 |
|
---|
[03b278dc] | 196 | <note><para>Using the bash completion script below is controversial.
|
---|
| 197 | Not all users like it. It adds many (usually over 1000) lines to the
|
---|
| 198 | bash environment and makes it difficult to use the 'set' command to
|
---|
| 199 | examine simple environment variables. Omitting this script does not
|
---|
| 200 | interfere with the ability of bash to use the tab key for file name
|
---|
| 201 | completion.</para></note>
|
---|
| 202 |
|
---|
[931a597] | 203 | <para>This script imports bash completion scripts, installed by many
|
---|
| 204 | other BLFS packages, to allow TAB command line completion.</para>
|
---|
| 205 |
|
---|
| 206 | <screen role="root"><userinput>cat > /etc/profile.d/bash_completion.sh << "EOF"
|
---|
| 207 | <literal># Begin /etc/profile.d/bash_completion.sh
|
---|
| 208 | # Import bash completion scripts
|
---|
| 209 |
|
---|
[5c3f3856] | 210 | # If the bash-completion package is installed, use its configuration instead
|
---|
| 211 | if [ -f /usr/share/bash-completion/bash_completion ]; then
|
---|
| 212 |
|
---|
| 213 | # Check for interactive bash and that we haven't already been sourced.
|
---|
| 214 | if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
---|
| 215 |
|
---|
| 216 | # Check for recent enough version of bash.
|
---|
| 217 | if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
|
---|
| 218 | [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
|
---|
| 219 | [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
|
---|
| 220 | . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
---|
| 221 | if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
|
---|
| 222 | # Source completion code.
|
---|
| 223 | . /usr/share/bash-completion/bash_completion
|
---|
| 224 | fi
|
---|
| 225 | fi
|
---|
| 226 | fi
|
---|
| 227 |
|
---|
| 228 | else
|
---|
| 229 |
|
---|
| 230 | # bash-completions are not installed, use only bash completion directory
|
---|
| 231 | if shopt -q progcomp; then
|
---|
| 232 | for script in /etc/bash_completion.d/* ; do
|
---|
| 233 | if [ -r $script ] ; then
|
---|
| 234 | . $script
|
---|
| 235 | fi
|
---|
| 236 | done
|
---|
| 237 | fi
|
---|
| 238 | fi
|
---|
| 239 |
|
---|
[931a597] | 240 | # End /etc/profile.d/bash_completion.sh</literal>
|
---|
| 241 | EOF</userinput></screen>
|
---|
| 242 | <para>Make sure that the directory exists:</para>
|
---|
| 243 |
|
---|
| 244 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/bash_completion.d</userinput></screen>
|
---|
| 245 |
|
---|
[5c3f3856] | 246 | <para>For a more complete installation, see
|
---|
| 247 | <ulink url="&blfs-wiki;/bash-shell-startup-files#bash-completions"/>.</para>
|
---|
[931a597] | 248 |
|
---|
[5c3f3856] | 249 | </sect3>
|
---|
[931a597] | 250 |
|
---|
[2753b70b] | 251 | <sect3 id="etc-profile.d-dircolors.sh">
|
---|
| 252 | <title>/etc/profile.d/dircolors.sh</title>
|
---|
| 253 |
|
---|
| 254 | <indexterm zone="postlfs-config-profile etc-profile.d-dircolors.sh">
|
---|
| 255 | <primary sortas="e-etc-profile.d-dircolors.sh">/etc/profile.d/dircolors.sh</primary>
|
---|
| 256 | </indexterm>
|
---|
| 257 |
|
---|
| 258 | <para>This script uses the <filename>~/.dircolors</filename> and
|
---|
| 259 | <filename>/etc/dircolors</filename> files to control the colors of file names in a
|
---|
| 260 | directory listing. They control colorized output of things like <command>ls
|
---|
[ba0deaad] | 261 | --color</command>. The explanation of how to initialize these files is at the
|
---|
[2753b70b] | 262 | end of this section.</para>
|
---|
| 263 |
|
---|
| 264 | <screen role="root"><userinput>cat > /etc/profile.d/dircolors.sh << "EOF"
|
---|
[b5905ae] | 265 | <literal># Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
|
---|
[1a396398] | 266 | if [ -f "/etc/dircolors" ] ; then
|
---|
| 267 | eval $(dircolors -b /etc/dircolors)
|
---|
[89ef45fc] | 268 | fi
|
---|
[384039a] | 269 |
|
---|
[89ef45fc] | 270 | if [ -f "$HOME/.dircolors" ] ; then
|
---|
| 271 | eval $(dircolors -b $HOME/.dircolors)
|
---|
[b554263] | 272 | fi
|
---|
[89ef45fc] | 273 |
|
---|
[b5905ae] | 274 | alias ls='ls --color=auto'
|
---|
| 275 | alias grep='grep --color=auto'</literal>
|
---|
[2753b70b] | 276 | EOF</userinput></screen>
|
---|
| 277 |
|
---|
| 278 | </sect3>
|
---|
| 279 |
|
---|
| 280 | <sect3 id="extrapaths.sh">
|
---|
| 281 | <title>/etc/profile.d/extrapaths.sh</title>
|
---|
| 282 |
|
---|
| 283 | <indexterm zone="postlfs-config-profile extrapaths.sh">
|
---|
| 284 | <primary sortas="e-etc-profile.d-extrapaths.sh">/etc/profile.d/extrapaths.sh</primary>
|
---|
| 285 | </indexterm>
|
---|
| 286 |
|
---|
[dc53944] | 287 | <para>This script adds some useful paths to the <envar>PATH</envar> and
|
---|
| 288 | can be used to customize other PATH related environment variables
|
---|
[f3429309] | 289 | (e.g. LD_LIBRARY_PATH, etc) that may be needed for all users.</para>
|
---|
[384039a] | 290 |
|
---|
[2753b70b] | 291 | <screen role="root"><userinput>cat > /etc/profile.d/extrapaths.sh << "EOF"
|
---|
| 292 | <literal>if [ -d /usr/local/lib/pkgconfig ] ; then
|
---|
[1a396398] | 293 | pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
|
---|
| 294 | fi
|
---|
| 295 | if [ -d /usr/local/bin ]; then
|
---|
| 296 | pathprepend /usr/local/bin
|
---|
[b554263] | 297 | fi
|
---|
[1a396398] | 298 | if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
|
---|
| 299 | pathprepend /usr/local/sbin
|
---|
[a4f641b] | 300 | fi
|
---|
[bfa21f3] | 301 |
|
---|
| 302 | # Set some defaults before other applications add to these paths.
|
---|
| 303 | pathappend /usr/share/man MANPATH
|
---|
[a4f641b] | 304 | pathappend /usr/share/info INFOPATH</literal>
|
---|
[2753b70b] | 305 | EOF</userinput></screen>
|
---|
| 306 |
|
---|
| 307 | </sect3>
|
---|
| 308 |
|
---|
| 309 | <sect3 id="readline.sh">
|
---|
| 310 | <title>/etc/profile.d/readline.sh</title>
|
---|
| 311 |
|
---|
| 312 | <indexterm zone="postlfs-config-profile readline.sh">
|
---|
| 313 | <primary sortas="e-etc-profile.d-readline.sh">/etc/profile.d/readline.sh</primary>
|
---|
| 314 | </indexterm>
|
---|
| 315 |
|
---|
[384039a] | 316 | <para>This script sets up the default <filename>inputrc</filename>
|
---|
| 317 | configuration file. If the user does not have individual settings, it uses the
|
---|
[2753b70b] | 318 | global file.</para>
|
---|
| 319 |
|
---|
| 320 | <screen role="root"><userinput>cat > /etc/profile.d/readline.sh << "EOF"
|
---|
| 321 | <literal># Setup the INPUTRC environment variable.
|
---|
[b554263] | 322 | if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
|
---|
[1a396398] | 323 | INPUTRC=/etc/inputrc
|
---|
[b554263] | 324 | fi
|
---|
[2753b70b] | 325 | export INPUTRC</literal>
|
---|
| 326 | EOF</userinput></screen>
|
---|
| 327 |
|
---|
| 328 | </sect3>
|
---|
| 329 |
|
---|
| 330 | <sect3 id="umask.sh">
|
---|
| 331 | <title>/etc/profile.d/umask.sh</title>
|
---|
| 332 |
|
---|
| 333 | <indexterm zone="postlfs-config-profile umask.sh">
|
---|
| 334 | <primary sortas="e-etc-profile.d-umask.sh">/etc/profile.d/umask.sh</primary>
|
---|
| 335 | </indexterm>
|
---|
[384039a] | 336 |
|
---|
| 337 | <para>Setting the <command>umask</command> value is important for security.
|
---|
| 338 | Here the default group write permissions are turned off for system users and when
|
---|
[2753b70b] | 339 | the user name and group name are not the same.</para>
|
---|
[b554263] | 340 |
|
---|
[2753b70b] | 341 | <screen role="root"><userinput>cat > /etc/profile.d/umask.sh << "EOF"
|
---|
[ec64d28] | 342 | <literal># By default, the umask should be set.
|
---|
[1a396398] | 343 | if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
|
---|
| 344 | umask 002
|
---|
| 345 | else
|
---|
| 346 | umask 022
|
---|
[2753b70b] | 347 | fi</literal>
|
---|
| 348 | EOF</userinput></screen>
|
---|
| 349 |
|
---|
| 350 | </sect3>
|
---|
| 351 |
|
---|
[be409f9a] | 352 | <!-- This is handled in the Xorg section of the book
|
---|
[2753b70b] | 353 | <sect3 id="X.sh">
|
---|
| 354 | <title>/etc/profile.d/X.sh</title>
|
---|
[1a396398] | 355 |
|
---|
[2753b70b] | 356 | <indexterm zone="postlfs-config-profile X.sh">
|
---|
| 357 | <primary sortas="e-etc-profile.d-X.sh">/etc/profile.d/X.sh</primary>
|
---|
| 358 | </indexterm>
|
---|
[1a396398] | 359 |
|
---|
[384039a] | 360 | <para>If <application>X</application> is installed, the <envar>PATH</envar>
|
---|
[2753b70b] | 361 | and <envar>PKG_CONFIG_PATH</envar> variables are also updated.</para>
|
---|
[1a396398] | 362 |
|
---|
[2753b70b] | 363 | <screen role="root"><userinput>cat > /etc/profile.d/X.sh << "EOF"
|
---|
| 364 | <literal>if [ -x /usr/X11R6/bin/X ]; then
|
---|
[1a396398] | 365 | pathappend /usr/X11R6/bin
|
---|
| 366 | fi
|
---|
| 367 | if [ -d /usr/X11R6/lib/pkgconfig ] ; then
|
---|
| 368 | pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
|
---|
[2753b70b] | 369 | fi</literal>
|
---|
| 370 | EOF</userinput></screen>
|
---|
| 371 |
|
---|
| 372 | </sect3>
|
---|
[be409f9a] | 373 | -->
|
---|
[d202a49f] | 374 | <sect3 id="i18n.sh">
|
---|
| 375 | <!-- This is handled system wide on systemd but LANG is not exported to
|
---|
| 376 | the environment, hence it's return...need to add additional text for
|
---|
| 377 | systemd only -->
|
---|
[0d7ec6f1] | 378 | <title>/etc/profile.d/i18n.sh</title>
|
---|
[2753b70b] | 379 |
|
---|
| 380 | <indexterm zone="postlfs-config-profile i18n.sh">
|
---|
| 381 | <primary sortas="e-etc-profile.d-i18n.sh">/etc/profile.d/i18n.sh</primary>
|
---|
| 382 | </indexterm>
|
---|
| 383 |
|
---|
[0f442884] | 384 | <para>This script sets an environment variable necessary for
|
---|
| 385 | native language support. A full discussion on determining this
|
---|
| 386 | variable can be found on the <ulink
|
---|
| 387 | url="&lfs-root;/chapter07/profile.html">LFS Bash Shell
|
---|
| 388 | Startup Files</ulink> page.</para>
|
---|
[2753b70b] | 389 |
|
---|
[1794983d] | 390 | <screen role="root" revision="sysv"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
[2753b70b] | 391 | <literal># Set up i18n variables
|
---|
[0f442884] | 392 | export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable></literal>
|
---|
[1794983d] | 393 | EOF</userinput></screen>
|
---|
| 394 |
|
---|
| 395 | <screen role="root" revision="systemd"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
| 396 | <literal># Set up i18n variables
|
---|
| 397 | . /etc/locale.conf
|
---|
| 398 | export LANG</literal>
|
---|
[2753b70b] | 399 | EOF</userinput></screen>
|
---|
| 400 |
|
---|
| 401 | </sect3>
|
---|
| 402 |
|
---|
| 403 | <sect3>
|
---|
| 404 | <title>Other Initialization Values</title>
|
---|
| 405 |
|
---|
[384039a] | 406 | <para>Other initialization can easily be added to the
|
---|
| 407 | <filename>profile</filename> by adding additional scripts to the
|
---|
[2753b70b] | 408 | <filename class='directory'>/etc/profile.d</filename> directory.</para>
|
---|
| 409 |
|
---|
| 410 | </sect3>
|
---|
| 411 |
|
---|
| 412 | </sect2>
|
---|
| 413 |
|
---|
| 414 | <sect2 id="etc-bashrc-profile">
|
---|
| 415 | <title>/etc/bashrc</title>
|
---|
| 416 |
|
---|
| 417 | <indexterm zone="postlfs-config-profile etc-bashrc-profile">
|
---|
| 418 | <primary sortas="e-etc-bashrc">/etc/bashrc</primary>
|
---|
| 419 | </indexterm>
|
---|
| 420 |
|
---|
| 421 | <para>Here is a base <filename>/etc/bashrc</filename>. Comments in the
|
---|
| 422 | file should explain everything you need.</para>
|
---|
| 423 |
|
---|
| 424 | <screen role="root"><userinput>cat > /etc/bashrc << "EOF"
|
---|
[384039a] | 425 | <literal># Begin /etc/bashrc
|
---|
| 426 | # Written for Beyond Linux From Scratch
|
---|
[b554263] | 427 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[4e88613] | 428 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
[ad33bab6] | 429 |
|
---|
[b554263] | 430 | # System wide aliases and functions.
|
---|
| 431 |
|
---|
| 432 | # System wide environment variables and startup programs should go into
|
---|
| 433 | # /etc/profile. Personal environment variables and startup programs
|
---|
| 434 | # should go into ~/.bash_profile. Personal aliases and functions should
|
---|
| 435 | # go into ~/.bashrc
|
---|
| 436 |
|
---|
[b5905ae] | 437 | # Provides colored /bin/ls and /bin/grep commands. Used in conjunction
|
---|
| 438 | # with code in /etc/profile.
|
---|
[1a396398] | 439 |
|
---|
[b554263] | 440 | alias ls='ls --color=auto'
|
---|
[b5905ae] | 441 | alias grep='grep --color=auto'
|
---|
[b554263] | 442 |
|
---|
[1a396398] | 443 | # Provides prompt for non-login shells, specifically shells started
|
---|
[2753b70b] | 444 | # in the X environment. [Review the LFS archive thread titled
|
---|
[384039a] | 445 | # PS1 Environment Variable for a great case study behind this script
|
---|
[dd362e5] | 446 | # addendum.]
|
---|
[1a396398] | 447 |
|
---|
[0d7ec6f1] | 448 | NORMAL="\[\e[0m\]"
|
---|
| 449 | RED="\[\e[1;31m\]"
|
---|
| 450 | GREEN="\[\e[1;32m\]"
|
---|
| 451 | if [[ $EUID == 0 ]] ; then
|
---|
| 452 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
| 453 | else
|
---|
| 454 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
| 455 | fi
|
---|
[28a9992] | 456 |
|
---|
[dc53944] | 457 | unset RED GREEN NORMAL
|
---|
| 458 |
|
---|
[2753b70b] | 459 | # End /etc/bashrc</literal>
|
---|
| 460 | EOF</userinput></screen>
|
---|
| 461 |
|
---|
| 462 | </sect2>
|
---|
| 463 |
|
---|
| 464 | <sect2 id="bash_profile-profile">
|
---|
| 465 | <title>~/.bash_profile</title>
|
---|
| 466 |
|
---|
| 467 | <indexterm zone="postlfs-config-profile bash_profile-profile">
|
---|
| 468 | <primary sortas="e-AA.bash_profile">~/.bash_profile</primary>
|
---|
| 469 | </indexterm>
|
---|
| 470 |
|
---|
| 471 | <para>Here is a base <filename>~/.bash_profile</filename>. If you want each
|
---|
| 472 | new user to have this file automatically, just change the output of
|
---|
| 473 | the command to <filename>/etc/skel/.bash_profile</filename> and check the
|
---|
| 474 | permissions after the command is run. You can then copy
|
---|
| 475 | <filename>/etc/skel/.bash_profile</filename> to the home directories of already
|
---|
[384039a] | 476 | existing users, including <systemitem class="username">root</systemitem>,
|
---|
[2753b70b] | 477 | and set the owner and group appropriately.</para>
|
---|
| 478 |
|
---|
| 479 | <screen><userinput>cat > ~/.bash_profile << "EOF"
|
---|
| 480 | <literal># Begin ~/.bash_profile
|
---|
[b554263] | 481 | # Written for Beyond Linux From Scratch
|
---|
| 482 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[4e88613] | 483 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
[b554263] | 484 |
|
---|
[64d97b7c] | 485 | # Personal environment variables and startup programs.
|
---|
[b554263] | 486 |
|
---|
| 487 | # Personal aliases and functions should go in ~/.bashrc. System wide
|
---|
| 488 | # environment variables and startup programs are in /etc/profile.
|
---|
| 489 | # System wide aliases and functions are in /etc/bashrc.
|
---|
| 490 |
|
---|
| 491 | if [ -f "$HOME/.bashrc" ] ; then
|
---|
[76d61ba] | 492 | source $HOME/.bashrc
|
---|
[b554263] | 493 | fi
|
---|
| 494 |
|
---|
| 495 | if [ -d "$HOME/bin" ] ; then
|
---|
[dc53944] | 496 | pathprepend $HOME/bin
|
---|
[b554263] | 497 | fi
|
---|
| 498 |
|
---|
[dc53944] | 499 | # Having . in the PATH is dangerous
|
---|
| 500 | #if [ $EUID -gt 99 ]; then
|
---|
| 501 | # pathappend .
|
---|
| 502 | #fi
|
---|
[b554263] | 503 |
|
---|
[2753b70b] | 504 | # End ~/.bash_profile</literal>
|
---|
| 505 | EOF</userinput></screen>
|
---|
| 506 |
|
---|
| 507 | </sect2>
|
---|
[384039a] | 508 |
|
---|
[6f36554] | 509 | <sect2 id="dot_profile-profile">
|
---|
| 510 | <title>~/.profile</title>
|
---|
| 511 |
|
---|
| 512 | <indexterm zone="postlfs-config-profile dot_profile-profile">
|
---|
| 513 | <primary sortas="e-AA.dot_profile">~/.profile</primary>
|
---|
| 514 | </indexterm>
|
---|
| 515 |
|
---|
| 516 | <para>Here is a base <filename>~/.profile</filename>. The comments and
|
---|
| 517 | instructions for using <filename class="directory">/etc/skel</filename> for
|
---|
| 518 | <filename>.bash_profile</filename> above also apply here. Only the target
|
---|
| 519 | file names are different.</para>
|
---|
| 520 |
|
---|
| 521 | <screen><userinput>cat > ~/.profile << "EOF"
|
---|
| 522 | <literal># Begin ~/.profile
|
---|
| 523 | # Personal environment variables and startup programs.
|
---|
| 524 |
|
---|
| 525 | if [ -d "$HOME/bin" ] ; then
|
---|
| 526 | pathprepend $HOME/bin
|
---|
| 527 | fi
|
---|
| 528 |
|
---|
[d202a49f] | 529 | # Set up user specific i18n variables
|
---|
| 530 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
| 531 |
|
---|
[6f36554] | 532 | # End ~/.profile</literal>
|
---|
| 533 | EOF</userinput></screen>
|
---|
| 534 |
|
---|
| 535 | </sect2>
|
---|
| 536 |
|
---|
[2753b70b] | 537 | <sect2 id="bashrc-profile">
|
---|
| 538 | <title>~/.bashrc</title>
|
---|
| 539 |
|
---|
| 540 | <indexterm zone="postlfs-config-profile bashrc-profile">
|
---|
| 541 | <primary sortas="e-AA.bashrc">~/.bashrc</primary>
|
---|
| 542 | </indexterm>
|
---|
| 543 |
|
---|
[6f36554] | 544 | <para>Here is a base <filename>~/.bashrc</filename>.</para>
|
---|
[2753b70b] | 545 |
|
---|
| 546 | <screen><userinput>cat > ~/.bashrc << "EOF"
|
---|
| 547 | <literal># Begin ~/.bashrc
|
---|
[b554263] | 548 | # Written for Beyond Linux From Scratch
|
---|
| 549 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 550 |
|
---|
| 551 | # Personal aliases and functions.
|
---|
| 552 |
|
---|
| 553 | # Personal environment variables and startup programs should go in
|
---|
[64d97b7c] | 554 | # ~/.bash_profile. System wide environment variables and startup
|
---|
[b554263] | 555 | # programs are in /etc/profile. System wide aliases and functions are
|
---|
[384039a] | 556 | # in /etc/bashrc.
|
---|
[b554263] | 557 |
|
---|
| 558 | if [ -f "/etc/bashrc" ] ; then
|
---|
[76d61ba] | 559 | source /etc/bashrc
|
---|
[b554263] | 560 | fi
|
---|
| 561 |
|
---|
[d202a49f] | 562 | # Set up user specific i18n variables
|
---|
| 563 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
| 564 |
|
---|
[2753b70b] | 565 | # End ~/.bashrc</literal>
|
---|
| 566 | EOF</userinput></screen>
|
---|
| 567 |
|
---|
| 568 | </sect2>
|
---|
[384039a] | 569 |
|
---|
| 570 |
|
---|
[2753b70b] | 571 | <sect2 id="bash_logout-profile">
|
---|
| 572 | <title>~/.bash_logout</title>
|
---|
| 573 |
|
---|
| 574 | <indexterm zone="postlfs-config-profile bash_logout-profile">
|
---|
| 575 | <primary sortas="e-AA.bash_logout">~/.bash_logout</primary>
|
---|
| 576 | </indexterm>
|
---|
| 577 |
|
---|
| 578 | <para>This is an empty <filename>~/.bash_logout</filename> that can be used as
|
---|
| 579 | a template. You will notice that the base <filename>~/.bash_logout</filename>
|
---|
| 580 | does not include a <userinput>clear</userinput> command. This is because the
|
---|
| 581 | clear is handled in the <filename>/etc/issue</filename> file.</para>
|
---|
| 582 |
|
---|
| 583 | <screen><userinput>cat > ~/.bash_logout << "EOF"
|
---|
| 584 | <literal># Begin ~/.bash_logout
|
---|
[b554263] | 585 | # Written for Beyond Linux From Scratch
|
---|
| 586 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 587 |
|
---|
| 588 | # Personal items to perform on logout.
|
---|
| 589 |
|
---|
[2753b70b] | 590 | # End ~/.bash_logout</literal>
|
---|
| 591 | EOF</userinput></screen>
|
---|
| 592 |
|
---|
| 593 | </sect2>
|
---|
[384039a] | 594 |
|
---|
| 595 |
|
---|
[2753b70b] | 596 | <sect2 id="etc-dircolors-profile">
|
---|
| 597 | <title>/etc/dircolors</title>
|
---|
| 598 |
|
---|
| 599 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
| 600 | <primary sortas="e-etc-dircolors">/etc/dircolors</primary>
|
---|
| 601 | </indexterm>
|
---|
| 602 |
|
---|
| 603 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
| 604 | <primary sortas="e-AA.dircolors">~/.dircolors</primary>
|
---|
| 605 | </indexterm>
|
---|
| 606 |
|
---|
[6f36554] | 607 | <para> If you want to use the <filename>dircolors</filename> capability,
|
---|
| 608 | then run the following command. The
|
---|
| 609 | <filename class="directory">/etc/skel</filename> setup steps shown above
|
---|
| 610 | also can be used here to provide a <filename>~/.dircolors</filename> file
|
---|
| 611 | when a new user is set up. As before, just change the output file name on
|
---|
| 612 | the following command and assure the permissions, owner, and group are
|
---|
| 613 | correct on the files created and/or copied.</para>
|
---|
[2753b70b] | 614 |
|
---|
| 615 | <screen role="root"><userinput>dircolors -p > /etc/dircolors</userinput></screen>
|
---|
| 616 |
|
---|
[6f36554] | 617 | <para>If you wish to customize the colors used for different file types,
|
---|
| 618 | you can edit the <filename>/etc/dircolors</filename> file. The instructions
|
---|
| 619 | for setting the colors are embedded in the file.</para>
|
---|
[2753b70b] | 620 |
|
---|
| 621 |
|
---|
| 622 | <para>Finally, Ian Macdonald has written an excellent collection of tips and
|
---|
| 623 | tricks to enhance your shell environment. You can read it online at
|
---|
[ba0deaad] | 624 | <ulink url="http://www.caliban.org/bash/index.shtml"/>.</para>
|
---|
[2753b70b] | 625 |
|
---|
| 626 | </sect2>
|
---|
| 627 |
|
---|
[b554263] | 628 | </sect1>
|
---|