The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
for:badly formed number ROOZ Shell Programming and Scripting 3 06-05-2008 05:35 PM
tail | grep lagging badly WasabiVengeance Shell Programming and Scripting 3 04-22-2008 06:53 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
Error: Internal system error: Unable to initialize standard output file firkus UNIX for Dummies Questions & Answers 2 10-25-2005 03:23 PM
New to it all, But i wanna script really badly!!! TheNewGuy Shell Programming and Scripting 3 07-03-2004 10:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2007
amitrajvarma amitrajvarma is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 43
Badly placed ()'s. - error

Hi,

when I execute the below script, I am getting following error "Badly placed ()'s". can anyone please help me fix
----------------------------------------------------------
# Usage: ani -n -a -s -w -d
#
#
# help_ani() To print help
#

help_ani()
{
echo "Usage: $0 -n -a -s -w -d"
echo "Options: These are optional argument"
echo " -n name of animal"
echo " -a age of animal"
echo " -s sex of animal "
echo " -w weight of animal"
echo " -d demo values (if any of the above options are used "
echo " their values are not taken)"
exit 1
}
#
#Start main procedure
#
#
#Set default value for variable
#
isdef=0
na=Moti
age="2 Months"
sex=Male
weight=3Kg
#
#if no argument
#
if [ $# -lt 1 ]; then
help_ani()
fi
while getopts n:a:s:w:d opt
do
case "$opt" in
n) na="$OPTARG";;
a) age="$OPTARG";;
s) sex="$OPTARG";;
w) weight="$OPTARG";;
d) isdef=1;;
/?) help_ani;;
esac
done

if [ $isdef -eq 0 ]
then
echo "Animal Name: $na, Age: $age, Sex: $sex, Weight: $weight (user define mode)"
else
na="Pluto Dog"
age=3
sex=Male
weight=20kg
echo "Animal Name: $na, Age: $age, Sex: $sex, Weight: $weight (demo mode)"
fi
------------------------------------

THx

Amit
Bits Awarded / Charged to amitrajvarma for this Post
Date User Comment Amount
07-23-2009 unni.raj Include the line #!/usr/bin/ksh in the very first line of the code 0
  #2 (permalink)  
Old 10-12-2007
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
I'm not sure what shell you're using but adding a space between function name and () sometimes helps.
  #3 (permalink)  
Old 10-12-2007
amitrajvarma amitrajvarma is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 43
My shell is tcsh
  #4 (permalink)  
Old 10-12-2007
ricoh ricoh is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
while calling the function dont use () . just call the function.
it will be :

if [ $# -lt 1 ]; then
help_ani
fi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0