Shell scripts vs. Python/Javascript scripts

Today at work, we discussed when to write a script in shell and when in a language such as Python or Javascript. I realized I enjoy writing a shell script when:

  • I integrate heavily with the system, such as creating SSH tunnels, mounting a device, or copying files around. I could do so in Python, but I would need to add boilerplate code around system commands. Or I would need to find an equivalent Python/Javascript library. In most cases, I've found vanilla shell scripts easier to write.
  • I do simple text processing over a mound of files, such as searching log files or replacing text. I feel like Usain Bolt when I pipe together commands from the powerful family of awk, sed, grep, cut, wc and the like.
  • I run a script in an environment where I have no access to another language. Unix commands are available on any unix machine, even if Python is not.

However, the more the script grows in complexity, the more cumbersome I feel when writing it in shell. I think it takes an extraordinary level of discipline and experience to make sure that a large shell script is easy to read and maintain. For that reason, I feel relieved when I can switch to Python or Javascript.

Another decision axis I find important is the team preference. Imagine the team doesn't need and doesn't want to learn shell. If I introduce shell scripts, I would be concerned that I would be the only one left to maintain the script.