This is an old revision of the document!
This article is currently being expanded upon. Please do not make any changes to it until this notice is removed.
Bash: Customization Basics
## Invocation Methods
#### Invoked as interactive login shell\n(ex: SSH, SU) 1. /etc/profile
a. /etc/profile.d/
2. /etc/bashrc 3. ~/.bash_profile
a. ~/.bashrc
4. ~/.bash_logout (upon logout)
#### Invoked as interactive non-login shell (ex: within X window manager) - ~/.bashrc
#### Invoked non-interactively (ex: scripts) - Defined by BASH_ENV
## Basics
###### `$ echo $PATH` See directories bash looks for scripts in.
## Notes
- User specific functions should go in user\'s .bashrc
- Global functions should be individual files in /etc/profile.d/
## Aliases
###### `$ alias -p` See list of active aliases.
###### `$ alias li=\'ls -li\'` Create alias for li for current shell process only.
###### `$ unalias` For unsetting aliases.
## Environment Variables
### Getting Variable Info
###### `$ env` See list of global variables.
###### `$ printenv` Same as above, but with less available option flags.
###### `$ set` See full list of global and local variables.
###### `$ declare` Another long list of environment variables.
###### `$ printenv HOME` See value for global variable HOME.
###### `$ echo $HOME` Same as above.
###### `$ ls $HOME` Use global variable HOME as part of another command.
### Setting Variables
###### `$ testvar=testvalue` Set value of new local variable \'testvar\'.
###### `$ testvar=\“A String Value\”` Same as above, but for strings.
###### `$ testvar=$testvar:moredata` Append more data to the end of existing variable.
###### `$ testvar=$(other | commands)` Assign variable the result of set of commands.
###### `$ export testvar` Export a local variable to the global environment.
###### `$ unset testvar` Removes variable \'testvar\'.
### Variable Arrays
###### `$ vararray=(one two three four five)` Define multiple values for variable as array.
###### `$ echo ${vararray[2]}` Echo column three from vararray.
###### `$ echo ${vararray[*]}` Echo entire array from vararray.
###### `$ vararray[2]=whatever` Change the value of column three in vararray.
###### `$ unset vararry[2]` Remove column 2 from vararray. Prior col 3 now new col 2.
### Variable Notes
- Get value of variables with `$`, but don\'t use `$` when assigning them.
- Global environment variables can be accessed from any child shells of the parent from which it was defined.
- Local environment variables can only be accessed from the process in which they were defined.
- Export and unset, when used in a child shell, will not affect the parent shell.
- Variable arrays start with an index value of zero, not one.
Find this page online at: https://bestpoint.institute/tools/bash/customization