Making a Post-Install Script: #!/bin/bash

I’ve installed Ubuntu… SO many times. One day, I decided to create a post-install script. This is the first in many posts I’ll be writing about creating a post-install script.

What is a post install? In this case, it’s something you run right after you install your OS—specifically Ubuntu. I will be referring mostly (if not completely) to the post-install script I created on GitHub:

Let’s start at the top: #!/bin/bash

Why do I need #!/bin/bash ?

Yeah, it was sort of a weird thing for me at first. Basically, this tells the shell what interpreter to run. /bin/sh is the default if you do not specify anything—and this is OK a lot of the time. I’d say you should roll with the default unless you run into issues that require you to use bash (which I have with my scripts).

For example, take the script below:

let "MYVAR += 1"
echo $MYVAR

Now, you’d expect that MYVAR would now be 2, but instead you get something like this:

./ 3: ./ let: not found

Try adding the /bin/bash shebang to the beginning:

let "MYVAR += 1"
echo $MYVAR

Now you simply get:


You can even specify something completely different:

#!/usr/bin/env python
print("I am Python now!")

I mainly use /bin/bash for my scripts. For reference, here’s a nice list of some differences between /bin/sh and /bin/bash: Appendix B Major Differences From The Bourne Shell.

Quick Note!

If you didn’t already figure this out, you need to make the script executable before being able to execute it. I simply did this:

chmod +x

Executable for everyone!

—and that’s it for now. Stay tuned for more posts around my post-install (and post-installs in general).

comments powered by Disqus