shellquote

package
v0.0.0-...-325f451 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package shellquote quotes strings for shell scripts.

Sometimes you get strings from the internet and need to quote them for security, other times you'll need to quote your own strings because doing it by hand is just too much work.

Another option is http://github.com/kballard/go-shellquote. The quoting algorithms are completely different and the results vary as well, but both produce working results in my brief testing. See https://github.com/frioux/go-scraps/tree/master/cmd/quotetest for a tool that shows the results of quoting with each package.

Example
package main

import (
	"fmt"
	"os"

	"github.com/frioux/leatherman/pkg/shellquote"
)

func main() {
	fmt.Println("#!/bin/sh")
	fmt.Println("")
	quoted, err := shellquote.Quote(os.Args[1:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't quote input: %s\n", err)
		os.Exit(1)
	}
	// error won't happen if the first input didn't error
	doublequoted, _ := shellquote.Quote([]string{quoted})
	fmt.Println("ssh superserver", doublequoted)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNull = errors.New("No way to quote string containing null bytes")

ErrNull will be returned from Quote if any of the strings contains a null byte.

Functions

func Quote

func Quote(in []string) (string, error)

Quote will return a shell quoted string for the passed tokens.

Types

This section is empty.

Jump to

Keyboard shortcuts

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