annotate bin/roll @ 7759:b4341511eb47

<fizzie> ` echo -e \'#! /bin/bash\\ncmd="$1"\\nshift\\nf="$*"\\nif [ -z "$f" && "$f" == *\\\\ * ]; then f="${cmd#* }"; cmd="${cmd%% *}"; fi\\nif [ -z "$f" ]; then echo try: \\\\`f command filename; else "$cmd" "$(< "$f")"; fi\' > bin/f
author HackBot
date Wed, 04 May 2016 21:35:48 +0000
parents e037173e0012
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e037173e0012 Initial import.
HackBot
parents:
diff changeset
1 #!/bin/bash
e037173e0012 Initial import.
HackBot
parents:
diff changeset
2 rolls="$*"
e037173e0012 Initial import.
HackBot
parents:
diff changeset
3 if [ "$rolls" = "" ] ; then rolls="1d6" ; fi
e037173e0012 Initial import.
HackBot
parents:
diff changeset
4
e037173e0012 Initial import.
HackBot
parents:
diff changeset
5 for i in $rolls
e037173e0012 Initial import.
HackBot
parents:
diff changeset
6 do
e037173e0012 Initial import.
HackBot
parents:
diff changeset
7 if expr "$i" : ".*[dD].*" >& /dev/null
e037173e0012 Initial import.
HackBot
parents:
diff changeset
8 then
e037173e0012 Initial import.
HackBot
parents:
diff changeset
9 rollc=`echo "$i" | sed 's/[dD].*//'`
e037173e0012 Initial import.
HackBot
parents:
diff changeset
10 diesz=`echo "$i" | sed 's/.*[dD]//'`
e037173e0012 Initial import.
HackBot
parents:
diff changeset
11 else
e037173e0012 Initial import.
HackBot
parents:
diff changeset
12 rollc=1
e037173e0012 Initial import.
HackBot
parents:
diff changeset
13 diesz="$i"
e037173e0012 Initial import.
HackBot
parents:
diff changeset
14 fi
e037173e0012 Initial import.
HackBot
parents:
diff changeset
15
e037173e0012 Initial import.
HackBot
parents:
diff changeset
16 roll=0
e037173e0012 Initial import.
HackBot
parents:
diff changeset
17 for (( j = 0; $j < $rollc; j++ ))
e037173e0012 Initial import.
HackBot
parents:
diff changeset
18 do
e037173e0012 Initial import.
HackBot
parents:
diff changeset
19 roll=$(( roll + (RANDOM % diesz) + 1 ))
e037173e0012 Initial import.
HackBot
parents:
diff changeset
20 done
e037173e0012 Initial import.
HackBot
parents:
diff changeset
21
e037173e0012 Initial import.
HackBot
parents:
diff changeset
22 echo -n $roll' '
e037173e0012 Initial import.
HackBot
parents:
diff changeset
23 done
e037173e0012 Initial import.
HackBot
parents:
diff changeset
24 echo