• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Madhu Kaparapu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic