#!/bin/bash
# core/str - Bash Script String Support

set -e


######
# String Support

# str_here_var() - Reads standard input into the named variable ($1).
# $1 - Name of variable to receive ``stdin`` as a string.
str_here_var() { read -r -d '' $1; }

# str_trim() - Trims whitespaces from start and end of a string ($1).
str_trim() {
	local str=$1
	shopt -s extglob
	str=${1%%+([[:space:]])}
	str=${1##+([[:space:]])}
	shopt -u extglob
	echo "$str"
}

# str_endswith() - Returns success if a string ($1) ends with
# another string ($2).
str_endswith() { [ "${1%$2}" != "$1" ]; }

# str_startswith() - Returns success if a string ($1) start with
# another string ($2).
str_startswith() { [ "${1#$2}" != "$1" ]; }

View the Developer Guide Index

View the Reference Manual Index


Generated on Thu May 4 18:59:27 PDT 2017 by mcsh i7 v0.19.0.