Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me George!!!!!

 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could you please let me know what's wrong with this script.
#!/bin/sh
for FILENAME in *.jsp
do
echo "processing ${FILENAME}"
name=Zaizar
cnt='grep -c $name ${FILENAME}'
echo $cnt
done
Instead of giving me the count it's simply printing
'grep -c $name ${FILENAME}'
Please let me know what's wrong here.
Bytheway i use C shell.
Thanks A Lot,
Suja.

[This message has been edited by sujatha mamidala (edited March 16, 2001).]
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sujatha,
as an aside, although you might be using the C shell, the script you describe is using the Bourne shell (or Bourne Again shell, or POSIX shell, depending on the setup of the UNIX/Linux/BSD box that you use).
The first line of your script...
#!/bin/sh
... is an indication to the executing shell what program will be used to interpret the lines of this script. So you will type the name of the script in your C shell session, and that will see the first line of your script and invoke the Bourne shell (/bin/sh) to interpret the lines of the script. Likewise, if you wanted to use perl you would use the following line as the first line of your perl script:
#!/usr/local/bin/perl
(assuming that perl resides in /usr/local/bin of course)
By the way, you don't need to address things to me personally, there are many people more experienced than me who check this forum too and can reply to these posts, it's better not to exclude them - you'd be missing out on their good advice if you do that.
 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again Thanks a lot George.
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problably out of date sujatha mamidala but I hope this helps
:
use `` instead of ''
if you use simple quotes you are using a string and `` is for executing commands

#!/bin/sh
for FILENAME in *.jsp
do
echo "processing ${FILENAME}"
name=Zaizar
cnt='grep -c $name ${FILENAME}'
echo $cnt
done

This script will work the same way

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic