# random colour xterm alias

**URL:** <https://community.unix.com/t/random-colour-xterm-alias/227073>\
**Category:** Shell Programming and Scripting\
**Created:** [January 9, 2009, 6:16am UTC](https://community.unix.com/t/random-colour-xterm-alias/227073 "2009-01-09T06:16:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcadia](https://community.unix.com/letter_avatar/arcadia/32/5_5575768a8748004e209b776fc1b2916d.png) [@arcadia](https://community.unix.com/u/arcadia)\
**Post date:** [January 9, 2009, 6:16am UTC](https://community.unix.com/t/random-colour-xterm-alias/227073/1 "2009-01-09T06:16:46Z")

</div>

I used to have this but do not know where it went - a script or an alias that:

opens a new xterm window with a random background colour.

I have this off "the internets" :  
alias xterm1="xterm ... -bg \#\* printf '%02x%02x%02x' {repeat 3 times $((RANDOM%128+128))}` &"

this gives me an alias: xterm1='xterm .. -bg \#8beaf7 &'  
..which kind of works, but it's not elegant and it means that the window colouring is only random recursively.

any of you have a "better" version of this?

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [January 9, 2009, 1:58pm UTC](https://community.unix.com/t/random-colour-xterm-alias/227073/2 "2009-01-09T13:58:06Z")

</div>

Put this in a script or a function:

```nohighlight
n=200 ## adjust to taste: higher value, lighter background
n1=$(( 256 - $n ))
bg=$( printf "#%x%x%x\n" $(( $RANDOM % $n1 + $n )) \
                         $(( $RANDOM % $n1 + $n )) \
                         $(( $RANDOM % $n1 + $n )) )
xterm -bg "$bg" &

```

---

<div class="post-metadata">

**Author:** ![arcadia](https://community.unix.com/letter_avatar/arcadia/32/5_5575768a8748004e209b776fc1b2916d.png) [@arcadia](https://community.unix.com/u/arcadia)\
**Post date:** [January 12, 2009, 9:57am UTC](https://community.unix.com/t/random-colour-xterm-alias/227073/3 "2009-01-12T09:57:28Z")

</div>

works like a charm - thanks.
