Showing posts with label timetable. Show all posts
Showing posts with label timetable. Show all posts

Tuesday, February 7, 2012

TT (newer version of timetable)

  Last year I had created a shell script which showed me my academic timetable for the day. I was a newbie in shell scripting at that time and hence the script was not so good. Hence, here is tt or I should say timetable2.0 ?
  This time I have stored my timetable in a timetable.txt file so that whenever I need to modify the timetable, I don't need to modify the script. Also, the code is much shorter this time with not so many if statements. Here is the new code:

#!/bin/bash
days=( Monday Tuesday Wednesday Thursday Friday )

if [ "$#" == 0 ]
then
  echo -e "\nToday's Timetable:"
  set `date +%u`
else
  echo -e "\n"${days[$1-1]}"'s timetable:"
fi
  sed -n $1p < timetable.txt
  echo -e "\n\n"


  Still to be added: Feature to change the timetable. But that's all for now. The new modification will come when I feel the mood of it :)

  

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!