3

I assume it is because of the interpreter's implementation. Can anyone give me a more in-depth answer please? Thanks.

Also, I wonder if bash has a garbage collector?

  • While that question is surely valid to ask, keep in mind that the languages have/had different goals. Also see this [SO question](http://stackoverflow.com/q/3637668/21567). – Christian.K Aug 26 '11 at 06:26
  • 1
    Slower in what circumstances exactly? IMHO the question is not very well-defined. While I have a hunch that it may indeed be true, some timing data and/or an example task would give us something to work with. – tripleee Aug 26 '11 at 06:41

1 Answers1

4

bash loads a large number of commands from disk. Most other scripting languages have many more instructions that they run internally.

For example, to do a simple computation in bash, you'd use a=`expr 1 + 2` and bash will first load /usr/bin/expr, run that command which writes the result in the output, bash collects the output (the ` quotes) and saves the result in the variable 'a'. That's definitively slow.

The advantage of bash is the incredible flexibility though. Each person may have a different set of powerful "instructions". For example, I have a small tool called hex to print out numbers in octal, hexadecimal and decimal all at once. Other languages would not integrate in the way bash does...

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • 1
    Bash is also largely dependent on the programs it uses. Something like `find . -type f -print0 | parallel -0 fgrep -I -f foo.txt` would run pretty quickly in Bash, whereas the equivalent would be very difficult in Ruby or Python and probably wouldn't work as quickly. – Swiss Aug 26 '11 at 06:30
  • A lot of it depends on how you use it. `let a=1+2` and there's no need for calling `expr`. https://gist.github.com/bf55669850447fbe783e – Michael Kohl Aug 26 '11 at 06:53