This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
Dash¶
Dash is a small, fast, secure, and POSIX compliant implementation of /bin/sh
. Dash is not Bash
compatible: be careful of bashisms.
Reference(s)
- https://wiki.archlinux.org/title/Dash
- https://wiki.archlinux.org/index.php/Pacman#Hooks
- https://aur.archlinux.org/cgit/aur.git/tree/dashbinsh.hook?h=dashbinsh
- https://wiki.gentoo.org/wiki/Dash
- https://github.com/koalaman/shellcheck
- https://wiki.gentoo.org/wiki/Shell
- https://wiki.archlinux.org/index.php/Command-line_shell
- https://wiki.archlinux.org/index.php/Command-line_shell#Changing_your_default_shell
Table of contents¶
Install¶
Config¶
Dash can be optionally defined as the default shell for the system.
In this case, one can identify the scripts containing features of Bash that aren't supported in
Dash ('bashisms'), those scripts will not work without being explicitly pointed to /bin/bash
.
-
Install
checkbashisms
: -
Check installed scripts with a
#!/bin/sh
shebang that may need modification:
Finally, switch the system default shell:
Updates of Bash will overwrite
/bin/sh
with the default symlink. To
prevent this, use the following pacman
hook, which will relink /bin/sh
after every affected update:
# sudo vi /etc/pacman.d/hooks/dashbinsh.hook
> [Trigger]
> Type = Package
> Operation = Install
> Operation = Upgrade
> Target = bash
>
> [Action]
> Description = Re-pointing /bin/sh symlink to dash...
> When = PostTransaction
> Exec = /usr/bin/ln -sfT dash /usr/bin/sh
> Depends = dash
Use¶
-
Let's consider the following script:
In order to execute it with Dash, run:
If you want to execute it directly, then make sure your script starts with
#!/bin/dash
(or#!/bin/sh
if$ ls -la /bin/sh
points to/bin/dash
), make this script executable ($ chmod +x yourscript.whatever
), and run:
Tip
You can check your scripts for errors, warnings and suggestions with
shellcheck
.
-
How to create a dash configuration file like
$HOME/.bashrc # or ${ZDOTDIR:-${HOME}}/.zshrc or wherever
:
If this cheat sheet has been useful to you, then please consider leaving a star here.