From 7408b72778bb027f6d2e33cd588eb0b496d374c3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 19 Sep 2019 14:24:24 +0300 Subject: [PATCH] docs: update --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 4c928e9..b9dc81e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,9 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s * [Get the current working directory](#get-the-current-working-directory) * [Get the PID of the current shell](#get-the-pid-of-the-current-shell) * [Get the current shell options](#get-the-current-shell-options) +* [SHELL QUIRKS](#shell-quirks) + * [`shift` with no function arguments crashes `dash`.](#shift-with-no-function-arguments-crashes-dash) + * [`read` with no given variable crashes `dash`.](#read-with-no-given-variable-crashes-dash) * [AFTERWORD](#afterword) @@ -858,6 +861,31 @@ This is an alternative to the `pwd` built-in. "$-" ``` +# SHELL QUIRKS + +## `shift` with no function arguments crashes `dash`. + +```shell +# This will crash `dash` if there are no arguments. +shift + +# Solution (shift on its own is really 'shift 1'). +# This uses 'shift 0' if there are no arguments and +# 'shift 1' if there are. +shift "$(($# > 0 ? 1 : 0))" +``` + +## `read` with no given variable crashes `dash`. + +```shell +# This will crash `dash`. +read -r + +# Solution. +# Use a dummy variable. +read -r _ +``` + # AFTERWORD Thanks for reading! If this bible helped you in any way and you'd like to give back, consider donating. Donations give me the time to make this the best resource possible. Can't donate? That's OK, star the repo and share it with your friends!