Storing other language output to Bash variable

To save the output of other language code in Bash, the example is as follows:

    $ result=$(python3 -c "print(10+15)")    
  

In the preceding example code, we have embedded python3 code in bash shell. The output of the print command which addition of two numbers will be stored in a bash variable result.

If we want to print the output of embedded language code directly on screen, then the example code is as follows:

    $ python3 -c "print(Hello World)"
  

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.