Len

str_len

Return the character length of a string, file, or piped input. With -b/--bytes, returns the byte length instead of character length. With a file argument, prints length and content for each line. With no arguments and no stdin, prints 0.

Arguments

  • $1 (string): Optional: -b|--bytes for byte length, or a string/file path

Exit codes

  • 0: Always

Output on stdout

  • Length (and optionally content) of the input

strlen

Alias for str_len.

len

Alias for str_len.

str_count

Count the number of non-overlapping occurrences of a substring within a string.

Example

str_count "banana" "an"   # => 2
str_count "hello" "l"     # => 2

Arguments

  • $1 (string): The string to search within
  • $2 (string): The substring to count

Exit codes

  • 0: Always

Output on stdout

  • Integer count of occurrences

str_word_count

Count the number of words in a string (split on whitespace).

Example

str_word_count "hello world foo"   # => 3
str_word_count "  spaced  out  "   # => 2

Arguments

  • ... (string): The string to count words in

Exit codes

  • 0: Always

Output on stdout

  • Integer word count