# Post your handy utility scripts!

**URL:** <https://forum.endeavouros.com/t/post-your-handy-utility-scripts/7213>\
**Category:** Community contributions\
**Created:** [August 21, 2020, 12:38pm UTC](https://forum.endeavouros.com/t/post-your-handy-utility-scripts/7213 "2020-08-21T12:38:24Z")\
**Posts on this page:** 1\
**Showing post:** 136

<div class="post-metadata">

**Author:** ![Kresimir](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/kresimir/32/73739_2.png) [@Kresimir](https://forum.endeavouros.com/u/Kresimir)\
**Post date:** [July 7, 2021, 4:09pm UTC](https://forum.endeavouros.com/t/post-your-handy-utility-scripts/7213/136 "2021-07-07T16:09:59Z")

</div>

Here is a little script that generates mixed case:

```plaintext
#!/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:

```plaintext
$ ./mixcase <<< 'Just pipe text into it and it will create mixed case!'
jUsT pIpE tExt inTo iT aNd It wiLL cReaTe miXeD cASe!

```

 ![mocking_spongebob](https://forum.endeavouros.com/uploads/default/original/3X/0/6/0666e8228c8e2fc5303b83d7b7a209596e9b8a78.jpeg)

Useful for most online interactions.

2023-08-23: Updated the script to not use `sed`, but instead use built-in Bash string manipulation techniques.

---

_[View the full topic](https://forum.endeavouros.com/t/post-your-handy-utility-scripts/7213)._
