Read from both STDIN and named files
[project-aon.git] / common / scripts / list-bookcodes-by-subseries.sh
1 #!/usr/bin/env bash
2 #
3 # List all bookcodes that match given subseries.
4
5 # Example:
6 #     list-bookcodes-by-subseries.sh lw gs
7
8 if [ ! -d "$AONDIR" ]; then
9     >&2 echo "Please set the AONDIR environment variable"
10     exit 1
11 fi
12
13 book_db="$AONDIR/common/sqlite/bookcodes.db"
14
15 for subseries in $@
16 do
17     if [[ ! $subseries =~ ^[a-z]+$ ]]; then
18         >&2 echo "invalid subseries"
19         exit 1
20     fi
21
22     sqlite3 -noheader "$book_db" <<EOF
23       select book 
24       from bookcodes 
25       where subseries = '$subseries'
26       order by book
27 EOF
28 done