Embedding other language codes or scripts in Bash shell scripts
There is a way to embed other language scripts or code in Bash Script. In this section, you will learn about it.
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.
The procedure to embed other language code is to call that language command itself...