#!/bin/bash # week7-demo-1 # Author: Murray Saul # Date: Feb 13, 2021 # # Purpose: Demonstration to user that you can run shell scripts that # will run operations in GRAPHICAL MODE since Live Knoppix # OS runs in a graphical desktop environment. # # Student performing this OPTIONAL (but cool) tutorial can see # the practicality of installing graphical shell scripts which # may provide students a PRIMER for the importance of automating # tasks in the UNIX / Linux environment. # Using "command substitution" (taught in week 12) at the end of this course # to GRAPHICALLY store output from issuing commands. In this case, store the results from # issuing the "zenity" command to prompt user graphically for a directory # pathname selection. Command redirects stderr to /dev/null to "throw-out" warnings # that normally occur from using the "zenity" command. selection=$(zenity --title "Directory Selection Window" --list --radiolist --text "Please Select a Directory" --hide-header --column "Select" --column "Directory" FALSE "/home/$USER" FALSE "/bin" FALSE "/dev" FALSE "/etc" 2> /dev/null) # Again, using "zenity" command to GRAPHICALLY display stdout from the "ls" command # for the selected directory pathname by using "command substitution" # and expanding the "selection" variable that was set in previous command. # Again, stderr from the command within "command substitution" is redirected # (thrown-out) to /dev/null to avoid displaying warnings associated with # running the "zenity" command. zenity --title "Directory Contents Window" --info --text "Contents of \"$selection\" Directory:\n\n$(ls $selection)" 2> /dev/null # Finally, graphically display that the program has ended and # instructs the user to press OK to close the dialog box and # proceed with the Knoppix tutorial. zenity --title "Completed Script Window" --info --text " \ Well Done!\n\nYou have completed running this demonstration script.\nClick OK and proceed with this tutorial.\n" 2>/dev/null # End of Bash Shell Script #