unix

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2023 License: BSD-3-Clause Imports: 7 Imported by: 3

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

View Source
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.

View Source
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.

View Source
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL