def sh_string(s):
 if ('\x00' in s):
  log.error('sh_string(): Cannot create a null-byte')
 chars = set(s)
 very_good = set(((string.ascii_letters + string.digits) + '_+.,/'))
 if (chars <= very_good):
  return s
 if (not (chars & set(ESCAPED))):
  return ("'%s'" % s)
 quoted_string = ''
 quoted = False
 for char in s:
  if (char not in ESCAPED):
   if (not quoted):
    quoted_string += SINGLE_QUOTE
    quoted = True
   quoted_string += char
  else:
   if quoted:
    quoted = False
    quoted_string += SINGLE_QUOTE
   quoted_string += ESCAPED[char]
 if quoted:
  quoted_string += SINGLE_QUOTE
 return quoted_string

def sh_string ( s ) : if ( '\x00' in s ) : log . error ( 'sh_string(): Cannot create a null-byte' ) chars = set ( s ) very_good = set ( ( ( string . ascii_letters + string . digits ) + '_+.,/' ) ) if ( chars <= very_good ) : return s if ( not ( chars & set ( ESCAPED ) ) ) : return ( "'%s'" % s ) quoted_string = '' quoted = False for char in s : if ( char not in ESCAPED ) : if ( not quoted ) : quoted_string += SINGLE_QUOTE quoted = True quoted_string += char else : if quoted : quoted = False quoted_string += SINGLE_QUOTE quoted_string += ESCAPED [ char ] if quoted : quoted_string += SINGLE_QUOTE return quoted_string
outputs a string in a format that will be understood by /bin/sh .