How to pass python variable string to shell command

Viewed 21

I have some environment variables that are set inside my python script and I would like to pass them inside my shell command. Is this the correct approach?

import os    

    #Set environment variable
    os.environ['VERISON'] = '1.30'

    #Get environment variable
    worker_version = os.environ.get('VERSION')

    
    #Shell command

    build_worker = Popen("cd /home/ubuntu/directory && docker build -t Test:$VERSION -f docker/Dockerfile.Test .", shell=True)
    build_worker.wait()

$VERSION should be set to '1.30' but isn't working

0 Answers
Related