Bash track: with or without commands?

Hello,

I just started the Bash-Track to deepen my knowledge about Bash-Programming. The exercise Hamming raises a question: For-Loop or cmp?

I used the command cmp as my first solution. Simply because my problem solving thinking was: “I only need the number of different chars”. But then I saw the community sollution most of them used a for-loop.

How is the Bash-Track intended to be used?

For me, tools like cmp are part of the standard Bash-Environment. Like the Standard-Library in other programming languages.

Kindly Regards

1 Like

That is an excellent question. And your observation of “tools like cmp are part of the standard … environment” is accurate.

Bash is used to “glue” many things together, not just the Bash environment. And so, if it is definitely a solid solution to use tools like this.

If you want to use the track with the discipline “nothing external” except for the language itself, we have been careful, so far, to let that happen. If there are tools available in the environment to solve the problem, that exploration is just as valid.

Indeed, we start to appreciate the tools that follow the Unix Way, which is “A tool does one thing, and that one thing well.” along with the idea that the output of that tooling is often most helpful when it can be piped, used for another tool in a chain of commands.

I would even go further and say that For-Loop or cmp is not the only option. Why not uniq as a tool? There are others!

Hello!

I typically encourage people to try to solve the bash exercises using only bash builtins and the bash language so they can learn the bash language. In my mind, the bash track is about learning the bash language, and is not set up as a Linux shell script track. If you interpret it as the latter, you can solve most exercises entirely using other standard environment languages (assuming they are installed on the container), like awk, jq, Python, etc, all of which have their own tracks!

Note, some few exercises do require external tools (Dart uses float values) which do require some external tools. But they are few and far between.

Hello,

yes, I think, to really learn Bash-Scripting it’s useful to stick to Bash-Builtins.
So, I will go this path.

And after that I go to the next part: Process Substituation and things like that. :slight_smile:

Thank you very much for your response.

You could do both: solve the exercise using the external tools, then do it again using only bash.

There is definitely no reason not to have both in any of the exercises you do. Iterations are nice for this.

Here’s an example: glennj's solution for Atbash Cipher in Bash on Exercism

2 Likes