#!/bin/bash
selectdir() {
# get directory list and convert it to an array
dir_list=($(ls -d $1/* | awk '{ print $1 }'))
selection=$(whiptail --title "Folder Selection" --menu "Select a folder:" 14 40 6 \
`for index in ${!dir_list[*]}; do printf "%d %s " $index ${dir_list[$index]}; done` \
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo ${dir_list[$selection]}
fi
}
path=$(selectdir $PWD)
echo "selected path = "$path