Here you can find the source of prettyPrintArgv(List
public static String prettyPrintArgv(List<String> argv)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.List; public class Main { /**/*from www .j ava 2 s. c o m*/ * Characters that have no special meaning to the shell. */ private static final String SAFE_PUNCTUATION = "@%-_+:,./"; /** * Given an argv array such as might be passed to execve(2), returns a string * that can be copied and pasted into a Bourne shell for a similar effect. */ public static String prettyPrintArgv(List<String> argv) { StringBuilder buf = new StringBuilder(); for (String arg : argv) { if (buf.length() > 0) { buf.append(' '); } buf.append(shellEscape(arg)); } return buf.toString(); } /** * Quotes a word so that it can be used, without further quoting, * as an argument (or part of an argument) in a shell command. */ public static String shellEscape(String word) { int len = word.length(); if (len == 0) { // Empty string is a special case: needs to be quoted to ensure that it gets // treated as a separate argument. return "''"; } for (int ii = 0; ii < len; ii++) { char c = word.charAt(ii); // We do this positively so as to be sure we don't inadvertently forget // any unsafe characters. if (!Character.isLetterOrDigit(c) && SAFE_PUNCTUATION.indexOf(c) == -1) { // replace() actually means "replace all". return "'" + word.replace("'", "'\\''") + "'"; } } return word; } }