Bash, here-document and Python

Bash: Bourne Again SHell

bash has the ability to create a document without having to write a file to disk.  This is done through 'here-document'.  
The documentation can be found here:  https://tldp.org/LDP/abs/html/here-docs.html

The basic syntax is:

    
    [n]<<[-]DELIMITER
        here-document
    DELIMITER
    
    


The DELIMITER tells what identifier is the end of the document.  'EOF' is commonly used, as the example below.

    
#!/bin/bash

echo "Bash Start";

# Just grab the system version of 'python3', that is installed.
# We do not want to assume a specific path or version of python3.
PYTHON=$(which python3);
cat <<-EOF | $PYTHON
	print("This is a test")
EOF

echo "Bash End";
    
    
I'm not going to get into the details, as there is a lot of documentation and examples out there. Check out some of the references below. REFERENCES
here-docs documentation: https://tldp.org/LDP/abs/html/here-docs.html
Examples1: https://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-bash
Examples2: https://phoenixnap.com/kb/bash-heredoc





As always, if you have any questions, just leave a comment.

Comments

Popular posts from this blog

Linux and Logitech Unify Dongles: Part 2

Linux and Logitech Unify Dongles