Here is a little script that generates mixed case:
#!/bin/bash
# A sImPlE sCrIpt tHAt GeNErAtEs MiXed cAse FroM ItS STdIn
max_repeat=2
function coinflip() {
printf $(($RANDOM%2))
}
while read line; do
uppercase_line="${line^^}"
lowercase_line="${line,,}"
len=${#line}
flip=$(coinflip)
n=0
for ((i = 0; i < len; i++)); do
oldflip=$flip
flip=$(coinflip)
if ((flip == oldflip)); then
((n++))
fi
if ((n >= max_repeat)); then
n=0
((flip = !flip))
fi
if ((flip)); then
printf '%s' "${uppercase_line:$i:1}"
else
printf '%s' "${lowercase_line:$i:1}"
fi
done
printf '\n'
done < "${1:-/dev/stdin}"
Usage:
$ ./mixcase <<< 'Just pipe text into it and it will create mixed case!'
jUsT pIpE tExt inTo iT aNd It wiLL cReaTe miXeD cASe!
Useful for most online interactions.
2023-08-23: Updated the script to not use sed
, but instead use built-in Bash string manipulation techniques.