Skip to content

Quoting Functions

🛠️ Tools · ⬅ Top


quoteBashString

Quote bash strings for inclusion as single-quoted for eval

Usage

quoteBashString text

Quote bash strings for inclusion as single-quoted for eval

Arguments

  • text - Text to quote

Examples

name="$(quoteBashString "$name")"

Sample Output

string quoted and appropriate to assign to a value in the shell

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

quoteGrepPattern

Quote grep -e patterns for shell use

Usage

quoteGrepPattern text

Quote grep -e patterns for shell use

Without arguments, displays help.

Arguments

  • text - EmptyString. Required. Text to quote.

Examples

grep -e "$(quoteGrepPattern "$pattern")" < "$filterFile"

Sample Output

string quoted and appropriate to insert in a grep search or replacement phrase

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

printf sed

escapeQuotes

Quote strings for inclusion in shell quoted strings

Usage

escapeQuotes [ text ]

Quote strings for inclusion in shell quoted strings Without arguments, displays help.

Writes to standard output

The input text properly quoted

Arguments

  • text - Text to quote

Examples

escapeQuotes "Now I can't not include this in a bash string."

Sample Output

Single quotes are prefixed with a backslash

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

escapeSingleQuotes

Quote strings for inclusion in shell quoted strings

Usage

escapeSingleQuotes [ text ]

Quote strings for inclusion in shell quoted strings

Without arguments, displays help.

Arguments

  • text - Text to quote

Examples

escapeSingleQuotes "Now I can't not include this in a bash string."

Sample Output

Single quotes are prefixed with a backslash

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

escapeDoubleQuotes

Quote strings for inclusion in shell quoted strings

Usage

escapeSingleQuotes text

Quote strings for inclusion in shell quoted strings Without arguments, displays help.

Arguments

  • text - Text to quote

Examples

escapeDoubleQuotes "Now I can't not include this in a bash string."

Sample Output

Single quotes are prefixed with a backslash

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

escapeBash

Converts strings to shell escaped strings

Usage

escapeBash [ string ]

Converts strings to shell escaped strings

Reads standard input

text - Optional.

Writes to standard output

bash-compatible string

Arguments

  • string - String. Optional. String to convert to a bash-compatible string.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

unquote

Unquote a string

Usage

unquote quote value

Unquote a string

Arguments

  • quote - String. Required. Must match beginning and end of string.
  • value - String. Required. Value to unquote.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

sedReplacePattern

Quote a sed command for search and replace

Usage

sedReplacePattern searchPattern replacePattern

Quote a sed command for search and replace Without arguments, displays help.

Arguments

  • searchPattern - Required. String. The string to search for.
  • replacePattern - Required. String. The replacement to replace with.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

quoteSedPattern

Quote sed search strings for shell use

Usage

quoteSedPattern text

Quote a string to be used in a sed pattern on the command line.

Arguments

  • text - EmptyString. Required. Text to quote

Examples

sed "s/$(quoteSedPattern "$1")/$(quoteSedPattern "$2")/g"
needSlash=$(quoteSedPattern '$.*/[\]^')

Sample Output

string quoted and appropriate to insert in a sed search or replacement phrase

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

printf sed usageDocument __help

quoteSedReplacement

Quote sed replacement strings for shell use

Usage

quoteSedReplacement text separatorChar

Quote sed replacement strings for shell use

Arguments

  • text - EmptyString. Required. Text to quote
  • separatorChar - The character used to separate the sed pattern and replacement. Defaults to /.

Examples

sed "s/$(quoteSedPattern "$1")/$(quoteSedReplacement "$2")/g"
needSlash=$(quoteSedPattern '$.*/[\]^')

Sample Output

string quoted and appropriate to insert in a sed replacement phrase

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

printf sed usageDocument __help