def shell_add_echo(script):
  """Goes over each line script, adds "echo cmd" in front of each cmd.

  ls a

  becomes

  echo * ls a
  ls a
  """
  new_script = ""
  for cmd in script.split('\n'):
    cmd = cmd.strip()
    if not cmd:
      continue
    new_script += "echo \\* " + shlex.quote(cmd) + "\n"
    new_script += cmd + "\n"
  return new_script
def shell_add_echo ( script ) : new_script = "" for cmd in script . split ( '\n' ) : cmd = cmd . strip ( ) if not cmd : continue new_script += "echo \\* " + shlex . quote ( cmd ) + "\n" new_script += cmd + "\n" return new_script
Goes over each line script, adds "echo cmd" in front of each cmd.

  ls a

  becomes

  echo * ls a
  ls a