I need help writing this script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need help writing this script
# 1  
Old 04-23-2011
I need help writing this script

Smilie

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

Code:
#!/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


Last edited by Scott; 04-23-2011 at 07:18 PM..
# 2  
Old 04-23-2011
Enjoy.... Check the changes
Code:
#!/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


Last edited by Scott; 04-23-2011 at 07:01 PM.. Reason: Please use code tags
# 3  
Old 04-23-2011
Quote:
Originally Posted by nowruzr
Smilie

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

Quote:
Originally Posted by shivangi
Enjoy.... Check the changes
Please use code tags.
Secondly, = and = = both works.
Also ` `(backticks) and $( ), both works. Infact it is recommended to use $( )

regards,
Ahamed
# 4  
Old 04-23-2011
I did try executing the changed script, the menu is getting displayed and also the output (after entering Date and not date in choice)
# 5  
Old 04-23-2011
Thank you guys

I think shivangi got it right. Smilie
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?
# 6  
Old 04-23-2011
Good it worked!!

for case insensitive, use
Code:
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
# 7  
Old 04-23-2011
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.

Code:
#!/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


Last edited by Scott; 04-23-2011 at 07:19 PM.. Reason: Please use CODE tags for CODE (not quote tags)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Help with script writing?

I am new for script writing. I have a file named as name.dat and contain numbers with different rows and columns. I want to sum numbers at one row with that of at another row; like row1 + row101 + row 201, with corresponding columns. Any one can help me to write a script for this operation. ... (1 Reply)
Discussion started by: kumnegert
1 Replies

2. Shell Programming and Scripting

Help in writing script

i need some help in donig some actions on files in a library. i want to get the n last files, and print to the screen their name, date, and how many times a specific string appears in each file.. how can i do this..?... (6 Replies)
Discussion started by: eee
6 Replies

3. Red Hat

writing a script

Dear Madam/Sir Who can help me with writing a script doing the following? 1- Read names of files (only files with special name format let say initially they have the same file name start like TT*) 2- Then create an empty files with the same names have been read in step one but with extension... (1 Reply)
Discussion started by: m.nageeb
1 Replies

4. Shell Programming and Scripting

Please help me in writing my script

hello all, I have a script, used to search for the strings from the set of 5 similar pattern file from the log dir. So here it goes . The input parameter is a part of the file name. When during the script execution, the script should parse the input parameter to original file's with the same... (0 Replies)
Discussion started by: baraghun
0 Replies

5. Shell Programming and Scripting

Help me in writing the script

Hi, I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its... (1 Reply)
Discussion started by: prakashreddy
1 Replies

6. UNIX for Dummies Questions & Answers

Need help writing this script

Here is the script I am trying to write along with my answer I wrote. Please help me understand why it doesn't work. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for... (1 Reply)
Discussion started by: wiggles
1 Replies

7. Shell Programming and Scripting

help writing script

hi all i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits. the file looks like below, 58331600563588885696ACXT5263 58331600563588885697ACXT5263 58331600563588885698ACXT5263 i want to write a script which will extract the... (8 Replies)
Discussion started by: dr46014
8 Replies

8. UNIX for Dummies Questions & Answers

help for writing a script

Hi, I need help writing a unix script to change the time in the server automatically when it reaches a specified time. Only on the 14th of april, when the time becomes midnight (00:00:00), I need the server to change the time automatically to 23:30:00 and start working on as usual with a... (2 Replies)
Discussion started by: amodha
2 Replies

9. Shell Programming and Scripting

Writing Script?

Anyone have an example of a simple shell script that solicits a (Y)es or (N)o response from the user. If the response is 'Y' display a message on the screen that thanks the user for the positive response. If the response is 'N' display a message that thanks the user for the negative response. If... (15 Replies)
Discussion started by: wmosley2
15 Replies

10. Shell Programming and Scripting

need help writing a script

Hello everyone. Well, I will get right to the point. I am new to Perl and trying to learn it as much as I can. I have been assigned the task of writing a perl script to extract information from firewall logs. Like I said, I am new to Perl and I am having a tough time because I think what I am... (3 Replies)
Discussion started by: tarballed
3 Replies
Login or Register to Ask a Question