public static String escapeQuotedSwitch(String value){
  return value.replaceAll("'","'\"'\"'");
}

public static String escapeQuotedSwitch ( String value ) { return value . replaceAll ( "'" , "'\"'\"'" ) ; }
escape quotes in the value that can cause the shell problems ( and prevent injection ) this doesn ' t escape spaces as it is assumed that the value will be wrapped in quotes this escaping is bash specific - might not work with other shells the way to escape a single quote inside single quotes in bash is by gluing a double - quoted single quote to the single quoted expression
