This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes error correction Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "error correction" Watch "error correction" New topic
Author

error correction

kalyani kal
Greenhorn

Joined: Jan 28, 2012
Posts: 3
Hello all..
I wrote the following code as part of my project work. I need to print 'i' value based on the number of ';'(semi colons) in the input string. but thw while loop is not getting executed. It is returning errors. I tried lot of alternatives bt could not figure it out.. Badly need in help.. please replty me

IN="aa;bb;cc;"
c= echo $IN | tr -dc ';' | wc -c
echo $c
i=1
while [ $i -le $c ];
do
echo $i
i=`expr $i + 1`
done
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1295

Hi,

I'm pretty rookie myself in shell script, but what I can see from below script is : output of the piped command is not getting assigned to 'c', i.e. if you try to print value of c, it prints nothing.

Secondly, during number comparison, one should wrap variables with double quotes like : while [ "$i" -le "$c" ];

Hope this helps. Also, reply to this if you find a way to assign output of piped commands to a variable.

Thanks.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
kalyani kal
Greenhorn

Joined: Jan 28, 2012
Posts: 3
Thank you for your reply dear Anayonkar Shivalkar. Yes what you said was correct. ther is a problem with value assignment to c. So i modified it as follows

IN="aa;bb;cc;"
c=`echo $IN | tr -dc ';' | wc -c`
echo $c
i=1
while [ $i -le $c ];
do
echo $i
i=`expr $i + 1`
done

I kept the second statement in back tick (`). It's working fine now..
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: error correction
 
Similar Threads
Expert guidance needed in understanding the part of a shell script
shell script in tcsh
Unable to compile java file through ant
Getting error - Chapter 4 of Ejb3 in action using glassfish server 2.1
Tomcat fails to restart with "Address already in use" exception