Difference between revisions of "Trillex bash 1"

From Teknologisk videncenter
Jump to: navigation, search
Line 35: Line 35:
 
  fi
 
  fi
  
==== Same as above but less advanced and working ====
+
==== Same As Above But Less Advanced and Working ====
  
 
  #!/bin/bash
 
  #!/bin/bash

Revision as of 12:02, 12 February 2009

Bash Scripts and Commands

Bash Commands

Bash Scripts

Program for greeting users. Doesn't work

#!/bin/bash
clear
echo -e "Welcome to my new bash-script"
echo -e "============================="
echo -e "\n\n"   # \n is the new-line command. So there will be two empty lines here
echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark"
echo -e "The time is `date +%H:%M`."
HOUR=`date +%H`
MINUTE=`date +%M`
if test $HOUR -le 7
 then
   echo -e "Please go to sleep."
     else if test $HOUR -le 8
       then
         echo -e "You are early."
           else if test ($HOUR -lt 11) -a ($MINUTE -lt 59)
             then
               echo -e "Good Morning."
                     else if test ($HOUR -lt 15) -a ($MINUTE -lt 59)
                       then
                         echo -e "Good afternoon."
                           else if test $HOUR -gt 16
                            then
                              echo -e "Please go home."     
                                fi
                           fi
                 fi
          fi
fi

Same As Above But Less Advanced and Working

#!/bin/bash
clear
echo -e "Welcome to my new bash-script"
echo -e "============================="
echo -e "\n\n"   # \n is the new-line command. So there will be two empty lines here
echo -e "Rune Nordblom\nPRC-Data, Viborg\nDenmark"
echo -e "The time is `date +%H:%M`."
HOUR=`date +%H`
MINUTE=`date +%M` 
if test $HOUR -lt 7
 then echo -e "Please go to sleep."
 elif test $HOUR -lt 8
 then echo -e "You are early."
 elif test $HOUR -lt 11
 then echo -e "Good Morning."
 elif test $HOUR -lt 15
 then echo -e "Good afternoon."
 elif test $HOUR -gt 16
 then echo -e "Please go home."     
fi