I am working on building a ncurses/dialog driven interactive shell script to Clonezilla to simplify the creation and restoration of images passed with very specific settings that we use each time. Part of the script asks the user to select an image for restoration and I have hit a wall.
I want to use a dialog radiolist for this part so that they can only select a single image file from a list of available images. I create the list of images on the fly and store it in a file called .clone_images_list
I am almost all the way there, I have everything working except that when the user selects a filename, it outputs the line number instead of the filename. I have tried everything that I can think of with no success.
Here is what I have so far:
.
#! /bin/bash COUNT=1 IMAGELIST="" while read i; do IMAGELIST="$IMAGELIST $COUNT $i off" let COUNT=COUNT+1 done < .clone_images_list dialog --backtitle "Available Image List" --radiolist "Select Image To Restore" 0 0 $COUNT $IMAGELIST 2> .tempfile IMAGEFILE=`cat .tempfile` echo $IMAGEFILE
Here is what my .clone_images_list looks like:
channel1.170822104015.img channel2.170822181523.img channel3.170822180559.img host.170822160320.img host.170822174917.img
This list can be longer or shorter and updates anytime a new image has been created.
For my script to work, I need to get the actual filename into a variable that I can use later in my script.
Looking for some ideas….
Advertisement
Answer
The radiolist widget returns the selected tag (which is the first column).
In this line
IMAGELIST="$IMAGELIST $COUNT $i off"
you are setting the tag field to a number. If you changed that to
IMAGELIST="$IMAGELIST $i $i off"
then the tag would be a filename.
If you do that, the --no-tags
option would be helpful, since otherwise the widget would display the filename twice.