0

I would like to avoid bugs/behaviors from the old versions of the bash interpreter, is there a solution to bundle a recent(like, >4.3) bash interpreter along with the script?

Buo-ren Lin
  • 133
  • 8
  • it may be easier if you use other languages like python which is much more stable than bash. – pynexj Apr 29 '20 at 08:25
  • 1
    I think there could be a way similar to the approaches in the answers [combine script and zip](https://stackoverflow.com/a/49351570/6770384) and [overwrite running script](https://stackoverflow.com/a/55730023/6770384). However, you probably have to compile bash statically linked. Also, the tools you call from inside your script (for instance `grep`, `sed`, ...) are still dependent on the user's platform even with a bundled bash. – Socowi Apr 29 '20 at 09:12

1 Answers1

0

It is a bad idea to write a script used for in a specific version of a shell. Write POSIX compliant shell scripts, it is not that difficult.

However, you can declare what interpreter is needed for the script at the top of your file with a shebang:

#!/path/to/interpreter

A common (and recommended) shebang for shell scripts is:

#!/bin/sh which links to the system shell.

If you want a particular shell, like bash, you would write: #!/bin/bash

For requiring specific versions of bash, you would need to write a check to verify the version of bash that is present.

pozix
  • 76
  • 5