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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.