https://github.com/depp/shellquote
Go library for quoting strings for a Posix shell
https://github.com/depp/shellquote
Last synced: about 1 year ago
JSON representation
Go library for quoting strings for a Posix shell
- Host: GitHub
- URL: https://github.com/depp/shellquote
- Owner: depp
- License: mit
- Created: 2020-10-19T01:31:55.000Z (over 5 years ago)
- Default Branch: trunk
- Last Pushed: 2021-04-16T00:59:00.000Z (about 5 years ago)
- Last Synced: 2025-01-27T11:46:07.975Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ShellQuote
ShellQuote is a Go library that quotes strings so they can be used by a POSIX shell.
## Installation
ShellQuote can be installed with `go get`.
```shell
go get github.com/depp/shellquote
```
## Usage
```go
import "github.com/depp/shellquote"
```
To quote a string, call `String()`. This adds quotes only as necessary. For example,
```go
// Prints x without quotes, because no quotes are needed.
fmt.Println(shellquote.String("x"))
// Prints '$x' with quotes.
fmt.Println(shellquote.String("$x"))
```
Another useful function is `LocalPath()`, which modifies a path so it is not misinterpreted as a flag.
```go
// Prints abc, because abc does not look like a flag.
fmt.Println(shellquote.LocalPath("abc"))
// Prints ./-h, because -t looks like a flag.
fmt.Println(shellquote.LocalPath("-h"))
```
## Limitations
Non-ASCII characters are not supported.
## License
This is licensed under the MIT license. See LICENSE.txt.