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