File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ function die() { echo -e " $@ " 1>&2 ; exit 1; }
4
+
5
+ if [ " x$1 " == " x" ]
6
+ then
7
+ die " Need a filename for input."
8
+ fi
9
+
10
+ MAGICFILE=$1
11
+ MAGICBASE=` basename $MAGICFILE `
12
+ INDEXFILE=" /var/tmp/.lrscramble.$MAGICBASE "
13
+
14
+ if ! [ -e $MAGICFILE ]
15
+ then
16
+ die " No such file."
17
+ fi
18
+
19
+
20
+ LENTH=` wc -l $MAGICFILE | cut -d\ -f1`
21
+
22
+ function reshuffle() {
23
+ for I in $( seq 1 $LENTH )
24
+ do
25
+ linez=( " ${linez[@]} " $I )
26
+ done
27
+ linez=($( shuf -e " ${linez[@]} " ) )
28
+ printf " %s\n" " ${linez[@]} " > $INDEXFILE
29
+ }
30
+
31
+ [ -e $INDEXFILE ] || reshuffle
32
+ NUMLINES=` wc -l $INDEXFILE | cut -d\ -f1`
33
+ NUMCHARS=` wc -c $INDEXFILE | cut -d\ -f1`
34
+ if [[ $NUMLINES -lt 1 ]] || [[ $NUMCHARS -lt 2 ]]
35
+ then
36
+ echo " Last invocation. Starting over."
37
+ reshuffle
38
+ fi
39
+
40
+ function nextnumber() {
41
+ readarray -t scrambles < $INDEXFILE
42
+ printf " %s\n" " ${scrambles[0]} "
43
+ scrambles=(" ${scrambles[@]: 1} " )
44
+ printf " %s\n" " ${scrambles[@]} " > $INDEXFILE
45
+ }
46
+
47
+ function pline() {
48
+ head -$1 $MAGICFILE | tail -1
49
+ }
50
+
51
+ pline ` nextnumber`
You can’t perform that action at this time.
0 commit comments