[kwlug-disc] Why I Don't Use #!/bin/bash - Shebangs Explained! (Another one by Dave at YSAP)

William Park opengeometry at yahoo.ca
Sun Aug 31 13:27:46 EDT 2025


Ah yes, I use ':' quite a lot at the top of script.

   - to set default if parameter is empty/null, eg.
     : ${xxx:=default}

   - to exit if paramter is empty/null, eg.
     : ${xxx:?must not be empty}


On 2025-08-31 09:50, Jason Eckert wrote:
> Somewhat related: If you've ever traced an ancient UNIX or Linux script, 
> you'd likely see a single colon on the first line instead of a shebang - 
> this is a shortcut to the true function and guarantees that the script 
> will run in the current shell, no matter what the calling shell is 
> (e.g., if you're in zsh and you run "bash script1.sh", it would still 
> run in zsh if the script started with a ":" line). It's one of those 
> things that are incredibly useful the few times you need it (and I've 
> used it many times over the years).
> 
> On Sun, 31 Aug 2025 at 01:59, Ron <ron at bclug.ca <mailto:ron at bclug.ca>> 
> wrote:
> 
> 
>     It's a long weekend, a good time to play in the garden, ride
>     bicycles up
>     and down hills, and watch some `bash` videos.
> 
> 
>     Dave at YSAP discusses "shebang" lines and does his deep-dive into them.
> 
> 
>     Shebang lines are those lines at the top of a script that bash
>     processes, right?
> 
>     Wrong. Bash ignores that line, it's the kernel that processes the
>     shebang.
> 
>     Node / v8 also are smart enough to ignore the shebang line, even though
>     lines starting with # in JS are *not* comments.  Cool!
> 
> 
> 
>     He compares behaviours on Darwin, Void Linux, and IllumOS / SunOS.
> 
>     Differences show up when passing options in shebang lines.
> 
> 
> 
>     Lots of interesting tricks can be had by tweaking that line, and after
>     some 10 minutes of general explanation, he heads down the rabbit hole
>     starting with his favourite distro, Void Linux.
> 
> 
>      > https://www.youtube.com/watch?v=aoHMiCzqCNw <https://
>     www.youtube.com/watch?v=aoHMiCzqCNw>
> 
> 
>     TL;DR:
> 
>     use:
> 
>     #!/usr/bin/env bash
> 
>     (or, since I'm a new convert)
> 
>     #!/usr/bin/env fish
> 
> 
>     _______________________________________________
>     kwlug-disc mailing list
>     To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
>     <mailto:kwlug-disc-leave at kwlug.org>
>     with the subject "unsubscribe", or email
>     kwlug-disc-owner at kwlug.org <mailto:kwlug-disc-owner at kwlug.org> to
>     contact a human being.
> 
> 
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.



More information about the kwlug-disc mailing list