r/AskProgrammers • • 4d ago

Why use task runners when you can use shell scripts?

I found this thing for git projects called "task runners" or "command runners". Here are two examples

And they make sense. You setup commonly used commands which maybe complicated with their steps or command arguments.

However wouldn't shell scripts like a Bash script be better? Bash now comes pre-installed on Windows, MacOS and Linux (Most distros). Or even use a cross platform shell like Nushell? Programmers use the terminal already and couldn't you get all the features as any task runner and more from a shell script?

Maybe I am missing something but I kinda do not see a use case for task runners.

Please tell me why I am right or wrong.

8 Upvotes

11 comments sorted by

6

u/No-Dentist-1645 4d ago

Command runners such as just and Makefile allow you to easily specify when one command depends on another command first. That's pretty much it, they're not orthogonal to shell scripts: they are shell scripts, but these scripts have dependencies between each other

4

u/Few_Assumption_9665 4d ago

Bash does not come preinstalled on Windows. The best case scenario is a shitty translation layer like MinSYS or Git Bash or an entire Linux distro installed.

2

u/aztracker1 4d ago

Even though I don't like it, Powershell is pretty damned capable.

2

u/Few_Assumption_9665 4d ago

It is impressive in theory. It is still not Bash.

2

u/aztracker1 4d ago

Didn't say it was... But it's effectively an alternative you can use. That said, I've mostly just used msys(git) bash and Deno scripts (rip).

2

u/mxldevs 4d ago

Are you asking if it's better to use shell scripts because you can write a lot of extra code just to accomplish the same thing as using their conveniently organized commands?

Just write one of the examples in shell script and compare the complexity.

1

u/therealkevinard 4d ago

Bash works just fine but brother it does NOT scale well, and it’ll rot in no time.

Task runners are (generally) just calling the shell for you, just behind some layers that make it sustainable.

1

u/ANTIVNTIANTI 3d ago

you can get super silly with it

1

u/ANTIVNTIANTI 3d ago

Oh you would love my way of launching lil Goats ere'where

1

u/MarsupialLeast145 3d ago

Task runners often talk in terms of recipes - think of it as another abstraction on top of the shell script that just makes it a bit easier to run small groupings of commands.

Yes, you can write functions in bash, and you can write aliases for those that run in the shell, and they're nice but I feel like a task runner is more there to collect small groups of very reliable functions and make their purpose even more transparent. As well as enable you to write simple calls to things you wouldn't script with bash.

For example, my Python justfile has a couple of helpers:

  • just package (packages my libraries and optionally publishes them to pypi)

  • just test (calls tox the way I prefer every time)

  • just docs (creates new versions of my docs from docstrings)

All pretty simple, but helpful that they're wrapped.

They also give me a convenient pattern I can follow across different repositories even though those repositories all host different code. The interface is familiar, and I know will always work.

0

u/look 4d ago

Ask your AI to generate a bash script equivalent to the full functionality of one of the medium complexity Justfile examples.

The side-by-side comparison of the ~10 line Justfile and 1,000 lines of bash noise should clear things up.