The file selection box

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

← A progress bar (gauge box)HomeThe form dialog for input →

  • The fselect (file-selection) dialog box shows a text data entry window in which operator can type or select a filename / directory name from the directory or filepath.
  • An operator can use tab or arrow keys to move between the windows. Press the space-bar to select the filename into box.


dialog --title "text" --fselect /path/to/dir height width
FILE=$(dialog --stdout --title "Please choose a file" --fselect $HOME/ 14 48)
echo "${FILE} file chosen."


  • filepath - can be a filepath in which case the file and directory windows will display the contents of the path and the text-entry window will contain the preselected filename.
  • height - set dialog box height.
  • width - set dialog box width.


  • Create a script called
# - Remove the file using dialog box
# -------------------------------------------------
# purpose - remove file
#  $1 - filename 
function delete_file(){
	local f="$1"
	local m="$0: file $f failed to delete."
	if [ -f $f ] 
		/bin/rm $FILE && m="$0: $f file deleted."
		m="$0: $f is not a file."
	dialog --title "Remove file" --clear --msgbox "$m" 10 50

# select filename using dialog
# store it to $FILE
FILE=$(dialog --title "Delete a file" --stdout --title "Please choose a file to delete" --fselect /tmp/ 14 48)

# delete file
[ ! -z $FILE ] && delete_file "$FILE"

Save and close the file. Run it as follows:

chmod +x

Sample outputs:

External links

← A progress bar (gauge box)HomeThe form dialog for input →