Skip to content

Instantly share code, notes, and snippets.

@matu3ba
Created September 10, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matu3ba/7c1d702f4d97b8037d2f8f09b72aeea2 to your computer and use it in GitHub Desktop.
Save matu3ba/7c1d702f4d97b8037d2f8f09b72aeea2 to your computer and use it in GitHub Desktop.
Incomplete list of safety shortcomings in POSIX shell
Incomplete list of safety shortcomings in POSIX shell
NEVER leave your variables unquoted.
https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells
And variables with common prefixes without braces.
https://stackoverflow.com/questions/8748831/when-do-we-need-curly-braces-around-shell-variables
Always clean up your environment to prevent stack smashing.
https://github.com/netblue30/firejail/issues/3678
Better use `test [expression]` and dont dare to ask why
`[ 12 -le 13 ]` is also part of POSIX shell.
And why there are spaces and what happens if you forget them.
You can not in a POSIX way reliably and sanely short
1. check if symbols is defined in a script.
https://stackoverflow.com/questions/18597697/posix-compliant-way-to-scope-variables-to-a-function-in-a-shell-script
2. detect if a script is being sourced
https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
3. get the current directory of the script.
https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
4. how to find files in PATH (standard is ambiguous how it should work)
https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
Shells are for exactly 3 purposes of very limited sized programs and use
an ideally type-checked language otherwise:
1. filepath manipulation with globbing and alike
2. piping programs and their output
3. simple execution flow with respective job control
@matu3ba
Copy link
Author

matu3ba commented Jul 29, 2023

stored in dotfiles with minimal adjustments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment