:wall:
Can't seem to figure out how to fix this please help
its not starting over like I would like it to
When I enter in "Date" or "Time" nothing comes
Also if you can tell me the commands for the other 3 stuff that would be much appreciated
#!/bin/bash
clear
while [ "$ans" != "Exit" ]; do
echo ".-----------------------------------------------------------------."
echo "| |"
echo "| Type in the following commands based on what you want to see: |"
echo "| |"
echo "| Today - to see the day of the week |"
echo "| Date - to see the date |"
echo "| Time - to see the time |"
echo "| Files - to show files in the home directory |"
echo "| Cal - to see the calendar |"
echo "| Letter - to open editor to write letters |"
echo "| Exit - to exit |"
echo "| |"
echo "'-----------------------------------------------------------------'"
echo " "
echo "Please type in your choice: "
read ans
if [ "$ans" == "Today" ]; then
clear
echo "\n"
echo $(date +%A)
echo "\n"
elif [ "$ans" == "Date" ]; then
clear
echo "\n"
echo $(date +%D)
echo "\n"
elif [ "$ans" == "Time" ]; then
clear
echo "\n"
echo $(date +%r)
echo "\n"
fi
done
Enjoy.... Check the changes
#!/bin/bash
clear
while [ "$ans" != "Exit" ]; do
echo ".-----------------------------------------------------------------."
echo "| |"
echo "| Type in the following commands based on what you want to see: |"
echo "| |"
echo "| Today - to see the day of the week |"
echo "| Date - to see the date |"
echo "| Time - to see the time |"
echo "| Files - to show files in the home directory |"
echo "| Cal - to see the calendar |"
echo "| Letter - to open editor to write letters |"
echo "| Exit - to exit |"
echo "| |"
echo "'-----------------------------------------------------------------'"
echo " "
echo "Please type in your choice: "
read ans
if [ "$ans" = "Today" ]; then
clear
echo "\n"
echo `date +%A`
echo "\n"
elif [ "$ans" = "Date" ]; then
clear
echo "\n"
echo `date +%D`
echo "\n"
elif [ "$ans" = "Time" ]; then
clear
echo "\n"
echo `date +%r`
echo "\n"
fi
done
I don't see anything wrong with your script (didn't try executing it though). I sure hope you are getting the menu displayed. May be you are entering "date" instead of "Date". Comparison is case sensitive.
regards,
Ahamed
---------- Post updated at 01:03 PM ---------- Previous update was at 01:01 PM ----------
Please use code tags.
Secondly, = and = = both works.
Also ` `(backticks) and $( ), both works. Infact it is recommended to use $( )
regards,
Ahamed
I did try executing the changed script, the menu is getting displayed and also the output (after entering Date and not date in choice)
I think shivangi got it right.
I made my some changes to it my self, once I am finished with it or if I run into any more trouble I will repost the script
and ty ahamed101 for the tips
---------- Post updated at 02:16 PM ---------- Previous update was at 02:15 PM ----------
btw is there a way to make it so that it is case insensitive, so that I can write date or Date daTE and it will work?
Good it worked!!
for case insensitive, use
typeset -l ans
When typeset -l ans is done, the shell reads the input from user and stores it in lower case.
In the comparison use lower case letter - i.e. if [ "$ans" = "date" ]
regards,
Ahamed
I got Date, Time, Today, and Letter to work right.
Now its time for Calendar and Files.
They both have a weird word wrap problem.
Also I wasn't able to incorporate the lowercase thing correctly, so if you could show me that that would be cool.
#!/bin/bash
clear
while [ "$ans" != "Exit" ]; do
echo ".-----------------------------------------------------------------."
echo "| |"
echo "| Type in the following commands based on what you want to see: |"
echo "| |"
echo "| Today - to see the day of the week |"
echo "| Date - to see the date |"
echo "| Time - to see the time |"
echo "| Files [path] - to show files and folders in that folder |"
echo "| Calendar - to see the calendar |"
echo "| Letter - to open editor to write letters |"
echo "| Exit - to exit |"
echo "| |"
echo "'-----------------------------------------------------------------'"
echo " "
echo "Please type in your choice: **Case Sensitive**"
read ans ans2
if [ "$ans" = "Today" ]; then
clear
echo " "
echo `date +%A`
echo " "
elif [ "$ans" = "Date" ]; then
clear
echo " "
echo `date +%D`
echo " "
elif [ "$ans" = "Time" ]; then
clear
echo " "
echo `date +%r`
echo " "
elif [ "$ans" = "Files" ]; then
clear
echo " "
echo `ls -l $ans2`
echo " "
elif [ "$ans" = "Calendar" ]; then
clear
echo " "
echo `Cal`
echo " "
elif [ "$ans" = "Letter" ]; then
clear
echo " "
echo " "
`open /Applications/Microsoft\ Office\ 2008/Microsoft\ Word.app/`
echo " "
else
clear
echo " "
echo "Error: Not an Option"
echo " "
fi
done
clear
Try this...
#!/bin/bash
typeset -l ans
clear
while [ "$ans" != "Exit" ]; do
echo ".-----------------------------------------------------------------."
echo "| |"
echo "| Type in the following commands based on what you want to see: |"
echo "| |"
echo "| Today - to see the day of the week |"
echo "| Date - to see the date |"
echo "| Time - to see the time |"
echo "| Files [path] - to show files and folders in that folder |"
echo "| Calendar - to see the calendar |"
echo "| Letter - to open editor to write letters |"
echo "| Exit - to exit |"
echo "| |"
echo "'-----------------------------------------------------------------'"
echo " "
echo "Please type in your choice: **Case Sensitive**"
read ans ans2
if [ "$ans" = "today" ]; then
clear
echo " "
echo `date +%A`
echo " "
elif [ "$ans" = "date" ]; then
clear
echo " "
echo `date +%D`
echo " "
elif [ "$ans" = "time" ]; then
clear
echo " "
echo `date +%r`
echo " "
elif [ "$ans" = "files" ]; then
clear
echo " "
ls -l $ans2
echo " "
elif [ "$ans" = "calendar" ]; then
clear
echo " "
cal
echo " "
elif [ "$ans" = "letter" ]; then
clear
echo " "
echo " "
`open /Applications/Microsoft\ Office\ 2008/Microsoft\ Word.app/`
echo " "
else
clear
echo " "
echo "Error: Not an Option"
echo " "
fi
done
clear
regards,
Ahamed
Thank you. I will test it out and see what happens