pure-bash-bible/manuscript/chapter16.txt

95 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2018-06-23 02:34:15 +02:00
# INTERNAL VARIABLES
2018-06-23 02:34:15 +02:00
## Get the location to the `bash` binary
2018-06-21 10:00:05 +02:00
2018-06-23 02:34:15 +02:00
```shell
"$BASH"
```
2018-06-23 02:34:15 +02:00
## Get the version of the current running `bash` process
2018-06-23 02:34:15 +02:00
```shell
# As a string.
"$BASH_VERSION"
2018-06-20 05:03:53 +02:00
2018-06-23 02:34:15 +02:00
# As an array.
"${BASH_VERSINFO[@]}"
```
2018-06-23 02:34:15 +02:00
## Open the user's preferred text editor
```shell
2018-06-23 02:34:15 +02:00
"$EDITOR" "$file"
# NOTE: This variable may be empty, set a fallback value.
"${EDITOR:-vi}" "$file"
```
2018-06-23 02:34:15 +02:00
## Get the name of the current function
```shell
# Current function.
"${FUNCNAME[0]}"
2018-06-23 02:34:15 +02:00
# Parent function.
"${FUNCNAME[1]}"
2018-06-23 02:34:15 +02:00
# So on and so forth.
"${FUNCNAME[2]}"
"${FUNCNAME[3]}"
2018-06-23 02:34:15 +02:00
# All functions including parents.
"${FUNCNAME[@]}"
```
2018-06-23 02:34:15 +02:00
## Get the host-name of the system
```shell
2018-06-23 02:34:15 +02:00
"$HOSTNAME"
2018-06-23 02:34:15 +02:00
# NOTE: This variable may be empty.
# Optionally set a fallback to the hostname command.
"${HOSTNAME:-$(hostname)}"
```
2018-06-23 02:34:15 +02:00
## Get the architecture of the Operating System
2018-06-23 02:34:15 +02:00
```shell
"$HOSTTYPE"
```
## Get the name of the Operating System / Kernel
2018-06-23 02:34:15 +02:00
This can be used to add conditional support for different Operating
Systems without needing to call `uname`.
2018-06-23 02:34:15 +02:00
```shell
"$OSTYPE"
```
2018-06-23 02:34:15 +02:00
## 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
2018-06-23 02:34:15 +02:00
"$RANDOM"
```
<!-- CHAPTER END -->