1 / 16

if then flowchart

if then flowchart. if test command. false. true. then commands. fi. Simple if statement. if [ $# –gt 9 ] then echo more than 9 arguments were entered echo “Use the shift command to see args 10-$#” fi. if then else flowchart. if test command. true. false. then commands.

aldona
Download Presentation

if then flowchart

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. if then flowchart if test command false true then commands fi Loops and Decisions Flowcharts

  2. Simple if statement if [ $# –gt 9 ] then echo more than 9 arguments were entered echo “Use the shift command to see args 10-$#” fi Loops and Decisions Flowcharts

  3. if then else flowchart if test command true false then commands else commands fi Loops and Decisions Flowcharts

  4. The full if statement • echo “Please enter filename to be backed up” • read fname • if [ -f $fname ] • then cp $fname ${fname}.bak • else echo filename $fname DOES NOT exist • fi Loops and Decisions Flowcharts

  5. The elif flowchart if test-command true false elif test-command false true then commands then commands else commands fi Loops and Decisions Flowcharts

  6. The if - elif statement • day=`date +"%A" • if [ $day = Monday ] ; then echo "Today is Monday" • elif [ $day = Tuesday ] ; then echo "Today is Tuesday" • elif [$day = Wednesday ] ; then echo "Today is Wednesday " • elif [ $day = Thursday ] ; then echo "Today is Thursday" • elif [ $day = Friday ] ; then echo "Today is Friday " • elif [ $day = Saturday ] ; then echo "Today is Saturday " • else echo "Today is Sunday” • fi Loops and Decisions Flowcharts

  7. The case structure flowchart case test-string = pattern-1? true commands-1 false test-string = pattern-2? true commands-2 false test-string = pattern-3? true commands-3 false esac Loops and Decisions Flowcharts

  8. The case structure 1 day=`date +”%A” case $day in M*) echo "Today is Monday“ ;; Tu*) echo "Today is Tuesday" ;; W*) echo "Today is Wednesday " ;; Th*) echo "Today is Thursday" ;; F*) echo "Today is Friday " ;; Sa*) echo "Today is Saturday " ;; Su*) echo "Today is Sunday” ;; esac Loops and Decisions Flowcharts

  9. The case structure 2 cat <<++ Main Menu 1. Display Current Directory 2. Print Today's Date x. Exit Main Manu Please enter your selection ++ (Note: script continued on Next slide) Loops and Decisions Flowcharts

  10. The case structure 2 - Continued • (Note: script continued from Previous slide) • read selection • case $selection in • 1) echo "Your Present Working Directory is: " • pwd ;; • 2) echo "Today's date and time is: " • date ;; • [xX]) leave=yes ;; • *) echo "Invalid choice, please try again" ;; • esac Loops and Decisions Flowcharts

  11. The while loop flowchart while test-command done false true do commands Loops and Decisions Flowcharts

  12. The until loop flowchart until test-command done true false do commands Loops and Decisions Flowcharts

  13. leave=no while [ $leave = no ] do cat <<++ Main Menu 1. The break and continue commands 2. Print Today's Date x. Exit Main Manu Please enter your selection ++ read selection Note: Script continues next slide The while structure Loops and Decisions Flowcharts

  14. Note: Script continues next slide case $selection in [ $USER = mohammed ] && continue Note: && means if command1 executes then do command2 [ $USER = mohammed -a $HOSTNAME = phobos ] && break echo This message NOT printed for user mohammed ;; 2) echo "Today's date and time is: " date ;; [xX]) leave=yes ;; *) echo "Invalid choice, please try again” ;; esac done echo Loop is done The while structure Loops and Decisions Flowcharts

  15. for in - flowchart Assign next argument in argument-list to loop-index do commands is there another argument in the argument-list? yes no done Loops and Decisions Flowcharts

  16. The for loop • echo “Enter file names to be copied: \c”; read fnames • for file in $fnames • do • cp $file ../${file}.bak • if [ $? –ne 0 ] • then echo “$file does not exist, Continue copying? Y/N” • read stop • if [ $stop != Y ] • then break • else echo copied file $file • fi • fi • done Loops and Decisions Flowcharts

More Related