3

I have a pretty important question, I have been a fan of the stegosaurus of cowsay(the package) that reads fortunes, input, etc.. So naturally it was of great importance to me to have this majestic creature tell me what day it is every day. I made the following script to do so using user input:

#!/bin/bash selection= until [ "$selection" = "0" ]; do echo "" echo "PROGRAM MENU" echo "1 - It's Monday!" echo "2 - It's Tuesday!" echo "3 - It's Wednesday!" echo "4 - It's Thursday!" echo "5 - It's Friday!" echo "6 - Custom input" echo "7 - Exit" echo "" echo -n "Enter selection: " read selection echo "" case $selection in 1 ) cowsay -f stegosaurus "It's Monday!" exit ;; 2 ) cowsay -f stegosaurus "It's Tuesday!" exit ;; 3 ) cowsay -f stegosaurus "It's Wednesday!" exit ;; 4 ) cowsay -f stegosaurus "It's Thursday!" exit ;; 5 ) cowsay -f stegosaurus "It's Friday!" exit ;; 6 ) echo -n "custom input > " read custom cowsay -f stegosaurus "$custom" exit ;; 7 ) exit ;; * ) cowsay -f stegosaurus "Guess what day it is?" exit ;; esac done 

However, this was one of my first scripts on a linux distrobution and I'm ready to enhance my creation by making it automatically update with the current day (Maybe even hour if I can). However, I haven't been able to do this so far.. Can anyone please help me or point me in the right direction?

I'd be incredibly grateful for any advice, thanks very much in advance!

4
  • I'm favoriting this question just so I can install cowsay and hear how stegosaurus sounds like! Commented Oct 23, 2013 at 17:26
  • @Shahbaz It's glorious. It fulfills that deep need to have a stegosaurus wearing a hat read you trivial text that you have been waiting all your life for. :) Commented Oct 23, 2013 at 17:34
  • consider reading man date Commented Oct 23, 2013 at 17:52
  • Look into the select command, which you are reimplementing. Commented Oct 23, 2013 at 17:57

3 Answers 3

4
cowsay -f stegosaurus "It's $(date +%A)" 

Check out the GNU date documentation for more examples of how you can format times. e.g.

cowsay -f stegosaurus "It's $(date +%A) and the time is $(date +%r)" 
Sign up to request clarification or add additional context in comments.

Comments

1

I believe you want to replace:

read selection 

...with:

selection=`date +'%u'` 

The date utility, combined with the +'FORMAT' argument, outputs various date elements / formats. The %u formatting symbol translates to

day of week (1..7); 1 represents Monday

The full doc is here: http://linux.about.com/od/commands/l/blcmdl1_date.htm

Bear in mind, this also means that the * ) case scenario no longer applies.

Note: The other answer -- "It's $(date +%A)" -- is perfect if you wish to have the output simply be "It's [day of week]!" -- only use this answer if you want to retain custom handling for any specific days of the week.

Comments

1

Try date command:

$ date +%A Wednesday 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.