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