Generate a string

Hi,

I want to generate a string like 99999 or 00000 depending upon the number of zeros or nines.. that is if I say 9 then I need the string "9" as 999999999. if I say 4 zeros then i need to get a string 0000. Like my input to a function are number ( 0,1,2) which should be there in the string and number of times it needs to repeat..\

Can any one give me the logic....

[~]$ NINE=9
[~]$ echo $NINE
9
[~]$ while [ $NINE -gt 0 ]
> do
> echo -n 9
> NINE=$((NINE-1))
> done
999999999
[~]$

Is this what you are looking for ?

Vino

Which among 0,1,2 will be repeated ? And which among those numbers represent the frequency of repetition ?

Vino

Try this:

#!/bin/sh

num=$1
count=0
while [ $count -lt $num ]; do
        echo "$num \c"
        count=`expr $count + 1`
done
echo

P.S. vino, I think the OP wants the number supplied to the script to be repeated 'number' number of times.

I have script where the string and count are variables

===================================================
#!/bin/sh

generate_string()
{
string=$1
count=$2

result=""

while [ $count -gt 0 ]
do
result="$result$string"
count=`expr $count - 1`
done

echo $result
}

generate_string 4 6

===================================================
The output of this sample code will be 444444

Hope this helps your purpose

Amit

i want ot write this inside a script. I want 0 and 9 to repeat as many times as a variable which i specify. I mean if i say var=4; then i want two strings 0000 and 9999.