#!/bin/bash #set -x # uncomment the above line for shell debugging opw='password' oui='userid' x=0 od[0]='Quit' echo -n "$x) ${od[$x]} " lv=1 lows=' ' for i in `grep .WORLD $ORACLE_HOME/network/admin/tnsnames.ora | cut -d. -f1 | grep -v [_] | sort` ; do x=$(($x+1)) od[$x]=$i nbs=' ' if [ $x -le 9 ] ; then nbs=' '; fi ots="$x) $nbs ${od[$x]}" tsta=$((20-${#ots})) ots="${ots}${lows:1:$tsta}" echo -n "$ots" lv=$(($lv+1)) if [ $lv -eq 3 ]; then echo " " lv=0; fi done; echo " " y=99 j=99 while [ $y == 99 ]; do echo -n "Pick then number of the database you want to use from 0 to $x :" read j j=${j:-0} k=$( echo $j | grep [^0-9] ) k=${k:-999} if [ $k != '999' ] ; then echo "$j must be numeric"; elif [[ $j -ge 0 && $j -le $x ]] ; then y=0; fi; done if [ $j -eq 0 ] ; then exit; fi cd /home/oracle/sql sqlplus $oui/$opw@${od[$j]} @/home/oracle/sql/settings.sql