1756548 Members
3575 Online
108848 Solutions
New Discussion юеВ

help_for script

 
SOLVED
Go to solution
Soul_1
Respected Contributor

help_for script

Hi,

I wrote one script to print the first 5 numbers
I want to modify this script in such a way that
it should display 1 and then replace 1 with 2 and so on.Its just like a stop watch.


#
echo "assigning value"
Value=1
while ((Value <= 5))
do
echo $Value
((Value=Value+1))
done


Thanks in advance
12 REPLIES 12
James R. Ferguson
Acclaimed Contributor
Solution

Re: help_for script

Hi Soul:

# cat ./timer
#!/usr/bin/sh
echo "assigning value"
Value=1
while ((Value <= 5))
do
echo "${Value}\b\c"
sleep 1
((Value=Value+1))
done
echo

Regards!

...JRF...
Soul_1
Respected Contributor

Re: help_for script

Hi,

Its working fine...

can u tell me what "\b\c" will do ?

: )

Thanks in advance
Steven Schweda
Honored Contributor

Re: help_for script

> can u tell me what "\b\c" will do ?

man echo
R.K. #
Honored Contributor

Re: help_for script

Hi Soul,

>> can u tell me what "\b\c" will do ?
\c instructs command not to perform a carriage return after the out-put.
\b is for backspace

This is how the line will not change (\c) and the number will be over-written (\b).

Don't fix what ain't broke
Soul_1
Respected Contributor

Re: help_for script

Hi,


When it comes to two digits ...its not displaying properly.when it reached two digits its displaying in one line.


Thanks in advance.
Steven Schweda
Honored Contributor

Re: help_for script

> When it comes to two digits ...its not
> displaying properly. [...]

Yes, one backspace character will not move
the cursor back two places. You might try
using two backspace characters in that case.

Have you ever used a typewriter? The
concepts here are similar.


> I wrote one script to print the first 5
> numbers

If you describe the actual problem which you
are trying to solve, then you may get better
(more appropriate) answers. Otherwise, if
you're the only one who knows what the actual
problem is, then you may need to do some
thinking for yourself.
Soul_1
Respected Contributor

Re: help_for script

hi,

Please help me to print first 25 numbers.


Thanks & Regards
Dennis Handly
Acclaimed Contributor

Re: help_for script

>When it comes to two digits

If the digits are at the beginning, you can use "\r" for a carriage return.
R.K. #
Honored Contributor

Re: help_for script

It is working after using \r
Little Interactive and edit as per Dennis:

# cat timer
#!/usr/bin/sh
echo "Enter a number for counting: \c"
read N
Value=1
while ((Value <= $N))
do
echo "${Value}\r\c" # use "r" here
sleep 1
((Value=Value+1))
done
echo


Thanks JRF and Dennis...a good learing for me as well :-)
Don't fix what ain't broke