Ordinal Suffix

Add an ordinal suffix to a number, returning formats like 1st, 2nd, 3rd, 4th.

Code

General
v=$((num % 100))
if [ $v -ge 11 ] && [ $v -le 13 ]; then echo "${num}th"
elif [ $((num % 10)) -eq 1 ]; then echo "${num}st"
elif [ $((num % 10)) -eq 2 ]; then echo "${num}nd"
elif [ $((num % 10)) -eq 3 ]; then echo "${num}rd"
else echo "${num}th"; fi

Parameters

The number to add suffix to

Server

More Bash Snippets