Embedding other language code in Bash shell script

We may need to include other language scripts in Bash for certain reasons such as the fact that a certain complex task is already coded in another language. For example, storing the values for pi; other languages could be better at getting the precise value of pi due to their library functions. Let us assume that the user knows Lua language scripting. Then, embedding Lua language script in Bash would be undertaken as follows:

    $ export PI=$(lua -e "print(string.format('%f', math.pi))")

The preceding line will inform Bash to save the output of Lua code in variable PI. In this example, the -e option to Lua informs Lua interpreter to execute next code. The Lua code will be enclosed in quotes. ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.