simple script with while loop getting problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers simple script with while loop getting problem
# 1  
Old 10-16-2010
simple script with while loop getting problem

Hello forum memebers.

can you correct the simple while program.

Code:
#! /bin/ksh
count=10
while [ $count -le 10 ]
do
   echo $count
   count='expr$count-1'
done

I think it will print 10 to 1 numbers but it running for indefinite times.

Last edited by Scott; 10-16-2010 at 07:27 AM.. Reason: Code tags, please...
# 2  
Old 10-16-2010
Code:
#! /bin/ksh
count=10
while [ $count -ge 1 ]
do
	echo $count
	count=$(expr $count - 1)
done

This User Gave Thanks to jlliagre For This Post:
# 3  
Old 10-16-2010
Code:
while [ $count -le 10 ]

you need [ $count -gt 0 ]
Code:
count='expr$count-1'

You used normal quotes instead of backticks, you forgot spaces before the $ and around the minus sign
This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with simple bash script involving a loop

Dear unix wizards, I'd be very grateful for your help with the following. I have a hypothetical file (file.txt) with three columns: 111 4 0.01 112 3 0.02 113 2 0.03 114 1 0.04 115 1 0.06 116 2 0.02 117 3 0.01 118 4 0.05 Column 2 consists of pairs of integers from 1 to 4 (each... (5 Replies)
Discussion started by: aberg
5 Replies

2. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

3. Shell Programming and Scripting

simple while loop script to check a connection

Hi, I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is... (9 Replies)
Discussion started by: zippyzip
9 Replies

4. Shell Programming and Scripting

Simple while-loop problem

Maybe because its Friday, but I can't get a simple while loop to work! #!bin/bash i=0 while do echo "Hello" ((i++)) done (17 Replies)
Discussion started by: linuxkid
17 Replies

5. Shell Programming and Scripting

Simple LOOP script help

I am trying to create a simple ksh loop script. What I've pasted below is not working. Any help is appreciated. typeset -i count typeset -i tcount count=0 tcount=0 while $tcount >= 11 do print "\$count is $count" pwd ls -l sleep 30 $(( $tcount = $count + 1 )) ... (5 Replies)
Discussion started by: musikman65
5 Replies

6. Shell Programming and Scripting

one simple shell script problem

Hi everyone, I am facing to one shell script problem, which is as following Write a shell script that: Takes a number of arguments. For each argument, print out all files in the current directory that contain this substring in their name. I know I need to use grep for the second... (7 Replies)
Discussion started by: shaloovia
7 Replies

7. Shell Programming and Scripting

Simple script problem

Hi everyone - I am sure this is a really simple problem but I'm a total noob at Linux scripting: I wanted to create a script that allows me to compare the current week number to the contents of a text file in my home directory: VAR1='date +%V' VAR2='cat /home/fred/file.txt' ... (6 Replies)
Discussion started by: FiniteRed
6 Replies

8. Shell Programming and Scripting

Simple bash for loop problem

I'm just trying to make a script that runs in command line to echo each line in a text file. Everything i found on google is telling me to do it like this but when I run it it just echos removethese.txt and thats it. Anyone know what im doing wrong? for i in removethese.txt; do echo $i; done ... (4 Replies)
Discussion started by: kingdbag
4 Replies

9. Shell Programming and Scripting

Simple script loop question

Hey all. Thanks in advance for any help you can give, hopefully this is an easy one. I want to create a loop to run a simple performance monitor like vmstat and record it to a file, but have very limited scripting skills (obviously). Starting with this... date >> /var/log/perfmon.log vmstat... (2 Replies)
Discussion started by: mattlock73
2 Replies

10. UNIX for Dummies Questions & Answers

simple shell script problem

hi all. i have a little problem. im basically reading input from the user from the keyboard into the variable "phonenumber". I want to do a little error check to check if the user doesnt enter anything in for the value phonenumber. i had this: read phonenumber if then ..... else ........ (2 Replies)
Discussion started by: djt0506
2 Replies
Login or Register to Ask a Question