101 lines
1.7 KiB
Plaintext
101 lines
1.7 KiB
Plaintext
# Internal Variables
|
|
|
|
**NOTE**: This list does not include every internal variable (*You can
|
|
help by adding a missing entry!*).
|
|
|
|
For a complete list, see:
|
|
http://tldp.org/LDP/abs/html/internalvariables.html
|
|
|
|
## Get the location to the `bash` binary
|
|
|
|
```shell
|
|
"$BASH"
|
|
```
|
|
|
|
## Get the version of the current running `bash` process
|
|
|
|
```shell
|
|
# As a string.
|
|
"$BASH_VERSION"
|
|
|
|
# As an array.
|
|
"${BASH_VERSINFO[@]}"
|
|
```
|
|
|
|
## Open the user's preferred text editor
|
|
|
|
```shell
|
|
"$EDITOR" "$file"
|
|
|
|
# NOTE: This variable may be empty, set a fallback value.
|
|
"${EDITOR:-vi}" "$file"
|
|
```
|
|
|
|
## Get the name of the current function
|
|
|
|
```shell
|
|
# Current function.
|
|
"${FUNCNAME[0]}"
|
|
|
|
# Parent function.
|
|
"${FUNCNAME[1]}"
|
|
|
|
# So on and so forth.
|
|
"${FUNCNAME[2]}"
|
|
"${FUNCNAME[3]}"
|
|
|
|
# All functions including parents.
|
|
"${FUNCNAME[@]}"
|
|
```
|
|
|
|
## Get the host-name of the system
|
|
|
|
```shell
|
|
"$HOSTNAME"
|
|
|
|
# NOTE: This variable may be empty.
|
|
# Optionally set a fallback to the hostname command.
|
|
"${HOSTNAME:-$(hostname)}"
|
|
```
|
|
|
|
## Get the architecture of the Operating System
|
|
|
|
```shell
|
|
"$HOSTTYPE"
|
|
```
|
|
|
|
## Get the name of the Operating System / Kernel
|
|
|
|
This can be used to add conditional support for different Operating
|
|
Systems without needing to call `uname`.
|
|
|
|
```shell
|
|
"$OSTYPE"
|
|
```
|
|
|
|
## Get the current working directory
|
|
|
|
This is an alternative to the `pwd` built-in.
|
|
|
|
```shell
|
|
"$PWD"
|
|
```
|
|
|
|
## Get the number of seconds the script has been running
|
|
|
|
```shell
|
|
"$SECONDS"
|
|
```
|
|
|
|
## Get a pseudorandom integer
|
|
|
|
Each time `$RANDOM` is used, a different integer between `0` and `32767` is returned. This variable should not be used for anything related to security (*this includes encryption keys etc*).
|
|
|
|
|
|
```shell
|
|
"$RANDOM"
|
|
```
|
|
|
|
<!-- CHAPTER END -->
|
|
|