Debian Codegraph @

agram2.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # agram2.sh
3 # Example of nested command substitution.
4
5 # Uses "anagram" utility
6 #+ that is part of the author's "yawl" word list package.
7 # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz
8 # http://bash.deta.in/yawl-0.3.2.tar.gz
9
10 E_NOARGS=86
11 E_BADARG=87
12 MINLEN=7
13
14 if [scip-shell system . . `[`. -z "$1" ]
15 then
16 echoscip-shell system . . echo. "Usage $0 LETTERSET"
17 exit $E_NOARGS # Script needs a command-line argument.
18 elif [scip-shell system . . `[`. ${#1} -lt $MINLEN ]
19 then
20 echoscip-shell system . . echo. "Argument must have at least $MINLEN letters."
21 exit $E_BADARG
22 fi
23
24
25
26 FILTER='.......' # Must have at least 7 letters.
27 # 1234567
28 Anagrams=( $(echscip-shell system . . echo.o $(anagram $1 | grescip-shell system . . grep.p $FILTER) ) )
29 # $( $( nested command sub. ) )
30 # ( array assignment )
31
32 echoscip-shell system . . echo.
33 echoscip-shell system . . echo. "${#Anagrams[*]} 7+ letter anagrams found"
34 echoscip-shell system . . echo.
35 echoscip-shell system . . echo. ${Anagrams[0]} # First anagram.
36 echoscip-shell system . . echo. ${Anagrams[1]} # Second anagram.
37 # Etc.
38
39 # echo "${Anagrams[*]}" # To list all the anagrams in a single line . . .
40
41 # Look ahead to the Arrays chapter for enlightenment on
42 #+ what's going on here.
43
44 # See also the agram.sh script for an exercise in anagram finding.
45
46 exit $?