mirror of
https://github.com/dylanaraps/pure-bash-bible.git
synced 2025-01-17 04:08:17 +01:00
95 lines
1.5 KiB
Plaintext
95 lines
1.5 KiB
Plaintext
# INTERNAL VARIABLES
|
|
|
|
## 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 -->
|
|
|