I'm BREAKING UP With Bash (Using dash as /bin/sh)

preview_player
Показать описание
Are you tired of having your shell scripts run by the slow, bloated bash? In this video, I'll show you how you can change your system shell (/bin/sh) to dash for minimal performance and security gains—and, more importantly, how to write better shell scripts that are portable, posix-compliant and usable by everyone, not just bash users.

0:00 Intro
1:14 Differences between bash and dash
2:35 Installing dash
2:45 Checking /bin/sh scripts to remove bashisms
6:23 Making your scripts dash-compliant
7:40 Or just set bash scripts explicitly with /bin/bash
9:02 Using shellcheck for even more detail
10:00 Symlinking /bin/sh to dash
10:41 Relinking dash every time bash updates
11:45 Conclusion
Рекомендации по теме
Комментарии
Автор

I highly dislike both bash and dash, I prefer cash. Aside from the joke, thanks for this video ;) Cheers from France !

alexisbouchezcode
Автор

9:22 On the shellcheck command output, if you follow that link, it will open a page where it give code examples on how to replace arrays.

MisterConscio
Автор

I tried to do this thing few months back. However, I switched back to having bash as my default shell for the following reasons:
1) I run linux natively on pretty modern hardware, so there really is not much overhead provided by bash compared to dash. It may be few milliseconds faster, but for me, it's not even noticeable.
2) First point, doesn't really justify not switching because it's neither a positive nor a negative for me to change, However, I use some scripts using dmenu, which use non-posix compliant bashism or some "bloat" in form of extra flags in gnuutils which aren't recognized by dash.
Took me a while to figure out some of it, learned about POSIX shell and that bashisms aren't just limited to shell but also gnuutils. Like how BSD echo is different from GNU echo and so on.
...
For example, echo -e "up\down\connect" | dmenu
in bash gives (using "|" as separations of the different options)
up | down | connect ✅✅
in dash gives
-e up | down | connect ❌❌
...
So simple thing right? just replace the -e flag with something standard... like just use \n
echo "up\n\down\nconnect" | dmenu
if you run a script having this in dash it'd produce
up | down | connect ✅✅
HOWEVER, now Bash breaks it?? giving
up\ndown\nconnect ❌❌ as one single option
...
At last, I ended up switching from simple echo to printf just to pipe the output to dmenu.
I saw luke smith's video on GNU is bloated and then Brodie's video on POSIX and just got to terms with using bash as my system shell.
If I were handling an enterprise-grade server running linux, where security is paramount, I would switch the system shell to dash(if it already isn't) else for my personal computer where threat model is alright I would just stick to using bash.
...
If you wish to check whether your script would run in dash without having to reboot your computer over and over again and checking if it breaks or not (totally not me lol) just use shellcheck --shell=dash <path to script>

saumitit
Автор

Beautiful videos man, pretty well edited, and content is pretty good as well!, I am subscribed!. Quick question, do you have any videos-tutorials on how did you tune-up your terminal and OS to look that way? everything looks so comfy and elegant!
Cheers from Mexico City (:

danny.cuevas
Автор

How bad is writing POSIX-Compliant shell scripts?

joaopauloalbq
Автор

my issue about this is that bash is the default shell in most of the distros so if you are going to install another scripting runtime then you should better write your scripts in a decent scripting language that doesn't have the context-switching mess of shell scripting and use perl, python, lua, ruby, guile, etc.

laughingvampire
Автор

For a non-posix shell I'd reccomend Elvish. Had a lot of fun writing scripts with it (not a system shell though).

llloveletter
Автор

ubuntu is pronounced oo-boon-too, not you-bun-too

laughingvampire
Автор

Great video but sadly dash was causing quite a few issues for me so won't be using it for now. Maybe in the future it'll be a viable alternative or maybe even the recommended program for a /bin/sh

f_aaris
Автор

I use the AUR package dashbinsh. pfetch hostname works fine for me. (pfetch-git from AUR). And my scripts use "#!/usr/bin/env bash"

nico
visit shbcf.ru