Added another entry

This commit is contained in:
Dylan Araps 2018-06-15 16:10:23 +10:00
parent 113686f557
commit 31289a98f1
1 changed files with 24 additions and 0 deletions

View File

@ -99,6 +99,7 @@ scripts and not full blown utilities.
* [Get the current working directory.](#get-the-current-working-directory)
* [Get the number of seconds the script has been running.](#get-the-number-of-seconds-the-script-has-been-running)
* [Other](#other)
* [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)
* [Bypass shell aliases.](#bypass-shell-aliases)
* [Bypass shell functions.](#bypass-shell-functions)
@ -1113,6 +1114,29 @@ This is an alternative to the `pwd` built-in.
# Other
## Check if a program is in the user's PATH.
```shell
# Bare.
type -p executable_name &>/dev/null
# As a test.
if type -p executable_name &>/dev/null; then
# Program is in PATH.
fi
# Inverse.
if ! type -p executable_name &>/dev/null; then
# Program is not in PATH.
fi
# Example (Exit early if program isn't installed).
if ! type -p convert &>/dev/null; then
printf '%s\n' "error: convert isn't installed, exiting..."
exit 1
fi
```
## Get the current date using `strftime`.
Bashs `printf` has a built-in method of getting the date which we can use