Merge pull request #52 from Crestwave/username

Add "Get the username of the current user" entry
This commit is contained in:
black
2019-01-19 10:37:23 +02:00
committed by GitHub
4 changed files with 29 additions and 4 deletions

View File

@@ -147,6 +147,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s
* [Use `read` as an alternative to the `sleep` command](#use-read-as-an-alternative-to-the-sleep-command) * [Use `read` as an alternative to the `sleep` command](#use-read-as-an-alternative-to-the-sleep-command)
* [Check if a program is in the user's PATH](#check-if-a-program-is-in-the-users-path) * [Check if a program is in the user's PATH](#check-if-a-program-is-in-the-users-path)
* [Get the current date using `strftime`](#get-the-current-date-using-strftime) * [Get the current date using `strftime`](#get-the-current-date-using-strftime)
* [Get the username of the current user](#get-the-username-of-the-current-user)
* [Generate a UUID V4](#generate-a-uuid-v4) * [Generate a UUID V4](#generate-a-uuid-v4)
* [Progress bars](#progress-bars) * [Progress bars](#progress-bars)
* [Get the list of functions in a script](#get-the-list-of-functions-in-a-script) * [Get the list of functions in a script](#get-the-list-of-functions-in-a-script)
@@ -1875,6 +1876,17 @@ $ printf '%s\n' "$date"
Fri 15 Jun - 10:00 AM Fri 15 Jun - 10:00 AM
``` ```
## Get the username of the current user
**CAVEAT:** Requires `bash` 4.4+
```shell
$ : \\u
# Expand the parameter as if it were a prompt string
$ printf '%s\n' "${_@P}"
black
```
## Generate a UUID V4 ## Generate a UUID V4
**CAVEAT**: The generated value is not cryptographically secure. **CAVEAT**: The generated value is not cryptographically secure.

View File

@@ -1,10 +1,10 @@
# FOREWORD # FOREWORD
A collection of pure `bash` alternatives to external processes and programs. The `bash` scripting language is more powerful than people realise and most tasks can be accomplished without the need for or dependence on external programs. A collection of pure `bash` alternatives to external processes and programs. The `bash` scripting language is more powerful than people realise and most tasks can be accomplished without depending on external programs.
Calling an external process in `bash` is expensive and excessive use will cause a noticeable slowdown. Scripts and programs written using built-in methods (*where applicable*) will be faster, require less dependencies and afford a better understanding of the language itself. Calling an external process in `bash` is expensive and excessive use will cause a noticeable slowdown. Scripts and programs written using built-in methods (*where applicable*) will be faster, require fewer dependencies and afford a better understanding of the language itself.
The content of this book provides a reference for solving problems encountered when writing programs and scripts in `bash`. Examples are in function format showcasing how to incorporate these solutions into code. The contents of this book provide a reference for solving problems encountered when writing programs and scripts in `bash`. Examples are in function formats showcasing how to incorporate these solutions into code.
<!-- CHAPTER END --> <!-- CHAPTER END -->

View File

@@ -64,7 +64,7 @@ John Black is my name.
The result of `bash`'s regex matching can be used to replace `sed` for a The result of `bash`'s regex matching can be used to replace `sed` for a
large number of use-cases. large number of use-cases.
**CAVEAT**: This is one of the few platform dependant `bash` features. **CAVEAT**: This is one of the few platform dependent `bash` features.
`bash` will use whatever regex engine is installed on the user's system. `bash` will use whatever regex engine is installed on the user's system.
Stick to POSIX regex features if aiming for compatibility. Stick to POSIX regex features if aiming for compatibility.

View File

@@ -82,8 +82,21 @@ $ printf '%s\n' "$date"
Fri 15 Jun - 10:00 AM Fri 15 Jun - 10:00 AM
``` ```
## Get the username of the current user
**CAVEAT:** Requires `bash` 4.4+
```shell
$ : \\u
# Expand the parameter as if it were a prompt string
$ printf '%s\n' "${_@P}"
black
```
## Generate a UUID V4 ## Generate a UUID V4
**CAVEAT**: The generated value is not cryptographically secure.
**Example Function:** **Example Function:**
```sh ```sh