Documentation ¶
Overview ¶
Package unix contains quoting interfaces for Unix-based shells.
Example ¶
filename := `Long File With 'Single' & "Double" Quotes.txt` fmt.Println(SingleQuote.MustQuote(filename)) // Echoing inside 'sh -c' requires a quoting to make it safe with an arbitrary string quoted := SingleQuote.Quote(filename) fmt.Println([]string{ "sh", "-c", fmt.Sprintf("echo %s | callme", quoted), }) unquoted, _ := SingleQuote.Unquote(quoted) fmt.Println(unquoted)
Output: true [sh -c echo 'Long File With '"'"'Single'"'"' & "Double" Quotes.txt' | callme] Long File With 'Single' & "Double" Quotes.txt
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ANSIC quote.BinaryQuoting = ansiC{}
ANSIC quotes and unquotes strings, surrounded by single quotes with a dollar sign prefix ($'…'), as specified by Bash and Zsh (ANSI-C quoting).
For example, the following string:
a b:"c d" 'e''f' "g\""
Would be quoted as:
$'a b:\"c d\" \'e\'\'f\' \"g\\\"\"'
See https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html for details.
var DoubleQuote quote.Quoting = doubleQuote{}
DoubleQuote quotes and unquotes strings, surrounded by double quotes (") as specified by POSIX.
For example, the following string:
a b:"c d" 'e''f' "g\""
Would be quoted as:
"a b:\"c d\" 'e''f' \"g\\\"\""
See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_03 for details.
var SingleQuote quote.Quoting = singleQuote{}
SingleQuote quotes and unquotes strings, surrounded by single quotes (') as specified by POSIX.
For example, the following string:
a b:"c d" 'e''f' "g\""
Would be quoted as:
'a b:"c d" '"'"'e'"'"''"'"'f'"'"' "g\""'
See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02 for details.
Functions ¶
This section is empty.
Types ¶
This section is empty.