Wednesday, August 17, 2011

timetable.sh for lazy people like me

   It is always very difficult for me to remember the time-table, especially for the first few weeks of semester. The condition was worse this semester, so I HAD to find a solution for this.I know, taking a photograph of the timetable would do it but I thought of doing something new (yeah!!)
 
   Since, the start of this semester, I had started using Linux and so I thought of making a shell script to help me.Well, fortunately I stuck to this idea and hence after about an hour of Googling, I was able to learn enough of shell scripting to help me here.Well, to save u from even one hour of googling, I am sharing the skeleton of the program:

#! /bin/bash

if [ "$#" == "0" ]
then
 
   set `date +%u`
if [ "$1" -eq "1" ]
then
   echo -e "Monday's timetable\n"

else if [ "$1" -eq "2" ]
then
   echo -e "\nTuesday\n"
else if [ "$1" -eq "3" ]
then
   echo -e "\n Wednesday\n"
  
else if [ "$1" -eq "4" ]
then
   echo -e "\n Thursday\n"
  
else if [ "$1" -eq "5" ]
then
   echo -e "\nFriday\n"
 fi
 fi
 fi
 fi
 fi
  
else

if [ "$1" == "1" ]
then
      same thing again


fi

fi


So, why did I use $# here?
  $# tells me the no of arguments passed. So if we passed a day number as an argument, then show that day's timetable, otherwise find the day of the week and then display the timetable.

why echo -e?
   Normally, echo doesnot support escape sequences so we need to add -e for them.

and date +%u gives u  the day of the week

We use the set command to give the value to the variable $1. $1 and all are special variables used in Shell script.

U can use == or -eq for checking the comparison. And it is visible that u need to end each if statement using fi!!

Anyways, now I have a shell script to tell me the timetable whenever I need it. Now all I need to do is make it autorun everyday in the morning and also turn it into a linux command. Will do that, and let u know :)

Enjoy this code till then. Yes, u are also welcome to tell me how to do the above!
  

No comments:

Post a Comment