Question : Bash - Shell Scripting Menu Help - Text Menu --> Visual Menu

I've got the following text menu below (in the code snippet) that creates menu entries based on a std unix file based in this format:
SITE1:DNS1:DNS2:TIMEZONE
SITE2:DNS1:DNS2:TIMEZONE

If possible I wanted to convert it to a more visual menu. Below is a static version of what I'm looking for, I just want the menu entries to be writen dynamicaly. Not sure if this is possible?

prompt_site() {
  TMP=$(mktemp /tmp/domainmenu.XXXXXX)
  trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
  $DIA --backtitle "Blah" --title  \
  "Domain" --menu "Select a site option." \
  0 0 0 $DIA_ESC \
  "1.Site1" \
  "2.Site2" \
  2> $TMP
  answer_site="$(cat $TMP)"
  [ -f "$TMP" ] && rm -f $TMP
case "$answer_site" in
  1.Site1)
      site="SITE1"; dns1=DNS1; dns2=DNS2; TZ=TIMEZONE; ;;
  2.Site2)
      site="SITE2"; dns1=DNS1; dns2=DNS2; TZ=TIMEZONE; ;;
  *)
      prompt_site;;
esac
}
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
prompt_location() {
file_location="${root}/filename"
iter=1
export iter
echo "Please choose a location/site:"
cat $file_location | while read line
do
    sname=`echo $line | cut -d':' -f 1`
    echo "("$iter")"  $sname
    iter=`expr $iter + 1`
done
 
echo -n "[1] "
read snum
 
max=`wc -l $file_location | cut -d ' ' -f 1`
 
if [ $snum -le $max ]
then
    myline=`cat $file_location | head -$snum | tail -1`
    site_name=`echo $myline | cut -d':' -f 1`
    site_dns1=`echo $myline | cut -d':' -f 2`
    site_dns2=`echo $myline | cut -d':' -f 3`
    site_tz=`echo $myline | cut -d':' -f 4`
	clear
else
	[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo 'Invalid selection'
	[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	prompt_location
fi
}
Open in New Window Select All

Answer : Bash - Shell Scripting Menu Help - Text Menu --> Visual Menu

OK, then maybe try to filter the selection after it's made.  Also put in a cat $TMP to see what is in the selection.  We had this almost there until we messed with how $filelist is generated, that tells me the problem is there (see the bottom of the post for a change to that).  We need to see what the --menu outputs as a selection which in turn is used to find the lines from the input file.  My guess is that it selects the entire line you select including any control characters.  Maybe try to redirect the selection out to a file and use vi to look at it - you may see the ^M character in there.  The setup of tgt_file needs to be cleaned up before the awk's for the variables.  Something like this might clean it up:

tgt_file=`cat $TMP | awk '{print $1}'`

Also when you set up $filelist it looks like you wil have "^M SITEA"  Try this instead:

filelist=`awk -F":" '{ print($1," \r")}' input`

That should give "SITEA [CR]"
Random Solutions  
 
programming4us programming4us