repeat output of string

Hi!
I want to print a string in a shell script n-times
I can do this by "perl -e 'print "x" x 80;'
this would print "x" 80 times

but is there a general solution without perl -
perhaps there is a command, to repeat any command for n-times??

thanks
witty
LVL 1
wittyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
#!/bin/csh -f
repeat 80 echo -n x
echo ""
# just a solution, but not very performant :(
0
wittyAuthor Commented:
ahoffmann,
that is exactly what I'm looking for!!
but my problem:
I only have ksh (and bash on another machine)
but there is no command like "repeat" in these shells!!

is there such a command in these two shells?

thanks
witty
0
ahoffmannCommented:
sorry, bash and ksh only have the:
until .. do .. done  loop
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ozoCommented:
typeset -R80 x=x
echo "$x" | tr ' ' x
0
chris_calabreseCommented:
I haven't tested this on bash, but it works under ksh and a strict POSIX.2 shell and I believe it uses only POSIX.2 constructs.  Therefore, if it doesn't work under bash, it's probably because bash is broken.


function repeat {
    if [ "$#" -lt 2 ]
    then    cat << EOF >&2
repeat: Usage Error: not enough arguments
USAGE: repeat number-of-times program-to-run argumnents ...
EOF
            return 2
    fi
    typeset -i n="$1"; shift
    while [ "$n" -gt 0 ]
    do  "$@"
        n="$((n-1))"
    done
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wittyAuthor Commented:
chris,
this is not exactly, what I wanted, but obviously there is no simple command to do this!

thanks to all of you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.