Pls. help me recreate shell trick

Fernando Pérez fperez528 at
Thu Nov 22 18:06:04 CET 2001

Daniel Dittmar wrote:

>> This was achieved as follows:
>> $ECHO rm -r /
>> where ECHO was either set to "echo" or nothing according to a command

Another option:

import os

def xsys(cmd,verbose=0,debug=0,head=''):
    """Execute a system command, but optionally print it.
    With debug=1, only prints."""

    stat = 0
    if verbose or debug: print head+cmd
    if not debug: stat = os.system(cmd)
    return stat



More information about the Python-list mailing list