Meaningless Drivel is fun!*
The moose likes Linux / UNIX and the fly likes Out;put is not getting in this Shell Script?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Out;put is not getting in this Shell Script??" Watch "Out;put is not getting in this Shell Script??" New topic
Author

Out;put is not getting in this Shell Script??

Madhu Kaparapu
Ranch Hand

Joined: Jul 04, 2005
Posts: 35
1) divisibility.sh
-------------------
echo "Enter the number:\n"
read x
y=`expr $x % 3`
z=`expr $x % 4`
if [$y -eq 0 -a $z -eq 0]
then
echo "Divisible by both"
elif [$y -eq 0]
then
echo "Divisible by 3 only"
elif [$z -eq 0]
then
echo "Divibible by 4 only"
else
echo "Not by both"
fi

output:
--------
divisibility.sh: line 5: [0: command not found
divisibility.sh: line 8: [0: command not found
divisibility.sh: line 11: [0: command not found
Not by both

==============================================
2) greetings.sh
----------------
h=`date "+%H"`
if [$h -gt 4 -a $h -lt 11]
then
echo "Good Morning"
elif [$h -ge 11 -a $h -lt 16]
then
echo "Good Afternoon"
elif [$h -ge 16 -a $h -lt 20]
then
echo "Good Evening"
else
echo "Good Night"
fi

output:
-------
greetings.sh: line 2: [12: command not found
greetings.sh: line 5: [12: command not found
greetings.sh: line 8: [12: command not found
Good Night

i don't where the bug lies, i am using suse linux.
please explaine me the correct way


Regards,
Madhu Kaparapu.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Believe it or not, "[" is a UNIX program -- see /usr/bin/[ !

You have to use whitespace after its name, before its arguments, just as for all UNIX programs. So, for example,



[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out;put is not getting in this Shell Script??
 
Similar Threads
Tomcat fails to restart with "Address already in use" exception
assertions
Chapter 5 K&B -Doubt
how to compare the values in arrays
error starting up 2nd instance of tomcat