This is part five of a series on how to approach bash programming in a way that’s safer and more structured than your basic script.
See part 1 if you want to catch the series from the start.
Last time, we created a failing test. We’ll work on making it work now, but I’m going to jump straight to the structure that a project with tests should take.
The project will be a hello, world! script, so let’s start with:
The hello_world function exists, but does nothing.
hello-world_shpec.bash to the
hello-world_shpec.bash in an editor and add the following to the
That finds the true location of the
readlink, then trims off the filename from the path. It then adds the
relative path to our
hello-world source file.
Note that on Mac, you’ll need to install GNU readlink via homebrew, then
greadlink instead of the
Shpec now outputs the following:
Still failing. Excellent!
At this point, all we need to do is update the hello_world function:
Continue with part 6 - outline script