Skip to content

Quoting Functions

🛠️ Tools · ⬅ Home


Usage

quoteBashString text

Quote bash strings for inclusion as single-quoted for eval

Arguments

  • text - EmptyString. Required. 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

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

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

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

Usage

escapeDoubleQuotes [ text ]

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

Arguments

  • text - String. Optional. 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

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

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

Usage

sedReplacePattern searchPattern replacePattern

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

Arguments

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

Return codes

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

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

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