Code Sample |
#!/bin/bash # This is another DSL MS-Word Viewer. # Made by Reidar Mosvold. clear while test "$answer" != "0" do clear echo "" echo " ************************************************" echo " DSL Word Viewer " echo " ************************************************" echo "" echo " 1 - List files in directory " echo " 2 - Change directory " echo " 3 - View MS-Word file " echo " 4 - Edit MS-Word file " echo " 5 - Convert MS-Word file to pdf " echo " 6 - View pdf file " echo " 7 - Remove a file " echo " 8 - Quit " echo "" echo -n " Choose a function (1-8) and press <ENTER> key :" read answer # cd $HOME # # 1 - List files # if test "$answer" = "1";then clear echo "" echo "Current directory is :" pwd echo "" echo "List files and directories" ls -la | more echo "" echo -n "Press <ENTER> to continue :" read stop fi # # 2 - Change directory # if test "$answer" = "2";then clear echo "" echo -n "Current directory is :" pwd echo "" echo "To continue in current directory answer with '.' (period) and press <ENTER>" echo "If you want to move one level up, answer with '..' (two periods) and press <ENTER>" echo "" echo "If you want to move back to your home-directory press <ENTER>" echo "" echo "If you want to move to a child-directory, write the name of the directory and press <ENTER>" echo "" echo -n "Which directory would you like to use :" read dir cd $dir echo "" echo -n "New active directory is :" pwd echo "" echo "List files in current directory :" ls echo "" echo -n "Press <ENTER> to continue :" read stop fi # # 3 - View MS-Word document # if test "$answer" = "3";then clear echo "" echo -n "Here are the files in " pwd echo "" ls echo "" echo "If the file is more than one page you may continue by pressing <ENTER>" echo "" echo -n "Which file would you like to view on your screen :" read file if test -s "$file";then antiword "$file" | more echo "" echo -n "Press <ENTER> to continue :" read stop else echo "" echo "The file does not exist or is not MS-Word format" echo "" echo -n "Press <ENTER> to continue :" read stop fi fi # # 4 - Edit MS-Word document # if test "$answer" = "4";then clear echo "" echo -n "Here are the files in " pwd echo "" ls echo "" echo -n "Which file would you like to edit :" read editwordfile echo "" echo -n "What new filename would you like to give the document (*.txt) :" read newfilename echo "" echo -n "Which editor would you like to use :" read editortouse if test -s "$editwordfile";then antiword "$editwordfile" > "$newfilename" "$editortouse" "$newfilename" echo "" echo -n "Press <ENTER> to continue :" read stop else echo "The file does not exist or is not in MS-Word format" echo "" echo -n "Press <ENTER> to continue :" read stop fi fi # # 5 - Convert MS-Word file to pdf # if test "$answer" = "5";then clear echo "" echo -n "Here are the files in " pwd echo "" ls echo "" echo -n "Which file (*.doc) would you like to convert to pdf :" read convertfile echo -n "Insert a new filename (*.pdf) :" read newfile if test -s "$convertfile";then antiword -p a4 "$convertfile" > testfil.ps ps2pdf testfil.ps "$newfile" rm -f testfil.ps echo "" echo -n "Press <ENTER> to continue :" read stop else echo "" echo "The file does not exist or is not in MS-Word format" echo "" echo -n "Press <ENTER> to continue :" read stop fi fi # # 6 - View pdf file # if test "$answer" = "6";then clear echo "" echo -n "Here are the files in " pwd echo "" ls echo "" echo -n "Which pdf file would you like to view :" read viewpdffile if test -s "$viewpdffile";then xpdf "$viewpdffile" & echo "" echo -n "Press <ENTER> to continue :" read stop else echo "" echo "The file does not exist or is empty" echo "" echo -n "Press <ENTER> to continue :" read stop fi fi # # 7 - Remove a file # if test "$answer" = "7";then clear echo "" echo -n "Here are the files in " pwd echo "" ls echo "" echo "(If you don't want to remove a file, press <ENTER>)" echo -n "Which file would you like to remove :" read removefile if test -s "$removefile";then rm "$removefile" echo "" echo -n "Press <ENTER> to continue :" read stop else echo "" echo "The file does not exist or is empty" echo "" echo -n "Press <ENTER> to continue :" read stop fi fi # # 8 - Quit # if test "$answer" = "8";then exit; fi done |
Code Sample |
case $answer in 1) clear echo " Current directory is :" pwd echo " List files and directories" ls -la | more echo -n " Press <ENTER> to continue :" read stop ;; 2) stuff for 2;; 3) stuff for 3;; blah blah blah esac |