105 Shells and Shell Scripting KT Flashcards
105.1 Customize and use the shell environment
The following is a partial list of the used files, terms and utilities:
. source /etc/bash.bashrc /etc/profile env export set unset ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc ~/.bash_logout function alias
.
Command: Read and execute commands from the filename argument in the current shell context.
. filename [arguments]
source
Command: Read and execute commands from the filename argument in the current shell context. source is a synonym for dot/period ‘.’ in bash, but not in POSIX sh, so for maximum compatibility use the period.
source filename [arguments]
/etc/bash.bashrc
System‐wide .bashrc file for interactive non-login shells.
The Debian version of bash is compiled with a special option (-DSYS_BASHRC) that makes bash read /etc/bash.bashrc before ~/.bashrc for interactive non-login shells. So, on Debian systems, /etc/bash.bashrc is to ~/.bashrc as /etc/profile is to ~/.bash_profile.
/etc/profile
/etc/profile: system‐wide .profile file for the Bourne shell.
When Bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
env
Command: Set each NAME to VALUE in the environment and run COMMAND. Run a program in a modified environment.
env [OPTION]… [-] [NAME=VALUE]… [COMMAND [ARG]…]
export
Command: Set export attribute for shell variables. Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied, assign VALUE before exporting.
export [-fn] [name[=value] …]
export -p
set
Command: Set or unset values of shell options and positional parameters. Change the value of shell attributes and positional parameters, or display the names and values of shell variables.
set [-abefhkmnptuvxBCHP] [-o option-name] [–] [arg …]
unset
Command: Unset values and attributes of shell variables and functions. For each NAME, remove the corresponding variable or function.
unset [-f] [-v] [-n] [name …]
~/.bash_profile
The ~/.bash_profile file is a configuration file for configuring user environments. The users can modify the default settings and add any extra configurations in it.
~/.bash_login
The ~/.bash_login file contains specific settings that are executed when a user logs in to the system.
~/.profile
The ~/.profile file is yet another configuration file that is read in the absence of the ~/.bash_profile and ~/.bash_login files.
~/.bashrc
User specific .bashrc file. ~/.bashrc: read and executed by bash(1) for interactive non‐login shells.
~/.bash_logout
The ~/.bash_logout file contains instructions for the logout procedure.
function
Command: This builtin command is used to create a new function. A function is a list of commands that will be executed when the name of the function is entered.
function [OPTIONS] NAME; BODY; end