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 :)

  

5 comments:

  1. Can you explain to me what the ${ } are? I have been using them but I don't really fully understand what they are.

    ReplyDelete
    Replies
    1. ${} is used to show that the output of the expression is to be used as a variable. For example, here ${days[$1-1]} means that the nth element of the 'days' array is to be echoed.

      Delete
    2. Is there a term for that expression?

      Delete
    3. I don't know, I just use it, whenever there is some calculation to be done.

      Delete
  2. ${} is used to show that the output of the expression is to be used as a variable. For example, here ${days[$1-1]} means that the nth element of the 'days' array is to be echoed.

    ReplyDelete