code: def sh(cmd):
      
  
      # Figure out what local variables are defined in the calling scope.
  
      import inspect
      frame = inspect.currentframe()
      try: locals = frame.f_back.f_locals
      finally: del frame
  
      # Run the given command in a shell.  Return everything written to stdout if
      # the command returns an error code of 0, otherwise raise an exception.
  
      from subprocess import Popen, PIPE, CalledProcessError
      process = Popen(cmd.format(**locals), shell=True, stdout=PIPE)
      stdout, unused_stderr = process.communicate()
      retcode = process.poll()
      if retcode:
          error = subprocess.CalledProcessError(retcode, cmd)
          error.output = stdout
          raise error
      return stdout.strip()
docs: Run the given command in a shell.
  
      The command should be a single string containing a shell command.  If the
      command contains the names of any local variables enclosed in braces, the
      actual values of the named variables will be filled in.  (Note that this
      works on variables defined in the calling scope, which is a little bit
      magical.)  Regular braces must be escaped as you would with str.format().
      Also be aware that this approach is vulnerable to shell injection attacks.