fork download
  1. show_datetime()
  2. {
  3. dialog --backtitle "Linux Shell Tutorial" --title "System date and Time" --infobox "Date is `date`" 3 40
  4. read
  5. return
  6. }
  7.  
  8. show_cal()
  9. {
  10. cal > menuchoice.temp.$$
  11. dialog --backtitle "Linux Shell Tutorial" --title "Calender" --infobox "`cat menuchoice.temp.$$`" 9 25
  12. read
  13. rm -f menuchoice.temp.$$
  14. return
  15. }
  16.  
  17. delete_file()
  18. {
  19. dialog --backtitle "Linux Shell Tutorial" --title "Delete file"\
  20. --inputbox "Enter directory path (Enter for Current Directory)"\
  21. 10 40 2>/tmp/dirip.$$
  22. rtval=$?
  23.  
  24. case $rtval in
  25. 1) rm -f /tmp/dirip.$$ ; return ;;
  26. 255) rm -f /tmp/dirip.$$ ; return ;;
  27. esac
  28.  
  29. mfile=`cat /tmp/dirip.$$`
  30.  
  31. if [ -z $mfile ]
  32. then
  33. mfile=`pwd`/*
  34. else
  35. grep "*" /tmp/dirip.$$
  36. if [ $? -eq 1 ]
  37. then
  38. mfile=$mfile/*
  39. fi
  40. fi
  41.  
  42. for i in $mfile
  43. do
  44. if [ -f $i ]
  45. then
  46. echo "$i Delete?" >> /tmp/finallist.$$
  47. fi
  48. done
  49.  
  50.  
  51. dialog --backtitle "Linux Shell Tutorial" --title "Select File to Delete"\
  52. --menu "Use [Up][Down] to move, [Enter] to select file"\
  53. 20 60 12 `cat /tmp/finallist.$$` 2>/tmp/file2delete.tmp.$$
  54.  
  55. rtval=$?
  56.  
  57. file2erase=`cat /tmp/file2delete.tmp.$$`
  58.  
  59. case $rtval in
  60. 0) dialog --backtitle "Linux Shell Tutorial" --title "Are you shur"\
  61. --yesno "\n\nDo you want to delete : $file2erase " 10 60
  62.  
  63. if [ $? -eq 0 ] ; then
  64. rm -f $file2erase
  65. if [ $? -eq 0 ] ; then
  66. dialog --backtitle "Linux Shell Tutorial"\
  67. --title "Information: Delete Command" --infobox "File: $file2erase is Sucessfully deleted,Press a key" 5 60
  68. read
  69. else
  70. dialog --backtitle "Linux Shell Tutorial"\
  71. --title "Error: Delete Command" --infobox "Error deleting File: $file2erase, Press a key" 5 60
  72. read
  73. fi
  74. else
  75. dialog --backtitle "Linux Shell Tutorial"\
  76. --title "Information: Delete Command" --infobox "File: $file2erase is not deleted, Action is canceled, Press a key" 5 60
  77. read
  78. fi
  79. ;;
  80. 1) rm -f /tmp/dirip.$$ ; rm -f /tmp/finallist.$$ ;
  81. rm -f /tmp/file2delete.tmp.$$; return;;
  82. 255) rm -f /tmp/dirip.$$ ; rm -f /tmp/finallist.$$ ;
  83. rm -f /tmp/file2delete.tmp.$$; return;;
  84. esac
  85. rm -f /tmp/dirip.$$
  86. rm -f /tmp/finallist.$$
  87. rm -f /tmp/file2delete.tmp.$$
  88. return
  89. }
  90.  
  91.  
  92.  
  93. while true
  94. do
  95. dialog --clear --title "Main Menu" \
  96. --menu "To move [UP/DOWN] arrow keys \n\
  97. [Enter] to Select\n\
  98. Choose the Service you like:" 20 51 4 \
  99. "Date/time" "To see System Date & Time" \
  100. "Calender" "To see Calaender"\
  101. "Delete" "To remove file"\
  102. "Exit" "To exit this Program" 2> menuchoice.temp.$$
  103.  
  104. retopt=$?
  105.  
  106. choice=`cat menuchoice.temp.$$`
  107.  
  108. rm -f menuchoice.temp.$$
  109.  
  110. case $retopt in
  111. 0)
  112. case $choice in
  113. Date/time) show_datetime ;;
  114. Calender) show_cal ;;
  115. Delete) delete_file ;;
  116. Exit) exit 0;;
  117. esac
  118. ;;
  119. 1) exit ;;
  120. 255) exit ;;
  121. esac
  122. done
  123. clear
Success #stdin #stdout 0.03s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty