github.com/stevenmatthewt/agent@v3.5.4+incompatible/bootstrap/shell/batch.go (about)

     1  package shell
     2  
     3  import "strings"
     4  
     5  // BatchEscape escapes a string for use with an `ECHO` statement in a Windows Batch file.
     6  // http://www.robvanderwoude.com/escapechars.php
     7  func BatchEscape(str string) string {
     8  	str = strings.Replace(str, "%", "%%", -1)
     9  	str = strings.Replace(str, "^", "^^", -1)
    10  	str = strings.Replace(str, "^", "^^", -1)
    11  	str = strings.Replace(str, "&", "^&", -1)
    12  	str = strings.Replace(str, "<", "^<", -1)
    13  	str = strings.Replace(str, ">", "^>", -1)
    14  	str = strings.Replace(str, "|", "^|", -1)
    15  
    16  	return str
    17  }