commands in /bin/sh like printf are slow

In our makefiles, we call shell commands like printf. Makefiles are internally executing that command through /bin/sh like /bin/sh -c printf hi. In my newly installed solaris machine, I have observed that some commands [printf] are running very slow. Then, I have seen the main reason as printf is not built-in function in the shell. But, in /bin/bash, it is built-in. The same command is running very fast in bash. As I know, /bin/bash [BASH] is advanced than /bin/sh [Bourne shell]. So, I have created a soft link from /bin/bash to /bin/sh. Now, whenever I execute /bin/sh, automatically bash will be executed. As of now, I did not get any problem with this approach and it seems bash has many built-in commands and fast.

3 Comments

  1. zzz said,

    December 5, 2007 at 11:04 am

    I think the reason is, that sh uses static linking, and bash dynamic.
    So when coming to performance, bash is generaly faster.

    However, when you wont be able link stuff for your shell (ie. some system partition would be lost), you would definitely want to use sh :-)

  2. Benjamin Sergeant said,

    February 19, 2008 at 4:24 am

    You should be careful when doing such things, you might have problems at next boot. Instead you should tell make to use bash to do his shell operations.

  3. tombarta said,

    August 6, 2008 at 6:18 am

    Agree with Ben. Add this to your Makefile to ensure that it uses bash instead of the user’s shell (whatever that may be):

    SHELL = /bin/bash

    I think this is good practice anyhow, because different systems may have very surprising interpretations. For example, on some ubuntu boxes I have run across, ‘echo -e …’ produces a different result from ‘/bin/echo -e …’ when using the default shell. Plus, sooner or later, some developer will decide to use a different shell, and unless the Makefile specifies its own shell, it will inherit the user’s environment and break all over itself when it encounters bash-specific syntax.


Post a Comment