The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting Processes heprox Shell Programming and Scripting 4 03-21-2007 05:44 AM
URGENT,URGENT- Need help tape drive installation sriny UNIX for Advanced & Expert Users 3 11-16-2006 03:43 PM
URGENT---URGENT--No OK PROMPt after RSC CONFIG sriny SUN Solaris 7 10-29-2006 11:06 AM
Help with counting files please gerard1 Shell Programming and Scripting 6 09-25-2006 01:37 PM
Counting LOC in C amatsaka High Level Programming 1 06-04-2002 03:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-20-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
urgent help in counting

Hi,

When i am running the following shell scripting then i am getting the following output..

echo "sunita"
echo "now date is: `date`"
echo "enter command"
read command
read command
read command
read command
echo "command is: $command"
if [ "$command" = "" ]
then
echo "command is blank"
else
count=1
echo "count is $count"
((count=$count++1))
echo "it is enterred only $count times"
fi


Output is:
sunita
now date is: tuesday 20 40:9
count is 1
it is enterred only 2 times ---> here i need the 4 times(because i have entered 4 times in $command)

Can anybody tell me that how shell i get it??????
It is very urgent.....
can anybody help me???????
  #2 (permalink)  
Old 05-20-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Your program is linear, not a loop

You read input four times. Each time, storing to the same variable name.
Then, you check on its status.
Print a 1 as count variable
add 1 to count
print out count again
Thus, the program is executing exactly as you wrote it.

You want to:
--store each variable to a distinct name
--loop through the variables when done (not a one-time if)
  #3 (permalink)  
Old 05-20-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
I got it but can you please tell me with the example...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0