strtoupper()

# strtoupper() -- — Make a string uppercase
# Usage: strtoupper string
#
# Example 1:
#
# echo $(strtoupper "saya suka makan");
#
# Example 2:
#
# string="$(strtoupper "saya sukan makan")";
# echo $string;

if [ -n "${BASH_VERSINFO[0]}" ] && [ ${BASH_VERSINFO[0]} -gt 3 ]; then
	# Updated: 20-Aug-2009 - for bash version 4
	strtoupper() {
		[ $# -eq 1 ] || return 1;
		echo ${1^^};
		return 0;
	}
else
	strtoupper() {
		[ $# -eq 1 ] || return 1;
		local _str _cu _cl _x;
		_cu=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
		_cl=(a b c d e f g h i j k l m n o p q r s t u v w x y z);
		_str=$1;
		for ((_x=0;_x<${#_cl[*]};_x++)); do
			_str=${_str//${_cl[$_x]}/${_cu[$_x]}};
		done;
		echo $_str;
		return 0;
	}
fi

Leave a Reply

Your email address will not be published. Required fields are marked *