shell script with If then else | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

shell script with If then else

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-11-2008
skatpally skatpally is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 9 January 2013, 1:07 PM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
shell script with If then else

Hii frds,
I am trying to write a shell script to display the date based on user input. I am geting syntax error. plz help. thanks - sam

UNIX version: AIX

#!/bin/ksh
echo -n "todays date want to know:"
set answer = $<
if ($answer == yes) then
date
exit 1
else
exit 2
endif


-n todays date want to know:
date1[3]: 0403-057 Syntax error at line 4 : `newline or ;' is not expected.
Sponsored Links
    #2  
Old 03-11-2008
skatpally skatpally is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 9 January 2013, 1:07 PM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Still unable to fugure out. looking for help
Sponsored Links
    #3  
Old 03-11-2008
in2nix4life's Avatar
in2nix4life in2nix4life is online now
Registered User
 
Join Date: Oct 2007
Last Activity: 22 July 2014, 3:19 PM EDT
Location: East Coast
Posts: 591
Thanks: 1
Thanked 170 Times in 156 Posts
Hope this helps:

#!/bin/ksh

echo -n "todays date want to know: "
read answer

if [ $answer == "yes" ]; then
date
exit 1
else
exit 2
fi
    #4  
Old 03-12-2008
skatpally skatpally is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 9 January 2013, 1:07 PM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks man it did work. I appreciate u r help.

Solution:

#!/bin/ksh
echo -n "todays date want to know:"
read $answer
if(answer==yes)
then
date
exit 1
else
exit 2
fi
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
call another shell script and pass parameters to that shell script sunrexstar Shell Programming and Scripting 2 11-29-2010 02:53 PM
How to use ssh execute other shell script on other host (shell script include nohup)? orablue Shell Programming and Scripting 1 11-18-2010 08:46 PM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 05:16 PM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 07:17 AM



All times are GMT -4. The time now is 03:20 PM.