• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,

reply
    Bookmark Topic Watch Topic
  • New Topic