Neal suggested that I wrote a how-to for easybashgui, giving the (limited) benefits of my experience with the library. This is a first stab at it. It's clearly incomplete, for (at least) two reasons:
One, I'm no bash expert and, to be frank, don't understand much of what Vittorio has written, and
Two, I've concentrated on the list function, because that's what I wanted when I stumbled upon the library in the first place.
With a bit of luck it will be of some use, and hopefully will result in some of the problems/shortcomings being solved by other users who do speak better bash than I do.
I've included two scripts, one just containing simple applications of all of the easybashgui functions referred to in the library's website, including some comments on what I found/didn't work, etc. The other script is a working (I think) implementation of the list function. Excuse the verbosity in the scripts; it's essential memory-support for me!!
Hope it helps!
#!/usr/bin/env bash
#
# This filename: ebg_howto_02 (ebg = easybashgui)
#
# library address is: /usr/local/bin/easybashgui
#
source easybashgui
#
# This is simply a collection of the options available on Vittorio's site
#+ (see http://sites.google.com/site/easybashgui/ and select 'screenshots')
#
# If you want to try these, simply copy this code into your favourite editor
#+ and save it into a (script) file, say 'ebg_howto_02' (in a directory in
#+ your $PATH). Make it executable with 'chmod +x /your/path/ebg_howto_02'.
#+ To run an easybashgui library function (e.g list, alert_message etc) just copy
#+ the relevant section of code (between the '##################' lines) to
#+ the beginning of this script (overwriting what may have been there before),
#+ and save the result. Run /your/path/ebg_howto_02.
#
# The only option that I have investigated in detail is 'list', which is
#+ described in more detail in the next script 'ebg_how_to'.
#+ Hope this helps.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
#
###########################################################################################
#
# This function works. So does output redirection (as shown), but why, is a mystery :-\
#+ However, the result is incorrect.
#
adjust "Please, set Volume level" "15" "40" "75" 2> ~/tmp/eebg_adjust01.tmp
clean_temp
exit 0
###########################################################################################
#
# This function works but I don't know how to use it.
#
for i in 10 20 30 40 50 60 70 80 90 100 ; do echo "${i}" && sleep 2 ; done | progress "This is a test progress..."
for i in 10 20 30 40 50 60 70 80 90 100 ; do echo "PROGRESS" && sleep 2 ; done | progress "This is a second test progress..." "10"
clean_temp
exit 0
###########################################################################################
#
# This function doesn't work but that's probably because I don't know how to use it.
#
wait_for "Please wait..." ; updatedb ; terminate_wait_for
clean_temp
exit 0
###########################################################################################
#
# Do NOT use this command: dselect && directory_choice="$(0< "${file_tmp}/${dir_tmp}" )"
#+ (from the web-site) because it will fail!
#+ instead, use the one below. This will still not work correctly; output redirection fails
#
dselect && directory_choice="" 2> ~/tmp/eebg_dselect01.tmp
#echo "stop" >> ~/tmp/dselect01.tmp
#dselect && directory_choice="$(0< "${dir_tmp}/${file_tmp}" )" 2> ~/tmp/dselect01.tmp
clean_temp
exit 0
###########################################################################################
#
# Do NOT use this command: fselect && file_choice="$(0< "${file_tmp}/${dir_tmp}" )"
#+ (from the web-site) because it will fail!
#+ instead, use the one below. This will still not work correctly; output redirection fails
#
fselect && file_choice="$(0< "${dir_tmp}/${file_tmp}" )" 2> ~/tmp/eebg_fselect01.tmp
#fselect && file_choice="$(0< "${file_tmp}/${dir_tmp}" )" # 2> ~/tmp/fselect01.tmp
clean_temp
exit 0
###########################################################################################
#
# This function works. So does output redirection (as shown), but why, is a mystery :-\
#
input 3 "Username" "root" "IP address" "192.168.0.1" "Destination directory" "/tmp" 2> ~/tmp/eebg_input01.tmp
clean_temp
exit 0
###########################################################################################
#
# This function works
#
alert_message "This is an \n alert_message"
clean_temp
exit 0
###########################################################################################
#
# This function works. So does output redirection (as shown), but why, is a mystery :-\
#
menu "enter in Server1" "enter in Server2" "enter in Server3" "enter in Server4" 2> ~/tmp/eebg_menu01.tmp
choice="$(0< "${dir_tmp}/${file_tmp}" )"
#
if_arg_is_an_empty_variable_then_exit "choice" #bye, bye, user... :)
#
if [ "${choice}" = "enter in Server1" ]
then
#
ok_message "Hello world ! \n ...enter in Server1..."
# exec xterm -geometry 145x50 -bg gray -fg black -e "ssh root@192.168.1.1 -Y"
#
elif [ "${choice}" = "enter in Server2" ]
then
#
ok_message "Hello world ! \n ...enter in Server2..."
# exec xterm -geometry 145x50 -bg lightblue -fg black -e "ssh root@192.168.1.2 -Y"
#
elif [ "${choice}" = "enter in Server3" ]
then
#
ok_message "Hello world ! \n ...enter in Server3..."
# exec xterm -geometry 145x50 -bg pink -fg black -e "ssh root@192.168.1.3 -Y"
#
elif [ "${choice}" = "enter in Server4" ]
then
#
ok_message "Hello world ! \n ...enter in Server4..."
# exec xterm -geometry 145x50 -bg cyan -fg black -e "ssh root@192.168.1.4 -Y"
#
fi
clean_temp
exit 0
###########################################################################################
#
# This function works.
#
message "This is a \n message"
clean_temp
exit 0
###########################################################################################
#
# This function works. So does output redirection (as shown), but why, is a mystery :-\
#
list +"Heavy metal" -"Rock and Roll" +"Country" +"Blues" -"Pop" -"Folk" +"Classical" 2> ~/tmp/eebg_list01.tmp
clean_temp
exit 0
###########################################################################################
#
# This function works.
#
ok_message "Hello world ! \n ...and peace to you..."
clean_temp
exit 0
###########################################################################################
#
# This function works. So does output redirection (as shown), but why, is a mystery :-\
# the answers are: OK=0, Cancel=1.
#+ don't see how to get an answer -gt 1 (perhaps it's using PROGRESS, see below) :-/
#
question "Do you like Contry music ?" 2> ~/tmp/eebg_question01.tmp
answer="${?}"
if [ ${answer} -eq 0 ]
then
ok_message "You do like it :)"
elif [ ${answer} -eq 1 ]
then
alert_message "You don't like it :("
else
ok_message "See you"
exit 0
fi
# if you use "PROGRESS" string in STDIN do not forget second argument ( "[elements number]" )
clean_temp
exit 0
###########################################################################################
#!/bin/sh
#
#
# This filename: ebg_howto (ebg = easybashgui)
#
# Syntax: ebg_howto src-filename dest-filename
#
# library address is: /usr/local/bin/easybashgui
#
# This is an implementation of the easybashgui 'list' function.
#+ As can be seen above (see Syntax) the script takes two arguments,
#+ a source file and a destination (results) file, both text.
#
# The source file contains entries, one per line, each of which can be
# a comment (with a '#' in column 1) or a value (with NO '#' in column 1).
#+ These entries are processed into an executable script, which is then run.
#
# If you want to try this, simply copy this code into your favourite editor
#+ and save it into a (script) file, say 'ebg_howto' (in a directory in
#+ your $PATH). Make it executable with 'chmod +x /your/path/ebg_howto'.
#
# Towards the bottom of the script there is a statement which looks
#+ something like this:
#+ echo ' 2> $1' >> "${dir_tmp}/${file_tmp03}"
#+ This enables the output (STDERR) to be captured; an attempt to redirect
#+ stdout will FAIL, because the easybashgui-library redirects stdout to stderr
#
# If you want to follow the script-file construction, you can do this by setting
#+ the variable 'tempfile_sw' =1; see below for the file-names used.
#
# For testing you could copy the following snippet into a text-file, say
#+ '/your/path/test_ip.txt', remove the first 4 characters on each line
#+ (but remember to leave the '#' on the label lines!!!), then run the
#+ following command:
#
#+ /your/path/ebg_howto /your/path/ebg_ht_test_ip.txt /your/path/ebg_ht_test_out.txt
#
#+ # Label line # (note the # in position 1)
#+ # Another label line
#+ # Yet other label line
#+ Value line # (note NO # in position 1!!)
#+ Another value line
#+ etc
#+ Final value line
#
## You will see that the label-lines (comments) also have tick-boxes; this
#+ is something that I have not been able to suppress (not wanting to alter
#+ Vittorio's library :-\ ); this may be possible later (??). However, this
#+ script removes any output lines beginning with a '#' (i.e. have been
#+ selected/ticked by the user) prior to writing the results file.
#
#
#
function init_ebg_list # initialise the ebg_list script
# Syntax: init_ebg_list output-file
{
echo '#!/usr/bin/env bash' > $1
echo '#' >> $1
echo 'source easybashgui' >> $1
echo '#' >> $1
echo '# This functions syntax: init_ebg_list dest-file' >> $1
echo '#' >> $1
echo '# Note: the # at the beginning of each lab-line is ' >> $1
echo '#+ VERY important (will also be ignored by' >> $1
echo '#+ system if the label is inadvertently selected)' >> $1
echo '#' >> $1
}
#
function rmfile() # remove file
# Syntax: rmfile filename
{
if [ -e $1 ];
then
{
rm $1
# echo $1" deleted"
}
fi
}
function init_tmp() # initialise temp-files
# Syntax: init_tmp
{
if [ -d "${HOME}/tmp" ]; then
dir_tmp="${HOME}/tmp"
else
dir_tmp="/tmp"
fi ; [ ! -d "${dir_tmp}" ] && mkdir "${dir_tmp}"
: dir_tmp
if [ $tempfile_sw -eq 0 ]; then # force SCRIPT-internal temp files
{
#
# echo "dir_tmp="$dir_tmp
# echo "file_tmp02="${dir_tmp}/${file_tmp02}
# echo "file_tmp03="${dir_tmp}/${file_tmp03}
# echo "file_tmp04="${dir_tmp}/${file_tmp04}
# echo "file_tmp05="${dir_tmp}/${file_tmp05}
# echo "file_tmp06="${dir_tmp}/${file_tmp06}
# echo "file_tmp07="${dir_tmp}/${file_tmp07}
if [ -f "${dir_tmp}/${file_tmp02}" ]; then
{
: 1> "${dir_tmp}/${file_tmp02}"
: 1> "${dir_tmp}/${file_tmp03}"
: 1> "${dir_tmp}/${file_tmp04}"
: 1> "${dir_tmp}/${file_tmp05}"
: 1> "${dir_tmp}/${file_tmp06}"
: 1> "${dir_tmp}/${file_tmp07}"
}
else
{
cd "${dir_tmp}"
export file_tmp02="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
export file_tmp03="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
export file_tmp04="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
export file_tmp05="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
export file_tmp06="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
export file_tmp07="$(mktemp "XXXXXXXXXXXXXXXXXXXX" )"
# echo "*********"
# echo "file_tmp02="${dir_tmp}/${file_tmp02}
# echo "file_tmp03="${dir_tmp}/${file_tmp03}
# echo "file_tmp04="${dir_tmp}/${file_tmp04}
# echo "file_tmp05="${dir_tmp}/${file_tmp05}
# echo "file_tmp06="${dir_tmp}/${file_tmp06}
# echo "file_tmp07="${dir_tmp}/${file_tmp07}
cd - 1>/dev/null
}
fi
}
else # force USER-retained temp files
{
cd "${dir_tmp}"
file_tmp02=ebg_ht002.tmp ; touch "${dir_tmp}/${file_tmp02}"
file_tmp03=ebg_ht003.tmp ; touch "${dir_tmp}/${file_tmp03}"
file_tmp04=ebg_ht004.tmp ; touch "${dir_tmp}/${file_tmp04}"
file_tmp05=ebg_ht005.tmp ; touch "${dir_tmp}/${file_tmp05}"
file_tmp06=ebg_ht006.tmp ; touch "${dir_tmp}/${file_tmp06}"
file_tmp07=ebg_ht007.tmp ; touch "${dir_tmp}/${file_tmp07}"
# if [ -a "$dir_tmp/$file_tmp01" ]; then
# echo "file_tmp01="${dir_tmp}/${file_tmp01}
# else
# echo "file ""$dir_tmp/$file_tmp01" " does not exist"
# fi
cd - 1>/dev/null
}
fi
}
function clean_tmp() # clean-up tmp-files
# Syntax: clean_tmp
{
# local FUNCT_NAME="clean_temp"
# local IFS=$' \t\n'
#
if [ $tempfile_sw -eq 0 ]; then # ONLY clean-up SCRIPT-internal temp files
{
rmfile ${dir_tmp}/$file_tmp02
rmfile ${dir_tmp}/$file_tmp03
rmfile ${dir_tmp}/$file_tmp04
rmfile ${dir_tmp}/$file_tmp05
rmfile ${dir_tmp}/$file_tmp06
rmfile ${dir_tmp}/$file_tmp07
}
fi
}
# Script proper starts here . . . . . . .
# Assuming that src-file exists, has a non-zero length and is regular . .
#
tempfile_sw=1 # =0 forces SCRIPT-internal temp files to be used (are deleted on completion)
#+ =1 for USER-retained
#
if [[ -s "$1" && -f "$1" ]]; then
{
init_tmp
echo "# Some title or another . . ." > "${dir_tmp}/${file_tmp06}"
cat "${dir_tmp}/${file_tmp06}" "$1" > "${dir_tmp}/${file_tmp07}"
azlins=(`wc -l "${dir_tmp}/${file_tmp07}"`) # ; echo $azlins
count=1
# The list steering-script is formed in two parts: the upper part (see init_ebg_list above)
#+ including the actual display strings with their names and ..
init_ebg_list "${dir_tmp}/${file_tmp02}"
# the lower part, containing the list-call with the display-strings references; init here
echo -n 'list ' > "${dir_tmp}/${file_tmp03}"
# for all source lines, add to the upper and lower parts as approp
while read LINE ; do
{
# echo "LINE="$LINE
# Truncate the line at col 55 (in case of error-input with excessively long lines :-/ )
LINE=`echo $LINE | cut -c1-55`
if [ ${LINE:0:1} = '#' ]; then
{
# this is a label, form display-string name and reference ('-' for unticked box)
echo 'lab'`(printf "%03d" $count)`'="'$LINE'"' >> "${dir_tmp}/${file_tmp02}"
echo -n ' -"$lab'`(printf "%03d" $count)`'"' >> "${dir_tmp}/${file_tmp03}"
}
else
{
# this is a value, form display-string name and reference ('+' for ticked box)
echo 'opt'`(printf "%03d" $count)`'="'$LINE'"' >> "${dir_tmp}/${file_tmp02}"
echo -n ' +"$opt'`(printf "%03d" $count)`'"' >> "${dir_tmp}/${file_tmp03}"
}
fi
}
let count=$count+1
done < "${dir_tmp}/${file_tmp07}"
# Now terminate the lower part
echo ' 2> $1' >> "${dir_tmp}/${file_tmp03}" ; echo -e 'clean_temp\n' >> "${dir_tmp}/${file_tmp03}"
# now join them into a complete script
cat "${dir_tmp}/${file_tmp02}" "${dir_tmp}/${file_tmp03}" > "${dir_tmp}/${file_tmp04}"
# make the script executable
chmod +x "${dir_tmp}/${file_tmp04}"
# and NOW, execute it; the result is in the argument-file
"${dir_tmp}/${file_tmp04}" "${dir_tmp}/${file_tmp05}"
# remove any inadvertantly selected (by user) label-lines ( # in col-1 )
grep -v '^#' "${dir_tmp}/${file_tmp05}" > "$2" #user-o/p
clean_tmp
}
fi
exit 0