#!/usr/bin/python
import os
import shutil
import commands
import time
import copy
name = 'test'
echo name
I have a simple python scripts like the above. When I attempt to execute it I get a syntax error when trying to output the name variable.
You cannot use UNIX commands in your Python script as if they were Python code,
echo nameis causing a syntax error becauseechois not a built-in statement or function in Python. Instead, useprint name.To run UNIX commands you will need to create a subprocess that runs the command. The simplest way to do this is using
os.system(), but thesubprocessmodule is preferable.