Simple while loop question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple while loop question
# 1  
Old 07-21-2006
Simple while loop question

I have written a script that countsdown from 20 to 1 and has a sleep in between each count but I want to make it sleep for half a second but I get errors whenever I change the sleep from 1 second to half a second any ideas? I am using Sun OS 5.9 heres what I've got:

X=0
while [ $X -le 20 ]
do
echo $X
X=$((X+1))
sleep 0.5
done
# 2  
Old 07-21-2006
You can“t do it with the sleep command.

Check this link
# 3  
Old 07-21-2006
The parameter of the sleep command is an integer, you can't specify an half of second.

From man page:
Code:
The sleep command suspends execution of a process for at least the interval
specified by the Seconds parameter. The amount of time specified in the Seconds
parameter can range from 1 to MAXINT (2,147,483,647) seconds.

# 4  
Old 07-21-2006
You can make this in perl:
Code:
$ perl -e "select(undef, undef, undef, 0.5)"

or if above doesn't work try
Code:
$ perl <<END                                     
> use Time::HiRes qw(sleep);
> sleep(0.5);
> END

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. Shell Programming and Scripting

Simple loop using for

Dear experts, I am writing a bash script. At some point of the program I need to have 'for' loop. For simplicity I tried with some other simple code. The format of the loop is given below. k=51 m=55 for j in {$k..$m};do w=$(($j+2)) z=$(($j+9)) echo "$w, $z" done But my... (4 Replies)
Discussion started by: vjramana
4 Replies

3. Shell Programming and Scripting

Simple while read line loop question

#!/bin/bash count=1 while read line do if (($count > 4)); then awk -v var1="$count" '{printf "%3s%8s%11s%11s%11s\n",var1,$2,$3,$4,$5}' else echo $line fi count=$((count+1)) done < posre_sub.itp > test cat test INPUT: ; position restraints for... (3 Replies)
Discussion started by: origamisven
3 Replies

4. Shell Programming and Scripting

really simple for loop question

apologies for the basicness of this question, but within a for loop how can i "list" my values as opposed to adding them to the same line for example if i use this it works fine for n in peter paul david do echo "my name is $n" done but i wanted to list my items ( i have quite a... (2 Replies)
Discussion started by: rethink
2 Replies

5. Shell Programming and Scripting

Simple using For loop

Hi expert, I'm using csh Code: #!/bin/csh set x = 0 set number = `awk '{array=$0} END {print array;}'` i want to use for loop to store data to $number repeatly untill x = 23 How to use c shell for loop? (2 Replies)
Discussion started by: vincyoxy
2 Replies

6. Shell Programming and Scripting

Simple for loop question

Hello I am a beginner of shell scripting and i am having trouble to do a for loop. I want a for loop to do stuff 3 times. i.e. in visual basic i do this for (counter = 0; counter < 3; counter++) on my shell script i have something like this at the moment ... (7 Replies)
Discussion started by: arex876
7 Replies

7. Shell Programming and Scripting

A simple (?) loop

I have what I believe is a simple programming question. I have a text file that looks like: mol 1 G:\stereo01.hin block text ... ... ... endmol 1 However, I would like a file that repeats this entire block of text several times over. The lines of text in the middle remain the same for each... (2 Replies)
Discussion started by: red baron
2 Replies

8. Shell Programming and Scripting

simple while loop

i have a script called file2 #!/bin/ksh i=0 while do echo $i >> result.txt i=`expr $i + 1` done echo "***********************" >> result ------------------------------------------------------------------- (10 Replies)
Discussion started by: ali560045
10 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

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies
Login or Register to Ask a Question