4 comments

[ 5.1 ms ] story [ 21.3 ms ] thread
I rewrote all my shell scripts to typescript+node.js. I enjoy type safety and good dev tools.

Ever since, I wonder why long shell scripts are needed. Why do some developers still write programs like these? What advantages shell have?

I’m with you in trying to avoid shell scripts. That said, shell scripts are especially convenient for simple glue scripts. No external dependencies and shell will run basically anywhere. Long isn’t necessarily bad for pipelines but anything over 100 lines is suspect.
Startup times might be important for you. For example it can take tens to hundred milliseconds to start a python 3 interpreter. This effect becomes even more noticeable when you have to do it multiple times, by chaining multiple scripts together.

You can avoid the slow startup by using languages that are able to generate small compiled binary, but then you wouldn't call it a script, because you have to recompile for every change.

Then there are other approaches like xonsh, where you (roughly speaking) replace bash or zsh with a python interpreter. Now you don't have to start the interpreter over and over again, because your shell is python. I think it's an interesting approach, but you have to like python and you will hardly find xonsh on any remote machine, so you are probably still confronted with bash and the like.

Yup! I'm write such ones.

Working on embedded systems with low resources. This is easiest to prototype something.