Differences between revisions 2 and 3
Revision 2 as of 2023-01-22 23:35:08
Size: 3952
Comment:
Revision 3 as of 2023-01-22 23:54:15
Size: 5292
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
== Bash == == Bash Internals ==



=== History ===

`$HISTFILE` is the `bash(1)` history filename.

`$HISTFILESIZE` is the maximum file size for `$HISTFILE`, while `$HISTSIZE` the maximum number of commands for `$HISTFILE`.

`$HISTCONTROL` and `$HISTIGNORE` configure which commands are recorded in the history.

`$HISTCMD` is the current command's history number.

If `$HISTTIMEFORMAT` is set, commands are recorded in the history with a timestamp formatted with this value.

`$histchars` configure the history expansion.

Line 15: Line 33:
`$BASHPID` is the current shell's PID. `$BASHPID` is the current shell's PID. `$PPID` is the PID of the shell's parent.
Line 24: Line 42:

`$EMACS` and `$INSIDE_EMACS` are used to determine if the shell is operating within [[Emacs]], in which case line editing will be disabled.
Line 47: Line 67:
`$BASH_SOURCE` is an array of source filenames corresponding to `$FUNCNAME`. Function `${FUNCNAME[i]}` is defined in file `${BASH_SOURCE[i]}`.

Similarly, `$BASH_LINENO` is an array of line numbers that corresponds to `$FUNCNAME`. Function `${FUNCNAME[i]}` is called from line number `${BASH_LINENO[i]}`.
`$FUNCNAME` is an array of functions currently in the call stack. `$BASH_SOURCE` is an array of source filenames corresponding to `$FUNCNAME`. Function `${FUNCNAME[i]}` is defined in file `${BASH_SOURCE[i]}`. Similarly, `$BASH_LINENO` is an array of line numbers that corresponds to `$FUNCNAME`. Function `${FUNCNAME[i]}` is called from line number `${BASH_LINENO[i]}`.
Line 78: Line 96:
`$HOME` is the user's home directory.
Line 94: Line 111:
== Locale ==

`$LC_COLLATE`, `$LC_CTYPE`, `$LC_MESSAGES`, `$LC_NUMERIC`, and `$LC_TIME` are all used in different contexts to determine the current locale.

`$LANG` is the fallback value. `$LC_ALL` overrides `$LANG` and all of the above if set.

----


Line 100: Line 127:
`$MAILCHECK` is the number of seconds `bash(1)` will wait between checks. The default is 60.
Line 104: Line 133:
== Path == == Paths ==

`$PWD` is the current working directory.
Line 122: Line 153:
`$PS0`

`$PS4`

----



== User ==

`$UID` is the user's ID. `$EUID` is the effective EID.

`$GROUPS` is an array of groups the user is a member of.

`$HOME` is the user's home directory.

Bash Shell Variables

This is a list of special variables that are set in bash(1) to configure it's behavior, or by bash(1) to indicate state. For programming variables, including special ones, see here.


Bash Internals

History

$HISTFILE is the bash(1) history filename.

$HISTFILESIZE is the maximum file size for $HISTFILE, while $HISTSIZE the maximum number of commands for $HISTFILE.

$HISTCONTROL and $HISTIGNORE configure which commands are recorded in the history.

$HISTCMD is the current command's history number.

If $HISTTIMEFORMAT is set, commands are recorded in the history with a timestamp formatted with this value.

$histchars configure the history expansion.

Useful

$BASHPID is the current shell's PID. $PPID is the PID of the shell's parent.

$BASH_VERSION is the current shell's version number. $BASH_VERSINFO is an array representing this information.

BASH_ENV is a startup file used when bash(1) is used as a script interpretter.

$BASH_REMATCH is an array set by the =~ operator. The first item is the substring matching the entire regular expression. ${BASH_REMATCH[i]} is the substring matching the ith subexpression.

$BASH_XTRACEFD will, if set to an integer corresponding to a valid file descriptor, cause trace output to be written to that file descriptor.

$EMACS and $INSIDE_EMACS are used to determine if the shell is operating within Emacs, in which case line editing will be disabled.

Not Useful

$BASHOPTS is a colon-delimited list of enabled shell options.

$BASH_COMPAT is the compat level of the shell. Setting to 4.2 or 42 is equivalent to using the compat42 shell option.

$BASH_ALIASES is an associative array of aliases. $BASH_CMDS is an associative array of builtins.

$BASH_LOADABLES_PATH is a colon-separated list of directories searched for dynamically loadable builtins.

$_ is, at first, the pathname used to call the shell. Thereafter every time a command is called, $_ is the last argument to that command. Furthermore, while a command is executed, $_ is set to the pathname used to call that command. This is exposed when a command inspects its environment.

$BASH_COMMAND is the command currently executing. If bash(1) is executing a trap, $BASH_COMMAND will show the command that triggered the trap.

If bash(1) is called like bash -c '...', $BASH_EXECUTION_STRING is set to the command string.

$BASH_ARGV is an array containing all the arguments in the current shell call stack, while $BASH_ARGC is the count of those arguments. These are only set if extended debugging mode is on.

In a similar manner, $BASH_ARGV0 is the name of the shell. It is identical to $0.

$FUNCNAME is an array of functions currently in the call stack. $BASH_SOURCE is an array of source filenames corresponding to $FUNCNAME. Function ${FUNCNAME[i]} is defined in file ${BASH_SOURCE[i]}. Similarly, $BASH_LINENO is an array of line numbers that corresponds to $FUNCNAME. Function ${FUNCNAME[i]} is called from line number ${BASH_LINENO[i]}.

$BASH_SUBSHELL is the current nesting level of shells.


Directory Stack

$DIRSTACK is an array containing the directory stack.


Get Opts

The getopts builtin sets two variables:

  • $OPTARG is the most recent options's value

  • $OPTIND is the most recent option's index


Home


Inter Field Separator

$IFS defines the characters that should be interpreted as separating tokens.

Frequently, this is only manipulated when writing a pipeline that specially delimits items with the null byte.


Locale

$LC_COLLATE, $LC_CTYPE, $LC_MESSAGES, $LC_NUMERIC, and $LC_TIME are all used in different contexts to determine the current locale.

$LANG is the fallback value. $LC_ALL overrides $LANG and all of the above if set.


Mail

If $MAIL is set, bash(1) monitors it (assuming it is a mail file or Maildir directory) and informs the user of changes.

Similarly, $MAILPATH is a colon-delimited list of locations to monitor. If set, $MAIL is not monitored.

$MAILCHECK is the number of seconds bash(1) will wait between checks. The default is 60.


Paths

$PWD is the current working directory.

$PATH is a colon-delimited list of directories searched for commands.

$CDPATH is similarly searched by the cd builtin.


Prompts

$PS1 is printed at the beginning of every command prompt.

$PS2 is printed at the beginning of run-on lines.

$PS3 is printed at the prompt in select menus.

$PS0

$PS4


User

$UID is the user's ID. $EUID is the effective EID.

$GROUPS is an array of groups the user is a member of.

$HOME is the user's home directory.


CategoryRicottone

Bash/ShellVariables (last edited 2023-01-30 02:10:05 by DominicRicottone)