Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Korn to Bash syntax 1

Status
Not open for further replies.

webopdoug

Technical User
Jun 27, 2006
5
US
I use the following in a UNIX Korn shell script

while [ i -lt $time ]; do
echo ".\c"
sleep 1
let i=i+1
done

It produces a ....... string to actively show the script is pausing.

This doesn't work with Bash. the result is
./c
./c
./c
etc

Is there an equivalent syntax for Bash?
 
yes...

[194][snafu]:/home/jeff> time=4
[195][snafu]:/home/jeff> i=1
[196][snafu]:/home/jeff> while [ $i -lt $time ]; do
=> echo ".\c"
=> sleep 1
=> ((i=$i+1))
=> done
.\c
.\c
.\c
[197][snafu]:/home/jeff>

several ways to skin a cat but it works.
 
Not what I was looking for... What I want to see is "dot dot dot" etc across the screen until the timer times out. The output to screen should liook something like this...

do something here
. . . . . . . . .
do something here
. . . . .
end

It works in Korn shell but not in Bash. THe output in bas is undesireable
.\c
.\c
.\c

The full pause function looks like this (for Unix Korn)

function pause {
time=$1
if [ -z "$time" ]; then
echo No time specified
echo Usage: pause time
return 1
fi
i=0
while [ i -lt $time ]; do
echo ".\c"
sleep 1
let i=i+1
done
echo
}

Looking for the equivalent in Bash.
 
oh, then your problem is really with how you're calling echo, not really bash specific?

[14186][snafu]:/home/jeff> i=0
[14187][snafu]:/home/jeff> time=4
[14188][snafu]:/home/jeff> while [ $i -lt $time ]; do echo -e ".\c"; sleep 1; ((i=$i+1)); done
....[14189][snafu]:/home/jeff>

echo -e to interpret the \c or just echo -n "." to suppress newline and give your line-o-dots?
 
Perfect. I used echo -n "."

asldl38015: pause 10
..........

Thank you.
 
If you want to have a portable function for both machines, try

[tt]printf "."[/tt]

instead of

[tt]echo ".\c"[/tt]
or
[tt]echo -c ".\c"[/tt]
or
[tt]echo -n "."[/tt]


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top