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

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