Prefix suffix
str_remove_prefix¶
Remove a prefix from a string. If the string does not start with the prefix, the original string is returned unchanged.
Example¶
str_remove_prefix "foobar" "foo" # => bar
str_remove_prefix "foobar" "baz" # => foobar
Arguments¶
- $1 (string): The string to process
- $2 (string): The prefix to remove
Exit codes¶
- 0: Always
Output on stdout¶
- String with prefix removed
str_remove_suffix¶
Remove a suffix from a string. If the string does not end with the suffix, the original string is returned unchanged.
Example¶
str_remove_suffix "foobar" "bar" # => foo
str_remove_suffix "foobar" "baz" # => foobar
Arguments¶
- $1 (string): The string to process
- $2 (string): The suffix to remove
Exit codes¶
- 0: Always
Output on stdout¶
- String with suffix removed
str_append_if_missing¶
Append a suffix to a string if the string does not already end with that suffix.
Example¶
str_append_if_missing "/etc/hosts" "s" # => /etc/hostss
str_append_if_missing "/etc/hosts" "/" # => /etc/hosts/
str_append_if_missing "/etc/hosts/" "/" # => /etc/hosts/
Arguments¶
- $1 (string): The string to process
- $2 (string): The suffix to append if missing
Exit codes¶
- 0: Always
Output on stdout¶
- String with suffix appended if it was missing
str_prepend_if_missing¶
Prepend a prefix to a string if the string does not already start with that prefix.
Example¶
str_prepend_if_missing "etc/hosts" "/" # => /etc/hosts
str_prepend_if_missing "/etc/hosts" "/" # => /etc/hosts
Arguments¶
- $1 (string): The string to process
- $2 (string): The prefix to prepend if missing
Exit codes¶
- 0: Always
Output on stdout¶
- String with prefix prepended if it was missing
str_append¶
Append one string to another and print the result. Optionally define a delimiter with -d|--delimiter (defaults to a single space).
Example¶
str_append -d ':' foo bar # => foo:bar
str_append foo bar # => foo bar
Arguments¶
- $1 (string): Optional: -d|--delimiter followed by delimiter string
- $2 (string): First string
- $3 (string): Second string to append
Exit codes¶
- 0: Always
Output on stdout¶
- Concatenated string
append¶
Alias for str_append.
str_prepend¶
Prepend one string to another and print the result. Optionally define a delimiter with -d|--delimiter (defaults to a single space).
Example¶
str_prepend -d ':' bar foo # => bar:foo
str_prepend bar foo # => bar foo
Arguments¶
- $1 (string): Optional: -d|--delimiter followed by delimiter string
- $2 (string): The string to prepend
- $3 (string): The string to prepend to
Exit codes¶
- 0: Always
Output on stdout¶
- Concatenated string
prepend¶
Prepend a string to each line of stdin. Optionally define a delimiter with -d|--delimiter (defaults to a single space).
Arguments¶
- $1 (string): Optional: -d|--delimiter followed by delimiter string
- $2 (string): The string to prepend to each line
Exit codes¶
- 0: Always
Output on stdout¶
- Each stdin line prefixed with the given string and delimiter